diff --git a/core/bin/zksync_server/src/node_builder.rs b/core/bin/zksync_server/src/node_builder.rs index f1db73164eb1..96205eb9fbfc 100644 --- a/core/bin/zksync_server/src/node_builder.rs +++ b/core/bin/zksync_server/src/node_builder.rs @@ -72,7 +72,10 @@ use zksync_node_framework::{ service::{ZkStackService, ZkStackServiceBuilder}, }; use zksync_types::{ - pubdata_da::PubdataSendingMode, settlement::SettlementMode, SHARED_BRIDGE_ETHER_TOKEN_ADDRESS, + commitment::{L1BatchCommitmentMode, PubdataType}, + pubdata_da::PubdataSendingMode, + settlement::SettlementMode, + SHARED_BRIDGE_ETHER_TOKEN_ADDRESS, }; use zksync_vlog::prometheus::PrometheusExporterConfig; @@ -118,6 +121,24 @@ impl MainNodeBuilder { self.node.runtime_handle() } + pub fn get_pubdata_type(&self) -> PubdataType { + if self.genesis_config.l1_batch_commit_data_generator_mode == L1BatchCommitmentMode::Rollup + { + return PubdataType::Rollup; + } + + let Some(da_client_config) = self.configs.da_client_config.clone() else { + return PubdataType::NoDA; + }; + + match da_client_config { + DAClientConfig::Avail(_) => PubdataType::Avail, + DAClientConfig::Celestia(_) => PubdataType::Celestia, + DAClientConfig::Eigen(_) => PubdataType::Eigen, + DAClientConfig::ObjectStore(_) => PubdataType::ObjectStore, + } + } + fn add_sigint_handler_layer(mut self) -> anyhow::Result { self.node.add_layer(SigintHandlerLayer); Ok(self) @@ -252,7 +273,7 @@ impl MainNodeBuilder { try_load_config!(self.configs.mempool_config), try_load_config!(wallets.state_keeper), self.contracts_config.l2_da_validator_addr, - self.genesis_config.l1_batch_commit_data_generator_mode, + self.get_pubdata_type(), ); let db_config = try_load_config!(self.configs.db_config); let experimental_vm_config = self diff --git a/core/lib/basic_types/src/commitment.rs b/core/lib/basic_types/src/commitment.rs index 0eed46aad782..c43a55bab4a9 100644 --- a/core/lib/basic_types/src/commitment.rs +++ b/core/lib/basic_types/src/commitment.rs @@ -58,8 +58,35 @@ impl FromStr for L1BatchCommitmentMode { } } +#[derive(Default, Copy, Debug, Clone, PartialEq, Serialize, Deserialize, Display)] +pub enum PubdataType { + #[default] + Rollup, + NoDA, + Avail, + Celestia, + Eigen, + ObjectStore, +} + +impl FromStr for PubdataType { + type Err = &'static str; + + fn from_str(s: &str) -> Result { + match s { + "Rollup" => Ok(Self::Rollup), + "NoDA" => Ok(Self::NoDA), + "Avail" => Ok(Self::Avail), + "Celestia" => Ok(Self::Celestia), + "Eigen" => Ok(Self::Eigen), + "ObjectStore" => Ok(Self::ObjectStore), + _ => Err("Incorrect DA client type; expected one of `Rollup`, `NoDA`, `Avail`, `Celestia`, `Eigen`, `ObjectStore`"), + } + } +} + #[derive(Default, Copy, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PubdataParams { pub l2_da_validator_address: Address, - pub pubdata_type: L1BatchCommitmentMode, + pub pubdata_type: PubdataType, } diff --git a/core/lib/dal/src/consensus/conv.rs b/core/lib/dal/src/consensus/conv.rs index 3153343d6014..140c3f6a84c3 100644 --- a/core/lib/dal/src/consensus/conv.rs +++ b/core/lib/dal/src/consensus/conv.rs @@ -5,7 +5,7 @@ use zksync_consensus_roles::{attester, node}; use zksync_protobuf::{read_optional_repr, read_required, required, ProtoFmt, ProtoRepr}; use zksync_types::{ abi, - commitment::{L1BatchCommitmentMode, PubdataParams}, + commitment::{PubdataParams, PubdataType}, ethabi, fee::Fee, h256_to_u256, @@ -112,8 +112,8 @@ impl ProtoRepr for proto::PubdataParams { l2_da_validator_address: required(&self.l2_da_validator_address) .and_then(|a| parse_h160(a)) .context("l2_da_validator_address")?, - pubdata_type: required(&self.pubdata_type) - .and_then(|x| Ok(proto::L1BatchCommitDataGeneratorMode::try_from(*x)?)) + pubdata_type: required(&self.pubdata_info) + .and_then(|x| Ok(proto::PubdataType::try_from(*x)?)) .context("pubdata_type")? .parse(), }) @@ -122,9 +122,7 @@ impl ProtoRepr for proto::PubdataParams { fn build(this: &Self::Type) -> Self { Self { l2_da_validator_address: Some(this.l2_da_validator_address.as_bytes().into()), - pubdata_type: Some( - proto::L1BatchCommitDataGeneratorMode::new(&this.pubdata_type) as i32, - ), + pubdata_info: Some(this.pubdata_type as i32), } } } @@ -572,18 +570,15 @@ impl ProtoRepr for proto::AttesterCommittee { } } -impl proto::L1BatchCommitDataGeneratorMode { - pub(crate) fn new(n: &L1BatchCommitmentMode) -> Self { - match n { - L1BatchCommitmentMode::Rollup => Self::Rollup, - L1BatchCommitmentMode::Validium => Self::Validium, - } - } - - pub(crate) fn parse(&self) -> L1BatchCommitmentMode { +impl proto::PubdataType { + pub(crate) fn parse(&self) -> PubdataType { match self { - Self::Rollup => L1BatchCommitmentMode::Rollup, - Self::Validium => L1BatchCommitmentMode::Validium, + Self::Rollup => PubdataType::Rollup, + Self::NoDa => PubdataType::NoDA, + Self::Avail => PubdataType::Avail, + Self::Celestia => PubdataType::Celestia, + Self::Eigen => PubdataType::Eigen, + Self::ObjectStore => PubdataType::ObjectStore, } } } diff --git a/core/lib/dal/src/consensus/proto/mod.proto b/core/lib/dal/src/consensus/proto/mod.proto index 49a69e8a36ec..6bae78ca5fe9 100644 --- a/core/lib/dal/src/consensus/proto/mod.proto +++ b/core/lib/dal/src/consensus/proto/mod.proto @@ -31,7 +31,8 @@ message Payload { message PubdataParams { optional bytes l2_da_validator_address = 1; // required; H160 - optional L1BatchCommitDataGeneratorMode pubdata_type = 2; // required + optional PubdataType pubdata_info = 3; // required + reserved 2; reserved "pubdata_type"; } message L1Transaction { @@ -149,7 +150,11 @@ message AttestationStatus { optional uint64 next_batch_to_attest = 2; // required } -enum L1BatchCommitDataGeneratorMode { +enum PubdataType { Rollup = 0; - Validium = 1; + NoDA = 1; + Avail = 2; + Celestia = 3; + Eigen = 4; + ObjectStore = 5; } diff --git a/core/lib/dal/src/consensus/tests.rs b/core/lib/dal/src/consensus/tests.rs index 465148dc7b5c..125db0de89f5 100644 --- a/core/lib/dal/src/consensus/tests.rs +++ b/core/lib/dal/src/consensus/tests.rs @@ -9,7 +9,7 @@ use zksync_protobuf::{ }; use zksync_test_contracts::Account; use zksync_types::{ - commitment::{L1BatchCommitmentMode, PubdataParams}, + commitment::{PubdataParams, PubdataType}, web3::Bytes, Execute, ExecuteTransactionCommon, L1BatchNumber, ProtocolVersionId, Transaction, }; @@ -58,8 +58,12 @@ fn payload(rng: &mut impl Rng, protocol_version: ProtocolVersionId) -> Payload { } else { PubdataParams { pubdata_type: match rng.gen_range(0..2) { - 0 => L1BatchCommitmentMode::Rollup, - _ => L1BatchCommitmentMode::Validium, + 0 => PubdataType::Rollup, + 1 => PubdataType::NoDA, + 2 => PubdataType::Avail, + 3 => PubdataType::Celestia, + 4 => PubdataType::Eigen, + _ => PubdataType::ObjectStore, }, l2_da_validator_address: rng.gen(), } diff --git a/core/lib/dal/src/factory_deps_dal.rs b/core/lib/dal/src/factory_deps_dal.rs index 424d708da241..64cbe78fbd1a 100644 --- a/core/lib/dal/src/factory_deps_dal.rs +++ b/core/lib/dal/src/factory_deps_dal.rs @@ -89,39 +89,36 @@ impl FactoryDepsDal<'_, '_> { .map(|row| row.bytecode)) } - pub async fn get_base_system_contracts( + pub async fn get_base_system_contracts_from_factory_deps( &mut self, bootloader_hash: H256, default_aa_hash: H256, evm_emulator_hash: Option, - ) -> anyhow::Result { + ) -> anyhow::Result> { let bootloader_bytecode = self .get_sealed_factory_dep(bootloader_hash) .await - .context("failed loading bootloader code")? - .with_context(|| format!("bootloader code with hash {bootloader_hash:?} should be present in the database"))?; - let bootloader_code = SystemContractCode { - code: bootloader_bytecode, - hash: bootloader_hash, - }; + .context("failed loading bootloader code")?; let default_aa_bytecode = self .get_sealed_factory_dep(default_aa_hash) .await - .context("failed loading default account code")? - .with_context(|| format!("default account code with hash {default_aa_hash:?} should be present in the database"))?; + .context("failed loading default account code")?; - let default_aa_code = SystemContractCode { - code: default_aa_bytecode, - hash: default_aa_hash, + let (Some(bootloader_bytecode), Some(default_aa_bytecode)) = + (bootloader_bytecode, default_aa_bytecode) + else { + return Ok(None); }; let evm_emulator_code = if let Some(evm_emulator_hash) = evm_emulator_hash { let evm_emulator_bytecode = self .get_sealed_factory_dep(evm_emulator_hash) .await - .context("failed loading EVM emulator code")? - .with_context(|| format!("EVM emulator code with hash {evm_emulator_hash:?} should be present in the database"))?; + .context("failed loading EVM emulator code")?; + let Some(evm_emulator_bytecode) = evm_emulator_bytecode else { + return Ok(None); + }; Some(SystemContractCode { code: evm_emulator_bytecode, @@ -131,11 +128,20 @@ impl FactoryDepsDal<'_, '_> { None }; - Ok(BaseSystemContracts { + let bootloader_code = SystemContractCode { + code: bootloader_bytecode, + hash: bootloader_hash, + }; + + let default_aa_code = SystemContractCode { + code: default_aa_bytecode, + hash: default_aa_hash, + }; + Ok(Some(BaseSystemContracts { bootloader: bootloader_code, default_aa: default_aa_code, evm_emulator: evm_emulator_code, - }) + })) } /// Returns bytecodes for factory deps with the specified `hashes`. diff --git a/core/lib/dal/src/models/storage_block.rs b/core/lib/dal/src/models/storage_block.rs index 54635932a1af..1aea27a497f0 100644 --- a/core/lib/dal/src/models/storage_block.rs +++ b/core/lib/dal/src/models/storage_block.rs @@ -7,7 +7,7 @@ use zksync_contracts::BaseSystemContractsHashes; use zksync_types::{ api, block::{L1BatchHeader, L2BlockHeader, UnsealedL1BatchHeader}, - commitment::{L1BatchCommitmentMode, L1BatchMetaParameters, L1BatchMetadata, PubdataParams}, + commitment::{L1BatchMetaParameters, L1BatchMetadata, PubdataParams, PubdataType}, fee_model::{BatchFeeInput, L1PeggedBatchFeeModelInput, PubdataIndependentBatchFeeModelInput}, l2_to_l1_log::{L2ToL1Log, SystemL2ToL1Log, UserL2ToL1Log}, Address, Bloom, L1BatchNumber, L2BlockNumber, ProtocolVersionId, SLChainId, H256, @@ -556,7 +556,7 @@ impl From for L2BlockHeader { .unwrap_or_default(), pubdata_params: PubdataParams { l2_da_validator_address: Address::from_slice(&row.l2_da_validator_address), - pubdata_type: L1BatchCommitmentMode::from_str(&row.pubdata_type).unwrap(), + pubdata_type: PubdataType::from_str(&row.pubdata_type).unwrap(), }, } } diff --git a/core/lib/dal/src/models/storage_sync.rs b/core/lib/dal/src/models/storage_sync.rs index 3f80f52c56eb..bac51c9e14d9 100644 --- a/core/lib/dal/src/models/storage_sync.rs +++ b/core/lib/dal/src/models/storage_sync.rs @@ -4,7 +4,7 @@ use zksync_contracts::BaseSystemContractsHashes; use zksync_db_connection::error::SqlxContext; use zksync_types::{ api::en, - commitment::{L1BatchCommitmentMode, PubdataParams}, + commitment::{PubdataParams, PubdataType}, parse_h160, parse_h256, parse_h256_opt, Address, L1BatchNumber, L2BlockNumber, ProtocolVersionId, Transaction, H256, }; @@ -97,7 +97,7 @@ impl TryFrom for SyncBlock { hash: parse_h256(&block.hash).decode_column("hash")?, protocol_version: parse_protocol_version(block.protocol_version)?, pubdata_params: PubdataParams { - pubdata_type: L1BatchCommitmentMode::from_str(&block.pubdata_type) + pubdata_type: PubdataType::from_str(&block.pubdata_type) .decode_column("Invalid pubdata type")?, l2_da_validator_address: parse_h160(&block.l2_da_validator_address) .decode_column("l2_da_validator_address")?, diff --git a/core/lib/dal/src/protocol_versions_dal.rs b/core/lib/dal/src/protocol_versions_dal.rs index 11f6a93efdc4..18dd7516f4de 100644 --- a/core/lib/dal/src/protocol_versions_dal.rs +++ b/core/lib/dal/src/protocol_versions_dal.rs @@ -1,7 +1,7 @@ use std::convert::TryInto; use anyhow::Context as _; -use zksync_contracts::{BaseSystemContracts, BaseSystemContractsHashes}; +use zksync_contracts::BaseSystemContractsHashes; use zksync_db_connection::{ connection::Connection, error::DalResult, @@ -200,12 +200,10 @@ impl ProtocolVersionsDal<'_, '_> { ProtocolVersionId::try_from(row.id as u16).map_err(|err| sqlx::Error::Decode(err.into())) } - /// Returns base system contracts' hashes. Prefer `load_base_system_contracts_by_version_id` if - /// you also want to load the contracts themselves AND expect the contracts to be in the DB - /// already. + /// Returns base system contracts' hashes. pub async fn get_base_system_contract_hashes_by_version_id( &mut self, - version_id: u16, + version_id: ProtocolVersionId, ) -> anyhow::Result> { let row = sqlx::query!( r#" @@ -218,10 +216,10 @@ impl ProtocolVersionsDal<'_, '_> { WHERE id = $1 "#, - i32::from(version_id) + i32::from(version_id as u16) ) .instrument("get_base_system_contract_hashes_by_version_id") - .with_arg("version_id", &version_id) + .with_arg("version_id", &(version_id as u16)) .fetch_optional(self.storage) .await .context("cannot fetch system contract hashes")?; @@ -237,45 +235,6 @@ impl ProtocolVersionsDal<'_, '_> { }) } - pub async fn load_base_system_contracts_by_version_id( - &mut self, - version_id: u16, - ) -> anyhow::Result> { - let row = sqlx::query!( - r#" - SELECT - bootloader_code_hash, - default_account_code_hash, - evm_emulator_code_hash - FROM - protocol_versions - WHERE - id = $1 - "#, - i32::from(version_id) - ) - .instrument("load_base_system_contracts_by_version_id") - .with_arg("version_id", &version_id) - .fetch_optional(self.storage) - .await - .context("cannot fetch system contract hashes")?; - - Ok(if let Some(row) = row { - let contracts = self - .storage - .factory_deps_dal() - .get_base_system_contracts( - H256::from_slice(&row.bootloader_code_hash), - H256::from_slice(&row.default_account_code_hash), - row.evm_emulator_code_hash.as_deref().map(H256::from_slice), - ) - .await?; - Some(contracts) - } else { - None - }) - } - pub async fn get_protocol_version_with_latest_patch( &mut self, version_id: ProtocolVersionId, diff --git a/core/lib/env_config/src/genesis.rs b/core/lib/env_config/src/genesis.rs index 486d354e6cb5..60c5a48993d7 100644 --- a/core/lib/env_config/src/genesis.rs +++ b/core/lib/env_config/src/genesis.rs @@ -84,7 +84,6 @@ impl FromEnv for GenesisConfig { bootloader_hash: state_keeper.bootloader_hash, default_aa_hash: state_keeper.default_aa_hash, evm_emulator_hash: state_keeper.evm_emulator_hash, - // TODO(EVM-676): for now, the settlement layer is always the same as the L1 network l1_chain_id: L1ChainId(network_config.network.chain_id().0), l2_chain_id: network_config.zksync_network_id, snark_wrapper_vk_hash: contracts_config.snark_wrapper_vk_hash, diff --git a/core/lib/multivm/src/pubdata_builders/rollup.rs b/core/lib/multivm/src/pubdata_builders/full_builder.rs similarity index 65% rename from core/lib/multivm/src/pubdata_builders/rollup.rs rename to core/lib/multivm/src/pubdata_builders/full_builder.rs index 4a818dfe2314..40a260314a0a 100644 --- a/core/lib/multivm/src/pubdata_builders/rollup.rs +++ b/core/lib/multivm/src/pubdata_builders/full_builder.rs @@ -2,28 +2,27 @@ use zksync_types::{ ethabi, ethabi::{ParamType, Token}, l2_to_l1_log::l2_to_l1_logs_tree_size, - writes::compress_state_diffs, Address, ProtocolVersionId, }; use super::utils::{ build_chained_bytecode_hash, build_chained_log_hash, build_chained_message_hash, - build_logs_root, encode_user_logs, + build_logs_root, extend_from_pubdata_input, }; use crate::interface::pubdata::{PubdataBuilder, PubdataInput}; #[derive(Debug, Clone, Copy)] -pub struct RollupPubdataBuilder { +pub struct FullPubdataBuilder { pub l2_da_validator: Address, } -impl RollupPubdataBuilder { +impl FullPubdataBuilder { pub fn new(l2_da_validator: Address) -> Self { Self { l2_da_validator } } } -impl PubdataBuilder for RollupPubdataBuilder { +impl PubdataBuilder for FullPubdataBuilder { fn l2_da_validator(&self) -> Address { self.l2_da_validator } @@ -95,34 +94,3 @@ impl PubdataBuilder for RollupPubdataBuilder { pubdata } } - -fn extend_from_pubdata_input(buffer: &mut Vec, pubdata_input: &PubdataInput) { - let PubdataInput { - user_logs, - l2_to_l1_messages, - published_bytecodes, - state_diffs, - } = pubdata_input; - - // Adding user L2->L1 logs. - buffer.extend(encode_user_logs(user_logs)); - - // Encoding L2->L1 messages - // Format: `[(numberOfMessages as u32) || (messages[1].len() as u32) || messages[1] || ... || (messages[n].len() as u32) || messages[n]]` - buffer.extend((l2_to_l1_messages.len() as u32).to_be_bytes()); - for message in l2_to_l1_messages { - buffer.extend((message.len() as u32).to_be_bytes()); - buffer.extend(message); - } - // Encoding bytecodes - // Format: `[(numberOfBytecodes as u32) || (bytecodes[1].len() as u32) || bytecodes[1] || ... || (bytecodes[n].len() as u32) || bytecodes[n]]` - buffer.extend((published_bytecodes.len() as u32).to_be_bytes()); - for bytecode in published_bytecodes { - buffer.extend((bytecode.len() as u32).to_be_bytes()); - buffer.extend(bytecode); - } - // Encoding state diffs - // Format: `[size of compressed state diffs u32 || compressed state diffs || (# state diffs: intial + repeated) as u32 || sorted state diffs by ]` - let state_diffs_compressed = compress_state_diffs(state_diffs.clone()); - buffer.extend(state_diffs_compressed); -} diff --git a/core/lib/multivm/src/pubdata_builders/validium.rs b/core/lib/multivm/src/pubdata_builders/hashed_builder.rs similarity index 90% rename from core/lib/multivm/src/pubdata_builders/validium.rs rename to core/lib/multivm/src/pubdata_builders/hashed_builder.rs index a9156e970aad..d779e0172d5a 100644 --- a/core/lib/multivm/src/pubdata_builders/validium.rs +++ b/core/lib/multivm/src/pubdata_builders/hashed_builder.rs @@ -13,17 +13,17 @@ use super::utils::{ use crate::interface::pubdata::{PubdataBuilder, PubdataInput}; #[derive(Debug, Clone, Copy)] -pub struct ValidiumPubdataBuilder { +pub struct HashedPubdataBuilder { pub l2_da_validator: Address, } -impl ValidiumPubdataBuilder { +impl HashedPubdataBuilder { pub fn new(l2_da_validator: Address) -> Self { Self { l2_da_validator } } } -impl PubdataBuilder for ValidiumPubdataBuilder { +impl PubdataBuilder for HashedPubdataBuilder { fn l2_da_validator(&self) -> Address { self.l2_da_validator } @@ -35,7 +35,7 @@ impl PubdataBuilder for ValidiumPubdataBuilder { ) -> Vec { assert!( !protocol_version.is_pre_gateway(), - "ValidiumPubdataBuilder must not be called for pre gateway" + "HashedPubdataBuilder must not be called for pre gateway" ); let mut pubdata = vec![]; @@ -79,7 +79,7 @@ impl PubdataBuilder for ValidiumPubdataBuilder { ) -> Vec { assert!( !protocol_version.is_pre_gateway(), - "ValidiumPubdataBuilder must not be called for pre gateway" + "HashedPubdataBuilder must not be called for pre gateway" ); let state_diffs_packed = input diff --git a/core/lib/multivm/src/pubdata_builders/mod.rs b/core/lib/multivm/src/pubdata_builders/mod.rs index c52c4c70c86a..875a093370f4 100644 --- a/core/lib/multivm/src/pubdata_builders/mod.rs +++ b/core/lib/multivm/src/pubdata_builders/mod.rs @@ -1,24 +1,26 @@ use std::rc::Rc; -pub use rollup::RollupPubdataBuilder; -pub use validium::ValidiumPubdataBuilder; -use zksync_types::commitment::{L1BatchCommitmentMode, PubdataParams}; +pub use full_builder::FullPubdataBuilder; +pub use hashed_builder::HashedPubdataBuilder; +use zksync_types::commitment::{PubdataParams, PubdataType}; use crate::interface::pubdata::PubdataBuilder; -mod rollup; +mod full_builder; +mod hashed_builder; #[cfg(test)] mod tests; mod utils; -mod validium; pub fn pubdata_params_to_builder(params: PubdataParams) -> Rc { match params.pubdata_type { - L1BatchCommitmentMode::Rollup => { - Rc::new(RollupPubdataBuilder::new(params.l2_da_validator_address)) - } - L1BatchCommitmentMode::Validium => { - Rc::new(ValidiumPubdataBuilder::new(params.l2_da_validator_address)) + PubdataType::NoDA => Rc::new(HashedPubdataBuilder::new(params.l2_da_validator_address)), + PubdataType::Rollup + | PubdataType::Avail + | PubdataType::Celestia + | PubdataType::Eigen + | PubdataType::ObjectStore => { + Rc::new(FullPubdataBuilder::new(params.l2_da_validator_address)) } } } diff --git a/core/lib/multivm/src/pubdata_builders/tests.rs b/core/lib/multivm/src/pubdata_builders/tests.rs index b06cb9405aa7..a3894110c8a1 100644 --- a/core/lib/multivm/src/pubdata_builders/tests.rs +++ b/core/lib/multivm/src/pubdata_builders/tests.rs @@ -3,7 +3,7 @@ use zksync_types::{ ACCOUNT_CODE_STORAGE_ADDRESS, BOOTLOADER_ADDRESS, }; -use super::{rollup::RollupPubdataBuilder, validium::ValidiumPubdataBuilder}; +use super::{full_builder::FullPubdataBuilder, hashed_builder::HashedPubdataBuilder}; use crate::interface::pubdata::{L1MessengerL2ToL1Log, PubdataBuilder, PubdataInput}; fn mock_input() -> PubdataInput { @@ -54,13 +54,13 @@ fn mock_input() -> PubdataInput { } #[test] -fn test_rollup_pubdata_building() { +fn test_full_pubdata_building() { let input = mock_input(); - let rollup_pubdata_builder = RollupPubdataBuilder::new(Address::zero()); + let full_pubdata_builder = FullPubdataBuilder::new(Address::zero()); let actual = - rollup_pubdata_builder.l1_messenger_operator_input(&input, ProtocolVersionId::Version24); + full_pubdata_builder.l1_messenger_operator_input(&input, ProtocolVersionId::Version24); let expected = "00000001000000000000000000000000000000000000000000008001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000800000000100000004deadbeef0000000100000060bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0100002a040001000000000000000000000000000000000000000000000000000000000000007e090e0000000c0901000000020000000000000000000000000000000000008002000000000000000000000000000000000000000000000000000000000000009b000000000000000000000000000000000000000000000000000000000000007d000000000000000c000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008002000000000000000000000000000000000000000000000000000000000000009c000000000000000000000000000000000000000000000000000000000000007e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; assert_eq!( &hex::encode(actual), @@ -69,7 +69,7 @@ fn test_rollup_pubdata_building() { ); let actual = - rollup_pubdata_builder.settlement_layer_pubdata(&input, ProtocolVersionId::Version24); + full_pubdata_builder.settlement_layer_pubdata(&input, ProtocolVersionId::Version24); let expected = "00000001000000000000000000000000000000000000000000008001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000800000000100000004deadbeef0000000100000060bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0100002a040001000000000000000000000000000000000000000000000000000000000000007e090e0000000c0901"; assert_eq!( &hex::encode(actual), @@ -78,7 +78,7 @@ fn test_rollup_pubdata_building() { ); let actual = - rollup_pubdata_builder.l1_messenger_operator_input(&input, ProtocolVersionId::Version27); + full_pubdata_builder.l1_messenger_operator_input(&input, ProtocolVersionId::Version27); let expected = "89f9a07233e608561d90f7c4e7bcea24d718e425a6bd6c8eefb48a334366143694c75fae278944d856d68e33bbd32937cb3a1ea35cbf7d6eeeb1150f500dd0d64d0efe420d6dafe5897eab2fc27b2e47af303397ed285ace146d836d042717b0a3dc4b28a603a33b28ce1d5c52c593a46a15a99f1afa1c1d92715284288958fd54a93de700000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000032300000001000000000000000000000000000000000000000000008001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000800000000100000004deadbeef0000000100000060bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0100002a040001000000000000000000000000000000000000000000000000000000000000007e090e0000000c0901000000020000000000000000000000000000000000008002000000000000000000000000000000000000000000000000000000000000009b000000000000000000000000000000000000000000000000000000000000007d000000000000000c000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008002000000000000000000000000000000000000000000000000000000000000009c000000000000000000000000000000000000000000000000000000000000007e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; assert_eq!( &hex::encode(actual), @@ -87,7 +87,7 @@ fn test_rollup_pubdata_building() { ); let actual = - rollup_pubdata_builder.settlement_layer_pubdata(&input, ProtocolVersionId::Version27); + full_pubdata_builder.settlement_layer_pubdata(&input, ProtocolVersionId::Version27); let expected = "00000001000000000000000000000000000000000000000000008001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000800000000100000004deadbeef0000000100000060bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0100002a040001000000000000000000000000000000000000000000000000000000000000007e090e0000000c0901"; assert_eq!( &hex::encode(actual), @@ -97,13 +97,13 @@ fn test_rollup_pubdata_building() { } #[test] -fn test_validium_pubdata_building() { +fn test_hashed_pubdata_building() { let input = mock_input(); - let validium_pubdata_builder = ValidiumPubdataBuilder::new(Address::zero()); + let hashed_pubdata_builder = HashedPubdataBuilder::new(Address::zero()); let actual = - validium_pubdata_builder.l1_messenger_operator_input(&input, ProtocolVersionId::Version27); + hashed_pubdata_builder.l1_messenger_operator_input(&input, ProtocolVersionId::Version27); let expected = "89f9a07233e608561d90f7c4e7bcea24d718e425a6bd6c8eefb48a334366143694c75fae278944d856d68e33bbd32937cb3a1ea35cbf7d6eeeb1150f500dd0d64d0efe420d6dafe5897eab2fc27b2e47af303397ed285ace146d836d042717b0a3dc4b28a603a33b28ce1d5c52c593a46a15a99f1afa1c1d92715284288958fd54a93de700000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000005c000000010000000000000000000000000000000000000000000080010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000008000000000"; assert_eq!( &hex::encode(actual), @@ -112,7 +112,7 @@ fn test_validium_pubdata_building() { ); let actual = - validium_pubdata_builder.settlement_layer_pubdata(&input, ProtocolVersionId::Version27); + hashed_pubdata_builder.settlement_layer_pubdata(&input, ProtocolVersionId::Version27); let expected = "fa96e2436e6fb4d668f5a06681a7c53fcb199b2747ee624ee52a13e85aac5f1e"; assert_eq!( &hex::encode(actual), diff --git a/core/lib/multivm/src/pubdata_builders/utils.rs b/core/lib/multivm/src/pubdata_builders/utils.rs index 83c9b9317640..3b30832b79dd 100644 --- a/core/lib/multivm/src/pubdata_builders/utils.rs +++ b/core/lib/multivm/src/pubdata_builders/utils.rs @@ -1,7 +1,7 @@ use zksync_mini_merkle_tree::MiniMerkleTree; -use zksync_types::{bytecode::BytecodeHash, web3::keccak256}; +use zksync_types::{bytecode::BytecodeHash, web3::keccak256, writes::compress_state_diffs}; -use crate::interface::pubdata::L1MessengerL2ToL1Log; +use crate::interface::pubdata::{L1MessengerL2ToL1Log, PubdataInput}; pub(crate) fn build_chained_log_hash(user_logs: &[L1MessengerL2ToL1Log]) -> Vec { let mut chained_log_hash = vec![0u8; 32]; @@ -68,3 +68,34 @@ pub(crate) fn encode_user_logs(user_logs: &[L1MessengerL2ToL1Log]) -> Vec { } result } + +pub(crate) fn extend_from_pubdata_input(buffer: &mut Vec, pubdata_input: &PubdataInput) { + let PubdataInput { + user_logs, + l2_to_l1_messages, + published_bytecodes, + state_diffs, + } = pubdata_input; + + // Adding user L2->L1 logs. + buffer.extend(encode_user_logs(user_logs)); + + // Encoding L2->L1 messages + // Format: `[(numberOfMessages as u32) || (messages[1].len() as u32) || messages[1] || ... || (messages[n].len() as u32) || messages[n]]` + buffer.extend((l2_to_l1_messages.len() as u32).to_be_bytes()); + for message in l2_to_l1_messages { + buffer.extend((message.len() as u32).to_be_bytes()); + buffer.extend(message); + } + // Encoding bytecodes + // Format: `[(numberOfBytecodes as u32) || (bytecodes[1].len() as u32) || bytecodes[1] || ... || (bytecodes[n].len() as u32) || bytecodes[n]]` + buffer.extend((published_bytecodes.len() as u32).to_be_bytes()); + for bytecode in published_bytecodes { + buffer.extend((bytecode.len() as u32).to_be_bytes()); + buffer.extend(bytecode); + } + // Encoding state diffs + // Format: `[size of compressed state diffs u32 || compressed state diffs || (# state diffs: intial + repeated) as u32 || sorted state diffs by ]` + let state_diffs_compressed = compress_state_diffs(state_diffs.clone()); + buffer.extend(state_diffs_compressed); +} diff --git a/core/lib/multivm/src/versions/testonly/l1_messenger.rs b/core/lib/multivm/src/versions/testonly/l1_messenger.rs index 5d602b1e7d66..dcbc432aafd0 100644 --- a/core/lib/multivm/src/versions/testonly/l1_messenger.rs +++ b/core/lib/multivm/src/versions/testonly/l1_messenger.rs @@ -15,7 +15,7 @@ use crate::{ pubdata::{PubdataBuilder, PubdataInput}, InspectExecutionMode, TxExecutionMode, VmInterfaceExt, }, - pubdata_builders::RollupPubdataBuilder, + pubdata_builders::FullPubdataBuilder, vm_latest::constants::ZK_SYNC_BYTES_PER_BLOB, }; @@ -48,7 +48,7 @@ fn compose_header_for_l1_commit_rollup(input: PubdataInput) -> Vec { let uncompressed_state_diffs_hash = keccak256(&uncompressed_state_diffs); full_header.extend(uncompressed_state_diffs_hash); - let pubdata_builder = RollupPubdataBuilder::new(Address::zero()); + let pubdata_builder = FullPubdataBuilder::new(Address::zero()); let mut full_pubdata = pubdata_builder.settlement_layer_pubdata(&input, ProtocolVersionId::latest()); let full_pubdata_hash = keccak256(&full_pubdata); @@ -127,7 +127,7 @@ pub(crate) fn test_rollup_da_output_hash_match() { let result = vm.vm.execute(InspectExecutionMode::OneTx); assert!(!result.result.is_failed(), "Transaction wasn't successful"); - let pubdata_builder = RollupPubdataBuilder::new(l2_da_validator_address); + let pubdata_builder = FullPubdataBuilder::new(l2_da_validator_address); let batch_result = vm.vm.finish_batch(Rc::new(pubdata_builder)); assert!( !batch_result.block_tip_execution_result.result.is_failed(), diff --git a/core/lib/multivm/src/versions/testonly/mod.rs b/core/lib/multivm/src/versions/testonly/mod.rs index 5ab13df87337..8f24c849272d 100644 --- a/core/lib/multivm/src/versions/testonly/mod.rs +++ b/core/lib/multivm/src/versions/testonly/mod.rs @@ -28,7 +28,7 @@ pub(super) use self::tester::{ validation_params, TestedVm, TestedVmForValidation, VmTester, VmTesterBuilder, }; use crate::{ - interface::storage::InMemoryStorage, pubdata_builders::RollupPubdataBuilder, + interface::storage::InMemoryStorage, pubdata_builders::FullPubdataBuilder, vm_latest::constants::BATCH_COMPUTATIONAL_GAS_LIMIT, }; @@ -123,7 +123,7 @@ pub(super) fn default_l1_batch(number: L1BatchNumber) -> L1BatchEnv { } pub(super) fn default_pubdata_builder() -> Rc { - Rc::new(RollupPubdataBuilder::new(Address::zero())) + Rc::new(FullPubdataBuilder::new(Address::zero())) } pub(super) fn make_address_rich(storage: &mut InMemoryStorage, address: Address) { diff --git a/core/lib/types/src/commitment/mod.rs b/core/lib/types/src/commitment/mod.rs index 786ce03e671d..6d73ad048774 100644 --- a/core/lib/types/src/commitment/mod.rs +++ b/core/lib/types/src/commitment/mod.rs @@ -9,7 +9,7 @@ use std::{collections::HashMap, convert::TryFrom}; use serde::{Deserialize, Serialize}; -pub use zksync_basic_types::commitment::{L1BatchCommitmentMode, PubdataParams}; +pub use zksync_basic_types::commitment::{L1BatchCommitmentMode, PubdataParams, PubdataType}; use zksync_contracts::BaseSystemContractsHashes; use zksync_crypto_primitives::hasher::{keccak::KeccakHasher, Hasher}; use zksync_mini_merkle_tree::MiniMerkleTree; diff --git a/core/lib/vm_executor/src/storage.rs b/core/lib/vm_executor/src/storage.rs index e5a2d404233b..96b0d60ed122 100644 --- a/core/lib/vm_executor/src/storage.rs +++ b/core/lib/vm_executor/src/storage.rs @@ -3,13 +3,13 @@ use std::time::{Duration, Instant}; use anyhow::Context; -use zksync_contracts::BaseSystemContracts; +use zksync_contracts::{BaseSystemContracts, SystemContractCode}; use zksync_dal::{Connection, Core, CoreDal, DalError}; use zksync_multivm::interface::{L1BatchEnv, L2BlockEnv, SystemEnv, TxExecutionMode}; use zksync_types::{ - block::L2BlockHeader, commitment::PubdataParams, fee_model::BatchFeeInput, - snapshots::SnapshotRecoveryStatus, Address, L1BatchNumber, L2BlockNumber, L2ChainId, - ProtocolVersionId, H256, ZKPORTER_IS_AVAILABLE, + block::L2BlockHeader, bytecode::BytecodeHash, commitment::PubdataParams, + fee_model::BatchFeeInput, snapshots::SnapshotRecoveryStatus, Address, L1BatchNumber, + L2BlockNumber, L2ChainId, ProtocolVersionId, H256, ZKPORTER_IS_AVAILABLE, }; const BATCH_COMPUTATIONAL_GAS_LIMIT: u32 = u32::MAX; @@ -308,15 +308,15 @@ impl L1BatchParamsProvider { ); let contract_hashes = first_l2_block_in_batch.header.base_system_contracts_hashes; - let base_system_contracts = storage - .factory_deps_dal() - .get_base_system_contracts( - contract_hashes.bootloader, - contract_hashes.default_aa, - contract_hashes.evm_emulator, - ) - .await - .context("failed getting base system contracts")?; + let base_system_contracts = get_base_system_contracts( + storage, + first_l2_block_in_batch.header.protocol_version, + contract_hashes.bootloader, + contract_hashes.default_aa, + contract_hashes.evm_emulator, + ) + .await + .context("failed getting base system contracts")?; let (system_env, l1_batch_env) = l1_batch_params( first_l2_block_in_batch.l1_batch_number, @@ -373,3 +373,96 @@ impl L1BatchParamsProvider { .map(Some) } } + +async fn get_base_system_contracts( + storage: &mut Connection<'_, Core>, + protocol_version: Option, + bootloader_hash: H256, + default_aa_hash: H256, + evm_simulator_hash: Option, +) -> anyhow::Result { + // There are two potential sources of base contracts bytecode: + // - Factory deps table in case the upgrade transaction has been executed before. + // - Factory deps of the upgrade transaction. + + // Firstly trying from factory deps + if let Some(deps) = storage + .factory_deps_dal() + .get_base_system_contracts_from_factory_deps( + bootloader_hash, + default_aa_hash, + evm_simulator_hash, + ) + .await? + { + return Ok(deps); + } + + let protocol_version = protocol_version.context("Protocol version not provided")?; + + let upgrade_tx = storage + .protocol_versions_dal() + .get_protocol_upgrade_tx(protocol_version) + .await? + .with_context(|| { + format!("Could not find base contracts for version {protocol_version:?}: bootloader {bootloader_hash:?} or {default_aa_hash:?}") + })?; + + anyhow::ensure!( + upgrade_tx.execute.factory_deps.len() >= 2, + "Upgrade transaction does not have enough factory deps" + ); + + let bootloader_preimage = upgrade_tx.execute.factory_deps[0].clone(); + let default_aa_preimage = upgrade_tx.execute.factory_deps[1].clone(); + + anyhow::ensure!( + BytecodeHash::for_bytecode(&bootloader_preimage).value() == bootloader_hash, + "Bootloader hash mismatch" + ); + anyhow::ensure!( + BytecodeHash::for_bytecode(&default_aa_preimage).value() == default_aa_hash, + "Default account hash mismatch" + ); + + if evm_simulator_hash.is_some() { + // TODO(EVM-933): support EVM emulator. + panic!("EVM simulator not supported as part of gateway upgrade"); + } + + Ok(BaseSystemContracts { + bootloader: SystemContractCode { + code: bootloader_preimage, + hash: bootloader_hash, + }, + default_aa: SystemContractCode { + code: default_aa_preimage, + hash: default_aa_hash, + }, + evm_emulator: None, + }) +} + +pub async fn get_base_system_contracts_by_version_id( + storage: &mut Connection<'_, Core>, + version_id: ProtocolVersionId, +) -> anyhow::Result> { + let hashes = storage + .protocol_versions_dal() + .get_base_system_contract_hashes_by_version_id(version_id) + .await?; + let Some(hashes) = hashes else { + return Ok(None); + }; + + Ok(Some( + get_base_system_contracts( + storage, + Some(version_id), + hashes.bootloader, + hashes.default_aa, + hashes.evm_emulator, + ) + .await?, + )) +} diff --git a/core/node/consistency_checker/src/lib.rs b/core/node/consistency_checker/src/lib.rs index a73adc44b83e..f7d904955789 100644 --- a/core/node/consistency_checker/src/lib.rs +++ b/core/node/consistency_checker/src/lib.rs @@ -14,12 +14,9 @@ use zksync_eth_client::{ }; use zksync_health_check::{Health, HealthStatus, HealthUpdater, ReactiveHealthCheck}; use zksync_l1_contract_interface::{ - i_executor::{ - commit::kzg::ZK_SYNC_BYTES_PER_BLOB, - structures::{ - CommitBatchInfo, StoredBatchInfo, PUBDATA_SOURCE_BLOBS, PUBDATA_SOURCE_CALLDATA, - PUBDATA_SOURCE_CUSTOM_PRE_GATEWAY, SUPPORTED_ENCODING_VERSION, - }, + i_executor::structures::{ + CommitBatchInfo, StoredBatchInfo, PUBDATA_SOURCE_BLOBS, PUBDATA_SOURCE_CALLDATA, + PUBDATA_SOURCE_CUSTOM_PRE_GATEWAY, SUPPORTED_ENCODING_VERSION, }, Tokenizable, }; @@ -231,31 +228,19 @@ impl LocalL1BatchCommitData { } /// All returned errors are validation errors. - fn verify_commitment(&self, reference: ðabi::Token) -> anyhow::Result<()> { + fn verify_commitment(&self, reference: ðabi::Token, is_gateway: bool) -> anyhow::Result<()> { let protocol_version = self .l1_batch .header .protocol_version .unwrap_or_else(ProtocolVersionId::last_potentially_undefined); - let da = detect_da(protocol_version, reference, self.commitment_mode) - .context("cannot detect DA source from reference commitment token")?; - - // For rollups with `PubdataSendingMode::Calldata`, it's required that the pubdata fits into a single blob. - if matches!(self.commitment_mode, L1BatchCommitmentMode::Rollup) - && matches!(da, PubdataSendingMode::Calldata) - { - let pubdata_len = self - .l1_batch - .header - .pubdata_input - .as_ref() - .map_or_else(|| self.l1_batch.construct_pubdata().len(), Vec::len); - anyhow::ensure!( - pubdata_len <= ZK_SYNC_BYTES_PER_BLOB, - "pubdata size is too large when using calldata DA source: expected <={ZK_SYNC_BYTES_PER_BLOB} bytes, \ - got {pubdata_len} bytes" - ); - } + let da = detect_da( + protocol_version, + reference, + self.commitment_mode, + is_gateway, + ) + .context("cannot detect DA source from reference commitment token")?; let local_token = CommitBatchInfo::new(self.commitment_mode, &self.l1_batch, da).into_token(); @@ -278,6 +263,7 @@ pub fn detect_da( protocol_version: ProtocolVersionId, reference: &Token, commitment_mode: L1BatchCommitmentMode, + is_gateway: bool, ) -> Result { fn parse_error(message: impl Into>) -> ethabi::Error { ethabi::Error::Other(message.into()) @@ -351,7 +337,11 @@ pub fn detect_da( })? as usize; match last_reference_token.get(65 + 32 * number_of_blobs) { - Some(&byte) if byte == PUBDATA_SOURCE_CALLDATA => Ok(PubdataSendingMode::Calldata), + Some(&byte) if byte == PUBDATA_SOURCE_CALLDATA => if is_gateway { + Ok(PubdataSendingMode::RelayedL2Calldata) + } else { + Ok(PubdataSendingMode::Calldata) + }, Some(&byte) if byte == PUBDATA_SOURCE_BLOBS => Ok(PubdataSendingMode::Blobs), Some(&byte) => Err(parse_error(format!( "unexpected first byte of the last reference token for rollup; expected one of [{PUBDATA_SOURCE_CALLDATA}, {PUBDATA_SOURCE_BLOBS}], \ @@ -565,8 +555,10 @@ impl ConsistencyChecker { format!("failed extracting commit data for transaction {commit_tx_hash:?}") }) .map_err(CheckError::Validation)?; + + let is_gateway = chain_data.chain_id != self.l1_chain_data.chain_id; local - .verify_commitment(&commitment) + .verify_commitment(&commitment, is_gateway) .map_err(CheckError::Validation) } diff --git a/core/node/eth_watch/src/event_processors/appended_chain_batch_root.rs b/core/node/eth_watch/src/event_processors/appended_chain_batch_root.rs index 68f731120c65..158d800d1ec3 100644 --- a/core/node/eth_watch/src/event_processors/appended_chain_batch_root.rs +++ b/core/node/eth_watch/src/event_processors/appended_chain_batch_root.rs @@ -226,6 +226,9 @@ impl BatchRootProcessor { metadata[0] = LOG_PROOF_SUPPORTED_METADATA_VERSION; metadata[1] = chain_agg_proof.chain_id_leaf_proof.len() as u8; + // Chain proofs are always final nodes in the proofs. + metadata[3] = 1; + let mut chain_proof_vector = vec![ u256_to_h256(sl_encoded_data), H256::from_low_u64_be(sl_chain_id.0), diff --git a/core/node/eth_watch/src/tests/mod.rs b/core/node/eth_watch/src/tests/mod.rs index 0b34a34ab63f..4687dac4499b 100644 --- a/core/node/eth_watch/src/tests/mod.rs +++ b/core/node/eth_watch/src/tests/mod.rs @@ -481,7 +481,7 @@ async fn test_batch_root_processor_from_genesis() { .unwrap() .unwrap(); let proof1 = hex::encode(bincode::serialize(&proof1).unwrap()); - assert_eq!(proof1, "000000000600000000000000420000000000000030783030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303030303030303030303030303030303030303030303030303030303030303530303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307833373561356266393039636230323134336533363935636136353865303634316537333961613539306630303034646261393335373263343463646239643264"); + assert_eq!(proof1, "000000000600000000000000420000000000000030783030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303030303030303030303030303030303030303030303030303030303030303530303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303031303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307833373561356266393039636230323134336533363935636136353865303634316537333961613539306630303034646261393335373263343463646239643264"); sl_client.set_last_finalized_block_number(11).await; watcher.loop_iteration(&mut connection).await.unwrap(); @@ -493,7 +493,7 @@ async fn test_batch_root_processor_from_genesis() { .unwrap() .unwrap(); let proof2 = hex::encode(bincode::serialize(&proof2).unwrap()); - assert_eq!(proof2, "0100000007000000000000004200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303031420000000000000030783130613265663736653730396433313862343539626534396631653864376630326437313230663262353031626330616664646439333566316138313363363742000000000000003078303030303030303030303030303030303030303030303030303030303030303930303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307861333738613230636132376237616533303731643162643763326164613030343639616263353765343239646436663438613833303932646237303539613138"); + assert_eq!(proof2, "0100000007000000000000004200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303031420000000000000030783130613265663736653730396433313862343539626534396631653864376630326437313230663262353031626330616664646439333566316138313363363742000000000000003078303030303030303030303030303030303030303030303030303030303030303930303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303031303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307861333738613230636132376237616533303731643162643763326164613030343639616263353765343239646436663438613833303932646237303539613138"); let proof3 = connection .blocks_dal() @@ -502,7 +502,7 @@ async fn test_batch_root_processor_from_genesis() { .unwrap() .unwrap(); let proof3 = hex::encode(bincode::serialize(&proof3).unwrap()); - assert_eq!(proof3, "02000000080000000000000042000000000000003078303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030324200000000000000307834363730306234643430616335633335616632633232646461323738376139316562353637623036633932346138666238616539613035623230633038633231420000000000000030786530633333333066363734623662326435373866393538613164626436366631363464303638623062623561396662303737656361303133393736666461366642000000000000003078303030303030303030303030303030303030303030303030303030303030306230303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307833373561356266393039636230323134336533363935636136353865303634316537333961613539306630303034646261393335373263343463646239643264"); + assert_eq!(proof3, "02000000080000000000000042000000000000003078303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030324200000000000000307834363730306234643430616335633335616632633232646461323738376139316562353637623036633932346138666238616539613035623230633038633231420000000000000030786530633333333066363734623662326435373866393538613164626436366631363464303638623062623561396662303737656361303133393736666461366642000000000000003078303030303030303030303030303030303030303030303030303030303030306230303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303031303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307833373561356266393039636230323134336533363935636136353865303634316537333961613539306630303034646261393335373263343463646239643264"); } #[test_log::test(tokio::test)] @@ -568,7 +568,7 @@ async fn test_batch_root_processor_restart() { .unwrap() .unwrap(); let proof = hex::encode(bincode::serialize(&proof).unwrap()); - assert_eq!(proof, "02000000080000000000000042000000000000003078303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030324200000000000000307834363730306234643430616335633335616632633232646461323738376139316562353637623036633932346138666238616539613035623230633038633231420000000000000030786530633333333066363734623662326435373866393538613164626436366631363464303638623062623561396662303737656361303133393736666461366642000000000000003078303030303030303030303030303030303030303030303030303030303030306230303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307833373561356266393039636230323134336533363935636136353865303634316537333961613539306630303034646261393335373263343463646239643264"); + assert_eq!(proof, "02000000080000000000000042000000000000003078303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030324200000000000000307834363730306234643430616335633335616632633232646461323738376139316562353637623036633932346138666238616539613035623230633038633231420000000000000030786530633333333066363734623662326435373866393538613164626436366631363464303638623062623561396662303737656361303133393736666461366642000000000000003078303030303030303030303030303030303030303030303030303030303030306230303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303031303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307833373561356266393039636230323134336533363935636136353865303634316537333961613539306630303034646261393335373263343463646239643264"); let proof = connection .blocks_dal() @@ -577,7 +577,7 @@ async fn test_batch_root_processor_restart() { .unwrap() .unwrap(); let proof = hex::encode(bincode::serialize(&proof).unwrap()); - assert_eq!(proof, "02000000080000000000000042000000000000003078303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030334200000000000000307837623765373735373139343639366666393634616233353837393131373362636337663735356132656161393334653935373061636533393139383435313265420000000000000030786530633333333066363734623662326435373866393538613164626436366631363464303638623062623561396662303737656361303133393736666461366642000000000000003078303030303030303030303030303030303030303030303030303030303030306430303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307835353063313735316338653764626166633839303939326634353532333636663064643565623665343362653535353936386264616338633732656466316261"); + assert_eq!(proof, "02000000080000000000000042000000000000003078303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030334200000000000000307837623765373735373139343639366666393634616233353837393131373362636337663735356132656161393334653935373061636533393139383435313265420000000000000030786530633333333066363734623662326435373866393538613164626436366631363464303638623062623561396662303737656361303133393736666461366642000000000000003078303030303030303030303030303030303030303030303030303030303030306430303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303031303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307835353063313735316338653764626166633839303939326634353532333636663064643565623665343362653535353936386264616338633732656466316261"); let proof = connection .blocks_dal() @@ -586,7 +586,7 @@ async fn test_batch_root_processor_restart() { .unwrap() .unwrap(); let proof = hex::encode(bincode::serialize(&proof).unwrap()); - assert_eq!(proof, "030000000900000000000000420000000000000030783030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303442000000000000003078303235663065363031353230366661626364326263613930316432633438396536336263356564346231356266356330633963363066396531363735383564614200000000000000307863633463343165646230633230333133343862323932623736386539626163316565386339326330396566386133323737633265636534303963313264383661420000000000000030783533656463316635616437396335393939626435373864666331333566396335316562643766616661343538356236346637316431356232646365316237323842000000000000003078303030303030303030303030303030303030303030303030303030303030306530303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307833373561356266393039636230323134336533363935636136353865303634316537333961613539306630303034646261393335373263343463646239643264"); + assert_eq!(proof, "030000000900000000000000420000000000000030783030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303442000000000000003078303235663065363031353230366661626364326263613930316432633438396536336263356564346231356266356330633963363066396531363735383564614200000000000000307863633463343165646230633230333133343862323932623736386539626163316565386339326330396566386133323737633265636534303963313264383661420000000000000030783533656463316635616437396335393939626435373864666331333566396335316562643766616661343538356236346637316431356232646365316237323842000000000000003078303030303030303030303030303030303030303030303030303030303030306530303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303031303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307833373561356266393039636230323134336533363935636136353865303634316537333961613539306630303034646261393335373263343463646239643264"); let proof = connection .blocks_dal() @@ -595,7 +595,7 @@ async fn test_batch_root_processor_restart() { .unwrap() .unwrap(); let proof = hex::encode(bincode::serialize(&proof).unwrap()); - assert_eq!(proof, "030000000900000000000000420000000000000030783030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303542000000000000003078323465653435363834376535373364313635613832333634306632303834383139636331613865333433316562633635633865363064333435343266313637324200000000000000307863633463343165646230633230333133343862323932623736386539626163316565386339326330396566386133323737633265636534303963313264383661420000000000000030783533656463316635616437396335393939626435373864666331333566396335316562643766616661343538356236346637316431356232646365316237323842000000000000003078303030303030303030303030303030303030303030303030303030303030306530303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307833373561356266393039636230323134336533363935636136353865303634316537333961613539306630303034646261393335373263343463646239643264"); + assert_eq!(proof, "030000000900000000000000420000000000000030783030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303542000000000000003078323465653435363834376535373364313635613832333634306632303834383139636331613865333433316562633635633865363064333435343266313637324200000000000000307863633463343165646230633230333133343862323932623736386539626163316565386339326330396566386133323737633265636534303963313264383661420000000000000030783533656463316635616437396335393939626435373864666331333566396335316562643766616661343538356236346637316431356232646365316237323842000000000000003078303030303030303030303030303030303030303030303030303030303030306530303030303030303030303030303030303030303030303030303030303030334200000000000000307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030316639420000000000000030783031303230303031303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303042000000000000003078303932343932386331333737613663663234633339633264343666386562396466323365383131623236646333353237653534383339366664346531373362314200000000000000307833373561356266393039636230323134336533363935636136353865303634316537333961613539306630303034646261393335373263343463646239643264"); } async fn get_all_db_txs(storage: &mut Connection<'_, Core>) -> Vec { diff --git a/core/node/metadata_calculator/src/api_server/tests.rs b/core/node/metadata_calculator/src/api_server/tests.rs index 9bb994cb4163..483236c3bc9b 100644 --- a/core/node/metadata_calculator/src/api_server/tests.rs +++ b/core/node/metadata_calculator/src/api_server/tests.rs @@ -131,11 +131,13 @@ fn assert_raw_nodes_response(response: &serde_json::Value) { assert_matches!(key, b'0'..=b'9' | b'a'..=b'f'); } - let node = response["0:0"].as_object().expect("not an object"); - assert!( - node.len() == 2 && node.contains_key("internal") && node.contains_key("raw"), - "{node:#?}" - ); + if let Some(value) = response.get("0:0") { + let node = value.as_object().expect("not an object"); + assert!( + node.len() == 2 && node.contains_key("internal") && node.contains_key("raw"), + "{node:#?}" + ); + } } fn assert_raw_stale_keys_response(response: &serde_json::Value) { diff --git a/core/node/node_framework/src/implementations/layers/state_keeper/mempool_io.rs b/core/node/node_framework/src/implementations/layers/state_keeper/mempool_io.rs index 77992f34c7f5..79eb233041a6 100644 --- a/core/node/node_framework/src/implementations/layers/state_keeper/mempool_io.rs +++ b/core/node/node_framework/src/implementations/layers/state_keeper/mempool_io.rs @@ -4,7 +4,7 @@ use zksync_config::configs::{ wallets, }; use zksync_state_keeper::{MempoolFetcher, MempoolGuard, MempoolIO, SequencerSealer}; -use zksync_types::{commitment::L1BatchCommitmentMode, Address, L2ChainId}; +use zksync_types::{commitment::PubdataType, Address, L2ChainId}; use crate::{ implementations::resources::{ @@ -40,7 +40,7 @@ pub struct MempoolIOLayer { mempool_config: MempoolConfig, wallets: wallets::StateKeeper, l2_da_validator_addr: Option
, - l1_batch_commit_data_generator_mode: L1BatchCommitmentMode, + pubdata_type: PubdataType, } #[derive(Debug, FromContext)] @@ -66,7 +66,7 @@ impl MempoolIOLayer { mempool_config: MempoolConfig, wallets: wallets::StateKeeper, l2_da_validator_addr: Option
, - l1_batch_commit_data_generator_mode: L1BatchCommitmentMode, + pubdata_type: PubdataType, ) -> Self { Self { zksync_network_id, @@ -74,7 +74,7 @@ impl MempoolIOLayer { mempool_config, wallets, l2_da_validator_addr, - l1_batch_commit_data_generator_mode, + pubdata_type, } } @@ -136,7 +136,7 @@ impl WiringLayer for MempoolIOLayer { self.mempool_config.delay_interval(), self.zksync_network_id, self.l2_da_validator_addr, - self.l1_batch_commit_data_generator_mode, + self.pubdata_type, )?; // Create sealer. diff --git a/core/node/node_sync/src/external_io.rs b/core/node/node_sync/src/external_io.rs index d3d908cfc169..eb79965fa28b 100644 --- a/core/node/node_sync/src/external_io.rs +++ b/core/node/node_sync/src/external_io.rs @@ -113,7 +113,7 @@ impl ExternalIO { .connection_tagged("sync_layer") .await? .protocol_versions_dal() - .get_base_system_contract_hashes_by_version_id(protocol_version as u16) + .get_base_system_contract_hashes_by_version_id(protocol_version) .await?; if base_system_contract_hashes.is_some() { return Ok(()); @@ -410,7 +410,7 @@ impl StateKeeperIO for ExternalIO { .connection_tagged("sync_layer") .await? .protocol_versions_dal() - .get_base_system_contract_hashes_by_version_id(protocol_version as u16) + .get_base_system_contract_hashes_by_version_id(protocol_version) .await? .with_context(|| { format!("Cannot load base system contracts' hashes for {protocol_version:?}. They should already be present") diff --git a/core/node/state_keeper/src/io/mempool.rs b/core/node/state_keeper/src/io/mempool.rs index cf354891236b..f553fcb57a08 100644 --- a/core/node/state_keeper/src/io/mempool.rs +++ b/core/node/state_keeper/src/io/mempool.rs @@ -15,12 +15,12 @@ use zksync_multivm::{interface::Halt, utils::derive_base_fee_and_gas_per_pubdata use zksync_node_fee_model::BatchFeeModelInputProvider; use zksync_types::{ block::UnsealedL1BatchHeader, - commitment::{L1BatchCommitmentMode, PubdataParams}, + commitment::{PubdataParams, PubdataType}, protocol_upgrade::ProtocolUpgradeTx, utils::display_timestamp, Address, L1BatchNumber, L2BlockNumber, L2ChainId, ProtocolVersionId, Transaction, H256, U256, }; -use zksync_vm_executor::storage::L1BatchParamsProvider; +use zksync_vm_executor::storage::{get_base_system_contracts_by_version_id, L1BatchParamsProvider}; use crate::{ io::{ @@ -58,7 +58,7 @@ pub struct MempoolIO { batch_fee_input_provider: Arc, chain_id: L2ChainId, l2_da_validator_address: Option
, - pubdata_type: L1BatchCommitmentMode, + pubdata_type: PubdataType, } impl IoSealCriteria for MempoolIO { @@ -382,18 +382,15 @@ impl StateKeeperIO for MempoolIO { protocol_version: ProtocolVersionId, _cursor: &IoCursor, ) -> anyhow::Result { - self.pool - .connection_tagged("state_keeper") - .await? - .protocol_versions_dal() - .load_base_system_contracts_by_version_id(protocol_version as u16) - .await - .context("failed loading base system contracts")? - .with_context(|| { - format!( - "no base system contracts persisted for protocol version {protocol_version:?}" - ) - }) + get_base_system_contracts_by_version_id( + &mut self.pool.connection_tagged("state_keeper").await?, + protocol_version, + ) + .await + .context("failed loading base system contracts")? + .with_context(|| { + format!("no base system contracts persisted for protocol version {protocol_version:?}") + }) } async fn load_batch_version_id( @@ -497,7 +494,7 @@ impl MempoolIO { delay_interval: Duration, chain_id: L2ChainId, l2_da_validator_address: Option
, - pubdata_type: L1BatchCommitmentMode, + pubdata_type: PubdataType, ) -> anyhow::Result { Ok(Self { mempool,