@@ -15,7 +15,6 @@ use snark_verifier::{
1515 fields:: { fp:: FpConfig , FieldChip } ,
1616 halo2_base:: {
1717 gates:: { GateInstructions , RangeInstructions } ,
18- utils:: fe_to_biguint,
1918 AssignedValue , Context , ContextParams ,
2019 QuantumCell :: Existing ,
2120 } ,
@@ -34,12 +33,12 @@ use crate::{
3433 aggregation:: { decoder:: WORKED_EXAMPLE , witgen:: process, BatchCircuitConfig , BatchData } ,
3534 batch:: BatchHash ,
3635 blob_consistency:: BlobConsistencyConfig ,
37- constants:: { ACC_LEN , DIGEST_LEN , FIXED_PROTOCOL_HALO2 , FIXED_PROTOCOL_SP1 } ,
36+ constants:: { ACC_LEN , DIGEST_LEN } ,
3837 core:: { assign_batch_hashes, extract_proof_and_instances_with_pairing_check} ,
3938 util:: parse_hash_digest_cells,
4039 witgen:: { zstd_encode, MultiBlockProcessResult } ,
41- ConfigParams , LOG_DEGREE , PI_CHAIN_ID , PI_CURRENT_BATCH_HASH , PI_CURRENT_STATE_ROOT ,
42- PI_CURRENT_WITHDRAW_ROOT , PI_PARENT_BATCH_HASH , PI_PARENT_STATE_ROOT ,
40+ ConfigParams , FixedProtocol , LOG_DEGREE , PI_CHAIN_ID , PI_CURRENT_BATCH_HASH ,
41+ PI_CURRENT_STATE_ROOT , PI_CURRENT_WITHDRAW_ROOT , PI_PARENT_BATCH_HASH , PI_PARENT_STATE_ROOT ,
4342} ;
4443
4544/// Batch circuit, the chunk aggregation routine below recursion circuit
@@ -63,14 +62,21 @@ pub struct BatchCircuit<const N_SNARKS: usize> {
6362 // batch hash circuit for which the snarks are generated
6463 // the chunks in this batch are also padded already
6564 pub batch_hash : BatchHash < N_SNARKS > ,
65+
66+ /// The SNARK protocol from the halo2-based inner circuit route.
67+ pub halo2_protocol : FixedProtocol ,
68+ /// The SNARK protocol from the sp1-based inner circuit route.
69+ pub sp1_protocol : FixedProtocol ,
6670}
6771
6872impl < const N_SNARKS : usize > BatchCircuit < N_SNARKS > {
69- pub fn new (
73+ pub fn new < P : Into < FixedProtocol > > (
7074 params : & ParamsKZG < Bn256 > ,
7175 snarks_with_padding : & [ Snark ] ,
7276 rng : impl Rng + Send ,
7377 batch_hash : BatchHash < N_SNARKS > ,
78+ halo2_protocol : P ,
79+ sp1_protocol : P ,
7480 ) -> Result < Self , snark_verifier:: Error > {
7581 let timer = start_timer ! ( || "generate aggregation circuit" ) ;
7682
@@ -128,6 +134,8 @@ impl<const N_SNARKS: usize> BatchCircuit<N_SNARKS> {
128134 flattened_instances,
129135 as_proof : Value :: known ( as_proof) ,
130136 batch_hash,
137+ halo2_protocol : halo2_protocol. into ( ) ,
138+ sp1_protocol : sp1_protocol. into ( ) ,
131139 } )
132140 }
133141
@@ -252,9 +260,7 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
252260 log:: trace!( "{}-th instance: {:?}" , i, e. value)
253261 }
254262
255- loader
256- . ctx_mut ( )
257- . print_stats ( & [ "snark aggregation" ] ) ;
263+ loader. ctx_mut ( ) . print_stats ( & [ "snark aggregation" ] ) ;
258264
259265 let mut ctx = Rc :: into_inner ( loader) . unwrap ( ) . into_ctx ( ) ;
260266
@@ -266,11 +272,8 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
266272 log:: info!( "populating constants" ) ;
267273 let mut preprocessed_polys_halo2 = Vec :: with_capacity ( 7 ) ;
268274 let mut preprocessed_polys_sp1 = Vec :: with_capacity ( 7 ) ;
269- let ( fixed_preprocessed_polys_halo2, fixed_transcript_init_state_halo2) =
270- FIXED_PROTOCOL_HALO2 . clone ( ) ;
271- let ( fixed_preprocessed_polys_sp1, fixed_transcript_init_state_sp1) =
272- FIXED_PROTOCOL_SP1 . clone ( ) ;
273- for ( i, & preprocessed_poly) in fixed_preprocessed_polys_halo2. iter ( ) . enumerate ( )
275+ for ( i, & preprocessed_poly) in
276+ self . halo2_protocol . preprocessed . iter ( ) . enumerate ( )
274277 {
275278 log:: debug!( "load const {i}" ) ;
276279 preprocessed_polys_halo2. push (
@@ -280,7 +283,8 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
280283 ) ;
281284 log:: debug!( "load const {i} OK" ) ;
282285 }
283- for ( i, & preprocessed_poly) in fixed_preprocessed_polys_sp1. iter ( ) . enumerate ( ) {
286+ for ( i, & preprocessed_poly) in self . sp1_protocol . preprocessed . iter ( ) . enumerate ( )
287+ {
284288 log:: debug!( "load const (sp1) {i}" ) ;
285289 preprocessed_polys_sp1. push (
286290 config
@@ -294,15 +298,15 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
294298 . field_chip ( )
295299 . range ( )
296300 . gate ( )
297- . assign_constant ( & mut ctx, fixed_transcript_init_state_halo2 )
301+ . assign_constant ( & mut ctx, self . halo2_protocol . init_state )
298302 . expect ( "IntegerInstructions::assign_constant infallible" ) ;
299303 log:: debug!( "load transcript OK" ) ;
300304 let transcript_init_state_sp1 = config
301305 . ecc_chip ( )
302306 . field_chip ( )
303307 . range ( )
304308 . gate ( )
305- . assign_constant ( & mut ctx, fixed_transcript_init_state_sp1 )
309+ . assign_constant ( & mut ctx, self . sp1_protocol . init_state )
306310 . expect ( "IntegerInstructions::assign_constant infallible" ) ;
307311 log:: info!( "populating constants OK" ) ;
308312
0 commit comments