Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use circuit.get_assert_message instead of closure/helper function #3127

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -35,7 +35,7 @@
/// @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`..
/// @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit.
/// @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs.
#[wasm_bindgen(js_name = executeCircuit, skip_jsdoc)]

Check warning on line 38 in acvm-repo/acvm_js/src/execute.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (jsdoc)
pub async fn execute_circuit(
circuit: Vec<u8>,
initial_witness: JsWitnessMap,
Expand All @@ -56,7 +56,7 @@
/// @param {WitnessMap} initial_witness - The initial witness map defining all of the inputs to `circuit`..
/// @param {ForeignCallHandler} foreign_call_handler - A callback to process any foreign calls from the circuit.
/// @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs.
#[wasm_bindgen(js_name = executeCircuitWithBlackBoxSolver, skip_jsdoc)]

Check warning on line 59 in acvm-repo/acvm_js/src/execute.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (jsdoc)
pub async fn execute_circuit_with_black_box_solver(
solver: &WasmBlackBoxFunctionSolver,
circuit: Vec<u8>,
Expand Down Expand Up @@ -84,17 +84,13 @@
| 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 @@
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
Loading