refactor env

This commit is contained in:
Jaremy Creechley 2024-05-02 15:47:12 +03:00
parent b118792cf4
commit 4aa45dadbd
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 9 additions and 9 deletions

View File

@ -34,7 +34,7 @@ template benchmark(benchmarkName: string, blk: untyped) =
fgGreen, "CPU Time [", benchmarkName, "] ", "avg(", $nn, "): ", elapsedStr, " s" fgGreen, "CPU Time [", benchmarkName, "] ", "avg(", $nn, "): ", elapsedStr, " s"
) )
proc runArkCircom(args: CircArgs, files: CircuitFiles) = proc runArkCircom(args: CircuitArgs, files: CircuitFiles) =
echo "Loading sample proof..." echo "Loading sample proof..."
var var
inputData = files.inputs.readFile() inputData = files.inputs.readFile()
@ -62,12 +62,12 @@ proc runArkCircom(args: CircArgs, files: CircuitFiles) =
verRes = circom.verify(proof, proofInputs).tryGet verRes = circom.verify(proof, proofInputs).tryGet
echo "verify result: ", verRes echo "verify result: ", verRes
proc runRapidSnark(args: CircArgs, files: CircuitFiles) = proc runRapidSnark(args: CircuitArgs, files: CircuitFiles) =
# time rapidsnark ${CIRCUIT_MAIN}.zkey witness.wtns proof.json public.json # time rapidsnark ${CIRCUIT_MAIN}.zkey witness.wtns proof.json public.json
echo "generating the witness..." echo "generating the witness..."
proc runBenchmark(args: CircArgs) = proc runBenchmark(args: CircuitArgs) =
## execute benchmarks given a set of args ## execute benchmarks given a set of args
## will create a folder in `benchmarks/circuit_bench_$(args)` ## will create a folder in `benchmarks/circuit_bench_$(args)`
## ##
@ -88,7 +88,7 @@ proc startBenchmarks*() =
echo "Running benchmark" echo "Running benchmark"
# setup() # setup()
checkEnv() checkEnv()
var args = CircArgs( var args = CircuitArgs(
depth: 32, # maximum depth of the slot tree depth: 32, # maximum depth of the slot tree
maxslots: 256, # maximum number of slots maxslots: 256, # maximum number of slots
cellsize: 2048, # cell size in bytes cellsize: 2048, # cell size in bytes

View File

@ -8,7 +8,7 @@ type
ptauUrl*: string ptauUrl*: string
codexProjDir*: string codexProjDir*: string
CircArgs* = object CircuitArgs* = object
depth*: int depth*: int
maxslots*: int maxslots*: int
cellsize*: int cellsize*: int
@ -97,13 +97,13 @@ proc downloadPtau*(ptauPath, ptauUrl: string) =
else: else:
echo "Found PTAU file at: ", ptauPath echo "Found PTAU file at: ", ptauPath
proc getCircuitBenchPath*(args: CircArgs): string = proc getCircuitBenchPath*(args: CircuitArgs): string =
var an = "" var an = ""
for f, v in fieldPairs(args): for f, v in fieldPairs(args):
an &= "_" & f & $v an &= "_" & f & $v
absolutePath("benchmarks/circuit_bench" & an) absolutePath("benchmarks/circuit_bench" & an)
proc generateCircomAndSamples*(args: CircArgs, env: CircuitEnv, name: string) = proc generateCircomAndSamples*(args: CircuitArgs, env: CircuitEnv, name: string) =
## run nim circuit and sample generator ## run nim circuit and sample generator
var cliCmd = env.nimCircuitCli var cliCmd = env.nimCircuitCli
for f, v in fieldPairs(args): for f, v in fieldPairs(args):
@ -114,7 +114,7 @@ proc generateCircomAndSamples*(args: CircArgs, env: CircuitEnv, name: string) =
runit fmt"{cliCmd} -v --circom={name}.circom --output=input.json" runit fmt"{cliCmd} -v --circom={name}.circom --output=input.json"
proc createCircuit*( proc createCircuit*(
args: CircArgs, args: CircuitArgs,
env: CircuitEnv, env: CircuitEnv,
name = "proof_main", name = "proof_main",
circBenchDir = getCircuitBenchPath(args), circBenchDir = getCircuitBenchPath(args),
@ -173,7 +173,7 @@ when isMainModule:
var env = CircuitEnv.default() var env = CircuitEnv.default()
checkEnv(env) checkEnv(env)
let args = CircArgs( let args = CircuitArgs(
depth: 32, # maximum depth of the slot tree depth: 32, # maximum depth of the slot tree
maxslots: 256, # maximum number of slots maxslots: 256, # maximum number of slots
cellsize: 2048, # cell size in bytes cellsize: 2048, # cell size in bytes