updating ark cli

This commit is contained in:
Jaremy Creechley 2024-05-02 22:39:11 +03:00
parent 2e9a638fe2
commit f1732d58c2
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
3 changed files with 78 additions and 49 deletions

View File

@ -21,10 +21,11 @@ type CircuitFiles* = object
dir*: string dir*: string
circName*: string circName*: string
proc runArkCircom(args: CircuitArgs, files: CircuitFiles, proofInputs: ProofInputs[Poseidon2Hash]) = proc runArkCircom(
args: CircuitArgs, files: CircuitFiles, proofInputs: ProofInputs[Poseidon2Hash]
) =
echo "Loading sample proof..." echo "Loading sample proof..."
var var circom = CircomCompat.init(
circom = CircomCompat.init(
files.r1cs, files.r1cs,
files.wasm, files.wasm,
files.zkey, files.zkey,
@ -71,7 +72,6 @@ proc printHelp() =
quit(1) quit(1)
proc parseCliOptions(args: var CircuitArgs, files: var CircuitFiles) = proc parseCliOptions(args: var CircuitArgs, files: var CircuitFiles) =
var argCtr: int = 0 var argCtr: int = 0
template expectPath(val: string): string = template expectPath(val: string): string =
if val == "": if val == "":
@ -90,31 +90,41 @@ proc parseCliOptions(args: var CircuitArgs, files: var CircuitFiles) =
# Switches # Switches
of cmdLongOption, cmdShortOption: of cmdLongOption, cmdShortOption:
case key case key
of "h", "help":
of "h", "help" : printHelp() printHelp()
of "d", "depth" : args.depth = parseInt(value) of "d", "depth":
of "N", "maxslots" : args.maxslots = parseInt(value) args.depth = parseInt(value)
of "N", "maxslots":
args.maxslots = parseInt(value)
# of "c", "cellsize" : args.cellsize = checkPowerOfTwo(parseInt(value),"cellSize") # of "c", "cellsize" : args.cellsize = checkPowerOfTwo(parseInt(value),"cellSize")
# of "b", "blocksize" : args.blocksize = checkPowerOfTwo(parseInt(value),"blockSize") # of "b", "blocksize" : args.blocksize = checkPowerOfTwo(parseInt(value),"blockSize")
of "n", "nsamples" : args.nsamples = parseInt(value) of "n", "nsamples":
of "e", "entropy" : args.entropy = parseInt(value) args.nsamples = parseInt(value)
of "e", "entropy":
args.entropy = parseInt(value)
# of "S", "seed" : args.seed = parseInt(value) # of "S", "seed" : args.seed = parseInt(value)
of "s", "nslots" : args.nslots = parseInt(value) of "s", "nslots":
of "K", "ncells" : args.ncells = checkPowerOfTwo(parseInt(value),"nCells") args.nslots = parseInt(value)
of "i", "index" : args.index = parseInt(value) of "K", "ncells":
args.ncells = checkPowerOfTwo(parseInt(value), "nCells")
of "r1cs" : files.r1cs = value.expectPath() of "i", "index":
of "wasm" : files.wasm = value.expectPath() args.index = parseInt(value)
of "zkey" : files.zkey = value.expectPath() of "r1cs":
of "inputs" : files.inputs = value.expectPath() files.r1cs = value.expectPath()
of "dir" : files.dir = value.expectPath() of "wasm":
of "name" : files.circName = value files.wasm = value.expectPath()
of "zkey":
files.zkey = value.expectPath()
of "inputs":
files.inputs = value.expectPath()
of "dir":
files.dir = value.expectPath()
of "name":
files.circName = value
else: else:
echo "Unknown option: ", key echo "Unknown option: ", key
echo "use --help to get a list of options" echo "use --help to get a list of options"
quit() quit()
of cmdEnd: of cmdEnd:
discard discard
@ -131,13 +141,21 @@ proc run*() =
parseCliOptions(args, files) parseCliOptions(args, files)
let dir = if files.dir != "": files.dir else: getCurrentDir() let dir =
if files.dir != "":
files.dir
else:
getCurrentDir()
if files.circName != "": if files.circName != "":
if files.r1cs == "": files.r1cs = dir / fmt"{files.circName}.r1cs" if files.r1cs == "":
if files.wasm == "": files.wasm = dir / fmt"{files.circName}.wasm" files.r1cs = dir / fmt"{files.circName}.r1cs"
if files.zkey == "": files.zkey = dir / fmt"{files.circName}.zkey" if files.wasm == "":
files.wasm = dir / fmt"{files.circName}.wasm"
if files.zkey == "":
files.zkey = dir / fmt"{files.circName}.zkey"
if files.inputs == "": files.inputs = dir / fmt"input.json" if files.inputs == "":
files.inputs = dir / fmt"input.json"
echo "Got file args: ", files echo "Got file args: ", files
@ -161,20 +179,29 @@ proc run*() =
inputs: JsonNode = !JsonNode.parse(inputData) inputs: JsonNode = !JsonNode.parse(inputData)
# sets default values for these args # sets default values for these args
if args.depth == 0: args.depth = codextypes.DefaultMaxSlotDepth # maximum depth of the slot tree if args.depth == 0:
if args.maxslots == 0: args.maxslots = 256 # maximum number of slots args.depth = codextypes.DefaultMaxSlotDepth
# maximum depth of the slot tree
if args.maxslots == 0:
args.maxslots = 256
# maximum number of slots
# sets number of samples to take # sets number of samples to take
if args.nsamples == 0: args.nsamples = 1 # number of samples to prove if args.nsamples == 0:
args.nsamples = 1
# number of samples to prove
# overrides the input.json params # overrides the input.json params
if args.entropy != 0: inputs["entropy"] = %($args.entropy) if args.entropy != 0:
if args.nslots != 0: inputs["nSlotsPerDataSet"] = % args.nslots inputs["entropy"] = %($args.entropy)
if args.index != 0: inputs["slotIndex"] = % args.index if args.nslots != 0:
if args.ncells != 0: inputs["nCellsPerSlot"] = % args.ncells inputs["nSlotsPerDataSet"] = %args.nslots
if args.index != 0:
inputs["slotIndex"] = %args.index
if args.ncells != 0:
inputs["nCellsPerSlot"] = %args.ncells
var var proofInputs = Poseidon2Hash.jsonToProofInput(inputs)
proofInputs = Poseidon2Hash.jsonToProofInput(inputs)
echo "Got args: ", args echo "Got args: ", args
runArkCircom(args, files, proofInputs) runArkCircom(args, files, proofInputs)

View File

@ -6,6 +6,8 @@
on on
--tlsEmulation: --tlsEmulation:
off off
--d:
release
# when not defined(chronicles_log_level): # when not defined(chronicles_log_level):
# --define:"chronicles_log_level:NONE" # compile all log statements # --define:"chronicles_log_level:NONE" # compile all log statements

View File

@ -34,7 +34,7 @@ template benchmark*(benchmarkName: string, blk: untyped) =
import std/math import std/math
func floorLog2* (x: int): int = func floorLog2*(x: int): int =
var k = -1 var k = -1
var y = x var y = x
while (y > 0): while (y > 0):
@ -42,13 +42,13 @@ func floorLog2* (x: int): int =
y = y shr 1 y = y shr 1
return k return k
func ceilingLog2* (x: int): int = func ceilingLog2*(x: int): int =
if (x==0): if (x == 0):
return -1 return -1
else: else:
return (floorLog2(x-1) + 1) return (floorLog2(x - 1) + 1)
func checkPowerOfTwo*(x: int , what: string): int = func checkPowerOfTwo*(x: int, what: string): int =
let k = ceilingLog2(x) let k = ceilingLog2(x)
assert( x == 2^k, ("`" & what & "` is expected to be a power of 2") ) assert(x == 2 ^ k, ("`" & what & "` is expected to be a power of 2"))
return x return x