@@ -2,7 +2,7 @@ use crate::{
22 aggregation:: decoder:: WORKED_EXAMPLE ,
33 blob:: BatchData ,
44 witgen:: { zstd_encode, MultiBlockProcessResult } ,
5- LOG_DEGREE , PI_CHAIN_ID , PI_CURRENT_BATCH_HASH , PI_CURRENT_STATE_ROOT ,
5+ FixedProtocol , LOG_DEGREE , PI_CHAIN_ID , PI_CURRENT_BATCH_HASH , PI_CURRENT_STATE_ROOT ,
66 PI_CURRENT_WITHDRAW_ROOT , PI_PARENT_BATCH_HASH , PI_PARENT_STATE_ROOT ,
77} ;
88use ark_std:: { end_timer, start_timer} ;
@@ -47,7 +47,7 @@ use zkevm_circuits::util::Challenges;
4747use crate :: {
4848 aggregation:: witgen:: process,
4949 batch:: BatchHash ,
50- constants:: { ACC_LEN , DIGEST_LEN , FIXED_PROTOCOL_HALO2 , FIXED_PROTOCOL_SP1 } ,
50+ constants:: { ACC_LEN , DIGEST_LEN } ,
5151 core:: { assign_batch_hashes, extract_proof_and_instances_with_pairing_check} ,
5252 util:: parse_hash_digest_cells,
5353 AssignedBarycentricEvaluationConfig , ConfigParams ,
@@ -76,14 +76,21 @@ pub struct BatchCircuit<const N_SNARKS: usize> {
7676 // batch hash circuit for which the snarks are generated
7777 // the chunks in this batch are also padded already
7878 pub batch_hash : BatchHash < N_SNARKS > ,
79+
80+ /// The SNARK protocol from the halo2-based inner circuit route.
81+ pub halo2_protocol : FixedProtocol ,
82+ /// The SNARK protocol from the sp1-based inner circuit route.
83+ pub sp1_protocol : FixedProtocol ,
7984}
8085
8186impl < const N_SNARKS : usize > BatchCircuit < N_SNARKS > {
82- pub fn new (
87+ pub fn new < P : Into < FixedProtocol > > (
8388 params : & ParamsKZG < Bn256 > ,
8489 snarks_with_padding : & [ Snark ] ,
8590 rng : impl Rng + Send ,
8691 batch_hash : BatchHash < N_SNARKS > ,
92+ halo2_protocol : P ,
93+ sp1_protocol : P ,
8794 ) -> Result < Self , snark_verifier:: Error > {
8895 let timer = start_timer ! ( || "generate aggregation circuit" ) ;
8996
@@ -141,6 +148,8 @@ impl<const N_SNARKS: usize> BatchCircuit<N_SNARKS> {
141148 flattened_instances,
142149 as_proof : Value :: known ( as_proof) ,
143150 batch_hash,
151+ halo2_protocol : halo2_protocol. into ( ) ,
152+ sp1_protocol : sp1_protocol. into ( ) ,
144153 } )
145154 }
146155
@@ -304,9 +313,7 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
304313 log:: trace!( "{}-th instance: {:?}" , i, e. value)
305314 }
306315
307- loader
308- . ctx_mut ( )
309- . print_stats ( & [ "snark aggregation" ] ) ;
316+ loader. ctx_mut ( ) . print_stats ( & [ "snark aggregation" ] ) ;
310317
311318 let mut ctx = Rc :: into_inner ( loader) . unwrap ( ) . into_ctx ( ) ;
312319
@@ -318,11 +325,8 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
318325 log:: info!( "populating constants" ) ;
319326 let mut preprocessed_polys_halo2 = Vec :: with_capacity ( 7 ) ;
320327 let mut preprocessed_polys_sp1 = Vec :: with_capacity ( 7 ) ;
321- let ( fixed_preprocessed_polys_halo2, fixed_transcript_init_state_halo2) =
322- FIXED_PROTOCOL_HALO2 . clone ( ) ;
323- let ( fixed_preprocessed_polys_sp1, fixed_transcript_init_state_sp1) =
324- FIXED_PROTOCOL_SP1 . clone ( ) ;
325- for ( i, & preprocessed_poly) in fixed_preprocessed_polys_halo2. iter ( ) . enumerate ( )
328+ for ( i, & preprocessed_poly) in
329+ self . halo2_protocol . preprocessed . iter ( ) . enumerate ( )
326330 {
327331 log:: debug!( "load const {i}" ) ;
328332 preprocessed_polys_halo2. push (
@@ -332,7 +336,8 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
332336 ) ;
333337 log:: debug!( "load const {i} OK" ) ;
334338 }
335- for ( i, & preprocessed_poly) in fixed_preprocessed_polys_sp1. iter ( ) . enumerate ( ) {
339+ for ( i, & preprocessed_poly) in self . sp1_protocol . preprocessed . iter ( ) . enumerate ( )
340+ {
336341 log:: debug!( "load const (sp1) {i}" ) ;
337342 preprocessed_polys_sp1. push (
338343 config
@@ -346,15 +351,15 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
346351 . field_chip ( )
347352 . range ( )
348353 . gate ( )
349- . assign_constant ( & mut ctx, fixed_transcript_init_state_halo2 )
354+ . assign_constant ( & mut ctx, self . halo2_protocol . init_state )
350355 . expect ( "IntegerInstructions::assign_constant infallible" ) ;
351356 log:: debug!( "load transcript OK" ) ;
352357 let transcript_init_state_sp1 = config
353358 . ecc_chip ( )
354359 . field_chip ( )
355360 . range ( )
356361 . gate ( )
357- . assign_constant ( & mut ctx, fixed_transcript_init_state_sp1 )
362+ . assign_constant ( & mut ctx, self . sp1_protocol . init_state )
358363 . expect ( "IntegerInstructions::assign_constant infallible" ) ;
359364 log:: info!( "populating constants OK" ) ;
360365
0 commit comments