@@ -9,6 +9,8 @@ use halo2_proofs::{
9
9
} ;
10
10
use itertools:: Itertools ;
11
11
use rand:: Rng ;
12
+ #[ cfg( not( feature = "disable_proof_aggregation" ) ) ]
13
+ use std:: rc:: Rc ;
12
14
use std:: { env, fs:: File } ;
13
15
14
16
#[ cfg( not( feature = "disable_proof_aggregation" ) ) ]
@@ -156,24 +158,59 @@ impl Circuit<Fr> for AggregationCircuit {
156
158
157
159
let timer = start_timer ! ( || "aggregation" ) ;
158
160
161
+ // load lookup table in range config
162
+ config
163
+ . range ( )
164
+ . load_lookup_table ( & mut layouter)
165
+ . expect ( "load range lookup table" ) ;
159
166
// ==============================================
160
167
// Step 1: snark aggregation circuit
161
168
// ==============================================
162
- #[ cfg( not( feature = "disable_proof_aggregation" ) ) ]
163
- let ( accumulator_instances, snark_inputs) = {
164
- config
165
- . range ( )
166
- . load_lookup_table ( & mut layouter)
167
- . expect ( "load range lookup table" ) ;
169
+ #[ cfg( feature = "disable_proof_aggregation" ) ]
170
+ let barycentric = {
171
+ let mut first_pass = halo2_base:: SKIP_FIRST_PASS ;
172
+ layouter. assign_region (
173
+ || "barycentric evaluation" ,
174
+ |region| {
175
+ if first_pass {
176
+ first_pass = false ;
177
+ return Ok ( BarycentricEvaluationCells :: default ( ) ) ;
178
+ }
179
+
180
+ let mut ctx = Context :: new (
181
+ region,
182
+ ContextParams {
183
+ max_rows : config. flex_gate ( ) . max_rows ,
184
+ num_context_ids : 1 ,
185
+ fixed_columns : config. flex_gate ( ) . constants . clone ( ) ,
186
+ } ,
187
+ ) ;
188
+
189
+ let barycentric = config. barycentric . assign2 (
190
+ & mut ctx,
191
+ self . batch_hash . blob . coefficients ,
192
+ self . batch_hash . blob . challenge_digest ,
193
+ self . batch_hash . blob . evaluation ,
194
+ ) ;
195
+
196
+ config. barycentric . scalar . range . finalize ( & mut ctx) ;
197
+ ctx. print_stats ( & [ "barycentric evaluation" ] ) ;
198
+
199
+ Ok ( barycentric)
200
+ } ,
201
+ ) ?
202
+ } ;
168
203
204
+ #[ cfg( not( feature = "disable_proof_aggregation" ) ) ]
205
+ let ( accumulator_instances, snark_inputs, barycentric) = {
169
206
let mut first_pass = halo2_base:: SKIP_FIRST_PASS ;
170
207
171
- let ( accumulator_instances, snark_inputs) = layouter. assign_region (
208
+ let ( accumulator_instances, snark_inputs, barycentric ) = layouter. assign_region (
172
209
|| "aggregation" ,
173
- |region| -> Result < ( Vec < AssignedValue < Fr > > , Vec < AssignedValue < Fr > > ) , Error > {
210
+ |region| {
174
211
if first_pass {
175
212
first_pass = false ;
176
- return Ok ( ( vec ! [ ] , vec ! [ ] ) ) ;
213
+ return Ok ( ( vec ! [ ] , vec ! [ ] , BarycentricEvaluationCells :: default ( ) ) ) ;
177
214
}
178
215
179
216
// stores accumulators for all snarks, including the padded ones
@@ -222,16 +259,26 @@ impl Circuit<Fr> for AggregationCircuit {
222
259
. flat_map ( |instance_column| instance_column. iter ( ) . skip ( ACC_LEN ) ) ,
223
260
) ;
224
261
225
- config. range ( ) . finalize ( & mut loader. ctx_mut ( ) ) ;
262
+ loader. ctx_mut ( ) . print_stats ( & [ "snark aggregation" ] ) ;
263
+
264
+ let mut ctx = Rc :: into_inner ( loader) . unwrap ( ) . into_ctx ( ) ;
265
+ let barycentric = config. barycentric . assign2 (
266
+ & mut ctx,
267
+ self . batch_hash . blob . coefficients ,
268
+ self . batch_hash . blob . challenge_digest ,
269
+ self . batch_hash . blob . evaluation ,
270
+ ) ;
226
271
227
- loader . ctx_mut ( ) . print_stats ( & [ "Range " ] ) ;
272
+ ctx . print_stats ( & [ "barycentric " ] ) ;
228
273
229
- Ok ( ( accumulator_instances, snark_inputs) )
274
+ config. range ( ) . finalize ( & mut ctx) ;
275
+
276
+ Ok ( ( accumulator_instances, snark_inputs, barycentric) )
230
277
} ,
231
278
) ?;
232
279
233
280
assert_eq ! ( snark_inputs. len( ) , MAX_AGG_SNARKS * DIGEST_LEN ) ;
234
- ( accumulator_instances, snark_inputs)
281
+ ( accumulator_instances, snark_inputs, barycentric )
235
282
} ;
236
283
end_timer ! ( timer) ;
237
284
// ==============================================
@@ -242,7 +289,7 @@ impl Circuit<Fr> for AggregationCircuit {
242
289
243
290
let timer = start_timer ! ( || "load aux table" ) ;
244
291
245
- let ( hash_digest_cells, expected_blob_cells, rlc_config_offset ) = {
292
+ let ( hash_digest_cells, expected_blob_cells) = {
246
293
config
247
294
. keccak_circuit_config
248
295
. load_aux_tables ( & mut layouter) ?;
@@ -281,11 +328,7 @@ impl Circuit<Fr> for AggregationCircuit {
281
328
. map_err ( |_e| Error :: ConstraintSystemFailure ) ?;
282
329
283
330
end_timer ! ( timer) ;
284
- (
285
- assigned_batch_hash. hash_output ,
286
- assigned_batch_hash. blob ,
287
- assigned_batch_hash. rlc_config_offset ,
288
- )
331
+ ( assigned_batch_hash. hash_output , assigned_batch_hash. blob )
289
332
} ;
290
333
// digests
291
334
let ( batch_pi_hash_digest, chunk_pi_hash_digests, _potential_batch_data_hash_digest) =
@@ -382,40 +425,13 @@ impl Circuit<Fr> for AggregationCircuit {
382
425
383
426
// blob data config
384
427
{
385
- let mut is_first_pass = true ;
386
- let be = layouter. assign_region (
387
- || "blob data and barycentric evaluation" ,
388
- |region| {
389
- if is_first_pass {
390
- is_first_pass = false ;
391
- return Ok ( BarycentricEvaluationCells :: default ( ) ) ;
392
- }
393
-
394
- let mut ctx = Context :: new (
395
- region,
396
- ContextParams {
397
- max_rows : config. flex_gate ( ) . max_rows ,
398
- num_context_ids : 1 ,
399
- fixed_columns : config. flex_gate ( ) . constants . clone ( ) ,
400
- } ,
401
- ) ;
402
-
403
- Ok ( config. barycentric . assign2 (
404
- & mut ctx,
405
- self . batch_hash . blob . coefficients ,
406
- self . batch_hash . blob . challenge_digest ,
407
- self . batch_hash . blob . evaluation ,
408
- ) )
409
- } ,
410
- ) ?;
411
- let barycentric_assignments = & be. barycentric_assignments ;
412
- let challenge_le = & be. z_le ;
413
- let evaluation_le = & be. y_le ;
428
+ let barycentric_assignments = & barycentric. barycentric_assignments ;
429
+ let challenge_le = & barycentric. z_le ;
430
+ let evaluation_le = & barycentric. y_le ;
414
431
415
432
let blob_data_exports = config. blob_data_config . assign (
416
433
& mut layouter,
417
434
challenges,
418
- rlc_config_offset,
419
435
& config. rlc_config ,
420
436
& self . batch_hash ,
421
437
barycentric_assignments,
@@ -481,14 +497,15 @@ impl CircuitExt<Fr> for AggregationCircuit {
481
497
482
498
fn selectors ( config : & Self :: Config ) -> Vec < Selector > {
483
499
// - advice columns from flex gate
484
- // - selector from RLC gate
500
+ // - selectors from RLC gate
485
501
config. 0 . flex_gate ( ) . basic_gates [ 0 ]
486
502
. iter ( )
487
503
. map ( |gate| gate. q_enable )
488
504
. chain (
489
505
[
490
506
config. 0 . rlc_config . selector ,
491
- config. 0 . rlc_config . enable_challenge ,
507
+ config. 0 . rlc_config . enable_challenge1 ,
508
+ config. 0 . rlc_config . enable_challenge2 ,
492
509
]
493
510
. iter ( )
494
511
. cloned ( ) ,
0 commit comments