Skip to content

Commit

Permalink
fix: parallellize pp generation
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed Oct 24, 2023
1 parent 15eeee9 commit 5d2f846
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/provider/non_hiding_kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,27 +136,34 @@ impl<E: Engine> UVUniversalKZGParam<E> {
let g = E::G1::random(&mut rng);
let h = E::G2::random(rng);

let powers_of_g_projective = (0..=max_degree)
.scan(g, |acc, _| {
let val = *acc;
*acc *= beta;
Some(val)
})
.collect::<Vec<E::G1>>();
let (powers_of_g_projective, powers_of_h_projective) = rayon::join(
|| {
(0..=max_degree)
.scan(g, |acc, _| {
let val = *acc;
*acc *= beta;
Some(val)
})
.collect::<Vec<E::G1>>()
},
|| {
(0..=max_degree)
.scan(h, |acc, _| {
let val = *acc;
*acc *= beta;
Some(val)
})
.collect::<Vec<E::G2>>()
},
);

let mut powers_of_g = vec![E::G1Affine::identity(); powers_of_g_projective.len()];
E::G1::batch_normalize(&powers_of_g_projective, &mut powers_of_g);

let powers_of_h_projective = (0..=max_degree)
.scan(h, |acc, _| {
let val = *acc;
*acc *= beta;
Some(val)
})
.collect::<Vec<E::G2>>();

let mut powers_of_h = vec![E::G2Affine::identity(); powers_of_h_projective.len()];
E::G2::batch_normalize(&powers_of_h_projective, &mut powers_of_h);

rayon::join(
|| E::G1::batch_normalize(&powers_of_g_projective, &mut powers_of_g),
|| E::G2::batch_normalize(&powers_of_h_projective, &mut powers_of_h),
);

Self {
powers_of_g,
Expand Down

0 comments on commit 5d2f846

Please sign in to comment.