adding verification

This commit is contained in:
Jaremy Creechley 2024-05-28 23:30:16 +01:00
parent 50d3ab84ea
commit ae01d061b7
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300

View File

@ -95,16 +95,11 @@ proc initCircomCtx*(
return ctx
proc prove*(
self: CircomCircuit, input: JsonNode
self: CircomCircuit, ctx: ptr CircomCompatCtx
): CircomProof =
## Encode buffers using a ctx
##
var ctx = initCircomCtx(self, input)
defer:
if ctx != nil:
ctx.addr.releaseCircomCompat()
var proofPtr: ptr Proof = nil
let proof: Proof =
@ -127,16 +122,11 @@ proc prove*(
proc verify*(
self: CircomCircuit,
jsonInput: JsonNode,
ctx: ptr CircomCompatCtx,
proof: CircomProof,
): bool =
## Verify a proof using a ctx
var ctx = initCircomCtx(self, jsonInput)
defer:
if ctx != nil:
ctx.addr.releaseCircomCompat()
var inputs: ptr Inputs
doAssert ctx.get_pub_inputs(inputs.addr) == ERR_OK
@ -272,8 +262,13 @@ proc run*() =
inputData = self.inputsPath.readFile()
inputs: JsonNode = !JsonNode.parse(inputData)
let proof = prove(self, inputs)
let verified = verify(self, inputs, proof)
var ctx = initCircomCtx(self, inputs)
defer:
if ctx != nil:
ctx.addr.releaseCircomCompat()
let proof = prove(self, ctx)
let verified = verify(self, ctx, proof)
when isMainModule:
run()