Skip to content

Commit ce4f528

Browse files
committed
fix: parallellize pp generation
1 parent f83d067 commit ce4f528

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/provider/non_hiding_kzg.rs

+25-18
Original file line numberDiff line numberDiff line change
@@ -136,27 +136,34 @@ impl<E: Engine> UVUniversalKZGParam<E> {
136136
let g = E::G1::random(&mut rng);
137137
let h = E::G2::random(rng);
138138

139-
let powers_of_g_projective = (0..=max_degree)
140-
.scan(g, |acc, _| {
141-
let val = *acc;
142-
*acc *= beta;
143-
Some(val)
144-
})
145-
.collect::<Vec<E::G1>>();
139+
let (powers_of_g_projective, powers_of_h_projective) = rayon::join(
140+
|| {
141+
(0..=max_degree)
142+
.scan(g, |acc, _| {
143+
let val = *acc;
144+
*acc *= beta;
145+
Some(val)
146+
})
147+
.collect::<Vec<E::G1>>()
148+
},
149+
|| {
150+
(0..=max_degree)
151+
.scan(h, |acc, _| {
152+
let val = *acc;
153+
*acc *= beta;
154+
Some(val)
155+
})
156+
.collect::<Vec<E::G2>>()
157+
},
158+
);
146159

147160
let mut powers_of_g = vec![E::G1Affine::identity(); powers_of_g_projective.len()];
148-
E::G1::batch_normalize(&powers_of_g_projective, &mut powers_of_g);
149-
150-
let powers_of_h_projective = (0..=max_degree)
151-
.scan(h, |acc, _| {
152-
let val = *acc;
153-
*acc *= beta;
154-
Some(val)
155-
})
156-
.collect::<Vec<E::G2>>();
157-
158161
let mut powers_of_h = vec![E::G2Affine::identity(); powers_of_h_projective.len()];
159-
E::G2::batch_normalize(&powers_of_h_projective, &mut powers_of_h);
162+
163+
rayon::join(
164+
|| E::G1::batch_normalize(&powers_of_g_projective, &mut powers_of_g),
165+
|| E::G2::batch_normalize(&powers_of_h_projective, &mut powers_of_h),
166+
);
160167

161168
Self {
162169
powers_of_g,

0 commit comments

Comments
 (0)