Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simplify how acvm_backend.wasm is embedded #4703

Merged
merged 5 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@ -242,7 +239,7 @@

/// Creates a pointer and allocates the bytes that the pointer references to, to the heap
pub(crate) fn allocate(&self, bytes: &[u8]) -> Result<WASMValue, Error> {
let ptr: i32 = self.call("bbmalloc", &bytes.len().into())?.try_into()?;

Check warning on line 242 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (bbmalloc)

let i32_bytes = ptr.to_be_bytes();
let u32_bytes = u32::from_be_bytes(i32_bytes);
Expand All @@ -261,10 +258,10 @@
let function_env = FunctionEnv::new(&mut store, memory.clone());
let custom_imports = imports! {
"env" => {
"logstr" => Function::new_typed_with_env(

Check warning on line 261 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (logstr)
&mut store,
&function_env,
logstr,

Check warning on line 264 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (logstr)
),
"memory" => memory.clone(),
},
Expand All @@ -287,7 +284,7 @@

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,25 +296,23 @@

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());

Check warning on line 305 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (jsvalue)
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)

Check warning on line 308 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (jsvalue)
.map_err(|_| "Error while creating BlackBox Functions vendor instance")
.unwrap();

(instance, memory, store)
}

fn logstr(mut env: FunctionEnvMut<Memory>, ptr: i32) {

Check warning on line 315 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (logstr)
let (memory, store) = env.data_and_store_mut();
let memory_view = memory.view(&store);

Expand All @@ -339,7 +334,7 @@
let memory_view = memory.view(&store);
match memory_view.write(buf_ptr as u64, u8_buffer.as_mut_slice()) {
Ok(_) => {
0_i32 // __WASI_ESUCCESS

Check warning on line 337 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (ESUCCESS)
}
Err(_) => {
29_i32 // __WASI_EIO
Expand Down
Loading