From fbe833d515879fac589e2ae056bc8db424a6d060 Mon Sep 17 00:00:00 2001 From: Balazs Komuves Date: Thu, 13 Nov 2025 20:11:31 +0100 Subject: [PATCH] update the Nim parser too --- nim/circom_witnessgen/graph.nim | 5 +++++ nim/circom_witnessgen/load.nim | 33 +++++++++++++++++++++++++++++++-- nim/main.nim | 15 +++++++++++++-- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/nim/circom_witnessgen/graph.nim b/nim/circom_witnessgen/graph.nim index 12e9ef0..c438550 100644 --- a/nim/circom_witnessgen/graph.nim +++ b/nim/circom_witnessgen/graph.nim @@ -86,9 +86,14 @@ type CircuitInputs* = seq[(string, SignalDescription)] + Prime* = object + primeNumber*: BigUInt + primeName*: string + GraphMetaData* = object witnessMapping*: WitnessMapping inputSignals*: CircuitInputs + prime*: Prime Graph* = object nodes*: seq[Node[uint32]] diff --git a/nim/circom_witnessgen/load.nim b/nim/circom_witnessgen/load.nim index 6be2935..07d340a 100644 --- a/nim/circom_witnessgen/load.nim +++ b/nim/circom_witnessgen/load.nim @@ -195,17 +195,46 @@ proc parseCircuitInput(buf: openArray[byte], p: var int): (string, SignalDescrip p = nextp return (name,desc) +proc parsePrime(buf: openArray[byte], p: var int): Prime = + + # prime number (BigUInt) + let fld1 = buf.parseProtoField(p, LEN) + assert( fld1 == 3 , "expecting protobuf field id 3") + let len1 = buf.parseVarInt(p) + let nextp1 = p + len1 + # protobuf is stupid, it's like triple wrapped + let fld1b = buf.parseProtoField(p, LEN) + assert( fld1b == 1 , "expecting protobuf field id 1") + let len1b = buf.parseVarInt(p) + var bytes: seq[byte] = newSeq[byte](len1b) + for i in 0..