From b6160fcd1b3c8d611116d83eb4eecfe83635d826 Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Fri, 28 Jun 2019 15:57:17 +0300 Subject: [PATCH] add some traits to efficiently work with Poseidon hash for now --- src/cs.rs | 4 ++-- src/sonic/tests/sonics.rs | 7 ++++--- src/sonic/unhelped/aggregate.rs | 12 ++++++++++++ tests/mimc.rs | 8 +++++--- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/cs.rs b/src/cs.rs index fb9ed93..9f68c7e 100644 --- a/src/cs.rs +++ b/src/cs.rs @@ -20,7 +20,7 @@ pub trait Circuit { } /// Represents a variable in our constraint system. -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] pub struct Variable(pub(crate) Index); impl Variable { @@ -39,7 +39,7 @@ impl Variable { /// Represents the index of either an input variable or /// auxillary variable. -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Debug, Hash, Eq)] pub enum Index { Input(usize), Aux(usize) diff --git a/src/sonic/tests/sonics.rs b/src/sonic/tests/sonics.rs index 0d077fb..3c406df 100644 --- a/src/sonic/tests/sonics.rs +++ b/src/sonic/tests/sonics.rs @@ -31,9 +31,9 @@ use crate::{ SynthesisError }; -const MIMC_ROUNDS: usize = 322; +// const MIMC_ROUNDS: usize = 322; -// const MIMC_ROUNDS: usize = 1000000; +const MIMC_ROUNDS: usize = 1000000; fn mimc( mut xl: E::Fr, @@ -471,7 +471,8 @@ fn test_succinct_sonic_mimc() { let srs_alpha = Fr::from_str("23728792").unwrap(); println!("making srs"); let start = Instant::now(); - let srs = SRS::::dummy(830564, srs_x, srs_alpha); + // let srs = SRS::::dummy(830564, srs_x, srs_alpha); + let srs = SRS::::dummy(40000000, srs_x, srs_alpha); println!("done in {:?}", start.elapsed()); { diff --git a/src/sonic/unhelped/aggregate.rs b/src/sonic/unhelped/aggregate.rs index 26b1dfa..1375c4c 100644 --- a/src/sonic/unhelped/aggregate.rs +++ b/src/sonic/unhelped/aggregate.rs @@ -132,6 +132,8 @@ pub fn create_aggregate_on_srs_using_information, S: Sy ) }; + println!("Commit and opening of for s(z, w) taken {:?}", start.elapsed()); + // now we need signature of correct computation. For this purpose // verifier already knows specialized SRS, so we can just commit to // s1 and s2 parts of such signature to get `w` and later open at this point! @@ -141,10 +143,20 @@ pub fn create_aggregate_on_srs_using_information, S: Sy // TODO: Precompute! // this will internally synthesize a circuit and structure of permutations + let start = Instant::now(); + let s2_eval = S2Eval::new(n); let s2_proof = s2_eval.evaluate(z, w, &srs); + + println!("S2 proof taken {:?}", start.elapsed()); + let start = Instant::now(); + let permutation_structure = create_permutation_structure(circuit); let (non_permuted_coeffs, permutations) = permutation_structure.create_permutation_vectors(); + + println!("Permutation vectors synthesis taken {:?}", start.elapsed()); + let start = Instant::now(); + let signature = PermutationArgument::make_signature( non_permuted_coeffs, permutations, diff --git a/tests/mimc.rs b/tests/mimc.rs index 383d8a7..b80cb7c 100644 --- a/tests/mimc.rs +++ b/tests/mimc.rs @@ -38,7 +38,9 @@ use bellman_ce::groth16::{ verify_proof, }; -const MIMC_ROUNDS: usize = 322; +// const MIMC_ROUNDS: usize = 322; + +const MIMC_ROUNDS: usize = 1000000; /// This is an implementation of MiMC, specifically a /// variant named `LongsightF322p3` for BLS12-381. @@ -171,7 +173,7 @@ impl<'a, E: Engine> Circuit for MiMCDemo<'a, E> { } #[test] -fn test_mimc() { +fn test_mimc_bls12() { // This may not be cryptographically safe, use // `OsRng` (for example) in production software. let rng = &mut thread_rng(); @@ -198,7 +200,7 @@ fn test_mimc() { println!("Creating proofs..."); // Let's benchmark stuff! - const SAMPLES: u32 = 50; + const SAMPLES: u32 = 1; let mut total_proving = Duration::new(0, 0); let mut total_verifying = Duration::new(0, 0);