From d26261d8e5bb3fb819e16a1fbe420ca6c7d4cc4a Mon Sep 17 00:00:00 2001 From: perekopskiy Date: Fri, 27 Sep 2024 13:26:31 +0300 Subject: [PATCH 01/10] fmt --- core/bin/external_node/src/config/mod.rs | 20 +---- core/bin/external_node/src/node_builder.rs | 13 +-- core/bin/zksync_server/src/node_builder.rs | 10 +-- core/lib/config/src/configs/contracts.rs | 4 - core/lib/config/src/testonly.rs | 2 - core/lib/dal/src/consensus/mod.rs | 49 ++++++------ core/lib/dal/src/consensus/proto/mod.proto | 2 +- core/lib/dal/src/consensus/tests.rs | 4 +- core/lib/dal/src/models/storage_sync.rs | 4 +- core/lib/env_config/src/contracts.rs | 5 -- core/lib/protobuf_config/src/contracts.rs | 18 ----- .../src/proto/config/contracts.proto | 4 +- core/lib/types/src/api/en.rs | 2 +- core/lib/types/src/api/mod.rs | 1 + core/lib/web3_decl/src/namespaces/zks.rs | 6 -- .../web3/backend_jsonrpsee/namespaces/zks.rs | 12 +-- .../api_server/src/web3/namespaces/zks.rs | 20 ++--- core/node/api_server/src/web3/state.rs | 5 +- core/node/consensus/src/storage/store.rs | 2 +- core/node/consensus/src/testonly.rs | 8 +- .../layers/state_keeper/output_handler.rs | 12 +-- core/node/node_sync/src/fetcher.rs | 2 +- core/node/node_sync/src/tests.rs | 9 +-- core/node/state_keeper/src/io/mempool.rs | 9 ++- core/node/state_keeper/src/io/persistence.rs | 80 ++++--------------- .../io/seal_logic/l2_block_seal_subtasks.rs | 13 ++- .../state_keeper/src/io/seal_logic/mod.rs | 6 +- core/node/state_keeper/src/io/tests/mod.rs | 17 +--- core/node/state_keeper/src/updates/mod.rs | 10 +-- 29 files changed, 98 insertions(+), 251 deletions(-) diff --git a/core/bin/external_node/src/config/mod.rs b/core/bin/external_node/src/config/mod.rs index 821df0a06de..dad2f3a87f6 100644 --- a/core/bin/external_node/src/config/mod.rs +++ b/core/bin/external_node/src/config/mod.rs @@ -111,7 +111,7 @@ pub(crate) struct RemoteENConfig { // a different name, with names adapted only for consistency. pub l1_shared_bridge_proxy_addr: Option
, pub l2_shared_bridge_addr: Option
, - pub l2_legacy_shared_bridge_addr: Option
, + pub l2_token_deployer_addr: Option
, pub l1_erc20_bridge_proxy_addr: Option
, pub l2_erc20_bridge_addr: Option
, pub l1_weth_bridge_addr: Option
, @@ -122,7 +122,6 @@ pub(crate) struct RemoteENConfig { pub dummy_verifier: bool, pub user_facing_bridgehub: Option
, - pub l2_native_token_vault_proxy_addr: Option
, } impl RemoteENConfig { @@ -135,14 +134,6 @@ impl RemoteENConfig { .get_testnet_paymaster() .rpc_context("get_testnet_paymaster") .await?; - let l2_native_token_vault_proxy_addr = client - .get_native_token_vault_proxy_addr() - .rpc_context("get_native_token_vault") - .await?; - let l2_legacy_shared_bridge_addr = client - .get_legacy_shared_bridge() - .rpc_context("get_legacy_shared_bridge") - .await?; let genesis = client.genesis_config().rpc_context("genesis").await.ok(); let ecosystem_contracts = client .get_ecosystem_contracts() @@ -208,7 +199,7 @@ impl RemoteENConfig { l2_erc20_bridge_addr: l2_erc20_default_bridge, l1_shared_bridge_proxy_addr: bridges.l1_shared_default_bridge, l2_shared_bridge_addr: l2_erc20_shared_bridge, - l2_legacy_shared_bridge_addr, + l2_token_deployer_addr: bridges.l2_token_deployer, l1_weth_bridge_addr: bridges.l1_weth_bridge, l2_weth_bridge_addr: bridges.l2_weth_bridge, base_token_addr, @@ -220,7 +211,6 @@ impl RemoteENConfig { .as_ref() .map(|a| a.dummy_verifier) .unwrap_or_default(), - l2_native_token_vault_proxy_addr, }) } @@ -240,10 +230,9 @@ impl RemoteENConfig { l1_shared_bridge_proxy_addr: Some(Address::repeat_byte(5)), l1_weth_bridge_addr: None, l2_shared_bridge_addr: Some(Address::repeat_byte(6)), - l2_legacy_shared_bridge_addr: Some(Address::repeat_byte(7)), + l2_token_deployer_addr: Some(Address::repeat_byte(6)), l1_batch_commit_data_generator_mode: L1BatchCommitmentMode::Rollup, dummy_verifier: true, - l2_native_token_vault_proxy_addr: Some(Address::repeat_byte(7)), } } } @@ -1417,6 +1406,7 @@ impl From<&ExternalNodeConfig> for InternalApiConfig { l2_shared_default_bridge: config.remote.l2_shared_bridge_addr, l1_weth_bridge: config.remote.l1_weth_bridge_addr, l2_weth_bridge: config.remote.l2_weth_bridge_addr, + l2_token_deployer: config.remote.l2_token_deployer_addr, }, bridgehub_proxy_addr: config.remote.bridgehub_proxy_addr, state_transition_proxy_addr: config.remote.state_transition_proxy_addr, @@ -1430,8 +1420,6 @@ impl From<&ExternalNodeConfig> for InternalApiConfig { filters_disabled: config.optional.filters_disabled, dummy_verifier: config.remote.dummy_verifier, l1_batch_commit_data_generator_mode: config.remote.l1_batch_commit_data_generator_mode, - l2_native_token_vault_proxy_addr: config.remote.l2_native_token_vault_proxy_addr, - l2_legacy_shared_bridge_addr: config.remote.l2_legacy_shared_bridge_addr, } } } diff --git a/core/bin/external_node/src/node_builder.rs b/core/bin/external_node/src/node_builder.rs index 70912552d93..4a5c143b275 100644 --- a/core/bin/external_node/src/node_builder.rs +++ b/core/bin/external_node/src/node_builder.rs @@ -192,18 +192,7 @@ impl ExternalNodeBuilder { const OPTIONAL_BYTECODE_COMPRESSION: bool = true; let persistence_layer = OutputHandlerLayer::new( - self.config - .remote - .l2_shared_bridge_addr - .expect("L2 shared bridge address is not set"), - self.config - .remote - .l2_native_token_vault_proxy_addr - .expect("L2 native token vault proxy address is not set"), - self.config - .remote - .l2_legacy_shared_bridge_addr - .expect("L2 legacy shared bridge address is not set"), + self.config.remote.l2_token_deployer_addr, self.config.optional.l2_block_seal_queue_capacity, ) .with_pre_insert_txs(true) // EN requires txs to be pre-inserted. diff --git a/core/bin/zksync_server/src/node_builder.rs b/core/bin/zksync_server/src/node_builder.rs index 763fd600e6f..01eea137b57 100644 --- a/core/bin/zksync_server/src/node_builder.rs +++ b/core/bin/zksync_server/src/node_builder.rs @@ -240,15 +240,7 @@ impl MainNodeBuilder { let wallets = self.wallets.clone(); let sk_config = try_load_config!(self.configs.state_keeper_config); let persistence_layer = OutputHandlerLayer::new( - self.contracts_config - .l2_shared_bridge_addr - .context("L2 shared bridge address")?, - self.contracts_config - .l2_native_token_vault_proxy_addr - .context("L2 native token vault proxy address")?, - self.contracts_config - .l2_legacy_shared_bridge_addr - .context("L2 legacy shared bridge address")?, + self.contracts_config.l2_shared_bridge_addr, sk_config.l2_block_seal_queue_capacity, ) .with_protective_reads_persistence_enabled(sk_config.protective_reads_persistence_enabled); diff --git a/core/lib/config/src/configs/contracts.rs b/core/lib/config/src/configs/contracts.rs index bf88c100cce..d96983c9719 100644 --- a/core/lib/config/src/configs/contracts.rs +++ b/core/lib/config/src/configs/contracts.rs @@ -30,7 +30,6 @@ pub struct ContractsConfig { pub validator_timelock_addr: Address, pub l1_shared_bridge_proxy_addr: Option
, pub l2_shared_bridge_addr: Option
, - pub l2_legacy_shared_bridge_addr: Option
, pub l1_erc20_bridge_proxy_addr: Option
, pub l2_erc20_bridge_addr: Option
, pub l1_weth_bridge_proxy_addr: Option
, @@ -44,7 +43,6 @@ pub struct ContractsConfig { // FIXME: maybe refactor pub user_facing_bridgehub_proxy_addr: Option
, pub user_facing_diamond_proxy_addr: Option
, - pub l2_native_token_vault_proxy_addr: Option
, pub l2_da_validator_addr: Option
, @@ -62,7 +60,6 @@ impl ContractsConfig { l2_erc20_bridge_addr: Some(Address::repeat_byte(0x0c)), l1_shared_bridge_proxy_addr: Some(Address::repeat_byte(0x0e)), l2_shared_bridge_addr: Some(Address::repeat_byte(0x0f)), - l2_legacy_shared_bridge_addr: Some(Address::repeat_byte(0x10)), l1_weth_bridge_proxy_addr: Some(Address::repeat_byte(0x0b)), l2_weth_bridge_addr: Some(Address::repeat_byte(0x0c)), l2_testnet_paymaster_addr: Some(Address::repeat_byte(0x11)), @@ -72,7 +69,6 @@ impl ContractsConfig { ecosystem_contracts: Some(EcosystemContracts::for_tests()), user_facing_bridgehub_proxy_addr: Some(Address::repeat_byte(0x15)), user_facing_diamond_proxy_addr: Some(Address::repeat_byte(0x16)), - l2_native_token_vault_proxy_addr: Some(Address::repeat_byte(0x0d)), chain_admin_addr: Some(Address::repeat_byte(0x18)), l2_da_validator_addr: Some(Address::repeat_byte(0x19)), } diff --git a/core/lib/config/src/testonly.rs b/core/lib/config/src/testonly.rs index f8a1105fe70..b8ad2bc8cd2 100644 --- a/core/lib/config/src/testonly.rs +++ b/core/lib/config/src/testonly.rs @@ -252,7 +252,6 @@ impl Distribution for EncodeDist { l2_erc20_bridge_addr: self.sample_opt(|| rng.gen()), l1_shared_bridge_proxy_addr: self.sample_opt(|| rng.gen()), l2_shared_bridge_addr: self.sample_opt(|| rng.gen()), - l2_legacy_shared_bridge_addr: self.sample_opt(|| rng.gen()), l1_weth_bridge_proxy_addr: self.sample_opt(|| rng.gen()), l2_weth_bridge_addr: self.sample_opt(|| rng.gen()), l2_testnet_paymaster_addr: self.sample_opt(|| rng.gen()), @@ -260,7 +259,6 @@ impl Distribution for EncodeDist { ecosystem_contracts: self.sample(rng), user_facing_bridgehub_proxy_addr: rng.gen(), user_facing_diamond_proxy_addr: rng.gen(), - l2_native_token_vault_proxy_addr: rng.gen(), l2_da_validator_addr: rng.gen(), base_token_addr: self.sample_opt(|| rng.gen()), chain_admin_addr: self.sample_opt(|| rng.gen()), diff --git a/core/lib/dal/src/consensus/mod.rs b/core/lib/dal/src/consensus/mod.rs index 763c13cc387..2a2df0adb45 100644 --- a/core/lib/dal/src/consensus/mod.rs +++ b/core/lib/dal/src/consensus/mod.rs @@ -142,7 +142,7 @@ pub struct Payload { pub fair_pubdata_price: Option, pub virtual_blocks: u32, pub operator_address: Address, - pub pubdata_params: PubdataParams, + pub pubdata_params: Option, pub transactions: Vec, pub last_in_batch: bool, } @@ -180,9 +180,19 @@ impl ProtoFmt for Payload { } } - let pubdata_params = required(&r.pubdata_params) - .context("pubdata_params")? - .clone(); + let pubdata_params = if let Some(pubdata_params) = &r.pubdata_params { + Some(PubdataParams { + l2_da_validator_address: required(&pubdata_params.l2_da_validator_address) + .and_then(|a| parse_h160(a)) + .context("operator_address")?, + pubdata_type: required(&pubdata_params.pubdata_type) + .and_then(|x| Ok(proto::L1BatchCommitDataGeneratorMode::try_from(*x)?)) + .context("l1_batch_commit_data_generator_mode")? + .parse(), + }) + } else { + None + }; Ok(Self { protocol_version, @@ -202,15 +212,7 @@ impl ProtoFmt for Payload { .context("operator_address")?, transactions, last_in_batch: *required(&r.last_in_batch).context("last_in_batch")?, - pubdata_params: PubdataParams { - l2_da_validator_address: required(&pubdata_params.l2_da_validator_address) - .and_then(|a| parse_h160(a)) - .context("operator_address")?, - pubdata_type: required(&pubdata_params.pubdata_type) - .and_then(|x| Ok(proto::L1BatchCommitDataGeneratorMode::try_from(*x)?)) - .context("l1_batch_commit_data_generator_mode")? - .parse(), - }, + pubdata_params, }) } @@ -229,17 +231,16 @@ impl ProtoFmt for Payload { transactions: vec![], transactions_v25: vec![], last_in_batch: Some(self.last_in_batch), - pubdata_params: Some(proto::PubdataParams { - l2_da_validator_address: Some( - self.pubdata_params - .l2_da_validator_address - .as_bytes() - .into(), - ), - pubdata_type: Some(proto::L1BatchCommitDataGeneratorMode::new( - &self.pubdata_params.pubdata_type, - ) as i32), - }), + pubdata_params: self + .pubdata_params + .map(|pubdata_params| proto::PubdataParams { + l2_da_validator_address: Some( + pubdata_params.l2_da_validator_address.as_bytes().into(), + ), + pubdata_type: Some(proto::L1BatchCommitDataGeneratorMode::new( + &pubdata_params.pubdata_type, + ) as i32), + }), }; match self.protocol_version { v if v >= ProtocolVersionId::Version25 => { diff --git a/core/lib/dal/src/consensus/proto/mod.proto b/core/lib/dal/src/consensus/proto/mod.proto index 24a8297031d..6083ad02910 100644 --- a/core/lib/dal/src/consensus/proto/mod.proto +++ b/core/lib/dal/src/consensus/proto/mod.proto @@ -27,7 +27,7 @@ message Payload { // Set for protocol_version >= 25. repeated TransactionV25 transactions_v25 = 12; optional bool last_in_batch = 10; // required - optional PubdataParams pubdata_params = 13; // required + optional PubdataParams pubdata_params = 13; // optional } message PubdataParams { diff --git a/core/lib/dal/src/consensus/tests.rs b/core/lib/dal/src/consensus/tests.rs index c99f8a37f7c..e50ff5b1cae 100644 --- a/core/lib/dal/src/consensus/tests.rs +++ b/core/lib/dal/src/consensus/tests.rs @@ -53,13 +53,13 @@ fn payload(rng: &mut impl Rng, protocol_version: ProtocolVersionId) -> Payload { }) .collect(), last_in_batch: rng.gen(), - pubdata_params: PubdataParams { + pubdata_params: Some(PubdataParams { pubdata_type: match rng.gen_range(0..2) { 0 => L1BatchCommitmentMode::Rollup, _ => L1BatchCommitmentMode::Validium, }, l2_da_validator_address: rng.gen(), - }, + }), } } diff --git a/core/lib/dal/src/models/storage_sync.rs b/core/lib/dal/src/models/storage_sync.rs index b9ef075f985..7bb3c228748 100644 --- a/core/lib/dal/src/models/storage_sync.rs +++ b/core/lib/dal/src/models/storage_sync.rs @@ -117,7 +117,7 @@ impl SyncBlock { virtual_blocks: Some(self.virtual_blocks), hash: Some(self.hash), protocol_version: self.protocol_version, - pubdata_params: self.pubdata_params, + pubdata_params: Some(self.pubdata_params), } } @@ -134,7 +134,7 @@ impl SyncBlock { operator_address: self.fee_account_address, transactions, last_in_batch: self.last_in_batch, - pubdata_params: self.pubdata_params, + pubdata_params: Some(self.pubdata_params), } } } diff --git a/core/lib/env_config/src/contracts.rs b/core/lib/env_config/src/contracts.rs index d1c6a252b02..01756fd2fd9 100644 --- a/core/lib/env_config/src/contracts.rs +++ b/core/lib/env_config/src/contracts.rs @@ -95,10 +95,6 @@ mod tests { user_facing_diamond_proxy_addr: Some(addr( "0xF00B988a98Ca742e7958DeF9F7823b5908715f4a", )), - l2_native_token_vault_proxy_addr: Some(addr( - "0xfc073319977e314f251eae6ae6be76b0b3baeecf", - )), - l2_legacy_shared_bridge_addr: Some(addr("0x8656770FA78c830456B00B4fFCeE6b1De0e1b888")), chain_admin_addr: Some(addr("0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347ff")), l2_da_validator_addr: Some(addr("0xed6fa5c14e7550b4caf2aa2818d24c69cbc347ff")), } @@ -131,7 +127,6 @@ CONTRACTS_USER_FACING_DIAMOND_PROXY_ADDR="0xF00B988a98Ca742e7958DeF9F7823b590871 CONTRACTS_L2_NATIVE_TOKEN_VAULT_PROXY_ADDR="0xfc073319977e314f251eae6ae6be76b0b3baeecf" CONTRACTS_L2_DA_VALIDATOR_ADDR="0xed6fa5c14e7550b4caf2aa2818d24c69cbc347ff" CONTRACTS_CHAIN_ADMIN_ADDR="0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347ff" -CONTRACTS_L2_LEGACY_SHARED_BRIDGE_ADDR="0x8656770FA78c830456B00B4fFCeE6b1De0e1b888" "#; lock.set_env(config); diff --git a/core/lib/protobuf_config/src/contracts.rs b/core/lib/protobuf_config/src/contracts.rs index a022c9aa1a1..616334b056c 100644 --- a/core/lib/protobuf_config/src/contracts.rs +++ b/core/lib/protobuf_config/src/contracts.rs @@ -76,12 +76,6 @@ impl ProtoRepr for proto::Contracts { .map(|x| parse_h160(x)) .transpose() .context("l2_shared_bridge_addr")?, - l2_legacy_shared_bridge_addr: l2 - .l2_legacy_shared_bridge_addr - .as_ref() - .map(|x| parse_h160(x)) - .transpose() - .context("l2_legacy_shared_bridge_addr")?, l1_weth_bridge_proxy_addr: weth_bridge .as_ref() .and_then(|bridge| bridge.l1_address.as_ref().map(|x| parse_h160(x))) @@ -119,12 +113,6 @@ impl ProtoRepr for proto::Contracts { .map(|x| parse_h160(x)) .transpose() .context("base_token_addr")?, - l2_native_token_vault_proxy_addr: l2 - .l2_native_token_vault_proxy_addr - .as_ref() - .map(|x| parse_h160(x)) - .transpose() - .context("l2_native_token_vault_proxy_addr")?, l2_da_validator_addr: l2 .l2_da_validator_addr .as_ref() @@ -172,13 +160,7 @@ impl ProtoRepr for proto::Contracts { }), l2: Some(proto::L2 { testnet_paymaster_addr: this.l2_testnet_paymaster_addr.map(|a| format!("{:?}", a)), - l2_native_token_vault_proxy_addr: this - .l2_native_token_vault_proxy_addr - .map(|a| format!("{:?}", a)), l2_da_validator_addr: this.l2_da_validator_addr.map(|a| format!("{:?}", a)), - l2_legacy_shared_bridge_addr: this - .l2_legacy_shared_bridge_addr - .map(|a| format!("{:?}", a)), }), bridges: Some(proto::Bridges { shared: Some(proto::Bridge { diff --git a/core/lib/protobuf_config/src/proto/config/contracts.proto b/core/lib/protobuf_config/src/proto/config/contracts.proto index 63e5eb1a3e9..655c67b003d 100644 --- a/core/lib/protobuf_config/src/proto/config/contracts.proto +++ b/core/lib/protobuf_config/src/proto/config/contracts.proto @@ -21,9 +21,7 @@ message L1 { message L2 { optional string testnet_paymaster_addr = 1; // optional; H160 - optional string l2_native_token_vault_proxy_addr = 2; // optional; H160 - optional string l2_da_validator_addr = 3; // optional; H160 - optional string l2_legacy_shared_bridge_addr = 4; // optional; H160 + optional string l2_da_validator_addr = 2; // optional; H160 } message Bridge { diff --git a/core/lib/types/src/api/en.rs b/core/lib/types/src/api/en.rs index 4a847b99e3d..52d66a29458 100644 --- a/core/lib/types/src/api/en.rs +++ b/core/lib/types/src/api/en.rs @@ -43,7 +43,7 @@ pub struct SyncBlock { /// Version of the protocol used for this block. pub protocol_version: ProtocolVersionId, /// Pubdata params used for this batch - pub pubdata_params: PubdataParams, + pub pubdata_params: Option, } /// Global configuration of the consensus served by the main node to the external nodes. diff --git a/core/lib/types/src/api/mod.rs b/core/lib/types/src/api/mod.rs index 65249f9bab6..75bcc6387aa 100644 --- a/core/lib/types/src/api/mod.rs +++ b/core/lib/types/src/api/mod.rs @@ -264,6 +264,7 @@ pub struct BridgeAddresses { pub l2_erc20_default_bridge: Option
, pub l1_weth_bridge: Option
, pub l2_weth_bridge: Option
, + pub l2_token_deployer: Option
, } #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] diff --git a/core/lib/web3_decl/src/namespaces/zks.rs b/core/lib/web3_decl/src/namespaces/zks.rs index b27bf262877..169d27aac1d 100644 --- a/core/lib/web3_decl/src/namespaces/zks.rs +++ b/core/lib/web3_decl/src/namespaces/zks.rs @@ -52,12 +52,6 @@ pub trait ZksNamespace { #[method(name = "getTestnetPaymaster")] async fn get_testnet_paymaster(&self) -> RpcResult>; - #[method(name = "getNativeTokenVault")] - async fn get_native_token_vault_proxy_addr(&self) -> RpcResult>; - - #[method(name = "getLegacySharedBridge")] - async fn get_legacy_shared_bridge(&self) -> RpcResult>; - #[method(name = "getBridgeContracts")] async fn get_bridge_contracts(&self) -> RpcResult; diff --git a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/zks.rs b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/zks.rs index c32a5e10ad0..14f3e6e7be4 100644 --- a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/zks.rs +++ b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/zks.rs @@ -54,16 +54,10 @@ impl ZksNamespaceServer for ZksNamespace { Ok(self.get_testnet_paymaster_impl()) } - async fn get_native_token_vault_proxy_addr(&self) -> RpcResult> { - Ok(self.get_native_token_vault_proxy_addr_impl()) - } - - async fn get_legacy_shared_bridge(&self) -> RpcResult> { - Ok(self.get_legacy_shared_bridge_impl()) - } - async fn get_bridge_contracts(&self) -> RpcResult { - Ok(self.get_bridge_contracts_impl()) + self.get_bridge_contracts_impl() + .await + .map_err(|err| self.current_method().map_err(err)) } async fn l1_chain_id(&self) -> RpcResult { diff --git a/core/node/api_server/src/web3/namespaces/zks.rs b/core/node/api_server/src/web3/namespaces/zks.rs index 09f1ead54a5..05ab8ddc271 100644 --- a/core/node/api_server/src/web3/namespaces/zks.rs +++ b/core/node/api_server/src/web3/namespaces/zks.rs @@ -7,7 +7,7 @@ use zksync_dal::{Connection, Core, CoreDal, DalError}; use zksync_metadata_calculator::api_server::TreeApiError; use zksync_mini_merkle_tree::MiniMerkleTree; use zksync_multivm::interface::VmExecutionResultAndLogs; -use zksync_system_constants::DEFAULT_L2_TX_GAS_PER_PUBDATA_BYTE; +use zksync_system_constants::{DEFAULT_L2_TX_GAS_PER_PUBDATA_BYTE, L2_ASSET_ROUTER_ADDRESS}; use zksync_types::{ api::{ state_override::StateOverride, BlockDetails, BridgeAddresses, ChainAggProof, GetLogsFilter, @@ -147,16 +147,18 @@ impl ZksNamespace { self.state.api_config.l2_testnet_paymaster_addr } - pub fn get_native_token_vault_proxy_addr_impl(&self) -> Option
{ - self.state.api_config.l2_native_token_vault_proxy_addr - } + pub async fn get_bridge_contracts_impl(&self) -> Result { + let mut bridge_contracts = self.state.api_config.bridge_addresses.clone(); + let mut storage = self.state.acquire_connection().await?; - pub fn get_legacy_shared_bridge_impl(&self) -> Option
{ - self.state.api_config.l2_legacy_shared_bridge_addr - } + // `L2_ASSET_ROUTER_ADDRESS` should be used as l2 bridge after gateway upgrade. + let pending_protocol_version = storage.blocks_dal().pending_protocol_version().await?; + if !pending_protocol_version.is_pre_gateway() { + bridge_contracts.l2_erc20_default_bridge = None; + bridge_contracts.l2_shared_default_bridge = Some(L2_ASSET_ROUTER_ADDRESS); + } - pub fn get_bridge_contracts_impl(&self) -> BridgeAddresses { - self.state.api_config.bridge_addresses.clone() + Ok(bridge_contracts) } pub fn l1_chain_id_impl(&self) -> U64 { diff --git a/core/node/api_server/src/web3/state.rs b/core/node/api_server/src/web3/state.rs index 203852346a9..c72380f2989 100644 --- a/core/node/api_server/src/web3/state.rs +++ b/core/node/api_server/src/web3/state.rs @@ -116,8 +116,6 @@ pub struct InternalApiConfig { pub dummy_verifier: bool, pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode, pub user_facing_bridgehub_addr: Option
, - pub l2_native_token_vault_proxy_addr: Option
, - pub l2_legacy_shared_bridge_addr: Option
, } impl InternalApiConfig { @@ -158,6 +156,7 @@ impl InternalApiConfig { .l1_weth_bridge_proxy_addr .unwrap_or_default(), ), + l2_token_deployer: contracts_config.l2_shared_bridge_addr, }, bridgehub_proxy_addr: contracts_config .ecosystem_contracts @@ -187,8 +186,6 @@ impl InternalApiConfig { .as_ref() .map(|a| a.bridgehub_proxy_addr), ), - l2_native_token_vault_proxy_addr: contracts_config.l2_native_token_vault_proxy_addr, - l2_legacy_shared_bridge_addr: contracts_config.l2_legacy_shared_bridge_addr, } } } diff --git a/core/node/consensus/src/storage/store.rs b/core/node/consensus/src/storage/store.rs index b3dd2bdac86..96a47f5abe7 100644 --- a/core/node/consensus/src/storage/store.rs +++ b/core/node/consensus/src/storage/store.rs @@ -35,7 +35,7 @@ fn to_fetched_block( l1_gas_price: payload.l1_gas_price, l2_fair_gas_price: payload.l2_fair_gas_price, fair_pubdata_price: payload.fair_pubdata_price, - pubdata_params: payload.pubdata_params, + pubdata_params: payload.pubdata_params.unwrap_or_default(), virtual_blocks: payload.virtual_blocks, operator_address: payload.operator_address, transactions: payload diff --git a/core/node/consensus/src/testonly.rs b/core/node/consensus/src/testonly.rs index 35802d14940..f91cde0544e 100644 --- a/core/node/consensus/src/testonly.rs +++ b/core/node/consensus/src/testonly.rs @@ -568,9 +568,7 @@ impl StateKeeperRunner { let (stop_send, stop_recv) = sync::watch::channel(false); let (persistence, l2_block_sealer) = StateKeeperPersistence::new( self.pool.0.clone(), - ethabi::Address::repeat_byte(11), - ethabi::Address::repeat_byte(12), - ethabi::Address::repeat_byte(13), + Some(ethabi::Address::repeat_byte(11)), 5, ); @@ -682,9 +680,7 @@ impl StateKeeperRunner { let (stop_send, stop_recv) = sync::watch::channel(false); let (persistence, l2_block_sealer) = StateKeeperPersistence::new( self.pool.0.clone(), - ethabi::Address::repeat_byte(11), - ethabi::Address::repeat_byte(12), - ethabi::Address::repeat_byte(13), + Some(ethabi::Address::repeat_byte(11)), 5, ); let tree_writes_persistence = TreeWritesPersistence::new(self.pool.0.clone()); diff --git a/core/node/node_framework/src/implementations/layers/state_keeper/output_handler.rs b/core/node/node_framework/src/implementations/layers/state_keeper/output_handler.rs index 21531a0eba3..3c1c276447e 100644 --- a/core/node/node_framework/src/implementations/layers/state_keeper/output_handler.rs +++ b/core/node/node_framework/src/implementations/layers/state_keeper/output_handler.rs @@ -35,10 +35,8 @@ use crate::{ /// - `L2BlockSealerTask` #[derive(Debug)] pub struct OutputHandlerLayer { - l2_shared_bridge_addr: Address, + l2_shared_bridge_addr: Option
, l2_block_seal_queue_capacity: usize, - l2_native_token_vault_proxy_addr: Address, - l2_legacy_shared_bridge_addr: Address, /// Whether transactions should be pre-inserted to DB. /// Should be set to `true` for EN's IO as EN doesn't store transactions in DB /// before they are included into L2 blocks. @@ -66,16 +64,12 @@ pub struct Output { impl OutputHandlerLayer { pub fn new( - l2_shared_bridge_addr: Address, - l2_native_token_vault_proxy_addr: Address, - l2_legacy_shared_bridge_addr: Address, + l2_shared_bridge_addr: Option
, l2_block_seal_queue_capacity: usize, ) -> Self { Self { l2_shared_bridge_addr, l2_block_seal_queue_capacity, - l2_native_token_vault_proxy_addr, - l2_legacy_shared_bridge_addr, pre_insert_txs: false, protective_reads_persistence_enabled: false, } @@ -115,8 +109,6 @@ impl WiringLayer for OutputHandlerLayer { let (mut persistence, l2_block_sealer) = StateKeeperPersistence::new( persistence_pool.clone(), self.l2_shared_bridge_addr, - self.l2_native_token_vault_proxy_addr, - self.l2_legacy_shared_bridge_addr, self.l2_block_seal_queue_capacity, ); if self.pre_insert_txs { diff --git a/core/node/node_sync/src/fetcher.rs b/core/node/node_sync/src/fetcher.rs index 6190a26d323..08e3d426243 100644 --- a/core/node/node_sync/src/fetcher.rs +++ b/core/node/node_sync/src/fetcher.rs @@ -94,7 +94,7 @@ impl TryFrom for FetchedBlock { .into_iter() .map(FetchedTransaction::new) .collect(), - pubdata_params: block.pubdata_params, + pubdata_params: block.pubdata_params.unwrap_or_default(), }) } } diff --git a/core/node/node_sync/src/tests.rs b/core/node/node_sync/src/tests.rs index 82d70dfa664..8582bbe9374 100644 --- a/core/node/node_sync/src/tests.rs +++ b/core/node/node_sync/src/tests.rs @@ -106,13 +106,8 @@ impl StateKeeperHandles { assert!(tx_hashes.iter().all(|tx_hashes| !tx_hashes.is_empty())); let sync_state = SyncState::default(); - let (persistence, l2_block_sealer) = StateKeeperPersistence::new( - pool.clone(), - Address::repeat_byte(1), - Address::default(), - Address::repeat_byte(13), - 5, - ); + let (persistence, l2_block_sealer) = + StateKeeperPersistence::new(pool.clone(), Some(Address::repeat_byte(1)), 5); let tree_writes_persistence = TreeWritesPersistence::new(pool.clone()); let output_handler = OutputHandler::new(Box::new(persistence.with_tx_insertion())) .with_handler(Box::new(tree_writes_persistence)) diff --git a/core/node/state_keeper/src/io/mempool.rs b/core/node/state_keeper/src/io/mempool.rs index ca20a2f6000..1a89cec9a40 100644 --- a/core/node/state_keeper/src/io/mempool.rs +++ b/core/node/state_keeper/src/io/mempool.rs @@ -195,6 +195,13 @@ impl StateKeeperIO for MempoolIO { continue; } + // Pubdata type should be `Rollup` for pre-gateway batches. + let pubdata_type = if protocol_version.is_pre_gateway() { + L1BatchCommitmentMode::Rollup + } else { + self.pubdata_type + }; + return Ok(Some(L1BatchParams { protocol_version, validation_computational_gas_limit: self.validation_computational_gas_limit, @@ -207,7 +214,7 @@ impl StateKeeperIO for MempoolIO { }, pubdata_params: PubdataParams { l2_da_validator_address: self.l2_da_validator_address, - pubdata_type: self.pubdata_type, + pubdata_type, }, })); } diff --git a/core/node/state_keeper/src/io/persistence.rs b/core/node/state_keeper/src/io/persistence.rs index cdca16b353f..e890cba41b4 100644 --- a/core/node/state_keeper/src/io/persistence.rs +++ b/core/node/state_keeper/src/io/persistence.rs @@ -29,9 +29,7 @@ struct Completable { #[derive(Debug)] pub struct StateKeeperPersistence { pool: ConnectionPool, - l2_shared_bridge_addr: Address, - l2_native_token_vault_proxy_addr: Address, - l2_legacy_shared_bridge_addr: Address, + l2_shared_bridge_addr: Option
, pre_insert_txs: bool, insert_protective_reads: bool, commands_sender: mpsc::Sender>, @@ -47,9 +45,7 @@ impl StateKeeperPersistence { /// `command_capacity` for unprocessed sealing commands. pub fn new( pool: ConnectionPool, - l2_shared_bridge_addr: Address, - l2_native_token_vault_proxy_addr: Address, - l2_legacy_shared_bridge_addr: Address, + l2_shared_bridge_addr: Option
, mut command_capacity: usize, ) -> (Self, L2BlockSealerTask) { let is_sync = command_capacity == 0; @@ -65,8 +61,6 @@ impl StateKeeperPersistence { let this = Self { pool, l2_shared_bridge_addr, - l2_native_token_vault_proxy_addr, - l2_legacy_shared_bridge_addr, pre_insert_txs: false, insert_protective_reads: true, commands_sender, @@ -163,12 +157,8 @@ impl StateKeeperOutputHandler for StateKeeperPersistence { } async fn handle_l2_block(&mut self, updates_manager: &UpdatesManager) -> anyhow::Result<()> { - let command = updates_manager.seal_l2_block_command( - self.l2_shared_bridge_addr, - self.l2_native_token_vault_proxy_addr, - self.l2_legacy_shared_bridge_addr, - self.pre_insert_txs, - ); + let command = + updates_manager.seal_l2_block_command(self.l2_shared_bridge_addr, self.pre_insert_txs); self.submit_l2_block(command).await; Ok(()) } @@ -185,8 +175,6 @@ impl StateKeeperOutputHandler for StateKeeperPersistence { .seal_l1_batch( self.pool.clone(), self.l2_shared_bridge_addr, - self.l2_native_token_vault_proxy_addr, - self.l2_legacy_shared_bridge_addr, self.insert_protective_reads, ) .await @@ -406,9 +394,7 @@ mod tests { let (persistence, l2_block_sealer) = StateKeeperPersistence::new( pool.clone(), - Address::default(), - Address::default(), - Address::default(), + Some(Address::default()), l2_block_sealer_capacity, ); let mut output_handler = OutputHandler::new(Box::new(persistence)) @@ -543,13 +529,8 @@ mod tests { .unwrap(); drop(storage); - let (mut persistence, l2_block_sealer) = StateKeeperPersistence::new( - pool.clone(), - Address::default(), - Address::default(), - Address::default(), - 1, - ); + let (mut persistence, l2_block_sealer) = + StateKeeperPersistence::new(pool.clone(), Some(Address::default()), 1); persistence = persistence.with_tx_insertion().without_protective_reads(); let mut output_handler = OutputHandler::new(Box::new(persistence)); tokio::spawn(l2_block_sealer.run()); @@ -587,22 +568,12 @@ mod tests { #[tokio::test] async fn l2_block_sealer_handle_blocking() { let pool = ConnectionPool::constrained_test_pool(1).await; - let (mut persistence, mut sealer) = StateKeeperPersistence::new( - pool, - Address::default(), - Address::default(), - Address::default(), - 1, - ); + let (mut persistence, mut sealer) = + StateKeeperPersistence::new(pool, Some(Address::default()), 1); // The first command should be successfully submitted immediately. let mut updates_manager = create_updates_manager(); - let seal_command = updates_manager.seal_l2_block_command( - Address::default(), - Address::default(), - Address::default(), - false, - ); + let seal_command = updates_manager.seal_l2_block_command(Some(Address::default()), false); persistence.submit_l2_block(seal_command).await; // The second command should lead to blocking @@ -610,12 +581,7 @@ mod tests { timestamp: 2, virtual_blocks: 1, }); - let seal_command = updates_manager.seal_l2_block_command( - Address::default(), - Address::default(), - Address::default(), - false, - ); + let seal_command = updates_manager.seal_l2_block_command(Some(Address::default()), false); { let submit_future = persistence.submit_l2_block(seal_command); futures::pin_mut!(submit_future); @@ -643,12 +609,7 @@ mod tests { timestamp: 3, virtual_blocks: 1, }); - let seal_command = updates_manager.seal_l2_block_command( - Address::default(), - Address::default(), - Address::default(), - false, - ); + let seal_command = updates_manager.seal_l2_block_command(Some(Address::default()), false); persistence.submit_l2_block(seal_command).await; let command = sealer.commands_receiver.recv().await.unwrap(); command.completion_sender.send(()).unwrap(); @@ -658,23 +619,14 @@ mod tests { #[tokio::test] async fn l2_block_sealer_handle_parallel_processing() { let pool = ConnectionPool::constrained_test_pool(1).await; - let (mut persistence, mut sealer) = StateKeeperPersistence::new( - pool, - Address::default(), - Address::default(), - Address::default(), - 5, - ); + let (mut persistence, mut sealer) = + StateKeeperPersistence::new(pool, Some(Address::default()), 5); // 5 L2 block sealing commands can be submitted without blocking. let mut updates_manager = create_updates_manager(); for i in 1..=5 { - let seal_command = updates_manager.seal_l2_block_command( - Address::default(), - Address::default(), - Address::default(), - false, - ); + let seal_command = + updates_manager.seal_l2_block_command(Some(Address::default()), false); updates_manager.push_l2_block(L2BlockParams { timestamp: i, virtual_blocks: 1, diff --git a/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs b/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs index 608e7f78f4b..bd283f23735 100644 --- a/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs +++ b/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs @@ -3,11 +3,11 @@ use async_trait::async_trait; use once_cell::sync::Lazy; use zksync_dal::{Connection, Core, CoreDal}; use zksync_multivm::interface::VmEvent; -use zksync_system_constants::CONTRACT_DEPLOYER_ADDRESS; +use zksync_system_constants::{CONTRACT_DEPLOYER_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS}; use zksync_types::{ ethabi, tokens::{TokenInfo, TokenMetadata}, - Address, L2BlockNumber, H160, H256, + Address, L2BlockNumber, H256, }; use zksync_utils::h256_to_account_address; @@ -333,10 +333,9 @@ impl L2BlockSealSubtask for InsertTokensSubtask { connection: &mut Connection<'_, Core>, ) -> anyhow::Result<()> { let is_fictive = command.is_l2_block_fictive(); - let mut deployer_address = command.l2_native_token_vault_proxy_addr; - if command.l2_legacy_shared_bridge_addr != H160::zero() { - deployer_address = command.l2_legacy_shared_bridge_addr; - } + let deployer_address = command + .l2_shared_bridge_addr + .unwrap_or(L2_NATIVE_TOKEN_VAULT_ADDRESS); let progress = L2_BLOCK_METRICS.start(L2BlockSealStage::ExtractAddedTokens, is_fictive); let added_tokens = extract_added_tokens(deployer_address, &command.l2_block.events); @@ -559,8 +558,6 @@ mod tests { base_system_contracts_hashes: Default::default(), protocol_version: Some(ProtocolVersionId::latest()), l2_shared_bridge_addr: Default::default(), - l2_native_token_vault_proxy_addr: Default::default(), - l2_legacy_shared_bridge_addr: Default::default(), pre_insert_txs: false, }; diff --git a/core/node/state_keeper/src/io/seal_logic/mod.rs b/core/node/state_keeper/src/io/seal_logic/mod.rs index 0894ace7904..643042a927a 100644 --- a/core/node/state_keeper/src/io/seal_logic/mod.rs +++ b/core/node/state_keeper/src/io/seal_logic/mod.rs @@ -46,9 +46,7 @@ impl UpdatesManager { pub(super) async fn seal_l1_batch( &self, pool: ConnectionPool, - l2_shared_bridge_addr: Address, - l2_native_token_vault_proxy_addr: Address, - l2_legacy_shared_bridge_addr: Address, + l2_shared_bridge_addr: Option
, insert_protective_reads: bool, ) -> anyhow::Result<()> { let started_at = Instant::now(); @@ -62,8 +60,6 @@ impl UpdatesManager { // Seal fictive L2 block with last events and storage logs. let l2_block_command = self.seal_l2_block_command( l2_shared_bridge_addr, - l2_native_token_vault_proxy_addr, - l2_legacy_shared_bridge_addr, false, // fictive L2 blocks don't have txs, so it's fine to pass `false` here. ); diff --git a/core/node/state_keeper/src/io/tests/mod.rs b/core/node/state_keeper/src/io/tests/mod.rs index e487efe0615..5871148dcd3 100644 --- a/core/node/state_keeper/src/io/tests/mod.rs +++ b/core/node/state_keeper/src/io/tests/mod.rs @@ -285,9 +285,7 @@ async fn processing_storage_logs_when_sealing_l2_block() { pubdata_params: Default::default(), base_system_contracts_hashes: BaseSystemContractsHashes::default(), protocol_version: Some(ProtocolVersionId::latest()), - l2_shared_bridge_addr: Address::default(), - l2_native_token_vault_proxy_addr: Address::default(), - l2_legacy_shared_bridge_addr: Address::default(), + l2_shared_bridge_addr: Default::default(), pre_insert_txs: false, }; connection_pool @@ -377,9 +375,7 @@ async fn processing_events_when_sealing_l2_block() { base_fee_per_gas: 10, base_system_contracts_hashes: BaseSystemContractsHashes::default(), protocol_version: Some(ProtocolVersionId::latest()), - l2_shared_bridge_addr: Address::default(), - l2_native_token_vault_proxy_addr: Address::default(), - l2_legacy_shared_bridge_addr: Address::default(), + l2_shared_bridge_addr: Default::default(), pre_insert_txs: false, }; pool.connection() @@ -468,13 +464,8 @@ async fn l2_block_processing_after_snapshot_recovery(commitment_mode: L1BatchCom vec![], ); - let (mut persistence, l2_block_sealer) = StateKeeperPersistence::new( - connection_pool.clone(), - Address::default(), - Address::default(), - Address::default(), - 0, - ); + let (mut persistence, l2_block_sealer) = + StateKeeperPersistence::new(connection_pool.clone(), Some(Address::default()), 0); tokio::spawn(l2_block_sealer.run()); persistence.handle_l2_block(&updates).await.unwrap(); diff --git a/core/node/state_keeper/src/updates/mod.rs b/core/node/state_keeper/src/updates/mod.rs index b640bc8f66a..5d29061c70e 100644 --- a/core/node/state_keeper/src/updates/mod.rs +++ b/core/node/state_keeper/src/updates/mod.rs @@ -85,9 +85,7 @@ impl UpdatesManager { pub(crate) fn seal_l2_block_command( &self, - l2_shared_bridge_addr: Address, - l2_native_token_vault_proxy_addr: Address, - l2_legacy_shared_bridge_addr: Address, + l2_shared_bridge_addr: Option
, pre_insert_txs: bool, ) -> L2BlockSealCommand { L2BlockSealCommand { @@ -101,8 +99,6 @@ impl UpdatesManager { base_system_contracts_hashes: self.base_system_contract_hashes, protocol_version: Some(self.protocol_version), l2_shared_bridge_addr, - l2_native_token_vault_proxy_addr, - l2_legacy_shared_bridge_addr, pre_insert_txs, } } @@ -213,9 +209,7 @@ pub struct L2BlockSealCommand { pub base_fee_per_gas: u64, pub base_system_contracts_hashes: BaseSystemContractsHashes, pub protocol_version: Option, - pub l2_shared_bridge_addr: Address, - pub l2_native_token_vault_proxy_addr: Address, - pub l2_legacy_shared_bridge_addr: Address, + pub l2_shared_bridge_addr: Option
, pub pubdata_params: PubdataParams, /// Whether transactions should be pre-inserted to DB. /// Should be set to `true` for EN's IO as EN doesn't store transactions in DB From 38a54601c15ebe57dd1b37033d41a1178ff2f7c5 Mon Sep 17 00:00:00 2001 From: perekopskiy Date: Fri, 27 Sep 2024 14:15:11 +0300 Subject: [PATCH 02/10] update zk_toolbox --- zk_toolbox/crates/config/src/contracts.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zk_toolbox/crates/config/src/contracts.rs b/zk_toolbox/crates/config/src/contracts.rs index 1d43e086f7c..3a39808677d 100644 --- a/zk_toolbox/crates/config/src/contracts.rs +++ b/zk_toolbox/crates/config/src/contracts.rs @@ -114,6 +114,7 @@ impl ContractsConfig { register_chain_output.access_control_restriction_addr; self.l1.chain_proxy_admin_addr = register_chain_output.chain_proxy_admin_addr; self.l2.l2_legacy_shared_bridge_addr = register_chain_output.l2_legacy_shared_bridge_addr; + self.bridges.shared.l2_address = Some(register_chain_output.l2_legacy_shared_bridge_addr); self.user_facing_diamond_proxy = register_chain_output.diamond_proxy_addr; } @@ -122,8 +123,8 @@ impl ContractsConfig { &mut self, initialize_bridges_output: &InitializeBridgeOutput, ) -> anyhow::Result<()> { - self.bridges.shared.l2_address = Some(L2_ASSET_ROUTER_ADDRESS); - self.bridges.erc20.l2_address = Some(L2_ASSET_ROUTER_ADDRESS); + // self.bridges.shared.l2_address = Some(L2_ASSET_ROUTER_ADDRESS); + // self.bridges.erc20.l2_address = Some(L2_ASSET_ROUTER_ADDRESS); self.l2.l2_native_token_vault_proxy_addr = L2_NATIVE_TOKEN_VAULT_ADDRESS; self.l2.l2_da_validator_addr = initialize_bridges_output.l2_da_validator_address; Ok(()) From b1518a962db4fb4d98b038e7f1a96dc1f17b875e Mon Sep 17 00:00:00 2001 From: perekopskiy Date: Fri, 27 Sep 2024 16:54:46 +0300 Subject: [PATCH 03/10] fix vm --- core/lib/basic_types/src/protocol_version.rs | 8 +-- core/lib/basic_types/src/vm.rs | 2 +- core/lib/multivm/src/utils/mod.rs | 28 +++++----- .../vm_latest/bootloader_state/state.rs | 41 +++++++++++---- .../vm_latest/bootloader_state/utils.rs | 51 ++++++++++++++----- .../src/versions/vm_latest/constants.rs | 2 +- .../vm_latest/tracers/pubdata_tracer.rs | 3 +- .../vm_latest/types/internals/pubdata.rs | 49 ++++++++++++++++++ .../vm_latest/types/internals/vm_state.rs | 3 ++ core/lib/multivm/src/versions/vm_latest/vm.rs | 10 ++-- core/lib/multivm/src/vm_instance.rs | 4 +- core/node/commitment_generator/src/utils.rs | 4 +- zk_toolbox/crates/config/src/contracts.rs | 2 +- 13 files changed, 156 insertions(+), 51 deletions(-) diff --git a/core/lib/basic_types/src/protocol_version.rs b/core/lib/basic_types/src/protocol_version.rs index ce915014595..132b78b51b5 100644 --- a/core/lib/basic_types/src/protocol_version.rs +++ b/core/lib/basic_types/src/protocol_version.rs @@ -120,8 +120,8 @@ impl ProtocolVersionId { ProtocolVersionId::Version22 => VmVersion::Vm1_4_2, ProtocolVersionId::Version23 => VmVersion::Vm1_5_0SmallBootloaderMemory, ProtocolVersionId::Version24 => VmVersion::Vm1_5_0IncreasedBootloaderMemory, - ProtocolVersionId::Version25 => VmVersion::VmSyncLayer, - ProtocolVersionId::Version26 => VmVersion::VmSyncLayer, + ProtocolVersionId::Version25 => VmVersion::VmGateway, + ProtocolVersionId::Version26 => VmVersion::VmGateway, } } @@ -280,8 +280,8 @@ impl From for VmVersion { ProtocolVersionId::Version22 => VmVersion::Vm1_4_2, ProtocolVersionId::Version23 => VmVersion::Vm1_5_0SmallBootloaderMemory, ProtocolVersionId::Version24 => VmVersion::Vm1_5_0IncreasedBootloaderMemory, - ProtocolVersionId::Version25 => VmVersion::VmSyncLayer, - ProtocolVersionId::Version26 => VmVersion::VmSyncLayer, + ProtocolVersionId::Version25 => VmVersion::VmGateway, + ProtocolVersionId::Version26 => VmVersion::VmGateway, } } } diff --git a/core/lib/basic_types/src/vm.rs b/core/lib/basic_types/src/vm.rs index ac31cae64f0..f11f98596f1 100644 --- a/core/lib/basic_types/src/vm.rs +++ b/core/lib/basic_types/src/vm.rs @@ -16,7 +16,7 @@ pub enum VmVersion { Vm1_4_2, Vm1_5_0SmallBootloaderMemory, Vm1_5_0IncreasedBootloaderMemory, - VmSyncLayer, + VmGateway, } impl VmVersion { diff --git a/core/lib/multivm/src/utils/mod.rs b/core/lib/multivm/src/utils/mod.rs index 07d109a59ba..44ed004adc2 100644 --- a/core/lib/multivm/src/utils/mod.rs +++ b/core/lib/multivm/src/utils/mod.rs @@ -55,7 +55,7 @@ pub fn derive_base_fee_and_gas_per_pubdata( ), VmVersion::Vm1_5_0SmallBootloaderMemory | VmVersion::Vm1_5_0IncreasedBootloaderMemory - | VmVersion::VmSyncLayer => { + | VmVersion::VmGateway => { crate::vm_latest::utils::fee::derive_base_fee_and_gas_per_pubdata( batch_fee_input.into_pubdata_independent(), ) @@ -85,7 +85,7 @@ pub fn get_batch_base_fee(l1_batch_env: &L1BatchEnv, vm_version: VmVersion) -> u VmVersion::Vm1_4_2 => crate::vm_1_4_2::utils::fee::get_batch_base_fee(l1_batch_env), VmVersion::Vm1_5_0SmallBootloaderMemory | VmVersion::Vm1_5_0IncreasedBootloaderMemory - | VmVersion::VmSyncLayer => crate::vm_latest::utils::fee::get_batch_base_fee(l1_batch_env), + | VmVersion::VmGateway => crate::vm_latest::utils::fee::get_batch_base_fee(l1_batch_env), } } @@ -213,7 +213,7 @@ pub fn derive_overhead( VmVersion::Vm1_4_2 => crate::vm_1_4_2::utils::overhead::derive_overhead(encoded_len), VmVersion::Vm1_5_0SmallBootloaderMemory | VmVersion::Vm1_5_0IncreasedBootloaderMemory - | VmVersion::VmSyncLayer => crate::vm_latest::utils::overhead::derive_overhead(encoded_len), + | VmVersion::VmGateway => crate::vm_latest::utils::overhead::derive_overhead(encoded_len), } } @@ -247,7 +247,7 @@ pub fn get_bootloader_encoding_space(version: VmVersion) -> u32 { crate::vm_latest::MultiVMSubversion::IncreasedBootloaderMemory, ) } - VmVersion::VmSyncLayer => crate::vm_latest::constants::get_bootloader_tx_encoding_space( + VmVersion::VmGateway => crate::vm_latest::constants::get_bootloader_tx_encoding_space( crate::vm_latest::MultiVMSubversion::IncreasedBootloaderMemory, ), } @@ -271,7 +271,7 @@ pub fn get_bootloader_max_txs_in_batch(version: VmVersion) -> usize { VmVersion::Vm1_4_2 => crate::vm_1_4_2::constants::MAX_TXS_IN_BATCH, VmVersion::Vm1_5_0SmallBootloaderMemory | VmVersion::Vm1_5_0IncreasedBootloaderMemory - | VmVersion::VmSyncLayer => crate::vm_latest::constants::MAX_TXS_IN_BATCH, + | VmVersion::VmGateway => crate::vm_latest::constants::MAX_TXS_IN_BATCH, } } @@ -294,7 +294,7 @@ pub fn gas_bootloader_batch_tip_overhead(version: VmVersion) -> u32 { VmVersion::Vm1_4_2 => crate::vm_1_4_2::constants::BOOTLOADER_BATCH_TIP_OVERHEAD, VmVersion::Vm1_5_0SmallBootloaderMemory | VmVersion::Vm1_5_0IncreasedBootloaderMemory - | VmVersion::VmSyncLayer => crate::vm_latest::constants::BOOTLOADER_BATCH_TIP_OVERHEAD, + | VmVersion::VmGateway => crate::vm_latest::constants::BOOTLOADER_BATCH_TIP_OVERHEAD, } } @@ -317,7 +317,7 @@ pub fn circuit_statistics_bootloader_batch_tip_overhead(version: VmVersion) -> u } VmVersion::Vm1_5_0SmallBootloaderMemory | VmVersion::Vm1_5_0IncreasedBootloaderMemory - | VmVersion::VmSyncLayer => { + | VmVersion::VmGateway => { crate::vm_latest::constants::BOOTLOADER_BATCH_TIP_CIRCUIT_STATISTICS_OVERHEAD as usize } } @@ -342,7 +342,7 @@ pub fn execution_metrics_bootloader_batch_tip_overhead(version: VmVersion) -> us } VmVersion::Vm1_5_0SmallBootloaderMemory | VmVersion::Vm1_5_0IncreasedBootloaderMemory - | VmVersion::VmSyncLayer => { + | VmVersion::VmGateway => { crate::vm_latest::constants::BOOTLOADER_BATCH_TIP_METRICS_SIZE_OVERHEAD as usize } } @@ -368,7 +368,7 @@ pub fn get_max_gas_per_pubdata_byte(version: VmVersion) -> u64 { VmVersion::Vm1_4_2 => crate::vm_1_4_2::constants::MAX_GAS_PER_PUBDATA_BYTE, VmVersion::Vm1_5_0SmallBootloaderMemory | VmVersion::Vm1_5_0IncreasedBootloaderMemory - | VmVersion::VmSyncLayer => crate::vm_latest::constants::MAX_GAS_PER_PUBDATA_BYTE, + | VmVersion::VmGateway => crate::vm_latest::constants::MAX_GAS_PER_PUBDATA_BYTE, } } @@ -397,7 +397,7 @@ pub fn get_used_bootloader_memory_bytes(version: VmVersion) -> usize { crate::vm_latest::MultiVMSubversion::SmallBootloaderMemory, ) } - VmVersion::Vm1_5_0IncreasedBootloaderMemory | VmVersion::VmSyncLayer => { + VmVersion::Vm1_5_0IncreasedBootloaderMemory | VmVersion::VmGateway => { crate::vm_latest::constants::get_used_bootloader_memory_bytes( crate::vm_latest::MultiVMSubversion::IncreasedBootloaderMemory, ) @@ -430,7 +430,7 @@ pub fn get_used_bootloader_memory_words(version: VmVersion) -> usize { crate::vm_latest::MultiVMSubversion::SmallBootloaderMemory, ) } - VmVersion::Vm1_5_0IncreasedBootloaderMemory | VmVersion::VmSyncLayer => { + VmVersion::Vm1_5_0IncreasedBootloaderMemory | VmVersion::VmGateway => { crate::vm_latest::constants::get_used_bootloader_memory_bytes( crate::vm_latest::MultiVMSubversion::IncreasedBootloaderMemory, ) @@ -458,7 +458,7 @@ pub fn get_max_batch_gas_limit(version: VmVersion) -> u64 { VmVersion::Vm1_4_2 => crate::vm_1_4_2::constants::BLOCK_GAS_LIMIT as u64, VmVersion::Vm1_5_0SmallBootloaderMemory | VmVersion::Vm1_5_0IncreasedBootloaderMemory - | VmVersion::VmSyncLayer => crate::vm_latest::constants::BATCH_GAS_LIMIT, + | VmVersion::VmGateway => crate::vm_latest::constants::BATCH_GAS_LIMIT, } } @@ -484,7 +484,7 @@ pub fn get_eth_call_gas_limit(version: VmVersion) -> u64 { VmVersion::Vm1_4_2 => crate::vm_1_4_2::constants::ETH_CALL_GAS_LIMIT as u64, VmVersion::Vm1_5_0SmallBootloaderMemory | VmVersion::Vm1_5_0IncreasedBootloaderMemory - | VmVersion::VmSyncLayer => crate::vm_latest::constants::ETH_CALL_GAS_LIMIT, + | VmVersion::VmGateway => crate::vm_latest::constants::ETH_CALL_GAS_LIMIT, } } @@ -507,7 +507,7 @@ pub fn get_max_batch_base_layer_circuits(version: VmVersion) -> usize { } VmVersion::Vm1_5_0SmallBootloaderMemory | VmVersion::Vm1_5_0IncreasedBootloaderMemory - | VmVersion::VmSyncLayer => crate::vm_latest::constants::MAX_BASE_LAYER_CIRCUITS, + | VmVersion::VmGateway => crate::vm_latest::constants::MAX_BASE_LAYER_CIRCUITS, } } diff --git a/core/lib/multivm/src/versions/vm_latest/bootloader_state/state.rs b/core/lib/multivm/src/versions/vm_latest/bootloader_state/state.rs index 69c780194eb..122704c24b9 100644 --- a/core/lib/multivm/src/versions/vm_latest/bootloader_state/state.rs +++ b/core/lib/multivm/src/versions/vm_latest/bootloader_state/state.rs @@ -18,6 +18,7 @@ use crate::{ constants::TX_DESCRIPTION_OFFSET, types::internals::{PubdataInput, TransactionData}, utils::l2_blocks::assert_next_block, + MultiVMSubversion, }, }; @@ -48,7 +49,10 @@ pub struct BootloaderState { free_tx_offset: usize, /// Information about the the pubdata that will be needed to supply to the L1Messenger pubdata_information: OnceCell, - pub(crate) pubdata_params: PubdataParams, + /// Params related to how the pubdata should be processed by the bootloader in the batch + pubdata_params: PubdataParams, + /// VM subversion + subversion: MultiVMSubversion, } impl BootloaderState { @@ -57,6 +61,7 @@ impl BootloaderState { initial_memory: BootloaderMemory, first_l2_block: L2BlockEnv, pubdata_params: PubdataParams, + subversion: MultiVMSubversion, ) -> Self { let l2_block = BootloaderL2Block::new(first_l2_block, 0); Self { @@ -68,6 +73,7 @@ impl BootloaderState { free_tx_offset: 0, pubdata_information: Default::default(), pubdata_params, + subversion, } } @@ -141,6 +147,7 @@ impl BootloaderState { pub(crate) fn last_l2_block(&self) -> &BootloaderL2Block { self.l2_blocks.last().unwrap() } + pub(crate) fn get_pubdata_information(&self) -> &PubdataInput { self.pubdata_information .get() @@ -148,14 +155,21 @@ impl BootloaderState { } pub(crate) fn get_encoded_pubdata(&self) -> Vec { - get_encoded_pubdata( - self.pubdata_information - .get() - .expect("Pubdata information is not set") - .clone(), - self.pubdata_params, - false, - ) + let pubdata_information = self + .pubdata_information + .get() + .expect("Pubdata information is not set") + .clone(); + + match self.subversion { + MultiVMSubversion::SmallBootloaderMemory + | MultiVMSubversion::IncreasedBootloaderMemory => { + pubdata_information.build_pubdata_legacy(false) + } + MultiVMSubversion::Gateway => { + get_encoded_pubdata(pubdata_information, self.pubdata_params, false) + } + } } fn last_mut_l2_block(&mut self) -> &mut BootloaderL2Block { @@ -199,6 +213,7 @@ impl BootloaderState { &mut initial_memory, pubdata_information, self.pubdata_params, + self.subversion, ); initial_memory } @@ -312,4 +327,12 @@ impl BootloaderState { ); } } + + pub(crate) fn get_pubdata_params(&self) -> PubdataParams { + self.pubdata_params + } + + pub(crate) fn get_vm_subversion(&self) -> MultiVMSubversion { + self.subversion + } } diff --git a/core/lib/multivm/src/versions/vm_latest/bootloader_state/utils.rs b/core/lib/multivm/src/versions/vm_latest/bootloader_state/utils.rs index 4c854223a63..09085402b0d 100644 --- a/core/lib/multivm/src/versions/vm_latest/bootloader_state/utils.rs +++ b/core/lib/multivm/src/versions/vm_latest/bootloader_state/utils.rs @@ -21,6 +21,7 @@ use crate::{ pubdata::{PubdataBuilder, RollupPubdataBuilder, ValidiumPubdataBuilder}, PubdataInput, }, + MultiVMSubversion, }, }; @@ -156,19 +157,45 @@ pub(crate) fn apply_pubdata_to_memory( memory: &mut BootloaderMemory, pubdata_information: PubdataInput, pubdata_params: PubdataParams, + subversion: MultiVMSubversion, ) { - // Skipping two slots as they will be filled by the bootloader itself: - // - One slot is for the selector of the call to the L1Messenger. - // - The other slot is for the 0x20 offset for the calldata. - let l1_messenger_pubdata_start_slot = OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_OFFSET + 1; - - let pubdata = get_encoded_pubdata(pubdata_information, pubdata_params, true); - - assert!( - // Note that unlike the previous version, the difference is `1`, since now it also includes the offset - pubdata.len() / 32 < OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_SLOTS, - "The encoded pubdata is too big" - ); + let (l1_messenger_pubdata_start_slot, pubdata) = match subversion { + MultiVMSubversion::SmallBootloaderMemory | MultiVMSubversion::IncreasedBootloaderMemory => { + // Skipping two slots as they will be filled by the bootloader itself: + // - One slot is for the selector of the call to the L1Messenger. + // - The other slot is for the 0x20 offset for the calldata. + let l1_messenger_pubdata_start_slot = OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_OFFSET + 2; + + // Need to skip first word as it represents array offset + // while bootloader expects only [len || data] + let pubdata = ethabi::encode(&[ethabi::Token::Bytes( + pubdata_information.build_pubdata_legacy(true), + )])[32..] + .to_vec(); + + assert!( + pubdata.len() / 32 <= OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_SLOTS - 2, + "The encoded pubdata is too big" + ); + + (l1_messenger_pubdata_start_slot, pubdata) + } + MultiVMSubversion::Gateway => { + // Skipping the first slot as it will be filled by the bootloader itself: + // It is for the selector of the call to the L1Messenger. + let l1_messenger_pubdata_start_slot = OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_OFFSET + 1; + + let pubdata = get_encoded_pubdata(pubdata_information, pubdata_params, true); + + assert!( + // Note that unlike the previous version, the difference is `1`, since now it also includes the offset + pubdata.len() / 32 < OPERATOR_PROVIDED_L1_MESSENGER_PUBDATA_SLOTS, + "The encoded pubdata is too big" + ); + + (l1_messenger_pubdata_start_slot, pubdata) + } + }; pubdata .chunks(32) diff --git a/core/lib/multivm/src/versions/vm_latest/constants.rs b/core/lib/multivm/src/versions/vm_latest/constants.rs index 64a05d0d13e..c047e6ffa3b 100644 --- a/core/lib/multivm/src/versions/vm_latest/constants.rs +++ b/core/lib/multivm/src/versions/vm_latest/constants.rs @@ -26,7 +26,7 @@ pub(crate) const fn get_used_bootloader_memory_bytes(subversion: MultiVMSubversi match subversion { MultiVMSubversion::SmallBootloaderMemory => 59_000_000, MultiVMSubversion::IncreasedBootloaderMemory => 63_800_000, - MultiVMSubversion::SyncLayer => 63_800_000, + MultiVMSubversion::Gateway => 63_800_000, } } diff --git a/core/lib/multivm/src/versions/vm_latest/tracers/pubdata_tracer.rs b/core/lib/multivm/src/versions/vm_latest/tracers/pubdata_tracer.rs index 1701c501cd3..9e620f96af2 100644 --- a/core/lib/multivm/src/versions/vm_latest/tracers/pubdata_tracer.rs +++ b/core/lib/multivm/src/versions/vm_latest/tracers/pubdata_tracer.rs @@ -239,7 +239,8 @@ impl VmTracer for PubdataTracer { apply_pubdata_to_memory( &mut memory_to_apply, pubdata_input, - bootloader_state.pubdata_params, + bootloader_state.get_pubdata_params(), + bootloader_state.get_vm_subversion(), ); state.memory.populate_page( BOOTLOADER_HEAP_PAGE as usize, diff --git a/core/lib/multivm/src/versions/vm_latest/types/internals/pubdata.rs b/core/lib/multivm/src/versions/vm_latest/types/internals/pubdata.rs index fbd01f2b7a7..c0684624bd8 100644 --- a/core/lib/multivm/src/versions/vm_latest/types/internals/pubdata.rs +++ b/core/lib/multivm/src/versions/vm_latest/types/internals/pubdata.rs @@ -19,6 +19,55 @@ pub(crate) struct PubdataInput { pub(crate) l2_to_l1_logs_tree_size: usize, } +impl PubdataInput { + pub(crate) fn build_pubdata_legacy(self, with_uncompressed_state_diffs: bool) -> Vec { + let mut l1_messenger_pubdata = vec![]; + + let PubdataInput { + user_logs, + l2_to_l1_messages, + published_bytecodes, + state_diffs, + .. + } = self; + + // Encoding user L2->L1 logs. + // Format: `[(numberOfL2ToL1Logs as u32) || l2tol1logs[1] || ... || l2tol1logs[n]]` + l1_messenger_pubdata.extend((user_logs.len() as u32).to_be_bytes()); + for l2tol1log in user_logs { + l1_messenger_pubdata.extend(l2tol1log.packed_encoding()); + } + + // Encoding L2->L1 messages + // Format: `[(numberOfMessages as u32) || (messages[1].len() as u32) || messages[1] || ... || (messages[n].len() as u32) || messages[n]]` + l1_messenger_pubdata.extend((l2_to_l1_messages.len() as u32).to_be_bytes()); + for message in l2_to_l1_messages { + l1_messenger_pubdata.extend((message.len() as u32).to_be_bytes()); + l1_messenger_pubdata.extend(message); + } + // Encoding bytecodes + // Format: `[(numberOfBytecodes as u32) || (bytecodes[1].len() as u32) || bytecodes[1] || ... || (bytecodes[n].len() as u32) || bytecodes[n]]` + l1_messenger_pubdata.extend((published_bytecodes.len() as u32).to_be_bytes()); + for bytecode in published_bytecodes { + l1_messenger_pubdata.extend((bytecode.len() as u32).to_be_bytes()); + l1_messenger_pubdata.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()); + l1_messenger_pubdata.extend(state_diffs_compressed); + + if with_uncompressed_state_diffs { + l1_messenger_pubdata.extend((state_diffs.len() as u32).to_be_bytes()); + for state_diff in state_diffs { + l1_messenger_pubdata.extend(state_diff.encode_padded()); + } + } + + l1_messenger_pubdata + } +} + pub trait PubdataBuilder { // when `l2_version` is true it will return the data to be sent to the L1_MESSENGER // otherwise it returns the array of bytes to be sent to L1 inside the operator input. diff --git a/core/lib/multivm/src/versions/vm_latest/types/internals/vm_state.rs b/core/lib/multivm/src/versions/vm_latest/types/internals/vm_state.rs index ab2f3d35d62..b6e5e127c85 100644 --- a/core/lib/multivm/src/versions/vm_latest/types/internals/vm_state.rs +++ b/core/lib/multivm/src/versions/vm_latest/types/internals/vm_state.rs @@ -33,6 +33,7 @@ use crate::{ oracles::storage::StorageOracle, types::l1_batch::bootloader_initial_memory, utils::l2_blocks::{assert_next_block, load_last_l2_block}, + MultiVMSubversion, }, }; @@ -64,6 +65,7 @@ pub(crate) fn new_vm_state( storage: StoragePtr, system_env: &SystemEnv, l1_batch_env: &L1BatchEnv, + subversion: MultiVMSubversion, ) -> (ZkSyncVmState, BootloaderState) { let last_l2_block = if let Some(last_l2_block) = load_last_l2_block(&storage) { last_l2_block @@ -182,6 +184,7 @@ pub(crate) fn new_vm_state( bootloader_initial_memory, first_l2_block, system_env.pubdata_params, + subversion, ); (vm, bootloader_state) diff --git a/core/lib/multivm/src/versions/vm_latest/vm.rs b/core/lib/multivm/src/versions/vm_latest/vm.rs index 91af2f4b0b6..a1b9f6acb51 100644 --- a/core/lib/multivm/src/versions/vm_latest/vm.rs +++ b/core/lib/multivm/src/versions/vm_latest/vm.rs @@ -36,13 +36,14 @@ pub(crate) enum MultiVMSubversion { SmallBootloaderMemory, /// The final correct version of v1.5.0 IncreasedBootloaderMemory, - SyncLayer, + /// Version for protocol v25 + Gateway, } impl MultiVMSubversion { #[cfg(test)] pub(crate) fn latest() -> Self { - Self::IncreasedBootloaderMemory + Self::Gateway } } @@ -54,7 +55,7 @@ impl TryFrom for MultiVMSubversion { match value { VmVersion::Vm1_5_0SmallBootloaderMemory => Ok(Self::SmallBootloaderMemory), VmVersion::Vm1_5_0IncreasedBootloaderMemory => Ok(Self::IncreasedBootloaderMemory), - VmVersion::VmSyncLayer => Ok(Self::SyncLayer), + VmVersion::VmGateway => Ok(Self::Gateway), _ => Err(VmVersionIsNotVm150Error), } } @@ -205,7 +206,8 @@ impl Vm { storage: StoragePtr, subversion: MultiVMSubversion, ) -> Self { - let (state, bootloader_state) = new_vm_state(storage.clone(), &system_env, &batch_env); + let (state, bootloader_state) = + new_vm_state(storage.clone(), &system_env, &batch_env, subversion); Self { bootloader_state, state, diff --git a/core/lib/multivm/src/vm_instance.rs b/core/lib/multivm/src/vm_instance.rs index 79dd42ca629..fdc1c429217 100644 --- a/core/lib/multivm/src/vm_instance.rs +++ b/core/lib/multivm/src/vm_instance.rs @@ -210,12 +210,12 @@ impl VmInstance { ); VmInstance::Vm1_5_0(vm) } - VmVersion::VmSyncLayer => { + VmVersion::VmGateway => { let vm = crate::vm_latest::Vm::new_with_subversion( l1_batch_env, system_env, storage_view, - crate::vm_latest::MultiVMSubversion::SyncLayer, + crate::vm_latest::MultiVMSubversion::Gateway, ); VmInstance::Vm1_5_0(vm) } diff --git a/core/node/commitment_generator/src/utils.rs b/core/node/commitment_generator/src/utils.rs index 15ede4878ed..9ed6682733c 100644 --- a/core/node/commitment_generator/src/utils.rs +++ b/core/node/commitment_generator/src/utils.rs @@ -74,7 +74,7 @@ impl CommitmentComputer for RealCommitmentComputer { )), VmVersion::Vm1_5_0SmallBootloaderMemory | VmVersion::Vm1_5_0IncreasedBootloaderMemory - | VmVersion::VmSyncLayer => Ok(H256( + | VmVersion::VmGateway => Ok(H256( circuit_sequencer_api_1_5_0::commitments::events_queue_commitment_fixed( &events_queue .iter() @@ -113,7 +113,7 @@ impl CommitmentComputer for RealCommitmentComputer { )), VmVersion::Vm1_5_0SmallBootloaderMemory | VmVersion::Vm1_5_0IncreasedBootloaderMemory - | VmVersion::VmSyncLayer => Ok(H256( + | VmVersion::VmGateway => Ok(H256( circuit_sequencer_api_1_5_0::commitments::initial_heap_content_commitment_fixed( &full_bootloader_memory, ), diff --git a/zk_toolbox/crates/config/src/contracts.rs b/zk_toolbox/crates/config/src/contracts.rs index 3a39808677d..2136016190d 100644 --- a/zk_toolbox/crates/config/src/contracts.rs +++ b/zk_toolbox/crates/config/src/contracts.rs @@ -1,6 +1,6 @@ use ethers::types::{Address, H256}; use serde::{Deserialize, Serialize}; -use zksync_system_constants::{L2_ASSET_ROUTER_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS}; +use zksync_system_constants::L2_NATIVE_TOKEN_VAULT_ADDRESS; use crate::{ consts::CONTRACTS_FILE, From 53be1c11dea98e17cd3f771b4bed54d46a98e9e9 Mon Sep 17 00:00:00 2001 From: perekopskiy Date: Fri, 27 Sep 2024 20:41:57 +0300 Subject: [PATCH 04/10] more fixes --- core/lib/contracts/src/lib.rs | 316 ++++++++++++++++++ .../src/i_executor/methods/commit_batches.rs | 14 +- .../src/i_executor/methods/execute_batches.rs | 53 ++- .../src/i_executor/methods/prove_batches.rs | 59 ++-- .../structures/commit_batch_info.rs | 67 +++- core/node/api_server/src/web3/metrics.rs | 4 +- core/node/eth_sender/src/eth_tx_aggregator.rs | 39 ++- core/node/eth_sender/src/zksync_functions.rs | 25 +- .../layers/state_keeper/mempool_io.rs | 4 +- core/node/state_keeper/src/io/mempool.rs | 24 +- core/node/state_keeper/src/io/tests/tester.rs | 2 +- .../fee_estimate.yul/fee_estimate.yul.zbin | Bin 76320 -> 76320 bytes .../gas_test.yul/gas_test.yul.zbin | Bin 72416 -> 72416 bytes .../playground_batch.yul.zbin | Bin 76512 -> 76512 bytes .../proved_batch.yul/proved_batch.yul.zbin | Bin 72928 -> 72928 bytes 15 files changed, 493 insertions(+), 114 deletions(-) diff --git a/core/lib/contracts/src/lib.rs b/core/lib/contracts/src/lib.rs index 5f98d65fcf2..1e14d59efc3 100644 --- a/core/lib/contracts/src/lib.rs +++ b/core/lib/contracts/src/lib.rs @@ -922,3 +922,319 @@ pub static DIAMOND_CUT: Lazy = Lazy::new(|| { }"#; serde_json::from_str(abi).unwrap() }); + +pub static POST_SHARED_BRIDGE_COMMIT_FUNCTION: Lazy = Lazy::new(|| { + let abi = r#" + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "batchNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "batchHash", + "type": "bytes32" + }, + { + "internalType": "uint64", + "name": "indexRepeatedStorageChanges", + "type": "uint64" + }, + { + "internalType": "uint256", + "name": "numberOfLayer1Txs", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "priorityOperationsHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "l2LogsTreeRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "commitment", + "type": "bytes32" + } + ], + "internalType": "struct IExecutor.StoredBatchInfo", + "name": "_lastCommittedBatchData", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "batchNumber", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "timestamp", + "type": "uint64" + }, + { + "internalType": "uint64", + "name": "indexRepeatedStorageChanges", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "newStateRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "numberOfLayer1Txs", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "priorityOperationsHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "bootloaderHeapInitialContentsHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "eventsQueueStateHash", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "systemLogs", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "pubdataCommitments", + "type": "bytes" + } + ], + "internalType": "struct IExecutor.CommitBatchInfo[]", + "name": "_newBatchesData", + "type": "tuple[]" + } + ], + "name": "commitBatchesSharedBridge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }"#; + serde_json::from_str(abi).unwrap() +}); + +pub static POST_SHARED_BRIDGE_PROVE_FUNCTION: Lazy = Lazy::new(|| { + let abi = r#" + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "batchNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "batchHash", + "type": "bytes32" + }, + { + "internalType": "uint64", + "name": "indexRepeatedStorageChanges", + "type": "uint64" + }, + { + "internalType": "uint256", + "name": "numberOfLayer1Txs", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "priorityOperationsHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "l2LogsTreeRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "commitment", + "type": "bytes32" + } + ], + "internalType": "struct IExecutor.StoredBatchInfo", + "name": "_prevBatch", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "batchNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "batchHash", + "type": "bytes32" + }, + { + "internalType": "uint64", + "name": "indexRepeatedStorageChanges", + "type": "uint64" + }, + { + "internalType": "uint256", + "name": "numberOfLayer1Txs", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "priorityOperationsHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "l2LogsTreeRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "commitment", + "type": "bytes32" + } + ], + "internalType": "struct IExecutor.StoredBatchInfo[]", + "name": "_committedBatches", + "type": "tuple[]" + }, + { + "components": [ + { + "internalType": "uint256[]", + "name": "recursiveAggregationInput", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "serializedProof", + "type": "uint256[]" + } + ], + "internalType": "struct IExecutor.ProofInput", + "name": "_proof", + "type": "tuple" + } + ], + "name": "proveBatchesSharedBridge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }"#; + serde_json::from_str(abi).unwrap() +}); + +pub static POST_SHARED_BRIDGE_EXECUTE_FUNCTION: Lazy = Lazy::new(|| { + let abi = r#" + { + "inputs": [ + { + "internalType": "uint256", + "name": "_chainId", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint64", + "name": "batchNumber", + "type": "uint64" + }, + { + "internalType": "bytes32", + "name": "batchHash", + "type": "bytes32" + }, + { + "internalType": "uint64", + "name": "indexRepeatedStorageChanges", + "type": "uint64" + }, + { + "internalType": "uint256", + "name": "numberOfLayer1Txs", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "priorityOperationsHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "l2LogsTreeRoot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "commitment", + "type": "bytes32" + } + ], + "internalType": "struct IExecutor.StoredBatchInfo[]", + "name": "_batchesData", + "type": "tuple[]" + } + ], + "name": "executeBatchesSharedBridge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }"#; + serde_json::from_str(abi).unwrap() +}); 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 e1bddf67ded..948108eaa62 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 @@ -26,16 +26,16 @@ impl CommitBatches<'_> { .map(|batch| CommitBatchInfo::new(self.mode, batch, self.pubdata_da).into_token()) .collect(); - let encoded_data = encode(&[ - stored_batch_info.clone(), - Token::Array(l1_batches_to_commit.clone()), - ]); - let commit_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data] - .concat() - .to_vec(); if pre_gateway { vec![stored_batch_info, Token::Array(l1_batches_to_commit)] } else { + let encoded_data = encode(&[ + stored_batch_info.clone(), + Token::Array(l1_batches_to_commit.clone()), + ]); + let commit_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data] + .concat() + .to_vec(); vec![ Token::Uint((self.last_committed_l1_batch.header.number.0 + 1).into()), Token::Uint( diff --git a/core/lib/l1_contract_interface/src/i_executor/methods/execute_batches.rs b/core/lib/l1_contract_interface/src/i_executor/methods/execute_batches.rs index bbf02201183..65aea1944b2 100644 --- a/core/lib/l1_contract_interface/src/i_executor/methods/execute_batches.rs +++ b/core/lib/l1_contract_interface/src/i_executor/methods/execute_batches.rs @@ -17,28 +17,45 @@ pub struct ExecuteBatches { impl Tokenize for &ExecuteBatches { fn into_tokens(self) -> Vec { - let encoded_data = encode(&[ - Token::Array( + let protocol_version = self.l1_batches[0].header.protocol_version.unwrap(); + + if protocol_version.is_pre_gateway() { + vec![Token::Array( self.l1_batches .iter() .map(|batch| StoredBatchInfo::from(batch).into_token()) .collect(), - ), - Token::Array( - self.priority_ops_proofs - .iter() - .map(|proof| proof.into_token()) - .collect(), - ), - ]); - let commit_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data] - .concat() - .to_vec(); + )] + } else { + let encoded_data = encode(&[ + Token::Array( + self.l1_batches + .iter() + .map(|batch| StoredBatchInfo::from(batch).into_token()) + .collect(), + ), + Token::Array( + self.priority_ops_proofs + .iter() + .map(|proof| proof.into_token()) + .collect(), + ), + ]); + let commit_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data] + .concat() + .to_vec(); - vec![ - Token::Uint((self.l1_batches[0].header.number.0).into()), - Token::Uint((self.l1_batches[self.l1_batches.len() - 1].header.number.0).into()), - Token::Bytes(commit_data), - ] + vec![ + Token::Uint(self.l1_batches[0].header.number.0.into()), + Token::Uint( + self.l1_batches[self.l1_batches.len() - 1] + .header + .number + .0 + .into(), + ), + Token::Bytes(commit_data), + ] + } } } diff --git a/core/lib/l1_contract_interface/src/i_executor/methods/prove_batches.rs b/core/lib/l1_contract_interface/src/i_executor/methods/prove_batches.rs index 086ec84fb00..60c68f69080 100644 --- a/core/lib/l1_contract_interface/src/i_executor/methods/prove_batches.rs +++ b/core/lib/l1_contract_interface/src/i_executor/methods/prove_batches.rs @@ -3,7 +3,6 @@ use zksync_prover_interface::outputs::L1BatchProofForL1; use zksync_types::{ commitment::L1BatchWithMetadata, ethabi::{encode, Token}, - U256, }; use crate::{ @@ -29,6 +28,7 @@ impl Tokenize for &ProveBatches { .map(|batch| StoredBatchInfo::from(batch).into_token()) .collect(); let batches_arg = Token::Array(batches_arg); + let protocol_version = self.l1_batches[0].header.protocol_version.unwrap(); if self.should_verify { // currently we only support submitting a single proof @@ -36,46 +36,39 @@ impl Tokenize for &ProveBatches { assert_eq!(self.l1_batches.len(), 1); let L1BatchProofForL1 { - aggregation_result_coords, - scheduler_proof, - .. + scheduler_proof, .. } = self.proofs.first().unwrap(); let (_, proof) = serialize_proof(scheduler_proof); - let aggregation_result_coords = if self.l1_batches[0] - .header - .protocol_version - .unwrap() - .is_pre_boojum() - { - aggregation_result_coords - .iter() - .map(|bytes| Token::Uint(U256::from_big_endian(bytes))) - .collect() + if protocol_version.is_pre_gateway() { + let proof_input = Token::Tuple(vec![ + Token::Array(Vec::new()), + Token::Array(proof.into_iter().map(Token::Uint).collect()), + ]); + + vec![prev_l1_batch_info, batches_arg, proof_input] } else { - Vec::new() - }; - let proof_input = Token::Array( - [ - aggregation_result_coords, - proof.into_iter().map(Token::Uint).collect(), - ] - .concat() - .to_vec(), - ); // todo this changed, might have to be debugged. + let proof_input = Token::Array(proof.into_iter().map(Token::Uint).collect()); - let encoded_data = encode(&[prev_l1_batch_info, batches_arg, proof_input]); - let commit_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data] - .concat() - .to_vec(); + let encoded_data = encode(&[prev_l1_batch_info, batches_arg, proof_input]); + let commit_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data] + .concat() + .to_vec(); + vec![ + Token::Uint((self.prev_l1_batch.header.number.0 + 1).into()), + Token::Uint( + (self.prev_l1_batch.header.number.0 + self.l1_batches.len() as u32).into(), + ), + Token::Bytes(commit_data), + ] + } + } else if protocol_version.is_pre_gateway() { vec![ - Token::Uint((self.prev_l1_batch.header.number.0 + 1).into()), - Token::Uint( - (self.prev_l1_batch.header.number.0 + self.l1_batches.len() as u32).into(), - ), - Token::Bytes(commit_data), + prev_l1_batch_info, + batches_arg, + Token::Tuple(vec![Token::Array(vec![]), Token::Array(vec![])]), ] } else { let encoded_data = encode(&[prev_l1_batch_info, batches_arg, Token::Array(vec![])]); 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 e39681d2e04..f9dcdaaed10 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 @@ -8,7 +8,7 @@ use zksync_types::{ ethabi::{ParamType, Token}, pubdata_da::PubdataDA, web3::{contract::Error as ContractError, keccak256}, - ProtocolVersionId, H256, STATE_DIFF_HASH_KEY_PRE_GATEWAY, U256, + ProtocolVersionId, H256, U256, }; use crate::{ @@ -19,6 +19,7 @@ use crate::{ /// These are used by the L1 Contracts to indicate what DA layer is used for pubdata const PUBDATA_SOURCE_CALLDATA: u8 = 0; const PUBDATA_SOURCE_BLOBS: u8 = 1; +const PUBDATA_SOURCE_CUSTOM_PRE_GATEWAY: u8 = 2; /// Encoding for `CommitBatchInfo` from `IExecutor.sol` for a contract running in rollup mode. #[derive(Debug)] @@ -215,23 +216,55 @@ impl Tokenizable for CommitBatchInfo<'_> { // Here we're not pushing any pubdata on purpose; no pubdata is sent in Validium mode. L1BatchCommitmentMode::Validium => vec![], })); + } else if protocol_version.is_pre_gateway() { + tokens.push(Token::Bytes(match (self.mode, self.pubdata_da) { + // Here we're not pushing any pubdata on purpose; no pubdata is sent in Validium mode. + ( + L1BatchCommitmentMode::Validium, + PubdataDA::Calldata | PubdataDA::RelayedL2Calldata, + ) => { + vec![PUBDATA_SOURCE_CALLDATA] + } + (L1BatchCommitmentMode::Validium, PubdataDA::Blobs) => { + vec![PUBDATA_SOURCE_BLOBS] + } + (L1BatchCommitmentMode::Rollup, PubdataDA::Custom) => { + panic!("Custom pubdata DA is incompatible with Rollup mode") + } + (L1BatchCommitmentMode::Validium, PubdataDA::Custom) => { + vec![PUBDATA_SOURCE_CUSTOM_PRE_GATEWAY] + } + ( + L1BatchCommitmentMode::Rollup, + PubdataDA::Calldata | PubdataDA::RelayedL2Calldata, + ) => { + // We compute and add the blob commitment to the pubdata payload so that we can verify the proof + // even if we are not using blobs. + let pubdata = self.pubdata_input(); + let blob_commitment = KzgInfo::new(&pubdata).to_blob_commitment(); + iter::once(PUBDATA_SOURCE_CALLDATA) + .chain(pubdata) + .chain(blob_commitment) + .collect() + } + (L1BatchCommitmentMode::Rollup, PubdataDA::Blobs) => { + let pubdata = self.pubdata_input(); + let pubdata_commitments = + pubdata.chunks(ZK_SYNC_BYTES_PER_BLOB).flat_map(|blob| { + let kzg_info = KzgInfo::new(blob); + kzg_info.to_pubdata_commitment() + }); + iter::once(PUBDATA_SOURCE_BLOBS) + .chain(pubdata_commitments) + .collect() + } + })); } else { - let state_diff_hash = if protocol_version.is_pre_gateway() { - self.l1_batch_with_metadata - .header - .system_logs - .iter() - .find_map(|log| { - (log.0.key == H256::from_low_u64_be(STATE_DIFF_HASH_KEY_PRE_GATEWAY)) - .then_some(log.0.value) - }) - .expect("Failed to get state_diff_hash from system logs") - } else { - self.l1_batch_with_metadata - .metadata - .state_diff_hash - .expect("Failed to get state_diff_hash from metadata") - }; + let state_diff_hash = self + .l1_batch_with_metadata + .metadata + .state_diff_hash + .expect("Failed to get state_diff_hash from metadata"); tokens.push(Token::Bytes(match (self.mode, self.pubdata_da) { // Validiums with custom DA need the inclusion data to be part of operator_da_input (L1BatchCommitmentMode::Validium, PubdataDA::Custom) => { diff --git a/core/node/api_server/src/web3/metrics.rs b/core/node/api_server/src/web3/metrics.rs index 9d8cbf813b0..2b78f58a16d 100644 --- a/core/node/api_server/src/web3/metrics.rs +++ b/core/node/api_server/src/web3/metrics.rs @@ -394,7 +394,9 @@ impl ApiMetrics { Web3Error::ProxyError(err) => { tracing::warn!("Error proxying call to main node in method `{method}`: {err}"); } - _ => { /* do nothing */ } + _ => { + tracing::debug!("Error in method `{method}`: {err:#}"); + } } let labels = Web3ErrorLabels { diff --git a/core/node/eth_sender/src/eth_tx_aggregator.rs b/core/node/eth_sender/src/eth_tx_aggregator.rs index 0d5acc624d0..92ef3fc2643 100644 --- a/core/node/eth_sender/src/eth_tx_aggregator.rs +++ b/core/node/eth_sender/src/eth_tx_aggregator.rs @@ -424,6 +424,7 @@ impl EthTxAggregator { fn encode_aggregated_op(&self, op: &AggregatedOperation) -> TxData { let mut args = vec![Token::Uint(self.rollup_chain_id.as_u64().into())]; + let is_op_pre_gateway = op.protocol_version().is_pre_gateway(); let (calldata, sidecar) = match op { AggregatedOperation::Commit(last_committed_l1_batch, l1_batches, pubdata_da) => { @@ -433,44 +434,46 @@ impl EthTxAggregator { pubdata_da: *pubdata_da, mode: self.aggregator.mode(), }; - let commit_data_base = commit_batches.into_tokens( - l1_batches[0] - .header - .protocol_version - .unwrap() - .is_pre_gateway(), - ); + let commit_data_base = commit_batches.into_tokens(is_op_pre_gateway); args.extend(commit_data_base); let commit_data = args; + let encoding_fn = if is_op_pre_gateway { + &self.functions.post_shared_bridge_commit + } else { + &self.functions.post_gateway_commit + }; + let l1_batch_for_sidecar = if PubdataDA::Blobs == self.aggregator.pubdata_da() { Some(l1_batches[0].clone()) } else { None }; - Self::encode_commit_data( - &self.functions.post_shared_bridge_commit, - &commit_data, - l1_batch_for_sidecar, - ) + Self::encode_commit_data(encoding_fn, &commit_data, l1_batch_for_sidecar) } AggregatedOperation::PublishProofOnchain(op) => { args.extend(op.into_tokens()); - let calldata = self - .functions - .post_shared_bridge_prove + let encoding_fn = if is_op_pre_gateway { + &self.functions.post_shared_bridge_prove + } else { + &self.functions.post_gateway_prove + }; + let calldata = encoding_fn .encode_input(&args) .expect("Failed to encode prove transaction data"); (calldata, None) } AggregatedOperation::Execute(op) => { args.extend(op.into_tokens()); - let calldata = self - .functions - .post_shared_bridge_execute + let encoding_fn = if is_op_pre_gateway { + &self.functions.post_shared_bridge_execute + } else { + &self.functions.post_gateway_execute + }; + let calldata = encoding_fn .encode_input(&args) .expect("Failed to encode execute transaction data"); (calldata, None) diff --git a/core/node/eth_sender/src/zksync_functions.rs b/core/node/eth_sender/src/zksync_functions.rs index b56009d0476..05c9805a4fc 100644 --- a/core/node/eth_sender/src/zksync_functions.rs +++ b/core/node/eth_sender/src/zksync_functions.rs @@ -1,4 +1,7 @@ -use zksync_contracts::{hyperchain_contract, multicall_contract, verifier_contract}; +use zksync_contracts::{ + hyperchain_contract, multicall_contract, verifier_contract, POST_SHARED_BRIDGE_COMMIT_FUNCTION, + POST_SHARED_BRIDGE_EXECUTE_FUNCTION, POST_SHARED_BRIDGE_PROVE_FUNCTION, +}; use zksync_types::ethabi::{Contract, Function}; #[derive(Debug)] @@ -6,6 +9,11 @@ pub(super) struct ZkSyncFunctions { pub(super) post_shared_bridge_commit: Function, pub(super) post_shared_bridge_prove: Function, pub(super) post_shared_bridge_execute: Function, + + pub(super) post_gateway_commit: Function, + pub(super) post_gateway_prove: Function, + pub(super) post_gateway_execute: Function, + pub(super) get_l2_bootloader_bytecode_hash: Function, pub(super) get_l2_default_account_bytecode_hash: Function, pub(super) get_verifier: Function, @@ -35,10 +43,14 @@ impl Default for ZkSyncFunctions { let verifier_contract = verifier_contract(); let multicall_contract = multicall_contract(); - let post_shared_bridge_commit = get_function(&zksync_contract, "commitBatchesSharedBridge"); - let post_shared_bridge_prove = get_function(&zksync_contract, "proveBatchesSharedBridge"); - let post_shared_bridge_execute = - get_function(&zksync_contract, "executeBatchesSharedBridge"); + let post_shared_bridge_commit = POST_SHARED_BRIDGE_COMMIT_FUNCTION.clone(); + let post_shared_bridge_prove = POST_SHARED_BRIDGE_PROVE_FUNCTION.clone(); + let post_shared_bridge_execute = POST_SHARED_BRIDGE_EXECUTE_FUNCTION.clone(); + + let post_gateway_commit = get_function(&zksync_contract, "commitBatchesSharedBridge"); + let post_gateway_prove = get_function(&zksync_contract, "proveBatchesSharedBridge"); + let post_gateway_execute = get_function(&zksync_contract, "executeBatchesSharedBridge"); + let get_l2_bootloader_bytecode_hash = get_function(&zksync_contract, "getL2BootloaderBytecodeHash"); let get_l2_default_account_bytecode_hash = @@ -53,6 +65,9 @@ impl Default for ZkSyncFunctions { post_shared_bridge_commit, post_shared_bridge_prove, post_shared_bridge_execute, + post_gateway_commit, + post_gateway_prove, + post_gateway_execute, get_l2_bootloader_bytecode_hash, get_l2_default_account_bytecode_hash, get_verifier, 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 45088b40ee8..191b4a699b9 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 @@ -136,9 +136,7 @@ impl WiringLayer for MempoolIOLayer { mempool_db_pool, &self.state_keeper_config, self.wallets.fee_account.address(), - self.contracts_config - .l2_da_validator_addr - .expect("L2 DA validator address not found"), + self.contracts_config.l2_da_validator_addr, self.genesis_config.l1_batch_commit_data_generator_mode, self.mempool_config.delay_interval(), self.zksync_network_id, diff --git a/core/node/state_keeper/src/io/mempool.rs b/core/node/state_keeper/src/io/mempool.rs index 1a89cec9a40..58e0d56be2d 100644 --- a/core/node/state_keeper/src/io/mempool.rs +++ b/core/node/state_keeper/src/io/mempool.rs @@ -51,7 +51,7 @@ pub struct MempoolIO { filter: L2TxFilter, l1_batch_params_provider: L1BatchParamsProvider, fee_account: Address, - l2_da_validator_address: Address, + l2_da_validator_address: Option
, pubdata_type: L1BatchCommitmentMode, validation_computational_gas_limit: u32, max_allowed_tx_gas_limit: U256, @@ -195,11 +195,16 @@ impl StateKeeperIO for MempoolIO { continue; } - // Pubdata type should be `Rollup` for pre-gateway batches. - let pubdata_type = if protocol_version.is_pre_gateway() { - L1BatchCommitmentMode::Rollup - } else { - self.pubdata_type + let pubdata_params = match ( + protocol_version.is_pre_gateway(), + self.l2_da_validator_address, + ) { + (true, _) => PubdataParams::default(), + (false, Some(l2_da_validator_address)) => PubdataParams { + l2_da_validator_address, + pubdata_type: self.pubdata_type, + }, + (false, None) => anyhow::bail!("L2 DA validator address not found"), }; return Ok(Some(L1BatchParams { @@ -212,10 +217,7 @@ impl StateKeeperIO for MempoolIO { // This value is effectively ignored by the protocol. virtual_blocks: 1, }, - pubdata_params: PubdataParams { - l2_da_validator_address: self.l2_da_validator_address, - pubdata_type, - }, + pubdata_params, })); } Ok(None) @@ -430,7 +432,7 @@ impl MempoolIO { pool: ConnectionPool, config: &StateKeeperConfig, fee_account: Address, - l2_da_validator_address: Address, + l2_da_validator_address: Option
, pubdata_type: L1BatchCommitmentMode, delay_interval: Duration, chain_id: L2ChainId, diff --git a/core/node/state_keeper/src/io/tests/tester.rs b/core/node/state_keeper/src/io/tests/tester.rs index 5b14922e6cf..6b7fc260b66 100644 --- a/core/node/state_keeper/src/io/tests/tester.rs +++ b/core/node/state_keeper/src/io/tests/tester.rs @@ -134,7 +134,7 @@ impl Tester { pool, &config, wallets.state_keeper.unwrap().fee_account.address(), - Default::default(), + Some(Default::default()), Default::default(), Duration::from_secs(1), L2ChainId::from(270), diff --git a/etc/multivm_bootloaders/vm_1_5_0_increased_memory/fee_estimate.yul/fee_estimate.yul.zbin b/etc/multivm_bootloaders/vm_1_5_0_increased_memory/fee_estimate.yul/fee_estimate.yul.zbin index 82cfdf96d3dcbe5cd57eef0ed7b3461964c1788c..75ee6377bdb645532c55f06f0e883cc078b5bd2b 100644 GIT binary patch delta 80 zcmV-W0I&a`)C8c^1c0;w!v-C*^24UR)vW-oDW}W3GTfuXAGQd!%~JUD1!_1)x8Mc= mAR{1zcQH(3Oeez6yXH}a$8MQ;1Ncjx9Nz#Kn24dEl^nfGIwrmV delta 80 zcmV-W0I&a`)C8c^1c0;w!v-CtU59vwMpp?BEwiYutJIOD^EEF7$eyjM-IC_Ix8Mc= mAR{0i;18&-EGn3?Hn@(Oi!{6{*gdi_rolcg7P$Qg`oaO=awT>E diff --git a/etc/multivm_bootloaders/vm_1_5_0_increased_memory/gas_test.yul/gas_test.yul.zbin b/etc/multivm_bootloaders/vm_1_5_0_increased_memory/gas_test.yul/gas_test.yul.zbin index c712f82cf0ec5145e4248c88cf8e48ac6a8761f9..63898975f4825f551c49f2f7f1d9ac293132966d 100644 GIT binary patch delta 77 zcmV-T0J8t!wFKa`1h9kn9kcSoroGjz0In&g%eyk%qr)Gz2(`^p`11v7I7hRf_#h%6 jy73)7D_ugL(hyhJ_<|n-!lEmoN-aa!txw|=0J|5~Sq3KV delta 77 zcmV-T0J8t!wFKa`1h9kn9i?4|c!x$;2@fr^sIIHjk)`uBF9gV*t*hOV=DM?>_#h%6 j-(YF%{qB6{7R$+*N=9Q9l_qicu!YUc@Gi8L(dXlEL`5qK diff --git a/etc/multivm_bootloaders/vm_1_5_0_increased_memory/playground_batch.yul/playground_batch.yul.zbin b/etc/multivm_bootloaders/vm_1_5_0_increased_memory/playground_batch.yul/playground_batch.yul.zbin index 06829ec6331681685fcd07f94c8bf9d5a0e3ac69..b1a5e063d84b66ebea9a6e021ef42d29b1346760 100644 GIT binary patch delta 80 zcmV-W0I&bx)db+x1c0;wBL^L`^24UR)vW-oDW}W3GTfuXAGQd!%~JUD1!_1)w?GF0 mfFmHtf0L(63WdYOS7J7@C~q5w@LxJ& delta 80 zcmV-W0I&bx)db+x1c0;wBL^L&U59vwMpp?BEwiYutJIOD^EEF7$eyjM-IC_Iw?GF0 mfFmFUMVsD~7)u%i_>cPYp{rJ)KD*{ZGNJ&R!iDP3h{=rJOD6mP diff --git a/etc/multivm_bootloaders/vm_1_5_0_increased_memory/proved_batch.yul/proved_batch.yul.zbin b/etc/multivm_bootloaders/vm_1_5_0_increased_memory/proved_batch.yul/proved_batch.yul.zbin index 4de1149c20af6e2a719fe121471f873a833497d6..26bb767d1b306421afbad07509e3e3e0b1e68f8c 100644 GIT binary patch delta 77 zcmV-T0J8t!xdh<31h5189kcSoroGjz0In&g%eyk%qr)Gz2(`^p`11v7I7hP}`k*2p jXc{9jR7OBR^0>~&a5T`->?Yn|vctJGM$vQ67&>EnJtHTy delta 77 zcmV-T0J8t!xdh<31h5189i?4|c!x$;2@fr^sIIHjk)`uBF9gV*t*hOV=DM>W`k*2p jH;rzvxTnF<3ia_2jl_uN5XMY|2WZNEKcAsqkIj|G1nww^ From b3cff29e05254a29361ea2ce99eb0fcfba85edc0 Mon Sep 17 00:00:00 2001 From: perekopskiy Date: Tue, 1 Oct 2024 10:23:29 +0300 Subject: [PATCH 05/10] refactor --- .../src/i_executor/methods/commit_batches.rs | 10 ++++++---- .../src/i_executor/methods/execute_batches.rs | 4 ++-- .../src/i_executor/methods/prove_batches.rs | 8 ++++---- core/node/consistency_checker/src/tests/mod.rs | 4 ++-- core/node/eth_sender/src/eth_tx_aggregator.rs | 2 +- 5 files changed, 15 insertions(+), 13 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 948108eaa62..a805876ca40 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,8 +6,9 @@ use zksync_types::{ use crate::{ i_executor::structures::{CommitBatchInfo, StoredBatchInfo, SUPPORTED_ENCODING_VERSION}, - Tokenizable, + Tokenizable, Tokenize, }; + /// Input required to encode `commitBatches` call for a contract #[derive(Debug)] pub struct CommitBatches<'a> { @@ -17,8 +18,9 @@ pub struct CommitBatches<'a> { pub mode: L1BatchCommitmentMode, } -impl CommitBatches<'_> { - pub fn into_tokens(self, pre_gateway: bool) -> Vec { +impl Tokenize for &CommitBatches<'_> { + fn into_tokens(self) -> Vec { + let protocol_version = self.l1_batches[0].header.protocol_version.unwrap(); let stored_batch_info = StoredBatchInfo::from(self.last_committed_l1_batch).into_token(); let l1_batches_to_commit: Vec = self .l1_batches @@ -26,7 +28,7 @@ impl CommitBatches<'_> { .map(|batch| CommitBatchInfo::new(self.mode, batch, self.pubdata_da).into_token()) .collect(); - if pre_gateway { + if protocol_version.is_pre_gateway() { vec![stored_batch_info, Token::Array(l1_batches_to_commit)] } else { let encoded_data = encode(&[ diff --git a/core/lib/l1_contract_interface/src/i_executor/methods/execute_batches.rs b/core/lib/l1_contract_interface/src/i_executor/methods/execute_batches.rs index 65aea1944b2..e2e29bfefcf 100644 --- a/core/lib/l1_contract_interface/src/i_executor/methods/execute_batches.rs +++ b/core/lib/l1_contract_interface/src/i_executor/methods/execute_batches.rs @@ -41,7 +41,7 @@ impl Tokenize for &ExecuteBatches { .collect(), ), ]); - let commit_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data] + let execute_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data] .concat() .to_vec(); @@ -54,7 +54,7 @@ impl Tokenize for &ExecuteBatches { .0 .into(), ), - Token::Bytes(commit_data), + Token::Bytes(execute_data), ] } } diff --git a/core/lib/l1_contract_interface/src/i_executor/methods/prove_batches.rs b/core/lib/l1_contract_interface/src/i_executor/methods/prove_batches.rs index 60c68f69080..a54cf407d09 100644 --- a/core/lib/l1_contract_interface/src/i_executor/methods/prove_batches.rs +++ b/core/lib/l1_contract_interface/src/i_executor/methods/prove_batches.rs @@ -52,7 +52,7 @@ impl Tokenize for &ProveBatches { let proof_input = Token::Array(proof.into_iter().map(Token::Uint).collect()); let encoded_data = encode(&[prev_l1_batch_info, batches_arg, proof_input]); - let commit_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data] + let prove_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data] .concat() .to_vec(); @@ -61,7 +61,7 @@ impl Tokenize for &ProveBatches { Token::Uint( (self.prev_l1_batch.header.number.0 + self.l1_batches.len() as u32).into(), ), - Token::Bytes(commit_data), + Token::Bytes(prove_data), ] } } else if protocol_version.is_pre_gateway() { @@ -72,7 +72,7 @@ impl Tokenize for &ProveBatches { ] } else { let encoded_data = encode(&[prev_l1_batch_info, batches_arg, Token::Array(vec![])]); - let commit_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data] + let prove_data = [[SUPPORTED_ENCODING_VERSION].to_vec(), encoded_data] .concat() .to_vec(); @@ -81,7 +81,7 @@ impl Tokenize for &ProveBatches { Token::Uint( (self.prev_l1_batch.header.number.0 + self.l1_batches.len() as u32).into(), ), - Token::Bytes(commit_data), + Token::Bytes(prove_data), ] } } diff --git a/core/node/consistency_checker/src/tests/mod.rs b/core/node/consistency_checker/src/tests/mod.rs index 07e750b41c3..296780513e0 100644 --- a/core/node/consistency_checker/src/tests/mod.rs +++ b/core/node/consistency_checker/src/tests/mod.rs @@ -8,7 +8,7 @@ use tokio::sync::mpsc; use zksync_config::GenesisConfig; use zksync_dal::Connection; use zksync_eth_client::{clients::MockSettlementLayer, Options}; -use zksync_l1_contract_interface::{i_executor::methods::CommitBatches, Tokenizable}; +use zksync_l1_contract_interface::{i_executor::methods::CommitBatches, Tokenizable, Tokenize}; use zksync_node_genesis::{insert_genesis_batch, mock_genesis_config, GenesisParams}; use zksync_node_test_utils::{ create_l1_batch, create_l1_batch_metadata, l1_batch_metadata_to_commitment_artifacts, @@ -67,7 +67,7 @@ pub(crate) fn build_commit_tx_input_data( pubdata_da: PubdataDA::Calldata, mode, } - .into_tokens(protocol_version.is_pre_gateway()); + .into_tokens(); if protocol_version.is_pre_boojum() { PRE_BOOJUM_COMMIT_FUNCTION.encode_input(&tokens).unwrap() diff --git a/core/node/eth_sender/src/eth_tx_aggregator.rs b/core/node/eth_sender/src/eth_tx_aggregator.rs index 92ef3fc2643..1c618a53795 100644 --- a/core/node/eth_sender/src/eth_tx_aggregator.rs +++ b/core/node/eth_sender/src/eth_tx_aggregator.rs @@ -434,7 +434,7 @@ impl EthTxAggregator { pubdata_da: *pubdata_da, mode: self.aggregator.mode(), }; - let commit_data_base = commit_batches.into_tokens(is_op_pre_gateway); + let commit_data_base = commit_batches.into_tokens(); args.extend(commit_data_base); From 901b23664eccfbc24b510a26a14e20d2b3bdef2c Mon Sep 17 00:00:00 2001 From: perekopskiy Date: Tue, 1 Oct 2024 11:13:37 +0300 Subject: [PATCH 06/10] rework bridge config --- core/bin/external_node/src/config/mod.rs | 12 +++-- core/bin/external_node/src/node_builder.rs | 2 +- core/lib/config/src/configs/contracts.rs | 7 +++ core/lib/config/src/testonly.rs | 1 + core/lib/env_config/src/contracts.rs | 2 + core/lib/protobuf_config/src/contracts.rs | 13 ++++- .../src/proto/config/contracts.proto | 3 +- core/lib/types/src/api/mod.rs | 2 +- .../web3/backend_jsonrpsee/namespaces/zks.rs | 4 +- .../api_server/src/web3/namespaces/zks.rs | 16 ++----- core/node/api_server/src/web3/state.rs | 2 +- .../layers/state_keeper/output_handler.rs | 47 +++++++++++++++++-- core/node/state_keeper/src/io/persistence.rs | 12 ++--- .../io/seal_logic/l2_block_seal_subtasks.rs | 12 ++--- .../state_keeper/src/io/seal_logic/mod.rs | 6 +-- core/node/state_keeper/src/io/tests/mod.rs | 4 +- core/node/state_keeper/src/updates/mod.rs | 6 +-- zk_toolbox/crates/config/src/contracts.rs | 11 ++--- 18 files changed, 105 insertions(+), 57 deletions(-) diff --git a/core/bin/external_node/src/config/mod.rs b/core/bin/external_node/src/config/mod.rs index ae3c066af01..94c7ea74866 100644 --- a/core/bin/external_node/src/config/mod.rs +++ b/core/bin/external_node/src/config/mod.rs @@ -110,8 +110,12 @@ pub(crate) struct RemoteENConfig { // the `l2_erc20_bridge_addr` and `l2_shared_bridge_addr` are basically the same contract, but with // a different name, with names adapted only for consistency. pub l1_shared_bridge_proxy_addr: Option
, + /// Contract address that serves as a shared bridge on L2. + /// It is expected that `L2SharedBridge` is used before gateway upgrade, and `L2AssetRouter` is used after. pub l2_shared_bridge_addr: Option
, - pub l2_token_deployer_addr: Option
, + /// Address of `L2SharedBridge` that was used before gateway upgrade. + /// `None` if chain genesis used post-gateway protocol version. + pub l2_legacy_shared_bridge_addr: Option
, pub l1_erc20_bridge_proxy_addr: Option
, pub l2_erc20_bridge_addr: Option
, pub l1_weth_bridge_addr: Option
, @@ -199,7 +203,7 @@ impl RemoteENConfig { l2_erc20_bridge_addr: l2_erc20_default_bridge, l1_shared_bridge_proxy_addr: bridges.l1_shared_default_bridge, l2_shared_bridge_addr: l2_erc20_shared_bridge, - l2_token_deployer_addr: bridges.l2_token_deployer, + l2_legacy_shared_bridge_addr: bridges.l2_legacy_shared_bridge, l1_weth_bridge_addr: bridges.l1_weth_bridge, l2_weth_bridge_addr: bridges.l2_weth_bridge, base_token_addr, @@ -230,7 +234,7 @@ impl RemoteENConfig { l1_shared_bridge_proxy_addr: Some(Address::repeat_byte(5)), l1_weth_bridge_addr: None, l2_shared_bridge_addr: Some(Address::repeat_byte(6)), - l2_token_deployer_addr: Some(Address::repeat_byte(6)), + l2_legacy_shared_bridge_addr: Some(Address::repeat_byte(7)), l1_batch_commit_data_generator_mode: L1BatchCommitmentMode::Rollup, dummy_verifier: true, } @@ -1404,7 +1408,7 @@ impl From<&ExternalNodeConfig> for InternalApiConfig { l2_shared_default_bridge: config.remote.l2_shared_bridge_addr, l1_weth_bridge: config.remote.l1_weth_bridge_addr, l2_weth_bridge: config.remote.l2_weth_bridge_addr, - l2_token_deployer: config.remote.l2_token_deployer_addr, + l2_legacy_shared_bridge: config.remote.l2_legacy_shared_bridge_addr, }, bridgehub_proxy_addr: config.remote.bridgehub_proxy_addr, state_transition_proxy_addr: config.remote.state_transition_proxy_addr, diff --git a/core/bin/external_node/src/node_builder.rs b/core/bin/external_node/src/node_builder.rs index fe34b9a8e05..e6284cb7f24 100644 --- a/core/bin/external_node/src/node_builder.rs +++ b/core/bin/external_node/src/node_builder.rs @@ -192,7 +192,7 @@ impl ExternalNodeBuilder { const OPTIONAL_BYTECODE_COMPRESSION: bool = true; let persistence_layer = OutputHandlerLayer::new( - self.config.remote.l2_token_deployer_addr, + self.config.remote.l2_legacy_shared_bridge_addr, self.config.optional.l2_block_seal_queue_capacity, ) .with_pre_insert_txs(true) // EN requires txs to be pre-inserted. diff --git a/core/lib/config/src/configs/contracts.rs b/core/lib/config/src/configs/contracts.rs index d96983c9719..2a17f74265d 100644 --- a/core/lib/config/src/configs/contracts.rs +++ b/core/lib/config/src/configs/contracts.rs @@ -29,7 +29,13 @@ pub struct ContractsConfig { pub diamond_proxy_addr: Address, pub validator_timelock_addr: Address, pub l1_shared_bridge_proxy_addr: Option
, + /// Contract address that serves as a shared bridge on L2. + /// It is expected that `L2SharedBridge` is used before gateway upgrade, and `L2AssetRouter` is used after. pub l2_shared_bridge_addr: Option
, + /// Address of `L2SharedBridge` that was used before gateway upgrade. + /// `None` if chain genesis used post-gateway protocol version. + /// If present it will be used as L2 token deployer address. + pub l2_legacy_shared_bridge_addr: Option
, pub l1_erc20_bridge_proxy_addr: Option
, pub l2_erc20_bridge_addr: Option
, pub l1_weth_bridge_proxy_addr: Option
, @@ -60,6 +66,7 @@ impl ContractsConfig { l2_erc20_bridge_addr: Some(Address::repeat_byte(0x0c)), l1_shared_bridge_proxy_addr: Some(Address::repeat_byte(0x0e)), l2_shared_bridge_addr: Some(Address::repeat_byte(0x0f)), + l2_legacy_shared_bridge_addr: Some(Address::repeat_byte(0xff)), l1_weth_bridge_proxy_addr: Some(Address::repeat_byte(0x0b)), l2_weth_bridge_addr: Some(Address::repeat_byte(0x0c)), l2_testnet_paymaster_addr: Some(Address::repeat_byte(0x11)), diff --git a/core/lib/config/src/testonly.rs b/core/lib/config/src/testonly.rs index ea12d053e62..abb23052149 100644 --- a/core/lib/config/src/testonly.rs +++ b/core/lib/config/src/testonly.rs @@ -254,6 +254,7 @@ impl Distribution for EncodeDist { l2_erc20_bridge_addr: self.sample_opt(|| rng.gen()), l1_shared_bridge_proxy_addr: self.sample_opt(|| rng.gen()), l2_shared_bridge_addr: self.sample_opt(|| rng.gen()), + l2_legacy_shared_bridge_addr: self.sample_opt(|| rng.gen()), l1_weth_bridge_proxy_addr: self.sample_opt(|| rng.gen()), l2_weth_bridge_addr: self.sample_opt(|| rng.gen()), l2_testnet_paymaster_addr: self.sample_opt(|| rng.gen()), diff --git a/core/lib/env_config/src/contracts.rs b/core/lib/env_config/src/contracts.rs index 01756fd2fd9..b9ca4e88d07 100644 --- a/core/lib/env_config/src/contracts.rs +++ b/core/lib/env_config/src/contracts.rs @@ -81,6 +81,7 @@ mod tests { l2_weth_bridge_addr: Some(addr("8656770FA78c830456B00B4fFCeE6b1De0e1b888")), l1_shared_bridge_proxy_addr: Some(addr("8656770FA78c830456B00B4fFCeE6b1De0e1b888")), l2_shared_bridge_addr: Some(addr("8656770FA78c830456B00B4fFCeE6b1De0e1b888")), + l2_legacy_shared_bridge_addr: Some(addr("8656770FA78c830456B00B4fFCeE6b1De0e1b888")), l2_testnet_paymaster_addr: Some(addr("FC073319977e314F251EAE6ae6bE76B0B3BAeeCF")), l1_multicall3_addr: addr("0xcA11bde05977b3631167028862bE2a173976CA11"), ecosystem_contracts: Some(EcosystemContracts { @@ -118,6 +119,7 @@ CONTRACTS_L2_CONSENSUS_REGISTRY_ADDR="D64e136566a9E04eb05B30184fF577F52682D182" CONTRACTS_L1_MULTICALL3_ADDR="0xcA11bde05977b3631167028862bE2a173976CA11" CONTRACTS_L1_SHARED_BRIDGE_PROXY_ADDR="0x8656770FA78c830456B00B4fFCeE6b1De0e1b888" CONTRACTS_L2_SHARED_BRIDGE_ADDR="0x8656770FA78c830456B00B4fFCeE6b1De0e1b888" +CONTRACTS_L2_LEGACY_SHARED_BRIDGE_ADDR="0x8656770FA78c830456B00B4fFCeE6b1De0e1b888" CONTRACTS_BRIDGEHUB_PROXY_ADDR="0x35ea7f92f4c5f433efe15284e99c040110cf6297" CONTRACTS_STATE_TRANSITION_PROXY_ADDR="0xd90f1c081c6117241624e97cb6147257c3cb2097" CONTRACTS_TRANSPARENT_PROXY_ADMIN_ADDR="0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347e5" diff --git a/core/lib/protobuf_config/src/contracts.rs b/core/lib/protobuf_config/src/contracts.rs index 616334b056c..546bffb279c 100644 --- a/core/lib/protobuf_config/src/contracts.rs +++ b/core/lib/protobuf_config/src/contracts.rs @@ -76,6 +76,12 @@ impl ProtoRepr for proto::Contracts { .map(|x| parse_h160(x)) .transpose() .context("l2_shared_bridge_addr")?, + l2_legacy_shared_bridge_addr: l2 + .legacy_shared_bridge + .as_ref() + .map(|x| parse_h160(x)) + .transpose() + .context("l2_legacy_shared_bridge_addr")?, l1_weth_bridge_proxy_addr: weth_bridge .as_ref() .and_then(|bridge| bridge.l1_address.as_ref().map(|x| parse_h160(x))) @@ -114,7 +120,7 @@ impl ProtoRepr for proto::Contracts { .transpose() .context("base_token_addr")?, l2_da_validator_addr: l2 - .l2_da_validator_addr + .da_validator_addr .as_ref() .map(|x| parse_h160(x)) .transpose() @@ -160,7 +166,10 @@ impl ProtoRepr for proto::Contracts { }), l2: Some(proto::L2 { testnet_paymaster_addr: this.l2_testnet_paymaster_addr.map(|a| format!("{:?}", a)), - l2_da_validator_addr: this.l2_da_validator_addr.map(|a| format!("{:?}", a)), + da_validator_addr: this.l2_da_validator_addr.map(|a| format!("{:?}", a)), + legacy_shared_bridge: this + .l2_legacy_shared_bridge_addr + .map(|a| format!("{:?}", a)), }), bridges: Some(proto::Bridges { shared: Some(proto::Bridge { diff --git a/core/lib/protobuf_config/src/proto/config/contracts.proto b/core/lib/protobuf_config/src/proto/config/contracts.proto index 655c67b003d..fedde21e41c 100644 --- a/core/lib/protobuf_config/src/proto/config/contracts.proto +++ b/core/lib/protobuf_config/src/proto/config/contracts.proto @@ -21,7 +21,8 @@ message L1 { message L2 { optional string testnet_paymaster_addr = 1; // optional; H160 - optional string l2_da_validator_addr = 2; // optional; H160 + optional string da_validator_addr = 2; // optional; H160 + optional string legacy_shared_bridge = 3; // optional; H160 } message Bridge { diff --git a/core/lib/types/src/api/mod.rs b/core/lib/types/src/api/mod.rs index 2fae3b01c7c..e583d7abe58 100644 --- a/core/lib/types/src/api/mod.rs +++ b/core/lib/types/src/api/mod.rs @@ -267,7 +267,7 @@ pub struct BridgeAddresses { pub l2_erc20_default_bridge: Option
, pub l1_weth_bridge: Option
, pub l2_weth_bridge: Option
, - pub l2_token_deployer: Option
, + pub l2_legacy_shared_bridge: Option
, } #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] diff --git a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/zks.rs b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/zks.rs index 14f3e6e7be4..b55c6ca5946 100644 --- a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/zks.rs +++ b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/zks.rs @@ -55,9 +55,7 @@ impl ZksNamespaceServer for ZksNamespace { } async fn get_bridge_contracts(&self) -> RpcResult { - self.get_bridge_contracts_impl() - .await - .map_err(|err| self.current_method().map_err(err)) + Ok(self.get_bridge_contracts_impl()) } async fn l1_chain_id(&self) -> RpcResult { diff --git a/core/node/api_server/src/web3/namespaces/zks.rs b/core/node/api_server/src/web3/namespaces/zks.rs index 05ab8ddc271..78f3edf83f9 100644 --- a/core/node/api_server/src/web3/namespaces/zks.rs +++ b/core/node/api_server/src/web3/namespaces/zks.rs @@ -7,7 +7,7 @@ use zksync_dal::{Connection, Core, CoreDal, DalError}; use zksync_metadata_calculator::api_server::TreeApiError; use zksync_mini_merkle_tree::MiniMerkleTree; use zksync_multivm::interface::VmExecutionResultAndLogs; -use zksync_system_constants::{DEFAULT_L2_TX_GAS_PER_PUBDATA_BYTE, L2_ASSET_ROUTER_ADDRESS}; +use zksync_system_constants::DEFAULT_L2_TX_GAS_PER_PUBDATA_BYTE; use zksync_types::{ api::{ state_override::StateOverride, BlockDetails, BridgeAddresses, ChainAggProof, GetLogsFilter, @@ -147,18 +147,8 @@ impl ZksNamespace { self.state.api_config.l2_testnet_paymaster_addr } - pub async fn get_bridge_contracts_impl(&self) -> Result { - let mut bridge_contracts = self.state.api_config.bridge_addresses.clone(); - let mut storage = self.state.acquire_connection().await?; - - // `L2_ASSET_ROUTER_ADDRESS` should be used as l2 bridge after gateway upgrade. - let pending_protocol_version = storage.blocks_dal().pending_protocol_version().await?; - if !pending_protocol_version.is_pre_gateway() { - bridge_contracts.l2_erc20_default_bridge = None; - bridge_contracts.l2_shared_default_bridge = Some(L2_ASSET_ROUTER_ADDRESS); - } - - Ok(bridge_contracts) + pub fn get_bridge_contracts_impl(&self) -> BridgeAddresses { + self.state.api_config.bridge_addresses.clone() } pub fn l1_chain_id_impl(&self) -> U64 { diff --git a/core/node/api_server/src/web3/state.rs b/core/node/api_server/src/web3/state.rs index c72380f2989..0c236710c07 100644 --- a/core/node/api_server/src/web3/state.rs +++ b/core/node/api_server/src/web3/state.rs @@ -156,7 +156,7 @@ impl InternalApiConfig { .l1_weth_bridge_proxy_addr .unwrap_or_default(), ), - l2_token_deployer: contracts_config.l2_shared_bridge_addr, + l2_legacy_shared_bridge: contracts_config.l2_legacy_shared_bridge_addr, }, bridgehub_proxy_addr: contracts_config .ecosystem_contracts diff --git a/core/node/node_framework/src/implementations/layers/state_keeper/output_handler.rs b/core/node/node_framework/src/implementations/layers/state_keeper/output_handler.rs index 3c1c276447e..7a0de619364 100644 --- a/core/node/node_framework/src/implementations/layers/state_keeper/output_handler.rs +++ b/core/node/node_framework/src/implementations/layers/state_keeper/output_handler.rs @@ -1,10 +1,12 @@ use anyhow::Context as _; +use zksync_dal::{Core, CoreDal}; +use zksync_db_connection::connection_pool::ConnectionPool; use zksync_node_framework_derive::FromContext; use zksync_state_keeper::{ io::seal_logic::l2_block_seal_subtasks::L2BlockSealProcess, L2BlockSealerTask, OutputHandler, StateKeeperPersistence, TreeWritesPersistence, }; -use zksync_types::Address; +use zksync_types::{Address, ProtocolVersionId}; use crate::{ implementations::resources::{ @@ -35,7 +37,7 @@ use crate::{ /// - `L2BlockSealerTask` #[derive(Debug)] pub struct OutputHandlerLayer { - l2_shared_bridge_addr: Option
, + l2_legacy_shared_bridge_addr: Option
, l2_block_seal_queue_capacity: usize, /// Whether transactions should be pre-inserted to DB. /// Should be set to `true` for EN's IO as EN doesn't store transactions in DB @@ -64,11 +66,11 @@ pub struct Output { impl OutputHandlerLayer { pub fn new( - l2_shared_bridge_addr: Option
, + l2_legacy_shared_bridge_addr: Option
, l2_block_seal_queue_capacity: usize, ) -> Self { Self { - l2_shared_bridge_addr, + l2_legacy_shared_bridge_addr, l2_block_seal_queue_capacity, pre_insert_txs: false, protective_reads_persistence_enabled: false, @@ -87,6 +89,38 @@ impl OutputHandlerLayer { self.protective_reads_persistence_enabled = protective_reads_persistence_enabled; self } + + async fn validate_l2_legacy_shared_bridge_addr( + &self, + pool: &ConnectionPool, + ) -> Result<(), WiringError> { + let mut connection = pool.connection().await.context("Get DB connection")?; + + if let Some(l2_block) = connection + .blocks_dal() + .get_earliest_l2_block_number() + .await + .context("failed to load earliest l2 block number")? + { + let header = connection + .blocks_dal() + .get_l2_block_header(l2_block) + .await + .context("failed to load L2 block header")? + .context("missing L2 block header")?; + let protocol_version = header + .protocol_version + .unwrap_or_else(ProtocolVersionId::last_potentially_undefined); + + if protocol_version.is_pre_gateway() && self.l2_legacy_shared_bridge_addr.is_none() { + return Err(WiringError::Configuration( + "Missing `l2_legacy_shared_bridge_addr` for chain that was initialized before gateway upgrade".to_string() + )); + } + } + + Ok(()) + } } #[async_trait::async_trait] @@ -106,9 +140,12 @@ impl WiringLayer for OutputHandlerLayer { .get_custom(L2BlockSealProcess::subtasks_len()) .await .context("Get master pool")?; + self.validate_l2_legacy_shared_bridge_addr(&persistence_pool) + .await?; + let (mut persistence, l2_block_sealer) = StateKeeperPersistence::new( persistence_pool.clone(), - self.l2_shared_bridge_addr, + self.l2_legacy_shared_bridge_addr, self.l2_block_seal_queue_capacity, ); if self.pre_insert_txs { diff --git a/core/node/state_keeper/src/io/persistence.rs b/core/node/state_keeper/src/io/persistence.rs index e890cba41b4..dc854c9e58f 100644 --- a/core/node/state_keeper/src/io/persistence.rs +++ b/core/node/state_keeper/src/io/persistence.rs @@ -29,7 +29,7 @@ struct Completable { #[derive(Debug)] pub struct StateKeeperPersistence { pool: ConnectionPool, - l2_shared_bridge_addr: Option
, + l2_legacy_shared_bridge_addr: Option
, pre_insert_txs: bool, insert_protective_reads: bool, commands_sender: mpsc::Sender>, @@ -45,7 +45,7 @@ impl StateKeeperPersistence { /// `command_capacity` for unprocessed sealing commands. pub fn new( pool: ConnectionPool, - l2_shared_bridge_addr: Option
, + l2_legacy_shared_bridge_addr: Option
, mut command_capacity: usize, ) -> (Self, L2BlockSealerTask) { let is_sync = command_capacity == 0; @@ -60,7 +60,7 @@ impl StateKeeperPersistence { }; let this = Self { pool, - l2_shared_bridge_addr, + l2_legacy_shared_bridge_addr, pre_insert_txs: false, insert_protective_reads: true, commands_sender, @@ -157,8 +157,8 @@ impl StateKeeperOutputHandler for StateKeeperPersistence { } async fn handle_l2_block(&mut self, updates_manager: &UpdatesManager) -> anyhow::Result<()> { - let command = - updates_manager.seal_l2_block_command(self.l2_shared_bridge_addr, self.pre_insert_txs); + let command = updates_manager + .seal_l2_block_command(self.l2_legacy_shared_bridge_addr, self.pre_insert_txs); self.submit_l2_block(command).await; Ok(()) } @@ -174,7 +174,7 @@ impl StateKeeperOutputHandler for StateKeeperPersistence { updates_manager .seal_l1_batch( self.pool.clone(), - self.l2_shared_bridge_addr, + self.l2_legacy_shared_bridge_addr, self.insert_protective_reads, ) .await diff --git a/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs b/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs index bd283f23735..9a57da5e18d 100644 --- a/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs +++ b/core/node/state_keeper/src/io/seal_logic/l2_block_seal_subtasks.rs @@ -18,7 +18,7 @@ use crate::{ }; fn extract_added_tokens( - l2_shared_bridge_addr: Address, + l2_token_deployer_addr: Address, all_generated_events: &[VmEvent], ) -> Vec { let deployed_tokens = all_generated_events @@ -28,7 +28,7 @@ fn extract_added_tokens( event.address == CONTRACT_DEPLOYER_ADDRESS && event.indexed_topics.len() == 4 && event.indexed_topics[0] == VmEvent::DEPLOY_EVENT_SIGNATURE - && h256_to_account_address(&event.indexed_topics[1]) == l2_shared_bridge_addr + && h256_to_account_address(&event.indexed_topics[1]) == l2_token_deployer_addr }) .map(|event| h256_to_account_address(&event.indexed_topics[3])); @@ -333,11 +333,11 @@ impl L2BlockSealSubtask for InsertTokensSubtask { connection: &mut Connection<'_, Core>, ) -> anyhow::Result<()> { let is_fictive = command.is_l2_block_fictive(); - let deployer_address = command - .l2_shared_bridge_addr + let token_deployer_address = command + .l2_legacy_shared_bridge_addr .unwrap_or(L2_NATIVE_TOKEN_VAULT_ADDRESS); let progress = L2_BLOCK_METRICS.start(L2BlockSealStage::ExtractAddedTokens, is_fictive); - let added_tokens = extract_added_tokens(deployer_address, &command.l2_block.events); + let added_tokens = extract_added_tokens(token_deployer_address, &command.l2_block.events); progress.observe(added_tokens.len()); @@ -557,7 +557,7 @@ mod tests { base_fee_per_gas: Default::default(), base_system_contracts_hashes: Default::default(), protocol_version: Some(ProtocolVersionId::latest()), - l2_shared_bridge_addr: Default::default(), + l2_legacy_shared_bridge_addr: Default::default(), pre_insert_txs: false, }; diff --git a/core/node/state_keeper/src/io/seal_logic/mod.rs b/core/node/state_keeper/src/io/seal_logic/mod.rs index 643042a927a..fd9a3d82af7 100644 --- a/core/node/state_keeper/src/io/seal_logic/mod.rs +++ b/core/node/state_keeper/src/io/seal_logic/mod.rs @@ -46,7 +46,7 @@ impl UpdatesManager { pub(super) async fn seal_l1_batch( &self, pool: ConnectionPool, - l2_shared_bridge_addr: Option
, + l2_legacy_shared_bridge_addr: Option
, insert_protective_reads: bool, ) -> anyhow::Result<()> { let started_at = Instant::now(); @@ -59,7 +59,7 @@ impl UpdatesManager { let progress = L1_BATCH_METRICS.start(L1BatchSealStage::FictiveL2Block); // Seal fictive L2 block with last events and storage logs. let l2_block_command = self.seal_l2_block_command( - l2_shared_bridge_addr, + l2_legacy_shared_bridge_addr, false, // fictive L2 blocks don't have txs, so it's fine to pass `false` here. ); @@ -335,7 +335,7 @@ impl L2BlockSealCommand { /// the bootloader enters the "tip" phase in which it can still generate events (e.g., /// one for sending fees to the operator). /// - /// `l2_shared_bridge_addr` is required to extract the information on newly added tokens. + /// `l2_legacy_shared_bridge_addr` is required to extract the information on newly added tokens. async fn seal_inner( &self, strategy: &mut SealStrategy<'_>, diff --git a/core/node/state_keeper/src/io/tests/mod.rs b/core/node/state_keeper/src/io/tests/mod.rs index 5871148dcd3..4cf4a7b5a70 100644 --- a/core/node/state_keeper/src/io/tests/mod.rs +++ b/core/node/state_keeper/src/io/tests/mod.rs @@ -285,7 +285,7 @@ async fn processing_storage_logs_when_sealing_l2_block() { pubdata_params: Default::default(), base_system_contracts_hashes: BaseSystemContractsHashes::default(), protocol_version: Some(ProtocolVersionId::latest()), - l2_shared_bridge_addr: Default::default(), + l2_legacy_shared_bridge_addr: Default::default(), pre_insert_txs: false, }; connection_pool @@ -375,7 +375,7 @@ async fn processing_events_when_sealing_l2_block() { base_fee_per_gas: 10, base_system_contracts_hashes: BaseSystemContractsHashes::default(), protocol_version: Some(ProtocolVersionId::latest()), - l2_shared_bridge_addr: Default::default(), + l2_legacy_shared_bridge_addr: Default::default(), pre_insert_txs: false, }; pool.connection() diff --git a/core/node/state_keeper/src/updates/mod.rs b/core/node/state_keeper/src/updates/mod.rs index 5d29061c70e..9d12d86de6f 100644 --- a/core/node/state_keeper/src/updates/mod.rs +++ b/core/node/state_keeper/src/updates/mod.rs @@ -85,7 +85,7 @@ impl UpdatesManager { pub(crate) fn seal_l2_block_command( &self, - l2_shared_bridge_addr: Option
, + l2_legacy_shared_bridge_addr: Option
, pre_insert_txs: bool, ) -> L2BlockSealCommand { L2BlockSealCommand { @@ -98,7 +98,7 @@ impl UpdatesManager { pubdata_params: self.pubdata_params, base_system_contracts_hashes: self.base_system_contract_hashes, protocol_version: Some(self.protocol_version), - l2_shared_bridge_addr, + l2_legacy_shared_bridge_addr, pre_insert_txs, } } @@ -209,7 +209,7 @@ pub struct L2BlockSealCommand { pub base_fee_per_gas: u64, pub base_system_contracts_hashes: BaseSystemContractsHashes, pub protocol_version: Option, - pub l2_shared_bridge_addr: Option
, + pub l2_legacy_shared_bridge_addr: Option
, pub pubdata_params: PubdataParams, /// Whether transactions should be pre-inserted to DB. /// Should be set to `true` for EN's IO as EN doesn't store transactions in DB diff --git a/zk_toolbox/crates/config/src/contracts.rs b/zk_toolbox/crates/config/src/contracts.rs index 2136016190d..07765a5e12f 100644 --- a/zk_toolbox/crates/config/src/contracts.rs +++ b/zk_toolbox/crates/config/src/contracts.rs @@ -1,6 +1,6 @@ use ethers::types::{Address, H256}; use serde::{Deserialize, Serialize}; -use zksync_system_constants::L2_NATIVE_TOKEN_VAULT_ADDRESS; +use zksync_system_constants::{L2_ASSET_ROUTER_ADDRESS, L2_NATIVE_TOKEN_VAULT_ADDRESS}; use crate::{ consts::CONTRACTS_FILE, @@ -113,8 +113,7 @@ impl ContractsConfig { self.l1.access_control_restriction_addr = register_chain_output.access_control_restriction_addr; self.l1.chain_proxy_admin_addr = register_chain_output.chain_proxy_admin_addr; - self.l2.l2_legacy_shared_bridge_addr = register_chain_output.l2_legacy_shared_bridge_addr; - self.bridges.shared.l2_address = Some(register_chain_output.l2_legacy_shared_bridge_addr); + self.l2.legacy_shared_bridge_addr = register_chain_output.l2_legacy_shared_bridge_addr; self.user_facing_diamond_proxy = register_chain_output.diamond_proxy_addr; } @@ -123,8 +122,8 @@ impl ContractsConfig { &mut self, initialize_bridges_output: &InitializeBridgeOutput, ) -> anyhow::Result<()> { - // self.bridges.shared.l2_address = Some(L2_ASSET_ROUTER_ADDRESS); - // self.bridges.erc20.l2_address = Some(L2_ASSET_ROUTER_ADDRESS); + self.bridges.shared.l2_address = Some(L2_ASSET_ROUTER_ADDRESS); + self.bridges.erc20.l2_address = Some(L2_ASSET_ROUTER_ADDRESS); self.l2.l2_native_token_vault_proxy_addr = L2_NATIVE_TOKEN_VAULT_ADDRESS; self.l2.l2_da_validator_addr = initialize_bridges_output.l2_da_validator_address; Ok(()) @@ -214,7 +213,7 @@ pub struct L2Contracts { pub default_l2_upgrader: Address, pub l2_da_validator_addr: Address, pub l2_native_token_vault_proxy_addr: Address, - pub l2_legacy_shared_bridge_addr: Address, + pub legacy_shared_bridge_addr: Address, pub consensus_registry: Option
, pub multicall3: Option
, } From 36f51989818fc3ce97cd4b19277c82e0c0cf5494 Mon Sep 17 00:00:00 2001 From: perekopskiy Date: Tue, 1 Oct 2024 11:53:25 +0300 Subject: [PATCH 07/10] fix name --- zk_toolbox/crates/config/src/contracts.rs | 4 ++-- zk_toolbox/crates/zk_inception/src/commands/chain/init.rs | 2 +- .../zk_inception/src/commands/chain/migrate_to_gateway.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/zk_toolbox/crates/config/src/contracts.rs b/zk_toolbox/crates/config/src/contracts.rs index 07765a5e12f..c2b69b7df8c 100644 --- a/zk_toolbox/crates/config/src/contracts.rs +++ b/zk_toolbox/crates/config/src/contracts.rs @@ -125,7 +125,7 @@ impl ContractsConfig { self.bridges.shared.l2_address = Some(L2_ASSET_ROUTER_ADDRESS); self.bridges.erc20.l2_address = Some(L2_ASSET_ROUTER_ADDRESS); self.l2.l2_native_token_vault_proxy_addr = L2_NATIVE_TOKEN_VAULT_ADDRESS; - self.l2.l2_da_validator_addr = initialize_bridges_output.l2_da_validator_address; + self.l2.da_validator_addr = initialize_bridges_output.l2_da_validator_address; Ok(()) } @@ -211,7 +211,7 @@ pub struct L1Contracts { pub struct L2Contracts { pub testnet_paymaster_addr: Address, pub default_l2_upgrader: Address, - pub l2_da_validator_addr: Address, + pub da_validator_addr: Address, pub l2_native_token_vault_proxy_addr: Address, pub legacy_shared_bridge_addr: Address, pub consensus_registry: Option
, diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs index 46f88509a4d..f2a6d597729 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs @@ -159,7 +159,7 @@ pub async fn init( chain_config.get_wallets_config()?.governor_private_key(), contracts_config.l1.diamond_proxy_addr, l1_da_validator_addr, - contracts_config.l2.l2_da_validator_addr, + contracts_config.l2.da_validator_addr, &init_args.forge_args.clone(), init_args.l1_rpc_url.clone(), ) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/migrate_to_gateway.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/migrate_to_gateway.rs index 7d8ad2ce6b7..8ec54c82339 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/migrate_to_gateway.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/migrate_to_gateway.rs @@ -214,7 +214,7 @@ pub async fn run(args: MigrateToGatewayArgs, shell: &Shell) -> anyhow::Result<() chain_access_control_restriction, U256::from(chain_config.chain_id.0), gateway_da_validator_address, - chain_contracts_config.l2.l2_da_validator_addr, + chain_contracts_config.l2.da_validator_addr, new_diamond_proxy_address, ), ) From 6c3d42a93a798170024eacd580260e4e74f21d30 Mon Sep 17 00:00:00 2001 From: perekopskiy Date: Tue, 1 Oct 2024 12:37:13 +0300 Subject: [PATCH 08/10] fix --- core/lib/protobuf_config/src/contracts.rs | 4 ++-- core/lib/protobuf_config/src/proto/config/contracts.proto | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/lib/protobuf_config/src/contracts.rs b/core/lib/protobuf_config/src/contracts.rs index 546bffb279c..f9670ead838 100644 --- a/core/lib/protobuf_config/src/contracts.rs +++ b/core/lib/protobuf_config/src/contracts.rs @@ -77,7 +77,7 @@ impl ProtoRepr for proto::Contracts { .transpose() .context("l2_shared_bridge_addr")?, l2_legacy_shared_bridge_addr: l2 - .legacy_shared_bridge + .legacy_shared_bridge_addr .as_ref() .map(|x| parse_h160(x)) .transpose() @@ -167,7 +167,7 @@ impl ProtoRepr for proto::Contracts { l2: Some(proto::L2 { testnet_paymaster_addr: this.l2_testnet_paymaster_addr.map(|a| format!("{:?}", a)), da_validator_addr: this.l2_da_validator_addr.map(|a| format!("{:?}", a)), - legacy_shared_bridge: this + legacy_shared_bridge_addr: this .l2_legacy_shared_bridge_addr .map(|a| format!("{:?}", a)), }), diff --git a/core/lib/protobuf_config/src/proto/config/contracts.proto b/core/lib/protobuf_config/src/proto/config/contracts.proto index fedde21e41c..54dda78afe5 100644 --- a/core/lib/protobuf_config/src/proto/config/contracts.proto +++ b/core/lib/protobuf_config/src/proto/config/contracts.proto @@ -22,7 +22,7 @@ message L1 { message L2 { optional string testnet_paymaster_addr = 1; // optional; H160 optional string da_validator_addr = 2; // optional; H160 - optional string legacy_shared_bridge = 3; // optional; H160 + optional string legacy_shared_bridge_addr = 3; // optional; H160 } message Bridge { From f97652b1a5f804e049c581839d63f1b0bc770219 Mon Sep 17 00:00:00 2001 From: perekopskiy Date: Tue, 1 Oct 2024 13:39:18 +0300 Subject: [PATCH 09/10] fix --- core/bin/zksync_server/src/node_builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/bin/zksync_server/src/node_builder.rs b/core/bin/zksync_server/src/node_builder.rs index bb2c0f7e1a3..5c55d060e92 100644 --- a/core/bin/zksync_server/src/node_builder.rs +++ b/core/bin/zksync_server/src/node_builder.rs @@ -240,7 +240,7 @@ impl MainNodeBuilder { let wallets = self.wallets.clone(); let sk_config = try_load_config!(self.configs.state_keeper_config); let persistence_layer = OutputHandlerLayer::new( - self.contracts_config.l2_shared_bridge_addr, + self.contracts_config.l2_legacy_shared_bridge_addr, sk_config.l2_block_seal_queue_capacity, ) .with_protective_reads_persistence_enabled(sk_config.protective_reads_persistence_enabled); From b8a8ead34b3ae620bfc220b53a4571adc0c51ba3 Mon Sep 17 00:00:00 2001 From: perekopskiy Date: Wed, 2 Oct 2024 13:09:12 +0300 Subject: [PATCH 10/10] remove comment --- core/node/state_keeper/src/io/seal_logic/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/node/state_keeper/src/io/seal_logic/mod.rs b/core/node/state_keeper/src/io/seal_logic/mod.rs index fd9a3d82af7..dce0ae090de 100644 --- a/core/node/state_keeper/src/io/seal_logic/mod.rs +++ b/core/node/state_keeper/src/io/seal_logic/mod.rs @@ -334,8 +334,6 @@ impl L2BlockSealCommand { /// that are created after the last processed tx in the L1 batch: after the last transaction is processed, /// the bootloader enters the "tip" phase in which it can still generate events (e.g., /// one for sending fees to the operator). - /// - /// `l2_legacy_shared_bridge_addr` is required to extract the information on newly added tokens. async fn seal_inner( &self, strategy: &mut SealStrategy<'_>,