diff --git a/tooling/debugger/src/lib.rs b/tooling/debugger/src/lib.rs index 306b8c7f301..9843e628988 100644 --- a/tooling/debugger/src/lib.rs +++ b/tooling/debugger/src/lib.rs @@ -9,8 +9,6 @@ use nargo::NargoError; use nargo::ops::ForeignCallExecutor; -use thiserror::Error; - use easy_repl::{command, CommandStatus, Critical, Repl}; use std::cell::{Cell, RefCell}; @@ -19,17 +17,6 @@ enum SolveResult { Ok, } -#[derive(Debug, Error)] -enum DebuggingError { - /// ACIR circuit execution error - #[error(transparent)] - ExecutionError(#[from] nargo::errors::ExecutionError), - - /// Oracle handling error - #[error(transparent)] - ForeignCallError(#[from] noirc_printable_type::ForeignCallError), -} - struct DebugContext<'backend, B: BlackBoxFunctionSolver> { acvm: Option>, debug_artifact: DebugArtifact, @@ -39,7 +26,7 @@ struct DebugContext<'backend, B: BlackBoxFunctionSolver> { } impl<'backend, B: BlackBoxFunctionSolver> DebugContext<'backend, B> { - fn step_opcode(&mut self) -> Result { + fn step_opcode(&mut self) -> Result { // Assert messages are not a map due to https://github.com/noir-lang/acvm/issues/522 let assert_messages = &self.circuit.assert_messages; let get_assert_message = |opcode_location| { @@ -65,7 +52,7 @@ impl<'backend, B: BlackBoxFunctionSolver> DebugContext<'backend, B> { _ => None, }; - Err(DebuggingError::ExecutionError(match call_stack { + 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"), @@ -116,7 +103,7 @@ impl<'backend, B: BlackBoxFunctionSolver> DebugContext<'backend, B> { } } - fn cont(&mut self) -> Result { + fn cont(&mut self) -> Result { loop { match self.step_opcode()? { SolveResult::Done => break, @@ -131,15 +118,6 @@ impl<'backend, B: BlackBoxFunctionSolver> DebugContext<'backend, B> { } } -impl From for DebuggingError { - fn from(e: nargo::errors::NargoError) -> Self { - match e { - NargoError::ForeignCallError(e1) => DebuggingError::ForeignCallError(e1), - _ => DebuggingError::ExecutionError(ExecutionError::Halted), - } - } -} - fn map_command_status(result: SolveResult) -> CommandStatus { match result { SolveResult::Ok => CommandStatus::Done, @@ -153,7 +131,7 @@ pub fn debug_circuit( debug_artifact: DebugArtifact, initial_witness: WitnessMap, show_output: bool, -) -> Result { +) -> Result, NargoError> { let opcodes = circuit.opcodes.clone(); let context = RefCell::new(DebugContext { @@ -208,8 +186,8 @@ pub fn debug_circuit( if solved.get() { let solved_witness = context.borrow_mut().finalize(); - Ok(solved_witness) + Ok(Some(solved_witness)) } else { - Err(NargoError::ExecutionError(ExecutionError::Halted)) + Ok(None) } } diff --git a/tooling/nargo/src/errors.rs b/tooling/nargo/src/errors.rs index dd68bfbc037..ea6e7fa8108 100644 --- a/tooling/nargo/src/errors.rs +++ b/tooling/nargo/src/errors.rs @@ -49,7 +49,6 @@ impl NargoError { OpcodeResolutionError::BrilligFunctionFailed { message, .. } => Some(message), OpcodeResolutionError::BlackBoxFunctionFailed(_, reason) => Some(reason), }, - ExecutionError::Halted => None, } } } @@ -61,9 +60,6 @@ pub enum ExecutionError { #[error(transparent)] SolvingError(#[from] OpcodeResolutionError), - - #[error("Execution halted")] - Halted, } /// Extracts the opcode locations from a nargo error. diff --git a/tooling/nargo_cli/src/cli/debug_cmd.rs b/tooling/nargo_cli/src/cli/debug_cmd.rs index 6d141309a30..81b0cf566b1 100644 --- a/tooling/nargo_cli/src/cli/debug_cmd.rs +++ b/tooling/nargo_cli/src/cli/debug_cmd.rs @@ -69,14 +69,21 @@ pub(crate) fn run( let (return_value, solved_witness) = debug_program_and_decode(compiled_program, package, &args.prover_name)?; - println!("[{}] Circuit witness successfully solved", package.name); - if let Some(return_value) = return_value { - println!("[{}] Circuit output: {return_value:?}", package.name); - } - if let Some(witness_name) = &args.witness_name { - let witness_path = save_witness_to_dir(solved_witness, witness_name, target_dir)?; + if let Some(solved_witness) = solved_witness { + println!("[{}] Circuit witness successfully solved", package.name); + + if let Some(return_value) = return_value { + println!("[{}] Circuit output: {return_value:?}", package.name); + } + + if let Some(witness_name) = &args.witness_name { + let witness_path = + save_witness_to_dir(solved_witness, witness_name, target_dir)?; - println!("[{}] Witness saved to {}", package.name, witness_path.display()); + println!("[{}] Witness saved to {}", package.name, witness_path.display()); + } + } else { + println!("Debugger execution halted."); } // Only debug the first binary package that matches the selection criteria @@ -90,21 +97,26 @@ fn debug_program_and_decode( program: CompiledProgram, package: &Package, prover_name: &str, -) -> Result<(Option, WitnessMap), CliError> { +) -> Result<(Option, Option), CliError> { // Parse the initial witness values from Prover.toml let (inputs_map, _) = read_inputs_from_file(&package.root_dir, prover_name, Format::Toml, &program.abi)?; let solved_witness = debug_program(&program, &inputs_map)?; let public_abi = program.abi.public_abi(); - let (_, return_value) = public_abi.decode(&solved_witness)?; - Ok((return_value, solved_witness)) + match solved_witness { + Some(witness) => { + let (_, return_value) = public_abi.decode(&witness)?; + Ok((return_value, Some(witness))) + } + None => Ok((None, None)), + } } pub(crate) fn debug_program( compiled_program: &CompiledProgram, inputs_map: &InputMap, -) -> Result { +) -> Result, CliError> { #[allow(deprecated)] let blackbox_solver = barretenberg_blackbox_solver::BarretenbergSolver::new();