1
- use std:: { marker:: PhantomData , ops:: Deref , sync:: Arc } ;
1
+ use std:: { iter :: zip , marker:: PhantomData , ops:: Deref , sync:: Arc } ;
2
2
3
3
use derivative:: Derivative ;
4
- use itertools:: { zip_eq, Itertools } ;
4
+ use itertools:: { izip , zip_eq, Itertools } ;
5
5
use opener:: OpeningProver ;
6
6
use p3_challenger:: FieldChallenger ;
7
7
use p3_commit:: { Pcs , PolynomialSpace } ;
@@ -18,7 +18,7 @@ use super::{
18
18
} ,
19
19
} ;
20
20
use crate :: {
21
- air_builders:: symbolic:: { SymbolicConstraints , SymbolicExpressionDag } ,
21
+ air_builders:: symbolic:: SymbolicConstraints ,
22
22
config:: {
23
23
Com , PcsProof , PcsProverData , RapPhaseSeqPartialProof , RapPhaseSeqProvingKey ,
24
24
StarkGenericConfig , Val ,
@@ -231,43 +231,112 @@ impl<SC: StarkGenericConfig> hal::RapPartialProver<CpuBackend<SC>> for CpuDevice
231
231
}
232
232
}
233
233
234
- type RapMatrixView < SC > =
235
- RapView < Arc < RowMajorMatrix < Val < SC > > > , Val < SC > , <SC as StarkGenericConfig >:: Challenge > ;
236
-
237
234
impl < SC : StarkGenericConfig > hal:: QuotientCommitter < CpuBackend < SC > > for CpuDevice < ' _ , SC > {
238
- fn get_extended_matrix (
239
- & self ,
240
- view : & PcsData < SC > ,
241
- matrix_idx : usize ,
242
- quotient_degree : u8 ,
243
- ) -> Option < Arc < RowMajorMatrix < Val < SC > > > > {
244
- let pcs = self . pcs ( ) ;
245
- let log_trace_height = * view. log_trace_heights . get ( matrix_idx) ?;
246
- let trace_domain = pcs. natural_domain_for_degree ( 1usize << log_trace_height) ;
247
- let quotient_domain =
248
- trace_domain. create_disjoint_domain ( trace_domain. size ( ) * quotient_degree as usize ) ;
249
- // NOTE[jpw]: (perf) this clones under the hood!
250
- let lde_matrix = self
251
- . pcs ( )
252
- . get_evaluations_on_domain ( & view. data , matrix_idx, quotient_domain)
253
- . to_row_major_matrix ( ) ;
254
- Some ( Arc :: new ( lde_matrix) )
255
- }
256
-
257
235
fn eval_and_commit_quotient (
258
236
& self ,
259
237
challenger : & mut SC :: Challenger ,
260
- constraints : & [ & SymbolicExpressionDag < Val < SC > > ] ,
261
- extended_views : Vec < RapMatrixView < SC > > ,
262
- quotient_degrees : & [ u8 ] ,
238
+ pk_views : & [ DeviceStarkProvingKey < CpuBackend < SC > > ] ,
239
+ public_values : & [ Vec < Val < SC > > ] ,
240
+ cached_views_per_air : & [ Vec <
241
+ SingleCommitPreimage < & Arc < RowMajorMatrix < Val < SC > > > , & PcsData < SC > > ,
242
+ > ] ,
243
+ common_main_pcs_data : & PcsData < SC > ,
244
+ prover_data_after : & ProverDataAfterRapPhases < CpuBackend < SC > > ,
263
245
) -> ( Com < SC > , PcsData < SC > ) {
246
+ let pcs = self . pcs ( ) ;
264
247
// Generate `alpha` challenge
265
248
let alpha: SC :: Challenge = challenger. sample_ext_element ( ) ;
266
249
tracing:: debug!( "alpha: {alpha:?}" ) ;
250
+ // Prepare extended views:
251
+ let mut common_main_idx = 0 ;
252
+ let extended_views = izip ! ( pk_views, cached_views_per_air, public_values)
253
+ . enumerate ( )
254
+ . map ( |( i, ( pk, cached_views, pvs) ) | {
255
+ let quotient_degree = pk. vk . quotient_degree ;
256
+ let log_trace_height = if pk. vk . has_common_main ( ) {
257
+ common_main_pcs_data. log_trace_heights [ common_main_idx]
258
+ } else {
259
+ log2_strict_usize ( cached_views[ 0 ] . trace . height ( ) ) as u8
260
+ } ;
261
+ let trace_domain = pcs. natural_domain_for_degree ( 1usize << log_trace_height) ;
262
+ let quotient_domain = trace_domain
263
+ . create_disjoint_domain ( trace_domain. size ( ) * quotient_degree as usize ) ;
264
+ // **IMPORTANT**: the return type of `get_evaluations_on_domain` is a matrix view. DO NOT call to_row_major_matrix as this will allocate new memory
265
+ let preprocessed = pk. preprocessed_data . as_ref ( ) . map ( |cv| {
266
+ pcs. get_evaluations_on_domain (
267
+ & cv. data . data ,
268
+ cv. matrix_idx as usize ,
269
+ quotient_domain,
270
+ )
271
+ } ) ;
272
+ let mut partitioned_main: Vec < _ > = cached_views
273
+ . iter ( )
274
+ . map ( |cv| {
275
+ pcs. get_evaluations_on_domain (
276
+ & cv. data . data ,
277
+ cv. matrix_idx as usize ,
278
+ quotient_domain,
279
+ )
280
+ } )
281
+ . collect ( ) ;
282
+ if pk. vk . has_common_main ( ) {
283
+ partitioned_main. push ( pcs. get_evaluations_on_domain (
284
+ & common_main_pcs_data. data ,
285
+ common_main_idx,
286
+ quotient_domain,
287
+ ) ) ;
288
+ common_main_idx += 1 ;
289
+ }
290
+ let pair = PairView {
291
+ log_trace_height,
292
+ preprocessed,
293
+ partitioned_main,
294
+ public_values : pvs. to_vec ( ) ,
295
+ } ;
296
+ let mut per_phase = zip (
297
+ & prover_data_after. committed_pcs_data_per_phase ,
298
+ & prover_data_after. rap_views_per_phase ,
299
+ )
300
+ . map ( |( ( _, pcs_data) , rap_views) | -> Option < _ > {
301
+ let rap_view = rap_views. get ( i) ?;
302
+ let matrix_idx = rap_view. inner ?;
303
+ let extended_matrix =
304
+ pcs. get_evaluations_on_domain ( & pcs_data. data , matrix_idx, quotient_domain) ;
305
+ Some ( RapSinglePhaseView {
306
+ inner : Some ( extended_matrix) ,
307
+ challenges : rap_view. challenges . clone ( ) ,
308
+ exposed_values : rap_view. exposed_values . clone ( ) ,
309
+ } )
310
+ } )
311
+ . collect_vec ( ) ;
312
+ while let Some ( last) = per_phase. last ( ) {
313
+ if last. is_none ( ) {
314
+ per_phase. pop ( ) ;
315
+ } else {
316
+ break ;
317
+ }
318
+ }
319
+ let per_phase = per_phase
320
+ . into_iter ( )
321
+ . map ( |v| v. unwrap_or_default ( ) )
322
+ . collect ( ) ;
323
+
324
+ RapView { pair, per_phase }
325
+ } )
326
+ . collect_vec ( ) ;
267
327
328
+ let ( constraints, quotient_degrees) : ( Vec < _ > , Vec < _ > ) = pk_views
329
+ . iter ( )
330
+ . map ( |pk| {
331
+ (
332
+ & pk. vk . symbolic_constraints . constraints ,
333
+ pk. vk . quotient_degree ,
334
+ )
335
+ } )
336
+ . unzip ( ) ;
268
337
let qc = QuotientCommitter :: new ( self . pcs ( ) , alpha) ;
269
338
let quotient_values = metrics_span ( "quotient_poly_compute_time_ms" , || {
270
- qc. quotient_values ( constraints, extended_views, quotient_degrees)
339
+ qc. quotient_values ( & constraints, extended_views, & quotient_degrees)
271
340
} ) ;
272
341
273
342
// Commit to quotient polynomials. One shared commit for all quotient polynomials
0 commit comments