Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit ed15b75

Browse files
committed
[chore] clean up; fix clippy
1 parent 4d66cd9 commit ed15b75

File tree

11 files changed

+63
-66
lines changed

11 files changed

+63
-66
lines changed

aggregator/src/core.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ use ark_std::{end_timer, start_timer};
22
use eth_types::Field;
33
use halo2_proofs::{
44
circuit::{AssignedCell, Layouter, Value},
5-
plonk::Error,
6-
};
7-
use halo2_proofs::{
85
halo2curves::bn256::{Bn256, G1Affine},
6+
plonk::Error,
97
poly::{commitment::ParamsProver, kzg::commitment::ParamsKZG},
108
};
119
use rand::Rng;

aggregator/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod batch;
77
/// Core module for circuit assignment
88
mod core;
99
/// Parameters for compression circuit
10-
pub mod param;
10+
mod param;
1111
/// proof aggregation
1212
mod proof_aggregation;
1313
/// proof compression
@@ -20,5 +20,6 @@ mod tests;
2020

2121
pub use batch::BatchHash;
2222
pub use chunk::ChunkHash;
23+
pub use param::*;
2324
pub use proof_aggregation::*;
2425
pub use proof_compression::*;

aggregator/src/proof_aggregation/circuit.rs

+24-30
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
use ark_std::{end_timer, start_timer};
2-
use halo2_proofs::plonk::Error;
32
use 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
};
98
use itertools::Itertools;
109
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;
1510
use 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+
};
2222
use zkevm_circuits::util::Challenges;
2323

