diff --git a/miden/src/cli/verify.rs b/miden/src/cli/verify.rs index 71e259ab4..1c0e5c9a3 100644 --- a/miden/src/cli/verify.rs +++ b/miden/src/cli/verify.rs @@ -1,4 +1,5 @@ use std::{path::PathBuf, time::Instant}; +use std::path::Path; use assembly::diagnostics::{IntoDiagnostic, Report, WrapErr}; use clap::Parser; @@ -17,33 +18,39 @@ pub struct VerifyCmd { output_file: Option, /// Path to proof file #[clap(short = 'p', long = "proof", value_parser)] - proof_file: PathBuf, + proof_file: Option, /// Program hash (hex) - #[clap(short = 'h', long = "program-hash")] + #[clap(short = 'x', long = "hash")] program_hash: String, } impl VerifyCmd { - pub fn execute(&self) -> Result<(), Report> { + pub fn execute(&mut self) -> Result<(), Report> { + + let (proof_file,output_file)=self.infer_defaults(); + + self.proof_file=Some(proof_file); + self.output_file=Some(output_file); + println!("==============================================================================="); - println!("Verifying proof: {}", self.proof_file.display()); + println!("Verifying proof: {}", self.proof_file.as_ref().unwrap().display()); println!("-------------------------------------------------------------------------------"); // read program hash from input 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(&self.input_file, &self.proof_file.as_ref().unwrap().clone())?; // 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(&self.output_file, &self.proof_file.as_ref().unwrap()).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.as_ref().unwrap().to_path_buf()), &self.proof_file.as_ref().unwrap()) .map_err(Report::msg)?; let now = Instant::now(); @@ -62,4 +69,26 @@ impl VerifyCmd { Ok(()) } -} + + pub fn infer_defaults(&self)->(PathBuf,PathBuf){ + let input_file = self.input_file.clone().unwrap_or_else(|| { + PathBuf::from("default_input_file.txt") + }); + + let base_name = input_file.file_stem().expect("Invalid input file").to_str().unwrap(); + + let proof_file = self.proof_file.clone().unwrap_or_else(|| { + let mut proof_path = input_file.parent().unwrap_or_else(|| Path::new(".")).to_path_buf(); + proof_path.push(format!("{}.proof", base_name)); + proof_path + }); + + let output_file = self.output_file.clone().unwrap_or_else(|| { + let mut output_path = input_file.parent().unwrap_or_else(|| Path::new(".")).to_path_buf(); + output_path.push(format!("{}.outputs", base_name)); + output_path + }); + + return (proof_file,output_file); + } +} \ No newline at end of file diff --git a/miden/src/main.rs b/miden/src/main.rs index 22fb81a15..a8d167785 100644 --- a/miden/src/main.rs +++ b/miden/src/main.rs @@ -36,8 +36,8 @@ pub enum Actions { /// CLI entry point impl Cli { - pub fn execute(&self) -> Result<(), Report> { - match &self.action { + pub fn execute(&mut self) -> Result<(), Report> { + match &mut self.action { Actions::Analyze(analyze) => analyze.execute(), Actions::Compile(compile) => compile.execute(), Actions::Bundle(compile) => compile.execute(), @@ -55,7 +55,7 @@ impl Cli { /// Executable entry point pub fn main() -> Result<(), Report> { // read command-line args - let cli = Cli::parse(); + let mut cli = Cli::parse(); initialize_diagnostics();