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

feat: Silence output of prove and verify #892

Merged
merged 3 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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 @@ -108,21 +108,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
46 changes: 24 additions & 22 deletions crates/nargo/src/cli/verify_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use clap::Args;
use noirc_abi::input_parser::{Format, InputValue};
use noirc_abi::MAIN_RETURN_NAME;
use noirc_driver::CompiledProgram;
use std::{collections::BTreeMap, path::Path};
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
};

/// Given a proof and a program, verify whether the proof is valid
#[derive(Debug, Clone, Args)]
Expand All @@ -33,34 +36,29 @@ 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
};
circuit_build_path
});

let result = verify_with_path(
verify_with_path(
config.program_dir,
proof_path,
proof_path.clone(),
jfecher marked this conversation as resolved.
Show resolved Hide resolved
circuit_build_path,
false,
args.allow_warnings,
)?;
println!("Proof verified : {result}");

Ok(())
)
}

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 @@ -77,15 +75,14 @@ pub fn verify_with_path<P: AsRef<Path>>(
(BTreeMap::new(), None)
};

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 @@ -94,7 +91,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 @@ -108,5 +106,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