From 4fdddafccdd11fb30f5e21fa333f1c1a0704cf9c Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Tue, 28 May 2024 19:52:10 +0100 Subject: [PATCH] adding proof input outputs --- benchmarks/circomcompat_cli.nim | 32 +++++++++++++++++++++++++++----- benchmarks/clitypes.nim | 3 +++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/benchmarks/circomcompat_cli.nim b/benchmarks/circomcompat_cli.nim index 72510500..251ece1d 100644 --- a/benchmarks/circomcompat_cli.nim +++ b/benchmarks/circomcompat_cli.nim @@ -54,6 +54,28 @@ proc initialize*(self: var CircomCircuit) = self.backendCfg = cfg self.vkp = vkpPtr +proc parseJsons( + ctx: var ptr CircomCompatCtx, + key: string, + value: JsonNode +) = + if value.kind == JString: + var num = value.parseBigInt() + echo "Big NUM: ", num + if ctx.pushInputU256Array(key.cstring, num.addr, 1) != ERR_OK: + raise newException(ValueError, "Failed to push BigInt from dec string") + elif value.kind == JInt: + var num = value.getInt().uint64 + echo "NUM: ", num + if ctx.pushInputU64(key.cstring, num) != ERR_OK: + raise newException(ValueError, "Failed to push JInt") + elif value.kind == JArray: + for item in value: + ctx.parseJsons(key, item) + else: + echo "unhandled val: " & $value + raise newException(ValueError, "Failed to push Json of " & $value.kind) + proc prove*(self: CircomCircuit, input: JsonNode) = ## Encode buffers using a ctx ## @@ -68,9 +90,9 @@ proc prove*(self: CircomCircuit, input: JsonNode) = if initCircomCompat(self.backendCfg, addr ctx) != ERR_OK or ctx == nil: raiseAssert("failed to initialize CircomCircuit ctx") - # if ctx.pushInputU256Array("entropy".cstring, entropy[0].addr, entropy.len.uint32) != - # ERR_OK: - # return failure("Failed to push entropy") + for key, value in input: + echo "KEY: ", key, " VAL: ", value.kind + ctx.parseJsons(key, value) # if ctx.pushInputU32("slotIndex".cstring, input.slotIndex.uint32) != ERR_OK: # return failure("Failed to push slotIndex") @@ -115,8 +137,8 @@ proc prove*(self: CircomCircuit, input: JsonNode) = if proofPtr != nil: proofPtr.addr.releaseProof() - echo "Proof:" - echo proof + # echo "Proof:" + # echo proof echo "\nProof:json:" let g16proof: Groth16Proof = proof.toGroth16Proof() echo pretty(%*(g16proof)) diff --git a/benchmarks/clitypes.nim b/benchmarks/clitypes.nim index c1057238..308bf99d 100644 --- a/benchmarks/clitypes.nim +++ b/benchmarks/clitypes.nim @@ -53,3 +53,6 @@ func toGroth16Proof*(proof: CircomProof): Groth16Proof = a: proof.a.toG1, b: proof.b.toG2, c: proof.c.toG1) + +proc parseBigInt*(input: JsonNode): UInt256 = + parse( input.str, UInt256 )