diff --git a/Cargo.lock b/Cargo.lock index 9df51775bda..88237d6b6d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,42 +5,19 @@ version = 3 [[package]] name = "acir" version = "0.11.0" -source = "git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310#018d6865e03ddd09ed409b383f38971ec9ec3310" +source = "git+https://github.com/noir-lang/acvm?rev=bbd9ab7ca5be3fb31f3e141fee2522704852f5de#bbd9ab7ca5be3fb31f3e141fee2522704852f5de" dependencies = [ - "acir_field 0.11.0 (git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310)", + "acir_field", "flate2", "rmp-serde", "serde", -] - -[[package]] -name = "acir" -version = "0.11.0" -source = "git+https://github.com/noir-lang/acvm?rev=a83333b9e270dfcfd40a36271896840ec0201bc4#a83333b9e270dfcfd40a36271896840ec0201bc4" -dependencies = [ - "acir_field 0.11.0 (git+https://github.com/noir-lang/acvm?rev=a83333b9e270dfcfd40a36271896840ec0201bc4)", - "flate2", - "rmp-serde", - "serde", -] - -[[package]] -name = "acir_field" -version = "0.11.0" -source = "git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310#018d6865e03ddd09ed409b383f38971ec9ec3310" -dependencies = [ - "ark-bn254", - "ark-ff", - "cfg-if 1.0.0", - "hex", - "num-bigint", - "serde", + "thiserror", ] [[package]] name = "acir_field" version = "0.11.0" -source = "git+https://github.com/noir-lang/acvm?rev=a83333b9e270dfcfd40a36271896840ec0201bc4#a83333b9e270dfcfd40a36271896840ec0201bc4" +source = "git+https://github.com/noir-lang/acvm?rev=bbd9ab7ca5be3fb31f3e141fee2522704852f5de#bbd9ab7ca5be3fb31f3e141fee2522704852f5de" dependencies = [ "ark-bn254", "ark-ff", @@ -53,28 +30,10 @@ dependencies = [ [[package]] name = "acvm" version = "0.11.0" -source = "git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310#018d6865e03ddd09ed409b383f38971ec9ec3310" +source = "git+https://github.com/noir-lang/acvm?rev=bbd9ab7ca5be3fb31f3e141fee2522704852f5de#bbd9ab7ca5be3fb31f3e141fee2522704852f5de" dependencies = [ - "acir 0.11.0 (git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310)", - "acvm_stdlib 0.11.0 (git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310)", - "blake2", - "crc32fast", - "indexmap", - "k256", - "num-bigint", - "num-traits", - "sha2 0.10.6", - "sha3", - "thiserror", -] - -[[package]] -name = "acvm" -version = "0.11.0" -source = "git+https://github.com/noir-lang/acvm?rev=a83333b9e270dfcfd40a36271896840ec0201bc4#a83333b9e270dfcfd40a36271896840ec0201bc4" -dependencies = [ - "acir 0.11.0 (git+https://github.com/noir-lang/acvm?rev=a83333b9e270dfcfd40a36271896840ec0201bc4)", - "acvm_stdlib 0.11.0 (git+https://github.com/noir-lang/acvm?rev=a83333b9e270dfcfd40a36271896840ec0201bc4)", + "acir", + "acvm_stdlib", "blake2", "crc32fast", "indexmap", @@ -89,9 +48,9 @@ dependencies = [ [[package]] name = "acvm-backend-barretenberg" version = "0.1.2" -source = "git+https://github.com/noir-lang/acvm-backend-barretenberg?rev=a97dc35affc33db015a0f84f7e0e22dd143ac558#a97dc35affc33db015a0f84f7e0e22dd143ac558" +source = "git+https://github.com/noir-lang/acvm-backend-barretenberg?rev=4f622b58144330ebc53d8458bd9e456a8efb147c#4f622b58144330ebc53d8458bd9e456a8efb147c" dependencies = [ - "acvm 0.11.0 (git+https://github.com/noir-lang/acvm?rev=a83333b9e270dfcfd40a36271896840ec0201bc4)", + "acvm", "barretenberg-sys", "dirs 3.0.2", "futures-util", @@ -108,17 +67,9 @@ dependencies = [ [[package]] name = "acvm_stdlib" version = "0.11.0" -source = "git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310#018d6865e03ddd09ed409b383f38971ec9ec3310" -dependencies = [ - "acir 0.11.0 (git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310)", -] - -[[package]] -name = "acvm_stdlib" -version = "0.11.0" -source = "git+https://github.com/noir-lang/acvm?rev=a83333b9e270dfcfd40a36271896840ec0201bc4#a83333b9e270dfcfd40a36271896840ec0201bc4" +source = "git+https://github.com/noir-lang/acvm?rev=bbd9ab7ca5be3fb31f3e141fee2522704852f5de#bbd9ab7ca5be3fb31f3e141fee2522704852f5de" dependencies = [ - "acir 0.11.0 (git+https://github.com/noir-lang/acvm?rev=a83333b9e270dfcfd40a36271896840ec0201bc4)", + "acir", ] [[package]] @@ -1885,7 +1836,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" name = "nargo" version = "0.5.1" dependencies = [ - "acvm 0.11.0 (git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310)", + "acvm", "iter-extended", "noirc_abi", "noirc_driver", @@ -1899,7 +1850,7 @@ dependencies = [ name = "nargo_cli" version = "0.5.1" dependencies = [ - "acvm 0.11.0 (git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310)", + "acvm", "acvm-backend-barretenberg", "assert_cmd", "assert_fs", @@ -1930,7 +1881,7 @@ dependencies = [ name = "noir_wasm" version = "0.5.1" dependencies = [ - "acvm 0.11.0 (git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310)", + "acvm", "build-data", "console_error_panic_hook", "gloo-utils", @@ -1946,7 +1897,7 @@ dependencies = [ name = "noirc_abi" version = "0.5.1" dependencies = [ - "acvm 0.11.0 (git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310)", + "acvm", "iter-extended", "serde", "serde_json", @@ -1960,7 +1911,7 @@ dependencies = [ name = "noirc_driver" version = "0.5.1" dependencies = [ - "acvm 0.11.0 (git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310)", + "acvm", "clap", "fm", "iter-extended", @@ -1986,7 +1937,7 @@ dependencies = [ name = "noirc_evaluator" version = "0.5.1" dependencies = [ - "acvm 0.11.0 (git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310)", + "acvm", "arena", "iter-extended", "noirc_abi", @@ -2002,7 +1953,7 @@ dependencies = [ name = "noirc_frontend" version = "0.5.1" dependencies = [ - "acvm 0.11.0 (git+https://github.com/noir-lang/acvm?rev=018d6865e03ddd09ed409b383f38971ec9ec3310)", + "acvm", "arena", "chumsky", "fm", diff --git a/Cargo.toml b/Cargo.toml index 408edb3b715..4563a629043 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,8 +24,7 @@ edition = "2021" rust-version = "1.66" [workspace.dependencies] -#acvm = "0.11.0" -acvm = { git = "https://github.com/noir-lang/acvm", rev = "018d6865e03ddd09ed409b383f38971ec9ec3310" } +acvm = "0.11.0" arena = { path = "crates/arena" } fm = { path = "crates/fm" } iter-extended = { path = "crates/iter-extended" } @@ -53,5 +52,5 @@ wasm-bindgen = { version = "0.2.83", features = ["serde-serialize"] } wasm-bindgen-test = "0.3.33" [patch.crates-io] -acvm = { package = "acvm", git = "https://github.com/noir-lang/acvm", rev = "a83333b9e270dfcfd40a36271896840ec0201bc4" } -acvm-backend-barretenberg = { git = "https://github.com/noir-lang/acvm-backend-barretenberg", rev = "a97dc35affc33db015a0f84f7e0e22dd143ac558" } +acvm = { package = "acvm", git = "https://github.com/noir-lang/acvm", rev = "bbd9ab7ca5be3fb31f3e141fee2522704852f5de" } +acvm-backend-barretenberg = { git = "https://github.com/noir-lang/acvm-backend-barretenberg", rev = "4f622b58144330ebc53d8458bd9e456a8efb147c" } diff --git a/crates/nargo/src/ops/execute.rs b/crates/nargo/src/ops/execute.rs index 04f3501d211..a46c440c76c 100644 --- a/crates/nargo/src/ops/execute.rs +++ b/crates/nargo/src/ops/execute.rs @@ -1,7 +1,6 @@ use acvm::pwg::{solve, PartialWitnessGeneratorStatus}; use acvm::PartialWitnessGenerator; -use acvm::{acir::circuit::Circuit, pwg::block::Blocks}; -use noirc_abi::WitnessMap; +use acvm::{acir::circuit::Circuit, acir::native_types::WitnessMap, pwg::block::Blocks}; use crate::NargoError; diff --git a/crates/nargo/src/ops/prove.rs b/crates/nargo/src/ops/prove.rs index 80771bc9cb7..523b2ed5ed4 100644 --- a/crates/nargo/src/ops/prove.rs +++ b/crates/nargo/src/ops/prove.rs @@ -1,6 +1,5 @@ -use acvm::acir::circuit::Circuit; +use acvm::acir::{circuit::Circuit, native_types::WitnessMap}; use acvm::ProofSystemCompiler; -use noirc_abi::WitnessMap; pub fn prove_execution( backend: &B, diff --git a/crates/nargo/src/ops/verify.rs b/crates/nargo/src/ops/verify.rs index cd76fbd430e..f2145e3cf87 100644 --- a/crates/nargo/src/ops/verify.rs +++ b/crates/nargo/src/ops/verify.rs @@ -1,6 +1,5 @@ -use acvm::acir::circuit::Circuit; +use acvm::acir::{circuit::Circuit, native_types::WitnessMap}; use acvm::ProofSystemCompiler; -use noirc_abi::WitnessMap; pub fn verify_proof( backend: &B, diff --git a/crates/nargo_cli/src/cli/execute_cmd.rs b/crates/nargo_cli/src/cli/execute_cmd.rs index 855fea04cb3..61e709ce500 100644 --- a/crates/nargo_cli/src/cli/execute_cmd.rs +++ b/crates/nargo_cli/src/cli/execute_cmd.rs @@ -1,10 +1,10 @@ use std::path::Path; -use acvm::acir::circuit::Circuit; +use acvm::acir::{circuit::Circuit, native_types::WitnessMap}; use acvm::Backend; use clap::Args; use noirc_abi::input_parser::{Format, InputValue}; -use noirc_abi::{Abi, InputMap, WitnessMap}; +use noirc_abi::{Abi, InputMap}; use noirc_driver::{CompileOptions, CompiledProgram}; use super::fs::{inputs::read_inputs_from_file, witness::save_witness_to_dir}; diff --git a/crates/nargo_cli/src/cli/fs/witness.rs b/crates/nargo_cli/src/cli/fs/witness.rs index d41123e74fa..3b2ca2aab9f 100644 --- a/crates/nargo_cli/src/cli/fs/witness.rs +++ b/crates/nargo_cli/src/cli/fs/witness.rs @@ -1,7 +1,6 @@ use std::path::{Path, PathBuf}; -use acvm::acir::native_types::Witness; -use noirc_abi::WitnessMap; +use acvm::acir::native_types::WitnessMap; use super::{create_named_dir, write_to_file}; use crate::{constants::WITNESS_EXT, errors::FilesystemError}; @@ -14,7 +13,7 @@ pub(crate) fn save_witness_to_dir>( create_named_dir(witness_dir.as_ref(), "witness"); let witness_path = witness_dir.as_ref().join(witness_name).with_extension(WITNESS_EXT); - let buf = Witness::to_bytes(&witness); + let buf: Vec = witness.try_into()?; write_to_file(buf.as_slice(), &witness_path); diff --git a/crates/nargo_cli/src/cli/test_cmd.rs b/crates/nargo_cli/src/cli/test_cmd.rs index 139d33b6c3d..16857f4b3a1 100644 --- a/crates/nargo_cli/src/cli/test_cmd.rs +++ b/crates/nargo_cli/src/cli/test_cmd.rs @@ -1,6 +1,6 @@ -use std::{collections::BTreeMap, io::Write, path::Path}; +use std::{io::Write, path::Path}; -use acvm::Backend; +use acvm::{acir::native_types::WitnessMap, Backend}; use clap::Args; use nargo::ops::execute_circuit; use noirc_driver::{CompileOptions, Driver}; @@ -89,7 +89,7 @@ fn run_test( // Run the backend to ensure the PWG evaluates functions like std::hash::pedersen, // otherwise constraints involving these expressions will not error. - match execute_circuit(backend, program.circuit, BTreeMap::new()) { + match execute_circuit(backend, program.circuit, WitnessMap::new()) { Ok(_) => Ok(()), Err(error) => { let writer = StandardStream::stderr(ColorChoice::Always); diff --git a/crates/nargo_cli/src/errors.rs b/crates/nargo_cli/src/errors.rs index 15d1917a5d6..94772b578b4 100644 --- a/crates/nargo_cli/src/errors.rs +++ b/crates/nargo_cli/src/errors.rs @@ -1,4 +1,4 @@ -use acvm::{Backend, ProofSystemCompiler, SmartContract}; +use acvm::{acir::native_types::WitnessMapError, Backend, ProofSystemCompiler, SmartContract}; use hex::FromHexError; use nargo::NargoError; use noirc_abi::errors::{AbiError, InputParserError}; @@ -21,6 +21,10 @@ pub(crate) enum FilesystemError { /// Input parsing error #[error(transparent)] InputParserError(#[from] InputParserError), + + /// WitnessMap serialization error + #[error(transparent)] + WitnessMapSerialization(#[from] WitnessMapError), } #[derive(Debug, Error)] diff --git a/crates/noirc_abi/src/lib.rs b/crates/noirc_abi/src/lib.rs index 191128b9407..56ed3728527 100644 --- a/crates/noirc_abi/src/lib.rs +++ b/crates/noirc_abi/src/lib.rs @@ -5,7 +5,10 @@ use std::{collections::BTreeMap, str}; -use acvm::{acir::native_types::Witness, FieldElement}; +use acvm::{ + acir::native_types::{Witness, WitnessMap}, + FieldElement, +}; use errors::AbiError; use input_parser::InputValue; use iter_extended::{try_btree_map, try_vecmap, vecmap}; @@ -22,9 +25,6 @@ mod serialization; /// A map from the fields in an TOML/JSON file which correspond to some ABI to their values pub type InputMap = BTreeMap; -/// A map from the witnesses in a constraint system to the field element values -pub type WitnessMap = BTreeMap; - /// A tuple of the arguments to a function along with its return value. pub type FunctionSignature = (Vec, Option); @@ -254,7 +254,7 @@ impl Abi { .collect::>()?; // Write input field elements into witness indices specified in `self.param_witnesses`. - let mut witness_map: WitnessMap = encoded_input_map + let mut witness_map: BTreeMap = encoded_input_map .iter() .flat_map(|(param_name, encoded_param_fields)| { let param_witness_indices = &self.param_witnesses[param_name]; @@ -297,7 +297,7 @@ impl Abi { (_, None) => {} } - Ok(witness_map) + Ok(witness_map.into()) } fn encode_value(value: InputValue) -> Result, AbiError> { diff --git a/crates/noirc_evaluator/src/ssa/acir_gen/operations/sort.rs b/crates/noirc_evaluator/src/ssa/acir_gen/operations/sort.rs index d85182f1387..ccea9caac4c 100644 --- a/crates/noirc_evaluator/src/ssa/acir_gen/operations/sort.rs +++ b/crates/noirc_evaluator/src/ssa/acir_gen/operations/sort.rs @@ -113,10 +113,8 @@ fn permutation_layer( #[cfg(test)] mod test { - use std::collections::BTreeMap; - use acvm::{ - acir::{circuit::opcodes::FunctionInput, native_types::Witness}, + acir::{circuit::opcodes::FunctionInput, native_types::Witness, native_types::WitnessMap}, pwg::{block::Blocks, solve, OpcodeResolution, PartialWitnessGeneratorStatus}, FieldElement, OpcodeResolutionError, PartialWitnessGenerator, }; @@ -131,7 +129,7 @@ mod test { impl PartialWitnessGenerator for MockBackend { fn aes( &self, - _initial_witness: &mut BTreeMap, + _initial_witness: &mut WitnessMap, _inputs: &[FunctionInput], _outputs: &[Witness], ) -> Result { @@ -139,7 +137,7 @@ mod test { } fn and( &self, - _initial_witness: &mut BTreeMap, + _initial_witness: &mut WitnessMap, _lhs: &FunctionInput, _rhs: &FunctionInput, _output: &Witness, @@ -148,7 +146,7 @@ mod test { } fn xor( &self, - _initial_witness: &mut BTreeMap, + _initial_witness: &mut WitnessMap, _lhs: &FunctionInput, _rhs: &FunctionInput, _output: &Witness, @@ -157,14 +155,14 @@ mod test { } fn range( &self, - _initial_witness: &mut BTreeMap, + _initial_witness: &mut WitnessMap, _input: &FunctionInput, ) -> Result { panic!("Path not trodden by this test") } fn sha256( &self, - _initial_witness: &mut BTreeMap, + _initial_witness: &mut WitnessMap, _inputs: &[FunctionInput], _outputs: &[Witness], ) -> Result { @@ -172,7 +170,7 @@ mod test { } fn blake2s( &self, - _initial_witness: &mut BTreeMap, + _initial_witness: &mut WitnessMap, _inputs: &[FunctionInput], _outputs: &[Witness], ) -> Result { @@ -180,7 +178,7 @@ mod test { } fn compute_merkle_root( &self, - _initial_witness: &mut BTreeMap, + _initial_witness: &mut WitnessMap, _leaf: &FunctionInput, _index: &FunctionInput, _hash_path: &[FunctionInput], @@ -190,7 +188,7 @@ mod test { } fn schnorr_verify( &self, - _initial_witness: &mut BTreeMap, + _initial_witness: &mut WitnessMap, _public_key_x: &FunctionInput, _public_key_y: &FunctionInput, _signature: &[FunctionInput], @@ -201,7 +199,7 @@ mod test { } fn pedersen( &self, - _initial_witness: &mut BTreeMap, + _initial_witness: &mut WitnessMap, _inputs: &[FunctionInput], _outputs: &[Witness], ) -> Result { @@ -209,7 +207,7 @@ mod test { } fn hash_to_field_128_security( &self, - _initial_witness: &mut BTreeMap, + _initial_witness: &mut WitnessMap, _inputs: &[FunctionInput], _output: &Witness, ) -> Result { @@ -217,7 +215,7 @@ mod test { } fn ecdsa_secp256k1( &self, - _initial_witness: &mut BTreeMap, + _initial_witness: &mut WitnessMap, _public_key_x: &[FunctionInput], _public_key_y: &[FunctionInput], _signature: &[FunctionInput], @@ -228,7 +226,7 @@ mod test { } fn fixed_base_scalar_mul( &self, - _initial_witness: &mut BTreeMap, + _initial_witness: &mut WitnessMap, _input: &FunctionInput, _outputs: &[Witness], ) -> Result { @@ -236,7 +234,7 @@ mod test { } fn keccak256( &self, - _initial_witness: &mut BTreeMap, + _initial_witness: &mut WitnessMap, _inputs: &[FunctionInput], _outputs: &[Witness], ) -> Result { @@ -255,7 +253,7 @@ mod test { let mut input = Vec::new(); let mut a_val = Vec::new(); let mut b_wit = Vec::new(); - let mut solved_witness: BTreeMap = BTreeMap::new(); + let mut solved_witness = WitnessMap::new(); for i in 0..n { let w = eval.add_witness_to_cs(); input.push(w.into());