store vkp on startup
This commit is contained in:
parent
20618507c9
commit
d977da9939
|
@ -37,6 +37,7 @@ type
|
||||||
wasmPath : string # path to the wasm file
|
wasmPath : string # path to the wasm file
|
||||||
zKeyPath : string # path to the zkey file
|
zKeyPath : string # path to the zkey file
|
||||||
backendCfg : ptr CircomBn254Cfg
|
backendCfg : ptr CircomBn254Cfg
|
||||||
|
vkp : ptr CircomKey
|
||||||
|
|
||||||
proc release*(self: CircomCompat) =
|
proc release*(self: CircomCompat) =
|
||||||
## Release the backend
|
## Release the backend
|
||||||
|
@ -44,20 +45,6 @@ proc release*(self: CircomCompat) =
|
||||||
|
|
||||||
self.backendCfg.unsafeAddr.releaseCfg()
|
self.backendCfg.unsafeAddr.releaseCfg()
|
||||||
|
|
||||||
proc getVerifyingKey*(
|
|
||||||
self: CircomCompat): ?!ptr CircomKey =
|
|
||||||
## Get the verifying key
|
|
||||||
##
|
|
||||||
|
|
||||||
var
|
|
||||||
cfg: ptr CircomBn254Cfg = self.backendCfg
|
|
||||||
vkpPtr: ptr VerifyingKey = nil
|
|
||||||
|
|
||||||
if cfg.getVerifyingKey(vkpPtr.addr) != ERR_OK or vkpPtr == nil:
|
|
||||||
return failure("Failed to get verifying key")
|
|
||||||
|
|
||||||
success vkpPtr
|
|
||||||
|
|
||||||
proc prove*[H](
|
proc prove*[H](
|
||||||
self: CircomCompat,
|
self: CircomCompat,
|
||||||
input: ProofInputs[H]): ?!CircomProof =
|
input: ProofInputs[H]): ?!CircomProof =
|
||||||
|
@ -181,15 +168,17 @@ proc verify*[H](
|
||||||
var
|
var
|
||||||
proofPtr = unsafeAddr proof
|
proofPtr = unsafeAddr proof
|
||||||
inputs = inputs.toCircomInputs()
|
inputs = inputs.toCircomInputs()
|
||||||
vkpPtr = ? self.getVerifyingKey()
|
|
||||||
|
|
||||||
let res = verifyCircuit(proofPtr, inputs.addr, vkpPtr)
|
try:
|
||||||
|
let res = verifyCircuit(proofPtr, inputs.addr, self.vkp)
|
||||||
if res == ERR_OK:
|
if res == ERR_OK:
|
||||||
success true
|
success true
|
||||||
elif res == ERR_FAILED_TO_VERIFY_PROOF:
|
elif res == ERR_FAILED_TO_VERIFY_PROOF:
|
||||||
success false
|
success false
|
||||||
else:
|
else:
|
||||||
failure("Failed to verify proof - err code: " & $res)
|
failure("Failed to verify proof - err code: " & $res)
|
||||||
|
finally:
|
||||||
|
inputs.releaseCircomInputs()
|
||||||
|
|
||||||
proc init*(
|
proc init*(
|
||||||
_: type CircomCompat,
|
_: type CircomCompat,
|
||||||
|
@ -212,13 +201,20 @@ proc init*(
|
||||||
addr cfg) != ERR_OK or cfg == nil:
|
addr cfg) != ERR_OK or cfg == nil:
|
||||||
raiseAssert("failed to initialize circom compat config")
|
raiseAssert("failed to initialize circom compat config")
|
||||||
|
|
||||||
|
var
|
||||||
|
vkpPtr: ptr VerifyingKey = nil
|
||||||
|
|
||||||
|
if cfg.getVerifyingKey(vkpPtr.addr) != ERR_OK or vkpPtr == nil:
|
||||||
|
raiseAssert("Failed to get verifying key")
|
||||||
|
|
||||||
CircomCompat(
|
CircomCompat(
|
||||||
r1csPath : r1csPath,
|
r1csPath : r1csPath,
|
||||||
wasmPath : wasmPath,
|
wasmPath : wasmPath,
|
||||||
zKeyPath : zKeyPath,
|
zKeyPath : zKeyPath,
|
||||||
backendCfg : cfg,
|
|
||||||
slotDepth : slotDepth,
|
slotDepth : slotDepth,
|
||||||
datasetDepth: datasetDepth,
|
datasetDepth: datasetDepth,
|
||||||
blkDepth : blkDepth,
|
blkDepth : blkDepth,
|
||||||
cellElms : cellElms,
|
cellElms : cellElms,
|
||||||
numSamples : numSamples)
|
numSamples : numSamples,
|
||||||
|
backendCfg : cfg,
|
||||||
|
vkp: vkpPtr)
|
||||||
|
|
Loading…
Reference in New Issue