diff --git a/CHANGELOG.md b/CHANGELOG.md index dcf5dce84..90bbc4eac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,12 @@ # Changelog #### Changes -- [BREAKING] `Process` no longer takes ownership of the `Host` (#1571) -- [BREAKING] `ProcessState` was converted from a trait to a struct (#1571) -- [BREAKING] `Host` and `AdviceProvider` traits simplified (#1572) -- [BREAKING] `MastForest` serialization/deserialization will store/read decorator data at the end of the binary (#1531) +- [BREAKING] `Process` no longer takes ownership of the `Host` (#1571). +- [BREAKING] `ProcessState` was converted from a trait to a struct (#1571). +- [BREAKING] `Host` and `AdviceProvider` traits simplified (#1572). +- [BREAKING] `MastForest` serialization/deserialization will store/read decorator data at the end of the binary (#1531). - [BREAKING] Updated Winterfell dependency to v0.11 (#1586). +- [BREAKING] resolved flag collision in `--verify` command and added functionality for optional input/output files (#1513). #### Enhancements - Added `miden_core::mast::MastForest::advice_map` to load it into the advice provider before the `MastForest` execution (#1574). diff --git a/miden/src/cli/verify.rs b/miden/src/cli/verify.rs index 71e259ab4..1130b82d4 100644 --- a/miden/src/cli/verify.rs +++ b/miden/src/cli/verify.rs @@ -1,6 +1,9 @@ -use std::{path::PathBuf, time::Instant}; +use std::{ + path::{Path, PathBuf}, + time::Instant, +}; -use assembly::diagnostics::{IntoDiagnostic, Report, WrapErr}; +use assembly::diagnostics::{IntoDiagnostic, Report, Result, WrapErr}; use clap::Parser; use miden_vm::{Kernel, ProgramInfo}; @@ -19,12 +22,14 @@ pub struct VerifyCmd { #[clap(short = 'p', long = "proof", value_parser)] proof_file: PathBuf, /// Program hash (hex) - #[clap(short = 'h', long = "program-hash")] + #[clap(short = 'x', long = "program-hash")] program_hash: String, } impl VerifyCmd { pub fn execute(&self) -> Result<(), Report> { + let (input_file, output_file) = self.infer_defaults().unwrap(); + println!("==============================================================================="); println!("Verifying proof: {}", self.proof_file.display()); println!("-------------------------------------------------------------------------------"); @@ -33,17 +38,17 @@ impl VerifyCmd { let program_hash = ProgramHash::read(&self.program_hash).map_err(Report::msg)?; // load input data from file - let input_data = InputFile::read(&self.input_file, &self.proof_file)?; + let input_data = InputFile::read(&Some(input_file), self.proof_file.as_ref())?; // fetch the stack inputs from the arguments let stack_inputs = input_data.parse_stack_inputs().map_err(Report::msg)?; // load outputs data from file let outputs_data = - OutputFile::read(&self.output_file, &self.proof_file).map_err(Report::msg)?; + OutputFile::read(&Some(output_file), self.proof_file.as_ref()).map_err(Report::msg)?; // load proof from file - let proof = ProofFile::read(&Some(self.proof_file.clone()), &self.proof_file) + let proof = ProofFile::read(&Some(self.proof_file.clone()), self.proof_file.as_ref()) .map_err(Report::msg)?; let now = Instant::now(); @@ -62,4 +67,25 @@ impl VerifyCmd { Ok(()) } + + fn infer_defaults(&self) -> Result<(PathBuf, PathBuf), Report> { + let proof_file = if Path::new(&self.proof_file.as_os_str()).try_exists().is_err() { + return Err(Report::msg("Proof file does not exist")); + } else { + self.proof_file.clone() + }; + + let input_file = self.input_file.clone().unwrap_or_else(|| { + let mut input_path = proof_file.clone(); + input_path.set_extension("inputs"); + input_path + }); + let output_file = self.output_file.clone().unwrap_or_else(|| { + let mut output_path = proof_file.clone(); + output_path.set_extension("outputs"); + output_path + }); + + Ok((input_file.to_path_buf(), output_file.to_path_buf())) + } }