implement async verify

This commit is contained in:
Jaremy Creechley 2024-05-20 18:57:42 +03:00
parent 2beb5ab2aa
commit 77dfa466a2
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300

View File

@ -28,7 +28,7 @@ proc prove*[H](
): Future[?!CircomProof] {.async.} =
## Generates proof using circom-compat asynchronously
##
without queue =? newSignalQueue[?!CircomProof](maxItems=1), err:
without queue =? newSignalQueue[?!CircomProof](maxItems = 1), err:
return failure(err)
template spawnTask() =
@ -46,12 +46,40 @@ proc prove*[H](
success(proof)
proc verifyTask[H](
circom: CircomCompat,
proof: CircomProof,
inputs: ProofInputs[H],
results: SignalQueuePtr[?!bool],
) =
let verified = circom.verify(proof, inputs)
if (let sent = results.send(verified); sent.isErr()):
error "Error sending verification results", msg = sent.error().msg
proc verify*[H](
self: AsyncCircomCompat, proof: CircomProof, inputs: ProofInputs[H]
): Future[?!bool] {.async.} =
## Verify a proof using a ctx
##
discard
##
without queue =? newSignalQueue[?!bool](maxItems = 1), err:
return failure(err)
template spawnTask() =
self.tp.spawn verifyTask(self.circom, proof, inputs, queue)
spawnTask()
let taskRes = await queue.recvAsync()
if (let res = queue.release(); res.isErr):
error "Error releasing proof queue ", msg = res.error().msg
without verifyRes =? taskRes, err:
return failure(err)
without verified =? verifyRes , err:
return failure(err)
success(verified)
proc init*(_: type AsyncCircomCompat, params: CircomCompatParams): AsyncCircomCompat =
## Create a new async circom