Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gateway preparation #3006

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8546f1c
reduce sync-layer-stable diff
perekopskiy Oct 3, 2024
48fd0e6
fix test
perekopskiy Oct 3, 2024
aff2e98
nits
perekopskiy Oct 7, 2024
cd015b6
move bridge address validation to SK persistance
perekopskiy Oct 7, 2024
068d654
fix en
perekopskiy Oct 7, 2024
847c3da
fix
perekopskiy Oct 7, 2024
f9e4c90
rework pubdata approach
perekopskiy Oct 8, 2024
379b5c3
unify naming
perekopskiy Oct 8, 2024
96f3af2
merge main
perekopskiy Oct 8, 2024
b00be9d
fix commitment
perekopskiy Oct 8, 2024
ecd8e24
fix
perekopskiy Oct 8, 2024
380c11d
resolve conflicts
perekopskiy Oct 9, 2024
b0d6af7
update evm commitment test json
perekopskiy Oct 9, 2024
8106288
another test json fix
perekopskiy Oct 9, 2024
f7133a6
Resolve conflicts
perekopskiy Oct 14, 2024
d4f5d67
Merge branch 'main' into sync-layer-reduce-diff
perekopskiy Oct 14, 2024
d8c6f4c
fix after merge
perekopskiy Oct 14, 2024
b8cee5e
Resolve conflicts
perekopskiy Oct 17, 2024
3304679
Resolve conflicts
perekopskiy Oct 17, 2024
01b89ee
put pubdata_builder to finish_batch
perekopskiy Oct 18, 2024
79c4ba2
move stuff to multivm
perekopskiy Oct 18, 2024
0984283
update tests
perekopskiy Oct 18, 2024
26bb438
fix tests
perekopskiy Oct 18, 2024
a56e0ef
update protocol version in json commitment test
perekopskiy Oct 18, 2024
4fbc3bb
remove pubdata_params from oneshot env
perekopskiy Oct 18, 2024
8ade31b
Resolve conflicts
perekopskiy Oct 22, 2024
0825647
remove finish_batch from dump playback
perekopskiy Oct 22, 2024
b22e77c
Address comments
perekopskiy Oct 22, 2024
f8c6863
nits
perekopskiy Oct 22, 2024
37d1e0f
resolve conflicts
perekopskiy Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +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<Address>,
/// 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>,
/// 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<Address>,
pub l1_erc20_bridge_proxy_addr: Option<Address>,
pub l2_erc20_bridge_addr: Option<Address>,
pub l1_weth_bridge_addr: Option<Address>,
Expand Down Expand Up @@ -189,6 +194,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: bridges.l2_legacy_shared_bridge,
l1_weth_bridge_addr: bridges.l1_weth_bridge,
l2_weth_bridge_addr: bridges.l2_weth_bridge,
base_token_addr,
Expand Down Expand Up @@ -218,6 +224,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_legacy_shared_bridge_addr: Some(Address::repeat_byte(7)),
l1_batch_commit_data_generator_mode: L1BatchCommitmentMode::Rollup,
dummy_verifier: true,
}
Expand Down Expand Up @@ -1395,6 +1402,7 @@ impl From<&ExternalNodeConfig> for InternalApiConfig {
l2_erc20_default_bridge: config.remote.l2_erc20_bridge_addr,
l1_shared_default_bridge: config.remote.l1_shared_bridge_proxy_addr,
l2_shared_default_bridge: config.remote.l2_shared_bridge_addr,
l2_legacy_shared_bridge: config.remote.l2_legacy_shared_bridge_addr,
l1_weth_bridge: config.remote.l1_weth_bridge_addr,
l2_weth_bridge: config.remote.l2_weth_bridge_addr,
},
Expand Down
20 changes: 16 additions & 4 deletions core/bin/external_node/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ use zksync_node_framework::{
service::{ZkStackService, ZkStackServiceBuilder},
};
use zksync_state::RocksdbStorageOptions;
use zksync_types::L2_NATIVE_TOKEN_VAULT_ADDRESS;

