cleanup cli

This commit is contained in:
Jaremy Creechley 2024-05-29 13:53:28 +01:00
parent 8b831c6764
commit 142c27e2b0
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
1 changed files with 13 additions and 14 deletions

View File

@ -1,5 +1,5 @@
import std/[sequtils, strformat, os, options, importutils] import std/[sequtils, strformat, os, options, importutils]
import std/[times, os, strutils, terminal, parseopt, json] import std/[times, os, strutils, terminal, parseopt, json, sets]
import pkg/questionable import pkg/questionable
import pkg/questionable/results import pkg/questionable/results
@ -21,6 +21,7 @@ type CircomCircuit* = object
circName*: string circName*: string
backendCfg: ptr CircomBn254Cfg backendCfg: ptr CircomBn254Cfg
vkp*: ptr VerifyingKey vkp*: ptr VerifyingKey
cmds*: HashSet[string]
proc release*(self: CircomCircuit) = proc release*(self: CircomCircuit) =
## Release the ctx ## Release the ctx
@ -61,12 +62,12 @@ proc parseJsons(
) = ) =
if value.kind == JString: if value.kind == JString:
var num = value.parseBigInt() var num = value.parseBigInt()
echo "Big NUM: ", num # echo "Big NUM: ", num
if (let res = ctx.pushInputU256Array(key.cstring, num.addr, 1); res != ERR_OK): if (let res = ctx.pushInputU256Array(key.cstring, num.addr, 1); res != ERR_OK):
raise newException(ValueError, "Failed to push BigInt from dec string " & $res) raise newException(ValueError, "Failed to push BigInt from dec string " & $res)
elif value.kind == JInt: elif value.kind == JInt:
var num = value.getInt().uint32 var num = value.getInt().uint32
echo "NUM: ", num, " orig: ", value.getInt() # echo "NUM: ", num, " orig: ", value.getInt()
if ctx.pushInputU32(key.cstring, num) != ERR_OK: if ctx.pushInputU32(key.cstring, num) != ERR_OK:
raise newException(ValueError, "Failed to push JInt") raise newException(ValueError, "Failed to push JInt")
elif value.kind == JArray: elif value.kind == JArray:
@ -95,7 +96,7 @@ proc initCircomCtx*(
raiseAssert("failed to initialize CircomCircuit ctx") raiseAssert("failed to initialize CircomCircuit ctx")
for key, value in input: for key, value in input:
echo "KEY: ", key, " VAL: ", value.kind # echo "KEY: ", key, " VAL: ", value.kind
ctx.parseJsons(key, value) ctx.parseJsons(key, value)
return ctx return ctx
@ -176,20 +177,17 @@ proc parseCliOptions(self: var CircomCircuit) =
printHelp() printHelp()
val.absolutePath val.absolutePath
let params =
@[
"--dir:benchmarks/circuit_bench_depth32_maxslots256_cellsize2048_blocksize65536_nsamples1_entropy1234567_seed12345_nslots11_ncells512_index3/",
"--name:proof_main"
]
# for kind, key, value in getOpt(params): # for kind, key, value in getOpt(params):
for kind, key, value in getOpt(): for kind, key, value in getOpt():
case kind case kind
# Positional arguments # Positional arguments
of cmdArgument: of cmdArgument:
echo "\nERROR: got unexpected arg: ", key, "\n" if key in ["prove", "verify"]:
printHelp() self.cmds.incl key
else:
echo "\nERROR: got unexpected arg: ", key, "\n"
printHelp()
# Switches # Switches
of cmdLongOption, cmdShortOption: of cmdLongOption, cmdShortOption:
@ -271,9 +269,10 @@ proc run*() =
ctx.addr.releaseCircomCompat() ctx.addr.releaseCircomCompat()
var pubInputs: ptr Inputs var pubInputs: ptr Inputs
doAssert ctx.get_pub_inputs(pubInputs.addr) == ERR_OK
defer: defer:
release_inputs(pubInputs.addr) if pubInputs != nil:
release_inputs(pubInputs.addr)
doAssert ctx.get_pub_inputs(pubInputs.addr) == ERR_OK
let proof = prove(self, ctx) let proof = prove(self, ctx)
let verified = verify(self, pubInputs, proof) let verified = verify(self, pubInputs, proof)