diff --git a/acvm_js/test/node/execute_circuit.test.ts b/acvm_js/test/node/execute_circuit.test.ts index 3b84d8d9..dac93b9f 100644 --- a/acvm_js/test/node/execute_circuit.test.ts +++ b/acvm_js/test/node/execute_circuit.test.ts @@ -205,3 +205,29 @@ it("successfully executes two circuits with same backend", async function () { expect(solvedWitness0).to.be.deep.eq(expectedWitnessMap); expect(solvedWitness1).to.be.deep.eq(expectedWitnessMap); }); + +it("successfully executes 500 circuits with same backend", async function () { + this.timeout(100000); + + // chose pedersen op here because it is the one with slow initialization + // that led to the decision to pull backend initialization into a separate + // function/wasmbind + const solver: WasmBlackBoxFunctionSolver = await createBlackBoxSolver(); + + const { bytecode, initialWitnessMap, expectedWitnessMap } = await import( + "../shared/pedersen" + ); + + for (let i = 0; i < 500; i++) { + const solvedWitness = await executeCircuitWithBlackBoxSolver( + solver, + bytecode, + initialWitnessMap, + () => { + throw Error("unexpected oracle"); + } + ); + + expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); + } +}); diff --git a/blackbox_solver/build.rs b/blackbox_solver/build.rs index 3c911d9b..39db930b 100644 --- a/blackbox_solver/build.rs +++ b/blackbox_solver/build.rs @@ -7,7 +7,7 @@ use std::{ const BARRETENBERG_ARCHIVE: &str = "BARRETENBERG_ARCHIVE"; const BARRETENBERG_BIN_DIR: &str = "BARRETENBERG_BIN_DIR"; -const BARRETENBERG_ARCHIVE_FALLBACK: &str = "https://github.com/AztecProtocol/barretenberg/releases/download/barretenberg-v0.4.6/acvm_backend.wasm.tar.gz"; +const BARRETENBERG_ARCHIVE_FALLBACK: &str = "https://github.com/AztecProtocol/barretenberg/releases/download/barretenberg-v0.5.0/acvm_backend.wasm.tar.gz"; // const ARCHIVE_SHA256: &str = "1xpycikqlvsjcryi3hkbc4mwmmdz7zshw6f76vyf1qssq53asyfx"; fn unpack_wasm(archive_path: &Path, target_dir: &Path) -> Result<(), String> { diff --git a/blackbox_solver/src/barretenberg/wasm/mod.rs b/blackbox_solver/src/barretenberg/wasm/mod.rs index 78d77d99..995ef673 100644 --- a/blackbox_solver/src/barretenberg/wasm/mod.rs +++ b/blackbox_solver/src/barretenberg/wasm/mod.rs @@ -87,13 +87,23 @@ impl Barretenberg { #[cfg(not(target_arch = "wasm32"))] pub(crate) fn new() -> Barretenberg { let (instance, memory, store) = instance_load(); - Barretenberg { memory, instance, store: RefCell::new(store) } + let barretenberg = Barretenberg { memory, instance, store: RefCell::new(store) }; + barretenberg.call_wasi_initialize(); + barretenberg } #[cfg(target_arch = "wasm32")] pub(crate) async fn initialize() -> Barretenberg { let (instance, memory, store) = instance_load().await; - Barretenberg { memory, instance, store: RefCell::new(store) } + let barretenberg = Barretenberg { memory, instance, store: RefCell::new(store) }; + barretenberg.call_wasi_initialize(); + barretenberg + } + /// Call initialization function for WASI, to initialize all of the appropriate + /// globals. + fn call_wasi_initialize(&self) { + self.call_multiple("_initialize", vec![]) + .expect("expected call to WASI initialization function to not fail"); } }