use crate::{config::ExternalNodeConfig, metrics::framework::ExternalNodeMetricsLayer, Component};

Expand Down Expand Up @@ -192,11 +193,22 @@ impl ExternalNodeBuilder {
// compression.
const OPTIONAL_BYTECODE_COMPRESSION: bool = true;

let l2_shared_bridge_addr = self
.config
.remote
.l2_shared_bridge_addr
.context("Missing `l2_shared_bridge_addr`")?;
let l2_legacy_shared_bridge_addr = if l2_shared_bridge_addr == L2_NATIVE_TOKEN_VAULT_ADDRESS
{
// System has migrated to `L2_NATIVE_TOKEN_VAULT_ADDRESS`, use legacy shared bridge address from main node.
self.config.remote.l2_legacy_shared_bridge_addr
} else {
// System hasn't migrated on `L2_NATIVE_TOKEN_VAULT_ADDRESS`, we can safely use `l2_shared_bridge_addr`.
l2_shared_bridge_addr
};

let persistence_layer = OutputHandlerLayer::new(
self.config
.remote
.l2_shared_bridge_addr
.expect("L2 shared bridge address is not set"),
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.
Expand Down
1 change: 1 addition & 0 deletions core/bin/snapshots_creator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ async fn create_l2_block(
base_fee_per_gas: 0,
gas_per_pubdata_limit: 0,
batch_fee_input: Default::default(),
pubdata_params: Default::default(),
base_system_contracts_hashes: Default::default(),
protocol_version: Some(Default::default()),
virtual_blocks: 0,
Expand Down
2 changes: 2 additions & 0 deletions core/bin/system-constants-generator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ pub(super) fn execute_internal_transfer_test() -> u32 {
execution_mode: TxExecutionMode::VerifyExecute,
default_validation_computational_gas_limit: BATCH_COMPUTATIONAL_GAS_LIMIT,
chain_id: L2ChainId::default(),
pubdata_params: Default::default(),
};

let eth_token_sys_contract = load_sys_contract("L2BaseToken");
Expand Down Expand Up @@ -313,6 +314,7 @@ pub(super) fn execute_user_txs_in_test_gas_vm(
execution_mode: TxExecutionMode::VerifyExecute,
default_validation_computational_gas_limit: BATCH_COMPUTATIONAL_GAS_LIMIT,
chain_id: L2ChainId::default(),
pubdata_params: Default::default(),
};

let mut vm: Vm<_, HistoryEnabled> =
Expand Down
6 changes: 3 additions & 3 deletions core/bin/zksync_server/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,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_legacy_shared_bridge_addr,
sk_config.l2_block_seal_queue_capacity,
)
.with_protective_reads_persistence_enabled(sk_config.protective_reads_persistence_enabled);
Expand All @@ -250,6 +248,8 @@ impl MainNodeBuilder {
sk_config.clone(),
try_load_config!(self.configs.mempool_config),
try_load_config!(wallets.state_keeper),
self.contracts_config.l2_da_validator_addr,
self.genesis_config.l1_batch_commit_data_generator_mode,
);
let db_config = try_load_config!(self.configs.db_config);
let experimental_vm_config = self
Expand Down
24 changes: 23 additions & 1 deletion core/lib/basic_types/src/commitment.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::str::FromStr;

use serde::{Deserialize, Serialize};
use strum::{Display, EnumIter};

use crate::{
ethabi,
web3::contract::{Detokenize, Error as ContractError},
U256,
Address, U256,
};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, EnumIter, Display)]
Expand Down Expand Up @@ -41,3 +43,23 @@ impl Detokenize for L1BatchCommitmentMode {
}
}
}

