Skip to content

Commit e609b72

Browse files
authored
Delete redundancy (#1415)
* chore: feature not required as zstd-decoder is already expensive * chore: do not need pre/post curie logic * tmp(test): fix test, later refactor
1 parent 902040e commit e609b72

File tree

8 files changed

+181
-536
lines changed

8 files changed

+181
-536
lines changed

aggregator/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,3 @@ csv = "1.1"
4646
[features]
4747
default = ["revm-precompile/c-kzg"]
4848
print-trace = ["ark-std/print-trace"]
49-
# This feature is useful for unit tests where we check the SAT of pi batch circuit
50-
disable_proof_aggregation = []

aggregator/src/aggregation/circuit.rs

+18-76
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
use crate::{
2-
aggregation::decoder::WORKED_EXAMPLE,
3-
blob::BatchData,
4-
witgen::{zstd_encode, MultiBlockProcessResult},
5-
LOG_DEGREE, PI_CHAIN_ID, PI_CURRENT_BATCH_HASH, PI_CURRENT_STATE_ROOT,
6-
PI_CURRENT_WITHDRAW_ROOT, PI_PARENT_BATCH_HASH, PI_PARENT_STATE_ROOT,
7-
};
81
use ark_std::{end_timer, start_timer};
9-
use halo2_base::{Context, ContextParams};
10-
11-
#[cfg(not(feature = "disable_proof_aggregation"))]
12-
use halo2_ecc::{ecc::EccChip, fields::fp::FpConfig};
13-
142
use halo2_proofs::{
153
circuit::{Layouter, SimpleFloorPlanner, Value},
164
halo2curves::bn256::{Bn256, Fr, G1Affine},
@@ -19,34 +7,34 @@ use halo2_proofs::{
197
};
208
use itertools::Itertools;
219
use rand::Rng;
22-
#[cfg(not(feature = "disable_proof_aggregation"))]
23-
use std::rc::Rc;
24-
use std::{env, fs::File};
25-
26-
#[cfg(not(feature = "disable_proof_aggregation"))]
27-
use snark_verifier::loader::halo2::{halo2_ecc::halo2_base::AssignedValue, Halo2Loader};
28-
use snark_verifier::pcs::kzg::KzgSuccinctVerifyingKey;
29-
#[cfg(not(feature = "disable_proof_aggregation"))]
3010
use snark_verifier::{
31-
loader::halo2::halo2_ecc::halo2_base,
32-
pcs::kzg::{Bdfg21, Kzg},
11+
loader::halo2::{
12+
halo2_ecc::{
13+
ecc::EccChip,
14+
fields::fp::FpConfig,
15+
halo2_base::{AssignedValue, Context, ContextParams},
16+
},
17+
Halo2Loader,
18+
},
19+
pcs::kzg::{Bdfg21, Kzg, KzgSuccinctVerifyingKey},
3320
};
34-
#[cfg(not(feature = "disable_proof_aggregation"))]
35-
use snark_verifier_sdk::{aggregate, flatten_accumulator};
36-
use snark_verifier_sdk::{CircuitExt, Snark, SnarkWitness};
21+
use snark_verifier_sdk::{aggregate, flatten_accumulator, CircuitExt, Snark, SnarkWitness};
22+
use std::{env, fs::File, rc::Rc};
3723
use zkevm_circuits::util::Challenges;
3824

3925
use crate::{
40-
aggregation::witgen::process,
26+
aggregation::{decoder::WORKED_EXAMPLE, witgen::process, BatchCircuitConfig},
4127
batch::BatchHash,
28+
blob::BatchData,
4229
constants::{ACC_LEN, DIGEST_LEN},
4330
core::{assign_batch_hashes, extract_proof_and_instances_with_pairing_check},
4431
util::parse_hash_digest_cells,
45-
AssignedBarycentricEvaluationConfig, ConfigParams,
32+
witgen::{zstd_encode, MultiBlockProcessResult},
33+
AssignedBarycentricEvaluationConfig, ConfigParams, LOG_DEGREE, PI_CHAIN_ID,
34+
PI_CURRENT_BATCH_HASH, PI_CURRENT_STATE_ROOT, PI_CURRENT_WITHDRAW_ROOT, PI_PARENT_BATCH_HASH,
35+
PI_PARENT_STATE_ROOT,
4636
};
4737

48-
use super::BatchCircuitConfig;
49-
5038
/// Batch circuit, the chunk aggregation routine below recursion circuit
5139
#[derive(Clone)]
5240
pub struct BatchCircuit<const N_SNARKS: usize> {
@@ -186,47 +174,10 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
186174
.range()
187175
.load_lookup_table(&mut layouter)
188176
.expect("load range lookup table");
177+
189178
// ==============================================
190179
// Step 1: snark aggregation circuit
191180
// ==============================================
192-
#[cfg(feature = "disable_proof_aggregation")]
193-
let barycentric = {
194-
let mut first_pass = halo2_base::SKIP_FIRST_PASS;
195-
layouter.assign_region(
196-
|| "barycentric evaluation",
197-
|region| {
198-
if first_pass {
199-
first_pass = false;
200-
return Ok(AssignedBarycentricEvaluationConfig::default());
201-
}
202-
203-
let mut ctx = Context::new(
204-
region,
205-
ContextParams {
206-
max_rows: config.flex_gate().max_rows,
207-
num_context_ids: 1,
208-
fixed_columns: config.flex_gate().constants.clone(),
209-
},
210-
);
211-
212-
let barycentric = config.barycentric.assign(
213-
&mut ctx,
214-
&self.batch_hash.point_evaluation_assignments.coefficients,
215-
self.batch_hash
216-
.point_evaluation_assignments
217-
.challenge_digest,
218-
self.batch_hash.point_evaluation_assignments.evaluation,
219-
);
220-
221-
config.barycentric.scalar.range.finalize(&mut ctx);
222-
ctx.print_stats(&["barycentric evaluation"]);
223-
224-
Ok(barycentric)
225-
},
226-
)?
227-
};
228-
229-
#[cfg(not(feature = "disable_proof_aggregation"))]
230181
let (accumulator_instances, snark_inputs, barycentric) = {
231182
use halo2_proofs::halo2curves::bn256::Fq;
232183
let mut first_pass = halo2_base::SKIP_FIRST_PASS;
@@ -375,21 +326,13 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
375326
};
376327

377328
// Extract digests
378-
#[cfg(feature = "disable_proof_aggregation")]
379-
let (_batch_hash_digest, _chunk_pi_hash_digests, _potential_batch_data_hash_digest) =
380-
parse_hash_digest_cells::<N_SNARKS>(&assigned_batch_hash.hash_output);
381-
382-
#[cfg(not(feature = "disable_proof_aggregation"))]
383329
let (_batch_hash_digest, chunk_pi_hash_digests, _potential_batch_data_hash_digest) =
384330
parse_hash_digest_cells::<N_SNARKS>(&assigned_batch_hash.hash_output);
385331

386332
// ========================================================================
387333
// step 2.a: check accumulator including public inputs to the snarks
388334
// ========================================================================
389-
#[cfg(not(feature = "disable_proof_aggregation"))]
390335
let mut first_pass = halo2_base::SKIP_FIRST_PASS;
391-
392-
#[cfg(not(feature = "disable_proof_aggregation"))]
393336
layouter.assign_region(
394337
|| "BatchCircuit: Chunk PI",
395338
|mut region| -> Result<(), Error> {
@@ -424,7 +367,6 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
424367
},
425368
)?;
426369

427-
#[cfg(not(feature = "disable_proof_aggregation"))]
428370
{
429371
assert!(accumulator_instances.len() == ACC_LEN);
430372
for (i, v) in accumulator_instances.iter().enumerate() {

aggregator/src/tests/aggregation.rs

+34-7
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,24 @@ use crate::{
1616
BatchData, ChunkInfo,
1717
};
1818

19-
// See https://github.com/scroll-tech/zkevm-circuits/pull/1311#issuecomment-2139559866
2019
#[test]
21-
fn test_max_agg_snarks_batch_circuit() {
20+
fn batch_circuit_raw() {
2221
let k = 21;
23-
24-
// This set up requires one round of keccak for chunk's data hash
25-
// let circuit: BatchCircuit<MAX_AGG_SNARKS> = build_new_batch_circuit(2, k);
2622
let circuit: BatchCircuit<MAX_AGG_SNARKS> = build_batch_circuit_skip_encoding();
2723
let instance = circuit.instances();
2824
let mock_prover = MockProver::<Fr>::run(k, &circuit, instance).unwrap();
2925
mock_prover.assert_satisfied_par();
3026
}
3127

28+
#[test]
29+
fn batch_circuit_encode() {
30+
let k = 21;
31+
let circuit: BatchCircuit<MAX_AGG_SNARKS> = build_new_batch_circuit(2, k);
32+
let instance = circuit.instances();
33+
let mock_prover = MockProver::<Fr>::run(k, &circuit, instance).unwrap();
34+
mock_prover.assert_satisfied_par();
35+
}
36+
3237
#[ignore]
3338
#[test]
3439
fn test_2_snark_batch_circuit() {
@@ -143,6 +148,19 @@ fn build_new_batch_circuit<const N_SNARKS: usize>(
143148
) -> BatchCircuit<N_SNARKS> {
144149
// inner circuit: Mock circuit
145150
let k0 = 8;
151+
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
152+
pub struct ChunkProof {
153+
pub chunk_info: ChunkInfo,
154+
}
155+
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
156+
struct BatchProvingTask {
157+
pub chunk_proofs: Vec<ChunkProof>,
158+
pub batch_header: BatchHeader<MAX_AGG_SNARKS>,
159+
}
160+
let file = std::fs::File::open("data/batch-task.json").expect("batch-task.json exists");
161+
let reader = std::io::BufReader::new(file);
162+
let batch_proving_task: BatchProvingTask =
163+
serde_json::from_reader(reader).expect("deserialisation should succeed");
146164

147165
let mut rng = test_rng();
148166
let params = gen_srs(k0);
@@ -163,6 +181,16 @@ fn build_new_batch_circuit<const N_SNARKS: usize>(
163181
let batch_data = BatchData::<N_SNARKS>::new(num_real_chunks, &chunks_with_padding);
164182
let batch_bytes = batch_data.get_batch_data_bytes();
165183
let blob_bytes = get_blob_bytes(&batch_bytes);
184+
let batch_header = BatchHeader::construct_from_chunks(
185+
batch_proving_task.batch_header.version,
186+
batch_proving_task.batch_header.batch_index,
187+
batch_proving_task.batch_header.l1_message_popped,
188+
batch_proving_task.batch_header.total_l1_message_popped,
189+
batch_proving_task.batch_header.parent_batch_hash,
190+
batch_proving_task.batch_header.last_block_timestamp,
191+
&chunks_with_padding,
192+
&blob_bytes,
193+
);
166194

167195
// ==========================
168196
// real chunks
@@ -190,8 +218,7 @@ fn build_new_batch_circuit<const N_SNARKS: usize>(
190218
// ==========================
191219
// batch
192220
// ==========================
193-
let batch_hash =
194-
BatchHash::construct(&chunks_with_padding, BatchHeader::default(), &blob_bytes);
221+
let batch_hash = BatchHash::construct(&chunks_with_padding, batch_header, &blob_bytes);
195222

196223
BatchCircuit::new(
197224
&params,

zkevm-circuits/src/evm_circuit/execution/begin_tx.rs

+5-26
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::{
66
util::{
77
and,
88
common_gadget::{
9-
CurieGadget, TransferGadgetInfo, TransferWithGasFeeGadget, TxAccessListGadget,
10-
TxEip1559Gadget, TxL1FeeGadget, TxL1MsgGadget,
9+
TransferGadgetInfo, TransferWithGasFeeGadget, TxAccessListGadget, TxEip1559Gadget,
10+
TxL1FeeGadget, TxL1MsgGadget,
1111
},
1212
constraint_builder::{
1313
ConstrainBuilderCommon, EVMConstraintBuilder, ReversionInfo, StepStateTransition,
@@ -100,7 +100,6 @@ pub(crate) struct BeginTxGadget<F> {
100100
tx_l1_msg: TxL1MsgGadget<F>,
101101
tx_access_list: TxAccessListGadget<F>,
102102
tx_eip1559: TxEip1559Gadget<F>,
103-
curie: CurieGadget<F>,
104103
}
105104

106105
impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
@@ -140,22 +139,14 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
140139
let tx_access_list = TxAccessListGadget::construct(cb, tx_id.expr(), tx_type.expr());
141140
let is_call_data_empty = IsZeroGadget::construct(cb, tx_call_data_length.expr());
142141

143-
let curie = CurieGadget::construct(cb, cb.curr.state.block_number.expr());
144-
145142
let tx_l1_msg = TxL1MsgGadget::construct(cb, tx_type.expr(), tx_caller_address.expr());
146143
let tx_l1_fee = cb.condition(not::expr(tx_l1_msg.is_l1_msg()), |cb| {
147144
cb.require_equal(
148145
"tx.nonce == sender.nonce",
149146
tx_nonce.expr(),
150147
sender_nonce.expr(),
151148
);
152-
TxL1FeeGadget::construct(
153-
cb,
154-
not::expr(curie.is_before_curie.expr()),
155-
tx_id.expr(),
156-
tx_data_gas_cost.expr(),
157-
tx_signed_length.expr(),
158-
)
149+
TxL1FeeGadget::construct(cb, tx_id.expr(), tx_signed_length.expr())
159150
});
160151
cb.condition(tx_l1_msg.is_l1_msg(), |cb| {
161152
cb.require_zero("l1fee is 0 for l1msg", tx_data_gas_cost.expr());
@@ -170,7 +161,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
170161
let l1_rw_delta = select::expr(
171162
tx_l1_msg.is_l1_msg(),
172163
tx_l1_msg.rw_delta(),
173-
tx_l1_fee.rw_delta(not::expr(curie.is_before_curie.expr())),
164+
tx_l1_fee.rw_delta(),
174165
) + 1.expr();
175166

176167
// the cost caused by l1
@@ -845,7 +836,6 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
845836
tx_l1_msg,
846837
tx_access_list,
847838
tx_eip1559,
848-
curie,
849839
}
850840
}
851841

@@ -897,10 +887,6 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
897887
self.tx_l1_msg
898888
.assign(region, offset, tx_type, caller_code_hash)?;
899889

900-
let is_curie = bus_mapping::circuit_input_builder::curie::is_curie_enabled(
901-
block.chain_id,
902-
tx.block_number,
903-
);
904890
// Add access-list RW offset.
905891
rws.offset_add(TxAccessListGadget::<F>::rw_delta_value(tx) as usize);
906892

@@ -920,16 +906,9 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
920906
0
921907
}
922908
} else {
923-
if is_curie {
924-
6
925-
} else {
926-
3
927-
}
909+
6
928910
});
929911

930-
self.curie
931-
.assign(region, offset, block.chain_id, tx.block_number)?;
932-
933912
let rw = rws.next();
934913
debug_assert_eq!(rw.tag(), RwTableTag::CallContext);
935914
debug_assert_eq!(rw.field_tag(), Some(CallContextFieldTag::L1Fee as u64));

0 commit comments

Comments
 (0)