mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-01-31 07:06:59 +00:00
implement async verify
This commit is contained in:
parent
2beb5ab2aa
commit
77dfa466a2
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user