Skip to content

Commit

Permalink
Try Prover.json if Prover.toml is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Jan 23, 2025
1 parent c8d5ce5 commit f75e052
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
8 changes: 4 additions & 4 deletions tooling/nargo_cli/src/cli/debug_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use nargo::package::{CrateName, Package};
use nargo::workspace::Workspace;
use nargo::{insert_all_files_for_workspace_into_file_manager, parse_all};
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection};
use noirc_abi::input_parser::{Format, InputValue};
use noirc_abi::input_parser::InputValue;
use noirc_abi::InputMap;
use noirc_driver::{
file_manager_with_stdlib, CompileOptions, CompiledProgram, NOIR_ARTIFACT_VERSION_STRING,
Expand All @@ -22,7 +22,7 @@ use noirc_frontend::debug::DebugInstrumenter;
use noirc_frontend::hir::ParsedFiles;

use super::compile_cmd::get_target_width;
use super::fs::{inputs::read_inputs_from_file, witness::save_witness_to_dir};
use super::fs::{inputs::read_inputs_from_file_any_format, witness::save_witness_to_dir};
use super::NargoConfig;
use crate::errors::CliError;

Expand Down Expand Up @@ -216,9 +216,9 @@ fn debug_program_and_decode(
prover_name: &str,
pedantic_solving: bool,
) -> Result<(Option<InputValue>, Option<WitnessStack<FieldElement>>), CliError> {
// Parse the initial witness values from Prover.toml
// Parse the initial witness values from Prover.toml or Prover.json
let (inputs_map, _) =
read_inputs_from_file(&package.root_dir, prover_name, Format::Toml, &program.abi)?;
read_inputs_from_file_any_format(&package.root_dir, prover_name, &program.abi)?;
let program_abi = program.abi.clone();
let witness_stack = debug_program(program, &inputs_map, pedantic_solving)?;

Expand Down
9 changes: 5 additions & 4 deletions tooling/nargo_cli/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ use nargo::foreign_calls::DefaultForeignCallBuilder;
use nargo::package::Package;
use nargo::PrintOutput;
use nargo_toml::{get_package_manifest, resolve_workspace_from_toml};
use noirc_abi::input_parser::{Format, InputValue};
use noirc_abi::input_parser::InputValue;
use noirc_abi::InputMap;
use noirc_artifacts::debug::DebugArtifact;
use noirc_driver::{CompileOptions, CompiledProgram, NOIR_ARTIFACT_VERSION_STRING};

use super::compile_cmd::compile_workspace_full;
use super::fs::{inputs::read_inputs_from_file, witness::save_witness_to_dir};
use super::fs::inputs::read_inputs_from_file_any_format;
use super::fs::witness::save_witness_to_dir;
use super::{NargoConfig, PackageOptions};
use crate::cli::fs::program::read_program_from_file;
use crate::errors::CliError;
Expand Down Expand Up @@ -111,9 +112,9 @@ fn execute_program_and_decode(
package_name: Option<String>,
pedantic_solving: bool,
) -> Result<ExecutionResults, CliError> {
// Parse the initial witness values from Prover.toml
// Parse the initial witness values from Prover.toml or Prover.json
let (inputs_map, expected_return) =
read_inputs_from_file(&package.root_dir, prover_name, Format::Toml, &program.abi)?;
read_inputs_from_file_any_format(&package.root_dir, prover_name, &program.abi)?;
let witness_stack = execute_program(
&program,
&inputs_map,
Expand Down
24 changes: 24 additions & 0 deletions tooling/nargo_cli/src/cli/fs/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,27 @@ pub(crate) fn read_inputs_from_file<P: AsRef<Path>>(

Ok((input_map, return_value))
}

/// Try to look for any format with the given file name:
/// 1. TOML
/// 2. JSON
pub(crate) fn read_inputs_from_file_any_format(
path: &Path,
file_name: &str,
abi: &Abi,
) -> Result<(InputMap, Option<InputValue>), FilesystemError> {
let mut first_missing = None;
for format in [Format::Toml, Format::Json] {
match read_inputs_from_file(path, file_name, format, abi) {
Err(e @ FilesystemError::MissingTomlFile(..)) => {
if first_missing.is_none() {
first_missing = Some(e);
}
}
other => {
return other;
}
}
}
Err(first_missing.expect("must have encountered an error"))
}

0 comments on commit f75e052

Please sign in to comment.