diff --git a/miden/src/cli/verify.rs b/miden/src/cli/verify.rs index 71e259ab4..c44e2e3c0 100644 --- a/miden/src/cli/verify.rs +++ b/miden/src/cli/verify.rs @@ -1,3 +1,4 @@ +use std::path::Path; use std::{path::PathBuf, time::Instant}; use assembly::diagnostics::{IntoDiagnostic, Report, WrapErr}; @@ -19,12 +20,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(); + println!("==============================================================================="); println!("Verifying proof: {}", self.proof_file.display()); println!("-------------------------------------------------------------------------------"); @@ -33,18 +36,21 @@ 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)?; + let outputs_data = 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) - .map_err(Report::msg)?; + let proof = ProofFile::read( + &Some(self.proof_file.clone()), + &self.proof_file.as_ref(), + ) + .map_err(Report::msg)?; let now = Instant::now(); @@ -62,4 +68,30 @@ impl VerifyCmd { Ok(()) } + + fn infer_defaults(&self) -> (PathBuf, PathBuf) { + let proof_file = if self.proof_file.exists() { + self.proof_file.clone() + } else { + PathBuf::from("default_proof_file.txt") + }; + + let base_name = proof_file.file_stem().expect("Invalid proof file").to_str().unwrap(); + + let input_file = self.input_file.clone().unwrap_or_else(|| { + let mut input_path = + proof_file.parent().unwrap_or_else(|| Path::new(".")).to_path_buf(); + input_path.push(format!("{}.inputs", base_name)); + input_path + }); + + let output_file = self.output_file.clone().unwrap_or_else(|| { + let mut output_path = + proof_file.parent().unwrap_or_else(|| Path::new(".")).to_path_buf(); + output_path.push(format!("{}.outputs", base_name)); + output_path + }); + + return (input_file, output_file); + } }