24-
use crate::core::{assign_batch_hashes, extract_accumulators_and_proof};
25-
use crate::proof_aggregation::config::AggregationConfig;
2624
use 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(

aggregator/src/proof_aggregation/public_input_aggregation/circuit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<F: Field> BatchHashCircuit<F> {
7777
/// orders:
7878
/// - batch_public_input_hash
7979
/// - batch_data_hash_preimage
80-
/// - chunk[i].piHash for i in [0, k)
80+
/// - chunk\[i\].piHash for i in \[0, k)
8181
pub(crate) fn extract_hash_preimages(&self) -> Vec<Vec<u8>> {
8282
let mut res = vec![];
8383

aggregator/src/proof_aggregation/public_input_aggregation/circuit_ext.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::BatchHashCircuit;
55

66
impl<F: Field> CircuitExt<F> for BatchHashCircuit<F> {
77
fn num_instance(&self) -> Vec<usize> {
8-
vec![self.instances()[0].len()]
8+
vec![132]
99
}
1010

1111
/// Compute the public inputs for this circuit.

aggregator/src/proof_compression/circuit.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ use halo2_proofs::{
99
plonk::{Circuit, ConstraintSystem, Error},
1010
};
1111
use rand::Rng;
12-
use snark_verifier::loader::halo2::halo2_ecc::halo2_base::{
13-
self,
14-
halo2_proofs::{
15-
halo2curves::bn256::{Bn256, Fr},
16-
poly::{commitment::ParamsProver, kzg::commitment::ParamsKZG},
17-
},
18-
Context, ContextParams,
19-
};
2012
use snark_verifier::{
21-
loader::halo2::Halo2Loader,
13+
loader::halo2::{
14+
halo2_ecc::halo2_base::{
15+
self,
16+
halo2_proofs::{
17+
halo2curves::bn256::{Bn256, Fr},
18+
poly::{commitment::ParamsProver, kzg::commitment::ParamsKZG},
19+
},
20+
Context, ContextParams,
21+
},
22+
Halo2Loader,
23+
},
2224
pcs::kzg::{Bdfg21, Kzg, KzgAccumulator, KzgSuccinctVerifyingKey},
2325
util::arithmetic::fe_to_limbs,
2426
};
@@ -98,7 +100,7 @@ impl Circuit<Fr> for CompressionCircuit {
98100
let mut first_pass = halo2_base::SKIP_FIRST_PASS;
99101
let mut instances = vec![];
100102
layouter.assign_region(
101-
|| "",
103+
|| "compression circuit",
102104
|region| {
103105
if first_pass {
104106
first_pass = false;

aggregator/src/proof_compression/config.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ use halo2_proofs::{
22
halo2curves::bn256::{Fq, Fr, G1Affine},
33
plonk::{Column, ConstraintSystem, Instance},
44
};
5-
use snark_verifier::loader::halo2::halo2_ecc::ecc::{BaseFieldEccChip, EccChip};
6-
use snark_verifier::loader::halo2::halo2_ecc::fields::fp::FpConfig;
7-
use snark_verifier::loader::halo2::halo2_ecc::halo2_base::{
8-
gates::{flex_gate::FlexGateConfig, range::RangeConfig},
9-
utils::modulus,
5+
use snark_verifier::loader::halo2::halo2_ecc::{
6+
ecc::{BaseFieldEccChip, EccChip},
7+
fields::fp::FpConfig,
8+
halo2_base::{
9+
gates::{flex_gate::FlexGateConfig, range::RangeConfig},
10+
utils::modulus,
11+
},
1012
};
1113

1214
use crate::param::{ConfigParams, BITS, LIMBS};

aggregator/src/tests/mock_chunk.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use ark_std::{end_timer, start_timer, test_rng};
22
use halo2_proofs::{dev::MockProver, halo2curves::bn256::Fr};
33
use snark_verifier::loader::halo2::halo2_ecc::halo2_base::utils::fs::gen_srs;
4-
use snark_verifier_sdk::CircuitExt;
54
use snark_verifier_sdk::{
65
gen_pk,
76
halo2::{gen_snark_shplonk, verify_snark_shplonk},
7+
CircuitExt,
88
};
99

1010
use crate::{ChunkHash, LOG_DEGREE};
@@ -15,6 +15,11 @@ mod config;
1515

1616
#[derive(Debug, Default, Clone, Copy)]
1717
/// A mock chunk circuit
18+
///
19+
/// This mock chunk circuit simulates a zkEVM circuit.
20+
/// It's public inputs consists of 64 elements:
21+
/// - data hash
22+
/// - public input hash
1823
pub struct MockChunkCircuit {
1924
pub(crate) chunk: ChunkHash,
2025
}

aggregator/src/tests/mock_chunk/circuit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl Circuit<Fr> for MockChunkCircuit {
3535
fn without_witnesses(&self) -> Self {
3636
Self::default()
3737
}
38+
3839
fn configure(meta: &mut ConstraintSystem<Fr>) -> Self::Config {
3940
let challenges = Challenges::construct(meta);
4041
let challenges_exprs = challenges.exprs(meta);

aggregator/src/tests/proof_aggregation.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn test_aggregation_circuit() {
6666
let snark = gen_snark_shplonk(
6767
&layer_0_params,
6868
&layer_0_pk,
69-
circuit.clone(),
69+
*circuit,
7070
&mut rng,
7171
Some(&path.join(Path::new(format!("layer_0_{}.snark", i).as_str()))),
7272
);
@@ -102,11 +102,7 @@ fn test_aggregation_circuit() {
102102
let compression_circuit =
103103
CompressionCircuit::new(&layer_1_params, layer_0_snarks[0].clone(), true, &mut rng);
104104

105-
let layer_1_pk = gen_pk(
106-
&layer_1_params,
107-
&compression_circuit,
108-
None
109-
);
105+
let layer_1_pk = gen_pk(&layer_1_params, &compression_circuit, None);
110106

111107
log::trace!("finished layer 1 pk gen");
112108
let mut layer_1_snarks = vec![];
@@ -154,8 +150,7 @@ fn test_aggregation_circuit() {
154150
let instances = aggregation_circuit.instances();
155151

156152
log::trace!("start mock proving");
157-
let mock_prover =
158-
MockProver::<Fr>::run(k1, &aggregation_circuit, instances.clone()).unwrap();
153+
let mock_prover = MockProver::<Fr>::run(k1, &aggregation_circuit, instances).unwrap();
159154

160155
mock_prover.assert_satisfied_par();
161156
}

aggregator/src/tests/proof_compression.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use halo2_proofs::{
1212
},
1313
transcript::TranscriptReadBuffer,
1414
};
15-
use snark_verifier::loader::halo2::halo2_ecc::halo2_base::{halo2_proofs, utils::fs::gen_srs};
1615
use snark_verifier::{
16+
loader::halo2::halo2_ecc::halo2_base::{halo2_proofs, utils::fs::gen_srs},
1717
pcs::kzg::{Bdfg21, Kzg},
1818
system::halo2::transcript::evm::EvmTranscript,
1919
};
@@ -59,7 +59,7 @@ fn test_proof_compression() {
5959
let layer_0_snark = gen_snark_shplonk(
6060
&layer_0_params,
6161
&layer_0_pk,
62-
circuit.clone(),
62+
circuit,
6363
&mut rng,
6464
Some(&path.join(Path::new("layer_0.snark"))),
6565
);
@@ -98,8 +98,7 @@ fn test_proof_compression() {
9898
CompressionCircuit::new(&layer_1_params, layer_0_snark, true, &mut rng);
9999
let instances = compression_circuit.instances();
100100

101-
let mock_prover =
102-
MockProver::<Fr>::run(k1, &compression_circuit, instances.clone()).unwrap();
101+
let mock_prover = MockProver::<Fr>::run(k1, &compression_circuit, instances).unwrap();
103102

104103
mock_prover.assert_satisfied_par();
105104
}
@@ -139,7 +138,7 @@ fn test_two_layer_proof_compression() {
139138
let layer_0_snark = gen_snark_shplonk(
140139
&layer_0_params,
141140
&layer_0_pk,
142-
circuit.clone(),
141+
circuit,
143142
&mut rng,
144143
Some(&path.join(Path::new("layer_0.snark"))),
145144
);
@@ -291,7 +290,7 @@ fn test_two_layer_proof_compression() {
291290
&layer_2_params,
292291
&layer_2_pk,
293292
compression_circuit.clone(),
294-
instances.clone(),
293+
instances,
295294
&mut rng,
296295
);
297296

0 commit comments

Comments
 (0)