Skip to content

Commit

Permalink
Merge branch 'master' into assert-eq-builtin
Browse files Browse the repository at this point in the history
* master:
  feat: Perform more checks for compile-time arithmetic (#2380)
  chore: Remove `noirc_abi::FunctionSignature` and define in terms of HIR (#2372)
  feat: Update to `acvm` 0.22.0 (#2363)
  • Loading branch information
TomAFrench committed Aug 21, 2023
2 parents 39eb976 + 1be2b1e commit d80cba1
Show file tree
Hide file tree
Showing 50 changed files with 444 additions and 388 deletions.
453 changes: 237 additions & 216 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ edition = "2021"
rust-version = "1.66"

[workspace.dependencies]
acvm = "0.21.0"
acvm = "0.22.0"
arena = { path = "crates/arena" }
fm = { path = "crates/fm" }
iter-extended = { path = "crates/iter-extended" }
Expand Down
2 changes: 1 addition & 1 deletion crates/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ tokio = { version = "1.0", features = ["io-std"] }
tokio-util = { version = "0.7.8", features = ["compat"] }

# Backends
acvm-backend-barretenberg = { version = "0.10.0", default-features = false }
acvm-backend-barretenberg = { version = "0.11.0", default-features = false }

[dev-dependencies]
tempdir = "0.3.7"
Expand Down
4 changes: 2 additions & 2 deletions crates/nargo_cli/src/cli/check_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use iter_extended::btree_map;
use nargo::{package::Package, prepare_package};
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_abi::{AbiParameter, AbiType, MAIN_RETURN_NAME};
use noirc_driver::{check_crate, compute_function_signature, CompileOptions};
use noirc_driver::{check_crate, compute_function_abi, CompileOptions};
use noirc_frontend::{
graph::{CrateId, CrateName},
hir::Context,
Expand Down Expand Up @@ -56,7 +56,7 @@ fn check_package(package: &Package, compile_options: &CompileOptions) -> Result<
Ok(())
} else {
// XXX: We can have a --overwrite flag to determine if you want to overwrite the Prover/Verifier.toml files
if let Some((parameters, return_type)) = compute_function_signature(&context, &crate_id) {
if let Some((parameters, return_type)) = compute_function_abi(&context, &crate_id) {
let path_to_prover_input = package.prover_input_path();
let path_to_verifier_input = package.verifier_input_path();

Expand Down
28 changes: 6 additions & 22 deletions crates/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use acvm::acir::circuit::OpcodeLabel;
use acvm::{acir::circuit::Circuit, Backend};
use acvm::{acir::circuit::Circuit, compiler::AcirTransformationMap, Backend};
use iter_extended::try_vecmap;
use iter_extended::vecmap;
use nargo::artifacts::debug::DebugArtifact;
use nargo::package::Package;
use nargo::prepare_package;
Expand Down Expand Up @@ -171,27 +169,20 @@ pub(crate) fn compile_package<B: Backend>(
let result = compile_main(&mut context, crate_id, compile_options);
let mut program = report_errors(result, &context, compile_options.deny_warnings)?;
// Apply backend specific optimizations.
let (optimized_circuit, opcode_labels) = optimize_circuit(backend, program.circuit)
let (optimized_circuit, location_map) = optimize_circuit(backend, program.circuit)
.expect("Backend does not support an opcode that is in the IR");

// TODO(#2110): Why does this set `program.circuit` to `optimized_circuit` instead of the function taking ownership
// and requiring we use `optimized_circuit` everywhere after
program.circuit = optimized_circuit;
let opcode_ids = vecmap(opcode_labels, |label| match label {
OpcodeLabel::Unresolved => {
unreachable!("Compiled circuit opcodes must resolve to some index")
}
OpcodeLabel::Resolved(index) => index as usize,
});
program.debug.update_acir(opcode_ids);
program.debug.update_acir(location_map);

Ok((context, program))
}

pub(super) fn optimize_circuit<B: Backend>(
backend: &B,
circuit: Circuit,
) -> Result<(Circuit, Vec<OpcodeLabel>), CliError<B>> {
) -> Result<(Circuit, AcirTransformationMap), CliError<B>> {
let result = acvm::compiler::compile(circuit, backend.np_language(), |opcode| {
backend.supports_opcode(opcode)
})
Expand All @@ -205,16 +196,9 @@ pub(super) fn optimize_contract<B: Backend>(
contract: CompiledContract,
) -> Result<CompiledContract, CliError<B>> {
let functions = try_vecmap(contract.functions, |mut func| {
let (optimized_bytecode, opcode_labels) = optimize_circuit(backend, func.bytecode)?;
let opcode_ids = vecmap(opcode_labels, |label| match label {
OpcodeLabel::Unresolved => {
unreachable!("Compiled circuit opcodes must resolve to some index")
}
OpcodeLabel::Resolved(index) => index as usize,
});

let (optimized_bytecode, location_map) = optimize_circuit(backend, func.bytecode)?;
func.bytecode = optimized_bytecode;
func.debug.update_acir(opcode_ids);
func.debug.update_acir(location_map);
Ok::<_, CliError<B>>(func)
})?;

Expand Down
31 changes: 17 additions & 14 deletions crates/nargo_cli/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use acvm::acir::circuit::OpcodeLabel;
use acvm::acir::circuit::OpcodeLocation;
use acvm::acir::{circuit::Circuit, native_types::WitnessMap};
use acvm::pwg::ErrorLocation;
use acvm::Backend;
use clap::Args;
use nargo::constants::PROVER_INPUT_FILE;
Expand Down Expand Up @@ -90,32 +91,34 @@ fn execute_package<B: Backend>(
Ok((return_value, solved_witness))
}

fn extract_unsatisfied_constraint_from_nargo_error(nargo_err: &NargoError) -> Option<usize> {
fn extract_unsatisfied_constraint_from_nargo_error(
nargo_err: &NargoError,
) -> Option<OpcodeLocation> {
let solving_err = match nargo_err {
nargo::NargoError::SolvingError(err) => err,
_ => return None,
};

match solving_err {
acvm::pwg::OpcodeResolutionError::UnsatisfiedConstrain { opcode_label } => {
match opcode_label {
OpcodeLabel::Unresolved => {
unreachable!("Cannot resolve index for unsatisfied constraint")
}
OpcodeLabel::Resolved(opcode_index) => Some(*opcode_index as usize),
acvm::pwg::OpcodeResolutionError::UnsatisfiedConstrain {
opcode_location: error_location,
} => match error_location {
ErrorLocation::Unresolved => {
unreachable!("Cannot resolve index for unsatisfied constraint")
}
}
ErrorLocation::Resolved(opcode_location) => Some(*opcode_location),
},
_ => None,
}
}

fn report_unsatisfied_constraint_error(
opcode_idx: Option<usize>,
opcode_location: Option<OpcodeLocation>,
debug: &DebugInfo,
context: &Context,
) {
if let Some(opcode_index) = opcode_idx {
if let Some(locations) = debug.opcode_location(opcode_index) {
if let Some(opcode_location) = opcode_location {
if let Some(locations) = debug.opcode_location(&opcode_location) {
// The location of the error itself will be the location at the top
// of the call stack (the last item in the Vec).
if let Some(location) = locations.last() {
Expand All @@ -142,8 +145,8 @@ pub(crate) fn execute_program<B: Backend>(
Ok(solved_witness) => Ok(solved_witness),
Err(err) => {
if let Some((debug, context)) = debug_data {
let opcode_idx = extract_unsatisfied_constraint_from_nargo_error(&err);
report_unsatisfied_constraint_error(opcode_idx, &debug, &context);
let opcode_location = extract_unsatisfied_constraint_from_nargo_error(&err);
report_unsatisfied_constraint_error(opcode_location, &debug, &context);
}

Err(crate::errors::CliError::NargoError(err))
Expand Down
Loading

0 comments on commit d80cba1

Please sign in to comment.