11use ark_std:: { end_timer, start_timer} ;
2- use halo2_proofs:: plonk:: Error ;
32use halo2_proofs:: {
43 circuit:: { Layouter , SimpleFloorPlanner , Value } ,
54 halo2curves:: bn256:: { Bn256 , Fq , Fr , G1Affine } ,
6- plonk:: { Circuit , ConstraintSystem } ,
5+ plonk:: { Circuit , ConstraintSystem , Error } ,
76 poly:: { commitment:: ParamsProver , kzg:: commitment:: ParamsKZG } ,
87} ;
98use itertools:: Itertools ;
109use rand:: Rng ;
11- use snark_verifier:: loader:: halo2:: halo2_ecc:: halo2_base:: {
12- self , AssignedValue , Context , ContextParams ,
13- } ;
14- use snark_verifier:: loader:: halo2:: Halo2Loader ;
1510use snark_verifier:: {
11+ loader:: halo2:: {
12+ halo2_ecc:: halo2_base:: { self , AssignedValue , Context , ContextParams } ,
13+ Halo2Loader ,
14+ } ,
1615 pcs:: kzg:: { Bdfg21 , Kzg , KzgAccumulator , KzgSuccinctVerifyingKey } ,
1716 util:: arithmetic:: fe_to_limbs,
1817} ;
19- use snark_verifier_sdk:: halo2:: aggregation:: { aggregate, flatten_accumulator} ;
20- use snark_verifier_sdk:: CircuitExt ;
21- use snark_verifier_sdk:: { halo2:: aggregation:: Svk , NativeLoader , Snark , SnarkWitness } ;
18+ use snark_verifier_sdk:: {
19+ halo2:: aggregation:: { aggregate, flatten_accumulator, Svk } ,
20+ CircuitExt , NativeLoader , Snark , SnarkWitness ,
21+ } ;
2222use zkevm_circuits:: util:: Challenges ;
2323
24- use crate :: core:: { assign_batch_hashes, extract_accumulators_and_proof} ;
25- use crate :: proof_aggregation:: config:: AggregationConfig ;
2624use crate :: {
25+ core:: { assign_batch_hashes, extract_accumulators_and_proof} ,
2726 param:: { ConfigParams , BITS , LIMBS } ,
27+ proof_aggregation:: config:: AggregationConfig ,
2828 BatchHashCircuit , ChunkHash ,
2929} ;
3030
@@ -104,7 +104,7 @@ impl AggregationCircuit {
104104
105105 Self {
106106 svk,
107- snarks : snarks. into_iter ( ) . cloned ( ) . map_into ( ) . collect ( ) ,
107+ snarks : snarks. iter ( ) . cloned ( ) . map_into ( ) . collect ( ) ,
108108 flattened_instances,
109109 as_proof : Value :: known ( as_proof) ,
110110 batch_hash_circuit,
@@ -157,18 +157,18 @@ impl Circuit<Fr> for AggregationCircuit {
157157 . expect ( "load range lookup table" ) ;
158158 let mut first_pass = halo2_base:: SKIP_FIRST_PASS ;
159159
160- // This circuit takes 2 steps
160+ // This circuit takes 3 steps
161161 // - 1. use aggregation circuit to aggregate the multiple snarks into a single one;
162- // re-export all the public input of the snarks, denoted by [snarks_instances], and
163- // the accumulator [acc_instances]
164- // - 2. use public input aggregation circuit to aggregate the chunks;
165- // expose the instance dentoed by [pi_agg_instances]
166- // - 3. assert [snarks_instances] are private inputs used for public input aggregation circuit
162+ // re-export all the public input of the snarks, denoted by [snarks_instances], and the
163+ // accumulator [acc_instances]
164+ // - 2. use public input aggregation circuit to aggregate the chunks; expose the instance
165+ // dentoed by [pi_agg_instances]
166+ // - 3. assert [snarks_instances] are private inputs used for public input aggregation
167+ // circuit
167168
168169 // ==============================================
169170 // Step 1: aggregation circuit
170171 // ==============================================
171- // let mut aggregation_instances = vec![];
172172 let mut accumulator_instances: Vec < AssignedValue < Fr > > = vec ! [ ] ;
173173 let mut snark_inputs: Vec < AssignedValue < Fr > > = vec ! [ ] ;
174174 layouter. assign_region (
@@ -192,7 +192,8 @@ impl Circuit<Fr> for AggregationCircuit {
192192
193193 //
194194 // extract the assigned values for
195- // - instances which are the public inputs of each chunk (prefixed with 12 instances from previous accumualtors)
195+ // - instances which are the public inputs of each chunk (prefixed with 12 instances
196+ // from previous accumualtors)
196197 // - new accumulator to be verified on chain
197198 //
198199 let ( assigned_aggreation_instances, acc) = aggregate :: < Kzg < Bn256 , Bdfg21 > > (
@@ -209,17 +210,13 @@ impl Circuit<Fr> for AggregationCircuit {
209210 // extract the following cells for later constraints
210211 // - the accumulators
211212 // - the public input from snark
212- accumulator_instances. extend (
213- flatten_accumulator ( acc)
214- . iter ( )
215- . map ( |assigned| assigned. clone ( ) ) ,
216- ) ;
213+ accumulator_instances. extend ( flatten_accumulator ( acc) . iter ( ) . copied ( ) ) ;
217214 // - the snark is not a fresh one, assigned_instances already contains an
218215 // accumulator so we want to skip the first 12 elements from the public input
219216 snark_inputs. extend (
220217 assigned_aggreation_instances
221218 . iter ( )
222- . flat_map ( |instance_column| instance_column. iter ( ) . skip ( 12 ) . map ( |x| x ) ) ,
219+ . flat_map ( |instance_column| instance_column. iter ( ) . skip ( 12 ) ) ,
223220 ) ;
224221
225222 config. range ( ) . finalize ( & mut loader. ctx_mut ( ) ) ;
@@ -243,7 +240,6 @@ impl Circuit<Fr> for AggregationCircuit {
243240 // step 2: public input aggregation circuit
244241 // ==============================================
245242 // extract all the hashes and load them to the hash table
246- // assert the public input matches that of the pi_aggregation_circuit
247243 let challenges = challenge. values ( & layouter) ;
248244
249245 let timer = start_timer ! ( || ( "extract hash" ) . to_string( ) ) ;
@@ -297,9 +293,7 @@ impl Circuit<Fr> for AggregationCircuit {
297293
298294 for chunk_idx in 0 ..self . snarks . len ( ) {
299295 // step 3.1, data hash
300- // - batch_data_hash := keccak(chunk_0.data_hash
301- // || ...
302- // || chunk_k-1.data_hash)
296+ // - batch_data_hash := keccak(chunk_0.data_hash || ... || chunk_k-1.data_hash)
303297 // where batch_data_hash is the second hash for pi aggregation
304298 for i in 0 ..32 {
305299 region. constrain_equal (
0 commit comments