diff --git a/aggregator/src/aggregation/blob_data.rs b/aggregator/src/aggregation/blob_data.rs index 11d5a496f0..460b7f2e7d 100644 --- a/aggregator/src/aggregation/blob_data.rs +++ b/aggregator/src/aggregation/blob_data.rs @@ -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, }; @@ -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, @@ -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::>(); let digest_bytes = digest_rows .iter() @@ -865,7 +865,7 @@ impl BlobDataConfig { .take(N_ROWS_METADATA + N_ROWS_DATA) .map(|row| row.byte.clone()) .collect::>(); - 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()); @@ -873,11 +873,11 @@ impl BlobDataConfig { 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::>(); - 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 { @@ -885,7 +885,7 @@ impl BlobDataConfig { challenge_digest: assigned_rows .iter() .rev() - .take(N_BYTES_32) + .take(N_BYTES_U256) .map(|row| row.byte.clone()) .collect(), chunk_data_digests, diff --git a/aggregator/src/blob.rs b/aggregator/src/blob.rs index b7e4382428..7954338f97 100644 --- a/aggregator/src/blob.rs +++ b/aggregator/src/blob.rs @@ -17,11 +17,11 @@ use zkevm_circuits::util::Challenges; /// form. pub const BLOB_WIDTH: usize = 4096; -/// 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 each BLS12-381 scalar into. The most-significant byte is 0. +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. @@ -34,7 +34,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; @@ -46,7 +46,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; @@ -191,7 +191,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();