impl FromStr for L1BatchCommitmentMode {
type Err = &'static str;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Rollup" => Ok(Self::Rollup),
"Validium" => Ok(Self::Validium),
_ => {
Err("Incorrect l1 batch commitment mode type; expected one of `Rollup`, `Validium`")
}
}
}
}

#[derive(Default, Copy, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PubdataParams {
pub l2_da_validator_address: Address,
pub pubdata_type: L1BatchCommitmentMode,
}
7 changes: 7 additions & 0 deletions core/lib/basic_types/src/protocol_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub enum ProtocolVersionId {
Version23,
Version24,
Version25,
Version26,
}

impl ProtocolVersionId {
Expand Down Expand Up @@ -120,6 +121,7 @@ impl ProtocolVersionId {
ProtocolVersionId::Version23 => VmVersion::Vm1_5_0SmallBootloaderMemory,
ProtocolVersionId::Version24 => VmVersion::Vm1_5_0IncreasedBootloaderMemory,
ProtocolVersionId::Version25 => VmVersion::Vm1_5_0IncreasedBootloaderMemory,
ProtocolVersionId::Version26 => VmVersion::VmGateway,
perekopskiy marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -137,6 +139,10 @@ impl ProtocolVersionId {
self <= &Self::Version22
}

pub fn is_pre_gateway(&self) -> bool {
self <= &Self::Version25
}

pub fn is_1_4_0(&self) -> bool {
self >= &ProtocolVersionId::Version18 && self < &ProtocolVersionId::Version20
}
Expand Down Expand Up @@ -275,6 +281,7 @@ impl From<ProtocolVersionId> for VmVersion {
ProtocolVersionId::Version23 => VmVersion::Vm1_5_0SmallBootloaderMemory,
ProtocolVersionId::Version24 => VmVersion::Vm1_5_0IncreasedBootloaderMemory,
ProtocolVersionId::Version25 => VmVersion::Vm1_5_0IncreasedBootloaderMemory,
ProtocolVersionId::Version26 => VmVersion::VmGateway,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions core/lib/basic_types/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum VmVersion {
Vm1_4_2,
Vm1_5_0SmallBootloaderMemory,
Vm1_5_0IncreasedBootloaderMemory,
VmGateway,
}

impl VmVersion {
Expand Down
9 changes: 9 additions & 0 deletions core/lib/config/src/configs/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ pub struct ContractsConfig {
pub diamond_proxy_addr: Address,
pub validator_timelock_addr: Address,
pub l1_shared_bridge_proxy_addr: Option<Address>,
/// 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>,
/// 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<Address>,
pub l1_erc20_bridge_proxy_addr: Option<Address>,
pub l2_erc20_bridge_addr: Option<Address>,
pub l1_weth_bridge_proxy_addr: Option<Address>,
Expand All @@ -40,6 +46,7 @@ pub struct ContractsConfig {
// Used by the RPC API and by the node builder in wiring the BaseTokenRatioProvider layer.
pub base_token_addr: Option<Address>,
pub chain_admin_addr: Option<Address>,
pub l2_da_validator_addr: Option<Address>,
}

impl ContractsConfig {
Expand All @@ -53,6 +60,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(0x19)),
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)),
Expand All @@ -61,6 +69,7 @@ impl ContractsConfig {
base_token_addr: Some(Address::repeat_byte(0x14)),
ecosystem_contracts: Some(EcosystemContracts::for_tests()),
chain_admin_addr: Some(Address::repeat_byte(0x18)),
l2_da_validator_addr: Some(Address::repeat_byte(0x1a)),
}
}
}
2 changes: 2 additions & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,15 @@ impl Distribution<configs::ContractsConfig> 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()),
l1_multicall3_addr: rng.gen(),
ecosystem_contracts: self.sample(rng),
base_token_addr: self.sample_opt(|| rng.gen()),
chain_admin_addr: self.sample_opt(|| rng.gen()),
l2_da_validator_addr: self.sample_opt(|| rng.gen()),
}
}
}
Expand Down
27 changes: 26 additions & 1 deletion core/lib/constants/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,37 @@ pub const CODE_ORACLE_ADDRESS: Address = H160([
0x00, 0x00, 0x80, 0x12,
]);

