From ebb5839838d5901440192d505d36ec00ac0af65c Mon Sep 17 00:00:00 2001 From: Tom French Date: Wed, 3 Apr 2024 11:25:53 +0100 Subject: [PATCH 1/3] chore: simplify how `acvm_backend.wasm` is embedded --- Cargo.lock | 16 -------------- acvm-repo/bn254_blackbox_solver/Cargo.toml | 20 ++---------------- acvm-repo/bn254_blackbox_solver/build.rs | 14 ------------ .../src/{ => wasm}/acvm_backend.wasm | Bin .../bn254_blackbox_solver/src/wasm/mod.rs | 13 ++++-------- 5 files changed, 6 insertions(+), 57 deletions(-) delete mode 100644 acvm-repo/bn254_blackbox_solver/build.rs rename acvm-repo/bn254_blackbox_solver/src/{ => wasm}/acvm_backend.wasm (100%) diff --git a/Cargo.lock b/Cargo.lock index 2f85b26f974..61672e81338 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -606,16 +606,11 @@ dependencies = [ "acvm_blackbox_solver", "ark-ec", "ark-ff", - "flate2", "getrandom 0.2.10", "js-sys", "noir_grumpkin", "num-bigint", "num-traits", - "pkg-config", - "reqwest", - "rust-embed", - "tar", "thiserror", "wasm-bindgen-futures", "wasmer", @@ -4037,7 +4032,6 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "shellexpand", "syn 2.0.32", "walkdir", ] @@ -4048,7 +4042,6 @@ version = "7.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d38ff6bf570dc3bb7100fce9f7b60c33fa71d80e88da3f2580df4ff2bdded74" dependencies = [ - "globset", "sha2", "walkdir", ] @@ -4469,15 +4462,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" -[[package]] -name = "shellexpand" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" -dependencies = [ - "dirs", -] - [[package]] name = "signature" version = "1.6.4" diff --git a/acvm-repo/bn254_blackbox_solver/Cargo.toml b/acvm-repo/bn254_blackbox_solver/Cargo.toml index 396e4aa0146..2d64de24b19 100644 --- a/acvm-repo/bn254_blackbox_solver/Cargo.toml +++ b/acvm-repo/bn254_blackbox_solver/Cargo.toml @@ -18,15 +18,8 @@ acvm_blackbox_solver.workspace = true thiserror.workspace = true num-traits.workspace = true -rust-embed = { version = "6.6.0", features = [ - "debug-embed", - "interpolate-folder-path", - "include-exclude", -] } - -grumpkin = { version = "0.1.0", package = "noir_grumpkin", features = [ - "std", -] } # BN254 fixed base scalar multiplication solver +# BN254 fixed base scalar multiplication solver +grumpkin = { version = "0.1.0", package = "noir_grumpkin", features = ["std"] } ark-ec = { version = "^0.4.0", default-features = false } ark-ff = { version = "^0.4.0", default-features = false } num-bigint.workspace = true @@ -44,15 +37,6 @@ js-sys.workspace = true getrandom.workspace = true wasmer = "4.2.6" -[build-dependencies] -pkg-config = "0.3" -tar = "~0.4.15" -flate2 = "~1.0.1" -reqwest = { version = "0.11.20", default-features = false, features = [ - "rustls-tls", - "blocking", -] } - [features] default = ["bn254"] bn254 = ["acir/bn254"] diff --git a/acvm-repo/bn254_blackbox_solver/build.rs b/acvm-repo/bn254_blackbox_solver/build.rs deleted file mode 100644 index 4269c86aba0..00000000000 --- a/acvm-repo/bn254_blackbox_solver/build.rs +++ /dev/null @@ -1,14 +0,0 @@ -use std::path::PathBuf; - -const BARRETENBERG_BIN_DIR: &str = "BARRETENBERG_BIN_DIR"; - -fn main() -> Result<(), String> { - let out_dir = std::env::var("OUT_DIR").unwrap(); - - let dest_path = PathBuf::from(out_dir.clone()).join("acvm_backend.wasm"); - - println!("cargo:rustc-env={BARRETENBERG_BIN_DIR}={out_dir}"); - std::fs::copy("./src/acvm_backend.wasm", dest_path).unwrap(); - - Ok(()) -} diff --git a/acvm-repo/bn254_blackbox_solver/src/acvm_backend.wasm b/acvm-repo/bn254_blackbox_solver/src/wasm/acvm_backend.wasm similarity index 100% rename from acvm-repo/bn254_blackbox_solver/src/acvm_backend.wasm rename to acvm-repo/bn254_blackbox_solver/src/wasm/acvm_backend.wasm diff --git a/acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs b/acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs index 3c867ae48dd..7cc849b3146 100644 --- a/acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs +++ b/acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs @@ -76,10 +76,7 @@ use wasmer::{ pub(super) const WASM_SCRATCH_BYTES: usize = 1024; /// Embed the Barretenberg WASM file -#[derive(rust_embed::RustEmbed)] -#[folder = "$BARRETENBERG_BIN_DIR"] -#[include = "acvm_backend.wasm"] -struct Wasm; +const WASM_BIN: &[u8] = include_bytes!("./acvm_backend.wasm"); impl Barretenberg { #[cfg(not(target_arch = "wasm32"))] @@ -287,7 +284,7 @@ fn instance_load() -> (Instance, Memory, Store) { let (memory, mut store, custom_imports) = init_memory_and_state(); - let module = Module::new(&store, Wasm::get("acvm_backend.wasm").unwrap().data).unwrap(); + let module = Module::new(&store, WASM_BIN).unwrap(); (Instance::new(&mut store, &module, &custom_imports).unwrap(), memory, store) } @@ -299,9 +296,7 @@ async fn instance_load() -> (Instance, Memory, Store) { let (memory, mut store, custom_imports) = init_memory_and_state(); - let wasm_binary = Wasm::get("acvm_backend.wasm").unwrap().data; - - let js_bytes = unsafe { js_sys::Uint8Array::view(&wasm_binary) }; + let js_bytes = unsafe { js_sys::Uint8Array::view(&WASM_BIN) }; let js_module_promise = WebAssembly::compile(&js_bytes); let js_module: js_sys::WebAssembly::Module = wasm_bindgen_futures::JsFuture::from(js_module_promise).await.unwrap().into(); @@ -309,7 +304,7 @@ async fn instance_load() -> (Instance, Memory, Store) { let js_instance_promise = WebAssembly::instantiate_module(&js_module, &custom_imports.as_jsvalue(&store).into()); let js_instance = wasm_bindgen_futures::JsFuture::from(js_instance_promise).await.unwrap(); - let module: wasmer::Module = (js_module, wasm_binary).into(); + let module: wasmer::Module = (js_module, WASM_BIN).into(); let instance: wasmer::Instance = Instance::from_jsvalue(&mut store, &module, &js_instance) .map_err(|_| "Error while creating BlackBox Functions vendor instance") .unwrap(); From 66b47c1ce5e0a35da6ab5883d6ef97c7347d0594 Mon Sep 17 00:00:00 2001 From: Tom French Date: Wed, 3 Apr 2024 11:29:03 +0100 Subject: [PATCH 2/3] chore: nit --- acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs b/acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs index 7cc849b3146..f4f6f56aa99 100644 --- a/acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs +++ b/acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs @@ -304,7 +304,7 @@ async fn instance_load() -> (Instance, Memory, Store) { let js_instance_promise = WebAssembly::instantiate_module(&js_module, &custom_imports.as_jsvalue(&store).into()); let js_instance = wasm_bindgen_futures::JsFuture::from(js_instance_promise).await.unwrap(); - let module: wasmer::Module = (js_module, WASM_BIN).into(); + let module = wasmer::Module::from((js_module, WASM_BIN)); let instance: wasmer::Instance = Instance::from_jsvalue(&mut store, &module, &js_instance) .map_err(|_| "Error while creating BlackBox Functions vendor instance") .unwrap(); From 2e2cacd2f04f41bc785abf326024f4063321ce72 Mon Sep 17 00:00:00 2001 From: Tom French Date: Wed, 3 Apr 2024 13:46:31 +0100 Subject: [PATCH 3/3] chore: update lockfile --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index 49cf8263634..906e49df6ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -605,6 +605,7 @@ dependencies = [ "acvm_blackbox_solver", "ark-ec", "ark-ff", + "cfg-if 1.0.0", "getrandom 0.2.10", "js-sys", "noir_grumpkin",