mirror of
https://github.com/AleoHQ/leo.git
synced 2025-01-01 22:36:52 +03:00
Adds command
This commit is contained in:
parent
a72e4ce4a3
commit
9f60cf3393
@ -9,3 +9,6 @@ pub use self::new::*;
|
||||
|
||||
pub mod run;
|
||||
pub use self::run::*;
|
||||
|
||||
pub mod setup;
|
||||
pub use self::setup::*;
|
||||
|
@ -1,11 +1,12 @@
|
||||
use crate::{cli::*, cli_types::*};
|
||||
use crate::commands::BuildCommand;
|
||||
use crate::compiler::Compiler;
|
||||
use crate::commands::SetupCommand;
|
||||
use crate::errors::CLIError;
|
||||
|
||||
use snarkos_curves::bls12_377::Fr;
|
||||
use snarkos_algorithms::snark::{create_random_proof, verify_proof};
|
||||
|
||||
use clap::ArgMatches;
|
||||
use rand::thread_rng;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RunCommand;
|
||||
@ -28,76 +29,34 @@ impl CLI for RunCommand {
|
||||
|
||||
#[cfg_attr(tarpaulin, skip)]
|
||||
fn output(options: Self::Options) -> Result<(), CLIError> {
|
||||
let circuit = BuildCommand::output(options)?;
|
||||
let (circuit, parameters, prepared_verifying_key) = SetupCommand::output(options)?;
|
||||
|
||||
fn run(circuit: Compiler<Fr>) {
|
||||
let rng = &mut thread_rng();
|
||||
|
||||
use snarkos_algorithms::snark::{create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof};
|
||||
use snarkos_curves::bls12_377::Bls12_377;
|
||||
let mut proving = Duration::new(0, 0);
|
||||
let mut verifying = Duration::new(0, 0);
|
||||
|
||||
use rand::thread_rng;
|
||||
use std::time::{Duration, Instant};
|
||||
let start = Instant::now();
|
||||
let proof = create_random_proof(circuit, ¶meters, rng).unwrap();
|
||||
|
||||
let mut setup = Duration::new(0, 0);
|
||||
let mut proving = Duration::new(0, 0);
|
||||
let mut verifying = Duration::new(0, 0);
|
||||
proving += start.elapsed();
|
||||
|
||||
let rng = &mut thread_rng();
|
||||
// let _inputs: Vec<_> = [1u32; 1].to_vec();
|
||||
|
||||
let start = Instant::now();
|
||||
let start = Instant::now();
|
||||
|
||||
let params = generate_random_parameters::<Bls12_377, _, _>(circuit.clone(), rng).unwrap();
|
||||
let is_success = verify_proof(&prepared_verifying_key, &proof, &[]).unwrap();
|
||||
|
||||
let prepared_verifying_key = prepare_verifying_key::<Bls12_377>(¶ms.vk);
|
||||
verifying += start.elapsed();
|
||||
|
||||
setup += start.elapsed();
|
||||
|
||||
let start = Instant::now();
|
||||
let proof = create_random_proof(circuit, ¶ms, rng).unwrap();
|
||||
|
||||
proving += start.elapsed();
|
||||
|
||||
// let _inputs: Vec<_> = [1u32; 1].to_vec();
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
let is_success = verify_proof(&prepared_verifying_key, &proof, &[]).unwrap();
|
||||
|
||||
verifying += start.elapsed();
|
||||
|
||||
println!(" ");
|
||||
println!(" Setup time : {:?} milliseconds", setup.as_millis());
|
||||
println!(" Prover time : {:?} milliseconds", proving.as_millis());
|
||||
println!(
|
||||
" Verifier time : {:?} milliseconds",
|
||||
verifying.as_millis()
|
||||
);
|
||||
println!(" Verifier output : {}", is_success);
|
||||
println!(" ");
|
||||
}
|
||||
|
||||
run(circuit);
|
||||
|
||||
// let source_files = SourceDirectory::files(&package_path)?;
|
||||
// BuildDirectory::create(&circuit_path).map_err(Error::BuildDirectory)?;
|
||||
// DataDirectory::create(&circuit_path).map_err(Error::DataDirectory)?;
|
||||
|
||||
// Compiler::build(
|
||||
// self.verbosity,
|
||||
// &self.witness,
|
||||
// &self.public_data,
|
||||
// &self.circuit,
|
||||
// &source_file_paths,
|
||||
// )
|
||||
// .map_err(Error::Compiler)?;
|
||||
//
|
||||
// VirtualMachine::run(
|
||||
// self.verbosity,
|
||||
// &self.circuit,
|
||||
// &self.witness,
|
||||
// &self.public_data,
|
||||
// )
|
||||
// .map_err(Error::VirtualMachine)?;
|
||||
println!(" ");
|
||||
println!(" Prover time : {:?} milliseconds", proving.as_millis());
|
||||
println!(
|
||||
" Verifier time : {:?} milliseconds",
|
||||
verifying.as_millis()
|
||||
);
|
||||
println!(" Verifier output : {}", is_success);
|
||||
println!(" ");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
50
leo/commands/setup.rs
Normal file
50
leo/commands/setup.rs
Normal file
@ -0,0 +1,50 @@
|
||||
use crate::{cli::*, cli_types::*};
|
||||
use crate::commands::BuildCommand;
|
||||
use crate::compiler::Compiler;
|
||||
use crate::errors::CLIError;
|
||||
|
||||
use snarkos_algorithms::snark::{generate_random_parameters, prepare_verifying_key, Parameters, PreparedVerifyingKey};
|
||||
use snarkos_curves::bls12_377::{Bls12_377, Fr};
|
||||
|
||||
use clap::ArgMatches;
|
||||
use rand::thread_rng;
|
||||
use std::time::Instant;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SetupCommand;
|
||||
|
||||
impl CLI for SetupCommand {
|
||||
type Options = ();
|
||||
type Output = (Compiler<Fr>, Parameters<Bls12_377>, PreparedVerifyingKey<Bls12_377>);
|
||||
|
||||
const NAME: NameType = "setup";
|
||||
const ABOUT: AboutType = "Run a program setup";
|
||||
const ARGUMENTS: &'static [ArgumentType] = &[];
|
||||
const FLAGS: &'static [FlagType] = &[];
|
||||
const OPTIONS: &'static [OptionType] = &[];
|
||||
const SUBCOMMANDS: &'static [SubCommandType] = &[];
|
||||
|
||||
#[cfg_attr(tarpaulin, skip)]
|
||||
fn parse(_arguments: &ArgMatches) -> Result<Self::Options, CLIError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg_attr(tarpaulin, skip)]
|
||||
fn output(options: Self::Options) -> Result<Self::Output, CLIError> {
|
||||
let circuit = BuildCommand::output(options)?;
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
let rng = &mut thread_rng();
|
||||
let parameters = generate_random_parameters::<Bls12_377, _, _>(circuit.clone(), rng).unwrap();
|
||||
let prepared_verifying_key = prepare_verifying_key::<Bls12_377>(¶meters.vk);
|
||||
|
||||
let finish = start.elapsed();
|
||||
|
||||
println!(" ");
|
||||
println!(" Setup time : {:?} milliseconds", finish.as_millis());
|
||||
println!(" ");
|
||||
|
||||
Ok((circuit, parameters, prepared_verifying_key))
|
||||
}
|
||||
}
|
15
leo/main.rs
15
leo/main.rs
@ -22,25 +22,24 @@ fn main() -> Result<(), CLIError> {
|
||||
NewCommand::new(),
|
||||
InitCommand::new(),
|
||||
BuildCommand::new(),
|
||||
SetupCommand::new(),
|
||||
RunCommand::new(),
|
||||
])
|
||||
.set_term_width(0)
|
||||
.get_matches();
|
||||
|
||||
match arguments.subcommand() {
|
||||
("new", Some(arguments)) => {
|
||||
NewCommand::output(NewCommand::parse(arguments)?)
|
||||
},
|
||||
("init", Some(arguments)) => {
|
||||
InitCommand::output(InitCommand::parse(arguments)?)
|
||||
},
|
||||
("new", Some(arguments)) => NewCommand::output(NewCommand::parse(arguments)?),
|
||||
("init", Some(arguments)) => InitCommand::output(InitCommand::parse(arguments)?),
|
||||
("build", Some(arguments)) => {
|
||||
BuildCommand::output(BuildCommand::parse(arguments)?)?;
|
||||
Ok(())
|
||||
},
|
||||
("run", Some(arguments)) => {
|
||||
RunCommand::output(RunCommand::parse(arguments)?)
|
||||
("setup", Some(arguments)) => {
|
||||
SetupCommand::output(SetupCommand::parse(arguments)?)?;
|
||||
Ok(())
|
||||
},
|
||||
("run", Some(arguments)) => RunCommand::output(RunCommand::parse(arguments)?),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user