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

Remove print to console for named proofs in nargo prove #718

Merged
merged 2 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions crates/nargo/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn start_cli() {
.subcommand(
App::new("prove")
.about("Create proof for this program")
.arg(Arg::with_name("proof_name").help("The name of the proof").required(true))
.arg(Arg::with_name("proof_name").help("The name of the proof"))
.arg(show_ssa.clone())
.arg(allow_warnings.clone()),
)
Expand Down Expand Up @@ -174,7 +174,7 @@ fn write_inputs_to_file<P: AsRef<Path>>(
pub fn prove_and_verify(proof_name: &str, prg_dir: &Path, show_ssa: bool) -> bool {
let tmp_dir = TempDir::new("p_and_v_tests").unwrap();
let proof_path = match prove_cmd::prove_with_path(
proof_name,
Some(proof_name),
prg_dir,
&tmp_dir.into_path(),
show_ssa,
Expand All @@ -187,7 +187,7 @@ pub fn prove_and_verify(proof_name: &str, prg_dir: &Path, show_ssa: bool) -> boo
}
};

verify_cmd::verify_with_path(prg_dir, &proof_path, show_ssa, false).unwrap()
verify_cmd::verify_with_path(prg_dir, &proof_path.unwrap(), show_ssa, false).unwrap()
}

fn add_std_lib(driver: &mut Driver) {
Expand Down
60 changes: 37 additions & 23 deletions crates/nargo/src/cli/prove_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,50 @@ use crate::{

pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> {
let args = args.subcommand_matches("prove").unwrap();
let proof_name = args.value_of("proof_name").unwrap();
let proof_name = args.value_of("proof_name");
let show_ssa = args.is_present("show-ssa");
let allow_warnings = args.is_present("allow-warnings");

prove(proof_name, show_ssa, allow_warnings)
}

/// In Barretenberg, the proof system adds a zero witness in the first index,
/// So when we add witness values, their index start from 1.
const WITNESS_OFFSET: u32 = 1;

fn prove(proof_name: &str, show_ssa: bool, allow_warnings: bool) -> Result<(), CliError> {
fn prove(proof_name: Option<&str>, show_ssa: bool, allow_warnings: bool) -> Result<(), CliError> {
let curr_dir = std::env::current_dir().unwrap();
let mut proof_path = PathBuf::new();
proof_path.push(PROOFS_DIR);
let result = prove_with_path(proof_name, curr_dir, proof_path, show_ssa, allow_warnings);
match result {
Ok(_) => Ok(()),
Err(e) => Err(e),

let mut proof_dir = PathBuf::new();
proof_dir.push(PROOFS_DIR);

prove_with_path(proof_name, curr_dir, proof_dir, show_ssa, allow_warnings)?;

Ok(())
}

pub fn prove_with_path<P: AsRef<Path>>(
proof_name: Option<&str>,
program_dir: P,
proof_dir: P,
show_ssa: bool,
allow_warnings: bool,
) -> Result<Option<PathBuf>, CliError> {
let (compiled_program, solved_witness) =
compile_circuit_and_witness(program_dir, show_ssa, allow_warnings)?;

let backend = crate::backends::ConcreteBackend;
let proof = backend.prove_with_meta(compiled_program.circuit, solved_witness);

println!("Proof successfully created");
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());
Ok(Some(proof_path))
} else {
println!("{}", hex::encode(&proof));
Ok(None)
}
}

Expand Down Expand Up @@ -112,28 +138,16 @@ fn solve_witness(
Ok(solved_witness)
}

pub fn prove_with_path<P: AsRef<Path>>(
fn save_proof_to_dir<P: AsRef<Path>>(
proof: Vec<u8>,
proof_name: &str,
program_dir: P,
proof_dir: P,
show_ssa: bool,
allow_warnings: bool,
) -> Result<PathBuf, CliError> {
let (compiled_program, solved_witness) =
compile_circuit_and_witness(program_dir, show_ssa, allow_warnings)?;

let backend = crate::backends::ConcreteBackend;
let proof = backend.prove_with_meta(compiled_program.circuit, solved_witness);

let mut proof_path = create_named_dir(proof_dir.as_ref(), "proof");
proof_path.push(proof_name);
proof_path.set_extension(PROOF_EXT);

println!("proof : {}", hex::encode(&proof));

let path = write_to_file(hex::encode(&proof).as_bytes(), &proof_path);
println!("Proof successfully created and located at {path}");
println!("{:?}", std::fs::canonicalize(&proof_path));
write_to_file(hex::encode(proof).as_bytes(), &proof_path);

Ok(proof_path)
}