@@ -125,15 +125,15 @@ impl<S: SpartanExtensionField> DensePolynomialPqx<S> {
125125 match mode {
126126 MODE_P => { self . bound_poly_p ( r) ; }
127127 MODE_Q => { self . bound_poly_q ( r) ; }
128- MODE_W => { self . bound_poly_w ( r) ; }
129- MODE_X => { self . bound_poly_x ( r) ; }
128+ MODE_W => { self . bound_poly_w_parallel ( r) ; }
129+ MODE_X => { self . bound_poly_x_parallel ( r) ; }
130130 _ => { panic ! ( "DensePolynomialPqx bound failed: unrecognized mode {}!" , mode) ; }
131131 }
132132 }
133133
134134 // Bound the last variable of "p" section to r
135135 // We are only allowed to bound "p" if we have bounded the entire q and x section
136- pub fn bound_poly_p ( & mut self , r : & S ) {
136+ fn bound_poly_p ( & mut self , r : & S ) {
137137 assert ! ( self . num_vars_p >= 1 ) ;
138138 assert_eq ! ( self . num_vars_q, 0 ) ;
139139 assert_eq ! ( self . num_vars_x, 0 ) ;
@@ -150,7 +150,7 @@ impl<S: SpartanExtensionField> DensePolynomialPqx<S> {
150150 }
151151
152152 // Bound the last variable of "q" section to r
153- pub fn bound_poly_q ( & mut self , r : & S ) {
153+ fn bound_poly_q ( & mut self , r : & S ) {
154154 assert ! ( self . num_vars_q >= 1 ) ;
155155 for p in 0 ..self . num_instances {
156156 let new_num_proofs = self . num_proofs [ p] . div_ceil ( 2 ) ;
@@ -170,7 +170,29 @@ impl<S: SpartanExtensionField> DensePolynomialPqx<S> {
170170
171171 // Bound the last variable of "w" section to r
172172 // We are only allowed to bound "w" if we have bounded the entire x section
173- pub fn bound_poly_w ( & mut self , r : & S ) {
173+ fn bound_poly_w_parallel ( & mut self , r : & S ) {
174+ let ZERO = S :: field_zero ( ) ;
175+ assert ! ( self . num_vars_w >= 1 ) ;
176+ assert_eq ! ( self . num_vars_x, 0 ) ;
177+ let new_num_witness_secs = self . num_witness_secs . div_ceil ( 2 ) ;
178+ let Z = std:: mem:: take ( & mut self . Z ) ;
179+ self . Z = Z . into_iter ( ) . map ( |Z_p | {
180+ Z_p . into_par_iter ( ) . map ( |mut Z_pq | {
181+ for w in 0 ..self . num_witness_secs {
182+ let Z_low = if 2 * w >= self . num_witness_secs { ZERO } else { Z_pq [ 2 * w] [ 0 ] } ;
183+ let Z_high = if 2 * w + 1 >= self . num_witness_secs { ZERO } else { Z_pq [ 2 * w + 1 ] [ 0 ] } ;
184+ Z_pq [ w] [ 0 ] = Z_low + r. clone ( ) * ( Z_high - Z_low ) ;
185+ }
186+ Z_pq
187+ } ) . collect :: < Vec < Vec < Vec < S > > > > ( )
188+ } ) . collect :: < Vec < Vec < Vec < Vec < S > > > > > ( ) ;
189+ self . num_witness_secs = new_num_witness_secs;
190+ self . num_vars_w -= 1 ;
191+ }
192+
193+ // Bound the last variable of "w" section to r
194+ // We are only allowed to bound "w" if we have bounded the entire x section
195+ fn _bound_poly_w ( & mut self , r : & S ) {
174196 assert ! ( self . num_vars_w >= 1 ) ;
175197 assert_eq ! ( self . num_vars_x, 0 ) ;
176198 let new_num_witness_secs = self . num_witness_secs . div_ceil ( 2 ) ;
@@ -188,7 +210,33 @@ impl<S: SpartanExtensionField> DensePolynomialPqx<S> {
188210}
189211
190212 // Bound the last variable of "x" section to r
191- pub fn bound_poly_x ( & mut self , r : & S ) {
213+ fn bound_poly_x_parallel ( & mut self , r : & S ) {
214+ let ZERO = S :: field_zero ( ) ;
215+ let new_num_inputs: Vec < Vec < usize > > = self . num_inputs . iter ( ) . map ( |p|
216+ p. iter ( ) . map ( |w| w. div_ceil ( 2 ) ) . collect ( )
217+ ) . collect ( ) ;
218+ // assert!(self.num_vars_x >= 1);
219+ let Z = std:: mem:: take ( & mut self . Z ) ;
220+ self . Z = Z . into_iter ( ) . enumerate ( ) . map ( |( p, Z_p ) | {
221+ Z_p . into_par_iter ( ) . map ( |mut Z_pq | {
222+ for w in 0 ..self . num_witness_secs {
223+ for x in 0 ..new_num_inputs[ p] [ w] {
224+ let Z_low = if 2 * x >= self . num_inputs [ p] [ w] { ZERO } else { Z_pq [ w] [ 2 * x] } ;
225+ let Z_high = if 2 * x + 1 >= self . num_inputs [ p] [ w] { ZERO } else { Z_pq [ w] [ 2 * x + 1 ] } ;
226+ Z_pq [ w] [ x] = Z_low + r. clone ( ) * ( Z_high - Z_low ) ;
227+ }
228+ }
229+ Z_pq
230+ } ) . collect :: < Vec < Vec < Vec < S > > > > ( )
231+ } ) . collect :: < Vec < Vec < Vec < Vec < S > > > > > ( ) ;
232+ self . num_inputs = new_num_inputs;
233+ if self . num_vars_x >= 1 {
234+ self . num_vars_x -= 1 ;
235+ }
236+ }
237+
238+ // Bound the last variable of "x" section to r
239+ fn _bound_poly_x ( & mut self , r : & S ) {
192240 // assert!(self.num_vars_x >= 1);
193241 for p in 0 ..self . num_instances {
194242 for w in 0 ..self . num_witness_secs {
@@ -293,14 +341,14 @@ impl<S: SpartanExtensionField> DensePolynomialPqx<S> {
293341 // Bound the entire "w" section to r_w in reverse
294342 pub fn bound_poly_vars_rw ( & mut self , r_w : & [ S ] ) {
295343 for r in r_w {
296- self . bound_poly_w ( r) ;
344+ self . bound_poly_w_parallel ( r) ;
297345 }
298346 }
299347
300348 // Bound the entire "x_rev" section to r_x
301349 pub fn bound_poly_vars_rx ( & mut self , r_x : & [ S ] ) {
302350 for r in r_x {
303- self . bound_poly_x ( r) ;
351+ self . bound_poly_x_parallel ( r) ;
304352 }
305353 }
306354
0 commit comments