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: remove conditional compilation around acvm_js package #4702

Merged
merged 2 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
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
Loading