code cleanup

This commit is contained in:
munna0908 2025-03-02 13:08:23 +05:30
parent f907cbcdda
commit 9f32717d11
No known key found for this signature in database
GPG Key ID: 2FFCD637E937D3E6
3 changed files with 22 additions and 31 deletions

View File

@ -215,18 +215,13 @@ proc asyncProve*[H](
task.circom.taskpool.spawn circomProveTask(taskPtr)
let threadFut = threadPtr.wait()
try:
await threadFut.join()
except CatchableError as exc:
try:
await threadFut
except AsyncError as asyncExc:
return failure(asyncExc.msg)
finally:
if exc of CancelledError:
raise (ref CancelledError) exc
else:
return failure(exc.msg)
if joinErr =? catch(await threadFut.join()).errorOption:
if err=? catch(await noCancel threadFut).errorOption:
return failure(err)
if joinErr of CancelledError:
raise joinErr
else:
return failure(joinErr)
if not task.success.load():
return failure("Failed to prove circuit")
@ -254,11 +249,11 @@ proc circomVerifyTask(task: ptr VerifyTask) {.gcsafe.} =
let res = verify_circuit(task[].proof, task[].inputs, task[].vkp)
if res == ERR_OK:
task[].success[].store(true)
task[].success[]=true
elif res == ERR_FAILED_TO_VERIFY_PROOF:
task[].success[].store(false)
task[].success[]=false
else:
task[].success[].store(false)
task[].success[]=false
error "Failed to verify proof", errorCode = res
proc asyncVerify*[H](
@ -292,19 +287,15 @@ proc asyncVerify*[H](
self.taskpool.spawn circomVerifyTask(taskPtr)
let threadFut = threadPtr.wait()
if joinErr =? catch(await threadFut.join()).errorOption:
if err=? catch(await noCancel threadFut).errorOption:
return failure(err)
if joinErr of CancelledError:
raise joinErr
else:
return failure(joinErr)
try:
await threadFut.join()
except CatchableError as exc:
try:
await threadFut
except AsyncError as asyncExc:
return failure(asyncExc.msg)
finally:
if exc of CancelledError:
raise (ref CancelledError) exc
else:
return failure(exc.msg)
success()
proc verify*[H](
@ -318,7 +309,7 @@ proc verify*[H](
try:
if error =? (await self.asyncVerify(proof, inputs, res)).errorOption:
return failure(error)
return success(res[].load())
return success(res[])
except CancelledError as exc:
raise exc

View File

@ -23,14 +23,14 @@ type
CircomProof* = Proof
CircomKey* = VerifyingKey
CircomInputs* = Inputs
VerifyResult* = ptr Atomic[bool]
VerifyResult* = ptr bool
ProofPtr* = ptr Proof
proc new*(_: type ProofPtr): ProofPtr =
cast[ptr Proof](allocShared0(sizeof(Proof)))
proc new*(_: type VerifyResult): VerifyResult =
cast[ptr Atomic[bool]](allocShared0(sizeof(Atomic[bool])))
cast[ptr bool](allocShared0(sizeof(bool)))
proc toCircomInputs*(inputs: ProofInputs[Poseidon2Hash]): CircomInputs =
var

View File

@ -166,4 +166,4 @@ suite "Test Prover":
check exc of CancelledError
finally:
# validate the verifyResponse
check verifyRes[].load() == true
check verifyRes[] == true