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: final gateway features for server #3462

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub(crate) struct RemoteENConfig {
pub l2_weth_bridge_addr: Option<Address>,
pub l2_testnet_paymaster_addr: Option<Address>,
pub l2_timestamp_asserter_addr: Option<Address>,
pub l1_wrapped_base_token_store: Option<Address>,
pub base_token_addr: Address,
pub l1_batch_commit_data_generator_mode: L1BatchCommitmentMode,
pub dummy_verifier: bool,
Expand Down Expand Up @@ -195,6 +196,9 @@ impl RemoteENConfig {
l1_bytecodes_supplier_addr: ecosystem_contracts
.as_ref()
.and_then(|a| a.l1_bytecodes_supplier_addr),
l1_wrapped_base_token_store: ecosystem_contracts
.as_ref()
.and_then(|a| a.l1_wrapped_base_token_store),
l1_diamond_proxy_addr,
l2_testnet_paymaster_addr,
l1_erc20_bridge_proxy_addr: bridges.l1_erc20_default_bridge,
Expand Down Expand Up @@ -235,6 +239,7 @@ impl RemoteENConfig {
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,
l1_wrapped_base_token_store: None,
dummy_verifier: true,
l2_timestamp_asserter_addr: None,
}
Expand Down Expand Up @@ -1477,6 +1482,7 @@ impl From<&ExternalNodeConfig> for InternalApiConfig {
l2_weth_bridge: config.remote.l2_weth_bridge_addr,
},
l1_bytecodes_supplier_addr: config.remote.l1_bytecodes_supplier_addr,
l1_wrapped_base_token_store: config.remote.l1_wrapped_base_token_store,
l1_bridgehub_proxy_addr: config.remote.l1_bridgehub_proxy_addr,
l1_state_transition_proxy_addr: config.remote.l1_state_transition_proxy_addr,
l1_transparent_proxy_admin_addr: config.remote.l1_transparent_proxy_admin_addr,
Expand Down
6 changes: 3 additions & 3 deletions core/lib/basic_types/src/protocol_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl ProtocolVersionId {
ProtocolVersionId::Version23 => VmVersion::Vm1_5_0SmallBootloaderMemory,
ProtocolVersionId::Version24 => VmVersion::Vm1_5_0IncreasedBootloaderMemory,
ProtocolVersionId::Version25 => VmVersion::Vm1_5_0IncreasedBootloaderMemory,
ProtocolVersionId::Version26 => VmVersion::Vm1_5_0IncreasedBootloaderMemory,
ProtocolVersionId::Version26 => VmVersion::VmGateway,
ProtocolVersionId::Version27 => VmVersion::VmGateway,
ProtocolVersionId::Version28 => unreachable!("Version 28 is not yet supported"),
}
Expand Down Expand Up @@ -192,7 +192,7 @@ impl ProtocolVersionId {
}

pub const fn gateway_upgrade() -> Self {
ProtocolVersionId::Version27
ProtocolVersionId::Version26
}
}

Expand Down Expand Up @@ -298,7 +298,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::Vm1_5_0IncreasedBootloaderMemory,
ProtocolVersionId::Version26 => VmVersion::VmGateway,
ProtocolVersionId::Version27 => VmVersion::VmGateway,
ProtocolVersionId::Version28 => unreachable!("Version 28 is not yet supported"),
}
Expand Down
2 changes: 1 addition & 1 deletion core/lib/basic_types/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub enum VmVersion {
impl VmVersion {
/// Returns the latest supported VM version.
pub const fn latest() -> VmVersion {
Self::Vm1_5_0IncreasedBootloaderMemory
Self::VmGateway
}
}

Expand Down
8 changes: 5 additions & 3 deletions core/lib/config/src/configs/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ pub struct EcosystemContracts {
pub state_transition_proxy_addr: Address,
pub transparent_proxy_admin_addr: Address,
pub l1_bytecodes_supplier_addr: Option<Address>,
// Note that on the contract side of things this contract is called `L2WrappedBaseTokenStore`,
// while on the server side for consistency with the conventions, where the prefix denotes
// the location of the contracts we call it `l1_wrapped_base_token_store`
pub l1_wrapped_base_token_store: Option<Address>,
}

impl EcosystemContracts {
Expand All @@ -18,6 +22,7 @@ impl EcosystemContracts {
state_transition_proxy_addr: Address::repeat_byte(0x15),
transparent_proxy_admin_addr: Address::repeat_byte(0x15),
l1_bytecodes_supplier_addr: Some(Address::repeat_byte(0x16)),
l1_wrapped_base_token_store: Some(Address::repeat_byte(0x17)),
}
}
}
Expand Down Expand Up @@ -50,8 +55,6 @@ pub struct ContractsConfig {
pub base_token_addr: Option<Address>,
pub l1_base_token_asset_id: Option<H256>,

pub l2_predeployed_wrapped_base_token_address: Option<Address>,

pub chain_admin_addr: Option<Address>,
pub l2_da_validator_addr: Option<Address>,
}
Expand All @@ -76,7 +79,6 @@ impl ContractsConfig {
governance_addr: Address::repeat_byte(0x13),
base_token_addr: Some(Address::repeat_byte(0x14)),
l1_base_token_asset_id: Some(H256::repeat_byte(0x15)),
l2_predeployed_wrapped_base_token_address: Some(Address::repeat_byte(0x1b)),
ecosystem_contracts: Some(EcosystemContracts::for_tests()),
chain_admin_addr: Some(Address::repeat_byte(0x18)),
l2_da_validator_addr: Some(Address::repeat_byte(0x1a)),
Expand Down
2 changes: 1 addition & 1 deletion core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ impl Distribution<configs::ContractsConfig> for EncodeDist {
ecosystem_contracts: self.sample(rng),
base_token_addr: self.sample_opt(|| rng.gen()),
l1_base_token_asset_id: self.sample_opt(|| rng.gen()),
l2_predeployed_wrapped_base_token_address: self.sample_opt(|| rng.gen()),
chain_admin_addr: self.sample_opt(|| rng.gen()),
l2_da_validator_addr: self.sample_opt(|| rng.gen()),
}
Expand Down Expand Up @@ -763,6 +762,7 @@ impl Distribution<configs::EcosystemContracts> for EncodeDist {
state_transition_proxy_addr: rng.gen(),
transparent_proxy_admin_addr: rng.gen(),
l1_bytecodes_supplier_addr: rng.gen(),
l1_wrapped_base_token_store: rng.gen(),
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion core/lib/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,25 @@ pub static POST_SHARED_BRIDGE_EXECUTE_FUNCTION: Lazy<Function> = Lazy::new(|| {
serde_json::from_str(abi).unwrap()
});

// Temporary thing, should be removed when new contracts are merged.
// Temporary items, should be removed when new contracts are merged.

pub static L1_ASSET_ROUTER_CONTRACT: Lazy<Contract> = Lazy::new(|| {
let abi = r#"
[
{"type":"function","name":"l2BridgeAddress","inputs":[{"name":"_chainId","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},
{"type":"function","name":"L1_NULLIFIER","inputs":[],"outputs":[{"name":"","type":"address","internalType":"contract IL1Nullifier"}],"stateMutability":"view"}
]"#;
serde_json::from_str(abi).unwrap()
});

pub static WRAPPED_BASE_TOKEN_STORE_CONTRACT: Lazy<Contract> = Lazy::new(|| {
let abi = r#"
[
{"type":"function","name":"l2WBaseTokenAddress","inputs":[{"name":"chainId","type":"uint256","internalType":"uint256"}],"outputs":[{"name":"l2WBaseTokenAddress","type":"address","internalType":"address"}],"stateMutability":"view"}
]"#;
serde_json::from_str(abi).unwrap()
});

pub static MESSAGE_ROOT_CONTRACT: Lazy<Contract> = Lazy::new(|| {
let abi = r#"
[{
Expand Down

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

19 changes: 19 additions & 0 deletions core/lib/dal/src/eth_sender_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ impl EthSenderDal<'_, '_> {
Ok(count.try_into().unwrap())
}

pub async fn get_unconfirmed_txs_count(&mut self) -> DalResult<usize> {
let count = sqlx::query!(
r#"
SELECT
COUNT(*)
FROM
eth_txs
WHERE
confirmed_eth_tx_history_id IS NULL
"#
)
.instrument("get_unconfirmed_txs_count")
.fetch_one(self.storage)
.await?
.count
.unwrap();
Ok(count.try_into().unwrap())
}

pub async fn get_eth_l1_batches(&mut self) -> sqlx::Result<L1BatchEthSenderStats> {
struct EthTxRow {
number: i64,
Expand Down
33 changes: 28 additions & 5 deletions core/lib/env_config/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ impl FromEnv for EcosystemContracts {
.parse()?,
transparent_proxy_admin_addr: std::env::var("CONTRACTS_TRANSPARENT_PROXY_ADMIN_ADDR")?
.parse()?,
// Not supported yet
l1_bytecodes_supplier_addr: None,
l1_bytecodes_supplier_addr: std::env::var("CONTRACTS_L1_BYTECODE_SUPPLIER_ADDR")?
.parse()
.ok(),
l1_wrapped_base_token_store: std::env::var(
"CONTRACTS_L1_WRAPPED_BASE_TOKEN_STORE_ADDR",
)?
.parse()
.ok(),
})
}
}
Expand Down Expand Up @@ -44,6 +50,9 @@ impl FromEnv for ContractsConfig {

#[cfg(test)]
mod tests {
use std::str::FromStr;

use zksync_basic_types::H256;
use zksync_config::configs::EcosystemContracts;
use zksync_system_constants::SHARED_BRIDGE_ETHER_TOKEN_ADDRESS;

Expand Down Expand Up @@ -72,11 +81,20 @@ mod tests {
bridgehub_proxy_addr: addr("0x35ea7f92f4c5f433efe15284e99c040110cf6297"),
state_transition_proxy_addr: addr("0xd90f1c081c6117241624e97cb6147257c3cb2097"),
transparent_proxy_admin_addr: addr("0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347e5"),
l1_bytecodes_supplier_addr: None,
l1_bytecodes_supplier_addr: Some(addr(
"0x36ea7f92f4c5f433efe15284e99c040110cf6297",
)),
l1_wrapped_base_token_store: Some(addr(
"0x36ea7f92f4c5f433efe15284e99c040110cf6298",
)),
}),
base_token_addr: Some(SHARED_BRIDGE_ETHER_TOKEN_ADDRESS),
l1_base_token_asset_id: None,
l2_predeployed_wrapped_base_token_address: None,
l1_base_token_asset_id: Some(
H256::from_str(
"0x0000000000000000000000000000000000000001000000000000000000000000",
)
.unwrap(),
),
chain_admin_addr: Some(addr("0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347ff")),
l2_da_validator_addr: Some(addr("0xed6fa5c14e7550b4caf2aa2818d24c69cbc347ff")),
l2_timestamp_asserter_addr: Some(addr("0x0000000000000000000000000000000000000002")),
Expand All @@ -101,11 +119,16 @@ 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_L1_BYTECODE_SUPPLIER_ADDR="0x36ea7f92f4c5f433efe15284e99c040110cf6297"
CONTRACTS_L2_LEGACY_SHARED_BRIDGE_ADDR="0x8656770FA78c830456B00B4fFCeE6b1De0e1b888"
CONTRACTS_BRIDGEHUB_PROXY_ADDR="0x35ea7f92f4c5f433efe15284e99c040110cf6297"
CONTRACTS_STATE_TRANSITION_PROXY_ADDR="0xd90f1c081c6117241624e97cb6147257c3cb2097"
CONTRACTS_TRANSPARENT_PROXY_ADMIN_ADDR="0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347e5"
CONTRACTS_BASE_TOKEN_ADDR="0x0000000000000000000000000000000000000001"
CONTRACTS_L1_BASE_TOKEN_ASSET_ID="0x0000000000000000000000000000000000000001000000000000000000000000"
CONTRACTS_L1_WRAPPED_BASE_TOKEN_STORE_ADDR="0x36ea7f92f4c5f433efe15284e99c040110cf6298"
CONTRACTS_L2_NATIVE_TOKEN_VAULT_PROXY_ADDR="0xfc073319977e314f251eae6ae6be76b0b3baeecf"
CONTRACTS_PREDEPLOYED_L2_WRAPPED_BASE_TOKEN_ADDRESS="0x35ea7f92f4c5f433efe15284e99c040110cf6299"
CONTRACTS_CHAIN_ADMIN_ADDR="0xdd6fa5c14e7550b4caf2aa2818d24c69cbc347ff"
CONTRACTS_L2_DA_VALIDATOR_ADDR="0xed6fa5c14e7550b4caf2aa2818d24c69cbc347ff"
CONTRACTS_L2_TIMESTAMP_ASSERTER_ADDR="0x0000000000000000000000000000000000000002"
Expand Down
16 changes: 7 additions & 9 deletions core/lib/protobuf_config/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ impl ProtoRepr for proto::Contracts {
.l1_bytecodes_supplier_addr
.as_ref()
.map(|x| parse_h160(x).expect("Invalid address")),
l1_wrapped_base_token_store: ecosystem_contracts
.l1_wrapped_base_token_store
.as_ref()
.map(|x| parse_h160(x).expect("Invalid address")),
})
} else {
None
Expand Down Expand Up @@ -123,12 +127,6 @@ impl ProtoRepr for proto::Contracts {
.map(|x| parse_h256(x))
.transpose()
.context("base_token_asset_id")?,
l2_predeployed_wrapped_base_token_address: l2
.predeployed_wrapped_base_token_address
.as_ref()
.map(|x| parse_h160(x))
.transpose()
.context("l2 predeployed_wrapped_base_token_address")?,
chain_admin_addr: l1
.chain_admin_addr
.as_ref()
Expand Down Expand Up @@ -164,6 +162,9 @@ impl ProtoRepr for proto::Contracts {
l1_bytecodes_supplier_addr: ecosystem_contracts
.l1_bytecodes_supplier_addr
.map(|x| format!("{:?}", x)),
l1_wrapped_base_token_store: ecosystem_contracts
.l1_wrapped_base_token_store
.map(|x| format!("{:?}", x)),
});
Self {
ecosystem_contracts,
Expand All @@ -184,9 +185,6 @@ impl ProtoRepr for proto::Contracts {
legacy_shared_bridge_addr: this
.l2_legacy_shared_bridge_addr
.map(|a| format!("{:?}", a)),
predeployed_wrapped_base_token_address: this
.l2_predeployed_wrapped_base_token_address
.map(|x| format!("{:?}", x)),
timestamp_asserter_addr: this
.l2_timestamp_asserter_addr
.map(|a| format!("{:?}", a)),
Expand Down
3 changes: 2 additions & 1 deletion core/lib/protobuf_config/src/proto/config/contracts.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ message EcosystemContracts {
optional string state_transition_proxy_addr = 2; // optional; h160
optional string transparent_proxy_admin_addr = 3; // optional; h160
optional string l1_bytecodes_supplier_addr = 4; // optional; h160
optional string l1_wrapped_base_token_store = 5; // optional; h160
}

message L1 {
Expand All @@ -26,7 +27,7 @@ message L2 {
optional string da_validator_addr = 2; // optional; H160
optional string legacy_shared_bridge_addr = 3; // optional; H160
optional string timestamp_asserter_addr = 4; // optional; H160
optional string predeployed_wrapped_base_token_address = 5; // optional; H160
reserved 5; reserved "predeployed_wrapped_base_token_address";
}

message Bridge {
Expand Down
6 changes: 3 additions & 3 deletions core/lib/types/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ impl GatewayUpgradeEncodedInput {
pub struct ZkChainSpecificUpgradeData {
pub base_token_asset_id: H256,
pub l2_legacy_shared_bridge: Address,
pub predeployed_l2_weth_address: Address,
pub l2_predeployed_wrapped_base_token: Address,
pub base_token_l1_address: Address,
pub base_token_name: String,
pub base_token_symbol: String,
Expand All @@ -551,7 +551,7 @@ impl ZkChainSpecificUpgradeData {
l2_legacy_shared_bridge: l2_legacy_shared_bridge?,
// Note, that some chains may not contain previous deployment of L2 wrapped base
// token. For those, zero address is used.
predeployed_l2_weth_address: predeployed_l2_weth_address.unwrap_or_default(),
l2_predeployed_wrapped_base_token: predeployed_l2_weth_address.unwrap_or_default(),
base_token_l1_address: base_token_l1_address?,
base_token_name: base_token_name?,
base_token_symbol: base_token_symbol?,
Expand All @@ -572,7 +572,7 @@ impl ZkChainSpecificUpgradeData {
Token::Tuple(vec![
Token::FixedBytes(self.base_token_asset_id.0.to_vec()),
Token::Address(self.l2_legacy_shared_bridge),
Token::Address(self.predeployed_l2_weth_address),
Token::Address(self.l2_predeployed_wrapped_base_token),
Token::Address(self.base_token_l1_address),
Token::String(self.base_token_name.clone()),
Token::String(self.base_token_symbol.clone()),
Expand Down
6 changes: 2 additions & 4 deletions core/lib/vm_executor/src/oneshot/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ impl<C: ContractsKind> MultiVmBaseSystemContracts<C> {
ProtocolVersionId::Version21 | ProtocolVersionId::Version22 => &self.post_1_4_2,
ProtocolVersionId::Version23 => &self.vm_1_5_0_small_memory,
ProtocolVersionId::Version24 => &self.vm_1_5_0_increased_memory,
ProtocolVersionId::Version25 | ProtocolVersionId::Version26 => {
&self.vm_protocol_defense
}
ProtocolVersionId::Version27 => &self.gateway,
ProtocolVersionId::Version25 => &self.vm_protocol_defense,
ProtocolVersionId::Version26 | ProtocolVersionId::Version27 => &self.gateway,
ProtocolVersionId::Version28 => unreachable!("Version 28 is not supported yet"),
};
let base = base.clone();
Expand Down
3 changes: 3 additions & 0 deletions core/lib/web3_decl/src/namespaces/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ pub trait UnstableNamespace {
l1_batch_number: L1BatchNumber,
chain_id: L2ChainId,
) -> RpcResult<Option<ChainAggProof>>;

#[method(name = "unconfirmedTxsCount")]
async fn get_unconfirmed_txs_count(&self) -> RpcResult<usize>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ impl UnstableNamespaceServer for UnstableNamespace {
.await
.map_err(|err| self.current_method().map_err(err))
}

async fn get_unconfirmed_txs_count(&self) -> RpcResult<usize> {
self.get_unconfirmed_txs_count_impl()
.await
.map_err(|err| self.current_method().map_err(err))
}
}
1 change: 1 addition & 0 deletions core/node/api_server/src/web3/namespaces/en.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ impl EnNamespace {
.l1_transparent_proxy_admin_addr
.unwrap(),
l1_bytecodes_supplier_addr: self.state.api_config.l1_bytecodes_supplier_addr,
l1_wrapped_base_token_store: self.state.api_config.l1_wrapped_base_token_store,
})
.context("Shared bridge doesn't supported")?)
}
Expand Down
Loading
Loading