integrate setup and proving

This commit is contained in:
Jaremy Creechley 2024-04-24 15:17:16 +03:00
parent 682d03b989
commit 91c695cb0e
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 19 additions and 20 deletions

View File

@ -1,5 +1,7 @@
import std/sequtils import std/sequtils
import std/strutils import std/strutils
import std/strformat
import std/os
import std/options import std/options
import std/importutils import std/importutils
@ -58,27 +60,25 @@ when isMainModule:
ncells: 512, # number of cells in this slot ncells: 512, # number of cells in this slot
) )
let benchenv = createCircuit(args) let env = createCircuit(args)
## TODO: copy over testcircomcompat proving ## TODO: copy over testcircomcompat proving
when false: let
let r1cs = env.dir / fmt"{env.name}.r1cs"
r1cs = "tests/circuits/fixtures/proof_main.r1cs" wasm = env.dir / fmt"{env.name}.wasm"
wasm = "tests/circuits/fixtures/proof_main.wasm" zkey = env.dir / fmt"{env.name}.zkey"
zkey = "tests/circuits/fixtures/proof_main.zkey" inputs = env.dir / fmt"inputs.json"
var var
circom: CircomCompat inputData = inputs.readFile()
proofInputs: ProofInputs[Poseidon2Hash] inputJson = !JsonNode.parse(inputData)
proofInputs = Poseidon2Hash.jsonToProofInput(inputJson)
circom = CircomCompat.init(r1cs, wasm, zkey)
let let proof = circom.prove(proofInputs).tryGet
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 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

View File

@ -129,10 +129,9 @@ proc createCircuit*(
for f, v in fieldPairs(args): for f, v in fieldPairs(args):
cliCmd &= " --" & f & "=" & $v cliCmd &= " --" & f & "=" & $v
if not "input.json".fileExists: if not "inputs.json".fileExists:
echo "Generating Circom Files..." echo "Generating Circom Files..."
# ${NIMCLI_DIR}/cli $CLI_ARGS -v --circom=${CIRCUIT_MAIN}.circom --output=input.json cliCmd &= fmt" -v --circom={name}.circom --output=inputs.json"
cliCmd &= fmt" -v --circom={name}.circom --output=input.json"
echo "CWD: ", getCurrentDir() echo "CWD: ", getCurrentDir()
echo "CLI_CMD: ", cliCmd echo "CLI_CMD: ", cliCmd