diff --git a/tooling/nargo/src/errors.rs b/tooling/nargo/src/errors.rs index b5571ff7758..0b8378702cb 100644 --- a/tooling/nargo/src/errors.rs +++ b/tooling/nargo/src/errors.rs @@ -2,8 +2,8 @@ use std::collections::BTreeMap; use acvm::{ acir::circuit::{ - ErrorSelector, OpcodeLocation, RawAssertionPayload, ResolvedAssertionPayload, - ResolvedOpcodeLocation, + brillig::BrilligFunctionId, ErrorSelector, OpcodeLocation, RawAssertionPayload, + ResolvedAssertionPayload, ResolvedOpcodeLocation, }, pwg::{ErrorLocation, OpcodeResolutionError}, AcirField, FieldElement, @@ -66,7 +66,7 @@ impl NargoError { ) -> Option { match self { NargoError::ExecutionError(error) => match error { - ExecutionError::AssertionFailed(payload, _) => match payload { + ExecutionError::AssertionFailed(payload, _, _) => match payload { ResolvedAssertionPayload::String(message) => Some(message.to_string()), ResolvedAssertionPayload::Raw(raw) => { let abi_type = error_types.get(&raw.selector)?; @@ -90,7 +90,11 @@ impl NargoError { #[derive(Debug, Error)] pub enum ExecutionError { #[error("Failed assertion")] - AssertionFailed(ResolvedAssertionPayload, Vec), + AssertionFailed( + ResolvedAssertionPayload, + Vec, + Option, + ), #[error("Failed to solve program: '{}'", .0)] SolvingError(OpcodeResolutionError, Option>), @@ -106,7 +110,7 @@ fn extract_locations_from_error( OpcodeResolutionError::BrilligFunctionFailed { .. }, acir_call_stack, ) => acir_call_stack.clone(), - ExecutionError::AssertionFailed(_, call_stack) => Some(call_stack.clone()), + ExecutionError::AssertionFailed(_, call_stack, _) => Some(call_stack.clone()), ExecutionError::SolvingError( OpcodeResolutionError::IndexOutOfBounds { opcode_location: error_location, .. }, acir_call_stack, @@ -148,6 +152,7 @@ fn extract_locations_from_error( OpcodeResolutionError::BrilligFunctionFailed { function_id, .. }, _, ) => Some(*function_id), + ExecutionError::AssertionFailed(_, _, function_id) => *function_id, _ => None, }; @@ -187,6 +192,7 @@ fn extract_message_from_error( NargoError::ExecutionError(ExecutionError::AssertionFailed( ResolvedAssertionPayload::String(message), _, + _, )) => { format!("Assertion failed: '{message}'") } diff --git a/tooling/nargo/src/ops/execute.rs b/tooling/nargo/src/ops/execute.rs index 5a43b1c2f9c..59d554d7ca5 100644 --- a/tooling/nargo/src/ops/execute.rs +++ b/tooling/nargo/src/ops/execute.rs @@ -117,10 +117,18 @@ impl<'a, F: AcirField, B: BlackBoxFunctionSolver, E: ForeignCallExecutor> _ => None, }; + let brillig_function_id = match &error { + OpcodeResolutionError::BrilligFunctionFailed { function_id, .. } => { + Some(*function_id) + } + _ => None, + }; + return Err(NargoError::ExecutionError(match assertion_payload { Some(payload) => ExecutionError::AssertionFailed( payload, call_stack.expect("Should have call stack for an assertion failure"), + brillig_function_id, ), None => ExecutionError::SolvingError(error, call_stack), }));