diff --git a/codex/slots/proofs/backends/asynccircoms.nim b/codex/slots/proofs/backends/asynccircoms.nim index 5a008b5d..b63fad5a 100644 --- a/codex/slots/proofs/backends/asynccircoms.nim +++ b/codex/slots/proofs/backends/asynccircoms.nim @@ -50,7 +50,7 @@ proc prove*[H]( without queue =? newSignalQueue[?!CircomProof](maxItems = 1), qerr: return failure(qerr) - var args = (ref ProverArgs[H])(circom: self.circom, data: input) + var args = (ref ProverArgs[H])(circom: self.circom.duplicate(), data: input) GC_ref(args) proc spawnTask() = @@ -87,7 +87,7 @@ proc verify*[H]( without queue =? newSignalQueue[?!bool](maxItems = 1), qerr: return failure(qerr) - var args = (ref VerifierArgs[H])(circom: self.circom, proof: proof, inputs: inputs) + var args = (ref VerifierArgs[H])(circom: self.circom.duplicate(), proof: proof, inputs: inputs) GC_ref(args) proc spawnTask() = @@ -116,9 +116,9 @@ proc init*( AsyncCircomCompat(circom: circom, tp: tp) proc duplicate*( - self: AsyncCircomCompat, tp: Taskpool + self: AsyncCircomCompat ): AsyncCircomCompat = ## Create a new async circom ## let circom = self.circom.duplicate() - AsyncCircomCompat(circom: circom, tp: tp) + AsyncCircomCompat(circom: circom, tp: self.tp) diff --git a/codex/slots/proofs/backends/circomcompat.nim b/codex/slots/proofs/backends/circomcompat.nim index 2fee7b35..517e829d 100644 --- a/codex/slots/proofs/backends/circomcompat.nim +++ b/codex/slots/proofs/backends/circomcompat.nim @@ -242,6 +242,7 @@ proc duplicate*( ## Create a new ctx var cfg: ptr CircomBn254Cfg if duplicateCircomConfig(self.backendCfg, cfg.addr) != ERR_OK or cfg == nil: - if cfg != nil: cfg.addr.releaseCfg() - raiseAssert("failed to initialize circom compat config") + if cfg != nil: + cfg.addr.releaseCfg() + raiseAssert("failed to initialize circom compat config") CircomCompat(params: self.params, backendCfg: cfg, vkp: self.vkp) diff --git a/tests/codex/slots/testprover.nim b/tests/codex/slots/testprover.nim index 0065a246..932d84e8 100644 --- a/tests/codex/slots/testprover.nim +++ b/tests/codex/slots/testprover.nim @@ -91,32 +91,32 @@ suite "Test Prover": let taskpool2 = Taskpool.new(num_threads = 2) - circomVerifyBackend = circomBackend.duplicate(taskpool2) + circomVerifyBackend = circomBackend.duplicate() proverVerify = Prover.new(store, circomVerifyBackend, samples) check: (await proverVerify.verify(proof, inputs)).tryGet == true - # test "Should sample and prove many slot": - # let - # r1cs = "tests/circuits/fixtures/proof_main.r1cs" - # wasm = "tests/circuits/fixtures/proof_main.wasm" + test "Should sample and prove many slot": + let + r1cs = "tests/circuits/fixtures/proof_main.r1cs" + wasm = "tests/circuits/fixtures/proof_main.wasm" - # taskpool = Taskpool.new(num_threads = 6) - # params = CircomCompatParams.init(r1cs, wasm) - # circomBackend = AsyncCircomCompat.init(params, taskpool) - # prover = Prover.new(store, circomBackend, samples) + taskpool = Taskpool.new(num_threads = 6) + params = CircomCompatParams.init(r1cs, wasm) + circomBackend = AsyncCircomCompat.init(params, taskpool) + prover = Prover.new(store, circomBackend, samples) - # var proofs = newSeq[Future[?!(AnyProofInputs, AnyProof)]]() - # for i in 1..50: - # echo "PROVE: ", i - # let - # challenge = (1234567).toF.toBytes.toArray32 + var proofs = newSeq[Future[?!(AnyProofInputs, AnyProof)]]() + for i in 1..50: + echo "PROVE: ", i + let + challenge = (1234567).toF.toBytes.toArray32 - # proofs.add(prover.prove(1, verifiable, challenge)) + proofs.add(prover.prove(1, verifiable, challenge)) - # await allFutures(proofs) + await allFutures(proofs) - # for pf in proofs: - # let (inputs, proof) = (await pf).tryGet - # check: - # (await prover.verify(proof, inputs)).tryGet == true + for pf in proofs: + let (inputs, proof) = (await pf).tryGet + check: + (await prover.verify(proof, inputs)).tryGet == true