diff --git a/benchmarks/codex_ark_prover_cli.nim b/benchmarks/codex_ark_prover_cli.nim index d4e90ed5..049e9b9b 100644 --- a/benchmarks/codex_ark_prover_cli.nim +++ b/benchmarks/codex_ark_prover_cli.nim @@ -21,16 +21,17 @@ type CircuitFiles* = object dir*: 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..." - var - circom = CircomCompat.init( - files.r1cs, - files.wasm, - files.zkey, - slotDepth = args.depth, - numSamples = args.nsamples, - ) + var circom = CircomCompat.init( + files.r1cs, + files.wasm, + files.zkey, + slotDepth = args.depth, + numSamples = args.nsamples, + ) defer: circom.release() # this comes from the rust FFI @@ -71,7 +72,6 @@ proc printHelp() = quit(1) proc parseCliOptions(args: var CircuitArgs, files: var CircuitFiles) = - var argCtr: int = 0 template expectPath(val: string): string = if val == "": @@ -90,33 +90,43 @@ proc parseCliOptions(args: var CircuitArgs, files: var CircuitFiles) = # Switches of cmdLongOption, cmdShortOption: case key - - of "h", "help" : printHelp() - of "d", "depth" : args.depth = parseInt(value) - of "N", "maxslots" : args.maxslots = parseInt(value) + of "h", "help": + printHelp() + of "d", "depth": + args.depth = parseInt(value) + of "N", "maxslots": + args.maxslots = parseInt(value) # of "c", "cellsize" : args.cellsize = checkPowerOfTwo(parseInt(value),"cellSize") # of "b", "blocksize" : args.blocksize = checkPowerOfTwo(parseInt(value),"blockSize") - of "n", "nsamples" : args.nsamples = parseInt(value) - of "e", "entropy" : args.entropy = parseInt(value) + of "n", "nsamples": + args.nsamples = parseInt(value) + of "e", "entropy": + args.entropy = parseInt(value) # of "S", "seed" : args.seed = parseInt(value) - of "s", "nslots" : args.nslots = parseInt(value) - of "K", "ncells" : args.ncells = checkPowerOfTwo(parseInt(value),"nCells") - of "i", "index" : args.index = parseInt(value) - - of "r1cs" : files.r1cs = value.expectPath() - of "wasm" : 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 - + of "s", "nslots": + args.nslots = parseInt(value) + of "K", "ncells": + args.ncells = checkPowerOfTwo(parseInt(value), "nCells") + of "i", "index": + args.index = parseInt(value) + of "r1cs": + files.r1cs = value.expectPath() + of "wasm": + 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: echo "Unknown option: ", key echo "use --help to get a list of options" quit() - of cmdEnd: - discard + discard proc run*() = ## Run Codex Ark/Circom based prover @@ -131,13 +141,21 @@ proc run*() = 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.r1cs == "": files.r1cs = dir / fmt"{files.circName}.r1cs" - if files.wasm == "": files.wasm = dir / fmt"{files.circName}.wasm" - if files.zkey == "": files.zkey = dir / fmt"{files.circName}.zkey" + if files.r1cs == "": + files.r1cs = dir / fmt"{files.circName}.r1cs" + 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 @@ -161,20 +179,29 @@ proc run*() = inputs: JsonNode = !JsonNode.parse(inputData) # sets default values for these args - if args.depth == 0: args.depth = codextypes.DefaultMaxSlotDepth # maximum depth of the slot tree - if args.maxslots == 0: args.maxslots = 256 # maximum number of slots + if args.depth == 0: + 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 - 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 - if args.entropy != 0: inputs["entropy"] = %($args.entropy) - if args.nslots != 0: inputs["nSlotsPerDataSet"] = % args.nslots - if args.index != 0: inputs["slotIndex"] = % args.index - if args.ncells != 0: inputs["nCellsPerSlot"] = % args.ncells + if args.entropy != 0: + inputs["entropy"] = %($args.entropy) + if args.nslots != 0: + inputs["nSlotsPerDataSet"] = %args.nslots + if args.index != 0: + inputs["slotIndex"] = %args.index + if args.ncells != 0: + inputs["nCellsPerSlot"] = %args.ncells - var - proofInputs = Poseidon2Hash.jsonToProofInput(inputs) + var proofInputs = Poseidon2Hash.jsonToProofInput(inputs) echo "Got args: ", args runArkCircom(args, files, proofInputs) diff --git a/benchmarks/config.nims b/benchmarks/config.nims index 805335f4..c5c2c5dc 100644 --- a/benchmarks/config.nims +++ b/benchmarks/config.nims @@ -6,6 +6,8 @@ on --tlsEmulation: off +--d: + release # when not defined(chronicles_log_level): # --define:"chronicles_log_level:NONE" # compile all log statements diff --git a/benchmarks/utils.nim b/benchmarks/utils.nim index cdd53664..12cb3be7 100644 --- a/benchmarks/utils.nim +++ b/benchmarks/utils.nim @@ -34,7 +34,7 @@ template benchmark*(benchmarkName: string, blk: untyped) = import std/math -func floorLog2* (x: int): int = +func floorLog2*(x: int): int = var k = -1 var y = x while (y > 0): @@ -42,13 +42,13 @@ func floorLog2* (x: int): int = y = y shr 1 return k -func ceilingLog2* (x: int): int = - if (x==0): +func ceilingLog2*(x: int): int = + if (x == 0): return -1 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) - 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