From cb2f2ebf5d8d78d54ebdb18db3c4f72b1031d9a9 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Thu, 31 Aug 2023 17:32:59 +0100 Subject: [PATCH 1/2] chore: only install `tokio-util` dependency on windows (#2425) --- crates/nargo_cli/Cargo.toml | 4 +++- crates/nargo_cli/src/main.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/nargo_cli/Cargo.toml b/crates/nargo_cli/Cargo.toml index da3eac653c5..e10fde13d7b 100644 --- a/crates/nargo_cli/Cargo.toml +++ b/crates/nargo_cli/Cargo.toml @@ -46,11 +46,13 @@ hex = "0.4.2" termcolor = "1.1.2" color-eyre = "0.6.2" tokio = { version = "1.0", features = ["io-std"] } -tokio-util = { version = "0.7.8", features = ["compat"] } # Backends acvm-backend-barretenberg = { path = "../acvm_backend_barretenberg" } +[target.'cfg(not(unix))'.dependencies] +tokio-util = { version = "0.7.8", features = ["compat"] } + [dev-dependencies] tempdir = "0.3.7" assert_cmd = "2.0.8" diff --git a/crates/nargo_cli/src/main.rs b/crates/nargo_cli/src/main.rs index 734dbdca2e7..f4d1e1862fc 100644 --- a/crates/nargo_cli/src/main.rs +++ b/crates/nargo_cli/src/main.rs @@ -1,7 +1,7 @@ #![forbid(unsafe_code)] -#![warn(unused_extern_crates)] #![warn(unreachable_pub)] #![warn(clippy::semicolon_if_nothing_returned)] +#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))] //! Nargo is the package manager for Noir //! This name was used because it sounds like `cargo` and From 3a7c2e83c837cf0aff92d2fb22f1f3baf88c28d7 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Thu, 31 Aug 2023 23:48:54 +0100 Subject: [PATCH 2/2] chore: Remove dead code from `acvm_backend_barretenberg` (#2512) --- crates/acvm_backend_barretenberg/src/lib.rs | 15 --------------- .../acvm_backend_barretenberg/src/proof_system.rs | 14 ++++++-------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/crates/acvm_backend_barretenberg/src/lib.rs b/crates/acvm_backend_barretenberg/src/lib.rs index 46867a6aeb4..704d2b4c7b0 100644 --- a/crates/acvm_backend_barretenberg/src/lib.rs +++ b/crates/acvm_backend_barretenberg/src/lib.rs @@ -1,25 +1,10 @@ #![warn(unused_crate_dependencies, unused_extern_crates)] #![warn(unreachable_pub)] -// `acvm-backend-barretenberg` can either interact with the Barretenberg backend through a static library -// or through an embedded wasm binary. It does not make sense to include both of these backends at the same time. -// We then throw a compilation error if both flags are set. -#[cfg(all(feature = "native", feature = "wasm"))] -compile_error!("feature \"native\" and feature \"wasm\" cannot be enabled at the same time"); - -#[cfg(all(feature = "native", target_arch = "wasm32"))] -compile_error!("feature \"native\" cannot be enabled for a \"wasm32\" target"); - -#[cfg(all(feature = "wasm", target_arch = "wasm32"))] -compile_error!("feature \"wasm\" cannot be enabled for a \"wasm32\" target"); - mod bb; mod proof_system; mod smart_contract; -/// The number of bytes necessary to store a `FieldElement`. -const FIELD_BYTES: usize = 32; - #[derive(Debug, Default)] pub struct Barretenberg; diff --git a/crates/acvm_backend_barretenberg/src/proof_system.rs b/crates/acvm_backend_barretenberg/src/proof_system.rs index 33ec8457a43..6b5916c7def 100644 --- a/crates/acvm_backend_barretenberg/src/proof_system.rs +++ b/crates/acvm_backend_barretenberg/src/proof_system.rs @@ -9,7 +9,7 @@ use acvm::{Language, ProofSystemCompiler}; use tempfile::tempdir; use crate::bb::{GatesCommand, ProveCommand, VerifyCommand, WriteVkCommand}; -use crate::{BackendError, Barretenberg, FIELD_BYTES}; +use crate::{BackendError, Barretenberg}; impl ProofSystemCompiler for Barretenberg { type Error = BackendError; @@ -76,9 +76,8 @@ impl ProofSystemCompiler for Barretenberg { let temp_dir_path_str = temp_directory.to_str().unwrap(); // Create a temporary file for the witness - let serialized_witnesses: Vec = witness_values - .try_into() - .expect("could not serialize witness map"); + let serialized_witnesses: Vec = + witness_values.try_into().expect("could not serialize witness map"); let witness_path = temp_directory.join("witness").with_extension("tr"); write_to_file(&serialized_witnesses, &witness_path); @@ -222,7 +221,7 @@ pub(super) fn read_bytes_from_file(path: &str) -> std::io::Result> { fn remove_public_inputs(num_pub_inputs: usize, proof: &[u8]) -> Vec { // Barretenberg prepends the public inputs onto the proof so we need to remove // the first `num_pub_inputs` field elements. - let num_bytes_to_remove = num_pub_inputs * FIELD_BYTES; + let num_bytes_to_remove = num_pub_inputs * (FieldElement::max_num_bytes() as usize); proof[num_bytes_to_remove..].to_vec() } @@ -232,9 +231,8 @@ fn prepend_public_inputs(proof: Vec, public_inputs: Vec) -> Ve return proof; } - let public_inputs_bytes = public_inputs - .into_iter() - .flat_map(|assignment| assignment.to_be_bytes()); + let public_inputs_bytes = + public_inputs.into_iter().flat_map(|assignment| assignment.to_be_bytes()); public_inputs_bytes.chain(proof.into_iter()).collect() }