From 393c2aaa8ac441a0684af965eca1e2f496af1f19 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 6 Feb 2024 12:36:21 -0600 Subject: [PATCH] add helper to unmarshal circom inputs --- tests/codex/slots/backends/helpers.nim | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/codex/slots/backends/helpers.nim b/tests/codex/slots/backends/helpers.nim index 8d6395b2..65e424ba 100644 --- a/tests/codex/slots/backends/helpers.nim +++ b/tests/codex/slots/backends/helpers.nim @@ -37,6 +37,31 @@ func toPublicInputs*[H](input: ProofInput[H]): PublicInputs[H] = entropy: input.entropy ) +proc toCircomInputs*[H](inputs: PublicInputs[H]): CircomInputs = + var + slotIndex = inputs.slotIndex.toF.toBytes.toArray32 + datasetRoot = inputs.datasetRoot.toBytes.toArray32 + entropy = inputs.entropy.toBytes.toArray32 + + elms = [ + entropy, + datasetRoot, + slotIndex + ] + + let inputsPtr = allocShared0(32 * elms.len) + copyMem(inputsPtr, addr elms[0], elms.len * 32) + + CircomInputs( + elms: cast[ptr array[32, byte]](inputsPtr), + len: elms.len.uint + ) + +proc releaseNimInputs*(inputs: var CircomInputs) = + if not inputs.elms.isNil: + deallocShared(inputs.elms) + inputs.elms = nil + func toJsonDecimal*(big: BigInt[254]): string = let s = big.toDecimal.strip( leading = true, trailing = false, chars = {'0'} ) if s.len == 0: "0" else: s