Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
fix: Add WASI 20 _initialize call to acvm_backend.wasm binary (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray authored Sep 3, 2023
1 parent 1e5dcf0 commit ec6ab0c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
26 changes: 26 additions & 0 deletions acvm_js/test/node/execute_circuit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
2 changes: 1 addition & 1 deletion blackbox_solver/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
14 changes: 12 additions & 2 deletions blackbox_solver/src/barretenberg/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down

0 comments on commit ec6ab0c

Please sign in to comment.