From ef3828520b6217c24b0c3e0851bea1a9aed57546 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Fri, 23 Feb 2024 15:56:30 -0300 Subject: [PATCH 01/16] Rename `CommitBatches` and `CommitBatchInfo` to `CommitBatchesRollup` and `CommitBatchInfoRollup` --- .../src/i_executor/methods/commit_batches.rs | 8 ++++---- .../l1_contract_interface/src/i_executor/methods/mod.rs | 3 ++- .../src/i_executor/structures/commit_batch_info.rs | 6 +++--- .../src/i_executor/structures/mod.rs | 2 +- core/lib/zksync_core/src/consistency_checker/mod.rs | 4 ++-- core/lib/zksync_core/src/consistency_checker/tests/mod.rs | 2 +- .../src/consistency_checker/tests/test_helpers.rs | 2 +- .../zksync_core/src/eth_sender/aggregated_operations.rs | 4 ++-- core/lib/zksync_core/src/eth_sender/aggregator.rs | 6 +++--- core/lib/zksync_core/src/eth_sender/publish_criterion.rs | 4 ++-- core/lib/zksync_core/src/eth_sender/tests_helpers.rs | 4 ++-- 11 files changed, 23 insertions(+), 22 deletions(-) diff --git a/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs b/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs index eee6a83710f3..720fcd6caba5 100644 --- a/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs +++ b/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs @@ -6,26 +6,26 @@ use zksync_types::{ }; use crate::{ - i_executor::structures::{CommitBatchInfo, StoredBatchInfo}, + i_executor::structures::{CommitBatchInfoRollup, StoredBatchInfo}, Tokenizable, Tokenize, }; /// Input required to encode `commitBatches` call. #[derive(Debug, Clone)] -pub struct CommitBatches { +pub struct CommitBatchesRollup { pub last_committed_l1_batch: L1BatchWithMetadata, pub l1_batches: Vec, pub l1_batch_commit_data_generator: Arc, } -impl Tokenize for CommitBatches { +impl Tokenize for CommitBatchesRollup { fn into_tokens(self) -> Vec { let stored_batch_info = StoredBatchInfo(&self.last_committed_l1_batch).into_token(); let l1_batches_to_commit = self .l1_batches .iter() .map(|batch| { - CommitBatchInfo::new(batch, self.l1_batch_commit_data_generator.clone()) + CommitBatchInfoRollup::new(batch, self.l1_batch_commit_data_generator.clone()) .into_token() }) .collect(); diff --git a/core/lib/l1_contract_interface/src/i_executor/methods/mod.rs b/core/lib/l1_contract_interface/src/i_executor/methods/mod.rs index 765586edb3fa..946cd5591840 100644 --- a/core/lib/l1_contract_interface/src/i_executor/methods/mod.rs +++ b/core/lib/l1_contract_interface/src/i_executor/methods/mod.rs @@ -1,7 +1,8 @@ //! Utilities for encoding input data for methods defined in `IExecutor.sol`. pub use self::{ - commit_batches::CommitBatches, execute_batches::ExecuteBatches, prove_batches::ProveBatches, + commit_batches::CommitBatchesRollup, execute_batches::ExecuteBatches, + prove_batches::ProveBatches, }; mod commit_batches; diff --git a/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs b/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs index 143ce2662855..66a179a71a6f 100644 --- a/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs +++ b/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs @@ -12,12 +12,12 @@ use crate::Tokenizable; /// Encoding for `CommitBatchInfo` from `IExecutor.sol` #[derive(Debug)] -pub struct CommitBatchInfo<'a> { +pub struct CommitBatchInfoRollup<'a> { pub l1_batch_with_metadata: &'a L1BatchWithMetadata, pub l1_batch_commit_data_generator: Arc, } -impl<'a> CommitBatchInfo<'a> { +impl<'a> CommitBatchInfoRollup<'a> { pub fn new( l1_batch_with_metadata: &'a L1BatchWithMetadata, l1_batch_commit_data_generator: Arc, @@ -29,7 +29,7 @@ impl<'a> CommitBatchInfo<'a> { } } -impl<'a> Tokenizable for CommitBatchInfo<'a> { +impl<'a> Tokenizable for CommitBatchInfoRollup<'a> { fn from_token(_token: Token) -> Result where Self: Sized, diff --git a/core/lib/l1_contract_interface/src/i_executor/structures/mod.rs b/core/lib/l1_contract_interface/src/i_executor/structures/mod.rs index d1ed57e41f2e..da4f74d6f151 100644 --- a/core/lib/l1_contract_interface/src/i_executor/structures/mod.rs +++ b/core/lib/l1_contract_interface/src/i_executor/structures/mod.rs @@ -3,4 +3,4 @@ mod commit_batch_info; mod stored_batch_info; -pub use self::{commit_batch_info::CommitBatchInfo, stored_batch_info::StoredBatchInfo}; +pub use self::{commit_batch_info::CommitBatchInfoRollup, stored_batch_info::StoredBatchInfo}; diff --git a/core/lib/zksync_core/src/consistency_checker/mod.rs b/core/lib/zksync_core/src/consistency_checker/mod.rs index 48f2641507bd..6f1d00ccd0d9 100644 --- a/core/lib/zksync_core/src/consistency_checker/mod.rs +++ b/core/lib/zksync_core/src/consistency_checker/mod.rs @@ -7,7 +7,7 @@ use zksync_contracts::PRE_BOOJUM_COMMIT_FUNCTION; use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_eth_client::{clients::QueryClient, Error as L1ClientError, EthInterface}; use zksync_health_check::{Health, HealthStatus, HealthUpdater, ReactiveHealthCheck}; -use zksync_l1_contract_interface::{i_executor::structures::CommitBatchInfo, Tokenizable}; +use zksync_l1_contract_interface::{i_executor::structures::CommitBatchInfoRollup, Tokenizable}; use zksync_types::{ l1_batch_commit_data_generator::L1BatchCommitDataGenerator, web3::ethabi, L1BatchNumber, H256, }; @@ -183,7 +183,7 @@ impl LocalL1BatchCommitData { Ok(Some(Self { is_pre_boojum, - l1_commit_data: CommitBatchInfo::new(&l1_batch, l1_batch_commit_data_generator) + l1_commit_data: CommitBatchInfoRollup::new(&l1_batch, l1_batch_commit_data_generator) .into_token(), commit_tx_hash, })) diff --git a/core/lib/zksync_core/src/consistency_checker/tests/mod.rs b/core/lib/zksync_core/src/consistency_checker/tests/mod.rs index 6adf6c8f08dd..65efa3ed41c7 100644 --- a/core/lib/zksync_core/src/consistency_checker/tests/mod.rs +++ b/core/lib/zksync_core/src/consistency_checker/tests/mod.rs @@ -52,7 +52,7 @@ pub(crate) fn build_commit_tx_input_data( l1_batch_commit_data_generator: Arc, ) -> Vec { let commit_tokens = batches.iter().map(|batch| { - CommitBatchInfo::new(batch, l1_batch_commit_data_generator.clone()).into_token() + CommitBatchInfoRollup::new(batch, l1_batch_commit_data_generator.clone()).into_token() }); let commit_tokens = ethabi::Token::Array(commit_tokens.collect()); diff --git a/core/lib/zksync_core/src/consistency_checker/tests/test_helpers.rs b/core/lib/zksync_core/src/consistency_checker/tests/test_helpers.rs index 160663f96318..1c0c59ec8f48 100644 --- a/core/lib/zksync_core/src/consistency_checker/tests/test_helpers.rs +++ b/core/lib/zksync_core/src/consistency_checker/tests/test_helpers.rs @@ -29,7 +29,7 @@ pub(crate) fn build_commit_tx_input_data_is_correct( .unwrap(); assert_eq!( commit_data, - CommitBatchInfo::new(batch, l1_batch_commit_data_generator.clone().clone()) + CommitBatchInfoRollup::new(batch, l1_batch_commit_data_generator.clone().clone()) .into_token() ); } diff --git a/core/lib/zksync_core/src/eth_sender/aggregated_operations.rs b/core/lib/zksync_core/src/eth_sender/aggregated_operations.rs index bb7cf75e50d4..bda71301f0ac 100644 --- a/core/lib/zksync_core/src/eth_sender/aggregated_operations.rs +++ b/core/lib/zksync_core/src/eth_sender/aggregated_operations.rs @@ -1,14 +1,14 @@ use std::ops; use zksync_l1_contract_interface::i_executor::methods::{ - CommitBatches, ExecuteBatches, ProveBatches, + CommitBatchesRollup, ExecuteBatches, ProveBatches, }; use zksync_types::{aggregated_operations::AggregatedActionType, L1BatchNumber, ProtocolVersionId}; #[allow(clippy::large_enum_variant)] #[derive(Debug, Clone)] pub enum AggregatedOperation { - Commit(CommitBatches), + Commit(CommitBatchesRollup), PublishProofOnchain(ProveBatches), Execute(ExecuteBatches), } diff --git a/core/lib/zksync_core/src/eth_sender/aggregator.rs b/core/lib/zksync_core/src/eth_sender/aggregator.rs index 78170c3855e8..0d4ac042edfe 100644 --- a/core/lib/zksync_core/src/eth_sender/aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/aggregator.rs @@ -4,7 +4,7 @@ use zksync_config::configs::eth_sender::{ProofLoadingMode, ProofSendingMode, Sen use zksync_contracts::BaseSystemContractsHashes; use zksync_dal::StorageProcessor; use zksync_l1_contract_interface::i_executor::methods::{ - CommitBatches, ExecuteBatches, ProveBatches, + CommitBatchesRollup, ExecuteBatches, ProveBatches, }; use zksync_object_store::{ObjectStore, ObjectStoreError}; use zksync_prover_interface::outputs::L1BatchProofForL1; @@ -179,7 +179,7 @@ impl Aggregator { last_sealed_batch: L1BatchNumber, base_system_contracts_hashes: BaseSystemContractsHashes, protocol_version_id: ProtocolVersionId, - ) -> Option { + ) -> Option { let mut blocks_dal = storage.blocks_dal(); let last_committed_l1_batch = blocks_dal .get_last_committed_to_eth_l1_batch() @@ -227,7 +227,7 @@ impl Aggregator { ) .await; - batches.map(|batches| CommitBatches { + batches.map(|batches| CommitBatchesRollup { last_committed_l1_batch, l1_batches: batches, l1_batch_commit_data_generator: self.l1_batch_commit_data_generator.clone(), diff --git a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs index 1d543423eb2d..2dad52748893 100644 --- a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs +++ b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs @@ -3,7 +3,7 @@ use std::{fmt, sync::Arc}; use async_trait::async_trait; use chrono::Utc; use zksync_dal::StorageProcessor; -use zksync_l1_contract_interface::{i_executor::structures::CommitBatchInfo, Tokenizable}; +use zksync_l1_contract_interface::{i_executor::structures::CommitBatchInfoRollup, Tokenizable}; use zksync_types::{ aggregated_operations::AggregatedActionType, commitment::L1BatchWithMetadata, ethabi, l1_batch_commit_data_generator::L1BatchCommitDataGenerator, L1BatchNumber, @@ -220,7 +220,7 @@ impl L1BatchPublishCriterion for DataSizeCriterion { for (index, l1_batch) in consecutive_l1_batches.iter().enumerate() { // TODO (PLA-771): Make sure that this estimation is correct. let l1_commit_data_size = - ethabi::encode(&[ethabi::Token::Array(vec![CommitBatchInfo::new( + ethabi::encode(&[ethabi::Token::Array(vec![CommitBatchInfoRollup::new( l1_batch, self.l1_batch_commit_data_generator.clone(), ) diff --git a/core/lib/zksync_core/src/eth_sender/tests_helpers.rs b/core/lib/zksync_core/src/eth_sender/tests_helpers.rs index a33579f83cef..10fd0b6a05c9 100644 --- a/core/lib/zksync_core/src/eth_sender/tests_helpers.rs +++ b/core/lib/zksync_core/src/eth_sender/tests_helpers.rs @@ -9,7 +9,7 @@ use zksync_config::{ use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_eth_client::{clients::MockEthereum, EthInterface}; use zksync_l1_contract_interface::i_executor::methods::{ - CommitBatches, ExecuteBatches, ProveBatches, + CommitBatchesRollup, ExecuteBatches, ProveBatches, }; use zksync_object_store::ObjectStoreFactory; use zksync_types::{ @@ -646,7 +646,7 @@ async fn commit_l1_batch( confirm: bool, l1_batch_commit_data_generator: Arc, ) -> H256 { - let operation = AggregatedOperation::Commit(CommitBatches { + let operation = AggregatedOperation::Commit(CommitBatchesRollup { last_committed_l1_batch: l1_batch_with_metadata(last_committed_l1_batch), l1_batches: vec![l1_batch_with_metadata(l1_batch)], l1_batch_commit_data_generator, From d682be48d3d501951d5d99e98032564e9f772365 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Thu, 29 Feb 2024 17:52:27 -0300 Subject: [PATCH 02/16] Big L1CommitBatchesDataGenerator refactor --- contracts | 2 +- core/bin/external_node/src/main.rs | 16 +-- .../src/i_executor/methods/commit_batches.rs | 36 ++++--- .../src/i_executor/methods/mod.rs | 3 +- .../structures/commit_batch_info.rs | 99 ++++++++++++++++--- .../src/i_executor/structures/mod.rs | 5 +- .../src/l1_batch_commit_data_generator.rs | 76 -------------- core/lib/types/src/lib.rs | 2 - .../src/consistency_checker/mod.rs | 27 +---- .../src/consistency_checker/tests/mod.rs | 98 +++--------------- .../consistency_checker/tests/test_helpers.rs | 46 +++------ .../src/eth_sender/aggregated_operations.rs | 17 ++-- .../zksync_core/src/eth_sender/aggregator.rs | 15 +-- .../src/eth_sender/eth_tx_aggregator.rs | 17 +++- .../l1_batch_commit_data_generator.rs | 50 ++++++++++ core/lib/zksync_core/src/eth_sender/mod.rs | 1 + .../src/eth_sender/publish_criterion.rs | 8 +- core/lib/zksync_core/src/eth_sender/tests.rs | 40 ++------ .../src/eth_sender/tests_helpers.rs | 32 ++---- core/lib/zksync_core/src/lib.rs | 15 +-- 20 files changed, 261 insertions(+), 344 deletions(-) delete mode 100644 core/lib/types/src/l1_batch_commit_data_generator.rs create mode 100644 core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs diff --git a/contracts b/contracts index 6804b2374ce2..ceb214b7650c 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit 6804b2374ce23a8f85f4e2d4ec96219c6aad6653 +Subproject commit ceb214b7650c6102703a9b5569a4056fe97a3be4 diff --git a/core/bin/external_node/src/main.rs b/core/bin/external_node/src/main.rs index 657807867fe9..735df320e7b9 100644 --- a/core/bin/external_node/src/main.rs +++ b/core/bin/external_node/src/main.rs @@ -8,7 +8,7 @@ use prometheus_exporter::PrometheusExporterConfig; use tokio::{sync::watch, task, time::sleep}; use zksync_basic_types::{Address, L2ChainId}; use zksync_concurrency::{ctx, scope}; -use zksync_config::configs::{chain::L1BatchCommitDataGeneratorMode, database::MerkleTreeMode}; +use zksync_config::configs::database::MerkleTreeMode; use zksync_core::{ api_server::{ execution_sandbox::VmConcurrencyLimiter, @@ -37,10 +37,6 @@ use zksync_dal::{healthcheck::ConnectionPoolHealthCheck, ConnectionPool}; use zksync_health_check::{AppHealthCheck, HealthStatus, ReactiveHealthCheck}; use zksync_state::PostgresStorageCaches; use zksync_storage::RocksDB; -use zksync_types::l1_batch_commit_data_generator::{ - L1BatchCommitDataGenerator, RollupModeL1BatchCommitDataGenerator, - ValidiumModeL1BatchCommitDataGenerator, -}; use zksync_utils::wait_for_tasks::wait_for_tasks; use zksync_web3_decl::jsonrpsee::http_client::HttpClient; @@ -233,15 +229,6 @@ async fn init_tasks( .context("failed initializing metadata calculator")?; app_health.insert_component(metadata_calculator.tree_health_check()); - let l1_batch_commit_data_generator: Arc = match config - .optional - .l1_batch_commit_data_generator_mode - { - L1BatchCommitDataGeneratorMode::Rollup => Arc::new(RollupModeL1BatchCommitDataGenerator {}), - L1BatchCommitDataGeneratorMode::Validium => { - Arc::new(ValidiumModeL1BatchCommitDataGenerator {}) - } - }; let consistency_checker = ConsistencyChecker::new( &config .required @@ -252,7 +239,6 @@ async fn init_tasks( .build() .await .context("failed to build connection pool for ConsistencyChecker")?, - l1_batch_commit_data_generator, ); app_health.insert_component(consistency_checker.health_check().clone()); let consistency_checker_handle = tokio::spawn(consistency_checker.run(stop_receiver.clone())); diff --git a/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs b/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs index 720fcd6caba5..c64d98a0b108 100644 --- a/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs +++ b/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs @@ -1,12 +1,7 @@ -use std::sync::Arc; - -use zksync_types::{ - commitment::L1BatchWithMetadata, ethabi::Token, - l1_batch_commit_data_generator::L1BatchCommitDataGenerator, -}; +use zksync_types::{commitment::L1BatchWithMetadata, ethabi::Token}; use crate::{ - i_executor::structures::{CommitBatchInfoRollup, StoredBatchInfo}, + i_executor::structures::{CommitBatchInfoRollup, CommitBatchInfoValidium, StoredBatchInfo}, Tokenizable, Tokenize, }; @@ -15,7 +10,6 @@ use crate::{ pub struct CommitBatchesRollup { pub last_committed_l1_batch: L1BatchWithMetadata, pub l1_batches: Vec, - pub l1_batch_commit_data_generator: Arc, } impl Tokenize for CommitBatchesRollup { @@ -24,10 +18,28 @@ impl Tokenize for CommitBatchesRollup { let l1_batches_to_commit = self .l1_batches .iter() - .map(|batch| { - CommitBatchInfoRollup::new(batch, self.l1_batch_commit_data_generator.clone()) - .into_token() - }) + .map(|batch| CommitBatchInfoRollup::new(batch).into_token()) + .collect(); + + vec![stored_batch_info, Token::Array(l1_batches_to_commit)] + } +} + +/// Input required to encode `commitBatches` call. +#[derive(Debug, Clone)] +pub struct CommitBatchesValidium { + pub last_committed_l1_batch: L1BatchWithMetadata, + pub l1_batches: Vec, +} + +impl Tokenize for CommitBatchesValidium { + // FIXME: use Validium + fn into_tokens(self) -> Vec { + let stored_batch_info = StoredBatchInfo(&self.last_committed_l1_batch).into_token(); + let l1_batches_to_commit = self + .l1_batches + .iter() + .map(|batch| CommitBatchInfoValidium::new(batch).into_token()) .collect(); vec![stored_batch_info, Token::Array(l1_batches_to_commit)] diff --git a/core/lib/l1_contract_interface/src/i_executor/methods/mod.rs b/core/lib/l1_contract_interface/src/i_executor/methods/mod.rs index 946cd5591840..9981656ba38f 100644 --- a/core/lib/l1_contract_interface/src/i_executor/methods/mod.rs +++ b/core/lib/l1_contract_interface/src/i_executor/methods/mod.rs @@ -1,7 +1,8 @@ //! Utilities for encoding input data for methods defined in `IExecutor.sol`. pub use self::{ - commit_batches::CommitBatchesRollup, execute_batches::ExecuteBatches, + commit_batches::{CommitBatchesRollup, CommitBatchesValidium}, + execute_batches::ExecuteBatches, prove_batches::ProveBatches, }; diff --git a/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs b/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs index 66a179a71a6f..d91c891a0fbd 100644 --- a/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs +++ b/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs @@ -1,9 +1,6 @@ -use std::sync::Arc; - use zksync_types::{ - commitment::{pre_boojum_serialize_commitments, L1BatchWithMetadata}, + commitment::{pre_boojum_serialize_commitments, serialize_commitments, L1BatchWithMetadata}, ethabi::Token, - l1_batch_commit_data_generator::L1BatchCommitDataGenerator, web3::{contract::Error as Web3ContractError, error::Error as Web3ApiError}, U256, }; @@ -14,17 +11,12 @@ use crate::Tokenizable; #[derive(Debug)] pub struct CommitBatchInfoRollup<'a> { pub l1_batch_with_metadata: &'a L1BatchWithMetadata, - pub l1_batch_commit_data_generator: Arc, } impl<'a> CommitBatchInfoRollup<'a> { - pub fn new( - l1_batch_with_metadata: &'a L1BatchWithMetadata, - l1_batch_commit_data_generator: Arc, - ) -> Self { + pub fn new(l1_batch_with_metadata: &'a L1BatchWithMetadata) -> Self { Self { l1_batch_with_metadata, - l1_batch_commit_data_generator, } } } @@ -52,12 +44,43 @@ impl<'a> Tokenizable for CommitBatchInfoRollup<'a> { { pre_boojum_into_token(self.l1_batch_with_metadata) } else { - self.l1_batch_commit_data_generator - .l1_commit_data(self.l1_batch_with_metadata) + Token::Tuple(rollup_mode_l1_commit_data(self.l1_batch_with_metadata)) + } + } +} + +/// Encoding for `CommitBatchInfo` from `IExecutor.sol` +#[derive(Debug)] +pub struct CommitBatchInfoValidium<'a> { + pub l1_batch_with_metadata: &'a L1BatchWithMetadata, +} + +impl<'a> CommitBatchInfoValidium<'a> { + pub fn new(l1_batch_with_metadata: &'a L1BatchWithMetadata) -> Self { + Self { + l1_batch_with_metadata, } } } +impl<'a> Tokenizable for CommitBatchInfoValidium<'a> { + fn from_token(_token: Token) -> Result + where + Self: Sized, + { + // Currently there is no need to decode this struct. + // We still want to implement `Tokenizable` trait for it, so that *once* it's needed + // the implementation is provided here and not in some other inconsistent way. + Err(Web3ContractError::Api(Web3ApiError::Decoder( + "Not implemented".to_string(), + ))) + } + + fn into_token(self) -> Token { + Token::Tuple(validium_mode_l1_commit_data(self.l1_batch_with_metadata)) + } +} + fn pre_boojum_into_token(l1_batch_commit_with_metadata: &L1BatchWithMetadata) -> Token { let header = &l1_batch_commit_with_metadata.header; let metadata = &l1_batch_commit_with_metadata.metadata; @@ -88,3 +111,55 @@ fn pre_boojum_into_token(l1_batch_commit_with_metadata: &L1BatchWithMetadata) -> ), ]) } + +fn encode_l1_commit(l1_batch_with_metadata: &L1BatchWithMetadata, pubdata: Token) -> Vec { + let header = &l1_batch_with_metadata.header; + let metadata = &l1_batch_with_metadata.metadata; + let commit_data = vec![ + // `batchNumber` + Token::Uint(U256::from(header.number.0)), + // `timestamp` + Token::Uint(U256::from(header.timestamp)), + // `indexRepeatedStorageChanges` + Token::Uint(U256::from(metadata.rollup_last_leaf_index)), + // `newStateRoot` + Token::FixedBytes(metadata.merkle_root_hash.as_bytes().to_vec()), + // `numberOfLayer1Txs` + Token::Uint(U256::from(header.l1_tx_count)), + // `priorityOperationsHash` + Token::FixedBytes(header.priority_ops_onchain_data_hash().as_bytes().to_vec()), + // `bootloaderHeapInitialContentsHash` + Token::FixedBytes( + metadata + .bootloader_initial_content_commitment + .unwrap() + .as_bytes() + .to_vec(), + ), + // `eventsQueueStateHash` + Token::FixedBytes( + metadata + .events_queue_commitment + .unwrap() + .as_bytes() + .to_vec(), + ), + // `systemLogs` + Token::Bytes(serialize_commitments(&header.system_logs)), + pubdata, + ]; + commit_data +} + +fn validium_mode_l1_commit_data(l1_batch_with_metadata: &L1BatchWithMetadata) -> Vec { + encode_l1_commit(l1_batch_with_metadata, Token::Bytes([0].to_vec())) +} + +fn rollup_mode_l1_commit_data(l1_batch_with_metadata: &L1BatchWithMetadata) -> Vec { + encode_l1_commit( + l1_batch_with_metadata, + Token::Bytes(L1BatchWithMetadata::construct_pubdata( + l1_batch_with_metadata, + )), + ) +} diff --git a/core/lib/l1_contract_interface/src/i_executor/structures/mod.rs b/core/lib/l1_contract_interface/src/i_executor/structures/mod.rs index da4f74d6f151..8d9ecd931095 100644 --- a/core/lib/l1_contract_interface/src/i_executor/structures/mod.rs +++ b/core/lib/l1_contract_interface/src/i_executor/structures/mod.rs @@ -3,4 +3,7 @@ mod commit_batch_info; mod stored_batch_info; -pub use self::{commit_batch_info::CommitBatchInfoRollup, stored_batch_info::StoredBatchInfo}; +pub use self::{ + commit_batch_info::{CommitBatchInfoRollup, CommitBatchInfoValidium}, + stored_batch_info::StoredBatchInfo, +}; diff --git a/core/lib/types/src/l1_batch_commit_data_generator.rs b/core/lib/types/src/l1_batch_commit_data_generator.rs deleted file mode 100644 index cd97e85b3e67..000000000000 --- a/core/lib/types/src/l1_batch_commit_data_generator.rs +++ /dev/null @@ -1,76 +0,0 @@ -use zksync_basic_types::{ethabi::Token, U256}; - -use crate::commitment::{serialize_commitments, L1BatchWithMetadata}; - -pub trait L1BatchCommitDataGenerator -where - Self: std::fmt::Debug + Send + Sync, -{ - fn l1_commit_data(&self, l1_batch_with_metadata: &L1BatchWithMetadata) -> Token; -} - -#[derive(Debug, Clone)] -pub struct RollupModeL1BatchCommitDataGenerator; - -#[derive(Debug, Clone)] -pub struct ValidiumModeL1BatchCommitDataGenerator; - -impl L1BatchCommitDataGenerator for RollupModeL1BatchCommitDataGenerator { - fn l1_commit_data(&self, l1_batch_with_metadata: &L1BatchWithMetadata) -> Token { - Token::Tuple(rollup_mode_l1_commit_data(l1_batch_with_metadata)) - } -} - -impl L1BatchCommitDataGenerator for ValidiumModeL1BatchCommitDataGenerator { - fn l1_commit_data(&self, l1_batch_with_metadata: &L1BatchWithMetadata) -> Token { - let mut commit_data = validium_mode_l1_commit_data(l1_batch_with_metadata); - commit_data.push(Token::Bytes(vec![])); - Token::Tuple(commit_data) - } -} - -fn validium_mode_l1_commit_data(l1_batch_with_metadata: &L1BatchWithMetadata) -> Vec { - let header = &l1_batch_with_metadata.header; - let metadata = &l1_batch_with_metadata.metadata; - let commit_data = vec![ - // `batchNumber` - Token::Uint(U256::from(header.number.0)), - // `timestamp` - Token::Uint(U256::from(header.timestamp)), - // `indexRepeatedStorageChanges` - Token::Uint(U256::from(metadata.rollup_last_leaf_index)), - // `newStateRoot` - Token::FixedBytes(metadata.merkle_root_hash.as_bytes().to_vec()), - // `numberOfLayer1Txs` - Token::Uint(U256::from(header.l1_tx_count)), - // `priorityOperationsHash` - Token::FixedBytes(header.priority_ops_onchain_data_hash().as_bytes().to_vec()), - // `bootloaderHeapInitialContentsHash` - Token::FixedBytes( - metadata - .bootloader_initial_content_commitment - .unwrap() - .as_bytes() - .to_vec(), - ), - // `eventsQueueStateHash` - Token::FixedBytes( - metadata - .events_queue_commitment - .unwrap() - .as_bytes() - .to_vec(), - ), - // `systemLogs` - Token::Bytes(serialize_commitments(&header.system_logs)), - ]; - commit_data -} - -fn rollup_mode_l1_commit_data(l1_batch_with_metadata: &L1BatchWithMetadata) -> Vec { - let mut commit_data = validium_mode_l1_commit_data(l1_batch_with_metadata); - commit_data.push(Token::Bytes(L1BatchWithMetadata::construct_pubdata( - l1_batch_with_metadata, - ))); - commit_data -} diff --git a/core/lib/types/src/lib.rs b/core/lib/types/src/lib.rs index 775ea2cd89c5..27cffb360a3f 100644 --- a/core/lib/types/src/lib.rs +++ b/core/lib/types/src/lib.rs @@ -55,8 +55,6 @@ pub mod transaction_request; pub mod utils; pub mod vm_version; -pub mod l1_batch_commit_data_generator; - /// Denotes the first byte of the special zkSync's EIP-712-signed transaction. pub const EIP_712_TX_TYPE: u8 = 0x71; diff --git a/core/lib/zksync_core/src/consistency_checker/mod.rs b/core/lib/zksync_core/src/consistency_checker/mod.rs index 6f1d00ccd0d9..08c778c0f6aa 100644 --- a/core/lib/zksync_core/src/consistency_checker/mod.rs +++ b/core/lib/zksync_core/src/consistency_checker/mod.rs @@ -1,4 +1,4 @@ -use std::{fmt, sync::Arc, time::Duration}; +use std::{fmt, time::Duration}; use anyhow::Context as _; use serde::Serialize; @@ -8,9 +8,7 @@ use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_eth_client::{clients::QueryClient, Error as L1ClientError, EthInterface}; use zksync_health_check::{Health, HealthStatus, HealthUpdater, ReactiveHealthCheck}; use zksync_l1_contract_interface::{i_executor::structures::CommitBatchInfoRollup, Tokenizable}; -use zksync_types::{ - l1_batch_commit_data_generator::L1BatchCommitDataGenerator, web3::ethabi, L1BatchNumber, H256, -}; +use zksync_types::{web3::ethabi, L1BatchNumber, H256}; use crate::{ metrics::{CheckerComponent, EN_METRICS}, @@ -135,7 +133,6 @@ impl LocalL1BatchCommitData { async fn new( storage: &mut StorageProcessor<'_>, batch_number: L1BatchNumber, - l1_batch_commit_data_generator: Arc, ) -> anyhow::Result> { let Some(storage_l1_batch) = storage .blocks_dal() @@ -183,8 +180,7 @@ impl LocalL1BatchCommitData { Ok(Some(Self { is_pre_boojum, - l1_commit_data: CommitBatchInfoRollup::new(&l1_batch, l1_batch_commit_data_generator) - .into_token(), + l1_commit_data: CommitBatchInfoRollup::new(&l1_batch).into_token(), commit_tx_hash, })) } @@ -201,19 +197,13 @@ pub struct ConsistencyChecker { event_handler: Box, l1_data_mismatch_behavior: L1DataMismatchBehavior, pool: ConnectionPool, - l1_batch_commit_data_generator: Arc, health_check: ReactiveHealthCheck, } impl ConsistencyChecker { const DEFAULT_SLEEP_INTERVAL: Duration = Duration::from_secs(5); - pub fn new( - web3_url: &str, - max_batches_to_recheck: u32, - pool: ConnectionPool, - l1_batch_commit_data_generator: Arc, - ) -> Self { + pub fn new(web3_url: &str, max_batches_to_recheck: u32, pool: ConnectionPool) -> Self { let web3 = QueryClient::new(web3_url).unwrap(); let (health_check, health_updater) = ConsistencyCheckerHealthUpdater::new(); Self { @@ -225,7 +215,6 @@ impl ConsistencyChecker { l1_data_mismatch_behavior: L1DataMismatchBehavior::Log, pool, health_check, - l1_batch_commit_data_generator, } } /// Returns health check associated with this checker. @@ -374,13 +363,7 @@ impl ConsistencyChecker { // The batch might be already committed but not yet processed by the external node's tree // OR the batch might be processed by the external node's tree but not yet committed. // We need both. - let Some(local) = LocalL1BatchCommitData::new( - &mut storage, - batch_number, - self.l1_batch_commit_data_generator.clone(), - ) - .await? - else { + let Some(local) = LocalL1BatchCommitData::new(&mut storage, batch_number).await? else { tokio::time::sleep(self.sleep_interval).await; continue; }; diff --git a/core/lib/zksync_core/src/consistency_checker/tests/mod.rs b/core/lib/zksync_core/src/consistency_checker/tests/mod.rs index 65efa3ed41c7..1be107113dce 100644 --- a/core/lib/zksync_core/src/consistency_checker/tests/mod.rs +++ b/core/lib/zksync_core/src/consistency_checker/tests/mod.rs @@ -10,13 +10,8 @@ use zksync_dal::StorageProcessor; use zksync_eth_client::clients::MockEthereum; use zksync_l1_contract_interface::i_executor::structures::StoredBatchInfo; use zksync_types::{ - aggregated_operations::AggregatedActionType, - commitment::L1BatchWithMetadata, - l1_batch_commit_data_generator::{ - RollupModeL1BatchCommitDataGenerator, ValidiumModeL1BatchCommitDataGenerator, - }, - web3::contract::Options, - ProtocolVersionId, H256, + aggregated_operations::AggregatedActionType, commitment::L1BatchWithMetadata, + web3::contract::Options, ProtocolVersionId, H256, }; use super::*; @@ -47,13 +42,10 @@ pub(crate) fn create_pre_boojum_l1_batch_with_metadata(number: u32) -> L1BatchWi l1_batch } -pub(crate) fn build_commit_tx_input_data( - batches: &[L1BatchWithMetadata], - l1_batch_commit_data_generator: Arc, -) -> Vec { - let commit_tokens = batches.iter().map(|batch| { - CommitBatchInfoRollup::new(batch, l1_batch_commit_data_generator.clone()).into_token() - }); +pub(crate) fn build_commit_tx_input_data(batches: &[L1BatchWithMetadata]) -> Vec { + let commit_tokens = batches + .iter() + .map(|batch| CommitBatchInfoRollup::new(batch).into_token()); let commit_tokens = ethabi::Token::Array(commit_tokens.collect()); let mut encoded = vec![]; @@ -70,7 +62,6 @@ pub(crate) fn build_commit_tx_input_data( pub(crate) fn create_mock_checker( client: MockEthereum, pool: ConnectionPool, - l1_batch_commit_data_generator: Arc, ) -> ConsistencyChecker { let (health_check, health_updater) = ConsistencyCheckerHealthUpdater::new(); ConsistencyChecker { @@ -81,7 +72,6 @@ pub(crate) fn create_mock_checker( event_handler: Box::new(health_updater), l1_data_mismatch_behavior: L1DataMismatchBehavior::Bail, pool, - l1_batch_commit_data_generator, health_check, } } @@ -106,12 +96,7 @@ impl HandleConsistencyCheckerEvent for mpsc::UnboundedSender { #[test] fn build_commit_tx_input_data_is_correct() { - test_helpers::build_commit_tx_input_data_is_correct(Arc::new( - RollupModeL1BatchCommitDataGenerator {}, - )); - test_helpers::build_commit_tx_input_data_is_correct(Arc::new( - ValidiumModeL1BatchCommitDataGenerator {}, - )); + test_helpers::build_commit_tx_input_data_is_correct(); } #[test] @@ -309,13 +294,6 @@ async fn normal_checker_function( test_helpers::normal_checker_function( batches_per_transaction, (mapper_name, save_actions_mapper), - Arc::new(RollupModeL1BatchCommitDataGenerator {}), - ) - .await; - test_helpers::normal_checker_function( - batches_per_transaction, - (mapper_name, save_actions_mapper), - Arc::new(ValidiumModeL1BatchCommitDataGenerator {}), ) .await; } @@ -325,31 +303,13 @@ async fn normal_checker_function( async fn checker_processes_pre_boojum_batches( (mapper_name, save_actions_mapper): (&'static str, SaveActionMapper), ) { - test_helpers::checker_processes_pre_boojum_batches( - (mapper_name, save_actions_mapper), - Arc::new(RollupModeL1BatchCommitDataGenerator {}), - ) - .await; - test_helpers::checker_processes_pre_boojum_batches( - (mapper_name, save_actions_mapper), - Arc::new(ValidiumModeL1BatchCommitDataGenerator {}), - ) - .await; + test_helpers::checker_processes_pre_boojum_batches((mapper_name, save_actions_mapper)).await; } #[test_casing(2, [false, true])] #[tokio::test] async fn checker_functions_after_snapshot_recovery(delay_batch_insertion: bool) { - test_helpers::checker_functions_after_snapshot_recovery( - delay_batch_insertion, - Arc::new(RollupModeL1BatchCommitDataGenerator {}), - ) - .await; - test_helpers::checker_functions_after_snapshot_recovery( - delay_batch_insertion, - Arc::new(ValidiumModeL1BatchCommitDataGenerator {}), - ) - .await; + test_helpers::checker_functions_after_snapshot_recovery(delay_batch_insertion).await; } #[derive(Debug, Clone, Copy)] @@ -372,21 +332,13 @@ impl IncorrectDataKind { Self::CommitDataForPreBoojum, ]; - async fn apply( - self, - client: &MockEthereum, - l1_batch: &L1BatchWithMetadata, - l1_batch_commit_data_generator: Arc, - ) -> H256 { + async fn apply(self, client: &MockEthereum, l1_batch: &L1BatchWithMetadata) -> H256 { let (commit_tx_input_data, successful_status) = match self { Self::MissingStatus => { return H256::zero(); // Do not execute the transaction } Self::MismatchedStatus => { - let commit_tx_input_data = build_commit_tx_input_data( - slice::from_ref(l1_batch), - l1_batch_commit_data_generator, - ); + let commit_tx_input_data = build_commit_tx_input_data(slice::from_ref(l1_batch)); (commit_tx_input_data, false) } Self::BogusCommitDataFormat => { @@ -398,27 +350,18 @@ impl IncorrectDataKind { Self::MismatchedCommitDataTimestamp => { let mut l1_batch = create_l1_batch_with_metadata(1); l1_batch.header.timestamp += 1; - let bogus_tx_input_data = build_commit_tx_input_data( - slice::from_ref(&l1_batch), - l1_batch_commit_data_generator, - ); + let bogus_tx_input_data = build_commit_tx_input_data(slice::from_ref(&l1_batch)); (bogus_tx_input_data, true) } Self::CommitDataForAnotherBatch => { let l1_batch = create_l1_batch_with_metadata(100); - let bogus_tx_input_data = build_commit_tx_input_data( - slice::from_ref(&l1_batch), - l1_batch_commit_data_generator, - ); + let bogus_tx_input_data = build_commit_tx_input_data(slice::from_ref(&l1_batch)); (bogus_tx_input_data, true) } Self::CommitDataForPreBoojum => { let mut l1_batch = create_l1_batch_with_metadata(1); l1_batch.header.protocol_version = Some(ProtocolVersionId::Version0); - let bogus_tx_input_data = build_commit_tx_input_data( - slice::from_ref(&l1_batch), - l1_batch_commit_data_generator, - ); + let bogus_tx_input_data = build_commit_tx_input_data(slice::from_ref(&l1_batch)); (bogus_tx_input_data, true) } }; @@ -441,18 +384,7 @@ impl IncorrectDataKind { // ^ `snapshot_recovery = true` is tested below; we don't want to run it with all incorrect data kinds #[tokio::test] async fn checker_detects_incorrect_tx_data(kind: IncorrectDataKind, snapshot_recovery: bool) { - test_helpers::checker_detects_incorrect_tx_data( - kind, - snapshot_recovery, - Arc::new(RollupModeL1BatchCommitDataGenerator {}), - ) - .await; - test_helpers::checker_detects_incorrect_tx_data( - kind, - snapshot_recovery, - Arc::new(ValidiumModeL1BatchCommitDataGenerator {}), - ) - .await; + test_helpers::checker_detects_incorrect_tx_data(kind, snapshot_recovery).await; } #[tokio::test] diff --git a/core/lib/zksync_core/src/consistency_checker/tests/test_helpers.rs b/core/lib/zksync_core/src/consistency_checker/tests/test_helpers.rs index 1c0c59ec8f48..8395302700b7 100644 --- a/core/lib/zksync_core/src/consistency_checker/tests/test_helpers.rs +++ b/core/lib/zksync_core/src/consistency_checker/tests/test_helpers.rs @@ -7,9 +7,7 @@ use zksync_types::{web3::contract::Options, L2ChainId, ProtocolVersion}; use super::*; use crate::genesis::{ensure_genesis_state, GenesisParams}; -pub(crate) fn build_commit_tx_input_data_is_correct( - l1_batch_commit_data_generator: Arc, -) { +pub(crate) fn build_commit_tx_input_data_is_correct() { let contract = zksync_contracts::zksync_contract(); let commit_function = contract.function("commitBatches").unwrap(); let batches = vec![ @@ -17,8 +15,7 @@ pub(crate) fn build_commit_tx_input_data_is_correct( create_l1_batch_with_metadata(2), ]; - let commit_tx_input_data = - build_commit_tx_input_data(&batches, l1_batch_commit_data_generator.clone()); + let commit_tx_input_data = build_commit_tx_input_data(&batches); for batch in &batches { let commit_data = ConsistencyChecker::extract_commit_data( @@ -27,18 +24,13 @@ pub(crate) fn build_commit_tx_input_data_is_correct( batch.header.number, ) .unwrap(); - assert_eq!( - commit_data, - CommitBatchInfoRollup::new(batch, l1_batch_commit_data_generator.clone().clone()) - .into_token() - ); + assert_eq!(commit_data, CommitBatchInfoRollup::new(batch).into_token()); } } pub(crate) async fn normal_checker_function( batches_per_transaction: usize, (mapper_name, save_actions_mapper): (&'static str, SaveActionMapper), - l1_batch_commit_data_generator: Arc, ) { println!("Using save_actions_mapper={mapper_name}"); @@ -53,8 +45,7 @@ pub(crate) async fn normal_checker_function( let client = MockEthereum::default(); for (i, l1_batches) in l1_batches.chunks(batches_per_transaction).enumerate() { - let input_data = - build_commit_tx_input_data(l1_batches, l1_batch_commit_data_generator.clone()); + let input_data = build_commit_tx_input_data(l1_batches); let signed_tx = client.sign_prepared_tx( input_data.clone(), Options { @@ -76,7 +67,7 @@ pub(crate) async fn normal_checker_function( let (l1_batch_updates_sender, mut l1_batch_updates_receiver) = mpsc::unbounded_channel(); let checker = ConsistencyChecker { event_handler: Box::new(l1_batch_updates_sender), - ..create_mock_checker(client, pool.clone(), l1_batch_commit_data_generator) + ..create_mock_checker(client, pool.clone()) }; let (stop_sender, stop_receiver) = watch::channel(false); @@ -105,7 +96,6 @@ pub(crate) async fn normal_checker_function( pub(crate) async fn checker_processes_pre_boojum_batches( (mapper_name, save_actions_mapper): (&'static str, SaveActionMapper), - l1_batch_commit_data_generator: Arc, ) { println!("Using save_actions_mapper={mapper_name}"); @@ -131,10 +121,7 @@ pub(crate) async fn checker_processes_pre_boojum_batches( let client = MockEthereum::default(); for (i, l1_batch) in l1_batches.iter().enumerate() { - let input_data = build_commit_tx_input_data( - slice::from_ref(l1_batch), - l1_batch_commit_data_generator.clone(), - ); + let input_data = build_commit_tx_input_data(slice::from_ref(l1_batch)); let signed_tx = client.sign_prepared_tx( input_data.clone(), Options { @@ -152,7 +139,7 @@ pub(crate) async fn checker_processes_pre_boojum_batches( let (l1_batch_updates_sender, mut l1_batch_updates_receiver) = mpsc::unbounded_channel(); let checker = ConsistencyChecker { event_handler: Box::new(l1_batch_updates_sender), - ..create_mock_checker(client, pool.clone(), l1_batch_commit_data_generator) + ..create_mock_checker(client, pool.clone()) }; let (stop_sender, stop_receiver) = watch::channel(false); @@ -179,10 +166,7 @@ pub(crate) async fn checker_processes_pre_boojum_batches( checker_task.await.unwrap().unwrap(); } -pub async fn checker_functions_after_snapshot_recovery( - delay_batch_insertion: bool, - l1_batch_commit_data_generator: Arc, -) { +pub async fn checker_functions_after_snapshot_recovery(delay_batch_insertion: bool) { let pool = ConnectionPool::test_pool().await; let mut storage = pool.access_storage().await.unwrap(); storage @@ -192,10 +176,7 @@ pub async fn checker_functions_after_snapshot_recovery( let l1_batch = create_l1_batch_with_metadata(99); - let commit_tx_input_data = build_commit_tx_input_data( - slice::from_ref(&l1_batch), - l1_batch_commit_data_generator.clone(), - ); + let commit_tx_input_data = build_commit_tx_input_data(slice::from_ref(&l1_batch)); let client = MockEthereum::default(); let signed_tx = client.sign_prepared_tx( commit_tx_input_data.clone(), @@ -227,7 +208,7 @@ pub async fn checker_functions_after_snapshot_recovery( let (l1_batch_updates_sender, mut l1_batch_updates_receiver) = mpsc::unbounded_channel(); let checker = ConsistencyChecker { event_handler: Box::new(l1_batch_updates_sender), - ..create_mock_checker(client, pool.clone(), l1_batch_commit_data_generator) + ..create_mock_checker(client, pool.clone()) }; let (stop_sender, stop_receiver) = watch::channel(false); let checker_task = tokio::spawn(checker.run(stop_receiver)); @@ -252,7 +233,6 @@ pub async fn checker_functions_after_snapshot_recovery( pub(crate) async fn checker_detects_incorrect_tx_data( kind: IncorrectDataKind, snapshot_recovery: bool, - l1_batch_commit_data_generator: Arc, ) { let pool = ConnectionPool::test_pool().await; let mut storage = pool.access_storage().await.unwrap(); @@ -269,9 +249,7 @@ pub(crate) async fn checker_detects_incorrect_tx_data( let l1_batch = create_l1_batch_with_metadata(if snapshot_recovery { 99 } else { 1 }); let client = MockEthereum::default(); - let commit_tx_hash = kind - .apply(&client, &l1_batch, l1_batch_commit_data_generator.clone()) - .await; + let commit_tx_hash = kind.apply(&client, &l1_batch).await; let commit_tx_hash_by_l1_batch = HashMap::from([(l1_batch.header.number, commit_tx_hash)]); let save_actions = [ @@ -286,7 +264,7 @@ pub(crate) async fn checker_detects_incorrect_tx_data( } drop(storage); - let checker = create_mock_checker(client, pool, l1_batch_commit_data_generator); + let checker = create_mock_checker(client, pool); let (_stop_sender, stop_receiver) = watch::channel(false); // The checker must stop with an error. tokio::time::timeout(Duration::from_secs(30), checker.run(stop_receiver)) diff --git a/core/lib/zksync_core/src/eth_sender/aggregated_operations.rs b/core/lib/zksync_core/src/eth_sender/aggregated_operations.rs index bda71301f0ac..52e7bbede06c 100644 --- a/core/lib/zksync_core/src/eth_sender/aggregated_operations.rs +++ b/core/lib/zksync_core/src/eth_sender/aggregated_operations.rs @@ -1,14 +1,15 @@ use std::ops; -use zksync_l1_contract_interface::i_executor::methods::{ - CommitBatchesRollup, ExecuteBatches, ProveBatches, +use zksync_l1_contract_interface::i_executor::methods::{ExecuteBatches, ProveBatches}; +use zksync_types::{ + aggregated_operations::AggregatedActionType, commitment::L1BatchWithMetadata, L1BatchNumber, + ProtocolVersionId, }; -use zksync_types::{aggregated_operations::AggregatedActionType, L1BatchNumber, ProtocolVersionId}; #[allow(clippy::large_enum_variant)] #[derive(Debug, Clone)] pub enum AggregatedOperation { - Commit(CommitBatchesRollup), + Commit(L1BatchWithMetadata, Vec), PublishProofOnchain(ProveBatches), Execute(ExecuteBatches), } @@ -16,7 +17,7 @@ pub enum AggregatedOperation { impl AggregatedOperation { pub fn get_action_type(&self) -> AggregatedActionType { match self { - Self::Commit(_) => AggregatedActionType::Commit, + Self::Commit(..) => AggregatedActionType::Commit, Self::PublishProofOnchain(_) => AggregatedActionType::PublishProofOnchain, Self::Execute(_) => AggregatedActionType::Execute, } @@ -24,7 +25,7 @@ impl AggregatedOperation { pub fn l1_batch_range(&self) -> ops::RangeInclusive { let batches = match self { - Self::Commit(op) => &op.l1_batches, + Self::Commit(_, l1_batches) => l1_batches, Self::PublishProofOnchain(op) => &op.l1_batches, Self::Execute(op) => &op.l1_batches, }; @@ -39,7 +40,7 @@ impl AggregatedOperation { pub fn get_action_caption(&self) -> &'static str { match self { - Self::Commit(_) => "commit", + Self::Commit(..) => "commit", Self::PublishProofOnchain(_) => "proof", Self::Execute(_) => "execute", } @@ -47,7 +48,7 @@ impl AggregatedOperation { pub fn protocol_version(&self) -> ProtocolVersionId { match self { - Self::Commit(op) => op.l1_batches[0].header.protocol_version.unwrap(), + Self::Commit(_, l1_batches) => l1_batches[0].header.protocol_version.unwrap(), Self::PublishProofOnchain(op) => op.l1_batches[0].header.protocol_version.unwrap(), Self::Execute(op) => op.l1_batches[0].header.protocol_version.unwrap(), } diff --git a/core/lib/zksync_core/src/eth_sender/aggregator.rs b/core/lib/zksync_core/src/eth_sender/aggregator.rs index 0d4ac042edfe..36e59bedbe05 100644 --- a/core/lib/zksync_core/src/eth_sender/aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/aggregator.rs @@ -10,12 +10,13 @@ use zksync_object_store::{ObjectStore, ObjectStoreError}; use zksync_prover_interface::outputs::L1BatchProofForL1; use zksync_types::{ aggregated_operations::AggregatedActionType, commitment::L1BatchWithMetadata, - helpers::unix_timestamp_ms, l1_batch_commit_data_generator::L1BatchCommitDataGenerator, - protocol_version::L1VerifierConfig, L1BatchNumber, ProtocolVersionId, + helpers::unix_timestamp_ms, protocol_version::L1VerifierConfig, L1BatchNumber, + ProtocolVersionId, }; use super::{ aggregated_operations::AggregatedOperation, + l1_batch_commit_data_generator::L1BatchCommitDataGenerator, publish_criterion::{ DataSizeCriterion, GasCriterion, L1BatchPublishCriterion, NumberCriterion, TimestampDeadlineCriterion, @@ -29,7 +30,6 @@ pub struct Aggregator { execute_criteria: Vec>, config: SenderConfig, blob_store: Arc, - l1_batch_commit_data_generator: Arc, } impl Aggregator { @@ -94,7 +94,6 @@ impl Aggregator { ], config, blob_store, - l1_batch_commit_data_generator, } } @@ -142,7 +141,12 @@ impl Aggregator { protocol_version_id, ) .await - .map(AggregatedOperation::Commit) + .map(|op| { + AggregatedOperation::Commit( + op.last_committed_l1_batch.clone(), + op.l1_batches.to_vec(), + ) + }) } } @@ -230,7 +234,6 @@ impl Aggregator { batches.map(|batches| CommitBatchesRollup { last_committed_l1_batch, l1_batches: batches, - l1_batch_commit_data_generator: self.l1_batch_commit_data_generator.clone(), }) } diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs index 13045119875a..7ea048092d57 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs @@ -22,6 +22,7 @@ use zksync_types::{ use super::aggregated_operations::AggregatedOperation; use crate::{ eth_sender::{ + l1_batch_commit_data_generator::L1BatchCommitDataGenerator, metrics::{PubdataKind, METRICS}, zksync_functions::ZkSyncFunctions, Aggregator, ETHSenderError, @@ -53,6 +54,7 @@ pub struct EthTxAggregator { functions: ZkSyncFunctions, base_nonce: u64, rollup_chain_id: L2ChainId, + l1_commit_data_generator: Arc, } impl EthTxAggregator { @@ -64,6 +66,7 @@ impl EthTxAggregator { l1_multicall3_address: Address, main_zksync_contract_address: Address, rollup_chain_id: L2ChainId, + l1_commit_data_generator: Arc, ) -> Self { let functions = ZkSyncFunctions::default(); let base_nonce = eth_client @@ -81,6 +84,7 @@ impl EthTxAggregator { functions, base_nonce, rollup_chain_id, + l1_commit_data_generator, } } @@ -367,8 +371,8 @@ impl EthTxAggregator { aggregated_op.get_action_caption() ); - if let AggregatedOperation::Commit(commit_op) = &aggregated_op { - for batch in &commit_op.l1_batches { + if let AggregatedOperation::Commit(_, l1_batches) = &aggregated_op { + for batch in l1_batches { METRICS.pubdata_size[&PubdataKind::StateDiffs] .observe(batch.metadata.state_diffs_compressed.len()); METRICS.pubdata_size[&PubdataKind::UserL2ToL1Logs] @@ -402,14 +406,17 @@ impl EthTxAggregator { let mut args = vec![Token::Uint(self.rollup_chain_id.as_u64().into())]; match op.clone() { - AggregatedOperation::Commit(op) => { + AggregatedOperation::Commit(last_committed_l1_batch, l1_batches) => { + let commit_data = self + .l1_commit_data_generator + .l1_commit_data(&last_committed_l1_batch, &l1_batches); if contracts_are_pre_shared_bridge { self.functions .pre_shared_bridge_commit - .encode_input(&op.into_tokens()) + .encode_input(&commit_data.into_tokens()) .expect("Failed to encode commit transaction data") } else { - args.extend(op.into_tokens()); + args.extend_from_slice(&commit_data); self.functions .post_shared_bridge_commit .as_ref() diff --git a/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs b/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs new file mode 100644 index 000000000000..fb3933a790c3 --- /dev/null +++ b/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs @@ -0,0 +1,50 @@ +use zksync_l1_contract_interface::{ + i_executor::methods::{CommitBatchesRollup, CommitBatchesValidium}, + Tokenize, +}; +use zksync_types::{commitment::L1BatchWithMetadata, ethabi::Token}; + +pub trait L1BatchCommitDataGenerator +where + Self: std::fmt::Debug + Send + Sync, +{ + fn l1_commit_data( + &self, + last_committed_l1_batch: &L1BatchWithMetadata, + l1_batches: &[L1BatchWithMetadata], + ) -> Vec; +} + +#[derive(Debug, Clone)] +pub struct RollupModeL1BatchCommitDataGenerator; + +#[derive(Debug, Clone)] +pub struct ValidiumModeL1BatchCommitDataGenerator; + +impl L1BatchCommitDataGenerator for RollupModeL1BatchCommitDataGenerator { + fn l1_commit_data( + &self, + last_committed_l1_batch: &L1BatchWithMetadata, + l1_batches: &[L1BatchWithMetadata], + ) -> Vec { + CommitBatchesRollup { + last_committed_l1_batch: last_committed_l1_batch.clone(), + l1_batches: l1_batches.to_vec(), + } + .into_tokens() + } +} + +impl L1BatchCommitDataGenerator for ValidiumModeL1BatchCommitDataGenerator { + fn l1_commit_data( + &self, + last_committed_l1_batch: &L1BatchWithMetadata, + l1_batches: &[L1BatchWithMetadata], + ) -> Vec { + CommitBatchesValidium { + last_committed_l1_batch: last_committed_l1_batch.clone(), + l1_batches: l1_batches.to_vec(), + } + .into_tokens() + } +} diff --git a/core/lib/zksync_core/src/eth_sender/mod.rs b/core/lib/zksync_core/src/eth_sender/mod.rs index 450e2776aa93..109624e5a4e8 100644 --- a/core/lib/zksync_core/src/eth_sender/mod.rs +++ b/core/lib/zksync_core/src/eth_sender/mod.rs @@ -3,6 +3,7 @@ mod aggregator; mod error; mod eth_tx_aggregator; mod eth_tx_manager; +pub mod l1_batch_commit_data_generator; mod metrics; mod publish_criterion; mod zksync_functions; diff --git a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs index 2dad52748893..9ebc5a3df67a 100644 --- a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs +++ b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs @@ -6,11 +6,14 @@ use zksync_dal::StorageProcessor; use zksync_l1_contract_interface::{i_executor::structures::CommitBatchInfoRollup, Tokenizable}; use zksync_types::{ aggregated_operations::AggregatedActionType, commitment::L1BatchWithMetadata, ethabi, - l1_batch_commit_data_generator::L1BatchCommitDataGenerator, L1BatchNumber, + L1BatchNumber, }; use super::metrics::METRICS; -use crate::gas_tracker::agg_l1_batch_base_cost; +use crate::{ + eth_sender::l1_batch_commit_data_generator::L1BatchCommitDataGenerator, + gas_tracker::agg_l1_batch_base_cost, +}; #[async_trait] pub trait L1BatchPublishCriterion: fmt::Debug + Send + Sync { @@ -222,7 +225,6 @@ impl L1BatchPublishCriterion for DataSizeCriterion { let l1_commit_data_size = ethabi::encode(&[ethabi::Token::Array(vec![CommitBatchInfoRollup::new( l1_batch, - self.l1_batch_commit_data_generator.clone(), ) .into_token()])]) .len(); diff --git a/core/lib/zksync_core/src/eth_sender/tests.rs b/core/lib/zksync_core/src/eth_sender/tests.rs index 00fc423b2b64..5df4c15d81f4 100644 --- a/core/lib/zksync_core/src/eth_sender/tests.rs +++ b/core/lib/zksync_core/src/eth_sender/tests.rs @@ -1,11 +1,9 @@ use std::sync::Arc; use zksync_dal::ConnectionPool; -use zksync_types::l1_batch_commit_data_generator::{ - RollupModeL1BatchCommitDataGenerator, ValidiumModeL1BatchCommitDataGenerator, -}; use super::tests_helpers::{self, EthSenderTester}; +use crate::{RollupModeL1BatchCommitDataGenerator, ValidiumModeL1BatchCommitDataGenerator}; // Tests that we send multiple transactions and confirm them all in one iteration. #[tokio::test] @@ -135,16 +133,8 @@ async fn correct_order_for_confirmations() -> anyhow::Result<()> { ) .await; - tests_helpers::correct_order_for_confirmations( - &mut rollup_tester, - Arc::new(RollupModeL1BatchCommitDataGenerator {}), - ) - .await?; - tests_helpers::correct_order_for_confirmations( - &mut validium_tester, - Arc::new(ValidiumModeL1BatchCommitDataGenerator {}), - ) - .await + tests_helpers::correct_order_for_confirmations(&mut rollup_tester).await?; + tests_helpers::correct_order_for_confirmations(&mut validium_tester).await } #[tokio::test] @@ -165,16 +155,8 @@ async fn skipped_l1_batch_at_the_start() -> anyhow::Result<()> { ) .await; - tests_helpers::skipped_l1_batch_at_the_start( - &mut rollup_tester, - Arc::new(RollupModeL1BatchCommitDataGenerator {}), - ) - .await?; - tests_helpers::skipped_l1_batch_at_the_start( - &mut validium_tester, - Arc::new(ValidiumModeL1BatchCommitDataGenerator {}), - ) - .await + tests_helpers::skipped_l1_batch_at_the_start(&mut rollup_tester).await?; + tests_helpers::skipped_l1_batch_at_the_start(&mut validium_tester).await } #[tokio::test] @@ -195,16 +177,8 @@ async fn skipped_l1_batch_in_the_middle() -> anyhow::Result<()> { ) .await; - tests_helpers::skipped_l1_batch_in_the_middle( - &mut rollup_tester, - Arc::new(RollupModeL1BatchCommitDataGenerator {}), - ) - .await?; - tests_helpers::skipped_l1_batch_in_the_middle( - &mut validium_tester, - Arc::new(ValidiumModeL1BatchCommitDataGenerator {}), - ) - .await + tests_helpers::skipped_l1_batch_in_the_middle(&mut rollup_tester).await?; + tests_helpers::skipped_l1_batch_in_the_middle(&mut validium_tester).await } #[tokio::test] diff --git a/core/lib/zksync_core/src/eth_sender/tests_helpers.rs b/core/lib/zksync_core/src/eth_sender/tests_helpers.rs index 10fd0b6a05c9..3a0e73c46398 100644 --- a/core/lib/zksync_core/src/eth_sender/tests_helpers.rs +++ b/core/lib/zksync_core/src/eth_sender/tests_helpers.rs @@ -8,16 +8,13 @@ use zksync_config::{ }; use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_eth_client::{clients::MockEthereum, EthInterface}; -use zksync_l1_contract_interface::i_executor::methods::{ - CommitBatchesRollup, ExecuteBatches, ProveBatches, -}; +use zksync_l1_contract_interface::i_executor::methods::{ExecuteBatches, ProveBatches}; use zksync_object_store::ObjectStoreFactory; use zksync_types::{ block::L1BatchHeader, commitment::{L1BatchMetaParameters, L1BatchMetadata, L1BatchWithMetadata}, ethabi::Token, helpers::unix_timestamp_ms, - l1_batch_commit_data_generator::L1BatchCommitDataGenerator, web3::contract::Error, Address, L1BatchNumber, L1BlockNumber, ProtocolVersionId, H256, }; @@ -29,6 +26,7 @@ use crate::{ }, l1_gas_price::GasAdjuster, utils::testonly::{create_l1_batch, l1_batch_metadata_to_commitment_artifacts}, + L1BatchCommitDataGenerator, }; // Alias to conveniently call static methods of `ETHSender`. @@ -107,7 +105,7 @@ impl EthSenderTester { Aggregator::new( aggregator_config.clone(), store_factory.create_store().await, - l1_batch_commit_data_generator, + l1_batch_commit_data_generator.clone(), ), gateway.clone(), // zkSync contract address @@ -115,6 +113,7 @@ impl EthSenderTester { contracts_config.l1_multicall3_addr, Address::random(), Default::default(), + l1_batch_commit_data_generator.clone(), ) .await; @@ -644,19 +643,16 @@ async fn commit_l1_batch( last_committed_l1_batch: L1BatchHeader, l1_batch: L1BatchHeader, confirm: bool, - l1_batch_commit_data_generator: Arc, ) -> H256 { - let operation = AggregatedOperation::Commit(CommitBatchesRollup { - last_committed_l1_batch: l1_batch_with_metadata(last_committed_l1_batch), - l1_batches: vec![l1_batch_with_metadata(l1_batch)], - l1_batch_commit_data_generator, - }); + let operation = AggregatedOperation::Commit( + l1_batch_with_metadata(last_committed_l1_batch), + vec![l1_batch_with_metadata(l1_batch)], + ); send_operation(tester, operation, confirm).await } pub(crate) async fn correct_order_for_confirmations( tester: &mut EthSenderTester, - l1_batch_commit_data_generator: Arc, ) -> anyhow::Result<()> { insert_genesis_protocol_version(tester).await; let genesis_l1_batch = insert_l1_batch(tester, L1BatchNumber(0)).await; @@ -668,7 +664,6 @@ pub(crate) async fn correct_order_for_confirmations( genesis_l1_batch.clone(), first_l1_batch.clone(), true, - l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( @@ -684,7 +679,6 @@ pub(crate) async fn correct_order_for_confirmations( first_l1_batch.clone(), second_l1_batch.clone(), true, - l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( @@ -719,7 +713,6 @@ pub(crate) async fn correct_order_for_confirmations( pub(crate) async fn skipped_l1_batch_at_the_start( tester: &mut EthSenderTester, - l1_batch_commit_data_generator: Arc, ) -> anyhow::Result<()> { insert_genesis_protocol_version(tester).await; let genesis_l1_batch = insert_l1_batch(tester, L1BatchNumber(0)).await; @@ -731,7 +724,6 @@ pub(crate) async fn skipped_l1_batch_at_the_start( genesis_l1_batch.clone(), first_l1_batch.clone(), true, - l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( @@ -747,7 +739,6 @@ pub(crate) async fn skipped_l1_batch_at_the_start( first_l1_batch.clone(), second_l1_batch.clone(), true, - l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( @@ -767,7 +758,6 @@ pub(crate) async fn skipped_l1_batch_at_the_start( second_l1_batch.clone(), third_l1_batch.clone(), false, - l1_batch_commit_data_generator.clone(), ) .await; @@ -783,7 +773,6 @@ pub(crate) async fn skipped_l1_batch_at_the_start( third_l1_batch.clone(), fourth_l1_batch.clone(), true, - l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( @@ -816,7 +805,6 @@ pub(crate) async fn skipped_l1_batch_at_the_start( pub(crate) async fn skipped_l1_batch_in_the_middle( tester: &mut EthSenderTester, - l1_batch_commit_data_generator: Arc, ) -> anyhow::Result<()> { insert_genesis_protocol_version(tester).await; let genesis_l1_batch = insert_l1_batch(tester, L1BatchNumber(0)).await; @@ -827,7 +815,6 @@ pub(crate) async fn skipped_l1_batch_in_the_middle( genesis_l1_batch.clone(), first_l1_batch.clone(), true, - l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch(tester, genesis_l1_batch, first_l1_batch.clone(), true).await; @@ -837,7 +824,6 @@ pub(crate) async fn skipped_l1_batch_in_the_middle( first_l1_batch.clone(), second_l1_batch.clone(), true, - l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( @@ -856,7 +842,6 @@ pub(crate) async fn skipped_l1_batch_in_the_middle( second_l1_batch.clone(), third_l1_batch.clone(), false, - l1_batch_commit_data_generator.clone(), ) .await; @@ -872,7 +857,6 @@ pub(crate) async fn skipped_l1_batch_in_the_middle( third_l1_batch.clone(), fourth_l1_batch.clone(), true, - l1_batch_commit_data_generator.clone(), ) .await; prove_l1_batch( diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 384372e1d551..5804a6021f07 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -38,10 +38,6 @@ use zksync_queued_job_processor::JobProcessor; use zksync_state::PostgresStorageCaches; use zksync_types::{ fee_model::FeeModelConfig, - l1_batch_commit_data_generator::{ - L1BatchCommitDataGenerator, RollupModeL1BatchCommitDataGenerator, - ValidiumModeL1BatchCommitDataGenerator, - }, protocol_version::{L1VerifierConfig, VerifierParams}, system_contracts::get_system_smart_contracts, web3::{contract::tokens::Detokenize, ethabi}, @@ -59,7 +55,13 @@ use crate::{ }, basic_witness_input_producer::BasicWitnessInputProducer, commitment_generator::CommitmentGenerator, - eth_sender::{Aggregator, EthTxAggregator, EthTxManager}, + eth_sender::{ + l1_batch_commit_data_generator::{ + L1BatchCommitDataGenerator, RollupModeL1BatchCommitDataGenerator, + ValidiumModeL1BatchCommitDataGenerator, + }, + Aggregator, EthTxAggregator, EthTxManager, + }, eth_watch::start_eth_watch, house_keeper::{ blocks_state_reporter::L1BatchMetricsReporter, @@ -707,7 +709,7 @@ pub async fn initialize_components( Aggregator::new( eth_sender.sender.clone(), store_factory.create_store().await, - l1_batch_commit_data_generator, + l1_batch_commit_data_generator.clone(), ), Arc::new(eth_client), contracts_config.validator_timelock_addr, @@ -718,6 +720,7 @@ pub async fn initialize_components( .as_ref() .context("network_config")? .zksync_network_id, + l1_batch_commit_data_generator.clone(), ) .await; task_futures.push(tokio::spawn( From 4a2f79eed6fd027a0ae9d69c6cdc58c55f1d5382 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Thu, 29 Feb 2024 18:45:28 -0300 Subject: [PATCH 03/16] Fix publish criterion --- .../src/eth_sender/publish_criterion.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs index 9ebc5a3df67a..0844bb368578 100644 --- a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs +++ b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs @@ -222,12 +222,15 @@ impl L1BatchPublishCriterion for DataSizeCriterion { for (index, l1_batch) in consecutive_l1_batches.iter().enumerate() { // TODO (PLA-771): Make sure that this estimation is correct. - let l1_commit_data_size = - ethabi::encode(&[ethabi::Token::Array(vec![CommitBatchInfoRollup::new( - l1_batch, - ) - .into_token()])]) - .len(); + // NOTE: any element will do for `StoredBlockInfo`. We subtract the size later for + // correctness, to avoid double accounting. + let l1_commit_data_size = ethabi::encode(&[ethabi::Token::Array( + self.l1_batch_commit_data_generator + .l1_commit_data(l1_batch, std::slice::from_ref(l1_batch)), + )]) + .len() + - STORED_BLOCK_INFO_SIZE; + if data_size_left < l1_commit_data_size { if index == 0 { panic!( From dab6387256ab0fc7adf5fa5547f3713987752b3c Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Fri, 1 Mar 2024 16:09:46 -0300 Subject: [PATCH 04/16] Fixes? --- .../src/i_executor/structures/commit_batch_info.rs | 14 ++++++++++++-- .../src/eth_sender/eth_tx_aggregator.rs | 4 ++-- .../src/eth_sender/publish_criterion.rs | 1 - 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs b/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs index d91c891a0fbd..b8360b8eb53d 100644 --- a/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs +++ b/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs @@ -77,7 +77,17 @@ impl<'a> Tokenizable for CommitBatchInfoValidium<'a> { } fn into_token(self) -> Token { - Token::Tuple(validium_mode_l1_commit_data(self.l1_batch_with_metadata)) + if self + .l1_batch_with_metadata + .header + .protocol_version + .unwrap() + .is_pre_boojum() + { + pre_boojum_into_token(self.l1_batch_with_metadata) + } else { + Token::Tuple(validium_mode_l1_commit_data(self.l1_batch_with_metadata)) + } } } @@ -152,7 +162,7 @@ fn encode_l1_commit(l1_batch_with_metadata: &L1BatchWithMetadata, pubdata: Token } fn validium_mode_l1_commit_data(l1_batch_with_metadata: &L1BatchWithMetadata) -> Vec { - encode_l1_commit(l1_batch_with_metadata, Token::Bytes([0].to_vec())) + encode_l1_commit(l1_batch_with_metadata, Token::Bytes(vec![])) } fn rollup_mode_l1_commit_data(l1_batch_with_metadata: &L1BatchWithMetadata) -> Vec { diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs index 7ea048092d57..bfd404a5e5d9 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs @@ -408,8 +408,8 @@ impl EthTxAggregator { match op.clone() { AggregatedOperation::Commit(last_committed_l1_batch, l1_batches) => { let commit_data = self - .l1_commit_data_generator - .l1_commit_data(&last_committed_l1_batch, &l1_batches); + .l1_commit_data_generator + .l1_commit_data(&last_committed_l1_batch, &l1_batches); if contracts_are_pre_shared_bridge { self.functions .pre_shared_bridge_commit diff --git a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs index 0844bb368578..dee139f8dae8 100644 --- a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs +++ b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs @@ -3,7 +3,6 @@ use std::{fmt, sync::Arc}; use async_trait::async_trait; use chrono::Utc; use zksync_dal::StorageProcessor; -use zksync_l1_contract_interface::{i_executor::structures::CommitBatchInfoRollup, Tokenizable}; use zksync_types::{ aggregated_operations::AggregatedActionType, commitment::L1BatchWithMetadata, ethabi, L1BatchNumber, From 23c106ebb10f295dc9c5cd8606b7dc9d8598cb8f Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Fri, 1 Mar 2024 17:20:20 -0300 Subject: [PATCH 05/16] Remove FIXME --- .../src/i_executor/methods/commit_batches.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs b/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs index c64d98a0b108..93b7eb713db2 100644 --- a/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs +++ b/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs @@ -33,7 +33,6 @@ pub struct CommitBatchesValidium { } impl Tokenize for CommitBatchesValidium { - // FIXME: use Validium fn into_tokens(self) -> Vec { let stored_batch_info = StoredBatchInfo(&self.last_committed_l1_batch).into_token(); let l1_batches_to_commit = self From ce86e8ffbe89fd2adda087904db26c90d59c332c Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Fri, 1 Mar 2024 18:54:39 -0300 Subject: [PATCH 06/16] Restore contracts --- contracts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts b/contracts index ceb214b7650c..6804b2374ce2 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit ceb214b7650c6102703a9b5569a4056fe97a3be4 +Subproject commit 6804b2374ce23a8f85f4e2d4ec96219c6aad6653 From c8e69015edd4b0892eeee9e97d04e16c9af24413 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Mon, 4 Mar 2024 14:25:21 -0300 Subject: [PATCH 07/16] Restore consistency checker - First splits the functionality of `L1CommitBatchesDataGenerator::l1_commit_data` into two separate functions, one for a single batch and one for the whole array that includes the previous block. - Then uses that for publish criteria and consistency checking, as they work on a per-batch basis. --- core/bin/external_node/src/main.rs | 16 ++- .../src/consistency_checker/mod.rs | 24 +++- .../src/consistency_checker/tests/mod.rs | 103 ++++++++++++++---- .../consistency_checker/tests/test_helpers.rs | 45 ++++++-- .../src/eth_sender/eth_tx_aggregator.rs | 2 +- .../l1_batch_commit_data_generator.rs | 29 ++++- .../src/eth_sender/publish_criterion.rs | 12 +- 7 files changed, 179 insertions(+), 52 deletions(-) diff --git a/core/bin/external_node/src/main.rs b/core/bin/external_node/src/main.rs index 735df320e7b9..23cb336877ea 100644 --- a/core/bin/external_node/src/main.rs +++ b/core/bin/external_node/src/main.rs @@ -8,7 +8,7 @@ use prometheus_exporter::PrometheusExporterConfig; use tokio::{sync::watch, task, time::sleep}; use zksync_basic_types::{Address, L2ChainId}; use zksync_concurrency::{ctx, scope}; -use zksync_config::configs::database::MerkleTreeMode; +use zksync_config::configs::{chain::L1BatchCommitDataGeneratorMode, database::MerkleTreeMode}; use zksync_core::{ api_server::{ execution_sandbox::VmConcurrencyLimiter, @@ -20,6 +20,10 @@ use zksync_core::{ commitment_generator::CommitmentGenerator, consensus, consistency_checker::ConsistencyChecker, + eth_sender::l1_batch_commit_data_generator::{ + L1BatchCommitDataGenerator, RollupModeL1BatchCommitDataGenerator, + ValidiumModeL1BatchCommitDataGenerator, + }, l1_gas_price::MainNodeFeeParamsFetcher, metadata_calculator::{MetadataCalculator, MetadataCalculatorConfig}, reorg_detector::ReorgDetector, @@ -229,6 +233,15 @@ async fn init_tasks( .context("failed initializing metadata calculator")?; app_health.insert_component(metadata_calculator.tree_health_check()); + let l1_batch_commit_data_generator: Arc = match config + .optional + .l1_batch_commit_data_generator_mode + { + L1BatchCommitDataGeneratorMode::Rollup => Arc::new(RollupModeL1BatchCommitDataGenerator {}), + L1BatchCommitDataGeneratorMode::Validium => { + Arc::new(ValidiumModeL1BatchCommitDataGenerator {}) + } + }; let consistency_checker = ConsistencyChecker::new( &config .required @@ -239,6 +252,7 @@ async fn init_tasks( .build() .await .context("failed to build connection pool for ConsistencyChecker")?, + l1_batch_commit_data_generator, ); app_health.insert_component(consistency_checker.health_check().clone()); let consistency_checker_handle = tokio::spawn(consistency_checker.run(stop_receiver.clone())); diff --git a/core/lib/zksync_core/src/consistency_checker/mod.rs b/core/lib/zksync_core/src/consistency_checker/mod.rs index 08c778c0f6aa..0a08071bfc54 100644 --- a/core/lib/zksync_core/src/consistency_checker/mod.rs +++ b/core/lib/zksync_core/src/consistency_checker/mod.rs @@ -1,4 +1,4 @@ -use std::{fmt, time::Duration}; +use std::{fmt, sync::Arc, time::Duration}; use anyhow::Context as _; use serde::Serialize; @@ -7,10 +7,10 @@ use zksync_contracts::PRE_BOOJUM_COMMIT_FUNCTION; use zksync_dal::{ConnectionPool, StorageProcessor}; use zksync_eth_client::{clients::QueryClient, Error as L1ClientError, EthInterface}; use zksync_health_check::{Health, HealthStatus, HealthUpdater, ReactiveHealthCheck}; -use zksync_l1_contract_interface::{i_executor::structures::CommitBatchInfoRollup, Tokenizable}; use zksync_types::{web3::ethabi, L1BatchNumber, H256}; use crate::{ + eth_sender::l1_batch_commit_data_generator::L1BatchCommitDataGenerator, metrics::{CheckerComponent, EN_METRICS}, utils::wait_for_l1_batch_with_metadata, }; @@ -133,6 +133,7 @@ impl LocalL1BatchCommitData { async fn new( storage: &mut StorageProcessor<'_>, batch_number: L1BatchNumber, + l1_batch_commit_data_generator: Arc, ) -> anyhow::Result> { let Some(storage_l1_batch) = storage .blocks_dal() @@ -180,7 +181,7 @@ impl LocalL1BatchCommitData { Ok(Some(Self { is_pre_boojum, - l1_commit_data: CommitBatchInfoRollup::new(&l1_batch).into_token(), + l1_commit_data: l1_batch_commit_data_generator.l1_commit_batch(&l1_batch), commit_tx_hash, })) } @@ -197,13 +198,19 @@ pub struct ConsistencyChecker { event_handler: Box, l1_data_mismatch_behavior: L1DataMismatchBehavior, pool: ConnectionPool, + l1_batch_commit_data_generator: Arc, health_check: ReactiveHealthCheck, } impl ConsistencyChecker { const DEFAULT_SLEEP_INTERVAL: Duration = Duration::from_secs(5); - pub fn new(web3_url: &str, max_batches_to_recheck: u32, pool: ConnectionPool) -> Self { + pub fn new( + web3_url: &str, + max_batches_to_recheck: u32, + pool: ConnectionPool, + l1_batch_commit_data_generator: Arc, + ) -> Self { let web3 = QueryClient::new(web3_url).unwrap(); let (health_check, health_updater) = ConsistencyCheckerHealthUpdater::new(); Self { @@ -215,6 +222,7 @@ impl ConsistencyChecker { l1_data_mismatch_behavior: L1DataMismatchBehavior::Log, pool, health_check, + l1_batch_commit_data_generator, } } /// Returns health check associated with this checker. @@ -363,7 +371,13 @@ impl ConsistencyChecker { // The batch might be already committed but not yet processed by the external node's tree // OR the batch might be processed by the external node's tree but not yet committed. // We need both. - let Some(local) = LocalL1BatchCommitData::new(&mut storage, batch_number).await? else { + let Some(local) = LocalL1BatchCommitData::new( + &mut storage, + batch_number, + self.l1_batch_commit_data_generator.clone(), + ) + .await? + else { tokio::time::sleep(self.sleep_interval).await; continue; }; diff --git a/core/lib/zksync_core/src/consistency_checker/tests/mod.rs b/core/lib/zksync_core/src/consistency_checker/tests/mod.rs index 1be107113dce..7f58d6bb7457 100644 --- a/core/lib/zksync_core/src/consistency_checker/tests/mod.rs +++ b/core/lib/zksync_core/src/consistency_checker/tests/mod.rs @@ -8,15 +8,19 @@ use test_casing::{test_casing, Product}; use tokio::sync::mpsc; use zksync_dal::StorageProcessor; use zksync_eth_client::clients::MockEthereum; -use zksync_l1_contract_interface::i_executor::structures::StoredBatchInfo; use zksync_types::{ aggregated_operations::AggregatedActionType, commitment::L1BatchWithMetadata, web3::contract::Options, ProtocolVersionId, H256, }; use super::*; -use crate::utils::testonly::{ - create_l1_batch, create_l1_batch_metadata, l1_batch_metadata_to_commitment_artifacts, +use crate::{ + eth_sender::l1_batch_commit_data_generator::{ + RollupModeL1BatchCommitDataGenerator, ValidiumModeL1BatchCommitDataGenerator, + }, + utils::testonly::{ + create_l1_batch, create_l1_batch_metadata, l1_batch_metadata_to_commitment_artifacts, + }, }; /// **NB.** For tests to run correctly, the returned value must be deterministic (i.e., depend only on `number`). @@ -42,26 +46,26 @@ pub(crate) fn create_pre_boojum_l1_batch_with_metadata(number: u32) -> L1BatchWi l1_batch } -pub(crate) fn build_commit_tx_input_data(batches: &[L1BatchWithMetadata]) -> Vec { - let commit_tokens = batches - .iter() - .map(|batch| CommitBatchInfoRollup::new(batch).into_token()); - let commit_tokens = ethabi::Token::Array(commit_tokens.collect()); - +pub(crate) fn build_commit_tx_input_data( + batches: &[L1BatchWithMetadata], + l1_batch_commit_data_generator: Arc, +) -> Vec { let mut encoded = vec![]; // Fake Solidity function selector (not checked for now) encoded.extend_from_slice(b"fake"); // Mock an additional argument used in real `commitBlocks` / `commitBatches`. In real transactions, // it's taken from the L1 batch previous to `batches[0]`, but since this argument is not checked, // it's OK to use `batches[0]`. - let prev_header_tokens = StoredBatchInfo(&batches[0]).into_token(); - encoded.extend_from_slice(ðabi::encode(&[prev_header_tokens, commit_tokens])); + encoded.extend_from_slice(ðabi::encode( + &l1_batch_commit_data_generator.l1_commit_batches(&batches[0], batches), + )); encoded } pub(crate) fn create_mock_checker( client: MockEthereum, pool: ConnectionPool, + l1_batch_commit_data_generator: Arc, ) -> ConsistencyChecker { let (health_check, health_updater) = ConsistencyCheckerHealthUpdater::new(); ConsistencyChecker { @@ -72,6 +76,7 @@ pub(crate) fn create_mock_checker( event_handler: Box::new(health_updater), l1_data_mismatch_behavior: L1DataMismatchBehavior::Bail, pool, + l1_batch_commit_data_generator, health_check, } } @@ -96,7 +101,12 @@ impl HandleConsistencyCheckerEvent for mpsc::UnboundedSender { #[test] fn build_commit_tx_input_data_is_correct() { - test_helpers::build_commit_tx_input_data_is_correct(); + test_helpers::build_commit_tx_input_data_is_correct(Arc::new( + RollupModeL1BatchCommitDataGenerator {}, + )); + test_helpers::build_commit_tx_input_data_is_correct(Arc::new( + ValidiumModeL1BatchCommitDataGenerator {}, + )); } #[test] @@ -294,6 +304,13 @@ async fn normal_checker_function( test_helpers::normal_checker_function( batches_per_transaction, (mapper_name, save_actions_mapper), + Arc::new(RollupModeL1BatchCommitDataGenerator {}), + ) + .await; + test_helpers::normal_checker_function( + batches_per_transaction, + (mapper_name, save_actions_mapper), + Arc::new(ValidiumModeL1BatchCommitDataGenerator {}), ) .await; } @@ -303,13 +320,31 @@ async fn normal_checker_function( async fn checker_processes_pre_boojum_batches( (mapper_name, save_actions_mapper): (&'static str, SaveActionMapper), ) { - test_helpers::checker_processes_pre_boojum_batches((mapper_name, save_actions_mapper)).await; + test_helpers::checker_processes_pre_boojum_batches( + (mapper_name, save_actions_mapper), + Arc::new(RollupModeL1BatchCommitDataGenerator {}), + ) + .await; + test_helpers::checker_processes_pre_boojum_batches( + (mapper_name, save_actions_mapper), + Arc::new(ValidiumModeL1BatchCommitDataGenerator {}), + ) + .await; } #[test_casing(2, [false, true])] #[tokio::test] async fn checker_functions_after_snapshot_recovery(delay_batch_insertion: bool) { - test_helpers::checker_functions_after_snapshot_recovery(delay_batch_insertion).await; + test_helpers::checker_functions_after_snapshot_recovery( + delay_batch_insertion, + Arc::new(RollupModeL1BatchCommitDataGenerator {}), + ) + .await; + test_helpers::checker_functions_after_snapshot_recovery( + delay_batch_insertion, + Arc::new(ValidiumModeL1BatchCommitDataGenerator {}), + ) + .await; } #[derive(Debug, Clone, Copy)] @@ -332,13 +367,21 @@ impl IncorrectDataKind { Self::CommitDataForPreBoojum, ]; - async fn apply(self, client: &MockEthereum, l1_batch: &L1BatchWithMetadata) -> H256 { + async fn apply( + self, + client: &MockEthereum, + l1_batch: &L1BatchWithMetadata, + l1_batch_commit_data_generator: Arc, + ) -> H256 { let (commit_tx_input_data, successful_status) = match self { Self::MissingStatus => { return H256::zero(); // Do not execute the transaction } Self::MismatchedStatus => { - let commit_tx_input_data = build_commit_tx_input_data(slice::from_ref(l1_batch)); + let commit_tx_input_data = build_commit_tx_input_data( + slice::from_ref(l1_batch), + l1_batch_commit_data_generator, + ); (commit_tx_input_data, false) } Self::BogusCommitDataFormat => { @@ -350,18 +393,27 @@ impl IncorrectDataKind { Self::MismatchedCommitDataTimestamp => { let mut l1_batch = create_l1_batch_with_metadata(1); l1_batch.header.timestamp += 1; - let bogus_tx_input_data = build_commit_tx_input_data(slice::from_ref(&l1_batch)); + let bogus_tx_input_data = build_commit_tx_input_data( + slice::from_ref(&l1_batch), + l1_batch_commit_data_generator, + ); (bogus_tx_input_data, true) } Self::CommitDataForAnotherBatch => { let l1_batch = create_l1_batch_with_metadata(100); - let bogus_tx_input_data = build_commit_tx_input_data(slice::from_ref(&l1_batch)); + let bogus_tx_input_data = build_commit_tx_input_data( + slice::from_ref(&l1_batch), + l1_batch_commit_data_generator, + ); (bogus_tx_input_data, true) } Self::CommitDataForPreBoojum => { let mut l1_batch = create_l1_batch_with_metadata(1); l1_batch.header.protocol_version = Some(ProtocolVersionId::Version0); - let bogus_tx_input_data = build_commit_tx_input_data(slice::from_ref(&l1_batch)); + let bogus_tx_input_data = build_commit_tx_input_data( + slice::from_ref(&l1_batch), + l1_batch_commit_data_generator, + ); (bogus_tx_input_data, true) } }; @@ -384,7 +436,18 @@ impl IncorrectDataKind { // ^ `snapshot_recovery = true` is tested below; we don't want to run it with all incorrect data kinds #[tokio::test] async fn checker_detects_incorrect_tx_data(kind: IncorrectDataKind, snapshot_recovery: bool) { - test_helpers::checker_detects_incorrect_tx_data(kind, snapshot_recovery).await; + test_helpers::checker_detects_incorrect_tx_data( + kind, + snapshot_recovery, + Arc::new(RollupModeL1BatchCommitDataGenerator {}), + ) + .await; + test_helpers::checker_detects_incorrect_tx_data( + kind, + snapshot_recovery, + Arc::new(ValidiumModeL1BatchCommitDataGenerator {}), + ) + .await; } #[tokio::test] diff --git a/core/lib/zksync_core/src/consistency_checker/tests/test_helpers.rs b/core/lib/zksync_core/src/consistency_checker/tests/test_helpers.rs index 8395302700b7..bb317f5adbd4 100644 --- a/core/lib/zksync_core/src/consistency_checker/tests/test_helpers.rs +++ b/core/lib/zksync_core/src/consistency_checker/tests/test_helpers.rs @@ -7,7 +7,9 @@ use zksync_types::{web3::contract::Options, L2ChainId, ProtocolVersion}; use super::*; use crate::genesis::{ensure_genesis_state, GenesisParams}; -pub(crate) fn build_commit_tx_input_data_is_correct() { +pub(crate) fn build_commit_tx_input_data_is_correct( + l1_batch_commit_data_generator: Arc, +) { let contract = zksync_contracts::zksync_contract(); let commit_function = contract.function("commitBatches").unwrap(); let batches = vec![ @@ -15,7 +17,8 @@ pub(crate) fn build_commit_tx_input_data_is_correct() { create_l1_batch_with_metadata(2), ]; - let commit_tx_input_data = build_commit_tx_input_data(&batches); + let commit_tx_input_data = + build_commit_tx_input_data(&batches, l1_batch_commit_data_generator.clone()); for batch in &batches { let commit_data = ConsistencyChecker::extract_commit_data( @@ -24,13 +27,17 @@ pub(crate) fn build_commit_tx_input_data_is_correct() { batch.header.number, ) .unwrap(); - assert_eq!(commit_data, CommitBatchInfoRollup::new(batch).into_token()); + assert_eq!( + commit_data, + l1_batch_commit_data_generator.l1_commit_batch(batch), + ); } } pub(crate) async fn normal_checker_function( batches_per_transaction: usize, (mapper_name, save_actions_mapper): (&'static str, SaveActionMapper), + l1_batch_commit_data_generator: Arc, ) { println!("Using save_actions_mapper={mapper_name}"); @@ -45,7 +52,8 @@ pub(crate) async fn normal_checker_function( let client = MockEthereum::default(); for (i, l1_batches) in l1_batches.chunks(batches_per_transaction).enumerate() { - let input_data = build_commit_tx_input_data(l1_batches); + let input_data = + build_commit_tx_input_data(l1_batches, l1_batch_commit_data_generator.clone()); let signed_tx = client.sign_prepared_tx( input_data.clone(), Options { @@ -67,7 +75,7 @@ pub(crate) async fn normal_checker_function( let (l1_batch_updates_sender, mut l1_batch_updates_receiver) = mpsc::unbounded_channel(); let checker = ConsistencyChecker { event_handler: Box::new(l1_batch_updates_sender), - ..create_mock_checker(client, pool.clone()) + ..create_mock_checker(client, pool.clone(), l1_batch_commit_data_generator) }; let (stop_sender, stop_receiver) = watch::channel(false); @@ -96,6 +104,7 @@ pub(crate) async fn normal_checker_function( pub(crate) async fn checker_processes_pre_boojum_batches( (mapper_name, save_actions_mapper): (&'static str, SaveActionMapper), + l1_batch_commit_data_generator: Arc, ) { println!("Using save_actions_mapper={mapper_name}"); @@ -121,7 +130,10 @@ pub(crate) async fn checker_processes_pre_boojum_batches( let client = MockEthereum::default(); for (i, l1_batch) in l1_batches.iter().enumerate() { - let input_data = build_commit_tx_input_data(slice::from_ref(l1_batch)); + let input_data = build_commit_tx_input_data( + slice::from_ref(l1_batch), + l1_batch_commit_data_generator.clone(), + ); let signed_tx = client.sign_prepared_tx( input_data.clone(), Options { @@ -139,7 +151,7 @@ pub(crate) async fn checker_processes_pre_boojum_batches( let (l1_batch_updates_sender, mut l1_batch_updates_receiver) = mpsc::unbounded_channel(); let checker = ConsistencyChecker { event_handler: Box::new(l1_batch_updates_sender), - ..create_mock_checker(client, pool.clone()) + ..create_mock_checker(client, pool.clone(), l1_batch_commit_data_generator) }; let (stop_sender, stop_receiver) = watch::channel(false); @@ -166,7 +178,10 @@ pub(crate) async fn checker_processes_pre_boojum_batches( checker_task.await.unwrap().unwrap(); } -pub async fn checker_functions_after_snapshot_recovery(delay_batch_insertion: bool) { +pub async fn checker_functions_after_snapshot_recovery( + delay_batch_insertion: bool, + l1_batch_commit_data_generator: Arc, +) { let pool = ConnectionPool::test_pool().await; let mut storage = pool.access_storage().await.unwrap(); storage @@ -176,7 +191,10 @@ pub async fn checker_functions_after_snapshot_recovery(delay_batch_insertion: bo let l1_batch = create_l1_batch_with_metadata(99); - let commit_tx_input_data = build_commit_tx_input_data(slice::from_ref(&l1_batch)); + let commit_tx_input_data = build_commit_tx_input_data( + slice::from_ref(&l1_batch), + l1_batch_commit_data_generator.clone(), + ); let client = MockEthereum::default(); let signed_tx = client.sign_prepared_tx( commit_tx_input_data.clone(), @@ -208,7 +226,7 @@ pub async fn checker_functions_after_snapshot_recovery(delay_batch_insertion: bo let (l1_batch_updates_sender, mut l1_batch_updates_receiver) = mpsc::unbounded_channel(); let checker = ConsistencyChecker { event_handler: Box::new(l1_batch_updates_sender), - ..create_mock_checker(client, pool.clone()) + ..create_mock_checker(client, pool.clone(), l1_batch_commit_data_generator) }; let (stop_sender, stop_receiver) = watch::channel(false); let checker_task = tokio::spawn(checker.run(stop_receiver)); @@ -233,6 +251,7 @@ pub async fn checker_functions_after_snapshot_recovery(delay_batch_insertion: bo pub(crate) async fn checker_detects_incorrect_tx_data( kind: IncorrectDataKind, snapshot_recovery: bool, + l1_batch_commit_data_generator: Arc, ) { let pool = ConnectionPool::test_pool().await; let mut storage = pool.access_storage().await.unwrap(); @@ -249,7 +268,9 @@ pub(crate) async fn checker_detects_incorrect_tx_data( let l1_batch = create_l1_batch_with_metadata(if snapshot_recovery { 99 } else { 1 }); let client = MockEthereum::default(); - let commit_tx_hash = kind.apply(&client, &l1_batch).await; + let commit_tx_hash = kind + .apply(&client, &l1_batch, l1_batch_commit_data_generator.clone()) + .await; let commit_tx_hash_by_l1_batch = HashMap::from([(l1_batch.header.number, commit_tx_hash)]); let save_actions = [ @@ -264,7 +285,7 @@ pub(crate) async fn checker_detects_incorrect_tx_data( } drop(storage); - let checker = create_mock_checker(client, pool); + let checker = create_mock_checker(client, pool, l1_batch_commit_data_generator); let (_stop_sender, stop_receiver) = watch::channel(false); // The checker must stop with an error. tokio::time::timeout(Duration::from_secs(30), checker.run(stop_receiver)) diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs index bfd404a5e5d9..ca1d71a56982 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs @@ -409,7 +409,7 @@ impl EthTxAggregator { AggregatedOperation::Commit(last_committed_l1_batch, l1_batches) => { let commit_data = self .l1_commit_data_generator - .l1_commit_data(&last_committed_l1_batch, &l1_batches); + .l1_commit_batches(&last_committed_l1_batch, &l1_batches); if contracts_are_pre_shared_bridge { self.functions .pre_shared_bridge_commit diff --git a/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs b/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs index fb3933a790c3..047aeeb28dff 100644 --- a/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs +++ b/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs @@ -1,6 +1,9 @@ use zksync_l1_contract_interface::{ - i_executor::methods::{CommitBatchesRollup, CommitBatchesValidium}, - Tokenize, + i_executor::{ + methods::{CommitBatchesRollup, CommitBatchesValidium}, + structures::{CommitBatchInfoRollup, CommitBatchInfoValidium}, + }, + Tokenizable, Tokenize, }; use zksync_types::{commitment::L1BatchWithMetadata, ethabi::Token}; @@ -8,11 +11,13 @@ pub trait L1BatchCommitDataGenerator where Self: std::fmt::Debug + Send + Sync, { - fn l1_commit_data( + fn l1_commit_batches( &self, last_committed_l1_batch: &L1BatchWithMetadata, l1_batches: &[L1BatchWithMetadata], ) -> Vec; + + fn l1_commit_batch(&self, l1_batch: &L1BatchWithMetadata) -> Token; } #[derive(Debug, Clone)] @@ -22,7 +27,7 @@ pub struct RollupModeL1BatchCommitDataGenerator; pub struct ValidiumModeL1BatchCommitDataGenerator; impl L1BatchCommitDataGenerator for RollupModeL1BatchCommitDataGenerator { - fn l1_commit_data( + fn l1_commit_batches( &self, last_committed_l1_batch: &L1BatchWithMetadata, l1_batches: &[L1BatchWithMetadata], @@ -33,10 +38,17 @@ impl L1BatchCommitDataGenerator for RollupModeL1BatchCommitDataGenerator { } .into_tokens() } + + fn l1_commit_batch(&self, l1_batch: &L1BatchWithMetadata) -> Token { + CommitBatchInfoRollup { + l1_batch_with_metadata: l1_batch, + } + .into_token() + } } impl L1BatchCommitDataGenerator for ValidiumModeL1BatchCommitDataGenerator { - fn l1_commit_data( + fn l1_commit_batches( &self, last_committed_l1_batch: &L1BatchWithMetadata, l1_batches: &[L1BatchWithMetadata], @@ -47,4 +59,11 @@ impl L1BatchCommitDataGenerator for ValidiumModeL1BatchCommitDataGenerator { } .into_tokens() } + + fn l1_commit_batch(&self, l1_batch: &L1BatchWithMetadata) -> Token { + CommitBatchInfoValidium { + l1_batch_with_metadata: l1_batch, + } + .into_token() + } } diff --git a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs index dee139f8dae8..674384be592a 100644 --- a/core/lib/zksync_core/src/eth_sender/publish_criterion.rs +++ b/core/lib/zksync_core/src/eth_sender/publish_criterion.rs @@ -221,14 +221,10 @@ impl L1BatchPublishCriterion for DataSizeCriterion { for (index, l1_batch) in consecutive_l1_batches.iter().enumerate() { // TODO (PLA-771): Make sure that this estimation is correct. - // NOTE: any element will do for `StoredBlockInfo`. We subtract the size later for - // correctness, to avoid double accounting. - let l1_commit_data_size = ethabi::encode(&[ethabi::Token::Array( - self.l1_batch_commit_data_generator - .l1_commit_data(l1_batch, std::slice::from_ref(l1_batch)), - )]) - .len() - - STORED_BLOCK_INFO_SIZE; + let l1_commit_data_size = ethabi::encode(&[self + .l1_batch_commit_data_generator + .l1_commit_batch(l1_batch)]) + .len(); if data_size_left < l1_commit_data_size { if index == 0 { From 2278532b51df1372aa9e419cffe1bed77fe886cc Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Mon, 4 Mar 2024 14:49:42 -0300 Subject: [PATCH 08/16] Fix double hardcoding to CommitBatchesRollup --- .../zksync_core/src/eth_sender/aggregator.rs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/core/lib/zksync_core/src/eth_sender/aggregator.rs b/core/lib/zksync_core/src/eth_sender/aggregator.rs index 36e59bedbe05..b0194aacc476 100644 --- a/core/lib/zksync_core/src/eth_sender/aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/aggregator.rs @@ -3,9 +3,7 @@ use std::sync::Arc; use zksync_config::configs::eth_sender::{ProofLoadingMode, ProofSendingMode, SenderConfig}; use zksync_contracts::BaseSystemContractsHashes; use zksync_dal::StorageProcessor; -use zksync_l1_contract_interface::i_executor::methods::{ - CommitBatchesRollup, ExecuteBatches, ProveBatches, -}; +use zksync_l1_contract_interface::i_executor::methods::{ExecuteBatches, ProveBatches}; use zksync_object_store::{ObjectStore, ObjectStoreError}; use zksync_prover_interface::outputs::L1BatchProofForL1; use zksync_types::{ @@ -141,12 +139,6 @@ impl Aggregator { protocol_version_id, ) .await - .map(|op| { - AggregatedOperation::Commit( - op.last_committed_l1_batch.clone(), - op.l1_batches.to_vec(), - ) - }) } } @@ -183,7 +175,7 @@ impl Aggregator { last_sealed_batch: L1BatchNumber, base_system_contracts_hashes: BaseSystemContractsHashes, protocol_version_id: ProtocolVersionId, - ) -> Option { + ) -> Option { let mut blocks_dal = storage.blocks_dal(); let last_committed_l1_batch = blocks_dal .get_last_committed_to_eth_l1_batch() @@ -231,10 +223,7 @@ impl Aggregator { ) .await; - batches.map(|batches| CommitBatchesRollup { - last_committed_l1_batch, - l1_batches: batches, - }) + batches.map(|batches| AggregatedOperation::Commit(last_committed_l1_batch, batches)) } async fn load_real_proof_operation( From c3d644165769b9b466502132fcbe347fbfde7f4b Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Mon, 4 Mar 2024 14:49:59 -0300 Subject: [PATCH 09/16] Fix double 'into_tokens' --- core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs index ca1d71a56982..cf1d72b61581 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs @@ -413,7 +413,7 @@ impl EthTxAggregator { if contracts_are_pre_shared_bridge { self.functions .pre_shared_bridge_commit - .encode_input(&commit_data.into_tokens()) + .encode_input(&commit_data) .expect("Failed to encode commit transaction data") } else { args.extend_from_slice(&commit_data); From 2192b61c98297710221f9bf951573f8ab43c1400 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Mon, 4 Mar 2024 15:16:34 -0300 Subject: [PATCH 10/16] Lints --- core/lib/zksync_core/src/eth_sender/aggregator.rs | 2 +- core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs | 1 + core/lib/zksync_core/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/lib/zksync_core/src/eth_sender/aggregator.rs b/core/lib/zksync_core/src/eth_sender/aggregator.rs index b0194aacc476..89cf3968f0c7 100644 --- a/core/lib/zksync_core/src/eth_sender/aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/aggregator.rs @@ -49,7 +49,7 @@ impl Aggregator { Box::from(DataSizeCriterion { op: AggregatedActionType::Commit, data_limit: config.max_eth_tx_data_size, - l1_batch_commit_data_generator: l1_batch_commit_data_generator.clone(), + l1_batch_commit_data_generator, }), Box::from(TimestampDeadlineCriterion { op: AggregatedActionType::Commit, diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs index cf1d72b61581..a9842936b95e 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs @@ -58,6 +58,7 @@ pub struct EthTxAggregator { } impl EthTxAggregator { + #[allow(clippy::too-many-arguments)] pub async fn new( config: SenderConfig, aggregator: Aggregator, diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 5804a6021f07..f8e77af37523 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -720,7 +720,7 @@ pub async fn initialize_components( .as_ref() .context("network_config")? .zksync_network_id, - l1_batch_commit_data_generator.clone(), + l1_batch_commit_data_generator, ) .await; task_futures.push(tokio::spawn( From 45649c92e270a2a0db33c0e972cba2691b90a0ea Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Mon, 4 Mar 2024 15:22:03 -0300 Subject: [PATCH 11/16] Lints --- core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs | 2 +- core/lib/zksync_core/src/lib.rs | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs index a9842936b95e..fa9bce07321e 100644 --- a/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/eth_tx_aggregator.rs @@ -58,7 +58,7 @@ pub struct EthTxAggregator { } impl EthTxAggregator { - #[allow(clippy::too-many-arguments)] + #[allow(clippy::too_many_arguments)] pub async fn new( config: SenderConfig, aggregator: Aggregator, diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index f8e77af37523..2e05586544e8 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -305,10 +305,9 @@ async fn ensure_l1_batch_commit_data_generation_mode( contracts_config: &ContractsConfig, eth_client: &impl EthInterface, ) -> anyhow::Result<()> { - let selected_l1_batch_commit_data_generator_mode = state_keeper_config - .l1_batch_commit_data_generator_mode - .clone(); - match get_pubdata_pricing_mode(&contracts_config, eth_client).await { + let selected_l1_batch_commit_data_generator_mode = + state_keeper_config.l1_batch_commit_data_generator_mode; + match get_pubdata_pricing_mode(contracts_config, eth_client).await { // Getters contract support getPubdataPricingMode method Ok(l1_contract_pubdata_pricing_mode) => { let l1_contract_batch_commitment_mode = From f19bd63050128927f72aeefd4a135220de4a5905 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 5 Mar 2024 11:16:05 -0300 Subject: [PATCH 12/16] Slightly more specific comments to new structures --- .../src/i_executor/methods/commit_batches.rs | 4 ++-- .../src/i_executor/structures/commit_batch_info.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs b/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs index 93b7eb713db2..3a7c5459581c 100644 --- a/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs +++ b/core/lib/l1_contract_interface/src/i_executor/methods/commit_batches.rs @@ -5,7 +5,7 @@ use crate::{ Tokenizable, Tokenize, }; -/// Input required to encode `commitBatches` call. +/// Input required to encode `commitBatches` call for a contract running in rollup mode. #[derive(Debug, Clone)] pub struct CommitBatchesRollup { pub last_committed_l1_batch: L1BatchWithMetadata, @@ -25,7 +25,7 @@ impl Tokenize for CommitBatchesRollup { } } -/// Input required to encode `commitBatches` call. +/// Input required to encode `commitBatches` call for a contract running in validium mode. #[derive(Debug, Clone)] pub struct CommitBatchesValidium { pub last_committed_l1_batch: L1BatchWithMetadata, diff --git a/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs b/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs index b8360b8eb53d..22292ab7be00 100644 --- a/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs +++ b/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs @@ -7,7 +7,7 @@ use zksync_types::{ use crate::Tokenizable; -/// Encoding for `CommitBatchInfo` from `IExecutor.sol` +/// Encoding for `CommitBatchInfo` from `IExecutor.sol` for a contract running in rollup mode. #[derive(Debug)] pub struct CommitBatchInfoRollup<'a> { pub l1_batch_with_metadata: &'a L1BatchWithMetadata, @@ -49,7 +49,7 @@ impl<'a> Tokenizable for CommitBatchInfoRollup<'a> { } } -/// Encoding for `CommitBatchInfo` from `IExecutor.sol` +/// Encoding for `CommitBatchInfo` from `IExecutor.sol` for a contract running in validium mode. #[derive(Debug)] pub struct CommitBatchInfoValidium<'a> { pub l1_batch_with_metadata: &'a L1BatchWithMetadata, From 01e53bd6c492b3a3ee5ebdd82d23faf3331d6da4 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 5 Mar 2024 11:30:58 -0300 Subject: [PATCH 13/16] Minor refactor for encode_l1_commit --- .../structures/commit_batch_info.rs | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs b/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs index 22292ab7be00..0ea8a627b654 100644 --- a/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs +++ b/core/lib/l1_contract_interface/src/i_executor/structures/commit_batch_info.rs @@ -1,5 +1,9 @@ use zksync_types::{ - commitment::{pre_boojum_serialize_commitments, serialize_commitments, L1BatchWithMetadata}, + block::L1BatchHeader, + commitment::{ + pre_boojum_serialize_commitments, serialize_commitments, L1BatchMetadata, + L1BatchWithMetadata, + }, ethabi::Token, web3::{contract::Error as Web3ContractError, error::Error as Web3ApiError}, U256, @@ -44,7 +48,11 @@ impl<'a> Tokenizable for CommitBatchInfoRollup<'a> { { pre_boojum_into_token(self.l1_batch_with_metadata) } else { - Token::Tuple(rollup_mode_l1_commit_data(self.l1_batch_with_metadata)) + Token::Tuple(encode_l1_commit( + &self.l1_batch_with_metadata.header, + &self.l1_batch_with_metadata.metadata, + Some(&self.l1_batch_with_metadata), + )) } } } @@ -86,7 +94,11 @@ impl<'a> Tokenizable for CommitBatchInfoValidium<'a> { { pre_boojum_into_token(self.l1_batch_with_metadata) } else { - Token::Tuple(validium_mode_l1_commit_data(self.l1_batch_with_metadata)) + Token::Tuple(encode_l1_commit( + &self.l1_batch_with_metadata.header, + &self.l1_batch_with_metadata.metadata, + None, + )) } } } @@ -122,9 +134,11 @@ fn pre_boojum_into_token(l1_batch_commit_with_metadata: &L1BatchWithMetadata) -> ]) } -fn encode_l1_commit(l1_batch_with_metadata: &L1BatchWithMetadata, pubdata: Token) -> Vec { - let header = &l1_batch_with_metadata.header; - let metadata = &l1_batch_with_metadata.metadata; +fn encode_l1_commit( + header: &L1BatchHeader, + metadata: &L1BatchMetadata, + pubdata_input: Option<&L1BatchWithMetadata>, +) -> Vec { let commit_data = vec![ // `batchNumber` Token::Uint(U256::from(header.number.0)), @@ -156,20 +170,11 @@ fn encode_l1_commit(l1_batch_with_metadata: &L1BatchWithMetadata, pubdata: Token ), // `systemLogs` Token::Bytes(serialize_commitments(&header.system_logs)), - pubdata, + Token::Bytes( + pubdata_input + .map(L1BatchWithMetadata::construct_pubdata) + .unwrap_or_default(), + ), ]; commit_data } - -fn validium_mode_l1_commit_data(l1_batch_with_metadata: &L1BatchWithMetadata) -> Vec { - encode_l1_commit(l1_batch_with_metadata, Token::Bytes(vec![])) -} - -fn rollup_mode_l1_commit_data(l1_batch_with_metadata: &L1BatchWithMetadata) -> Vec { - encode_l1_commit( - l1_batch_with_metadata, - Token::Bytes(L1BatchWithMetadata::construct_pubdata( - l1_batch_with_metadata, - )), - ) -} From aa0ad57df3b192dd458a463069785853ecb31ee6 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 5 Mar 2024 11:41:03 -0300 Subject: [PATCH 14/16] Doc comments --- .../eth_sender/l1_batch_commit_data_generator.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs b/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs index 047aeeb28dff..b8657ff7ce63 100644 --- a/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs +++ b/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs @@ -7,22 +7,35 @@ use zksync_l1_contract_interface::{ }; use zksync_types::{commitment::L1BatchWithMetadata, ethabi::Token}; +/// [`L1BatchCommitDataGenerator`] abstracts how a batch or list of batches need to be tokenized +/// for committing to L1. pub trait L1BatchCommitDataGenerator where Self: std::fmt::Debug + Send + Sync, { + /// [`l1_commit_batches`] is the method you want when committing a block. + /// It uses metadata from `last_committed_l1_batch` and the batches in `l1_batches` to produce + /// the full commit data. fn l1_commit_batches( &self, last_committed_l1_batch: &L1BatchWithMetadata, l1_batches: &[L1BatchWithMetadata], ) -> Vec; + /// [`l1_commit_batch`] is used mostly for size calculations for sealing criteria and for + /// consistency checks. Instead of preparing a full commit, it tokenizes an individual batch. fn l1_commit_batch(&self, l1_batch: &L1BatchWithMetadata) -> Token; } +/// [`RollupModeL1BatchCommitDataGenerator`] implements [`L1BatchCommitDataGenerator`] for +/// contracts operating in rollup mode. It differs from [`ValidiumModeL1BatchCommitDataGenerator`] +/// in that it includes the pubdata in the produced message. #[derive(Debug, Clone)] pub struct RollupModeL1BatchCommitDataGenerator; +/// [`ValidiumModeL1BatchCommitDataGenerator`] implements [`L1BatchCommitDataGenerator`] for +/// contracts operating in rollup mode. It differs from [`RollupModeL1BatchCommitDataGenerator`] +/// in that it does not include the pubdata in the produced message. #[derive(Debug, Clone)] pub struct ValidiumModeL1BatchCommitDataGenerator; From 0b9b0e2f0e147c06ef7b36ac150ce00e3471fe94 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 5 Mar 2024 11:41:26 -0300 Subject: [PATCH 15/16] Copy-paste --- .../src/eth_sender/l1_batch_commit_data_generator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs b/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs index b8657ff7ce63..de6806f478ef 100644 --- a/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs +++ b/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs @@ -34,7 +34,7 @@ where pub struct RollupModeL1BatchCommitDataGenerator; /// [`ValidiumModeL1BatchCommitDataGenerator`] implements [`L1BatchCommitDataGenerator`] for -/// contracts operating in rollup mode. It differs from [`RollupModeL1BatchCommitDataGenerator`] +/// contracts operating in validium mode. It differs from [`RollupModeL1BatchCommitDataGenerator`] /// in that it does not include the pubdata in the produced message. #[derive(Debug, Clone)] pub struct ValidiumModeL1BatchCommitDataGenerator; From edbc278d3c79d706d2b53732080d9055644ec54e Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 5 Mar 2024 15:04:15 -0300 Subject: [PATCH 16/16] spellcheck --- .../src/eth_sender/l1_batch_commit_data_generator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs b/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs index de6806f478ef..c3a68969a67a 100644 --- a/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs +++ b/core/lib/zksync_core/src/eth_sender/l1_batch_commit_data_generator.rs @@ -23,7 +23,7 @@ where ) -> Vec; /// [`l1_commit_batch`] is used mostly for size calculations for sealing criteria and for - /// consistency checks. Instead of preparing a full commit, it tokenizes an individual batch. + /// consistency checks. Instead of preparing a full commit, it will tokenize an individual batch. fn l1_commit_batch(&self, l1_batch: &L1BatchWithMetadata) -> Token; }