Skip to content

Commit

Permalink
add some traits to efficiently work with Poseidon hash for now
Browse files Browse the repository at this point in the history
  • Loading branch information
shamatar committed Jun 28, 2019
1 parent dc47502 commit b6160fc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/cs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait Circuit<E: Engine> {
}

/// 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 {
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/sonic/tests/sonics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E: Engine>(
mut xl: E::Fr,
Expand Down Expand Up @@ -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::<Bls12>::dummy(830564, srs_x, srs_alpha);
// let srs = SRS::<Bls12>::dummy(830564, srs_x, srs_alpha);
let srs = SRS::<Bls12>::dummy(40000000, srs_x, srs_alpha);
println!("done in {:?}", start.elapsed());

{
Expand Down
12 changes: 12 additions & 0 deletions src/sonic/unhelped/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ pub fn create_aggregate_on_srs_using_information<E: Engine, C: Circuit<E>, 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!
Expand All @@ -141,10 +143,20 @@ pub fn create_aggregate_on_srs_using_information<E: Engine, C: Circuit<E>, 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,
Expand Down
8 changes: 5 additions & 3 deletions tests/mimc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -171,7 +173,7 @@ impl<'a, E: Engine> Circuit<E> 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();
Expand All @@ -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);

Expand Down

0 comments on commit b6160fc

Please sign in to comment.