it runs now?

This commit is contained in:
Jaremy Creechley 2024-05-31 12:38:37 +01:00
parent caaeba8781
commit ad9d1c39d5
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
3 changed files with 24 additions and 18 deletions

View File

@ -27,8 +27,8 @@ proc proveTask(
params: CircomCompatParams, data: ProofInputs[Poseidon2Hash], results: SignalQueuePtr[?!CircomProof] params: CircomCompatParams, data: ProofInputs[Poseidon2Hash], results: SignalQueuePtr[?!CircomProof]
) = ) =
var data = data.deepCopy() var data = data
var params = params.deepCopy() var params = params
try: try:
echo "TASK: task: " echo "TASK: task: "
echo "TASK: task: params: ", params.r1csPath.cstring.pointer.repr echo "TASK: task: params: ", params.r1csPath.cstring.pointer.repr
@ -42,8 +42,8 @@ proc proveTask(
# echo "TASK: task: proof: ", proof.get.hash # echo "TASK: task: proof: ", proof.get.hash
echo "TASK: task: proof: ", proof echo "TASK: task: proof: ", proof
echo "TASK: task: params POST: ", params echo "TASK: task: params POST: ", params
let fake = CircomProof.failure("failed") # let fake = CircomProof.failure("failed")
if (let sent = results.send(fake); sent.isErr()): if (let sent = results.send(proof); sent.isErr()):
error "Error sending proof results", msg = sent.error().msg error "Error sending proof results", msg = sent.error().msg
except Exception: except Exception:
echo "PROVER DIED" echo "PROVER DIED"
@ -81,12 +81,18 @@ proc prove*[H](
success(proof) success(proof)
proc verifyTask[H]( proc verifyTask[H](
circom: CircomCompat, params: CircomCompatParams,
proof: CircomProof, proof: CircomProof,
inputs: ProofInputs[H], inputs: ProofInputs[H],
results: SignalQueuePtr[?!bool], results: SignalQueuePtr[?!bool],
) = ) =
let verified = circom.verify(proof, inputs) echo "VERIFY: task: proof: ", proof
var params = params
if localCircom.isNone:
localCircom = some CircomCompat.init(params)
let verified = localCircom.get().verify(proof, inputs)
echo "VERIFY: task: result: ", verified echo "VERIFY: task: result: ", verified
if (let sent = results.send(verified); sent.isErr()): if (let sent = results.send(verified); sent.isErr()):
@ -101,7 +107,7 @@ proc verify*[H](
return failure(qerr) return failure(qerr)
proc spawnTask() = proc spawnTask() =
self.tp.spawn verifyTask(self.circom, proof, inputs, queue) self.tp.spawn verifyTask(self.params, proof, inputs, queue)
spawnTask() spawnTask()

View File

@ -176,11 +176,11 @@ proc verify*[H](
## ##
var var
proofPtr = unsafeAddr proof proof = proof
inputs = inputs.toCircomInputs() inputs = inputs.toCircomInputs()
try: try:
let res = verifyCircuit(proofPtr, inputs.addr, self.vkp) let res = verifyCircuit(proof.addr, inputs.addr, self.vkp)
if res == ERR_OK: if res == ERR_OK:
success true success true
elif res == ERR_FAILED_TO_VERIFY_PROOF: elif res == ERR_FAILED_TO_VERIFY_PROOF:

View File

@ -67,10 +67,11 @@ suite "Test Prover":
prover = Prover.new(store, circomBackend, samples) prover = Prover.new(store, circomBackend, samples)
challenge = 1234567.toF.toBytes.toArray32 challenge = 1234567.toF.toBytes.toArray32
(inputs, proof) = (await prover.prove(1, verifiable, challenge)).tryGet (inputs, proof) = (await prover.prove(1, verifiable, challenge)).tryGet
# res = (await prover.prove(1, verifiable, challenge))
echo "TEST PROOF: result: ", proof
echo "TEST PROOF: state: ", params echo "TEST PROOF: state: ", params
# check: check:
# (await prover.verify(proof, inputs)).tryGet == true (await prover.verify(proof, inputs)).tryGet == true
test "Should sample and prove many slot": test "Should sample and prove many slot":
let let
@ -84,7 +85,7 @@ suite "Test Prover":
prover = Prover.new(store, circomBackend, samples) prover = Prover.new(store, circomBackend, samples)
var proofs = newSeq[Future[?!(AnyProofInputs, AnyProof)]]() var proofs = newSeq[Future[?!(AnyProofInputs, AnyProof)]]()
for i in 1..50: for i in 1..20:
echo "PROVE: ", i echo "PROVE: ", i
let let
challenge = (1234567).toF.toBytes.toArray32 challenge = (1234567).toF.toBytes.toArray32
@ -94,9 +95,8 @@ suite "Test Prover":
await allFutures(proofs) await allFutures(proofs)
echo "done" echo "done"
for pf in proofs:
# for pf in proofs: let (inputs, proof) = (await pf).tryGet
# let (inputs, proof) = (await pf).tryGet check:
# check: (await prover.verify(proof, inputs)).tryGet == true
# (await prover.verify(proof, inputs)).tryGet == true
echo "done done" echo "done done"