Skip to content

Commit

Permalink
chore: remove conditional compilation around acvm_js package (#4702)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

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

## Summary\*

We previously had acvm_js wrapped in a big conditional compilation
statement which shortcircuited it if it wasn't building for a wasm
architecture.

This isn't ideal as it prevents a lot of IDE LSP features from working
and it shouldn't be necessary (as shown by the other wasm packages).
I've then removed this and fixed any issues caused as a result.

## Additional Context



## Documentation\*

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

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench committed Apr 3, 2024
1 parent 07af567 commit a6c2c9f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

7 changes: 2 additions & 5 deletions acvm-repo/acvm_js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@ repository.workspace = true
crate-type = ["cdylib"]

[dependencies]
cfg-if = "1.0.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
acvm.workspace = true
bn254_blackbox_solver = { workspace = true, optional = true }
wasm-bindgen.workspace = true
wasm-bindgen-futures.workspace = true
console_error_panic_hook.workspace = true
gloo-utils.workspace = true
js-sys.workspace = true
js-sys.workspace = true
serde.workspace = true
tracing-subscriber.workspace = true
tracing-web.workspace = true

serde = { version = "1.0.136", features = ["derive"] }
const-str = "0.5.5"

[build-dependencies]
Expand Down
2 changes: 0 additions & 2 deletions acvm-repo/acvm_js/src/black_box_solvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub fn ecdsa_secp256k1_verify(
signature,
)
.unwrap()
.into()
}

/// Verifies a ECDSA signature over the secp256r1 curve.
Expand All @@ -81,5 +80,4 @@ pub fn ecdsa_secp256r1_verify(
signature,
)
.unwrap()
.into()
}
2 changes: 1 addition & 1 deletion acvm-repo/acvm_js/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub async fn execute_circuit_with_black_box_solver(
None => error.to_string(),
};

return Err(JsExecutionError::new(error_string.into(), call_stack).into());
return Err(JsExecutionError::new(error_string, call_stack).into());
}
ACVMStatus::RequiresForeignCall(foreign_call) => {
let result = resolve_brillig(&foreign_call_handler, &foreign_call).await?;
Expand Down
47 changes: 21 additions & 26 deletions acvm-repo/acvm_js/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

// TODO: Absence of per package targets
// https://doc.rust-lang.org/cargo/reference/unstable.html#per-package-target
// otherwise could be reorganized to make this file more pretty.
mod black_box_solvers;
mod build_info;
mod compression;
mod execute;
mod foreign_call;
mod js_execution_error;
mod js_witness_map;
mod logging;
mod public_witness;

cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
mod build_info;
mod compression;
mod execute;
mod foreign_call;
mod js_witness_map;
mod logging;
mod public_witness;
mod js_execution_error;
mod black_box_solvers;

pub use black_box_solvers::{and, xor, sha256, blake2s256, keccak256, ecdsa_secp256k1_verify, ecdsa_secp256r1_verify};
pub use build_info::build_info;
pub use compression::{compress_witness, decompress_witness};
pub use execute::{execute_circuit, execute_circuit_with_black_box_solver, create_black_box_solver};
pub use js_witness_map::JsWitnessMap;
pub use logging::init_log_level;
pub use public_witness::{get_public_parameters_witness, get_public_witness, get_return_witness};
pub use js_execution_error::JsExecutionError;
}
}
pub use black_box_solvers::{
and, blake2s256, ecdsa_secp256k1_verify, ecdsa_secp256r1_verify, keccak256, sha256, xor,
};
pub use build_info::build_info;
pub use compression::{compress_witness, decompress_witness};
pub use execute::{
create_black_box_solver, execute_circuit, execute_circuit_with_black_box_solver,
};
pub use js_execution_error::JsExecutionError;
pub use js_witness_map::JsWitnessMap;
pub use logging::init_log_level;
pub use public_witness::{get_public_parameters_witness, get_public_witness, get_return_witness};
1 change: 1 addition & 0 deletions acvm-repo/bn254_blackbox_solver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ acir.workspace = true
acvm_blackbox_solver.workspace = true
thiserror.workspace = true
num-traits.workspace = true
cfg-if = "1.0.0"

rust-embed = { version = "6.6.0", features = [
"debug-embed",
Expand Down
13 changes: 10 additions & 3 deletions acvm-repo/bn254_blackbox_solver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ pub struct Bn254BlackBoxSolver {
}

impl Bn254BlackBoxSolver {
#[cfg(target_arch = "wasm32")]
pub async fn initialize() -> Bn254BlackBoxSolver {
let blackbox_vendor = Barretenberg::initialize().await;
Bn254BlackBoxSolver { blackbox_vendor }
// We fallback to the sync initialization of barretenberg on non-wasm targets.
// This ensures that wasm packages consuming this still build on the default target (useful for linting, etc.)
cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] {
let blackbox_vendor = Barretenberg::initialize().await;
Bn254BlackBoxSolver { blackbox_vendor }
} else {
Bn254BlackBoxSolver::new()
}
}
}

#[cfg(not(target_arch = "wasm32"))]
Expand Down

0 comments on commit a6c2c9f

Please sign in to comment.