From 91c695cb0e0cce76861a00fd17fe263f41a9ed29 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Wed, 24 Apr 2024 15:17:16 +0300 Subject: [PATCH] integrate setup and proving --- benchmarks/ark_prover_bench.nim | 34 ++++++++++++++++----------------- benchmarks/create_circuits.nim | 5 ++--- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/benchmarks/ark_prover_bench.nim b/benchmarks/ark_prover_bench.nim index 65fe1f98..ed3f3ef7 100644 --- a/benchmarks/ark_prover_bench.nim +++ b/benchmarks/ark_prover_bench.nim @@ -1,5 +1,7 @@ import std/sequtils import std/strutils +import std/strformat +import std/os import std/options import std/importutils @@ -58,27 +60,25 @@ when isMainModule: ncells: 512, # number of cells in this slot ) - let benchenv = createCircuit(args) + let env = createCircuit(args) ## TODO: copy over testcircomcompat proving - when false: - let - r1cs = "tests/circuits/fixtures/proof_main.r1cs" - wasm = "tests/circuits/fixtures/proof_main.wasm" - zkey = "tests/circuits/fixtures/proof_main.zkey" + let + r1cs = env.dir / fmt"{env.name}.r1cs" + wasm = env.dir / fmt"{env.name}.wasm" + zkey = env.dir / fmt"{env.name}.zkey" + inputs = env.dir / fmt"inputs.json" - var - circom: CircomCompat - proofInputs: ProofInputs[Poseidon2Hash] + var + inputData = inputs.readFile() + inputJson = !JsonNode.parse(inputData) + proofInputs = Poseidon2Hash.jsonToProofInput(inputJson) + circom = CircomCompat.init(r1cs, wasm, zkey) - let - inputData = readFile("tests/circuits/fixtures/input.json") - inputJson = !JsonNode.parse(inputData) - proofInputs = Poseidon2Hash.jsonToProofInput(inputJson) - circom = CircomCompat.init(r1cs, wasm, zkey) + let proof = circom.prove(proofInputs).tryGet - let proof = circom.prove(proofInputs).tryGet + let verRes = circom.verify(proof, proofInputs).tryGet + echo "verify: ", verRes - circom.verify(proof, proofInputs).tryGet - circom.release() # this comes from the rust FFI + circom.release() # this comes from the rust FFI diff --git a/benchmarks/create_circuits.nim b/benchmarks/create_circuits.nim index af7428ae..36ebde00 100644 --- a/benchmarks/create_circuits.nim +++ b/benchmarks/create_circuits.nim @@ -129,10 +129,9 @@ proc createCircuit*( for f, v in fieldPairs(args): cliCmd &= " --" & f & "=" & $v - if not "input.json".fileExists: + if not "inputs.json".fileExists: echo "Generating Circom Files..." - # ${NIMCLI_DIR}/cli $CLI_ARGS -v --circom=${CIRCUIT_MAIN}.circom --output=input.json - cliCmd &= fmt" -v --circom={name}.circom --output=input.json" + cliCmd &= fmt" -v --circom={name}.circom --output=inputs.json" echo "CWD: ", getCurrentDir() echo "CLI_CMD: ", cliCmd