delete benchmark

This commit is contained in:
collin 2020-06-01 17:54:39 -07:00
parent 8852c17857
commit 01cc8e3066
6 changed files with 1 additions and 184 deletions

14
Cargo.lock generated
View File

@ -467,20 +467,6 @@ dependencies = [
"toml",
]
[[package]]
name = "leo-benchmark"
version = "0.1.0"
dependencies = [
"from-pest",
"leo-compiler",
"rand",
"snarkos-algorithms",
"snarkos-curves",
"snarkos-errors",
"snarkos-gadgets",
"snarkos-models",
]
[[package]]
name = "leo-compiler"
version = "0.1.0"

View File

@ -13,7 +13,7 @@ name = "leo"
path = "leo/main.rs"
[workspace]
members = [ "benchmark", "compiler" ]
members = [ "compiler" ]
[dependencies]
leo-compiler = { path = "compiler", version = "0.1.0" }

View File

@ -1,17 +0,0 @@
[package]
name = "leo-benchmark"
version = "0.1.0"
authors = ["The Aleo Team <hello@aleo.org>"]
edition = "2018"
[dependencies]
leo-compiler = { path = "../compiler", version = "0.1.0" }
snarkos-algorithms = { path = "../../snarkOS/algorithms", version = "0.8.0" }
snarkos-curves = { path = "../../snarkOS/curves", version = "0.8.0" }
snarkos-errors = { path = "../../snarkOS/errors", version = "0.8.0" }
snarkos-gadgets = { path = "../../snarkOS/gadgets", version = "0.8.0" }
snarkos-models = { path = "../../snarkOS/models", version = "0.8.0" }
from-pest = { version = "0.3.1" }
rand = { version = "0.7" }

View File

@ -1,10 +0,0 @@
function test(mut a: u32) {
a = 0;
}
function main() -> u32 {
let a = 1;
test(a);
return a // <- returns 1
}

View File

@ -1,8 +0,0 @@
struct Point {
u32 x
u32 y
}
function test() -> (u32) {
return 5
}

View File

@ -1,134 +0,0 @@
use leo_compiler::{self, ast, errors::CompilerError, InputValue, Program};
use from_pest::FromPest;
use rand::thread_rng;
use snarkos_algorithms::snark::{
create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof,
};
use snarkos_curves::bls12_377::{Bls12_377, Fr};
use snarkos_errors::gadgets::SynthesisError;
use snarkos_models::{
curves::{Field, PrimeField},
gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem},
};
use std::{
fs,
marker::PhantomData,
time::{Duration, Instant},
};
#[derive(Clone)]
pub struct Benchmark<F: Field + PrimeField> {
program: Program<F>,
parameters: Vec<Option<InputValue<F>>>,
_engine: PhantomData<F>,
}
impl<F: Field + PrimeField> Benchmark<F> {
pub fn new() -> Self {
Self {
program: Program::new(),
parameters: vec![],
_engine: PhantomData,
}
}
pub fn evaluate_program(&mut self) -> Result<(), CompilerError> {
// Read in file as string
let unparsed_file = fs::read_to_string("simple.leo").expect("cannot read file");
// Parse the file using leo.pest
let mut file = ast::parse(&unparsed_file).expect("unsuccessful parse");
// Build the abstract syntax tree
let syntax_tree = ast::File::from_pest(&mut file).expect("infallible");
// Build a leo program from the syntax tree
self.program = Program::<F>::from(syntax_tree, "simple".into());
self.parameters = vec![None; self.program.num_parameters];
println!(" compiled: {:#?}\n", self.program);
Ok(())
}
}
impl<F: Field + PrimeField> ConstraintSynthesizer<F> for Benchmark<F> {
fn generate_constraints<CS: ConstraintSystem<F>>(
self,
cs: &mut CS,
) -> Result<(), SynthesisError> {
let _res = leo_compiler::generate_constraints(cs, self.program, self.parameters).unwrap();
println!(" Result: {}", _res);
// Write results to file or something
Ok(())
}
}
fn main() {
let mut setup = Duration::new(0, 0);
let mut proving = Duration::new(0, 0);
let mut verifying = Duration::new(0, 0);
let rng = &mut thread_rng();
let start = Instant::now();
// Load and compile program
let mut program = Benchmark::<Fr>::new();
program.evaluate_program().unwrap();
// Generate proof parameters
let params = { generate_random_parameters::<Bls12_377, _, _>(program.clone(), rng).unwrap() };
let prepared_verifying_key = prepare_verifying_key::<Bls12_377>(&params.vk);
setup += start.elapsed();
let start = Instant::now();
// Set main function arguments in compiled program
// let argument = Some(InputValue::Field(Fr::one()));
// let bool_true = InputValue::Boolean(true);
// let array = InputValue::Array(vec![bool_true.clone(), bool_true.clone(), bool_true.clone()]);
// let argument = Some(array);
//
// program.parameters = vec![argument];
// Generate proof
let proof = create_random_proof(program, &params, rng).unwrap();
proving += start.elapsed();
let start = Instant::now();
// let public_input = Fr::one();
// Verify proof
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!(" ");
// let mut cs = TestConstraintSystem::<Fr>::new();
//
// println!("\n satisfied: {:?}", cs.is_satisfied());
//
// println!(
// "\n number of constraints for input: {}",
// cs.num_constraints()
// );
//
}