Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix]: VerifyCmd Flag Collision #1513

Open
wants to merge 5 commits into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions miden/src/cli/verify.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::Path;
use std::{path::PathBuf, time::Instant};

use assembly::diagnostics::{IntoDiagnostic, Report, WrapErr};
Expand All @@ -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!("-------------------------------------------------------------------------------");
Expand All @@ -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();

Expand All @@ -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);
}
}