mirror of
https://github.com/status-im/nim-codex.git
synced 2025-03-04 04:10:42 +00:00
cosmetic changes
This commit is contained in:
parent
5c7b39fc0a
commit
180f280736
@ -53,7 +53,7 @@ type
|
|||||||
proof: ptr CircomProof
|
proof: ptr CircomProof
|
||||||
vkp: ptr CircomKey
|
vkp: ptr CircomKey
|
||||||
inputs: ptr CircomInputs
|
inputs: ptr CircomInputs
|
||||||
success: ptr Atomic[bool]
|
success: VerifyResult
|
||||||
signal: ThreadSignalPtr
|
signal: ThreadSignalPtr
|
||||||
|
|
||||||
func normalizeInput*[H](
|
func normalizeInput*[H](
|
||||||
@ -230,7 +230,7 @@ proc asyncProve*[H](
|
|||||||
proc prove*[H](
|
proc prove*[H](
|
||||||
self: CircomCompat, input: ProofInputs[H]
|
self: CircomCompat, input: ProofInputs[H]
|
||||||
): Future[?!CircomProof] {.async, raises: [CancelledError].} =
|
): Future[?!CircomProof] {.async, raises: [CancelledError].} =
|
||||||
var proof = newProof()
|
var proof = ProofPtr.new()
|
||||||
defer:
|
defer:
|
||||||
destroyProof(proof)
|
destroyProof(proof)
|
||||||
|
|
||||||
@ -245,6 +245,7 @@ proc circomVerifyTask(task: ptr VerifyTask) {.gcsafe.} =
|
|||||||
defer:
|
defer:
|
||||||
task[].inputs[].releaseCircomInputs()
|
task[].inputs[].releaseCircomInputs()
|
||||||
discard task[].signal.fireSync()
|
discard task[].signal.fireSync()
|
||||||
|
|
||||||
let res = verify_circuit(task[].proof, task[].inputs, task[].vkp)
|
let res = verify_circuit(task[].proof, task[].inputs, task[].vkp)
|
||||||
if res == ERR_OK:
|
if res == ERR_OK:
|
||||||
task[].success[].store(true)
|
task[].success[].store(true)
|
||||||
@ -258,7 +259,7 @@ proc asyncVerify*[H](
|
|||||||
self: CircomCompat,
|
self: CircomCompat,
|
||||||
proof: CircomProof,
|
proof: CircomProof,
|
||||||
inputs: ProofInputs[H],
|
inputs: ProofInputs[H],
|
||||||
success: ptr Atomic[bool],
|
success: VerifyResult,
|
||||||
): Future[?!void] {.async.} =
|
): Future[?!void] {.async.} =
|
||||||
var proofPtr = unsafeAddr proof
|
var proofPtr = unsafeAddr proof
|
||||||
var inputs = inputs.toCircomInputs()
|
var inputs = inputs.toCircomInputs()
|
||||||
@ -298,7 +299,6 @@ proc asyncVerify*[H](
|
|||||||
raise (ref CancelledError) exc
|
raise (ref CancelledError) exc
|
||||||
else:
|
else:
|
||||||
return failure(exc.msg)
|
return failure(exc.msg)
|
||||||
|
|
||||||
success()
|
success()
|
||||||
|
|
||||||
proc verify*[H](
|
proc verify*[H](
|
||||||
@ -306,7 +306,7 @@ proc verify*[H](
|
|||||||
): Future[?!bool] {.async, raises: [CancelledError].} =
|
): Future[?!bool] {.async, raises: [CancelledError].} =
|
||||||
## Verify a proof using a ctx
|
## Verify a proof using a ctx
|
||||||
##
|
##
|
||||||
var res = newVerifyResult()
|
var res = VerifyResult.new()
|
||||||
defer:
|
defer:
|
||||||
destroyVerifyResult(res)
|
destroyVerifyResult(res)
|
||||||
try:
|
try:
|
||||||
|
@ -23,7 +23,16 @@ type
|
|||||||
CircomProof* = Proof
|
CircomProof* = Proof
|
||||||
CircomKey* = VerifyingKey
|
CircomKey* = VerifyingKey
|
||||||
CircomInputs* = Inputs
|
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 =
|
proc toCircomInputs*(inputs: ProofInputs[Poseidon2Hash]): CircomInputs =
|
||||||
var
|
var
|
||||||
@ -55,17 +64,11 @@ func toG2*(g: CircomG2): G2Point =
|
|||||||
func toGroth16Proof*(proof: CircomProof): Groth16Proof =
|
func toGroth16Proof*(proof: CircomProof): Groth16Proof =
|
||||||
Groth16Proof(a: proof.a.toG1, b: proof.b.toG2, c: proof.c.toG1)
|
Groth16Proof(a: proof.a.toG1, b: proof.b.toG2, c: proof.c.toG1)
|
||||||
|
|
||||||
proc newProof*(): ptr Proof =
|
proc destroyVerifyResult*(result: VerifyResult) =
|
||||||
result = cast[ptr Proof](allocShared0(sizeof(Proof)))
|
|
||||||
|
|
||||||
proc newVerifyResult*(): ptr VerifyResult =
|
|
||||||
result = cast[ptr VerifyResult](allocShared0(sizeof(VerifyResult)))
|
|
||||||
|
|
||||||
proc destroyVerifyResult*(result: ptr VerifyResult) =
|
|
||||||
if result != nil:
|
if result != nil:
|
||||||
deallocShared(result)
|
deallocShared(result)
|
||||||
|
|
||||||
proc destroyProof*(proof: ptr Proof) =
|
proc destroyProof*(proof: ProofPtr) =
|
||||||
if proof != nil:
|
if proof != nil:
|
||||||
deallocShared(proof)
|
deallocShared(proof)
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ suite "Test Prover":
|
|||||||
|
|
||||||
for i in 0 ..< verifyResults.len:
|
for i in 0 ..< verifyResults.len:
|
||||||
check:
|
check:
|
||||||
verifyResults[i].read().isErr == false
|
verifyResults[i].read().tryGet() == true
|
||||||
|
|
||||||
test "Should complete prove/verify task when cancelled":
|
test "Should complete prove/verify task when cancelled":
|
||||||
let (_, _, verifiable) = await createVerifiableManifest(
|
let (_, _, verifiable) = await createVerifiableManifest(
|
||||||
@ -135,7 +135,7 @@ suite "Test Prover":
|
|||||||
|
|
||||||
let (inputs, proof) = (await prover.prove(1, verifiable, challenge)).tryGet
|
let (inputs, proof) = (await prover.prove(1, verifiable, challenge)).tryGet
|
||||||
|
|
||||||
var cancelledProof = newProof()
|
var cancelledProof = ProofPtr.new()
|
||||||
defer:
|
defer:
|
||||||
destroyProof(cancelledProof)
|
destroyProof(cancelledProof)
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ suite "Test Prover":
|
|||||||
check:
|
check:
|
||||||
(await prover.verify(cancelledProof[], inputs)).tryGet == true
|
(await prover.verify(cancelledProof[], inputs)).tryGet == true
|
||||||
|
|
||||||
var verifyRes = newVerifyResult()
|
var verifyRes = VerifyResult.new()
|
||||||
defer:
|
defer:
|
||||||
destroyVerifyResult(verifyRes)
|
destroyVerifyResult(verifyRes)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user