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

Commit c5bd0c1

Browse files
committed
wip
1 parent 487c83e commit c5bd0c1

File tree

5 files changed

+81
-44
lines changed

5 files changed

+81
-44
lines changed

aggregator/src/aggregation/batch_data.rs

+9-38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
aggregation::rlc::POWS_OF_256, blob_consistency::BLOB_WIDTH, constants::N_BYTES_U256,
3-
BatchHash, ChunkInfo, RlcConfig,
2+
aggregation::rlc::POWS_OF_256, aggregation::util::constrain_crt_equals_bytes,
3+
blob_consistency::BLOB_WIDTH, constants::N_BYTES_U256, BatchHash, ChunkInfo, RlcConfig,
44
};
55
use eth_types::{H256, U256};
66
use ethers_core::utils::keccak256;
@@ -401,7 +401,7 @@ impl<const N_SNARKS: usize> BatchDataConfig<N_SNARKS> {
401401
chunks_are_padding: &[AssignedCell<Fr, Fr>],
402402
batch_data: &BatchData<N_SNARKS>,
403403
versioned_hash: H256,
404-
barycentric_assignments: &[CRTInteger<Fr>],
404+
challenge_digest: &CRTInteger<Fr>,
405405
) -> Result<AssignedBatchDataExport, Error> {
406406
self.load_range_tables(layouter)?;
407407

@@ -418,7 +418,7 @@ impl<const N_SNARKS: usize> BatchDataConfig<N_SNARKS> {
418418
challenge_value,
419419
rlc_config,
420420
chunks_are_padding,
421-
barycentric_assignments,
421+
challenge_digest,
422422
&assigned_rows,
423423
)
424424
},
@@ -550,7 +550,7 @@ impl<const N_SNARKS: usize> BatchDataConfig<N_SNARKS> {
550550
// The chunks_are_padding assigned cells are exports from the conditional constraints in
551551
// `core.rs`. Since these are already constrained, we can just use them as is.
552552
chunks_are_padding: &[AssignedCell<Fr, Fr>],
553-
barycentric_assignments: &[CRTInteger<Fr>],
553+
assigned_challenge_digest: &CRTInteger<Fr>,
554554
assigned_rows: &[AssignedBatchDataConfig],
555555
) -> Result<AssignedBatchDataExport, Error> {
556556
let n_rows_metadata = BatchData::<N_SNARKS>::n_rows_metadata();
@@ -996,41 +996,12 @@ impl<const N_SNARKS: usize> BatchDataConfig<N_SNARKS> {
996996
////////////////////////////////////////////////////////////////////////////////
997997
//////////////////////////// CHALLENGE DIGEST CHECK ////////////////////////////
998998
////////////////////////////////////////////////////////////////////////////////
999-
1000-
assert_eq!(barycentric_assignments.len(), BLOB_WIDTH + 1);
1001-
let challenge_digest_crt = barycentric_assignments
1002-
.get(BLOB_WIDTH)
1003-
.expect("challenge digest CRT");
1004-
let challenge_digest_limb1 = rlc_config.inner_product(
1005-
region,
1006-
&challenge_digest[0..11],
1007-
&pows_of_256,
1008-
&mut rlc_config_offset,
1009-
)?;
1010-
let challenge_digest_limb2 = rlc_config.inner_product(
1011-
region,
1012-
&challenge_digest[11..22],
1013-
&pows_of_256,
1014-
&mut rlc_config_offset,
1015-
)?;
1016-
let challenge_digest_limb3 = rlc_config.inner_product(
1017-
region,
1018-
&challenge_digest[22..32],
1019-
&pows_of_256[0..10],
999+
constrain_crt_equals_bytes(
1000+
rlc_config,
1001+
assigned_challenge_digest,
1002+
&challenge_digest,
10201003
&mut rlc_config_offset,
10211004
)?;
1022-
region.constrain_equal(
1023-
challenge_digest_limb1.cell(),
1024-
challenge_digest_crt.truncation.limbs[0].cell(),
1025-
)?;
1026-
region.constrain_equal(
1027-
challenge_digest_limb2.cell(),
1028-
challenge_digest_crt.truncation.limbs[1].cell(),
1029-
)?;
1030-
region.constrain_equal(
1031-
challenge_digest_limb3.cell(),
1032-
challenge_digest_crt.truncation.limbs[2].cell(),
1033-
)?;
10341005

10351006
Ok(export)
10361007
}

aggregator/src/aggregation/circuit.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
394394

395395
// blob data config
396396
{
397-
let barycentric_assignments = &barycentric.barycentric_assignments;
398397
let challenge_le = &barycentric.z_le;
399398
let evaluation_le = &barycentric.y_le;
400399

@@ -410,7 +409,7 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
410409
BlobConsistencyConfig::<N_SNARKS>::link(
411410
&mut layouter,
412411
&blob_data_exports.blob_crts_limbs,
413-
barycentric_assignments,
412+
barycentric.blob_crts(),
414413
)?;
415414

416415
let batch_data_exports = config.batch_data_config.assign(
@@ -420,7 +419,7 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
420419
&assigned_batch_hash.chunks_are_padding,
421420
&batch_data,
422421
self.batch_hash.blob_consistency_witness.id(),
423-
barycentric_assignments,
422+
barycentric.challenge_digest(),
424423
)?;
425424

426425
// conditionally encode those bytes. By default we use a worked example.

aggregator/src/aggregation/util.rs

+58-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
use crate::RlcConfig;
12
use gadgets::util::Expr;
3+
use halo2_ecc::bigint::CRTInteger;
24
use halo2_proofs::{
3-
plonk::{Advice, Column, ConstraintSystem, Expression, VirtualCells},
5+
circuit::{AssignedCell, Region},
6+
halo2curves::bn256::Fr,
7+
plonk::{Advice, Column, ConstraintSystem, Error, Expression, VirtualCells},
48
poly::Rotation,
59
};
10+
use itertools::Itertools;
611
use zkevm_circuits::util::Field;
712

813
#[derive(Clone, Copy, Debug)]
@@ -29,3 +34,55 @@ impl BooleanAdvice {
2934
meta.query_advice(self.column, at)
3035
}
3136
}
37+
38+
pub fn constrain_crt_equals_bytes(
39+
region: &mut Region<Fr>,
40+
rlc_config: RlcConfig,
41+
crt: &CRTInteger<Fr>,
42+
bytes: &[AssignedCell<Fr, Fr>],
43+
rlc_config_offset: &mut usize,
44+
) -> Result<(), Error> {
45+
let mut powers_of_256 = vec![];
46+
for i in 0..11 {
47+
let assigned_cell =
48+
rlc_config.load_private(region, Fr::from(256).pow(i), rlc_config_offset)?;
49+
let region_index = assigned_cell.cell().region_index;
50+
let fixed_cell = if i == 0 {
51+
rlc_config.one_cell(region_index)
52+
} else {
53+
rlc_config.pow_of_two_hundred_and_fifty_six_cell(region_index, i)
54+
};
55+
region.constrain_equal(fixed_cell, assigned_cell.cell())?;
56+
powers_of_256.push(assigned_cell);
57+
}
58+
59+
let limb_from_bytes_lo = rlc_config.inner_product(
60+
region,
61+
&bytes[0..11],
62+
&powers_of_256,
63+
&mut rlc_config_offset,
64+
)?;
65+
let limb_from_bytes_mid = rlc_config.inner_product(
66+
region,
67+
&bytes[11..22],
68+
&powers_of_256,
69+
&mut rlc_config_offset,
70+
)?;
71+
let limb_from_bytes_hi = rlc_config.inner_product(
72+
region,
73+
&bytes[22..32],
74+
&powers_of_256[0..10],
75+
&mut rlc_config_offset,
76+
)?;
77+
78+
for (limb_from_bytes, crt_limb) in [limb_from_bytes_lo, limb_from_bytes_mid, limb_from_bytes_hi]
79+
.iter()
80+
.zip_eq(crt.limbs())
81+
{
82+
region.constrain_equal(limb_from_bytes.cell(), crt_limb.cell())?
83+
}
84+
85+
Ok(())
86+
87+
// This can just be a collect....
88+
}

aggregator/src/blob_consistency/eip4844/barycentric.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,23 @@ pub struct BarycentricEvaluationConfig {
5555
pub struct AssignedBarycentricEvaluationConfig {
5656
/// CRTIntegers for the BLOB_WIDTH number of blob polynomial coefficients, followed by a
5757
/// CRTInteger for the challenge digest.
58-
pub(crate) barycentric_assignments: Vec<CRTInteger<Fr>>,
58+
barycentric_assignments: Vec<CRTInteger<Fr>>,
5959
/// 32 Assigned cells representing the LE-bytes of challenge z.
6060
pub(crate) z_le: Vec<AssignedValue<Fr>>,
6161
/// 32 Assigned cells representing the LE-bytes of evaluation y.
6262
pub(crate) y_le: Vec<AssignedValue<Fr>>,
6363
}
6464

65+
impl AssignedBarycentricEvaluationConfig {
66+
pub fn blob_crts(&self) -> &[CRTInteger<Fr>] {
67+
&self.barycentric_assignments[0..BLOB_WIDTH]
68+
}
69+
70+
pub fn challenge_digest(&self) -> &CRTInteger<Fr> {
71+
&self.barycentric_assignments[BLOB_WIDTH]
72+
}
73+
}
74+
6575
impl BarycentricEvaluationConfig {
6676
pub fn construct(range: RangeConfig<Fr>) -> Self {
6777
Self {

aggregator/src/blob_consistency/eip4844/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl Circuit<Fr> for BlobCircuit {
199199
challenge_values,
200200
&config.rlc,
201201
&chunks_are_padding,
202-
&barycentric_assignments.barycentric_assignments,
202+
barycentric_assignments.challenge_digest(),
203203
&assigned_rows,
204204
)?;
205205

0 commit comments

Comments
 (0)