Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions aggregator/src/aggregation/blob_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use zkevm_circuits::{
use crate::{
aggregation::rlc::POWS_OF_256,
blob::{
BlobData, BLOB_WIDTH, N_BYTES_31, N_BYTES_32, N_ROWS_BLOB_DATA_CONFIG, N_ROWS_DATA,
N_ROWS_DIGEST_BYTES, N_ROWS_DIGEST_RLC, N_ROWS_METADATA,
BlobData, BLOB_WIDTH, N_BYTES_U256, N_DATA_BYTES_PER_COEFFICIENT, N_ROWS_BLOB_DATA_CONFIG,
N_ROWS_DATA, N_ROWS_DIGEST_BYTES, N_ROWS_DIGEST_RLC, N_ROWS_METADATA,
},
RlcConfig, MAX_AGG_SNARKS,
};
Expand Down Expand Up @@ -517,7 +517,7 @@ impl BlobDataConfig {
};

// load cells representing the keccak digest of empty bytes.
let mut empty_digest_cells = Vec::with_capacity(N_BYTES_32);
let mut empty_digest_cells = Vec::with_capacity(N_BYTES_U256);
for (i, &byte) in keccak256([]).iter().enumerate() {
let cell = rlc_config.load_private(
&mut region,
Expand Down Expand Up @@ -815,8 +815,8 @@ impl BlobDataConfig {
{
let digest_rows = rows
.iter()
.skip(N_BYTES_32 * i)
.take(N_BYTES_32)
.skip(N_BYTES_U256 * i)
.take(N_BYTES_U256)
.collect::<Vec<_>>();
let digest_bytes = digest_rows
.iter()
Expand Down Expand Up @@ -865,27 +865,27 @@ impl BlobDataConfig {
.take(N_ROWS_METADATA + N_ROWS_DATA)
.map(|row| row.byte.clone())
.collect::<Vec<_>>();
for chunk in blob_bytes.chunks_exact(N_BYTES_31) {
for chunk in blob_bytes.chunks_exact(N_DATA_BYTES_PER_COEFFICIENT) {
// blob bytes are supposed to be deserialised in big-endianness. However, we
// have the export from BarycentricConfig in little-endian bytes.
blob_fields.push(chunk.iter().rev().cloned().collect());
}
let mut chunk_data_digests = Vec::with_capacity(MAX_AGG_SNARKS);
let chunk_data_digests_bytes = assigned_rows
.iter()
.skip(N_ROWS_METADATA + N_ROWS_DATA + N_ROWS_DIGEST_RLC + N_BYTES_32)
.take(MAX_AGG_SNARKS * N_BYTES_32)
.skip(N_ROWS_METADATA + N_ROWS_DATA + N_ROWS_DIGEST_RLC + N_BYTES_U256)
.take(MAX_AGG_SNARKS * N_BYTES_U256)
.map(|row| row.byte.clone())
.collect::<Vec<_>>();
for chunk in chunk_data_digests_bytes.chunks_exact(N_BYTES_32) {
for chunk in chunk_data_digests_bytes.chunks_exact(N_BYTES_U256) {
chunk_data_digests.push(chunk.to_vec());
}
let export = AssignedBlobDataExport {
num_valid_chunks,
challenge_digest: assigned_rows
.iter()
.rev()
.take(N_BYTES_32)
.take(N_BYTES_U256)
.map(|row| row.byte.clone())
.collect(),
chunk_data_digests,
Expand Down
14 changes: 7 additions & 7 deletions aggregator/src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ pub const BLOB_WIDTH: usize = 4096;
/// Logarithm to the base 2 of BLOB_WIDTH.
pub const LOG_BLOB_WIDTH: usize = 12;

/// The number 32
pub const N_BYTES_32: usize = 32;
/// The number of bytes to represent an unsigned 256 bit number.
pub const N_BYTES_U256: usize = 32;

/// The number 31
pub const N_BYTES_31: usize = N_BYTES_32 - 1;
/// The number data bytes we pack into each BLS12-381 scalar. The most 32nd byte is is 0.
Comment thread
roynalnaruto marked this conversation as resolved.
Outdated
pub const N_DATA_BYTES_PER_COEFFICIENT: usize = 31;

/// The number of rows to encode number of valid chunks (num_valid_snarks) in a batch, in the Blob
/// Data config. Since num_valid_chunks is u16, we use 2 bytes/rows.
Expand All @@ -36,7 +36,7 @@ pub const N_ROWS_CHUNK_SIZES: usize = MAX_AGG_SNARKS * 4;
/// The number of bytes that we can fit in a blob. Note that each coefficient is represented in 32
/// bytes, however, since those 32 bytes must represent a BLS12-381 scalar in its canonical form,
/// we explicitly set the most-significant byte to 0, effectively utilising only 31 bytes.
pub const N_BLOB_BYTES: usize = BLOB_WIDTH * N_BYTES_31;
pub const N_BLOB_BYTES: usize = BLOB_WIDTH * N_DATA_BYTES_PER_COEFFICIENT;

/// The number of rows in Blob Data config's layout to represent the "blob metadata" section.
pub const N_ROWS_METADATA: usize = N_ROWS_NUM_CHUNKS + N_ROWS_CHUNK_SIZES;
Expand All @@ -48,7 +48,7 @@ pub const N_ROWS_DATA: usize = N_BLOB_BYTES - N_ROWS_METADATA;
pub const N_ROWS_DIGEST_RLC: usize = 1 + 1 + MAX_AGG_SNARKS;

/// The number of rows in Blob Data config's layout to represent the "digest bytes" section.
pub const N_ROWS_DIGEST_BYTES: usize = N_ROWS_DIGEST_RLC * N_BYTES_32;
pub const N_ROWS_DIGEST_BYTES: usize = N_ROWS_DIGEST_RLC * N_BYTES_U256;

/// The total number of rows in "digest rlc" and "digest bytes" sections.
pub const N_ROWS_DIGEST: usize = N_ROWS_DIGEST_RLC + N_ROWS_DIGEST_BYTES;
Expand Down Expand Up @@ -186,7 +186,7 @@ impl BlobData {

/// Get the BLOB_WIDTH number of scalar field elements, as 32-bytes unsigned integers.
pub(crate) fn get_coefficients(&self) -> [U256; BLOB_WIDTH] {
let mut coefficients = [[0u8; N_BYTES_32]; BLOB_WIDTH];
let mut coefficients = [[0u8; N_BYTES_U256]; BLOB_WIDTH];

// We only consider the data from `valid` chunks and ignore the padded chunks.
let metadata_bytes = self.to_metadata_bytes();
Expand Down