1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use crate::{cli::*, cli_types::*, commands::SetupCommand, errors::CLIError};
use leo_package::{outputs::ProofFile, root::Manifest};
use snarkvm_algorithms::snark::groth16::{Groth16, PreparedVerifyingKey, Proof};
use snarkvm_curves::bls12_377::{Bls12_377, Fr};
use snarkvm_models::algorithms::SNARK;
use clap::ArgMatches;
use rand::thread_rng;
use std::{convert::TryFrom, env::current_dir, time::Instant};
#[derive(Debug)]
pub struct ProveCommand;
impl CLI for ProveCommand {
type Options = bool;
type Output = (Proof<Bls12_377>, PreparedVerifyingKey<Bls12_377>);
const ABOUT: AboutType = "Run the program and produce a proof";
const ARGUMENTS: &'static [ArgumentType] = &[];
const FLAGS: &'static [FlagType] = &[("--skip-key-check")];
const NAME: NameType = "prove";
const OPTIONS: &'static [OptionType] = &[];
const SUBCOMMANDS: &'static [SubCommandType] = &[];
#[cfg_attr(tarpaulin, skip)]
fn parse(arguments: &ArgMatches) -> Result<Self::Options, CLIError> {
Ok(!arguments.is_present("skip-key-check"))
}
#[cfg_attr(tarpaulin, skip)]
fn output(do_setup_check: Self::Options) -> Result<Self::Output, CLIError> {
let (program, parameters, prepared_verifying_key) = SetupCommand::output(do_setup_check)?;
let span = tracing::span!(tracing::Level::INFO, "Proving");
let enter = span.enter();
let path = current_dir()?;
let package_name = Manifest::try_from(path.as_path())?.get_package_name();
tracing::info!("Starting...");
let start = Instant::now();
let rng = &mut thread_rng();
let program_proof = Groth16::<Bls12_377, _, Vec<Fr>>::prove(¶meters, &program, rng)?;
let end = start.elapsed().as_millis();
let mut proof = vec![];
program_proof.write(&mut proof)?;
ProofFile::new(&package_name).write_to(&path, &proof)?;
drop(enter);
tracing::span!(tracing::Level::INFO, "Done").in_scope(|| {
tracing::info!("Finished in {:?} milliseconds\n", end);
});
Ok((program_proof, prepared_verifying_key))
}
}