Skip to content

Commit

Permalink
chore: simplify how acvm_backend.wasm is embedded (#4703)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

We only need a single file to be embedded into `bn254_blackbox_solver`
so we don't need the overhead of `rust_embed`. We can instead just
assign the bytes to a const variable.

I've also removed some build dependencies which are unnecessary.


## Additional Context



## Documentation\*

Check one:
- [ ] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [ ] I have tested the changes locally.
- [ ] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench authored Apr 3, 2024
1 parent 8fea405 commit 68f9eeb
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 57 deletions.
16 changes: 0 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 2 additions & 18 deletions acvm-repo/bn254_blackbox_solver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,8 @@ thiserror.workspace = true
num-traits.workspace = true
cfg-if = "1.0.0"

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
Expand All @@ -45,15 +38,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"]
14 changes: 0 additions & 14 deletions acvm-repo/bn254_blackbox_solver/build.rs

This file was deleted.

13 changes: 4 additions & 9 deletions acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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)
}
Expand All @@ -299,17 +296,15 @@ 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();

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::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();
Expand Down

0 comments on commit 68f9eeb

Please sign in to comment.