Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel SRS creation #1300

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions poly-commitment/src/srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use ark_poly::{EvaluationDomain, Radix2EvaluationDomain as D};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use blake2::{Blake2b512, Digest};
use groupmap::GroupMap;
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use std::array;
Expand Down Expand Up @@ -289,3 +290,37 @@ where
}
}
}

impl<G: CommitmentCurve> SRS<G>
where
<G as CommitmentCurve>::Map: Sync,
G::BaseField: PrimeField,
{
/// This function creates SRS instance for circuits with number of rows up to `depth`.
pub fn create_parallel(depth: usize) -> Self {
let m = G::Map::setup();

let g: Vec<_> = (0..depth)
.into_par_iter()
.map(|i| {
let mut h = Blake2b512::new();
h.update((i as u32).to_be_bytes());
point_of_random_bytes(&m, &h.finalize())
})
.collect();

const MISC: usize = 1;
let [h]: [G; MISC] = array::from_fn(|i| {
let mut h = Blake2b512::new();
h.update("srs_misc".as_bytes());
h.update((i as u32).to_be_bytes());
point_of_random_bytes(&m, &h.finalize())
});

SRS {
g,
h,
lagrange_bases: HashMap::new(),
}
}
}