Skip to content

Commit

Permalink
feat!: Move WitnessMap type into ACVM to avoid leaking BTreeMap type
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed May 15, 2023
1 parent b71f690 commit e1f5b61
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 109 deletions.
85 changes: 18 additions & 67 deletions Cargo.lock

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

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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" }
3 changes: 1 addition & 2 deletions crates/nargo/src/ops/execute.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 1 addition & 2 deletions crates/nargo/src/ops/prove.rs
Original file line number Diff line number Diff line change
@@ -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<B: ProofSystemCompiler>(
backend: &B,
Expand Down
3 changes: 1 addition & 2 deletions crates/nargo/src/ops/verify.rs
Original file line number Diff line number Diff line change
@@ -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<B: ProofSystemCompiler>(
backend: &B,
Expand Down
4 changes: 2 additions & 2 deletions crates/nargo_cli/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
5 changes: 2 additions & 3 deletions crates/nargo_cli/src/cli/fs/witness.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -14,7 +13,7 @@ pub(crate) fn save_witness_to_dir<P: AsRef<Path>>(
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<u8> = witness.try_into()?;

write_to_file(buf.as_slice(), &witness_path);

Expand Down
6 changes: 3 additions & 3 deletions crates/nargo_cli/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -89,7 +89,7 @@ fn run_test<B: Backend>(

// 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);
Expand Down
6 changes: 5 additions & 1 deletion crates/nargo_cli/src/errors.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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)]
Expand Down
12 changes: 6 additions & 6 deletions crates/noirc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<String, InputValue>;

/// A map from the witnesses in a constraint system to the field element values
pub type WitnessMap = BTreeMap<Witness, FieldElement>;

/// A tuple of the arguments to a function along with its return value.
pub type FunctionSignature = (Vec<AbiParameter>, Option<AbiType>);

Expand Down Expand Up @@ -254,7 +254,7 @@ impl Abi {
.collect::<Result<_, _>>()?;

// 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<Witness, FieldElement> = encoded_input_map
.iter()
.flat_map(|(param_name, encoded_param_fields)| {
let param_witness_indices = &self.param_witnesses[param_name];
Expand Down Expand Up @@ -297,7 +297,7 @@ impl Abi {
(_, None) => {}
}

Ok(witness_map)
Ok(witness_map.into())
}

fn encode_value(value: InputValue) -> Result<Vec<FieldElement>, AbiError> {
Expand Down
Loading

0 comments on commit e1f5b61

Please sign in to comment.