wire in prove

This commit is contained in:
Jaremy Creechley 2024-05-17 00:51:57 +03:00
parent 38ac70809e
commit 0dfa2cc488
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 9 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import pkg/chronos/threadsync
import pkg/questionable/results
import ../../types
import ../../../utils/asyncthreads
import ./circomcompat
@ -21,7 +22,7 @@ type
tp*: Taskpool
# Args objects are missing seq[seq[byte]] field, to avoid unnecessary data copy
ProveTaskArgs = object
ProveTaskArgs* = object
signal: ThreadSignalPtr
params: CircomCompatParams
@ -29,16 +30,16 @@ var circomBackend {.threadvar.}: CircomCompat
proc proveTask[H](
args: ProveTaskArgs, data: ProofInputs[H]
): Result[CircomProof, cstring] =
): Result[CircomProof, string] =
try:
let res = circomBackend.prove(data)
if res.isOk:
return ok(res.get())
else:
return err(res.error)
return err(res.error().msg)
except CatchableError as exception:
return err(exception.msg.cstring)
return err(exception.msg)
finally:
if err =? args.signal.fireSync().mapFailure.errorOption():
error "Error firing signal in proveTask ", msg = err.msg
@ -53,9 +54,10 @@ proc prove*[H](
return failure(err)
let args = ProveTaskArgs(signal: signal, params: self.params)
self.tp.spawn proveTask(args, input)
let flowvar = self.tp.spawn proveTask(args, input)
await wait(signal)
without res =? await awaitThreadResult(signal, flowvar), err:
return failure(err)
proc verify*[H](
self: AsyncCircomCompat, proof: CircomProof, inputs: ProofInputs[H]

View File

@ -13,6 +13,7 @@ import pkg/chronicles
import pkg/circomcompat
import pkg/poseidon2
import pkg/questionable/results
import pkg/taskpools
import pkg/libp2p/cid