Skip to content

Commit

Permalink
chore: use circuit.get_assert_message instead of closure/helper fun…
Browse files Browse the repository at this point in the history
…ction (#3127)

Co-authored-by: Tom French <git@tomfren.ch>
  • Loading branch information
TomAFrench and TomAFrench authored Oct 12, 2023
1 parent 0fc8f20 commit faaf6d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
26 changes: 5 additions & 21 deletions acvm-repo/acvm_js/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use acvm::{
acir::circuit::{Circuit, OpcodeLocation},
acir::circuit::Circuit,
pwg::{ACVMStatus, ErrorLocation, OpcodeResolutionError, ACVM},
};
#[allow(deprecated)]
Expand Down Expand Up @@ -84,17 +84,13 @@ pub async fn execute_circuit_with_black_box_solver(
| OpcodeResolutionError::IndexOutOfBounds {
opcode_location: ErrorLocation::Resolved(opcode_location),
..
} => (
get_assert_message(&circuit.assert_messages, opcode_location),
Some(vec![*opcode_location]),
),
} => {
(circuit.get_assert_message(*opcode_location), Some(vec![*opcode_location]))
}
OpcodeResolutionError::BrilligFunctionFailed { call_stack, .. } => {
let failing_opcode =
call_stack.last().expect("Brillig error call stacks cannot be empty");
(
get_assert_message(&circuit.assert_messages, failing_opcode),
Some(call_stack.clone()),
)
(circuit.get_assert_message(*failing_opcode), Some(call_stack.clone()))
}
_ => (None, None),
};
Expand All @@ -117,15 +113,3 @@ pub async fn execute_circuit_with_black_box_solver(
let witness_map = acvm.finalize();
Ok(witness_map.into())
}

// Searches the slice for `opcode_location`.
// This is functionality equivalent to .get on a map.
fn get_assert_message(
assert_messages: &[(OpcodeLocation, String)],
opcode_location: &OpcodeLocation,
) -> Option<String> {
assert_messages
.iter()
.find(|(loc, _)| loc == opcode_location)
.map(|(_, message)| message.clone())
}
15 changes: 3 additions & 12 deletions tooling/nargo/src/ops/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ pub fn execute_circuit<B: BlackBoxFunctionSolver>(
) -> Result<WitnessMap, NargoError> {
let mut acvm = ACVM::new(blackbox_solver, &circuit.opcodes, initial_witness);

// Assert messages are not a map due to https://github.com/noir-lang/acvm/issues/522
let get_assert_message = |opcode_location| {
circuit
.assert_messages
.iter()
.find(|(loc, _)| loc == opcode_location)
.map(|(_, message)| message.clone())
};

let mut foreign_call_executor = ForeignCallExecutor::default();

loop {
Expand All @@ -47,10 +38,10 @@ pub fn execute_circuit<B: BlackBoxFunctionSolver>(

return Err(NargoError::ExecutionError(match call_stack {
Some(call_stack) => {
if let Some(assert_message) = get_assert_message(
call_stack.last().expect("Call stacks should not be empty"),
if let Some(assert_message) = circuit.get_assert_message(
*call_stack.last().expect("Call stacks should not be empty"),
) {
ExecutionError::AssertionFailed(assert_message, call_stack)
ExecutionError::AssertionFailed(assert_message.to_owned(), call_stack)
} else {
ExecutionError::SolvingError(error)
}
Expand Down

0 comments on commit faaf6d2

Please sign in to comment.