Skip to content

Commit

Permalink
feat: Silence output of prove and verify (#892)
Browse files Browse the repository at this point in the history
* Silence output of prove and verify

* Cleanup output
  • Loading branch information
jfecher authored Feb 22, 2023
1 parent 6c7aa2f commit 811b346
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 37 deletions.
21 changes: 10 additions & 11 deletions crates/nargo/src/cli/prove_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,20 @@ pub fn prove_with_path<P: AsRef<Path>>(
let proof =
backend.prove_with_pk(compiled_program.circuit.clone(), solved_witness, proving_key);

println!("Proof successfully created");
if check_proof {
let valid_proof =
verify_proof(compiled_program, public_inputs, return_value, &proof, verification_key)?;
println!("Proof verified : {valid_proof}");
if !valid_proof {
return Err(CliError::Generic("Could not verify generated proof".to_owned()));
}
let no_proof_name = "".into();
verify_proof(
compiled_program,
public_inputs,
return_value,
&proof,
verification_key,
no_proof_name,
)?;
}

let proof_path = if let Some(proof_name) = proof_name {
let proof_path = save_proof_to_dir(&proof, &proof_name, proof_dir)?;

println!("Proof saved to {}", proof_path.display());
Some(proof_path)
Some(save_proof_to_dir(&proof, &proof_name, proof_dir)?)
} else {
println!("{}", hex::encode(&proof));
None
Expand Down
45 changes: 19 additions & 26 deletions crates/nargo/src/cli/verify_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use acvm::{FieldElement, ProofSystemCompiler};
use clap::Args;
use noirc_abi::input_parser::{Format, InputValue};
use noirc_driver::CompiledProgram;
use std::path::Path;
use std::path::{Path, PathBuf};

/// Given a proof and a program, verify whether the proof is valid
#[derive(Debug, Clone, Args)]
Expand All @@ -32,34 +32,23 @@ pub(crate) fn run(args: VerifyCommand, config: NargoConfig) -> Result<(), CliErr
proof_path.push(Path::new(&args.proof));
proof_path.set_extension(PROOF_EXT);

let circuit_build_path = if let Some(circuit_name) = args.circuit_name {
let circuit_build_path = args.circuit_name.map(|circuit_name| {
let mut circuit_build_path = config.program_dir.clone();
circuit_build_path.push(TARGET_DIR);
circuit_build_path.push(circuit_name);
Some(circuit_build_path)
} else {
None
};

let result = verify_with_path(
config.program_dir,
proof_path,
circuit_build_path,
false,
args.allow_warnings,
)?;
println!("Proof verified : {result}");
circuit_build_path
});

Ok(())
verify_with_path(config.program_dir, proof_path, circuit_build_path, false, args.allow_warnings)
}

pub fn verify_with_path<P: AsRef<Path>>(
fn verify_with_path<P: AsRef<Path>>(
program_dir: P,
proof_path: P,
proof_path: PathBuf,
circuit_build_path: Option<P>,
show_ssa: bool,
allow_warnings: bool,
) -> Result<bool, CliError> {
) -> Result<(), CliError> {
let compiled_program = compile_circuit(program_dir.as_ref(), show_ssa, allow_warnings)?;
let (_, verification_key) =
fetch_pk_and_vk(&compiled_program.circuit, circuit_build_path, false, true)?;
Expand All @@ -69,15 +58,14 @@ pub fn verify_with_path<P: AsRef<Path>>(
let (public_inputs_map, return_value) =
read_inputs_from_file(program_dir, VERIFIER_INPUT_FILE, Format::Toml, &public_abi)?;

let valid_proof = verify_proof(
verify_proof(
compiled_program,
public_inputs_map,
return_value,
&load_hex_data(proof_path)?,
&load_hex_data(&proof_path)?,
verification_key,
)?;

Ok(valid_proof)
proof_path,
)
}

pub(crate) fn verify_proof(
Expand All @@ -86,7 +74,8 @@ pub(crate) fn verify_proof(
return_value: Option<InputValue>,
proof: &[u8],
verification_key: Vec<u8>,
) -> Result<bool, CliError> {
proof_name: PathBuf,
) -> Result<(), CliError> {
let public_abi = compiled_program.abi.public_abi();
let public_inputs = public_abi.encode(&public_inputs_map, return_value)?;

Expand All @@ -100,5 +89,9 @@ pub(crate) fn verify_proof(
verification_key,
);

Ok(valid_proof)
if valid_proof {
Ok(())
} else {
Err(CliError::InvalidProof(proof_name))
}
}
2 changes: 2 additions & 0 deletions crates/nargo/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub enum CliError {
MissingVerificationkey(PathBuf),
#[error("Error: the circuit you are trying to prove differs from the build artifact at {}\nYou must call `nargo compile` to generate the correct proving and verification keys for this circuit", .0.display())]
MismatchedAcir(PathBuf),
#[error("Failed to verify proof {}", .0.display())]
InvalidProof(PathBuf),
}

impl From<OpcodeResolutionError> for CliError {
Expand Down

0 comments on commit 811b346

Please sign in to comment.