From 0dfa2cc488f260ca5172e262560c053f7b37c86f Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Fri, 17 May 2024 00:51:57 +0300 Subject: [PATCH] wire in prove --- codex/slots/proofs/backends/asynccircoms.nim | 14 ++++++++------ codex/slots/proofs/prover.nim | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/codex/slots/proofs/backends/asynccircoms.nim b/codex/slots/proofs/backends/asynccircoms.nim index e9589274..efd1141d 100644 --- a/codex/slots/proofs/backends/asynccircoms.nim +++ b/codex/slots/proofs/backends/asynccircoms.nim @@ -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] diff --git a/codex/slots/proofs/prover.nim b/codex/slots/proofs/prover.nim index dfe93e2c..1c2d4ccf 100644 --- a/codex/slots/proofs/prover.nim +++ b/codex/slots/proofs/prover.nim @@ -13,6 +13,7 @@ import pkg/chronicles import pkg/circomcompat import pkg/poseidon2 import pkg/questionable/results +import pkg/taskpools import pkg/libp2p/cid