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

Commit 40a8848

Browse files
kunxian-xiaroynalnarutoMason Liang
authored
Fix bugs in integration test (#1160)
* split blob data region into two separate regions * fix * load tables for BlobDataConfig * fix wrong rlc in blob data rows * fix challenge z lookup * keccak lookup for metadata row and minor fixes (#1162) * fmt * fix challenge z * rlc keccak vs evm (#1163) * put barycentric eval and snark aggregation in same region * fix copy constraints (limb construction and endianness) (#1164) * fix copy constraints (limb construction and endianness) * fix typo --------- Co-authored-by: Mason Liang <mason@scroll.io> * cleanup --------- Co-authored-by: Rohit Narurkar <rohit.narurkar@proton.me> Co-authored-by: Mason Liang <mason@scroll.io>
1 parent 9d55e06 commit 40a8848

File tree

9 files changed

+390
-220
lines changed

9 files changed

+390
-220
lines changed

aggregator/src/aggregation/blob_data.rs

Lines changed: 196 additions & 99 deletions
Large diffs are not rendered by default.

aggregator/src/aggregation/circuit.rs

Lines changed: 68 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use halo2_proofs::{
99
};
1010
use itertools::Itertools;
1111
use rand::Rng;
12+
#[cfg(not(feature = "disable_proof_aggregation"))]
13+
use std::rc::Rc;
1214
use std::{env, fs::File};
1315

1416
#[cfg(not(feature = "disable_proof_aggregation"))]
@@ -156,24 +158,59 @@ impl Circuit<Fr> for AggregationCircuit {
156158

157159
let timer = start_timer!(|| "aggregation");
158160

161+
// load lookup table in range config
162+
config
163+
.range()
164+
.load_lookup_table(&mut layouter)
165+
.expect("load range lookup table");
159166
// ==============================================
160167
// Step 1: snark aggregation circuit
161168
// ==============================================
162-
#[cfg(not(feature = "disable_proof_aggregation"))]
163-
let (accumulator_instances, snark_inputs) = {
164-
config
165-
.range()
166-
.load_lookup_table(&mut layouter)
167-
.expect("load range lookup table");
169+
#[cfg(feature = "disable_proof_aggregation")]
170+
let barycentric = {
171+
let mut first_pass = halo2_base::SKIP_FIRST_PASS;
172+
layouter.assign_region(
173+
|| "barycentric evaluation",
174+
|region| {
175+
if first_pass {
176+
first_pass = false;
177+
return Ok(BarycentricEvaluationCells::default());
178+
}
179+
180+
let mut ctx = Context::new(
181+
region,
182+
ContextParams {
183+
max_rows: config.flex_gate().max_rows,
184+
num_context_ids: 1,
185+
fixed_columns: config.flex_gate().constants.clone(),
186+
},
187+
);
188+
189+
let barycentric = config.barycentric.assign2(
190+
&mut ctx,
191+
self.batch_hash.blob.coefficients,
192+
self.batch_hash.blob.challenge_digest,
193+
self.batch_hash.blob.evaluation,
194+
);
195+
196+
config.barycentric.scalar.range.finalize(&mut ctx);
197+
ctx.print_stats(&["barycentric evaluation"]);
198+
199+
Ok(barycentric)
200+
},
201+
)?
202+
};
168203

204+
#[cfg(not(feature = "disable_proof_aggregation"))]
205+
let (accumulator_instances, snark_inputs, barycentric) = {
169206
let mut first_pass = halo2_base::SKIP_FIRST_PASS;
170207

171-
let (accumulator_instances, snark_inputs) = layouter.assign_region(
208+
let (accumulator_instances, snark_inputs, barycentric) = layouter.assign_region(
172209
|| "aggregation",
173-
|region| -> Result<(Vec<AssignedValue<Fr>>, Vec<AssignedValue<Fr>>), Error> {
210+
|region| {
174211
if first_pass {
175212
first_pass = false;
176-
return Ok((vec![], vec![]));
213+
return Ok((vec![], vec![], BarycentricEvaluationCells::default()));
177214
}
178215

179216
// stores accumulators for all snarks, including the padded ones
@@ -222,16 +259,26 @@ impl Circuit<Fr> for AggregationCircuit {
222259
.flat_map(|instance_column| instance_column.iter().skip(ACC_LEN)),
223260
);
224261

225-
config.range().finalize(&mut loader.ctx_mut());
262+
loader.ctx_mut().print_stats(&["snark aggregation"]);
263+
264+
let mut ctx = Rc::into_inner(loader).unwrap().into_ctx();
265+
let barycentric = config.barycentric.assign2(
266+
&mut ctx,
267+
self.batch_hash.blob.coefficients,
268+
self.batch_hash.blob.challenge_digest,
269+
self.batch_hash.blob.evaluation,
270+
);
226271

227-
loader.ctx_mut().print_stats(&["Range"]);
272+
ctx.print_stats(&["barycentric"]);
228273

229-
Ok((accumulator_instances, snark_inputs))
274+
config.range().finalize(&mut ctx);
275+
276+
Ok((accumulator_instances, snark_inputs, barycentric))
230277
},
231278
)?;
232279

233280
assert_eq!(snark_inputs.len(), MAX_AGG_SNARKS * DIGEST_LEN);
234-
(accumulator_instances, snark_inputs)
281+
(accumulator_instances, snark_inputs, barycentric)
235282
};
236283
end_timer!(timer);
237284
// ==============================================
@@ -242,7 +289,7 @@ impl Circuit<Fr> for AggregationCircuit {
242289

243290
let timer = start_timer!(|| "load aux table");
244291

245-
let (hash_digest_cells, expected_blob_cells, rlc_config_offset) = {
292+
let (hash_digest_cells, expected_blob_cells) = {
246293
config
247294
.keccak_circuit_config
248295
.load_aux_tables(&mut layouter)?;
@@ -281,11 +328,7 @@ impl Circuit<Fr> for AggregationCircuit {
281328
.map_err(|_e| Error::ConstraintSystemFailure)?;
282329

283330
end_timer!(timer);
284-
(
285-
assigned_batch_hash.hash_output,
286-
assigned_batch_hash.blob,
287-
assigned_batch_hash.rlc_config_offset,
288-
)
331+
(assigned_batch_hash.hash_output, assigned_batch_hash.blob)
289332
};
290333
// digests
291334
let (batch_pi_hash_digest, chunk_pi_hash_digests, _potential_batch_data_hash_digest) =
@@ -382,40 +425,13 @@ impl Circuit<Fr> for AggregationCircuit {
382425

383426
// blob data config
384427
{
385-
let mut is_first_pass = true;
386-
let be = layouter.assign_region(
387-
|| "blob data and barycentric evaluation",
388-
|region| {
389-
if is_first_pass {
390-
is_first_pass = false;
391-
return Ok(BarycentricEvaluationCells::default());
392-
}
393-
394-
let mut ctx = Context::new(
395-
region,
396-
ContextParams {
397-
max_rows: config.flex_gate().max_rows,
398-
num_context_ids: 1,
399-
fixed_columns: config.flex_gate().constants.clone(),
400-
},
401-
);
402-
403-
Ok(config.barycentric.assign2(
404-
&mut ctx,
405-
self.batch_hash.blob.coefficients,
406-
self.batch_hash.blob.challenge_digest,
407-
self.batch_hash.blob.evaluation,
408-
))
409-
},
410-
)?;
411-
let barycentric_assignments = &be.barycentric_assignments;
412-
let challenge_le = &be.z_le;
413-
let evaluation_le = &be.y_le;
428+
let barycentric_assignments = &barycentric.barycentric_assignments;
429+
let challenge_le = &barycentric.z_le;
430+
let evaluation_le = &barycentric.y_le;
414431

415432
let blob_data_exports = config.blob_data_config.assign(
416433
&mut layouter,
417434
challenges,
418-
rlc_config_offset,
419435
&config.rlc_config,
420436
&self.batch_hash,
421437
barycentric_assignments,
@@ -481,14 +497,15 @@ impl CircuitExt<Fr> for AggregationCircuit {
481497

482498
fn selectors(config: &Self::Config) -> Vec<Selector> {
483499
// - advice columns from flex gate
484-
// - selector from RLC gate
500+
// - selectors from RLC gate
485501
config.0.flex_gate().basic_gates[0]
486502
.iter()
487503
.map(|gate| gate.q_enable)
488504
.chain(
489505
[
490506
config.0.rlc_config.selector,
491-
config.0.rlc_config.enable_challenge,
507+
config.0.rlc_config.enable_challenge1,
508+
config.0.rlc_config.enable_challenge2,
492509
]
493510
.iter()
494511
.cloned(),

aggregator/src/aggregation/rlc/config.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use halo2_proofs::{
66

77
#[cfg(test)]
88
use halo2_proofs::plonk::FirstPhase;
9-
use zkevm_circuits::util::Challenges;
9+
use zkevm_circuits::util::{Challenges, Expr};
1010

1111
/// This config is used to compute RLCs for bytes.
1212
/// It requires a phase 2 column
@@ -18,13 +18,15 @@ pub struct RlcConfig {
1818
pub(crate) phase_2_column: Column<Advice>,
1919
pub(crate) selector: Selector,
2020
pub(crate) fixed: Column<Fixed>,
21-
pub(crate) enable_challenge: Selector,
21+
pub(crate) enable_challenge1: Selector,
22+
pub(crate) enable_challenge2: Selector,
2223
}
2324

2425
impl RlcConfig {
2526
pub(crate) fn configure(meta: &mut ConstraintSystem<Fr>, challenge: Challenges) -> Self {
2627
let selector = meta.complex_selector();
27-
let enable_challenge = meta.complex_selector();
28+
let enable_challenge1 = meta.complex_selector();
29+
let enable_challenge2 = meta.complex_selector();
2830
let challenge_expr = challenge.exprs(meta);
2931

3032
#[cfg(test)]
@@ -61,18 +63,22 @@ impl RlcConfig {
6163
// constraint: q2*(a-challenge) = 0
6264
// FIXME later: Pretty wasteful to have a dedicated custom gate and selector column just
6365
// to extract the keccak challenge cell...
64-
let q2 = meta.query_selector(enable_challenge);
65-
let cs2 = q2 * (a - challenge_expr.keccak_input());
66+
let q2 = meta.query_selector(enable_challenge1);
67+
let cs2 = q2 * (a.expr() - challenge_expr.keccak_input());
6668

67-
vec![cs1, cs2]
69+
let q3 = meta.query_selector(enable_challenge2);
70+
let cs3 = q3 * (a - challenge_expr.evm_word());
71+
72+
vec![cs1, cs2, cs3]
6873
});
6974
Self {
7075
#[cfg(test)]
7176
_phase_1_column,
7277
phase_2_column,
7378
selector,
7479
fixed,
75-
enable_challenge,
80+
enable_challenge1,
81+
enable_challenge2,
7682
}
7783
}
7884
}

aggregator/src/aggregation/rlc/gates.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,38 @@ impl RlcConfig {
197197
res
198198
}
199199

200-
pub(crate) fn read_challenge(
200+
pub(crate) fn read_challenge1(
201201
&self,
202202
region: &mut Region<Fr>,
203203
challenge_value: Challenges<Value<Fr>>,
204204
offset: &mut usize,
205205
) -> Result<AssignedCell<Fr, Fr>, Error> {
206206
let challenge_value = challenge_value.keccak_input();
207207
let challenge_cell = region.assign_advice(
208-
|| "assign challenge",
208+
|| "assign challenge1",
209209
self.phase_2_column,
210210
*offset,
211211
|| challenge_value,
212212
)?;
213-
self.enable_challenge.enable(region, *offset)?;
213+
self.enable_challenge1.enable(region, *offset)?;
214+
*offset += 1;
215+
Ok(challenge_cell)
216+
}
217+
218+
pub(crate) fn read_challenge2(
219+
&self,
220+
region: &mut Region<Fr>,
221+
challenge_value: Challenges<Value<Fr>>,
222+
offset: &mut usize,
223+
) -> Result<AssignedCell<Fr, Fr>, Error> {
224+
let challenge_value = challenge_value.evm_word();
225+
let challenge_cell = region.assign_advice(
226+
|| "assign challenge2",
227+
self.phase_2_column,
228+
*offset,
229+
|| challenge_value,
230+
)?;
231+
self.enable_challenge2.enable(region, *offset)?;
214232
*offset += 1;
215233
Ok(challenge_cell)
216234
}
@@ -250,7 +268,7 @@ impl RlcConfig {
250268

251269
a.copy_advice(|| "a", region, self.phase_2_column, *offset)?;
252270
let one = region.assign_advice(
253-
|| "c",
271+
|| "b",
254272
self.phase_2_column,
255273
*offset + 1,
256274
|| Value::known(Fr::one()),

0 commit comments

Comments
 (0)