1
1
use ark_std:: { end_timer, start_timer} ;
2
- use halo2_proofs:: plonk:: Error ;
3
2
use halo2_proofs:: {
4
3
circuit:: { Layouter , SimpleFloorPlanner , Value } ,
5
4
halo2curves:: bn256:: { Bn256 , Fq , Fr , G1Affine } ,
6
- plonk:: { Circuit , ConstraintSystem } ,
5
+ plonk:: { Circuit , ConstraintSystem , Error } ,
7
6
poly:: { commitment:: ParamsProver , kzg:: commitment:: ParamsKZG } ,
8
7
} ;
9
8
use itertools:: Itertools ;
10
9
use 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 ;
15
10
use snark_verifier:: {
11
+ loader:: halo2:: {
12
+ halo2_ecc:: halo2_base:: { self , AssignedValue , Context , ContextParams } ,
13
+ Halo2Loader ,
14
+ } ,
16
15
pcs:: kzg:: { Bdfg21 , Kzg , KzgAccumulator , KzgSuccinctVerifyingKey } ,
17
16
util:: arithmetic:: fe_to_limbs,
18
17
} ;
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
+ } ;
22
22
use zkevm_circuits:: util:: Challenges ;
23
23
24
- use crate :: core:: { assign_batch_hashes, extract_accumulators_and_proof} ;
25
- use crate :: proof_aggregation:: config:: AggregationConfig ;
26
24
use crate :: {
25
+ core:: { assign_batch_hashes, extract_accumulators_and_proof} ,
27
26
param:: { ConfigParams , BITS , LIMBS } ,
27
+ proof_aggregation:: config:: AggregationConfig ,
28
28
BatchHashCircuit , ChunkHash ,
29
29
} ;
30
30
@@ -104,7 +104,7 @@ impl AggregationCircuit {
104
104
105
105
Self {
106
106
svk,
107
- snarks : snarks. into_iter ( ) . cloned ( ) . map_into ( ) . collect ( ) ,
107
+ snarks : snarks. iter ( ) . cloned ( ) . map_into ( ) . collect ( ) ,
108
108
flattened_instances,
109
109
as_proof : Value :: known ( as_proof) ,
110
110
batch_hash_circuit,
@@ -157,18 +157,18 @@ impl Circuit<Fr> for AggregationCircuit {
157
157
. expect ( "load range lookup table" ) ;
158
158
let mut first_pass = halo2_base:: SKIP_FIRST_PASS ;
159
159
160
- // This circuit takes 2 steps
160
+ // This circuit takes 3 steps
161
161
// - 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
167
168
168
169
// ==============================================
169
170
// Step 1: aggregation circuit
170
171
// ==============================================
171
- // let mut aggregation_instances = vec![];
172
172
let mut accumulator_instances: Vec < AssignedValue < Fr > > = vec ! [ ] ;
173
173
let mut snark_inputs: Vec < AssignedValue < Fr > > = vec ! [ ] ;
174
174
layouter. assign_region (
@@ -192,7 +192,8 @@ impl Circuit<Fr> for AggregationCircuit {
192
192
193
193
//
194
194
// 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)
196
197
// - new accumulator to be verified on chain
197
198
//
198
199
let ( assigned_aggreation_instances, acc) = aggregate :: < Kzg < Bn256 , Bdfg21 > > (
@@ -209,17 +210,13 @@ impl Circuit<Fr> for AggregationCircuit {
209
210
// extract the following cells for later constraints
210
211
// - the accumulators
211
212
// - 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 ( ) ) ;
217
214
// - the snark is not a fresh one, assigned_instances already contains an
218
215
// accumulator so we want to skip the first 12 elements from the public input
219
216
snark_inputs. extend (
220
217
assigned_aggreation_instances
221
218
. iter ( )
222
- . flat_map ( |instance_column| instance_column. iter ( ) . skip ( 12 ) . map ( |x| x ) ) ,
219
+ . flat_map ( |instance_column| instance_column. iter ( ) . skip ( 12 ) ) ,
223
220
) ;
224
221
225
222
config. range ( ) . finalize ( & mut loader. ctx_mut ( ) ) ;
@@ -243,7 +240,6 @@ impl Circuit<Fr> for AggregationCircuit {
243
240
// step 2: public input aggregation circuit
244
241
// ==============================================
245
242
// extract all the hashes and load them to the hash table
246
- // assert the public input matches that of the pi_aggregation_circuit
247
243
let challenges = challenge. values ( & layouter) ;
248
244
249
245
let timer = start_timer ! ( || ( "extract hash" ) . to_string( ) ) ;
@@ -297,9 +293,7 @@ impl Circuit<Fr> for AggregationCircuit {
297
293
298
294
for chunk_idx in 0 ..self . snarks . len ( ) {
299
295
// 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)
303
297
// where batch_data_hash is the second hash for pi aggregation
304
298
for i in 0 ..32 {
305
299
region. constrain_equal (
0 commit comments