/// Note, that the `Create2Factory` is explicitly deployed on a non-system-contract address.
/// Note, that the `Create2Factory` and higher are is explicitly deployed on a non-system-contract address.
pub const CREATE2_FACTORY_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00,
]);

pub const L2_GENESIS_UPGRADE_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x01,
]);

pub const L2_BRIDGEHUB_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x02,
]);

pub const L2_ASSET_ROUTER_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x03,
]);

pub const L2_NATIVE_TOKEN_VAULT_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x04,
]);

pub const L2_MESSAGE_ROOT_ADDRESS: Address = H160([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x05,
]);

pub const ERC20_TRANSFER_TOPIC: H256 = H256([
221, 242, 82, 173, 27, 226, 200, 155, 105, 194, 176, 104, 252, 55, 141, 170, 149, 43, 167, 241,
99, 196, 161, 22, 40, 245, 90, 77, 245, 35, 179, 239,
Expand Down
1 change: 1 addition & 0 deletions core/lib/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod contracts;
pub mod crypto;
pub mod ethereum;
pub mod fees;
pub mod message_root;
pub mod system_context;
pub mod system_logs;
pub mod trusted_slots;
Expand Down
5 changes: 5 additions & 0 deletions core/lib/constants/src/message_root.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Position of `FullTree::_height` in `MessageRoot`'s storage layout.
pub const AGG_TREE_HEIGHT_KEY: usize = 3;

// Position of `FullTree::nodes` in `MessageRoot`'s storage layout.
pub const AGG_TREE_NODES_KEY: usize = 5;
11 changes: 4 additions & 7 deletions core/lib/constants/src/system_logs.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/// The key of the system log with value of the L2->L1 logs tree root hash
pub const L2_TO_L1_LOGS_TREE_ROOT_KEY: u32 = 0;

/// The key of the system log with value of the state diff hash
pub const STATE_DIFF_HASH_KEY: u32 = 2;
/// The key of the system log with value of the state diff hash for pre-gateway protocol versions
pub const STATE_DIFF_HASH_KEY_PRE_GATEWAY: u32 = 2;

/// The key of the system log with value of the first blob linear hash
pub const BLOB1_LINEAR_HASH_KEY: u32 = 7;

/// The key of the system log with value of the second blob linear hash
pub const BLOB2_LINEAR_HASH_KEY: u32 = 8;
/// The key of the system log with value of the first blob linear hash for pre-gateway protocol versions
pub const BLOB1_LINEAR_HASH_KEY_PRE_GATEWAY: u32 = 7;
14 changes: 14 additions & 0 deletions core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,13 @@ impl BaseSystemContracts {
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

pub fn playground_gateway() -> Self {
let bootloader_bytecode = read_zbin_bytecode(
"etc/multivm_bootloaders/vm_gateway/playground_batch.yul/playground_batch.yul.zbin",
);
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

pub fn estimate_gas_pre_virtual_blocks() -> Self {
let bootloader_bytecode = read_zbin_bytecode(
"etc/multivm_bootloaders/vm_1_3_2/fee_estimate.yul/fee_estimate.yul.zbin",
Expand Down Expand Up @@ -471,6 +478,13 @@ impl BaseSystemContracts {
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

pub fn estimate_gas_gateway() -> Self {
let bootloader_bytecode = read_zbin_bytecode(
"etc/multivm_bootloaders/vm_gateway/fee_estimate.yul/fee_estimate.yul.zbin",
);
BaseSystemContracts::load_with_bootloader(bootloader_bytecode)
}

pub fn hashes(&self) -> BaseSystemContractsHashes {
BaseSystemContractsHashes {
bootloader: self.bootloader.hash,
Expand Down
Loading
Loading