cosmetic changes

This commit is contained in:
munna0908 2025-02-21 17:15:50 +05:30
parent 5c7b39fc0a
commit 180f280736
No known key found for this signature in database
GPG Key ID: 2FFCD637E937D3E6
3 changed files with 20 additions and 17 deletions

View File

@ -53,7 +53,7 @@ type
proof: ptr CircomProof
vkp: ptr CircomKey
inputs: ptr CircomInputs
success: ptr Atomic[bool]
success: VerifyResult
signal: ThreadSignalPtr
func normalizeInput*[H](
@ -230,7 +230,7 @@ proc asyncProve*[H](
proc prove*[H](
self: CircomCompat, input: ProofInputs[H]
): Future[?!CircomProof] {.async, raises: [CancelledError].} =
var proof = newProof()
var proof = ProofPtr.new()
defer:
destroyProof(proof)
@ -245,6 +245,7 @@ proc circomVerifyTask(task: ptr VerifyTask) {.gcsafe.} =
defer:
task[].inputs[].releaseCircomInputs()
discard task[].signal.fireSync()
let res = verify_circuit(task[].proof, task[].inputs, task[].vkp)
if res == ERR_OK:
task[].success[].store(true)
@ -258,7 +259,7 @@ proc asyncVerify*[H](
self: CircomCompat,
proof: CircomProof,
inputs: ProofInputs[H],
success: ptr Atomic[bool],
success: VerifyResult,
): Future[?!void] {.async.} =
var proofPtr = unsafeAddr proof
var inputs = inputs.toCircomInputs()
@ -298,7 +299,6 @@ proc asyncVerify*[H](
raise (ref CancelledError) exc
else:
return failure(exc.msg)
success()
proc verify*[H](
@ -306,7 +306,7 @@ proc verify*[H](
): Future[?!bool] {.async, raises: [CancelledError].} =
## Verify a proof using a ctx
##
var res = newVerifyResult()
var res = VerifyResult.new()
defer:
destroyVerifyResult(res)
try:

View File

@ -23,7 +23,16 @@ type
CircomProof* = Proof
CircomKey* = VerifyingKey
CircomInputs* = Inputs
VerifyResult* = Atomic[bool]
VerifyResult* = ptr Atomic[bool]
ProofPtr* = ptr Proof
export ProofPtr
proc new*(_: type ProofPtr): ProofPtr =
cast[ptr Proof](allocShared0(sizeof(Proof)))
proc new*(_: type VerifyResult): VerifyResult =
cast[ptr Atomic[bool]](allocShared0(sizeof(Atomic[bool])))
proc toCircomInputs*(inputs: ProofInputs[Poseidon2Hash]): CircomInputs =
var
@ -55,17 +64,11 @@ func toG2*(g: CircomG2): G2Point =
func toGroth16Proof*(proof: CircomProof): Groth16Proof =
Groth16Proof(a: proof.a.toG1, b: proof.b.toG2, c: proof.c.toG1)
proc newProof*(): ptr Proof =
result = cast[ptr Proof](allocShared0(sizeof(Proof)))
proc newVerifyResult*(): ptr VerifyResult =
result = cast[ptr VerifyResult](allocShared0(sizeof(VerifyResult)))
proc destroyVerifyResult*(result: ptr VerifyResult) =
proc destroyVerifyResult*(result: VerifyResult) =
if result != nil:
deallocShared(result)
proc destroyProof*(proof: ptr Proof) =
proc destroyProof*(proof: ProofPtr) =
if proof != nil:
deallocShared(proof)

View File

@ -121,7 +121,7 @@ suite "Test Prover":
for i in 0 ..< verifyResults.len:
check:
verifyResults[i].read().isErr == false
verifyResults[i].read().tryGet() == true
test "Should complete prove/verify task when cancelled":
let (_, _, verifiable) = await createVerifiableManifest(
@ -135,7 +135,7 @@ suite "Test Prover":
let (inputs, proof) = (await prover.prove(1, verifiable, challenge)).tryGet
var cancelledProof = newProof()
var cancelledProof = ProofPtr.new()
defer:
destroyProof(cancelledProof)
@ -152,7 +152,7 @@ suite "Test Prover":
check:
(await prover.verify(cancelledProof[], inputs)).tryGet == true
var verifyRes = newVerifyResult()
var verifyRes = VerifyResult.new()
defer:
destroyVerifyResult(verifyRes)