Skip to content

Commit

Permalink
Return error if the return value is missing in execution
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Dec 10, 2024
1 parent 914209b commit 560970f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tooling/nargo_cli/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub(crate) fn run(args: ExecuteCommand, config: NargoConfig) -> Result<(), CliEr
let program_artifact_path = workspace.package_build_path(package);
let program: CompiledProgram =
read_program_from_file(program_artifact_path.clone())?.into();
let abi = program.abi.clone();

let results = execute_program_and_decode(
program,
Expand All @@ -93,6 +94,14 @@ pub(crate) fn run(args: ExecuteCommand, config: NargoConfig) -> Result<(), CliEr
return Err(CliError::UnexpectedReturn { expected, actual: results.actual_return });
}
}
// Abi::decode returns None if the WitnessMap is empty in places corresponding to the return,
// positing that the caller should decide whether a result should be present.
// Arguably at the end of circuit execution it should be.
if let Some(ref expected) = abi.return_type {
if results.actual_return.is_none() {
return Err(CliError::MissingReturn { expected: expected.clone() });
}
}
}
Ok(())
}
Expand Down
4 changes: 4 additions & 0 deletions tooling/nargo_cli/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use noir_debugger::errors::DapError;
use noirc_abi::{
errors::{AbiError, InputParserError},
input_parser::InputValue,
AbiReturnType,
};
use std::path::PathBuf;
use thiserror::Error;
Expand Down Expand Up @@ -70,4 +71,7 @@ pub(crate) enum CliError {

#[error("Unexpected return value: expected {expected:?}; got {actual:?}")]
UnexpectedReturn { expected: InputValue, actual: Option<InputValue> },

#[error("Missing return witnesses; expected {expected:?}")]
MissingReturn { expected: AbiReturnType },
}

0 comments on commit 560970f

Please sign in to comment.