Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher committed Jan 13, 2023
2 parents ee0c4e7 + c82f0dc commit 6a06443
Show file tree
Hide file tree
Showing 48 changed files with 394 additions and 260 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions crates/acir/src/circuit/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ impl std::fmt::Debug for Gate {
r.witness_index()
)
}
Gate::And(g) => write!(f, "{:?}", g),
Gate::Xor(g) => write!(f, "{:?}", g),
Gate::GadgetCall(g) => write!(f, "{:?}", g),
Gate::And(g) => write!(f, "{g:?}"),
Gate::Xor(g) => write!(f, "{g:?}"),
Gate::GadgetCall(g) => write!(f, "{g:?}"),
Gate::Directive(Directive::ToRadix { a, b, radix }) => {
write!(
f,
Expand Down
2 changes: 1 addition & 1 deletion crates/acvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl CustomGate for Language {
pub fn hash_constraint_system(cs: &Circuit) {
use sha2::{Digest, Sha256};
let mut hasher = Sha256::new();
hasher.update(&format!("{:?}", cs));
hasher.update(format!("{cs:?}"));
let result = hasher.finalize();
println!("hash of constraint system : {:x?}", &result[..]);
}
2 changes: 1 addition & 1 deletion crates/fm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl FileManager {

let dir = self.path(anchor).to_path_buf();

candidate_files.push(dir.join(format!("{}.{}", mod_name, FILE_EXTENSION)));
candidate_files.push(dir.join(format!("{mod_name}.{FILE_EXTENSION}")));

for candidate in candidate_files.iter() {
if let Some(file_id) = self.add_file(candidate, FileType::Normal) {
Expand Down
1 change: 1 addition & 0 deletions crates/nargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dirs = "4"
[dependencies]
dirs = "3.0.1"
url = "2.2.0"
iter-extended = { path = "../iter-extended" }
noirc_driver = { path = "../noirc_driver", features = ["std"] }
noirc_frontend = { path = "../noirc_frontend" }
noirc_abi = { path = "../noirc_abi" }
Expand Down
4 changes: 2 additions & 2 deletions crates/nargo/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn copy<U: AsRef<Path>, V: AsRef<Path>>(from: U, to: V) -> Result<(), std::i
output_root.join(&src)
};
if fs::metadata(&dest).is_err() {
println!(" mkdir: {:?}", dest);
println!(" mkdir: {dest:?}");
fs::create_dir_all(&dest)?;
}

Expand All @@ -52,7 +52,7 @@ pub fn copy<U: AsRef<Path>, V: AsRef<Path>>(from: U, to: V) -> Result<(), std::i
fs::copy(&path, &dest_path)?;
}
None => {
println!("failed: {:?}", path);
println!("failed: {path:?}");
}
}
}
Expand Down
26 changes: 19 additions & 7 deletions crates/nargo/src/cli/build_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use crate::{errors::CliError, resolver::Resolver};
use acvm::ProofSystemCompiler;
use clap::ArgMatches;
use std::path::{Path, PathBuf};
use iter_extended::btree_map;
use noirc_abi::{Abi, AbiParameter, AbiType};
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
};

use super::{add_std_lib, write_to_file, PROVER_INPUT_FILE, VERIFIER_INPUT_FILE};

Expand All @@ -21,24 +26,24 @@ pub fn build_from_path<P: AsRef<Path>>(p: P, allow_warnings: bool) -> Result<(),
add_std_lib(&mut driver);
driver.build(allow_warnings);
// XXX: We can have a --overwrite flag to determine if you want to overwrite the Prover/Verifier.toml files
if let Some(x) = driver.compute_abi() {
if let Some(abi) = driver.compute_abi() {
// XXX: The root config should return an enum to determine if we are looking for .json or .toml
// For now it is hard-coded to be toml.
//
// Check for input.toml and verifier.toml
let path_to_root = PathBuf::from(p.as_ref());
let path_to_prover_input = path_to_root.join(format!("{}.toml", PROVER_INPUT_FILE));
let path_to_verifier_input = path_to_root.join(format!("{}.toml", VERIFIER_INPUT_FILE));
let path_to_prover_input = path_to_root.join(format!("{PROVER_INPUT_FILE}.toml"));
let path_to_verifier_input = path_to_root.join(format!("{VERIFIER_INPUT_FILE}.toml"));

// If they are not available, then create them and
// populate them based on the ABI
if !path_to_prover_input.exists() {
let toml = toml::to_string(&x).unwrap();
let toml = toml::to_string(&build_empty_map(abi.clone())).unwrap();
write_to_file(toml.as_bytes(), &path_to_prover_input);
}
if !path_to_verifier_input.exists() {
let abi = x.public_abi();
let toml = toml::to_string(&abi).unwrap();
let public_abi = abi.public_abi();
let toml = toml::to_string(&build_empty_map(public_abi)).unwrap();
write_to_file(toml.as_bytes(), &path_to_verifier_input);
}
} else {
Expand All @@ -47,6 +52,13 @@ pub fn build_from_path<P: AsRef<Path>>(p: P, allow_warnings: bool) -> Result<(),
Ok(())
}

fn build_empty_map(abi: Abi) -> BTreeMap<String, &'static str> {
btree_map(abi.parameters, |AbiParameter { name, typ, .. }| {
let default_value = if matches!(typ, AbiType::Array { .. }) { "[]" } else { "" };
(name, default_value)
})
}

#[cfg(test)]
mod tests {
const TEST_DATA_DIR: &str = "tests/build_tests_data";
Expand Down
2 changes: 1 addition & 1 deletion crates/nargo/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn generate_circuit_and_witness_to_disk<P: AsRef<Path>>(
circuit_path.push(circuit_name);
circuit_path.set_extension(crate::cli::ACIR_EXT);
let path = write_to_file(serialized.as_slice(), &circuit_path);
println!("Generated ACIR code into {}", path);
println!("Generated ACIR code into {path}");
println!("{:?}", std::fs::canonicalize(&circuit_path));

if generate_witness {
Expand Down
2 changes: 1 addition & 1 deletion crates/nargo/src/cli/contract_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> {
contract_path.set_extension("sol");

let path = write_to_file(smart_contract_string.as_bytes(), &contract_path);
println!("Contract successfully created and located at {}", path);
println!("Contract successfully created and located at {path}");
Ok(())
}
2 changes: 1 addition & 1 deletion crates/nargo/src/cli/gates_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn count_gates_with_path<P: AsRef<Path>>(
println!("Total gates generated for language {:?}: {}\n", backend.np_language(), gates.len());

let exact_circuit_size = backend.get_exact_circuit_size(compiled_program.circuit);
println!("\nBackend circuit size: {}\n", exact_circuit_size);
println!("\nBackend circuit size: {exact_circuit_size}\n");

Ok(())
}
4 changes: 2 additions & 2 deletions crates/nargo/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn start_cli() {
Some("compile") => compile_cmd::run(matches),
Some("verify") => verify_cmd::run(matches),
Some("gates") => gates_cmd::run(matches),
Some(x) => Err(CliError::Generic(format!("unknown command : {}", x))),
Some(x) => Err(CliError::Generic(format!("unknown command : {x}"))),
_ => unreachable!(),
};
if let Err(err) = result {
Expand Down Expand Up @@ -184,7 +184,7 @@ pub fn prove_and_verify(proof_name: &str, prg_dir: &Path, show_ssa: bool) -> boo
) {
Ok(p) => p,
Err(error) => {
println!("{}", error);
println!("{error}");
return false;
}
};
Expand Down
7 changes: 3 additions & 4 deletions crates/nargo/src/cli/prove_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fn solve_witness(
let abi = compiled_program.abi.as_ref().unwrap();
let encoded_inputs = abi.clone().encode(witness_map, true).map_err(|error| match error {
AbiError::UndefinedInput(_) => {
CliError::Generic(format!("{} in the {}.toml file.", error, PROVER_INPUT_FILE))
CliError::Generic(format!("{error} in the {PROVER_INPUT_FILE}.toml file."))
}
_ => CliError::from(error),
})?;
Expand All @@ -108,8 +108,7 @@ fn solve_witness(

match solver_res {
GateResolution::UnsupportedOpcode(opcode) => return Err(CliError::Generic(format!(
"backend does not currently support the {} opcode. ACVM does not currently fall back to arithmetic gates.",
opcode
"backend does not currently support the {opcode} opcode. ACVM does not currently fall back to arithmetic gates.",
))),
GateResolution::UnsatisfiedConstrain => return Err(CliError::Generic(
"could not satisfy all constraints".to_string()
Expand Down Expand Up @@ -141,7 +140,7 @@ pub fn prove_with_path<P: AsRef<Path>>(
println!("proof : {}", hex::encode(&proof));

let path = write_to_file(hex::encode(&proof).as_bytes(), &proof_path);
println!("Proof successfully created and located at {}", path);
println!("Proof successfully created and located at {path}");
println!("{:?}", std::fs::canonicalize(&proof_path));

Ok(proof_path)
Expand Down
4 changes: 2 additions & 2 deletions crates/nargo/src/cli/verify_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> {

let allow_warnings = args.is_present("allow-warnings");
let result = verify(proof_name, allow_warnings)?;
println!("Proof verified : {}\n", result);
println!("Proof verified : {result}\n");
Ok(())
}

Expand Down Expand Up @@ -63,7 +63,7 @@ fn verify_proof(
let public_abi = compiled_program.abi.unwrap().public_abi();
let public_inputs = public_abi.encode(&public_inputs, false).map_err(|error| match error {
AbiError::UndefinedInput(_) => {
CliError::Generic(format!("{} in the {}.toml file.", error, VERIFIER_INPUT_FILE))
CliError::Generic(format!("{error} in the {VERIFIER_INPUT_FILE}.toml file."))
}
_ => CliError::from(error),
})?;
Expand Down
8 changes: 4 additions & 4 deletions crates/nargo/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl CliError {
stderr
.set_color(ColorSpec::new().set_fg(Some(Color::Red)))
.expect("cannot set color for stderr in StandardStream");
writeln!(&mut stderr, "{}", self).expect("cannot write to stderr");
writeln!(&mut stderr, "{self}").expect("cannot write to stderr");

std::process::exit(1)
}
Expand All @@ -27,16 +27,16 @@ impl CliError {
impl Display for CliError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CliError::Generic(msg) => write!(f, "Error: {}", msg),
CliError::Generic(msg) => write!(f, "Error: {msg}"),
CliError::DestinationAlreadyExists(path) =>
write!(f, "Error: destination {} already exists", path.display()),
CliError::PathNotValid(path) => {
write!(f, "Error: {} is not a valid path", path.display())
}
CliError::ProofNotValid(hex_error) => {
write!(f, "Error: could not parse proof data ({})", hex_error)
write!(f, "Error: could not parse proof data ({hex_error})")
}
CliError::MissingTomlFile(path) => write!(f, "cannot find input file located at {:?}, run nargo build to generate the missing Prover and/or Verifier toml files", path),
CliError::MissingTomlFile(path) => write!(f, "cannot find input file located at {path:?}, run nargo build to generate the missing Prover and/or Verifier toml files"),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/nargo/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ impl<'a> Resolver<'a> {

if crate_type == &CrateType::Binary {
return Err(CliError::Generic(format!(
"{} is a binary package and so it cannot be depended upon. src : {:?}",
dep_pkg_name, pkg_src
"{dep_pkg_name} is a binary package and so it cannot be depended upon. src : {pkg_src:?}"
)));
}

Expand Down
12 changes: 6 additions & 6 deletions crates/noir_field/src/generic_ark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ impl<F: PrimeField> std::fmt::Display for FieldElement<F> {
let s = big_f.bits();
let big_s = BigUint::one() << s;
if big_s == big_f {
return write!(f, "2^{}", s);
return write!(f, "2^{s}");
}
if big_f == BigUint::zero() {
return write!(f, "0");
}
let big_minus = BigUint::from_bytes_be(&(self.neg()).to_bytes());
if big_minus.to_string().len() < big_f.to_string().len() {
return write!(f, "-{}", big_minus);
return write!(f, "-{big_minus}");
}
write!(f, "{}", big_f)
write!(f, "{big_f}")
}
}

Expand All @@ -47,13 +47,13 @@ impl<F: PrimeField> std::fmt::Debug for FieldElement<F> {
let s = big_f.bits();
let big_s = BigUint::one() << s;
if big_s == big_f {
return write!(f, "2^{}", s);
return write!(f, "2^{s}");
}
if big_f.clone() % BigUint::from(2_u128).pow(32) == BigUint::zero() {
return write!(f, "2^32*{}", big_f / BigUint::from(2_u128).pow(32));
}

write!(f, "{}", self)
write!(f, "{self}")
}
}

Expand Down Expand Up @@ -106,7 +106,7 @@ impl<'de, T: ark_ff::PrimeField> Deserialize<'de> for FieldElement<T> {
let s = <&str>::deserialize(deserializer)?;
match Self::from_hex(s) {
Some(value) => Ok(value),
None => Err(serde::de::Error::custom(format!("Invalid hex for FieldElement: {}", s))),
None => Err(serde::de::Error::custom(format!("Invalid hex for FieldElement: {s}"))),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/noirc_abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ toml = "0.5.8"
serde = { version = "1.0.136", features = ["derive"] }
serde_derive = "1.0.136"
blake2 = "0.9.1"

[dev-dependencies]
serde_json = "1.0"
18 changes: 8 additions & 10 deletions crates/noirc_abi/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ impl std::fmt::Display for InputParserError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
InputParserError::ParseTomlMap(err_msg) => {
write!(f, "input.toml file is badly formed, could not parse, {}", err_msg)
write!(f, "input.toml file is badly formed, could not parse, {err_msg}")
}
InputParserError::ParseStr(err_msg) => write!(
f,
"Expected witness values to be integers, provided value causes `{}` error",
err_msg
"Expected witness values to be integers, provided value causes `{err_msg}` error"
),
InputParserError::ParseHexStr(err_msg) => {
write!(f, "Could not parse hex value {}", err_msg)
write!(f, "Could not parse hex value {err_msg}")
}
InputParserError::DuplicateVariableName(err_msg) => {
write!(f, "duplicate variable name {}", err_msg)
write!(f, "duplicate variable name {err_msg}")
}
}
}
Expand All @@ -47,23 +46,22 @@ impl std::fmt::Display for AbiError {
match self {
AbiError::Generic(msg) => msg.clone(),
AbiError::UnexpectedParams(unexpected_params) =>
format!("Received parameters not expected by ABI: {:?}", unexpected_params),
format!("Received parameters not expected by ABI: {unexpected_params:?}"),
AbiError::TypeMismatch { param, value } => {
format!(
"The parameter {} is expected to be a {:?} but found incompatible value {:?}",
param.name, param.typ, value
)
}
AbiError::MissingParam(name) => {
format!("ABI expects the parameter `{}`, but this was not found", name)
format!("ABI expects the parameter `{name}`, but this was not found")
}
AbiError::UndefinedInput(name) => {
format!("Input value `{}` is not defined", name)
format!("Input value `{name}` is not defined")
}
AbiError::UnexpectedInputLength { expected, actual } => {
format!(
"ABI specifies an input of length {} but received input of length {}",
expected, actual
"ABI specifies an input of length {expected} but received input of length {actual}"
)
}
}
Expand Down
Loading

0 comments on commit 6a06443

Please sign in to comment.