From ba0e7d9e2a5e582eb5ee2d26bbf7f17829df3b5c Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 15 Mar 2024 15:45:26 +0100 Subject: [PATCH] Fixes issue where inner-scope values are lost before returning --- codex/slots/proofs/backendfactory.nim | 3 +++ tests/codex/slots/testbackendfactory.nim | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/codex/slots/proofs/backendfactory.nim b/codex/slots/proofs/backendfactory.nim index 0f6a9b31..89abd27d 100644 --- a/codex/slots/proofs/backendfactory.nim +++ b/codex/slots/proofs/backendfactory.nim @@ -103,4 +103,7 @@ proc initializeBackend*( without backend =? (await initializeFromCeremonyHash(config, ceremonyHash, utils)), urlErr: warn "Could not initialize prover backend from ceremony url...", msg = urlErr.msg return failure(urlErr) + # Unexpected: value of backend does not survive leaving each scope. (definition does though...) + return success(backend) + return success(backend) return success(backend) diff --git a/tests/codex/slots/testbackendfactory.nim b/tests/codex/slots/testbackendfactory.nim index 05a32e17..1c73631d 100644 --- a/tests/codex/slots/testbackendfactory.nim +++ b/tests/codex/slots/testbackendfactory.nim @@ -1,7 +1,5 @@ import os import std/strutils -import std/sugar -import std/math import ../../asynctest @@ -12,7 +10,6 @@ import pkg/codex/slots/proofs/backends import pkg/codex/slots/proofs/backendfactory import pkg/codex/slots/proofs/backendutils -import ./helpers import ../helpers type @@ -34,6 +31,11 @@ method initializeCircomBackend*( self.argR1csFile = r1csFile self.argWasmFile = wasmFile self.argZKeyFile = zKeyFile + # We return a backend with *something* that's not nil that we can check for. + var + key = VerifyingKey(icLen: 123) + vkpPtr: ptr VerifyingKey = key.addr + return CircomCompat(vkp: vkpPtr) method downloadFile*( self: BackendUtilsMock, @@ -85,6 +87,7 @@ suite "Test BackendFactory": backend = (await initializeBackend(config, ceremonyHash, utilsMock)).tryGet check: + backend.vkp != nil utilsMock.argR1csFile == $config.circomR1cs utilsMock.argWasmFile == $config.circomWasm utilsMock.argZKeyFile == $config.circomZkey @@ -110,6 +113,7 @@ suite "Test BackendFactory": backend = (await initializeBackend(config, ceremonyHash, utilsMock)).tryGet check: + backend.vkp != nil utilsMock.argR1csFile == config.dataDir / "proof_main.r1cs" utilsMock.argWasmFile == config.dataDir / "proof_main.wasm" utilsMock.argZKeyFile == config.dataDir / "proof_main.zkey" @@ -135,6 +139,7 @@ suite "Test BackendFactory": backend = (await initializeBackend(config, ceremonyHash, utilsMock)).tryGet check: + backend.vkp != nil utilsMock.argR1csFile == config.dataDir / "proof_main.r1cs" utilsMock.argWasmFile == config.dataDir / "proof_main.wasm" utilsMock.argZKeyFile == config.dataDir / "proof_main.zkey"