proving wiring

This commit is contained in:
Jaremy Creechley 2024-05-28 15:39:17 +01:00
parent 2fea35cecd
commit 472fbefc5f
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
1 changed files with 25 additions and 34 deletions

View File

@ -11,9 +11,7 @@ import pkg/poseidon2/io
import ./utils
import ./create_circuits
type
CircomCircuit* = object
type CircomCircuit* = object
r1csPath*: string
wasmPath*: string
zkeyPath*: string
@ -31,20 +29,16 @@ proc release*(self: CircomCircuit) =
if not isNil(self.vkp):
self.vkp.unsafeAddr.release_key()
proc init*(
_: type CircomCircuit,
r1csPath: string,
wasmPath: string,
zkeyPath: string = "",
): CircomCircuit =
proc initialize*(self: var CircomCircuit) =
## Create a new ctx
##
var cfg: ptr CircomBn254Cfg
var zkey = if zkeyPath.len > 0: zkeyPath.cstring else: nil
var zkey = if self.zkeyPath.len > 0: self.zkeyPath.cstring else: nil
if initCircomConfig(r1csPath.cstring, wasmPath.cstring, zkey, cfg.addr) != ERR_OK or
cfg == nil:
if initCircomConfig(
self.r1csPath.cstring, self.wasmPath.cstring, self.zkeyPath.cstring, cfg.addr
) != ERR_OK or cfg == nil:
if cfg != nil:
cfg.addr.releaseCfg()
raiseAssert("failed to initialize circom compat config")
@ -56,13 +50,8 @@ proc init*(
vkpPtr.addr.releaseKey()
raiseAssert("Failed to get verifying key")
CircomCircuit(
r1csPath: r1csPath,
wasmPath: wasmPath,
zkeyPath: zkeyPath,
backendCfg: cfg,
vkp: vkpPtr,
)
self.backendCfg = cfg
self.vkp = vkpPtr
proc prove*(self: CircomCircuit, input: JsonNode) =
## Encode buffers using a ctx
@ -155,9 +144,10 @@ proc parseCliOptions(self: var CircomCircuit) =
printHelp()
val.absolutePath
let params = @[
let params =
@[
"--dir:benchmarks/circuit_bench_depth32_maxslots256_cellsize2048_blocksize65536_nsamples1_entropy1234567_seed12345_nslots11_ncells512_index3/",
"--name:proof_main",
"--name:proof_main"
]
for kind, key, value in getOpt(params):
@ -199,8 +189,7 @@ proc run*() =
# prove wasm ${CIRCUIT_MAIN}.zkey witness.wtns proof.json public.json
var
self = CircomCircuit()
var self = CircomCircuit()
parseCliOptions(self)
@ -237,6 +226,8 @@ proc run*() =
echo "ERROR: couldn't find all files"
printHelp()
self.initialize()
var
inputData = self.inputsPath.readFile()
inputs: JsonNode = !JsonNode.parse(inputData)