Skip to content

Commit

Permalink
fix: VerifyCmd Flag Collision (#1513)
Browse files Browse the repository at this point in the history
  • Loading branch information
varun-doshi authored Nov 29, 2024
1 parent 60a32af commit 18cb244
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
38 changes: 32 additions & 6 deletions miden/src/cli/verify.rs
Original file line number Diff line number Diff line change
@@ -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};

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

0 comments on commit 18cb244

Please sign in to comment.