From f18f4a41b6c4e036e77a62f254758e8ed7e9539f Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 31 Aug 2023 17:48:10 +0100 Subject: [PATCH 1/2] chore: remove dead code --- crates/acvm_backend_barretenberg/src/lib.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/crates/acvm_backend_barretenberg/src/lib.rs b/crates/acvm_backend_barretenberg/src/lib.rs index 46867a6aeb4..76f465ceb42 100644 --- a/crates/acvm_backend_barretenberg/src/lib.rs +++ b/crates/acvm_backend_barretenberg/src/lib.rs @@ -1,18 +1,6 @@ #![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; From f0212d343406e76b0f5779da643adec2fc1d0913 Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 31 Aug 2023 22:41:12 +0100 Subject: [PATCH 2/2] chore: remove `FIELD_BYTES` constant --- crates/acvm_backend_barretenberg/src/lib.rs | 3 --- .../acvm_backend_barretenberg/src/proof_system.rs | 14 ++++++-------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/crates/acvm_backend_barretenberg/src/lib.rs b/crates/acvm_backend_barretenberg/src/lib.rs index 76f465ceb42..704d2b4c7b0 100644 --- a/crates/acvm_backend_barretenberg/src/lib.rs +++ b/crates/acvm_backend_barretenberg/src/lib.rs @@ -5,9 +5,6 @@ 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() }