Skip to content

Commit ea18999

Browse files
chore: Reduction of diff between main and sync-layer-stable (#3400)
## What ❔ This PR includes: - Changes to VM. Note, that since they are only activated during usage of the new ProtocolVersion, they should not affect the current behavior. - Changes to the VM introduce the max new factory deps as equal to 64 (but only to the last subversion) - The block reverted made to work on top of gateway, but most of the diff is due to the removal of the support for env-based instead of file based inputs - Gateway config ported - Some various changes to gateway-specific logic that should not be active before the upgrade ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`.
1 parent e4848c5 commit ea18999

File tree

86 files changed

+1375
-412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1375
-412
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/bin/block_reverter/src/main.rs

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ use zksync_block_reverter::{
1616
use zksync_config::{
1717
configs::{
1818
chain::NetworkConfig, wallets::Wallets, BasicWitnessInputProducerConfig, DatabaseSecrets,
19-
GeneralConfig, L1Secrets, ObservabilityConfig, ProtectiveReadsWriterConfig,
19+
GatewayChainConfig, GeneralConfig, L1Secrets, ObservabilityConfig,
20+
ProtectiveReadsWriterConfig,
2021
},
2122
ContractsConfig, DBConfig, EthConfig, GenesisConfig, PostgresConfig,
2223
};
2324
use zksync_core_leftovers::temp_config_store::read_yaml_repr;
2425
use zksync_dal::{ConnectionPool, Core};
2526
use zksync_env_config::{object_store::SnapshotsObjectStoreConfig, FromEnv};
2627
use zksync_object_store::ObjectStoreFactory;
28+
use zksync_protobuf_config::proto;
2729
use zksync_types::{Address, L1BatchNumber};
2830

2931
#[derive(Debug, Parser)]
@@ -46,6 +48,10 @@ struct Cli {
4648
/// Path to yaml genesis config. If set, it will be used instead of env vars
4749
#[arg(long, global = true)]
4850
genesis_path: Option<PathBuf>,
51+
/// Path to yaml config of the chain on top of gateway.
52+
/// It should be skipped in case a chain is not settling on top of Gateway.
53+
#[arg(long, global = true)]
54+
gateway_chain_path: Option<PathBuf>,
4955
}
5056

5157
#[derive(Debug, Subcommand)]
@@ -182,23 +188,22 @@ async fn main() -> anyhow::Result<()> {
182188
.context("BasicWitnessInputProducerConfig::from_env()")?,
183189
};
184190
let contracts = match opts.contracts_config_path {
185-
Some(path) => read_yaml_repr::<zksync_protobuf_config::proto::contracts::Contracts>(&path)
191+
Some(path) => read_yaml_repr::<proto::contracts::Contracts>(&path)
186192
.context("failed decoding contracts YAML config")?,
187193
None => ContractsConfig::from_env().context("ContractsConfig::from_env()")?,
188194
};
189195
let secrets_config = if let Some(path) = opts.secrets_path {
190196
Some(
191-
read_yaml_repr::<zksync_protobuf_config::proto::secrets::Secrets>(&path)
197+
read_yaml_repr::<proto::secrets::Secrets>(&path)
192198
.context("failed decoding secrets YAML config")?,
193199
)
194200
} else {
195201
None
196202
};
197203

198-
let default_priority_fee_per_gas = eth_sender
199-
.gas_adjuster
200-
.context("gas_adjuster")?
201-
.default_priority_fee_per_gas;
204+
let gas_adjuster = eth_sender.gas_adjuster.context("gas_adjuster")?;
205+
let default_priority_fee_per_gas = gas_adjuster.default_priority_fee_per_gas;
206+
let settlement_mode = gas_adjuster.settlement_mode;
202207

203208
let database_secrets = match &secrets_config {
204209
Some(secrets_config) => secrets_config
@@ -230,7 +235,40 @@ async fn main() -> anyhow::Result<()> {
230235
}
231236
};
232237

233-
let config = BlockReverterEthConfig::new(&eth_sender, &contracts, zksync_network_id)?;
238+
let (sl_rpc_url, sl_diamond_proxy, sl_validator_timelock) = if settlement_mode.is_gateway() {
239+
// Gateway config is required to be provided by file for now.
240+
let gateway_chain_config: GatewayChainConfig =
241+
read_yaml_repr::<proto::gateway::GatewayChainConfig>(
242+
&opts
243+
.gateway_chain_path
244+
.context("Genesis config path not provided")?,
245+
)
246+
.context("failed decoding genesis YAML config")?;
247+
248+
let gateway_url = l1_secrets
249+
.gateway_rpc_url
250+
.context("Gateway URL not found")?;
251+
252+
(
253+
gateway_url,
254+
gateway_chain_config.diamond_proxy_addr,
255+
gateway_chain_config.validator_timelock_addr,
256+
)
257+
} else {
258+
(
259+
l1_secrets.l1_rpc_url,
260+
contracts.diamond_proxy_addr,
261+
contracts.validator_timelock_addr,
262+
)
263+
};
264+
265+
let config = BlockReverterEthConfig::new(
266+
&eth_sender,
267+
sl_diamond_proxy,
268+
sl_validator_timelock,
269+
zksync_network_id,
270+
settlement_mode,
271+
)?;
234272

235273
let connection_pool = ConnectionPool::<Core>::builder(
236274
database_secrets.master_url()?,
@@ -246,12 +284,12 @@ async fn main() -> anyhow::Result<()> {
246284
json,
247285
operator_address,
248286
} => {
249-
let eth_client = Client::<L1>::http(l1_secrets.l1_rpc_url.clone())
287+
let sl_client = Client::<L1>::http(sl_rpc_url)
250288
.context("Ethereum client")?
251289
.build();
252290

253291
let suggested_values = block_reverter
254-
.suggested_values(&eth_client, &config, operator_address)
292+
.suggested_values(&sl_client, &config, operator_address)
255293
.await?;
256294
if json {
257295
println!("{}", serde_json::to_string(&suggested_values)?);
@@ -264,9 +302,7 @@ async fn main() -> anyhow::Result<()> {
264302
priority_fee_per_gas,
265303
nonce,
266304
} => {
267-
let eth_client = Client::http(l1_secrets.l1_rpc_url.clone())
268-
.context("Ethereum client")?
269-
.build();
305+
let sl_client = Client::http(sl_rpc_url).context("Ethereum client")?.build();
270306
let reverter_private_key = if let Some(wallets_config) = wallets_config {
271307
wallets_config
272308
.eth_sender
@@ -285,21 +321,21 @@ async fn main() -> anyhow::Result<()> {
285321
};
286322

287323
let priority_fee_per_gas = priority_fee_per_gas.unwrap_or(default_priority_fee_per_gas);
288-
let l1_chain_id = eth_client
324+
let l1_chain_id = sl_client
289325
.fetch_chain_id()
290326
.await
291327
.context("cannot fetch Ethereum chain ID")?;
292-
let eth_client = PKSigningClient::new_raw(
328+
let sl_client = PKSigningClient::new_raw(
293329
reverter_private_key,
294-
contracts.diamond_proxy_addr,
330+
sl_diamond_proxy,
295331
priority_fee_per_gas,
296332
l1_chain_id,
297-
Box::new(eth_client),
333+
Box::new(sl_client),
298334
);
299335

300336
block_reverter
301337
.send_ethereum_revert_transaction(
302-
&eth_client,
338+
&sl_client,
303339
&config,
304340
L1BatchNumber(l1_batch_number),
305341
nonce,

core/bin/external_node/src/config/mod.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ impl ConfigurationSource for Environment {
102102
/// This part of the external node config is fetched directly from the main node.
103103
#[derive(Debug, Deserialize)]
104104
pub(crate) struct RemoteENConfig {
105+
pub l1_bytecodes_supplier_addr: Option<Address>,
105106
#[serde(alias = "bridgehub_proxy_addr")]
106107
pub l1_bridgehub_proxy_addr: Option<Address>,
107108
#[serde(alias = "state_transition_proxy_addr")]
@@ -191,6 +192,9 @@ impl RemoteENConfig {
191192
l1_transparent_proxy_admin_addr: ecosystem_contracts
192193
.as_ref()
193194
.map(|a| a.transparent_proxy_admin_addr),
195+
l1_bytecodes_supplier_addr: ecosystem_contracts
196+
.as_ref()
197+
.and_then(|a| a.l1_bytecodes_supplier_addr),
194198
l1_diamond_proxy_addr,
195199
l2_testnet_paymaster_addr,
196200
l1_erc20_bridge_proxy_addr: bridges.l1_erc20_default_bridge,
@@ -216,6 +220,7 @@ impl RemoteENConfig {
216220
#[cfg(test)]
217221
fn mock() -> Self {
218222
Self {
223+
l1_bytecodes_supplier_addr: None,
219224
l1_bridgehub_proxy_addr: None,
220225
l1_state_transition_proxy_addr: None,
221226
l1_transparent_proxy_admin_addr: None,
@@ -983,11 +988,11 @@ impl OptionalENConfig {
983988
/// This part of the external node config is required for its operation.
984989
#[derive(Debug, Deserialize)]
985990
pub(crate) struct RequiredENConfig {
986-
/// The chain ID of the L1 network (e.g., 1 for Ethereum mainnet). In the future, it may be different from the settlement layer.
991+
/// The chain ID of the L1 network (e.g., 1 for Ethereum mainnet).
987992
pub l1_chain_id: L1ChainId,
988-
/// The chain ID of the settlement layer (e.g., 1 for Ethereum mainnet). This ID will be checked against the `eth_client_url` RPC provider on initialization
989-
/// to ensure that there's no mismatch between the expected and actual settlement layer network.
990-
pub sl_chain_id: Option<SLChainId>,
993+
/// The chain ID of the gateway. This ID will be checked against the `gateway_rpc_url` RPC provider on initialization
994+
/// to ensure that there's no mismatch between the expected and actual gateway network.
995+
pub gateway_chain_id: Option<SLChainId>,
991996
/// L2 chain ID (e.g., 270 for ZKsync Era mainnet). This ID will be checked against the `main_node_url` RPC provider on initialization
992997
/// to ensure that there's no mismatch between the expected and actual L2 network.
993998
pub l2_chain_id: L2ChainId,
@@ -1009,10 +1014,6 @@ pub(crate) struct RequiredENConfig {
10091014
}
10101015

10111016
impl RequiredENConfig {
1012-
pub fn settlement_layer_id(&self) -> SLChainId {
1013-
self.sl_chain_id.unwrap_or(self.l1_chain_id.into())
1014-
}
1015-
10161017
fn from_env() -> anyhow::Result<Self> {
10171018
envy::prefixed("EN_")
10181019
.from_env()
@@ -1034,7 +1035,7 @@ impl RequiredENConfig {
10341035
.context("Database config is required")?;
10351036
Ok(RequiredENConfig {
10361037
l1_chain_id: en_config.l1_chain_id,
1037-
sl_chain_id: None,
1038+
gateway_chain_id: en_config.gateway_chain_id,
10381039
l2_chain_id: en_config.l2_chain_id,
10391040
http_port: api_config.web3_json_rpc.http_port,
10401041
ws_port: api_config.web3_json_rpc.ws_port,
@@ -1055,7 +1056,7 @@ impl RequiredENConfig {
10551056
fn mock(temp_dir: &tempfile::TempDir) -> Self {
10561057
Self {
10571058
l1_chain_id: L1ChainId(9),
1058-
sl_chain_id: None,
1059+
gateway_chain_id: None,
10591060
l2_chain_id: L2ChainId::default(),
10601061
http_port: 0,
10611062
ws_port: 0,
@@ -1401,12 +1402,12 @@ impl ExternalNodeConfig<()> {
14011402
if let Some(local_diamond_proxy_addr) = self.optional.contracts_diamond_proxy_addr {
14021403
anyhow::ensure!(
14031404
local_diamond_proxy_addr == remote_diamond_proxy_addr,
1404-
"Diamond proxy address {local_diamond_proxy_addr:?} specified in config doesn't match one returned \
1405+
"L1 diamond proxy address {local_diamond_proxy_addr:?} specified in config doesn't match one returned \
14051406
by main node ({remote_diamond_proxy_addr:?})"
14061407
);
14071408
} else {
14081409
tracing::info!(
1409-
"Diamond proxy address is not specified in config; will use address \
1410+
"L1 diamond proxy address is not specified in config; will use address \
14101411
returned by main node: {remote_diamond_proxy_addr:?}"
14111412
);
14121413
}
@@ -1475,10 +1476,11 @@ impl From<&ExternalNodeConfig> for InternalApiConfig {
14751476
l1_weth_bridge: config.remote.l1_weth_bridge_addr,
14761477
l2_weth_bridge: config.remote.l2_weth_bridge_addr,
14771478
},
1479+
l1_bytecodes_supplier_addr: config.remote.l1_bytecodes_supplier_addr,
14781480
l1_bridgehub_proxy_addr: config.remote.l1_bridgehub_proxy_addr,
14791481
l1_state_transition_proxy_addr: config.remote.l1_state_transition_proxy_addr,
14801482
l1_transparent_proxy_admin_addr: config.remote.l1_transparent_proxy_admin_addr,
1481-
l1_diamond_proxy_addr: config.remote.l1_diamond_proxy_addr,
1483+
l1_diamond_proxy_addr: config.l1_diamond_proxy_address(),
14821484
l2_testnet_paymaster_addr: config.remote.l2_testnet_paymaster_addr,
14831485
req_entities_limit: config.optional.req_entities_limit,
14841486
fee_history_limit: config.optional.fee_history_limit,

core/bin/external_node/src/node_builder.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ impl ExternalNodeBuilder {
133133
fn add_external_node_metrics_layer(mut self) -> anyhow::Result<Self> {
134134
self.node.add_layer(ExternalNodeMetricsLayer {
135135
l1_chain_id: self.config.required.l1_chain_id,
136-
sl_chain_id: self.config.required.settlement_layer_id(),
136+
sl_chain_id: self
137+
.config
138+
.required
139+
.gateway_chain_id
140+
.unwrap_or(self.config.required.l1_chain_id.into()),
137141
l2_chain_id: self.config.required.l2_chain_id,
138142
postgres_pool_size: self.config.postgres.max_connections,
139143
});
@@ -179,8 +183,9 @@ impl ExternalNodeBuilder {
179183

180184
fn add_query_eth_client_layer(mut self) -> anyhow::Result<Self> {
181185
let query_eth_client_layer = QueryEthClientLayer::new(
182-
self.config.required.settlement_layer_id(),
186+
self.config.required.l1_chain_id,
183187
self.config.required.eth_client_url.clone(),
188+
self.config.required.gateway_chain_id,
184189
self.config.optional.gateway_url.clone(),
185190
);
186191
self.node.add_layer(query_eth_client_layer);
@@ -285,8 +290,9 @@ impl ExternalNodeBuilder {
285290

286291
fn add_validate_chain_ids_layer(mut self) -> anyhow::Result<Self> {
287292
let layer = ValidateChainIdsLayer::new(
288-
self.config.required.settlement_layer_id(),
293+
self.config.required.l1_chain_id,
289294
self.config.required.l2_chain_id,
295+
self.config.required.gateway_chain_id,
290296
);
291297
self.node.add_layer(layer);
292298
Ok(self)

core/bin/external_node/src/tests/framework.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use zksync_node_framework::{
1717
task::TaskKind,
1818
FromContext, IntoContext, StopReceiver, Task, TaskId, WiringError, WiringLayer,
1919
};
20-
use zksync_types::{L2ChainId, SLChainId};
20+
use zksync_types::{L1ChainId, L2ChainId};
2121
use zksync_web3_decl::client::{MockClient, L1, L2};
2222

2323
use super::ExternalNodeBuilder;
@@ -127,11 +127,11 @@ impl WiringLayer for MockL1ClientLayer {
127127

128128
fn layer_name(&self) -> &'static str {
129129
// We don't care about values, we just want to hijack the layer name.
130-
// TODO(EVM-676): configure the `settlement_mode` here
131130
QueryEthClientLayer::new(
132-
SLChainId(1),
131+
L1ChainId(1),
133132
"https://example.com".parse().unwrap(),
134-
Default::default(),
133+
None,
134+
None,
135135
)
136136
.layer_name()
137137
}

core/bin/system-constants-generator/src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use std::fs;
33
use codegen::{Block, Scope};
44
use serde::{Deserialize, Serialize};
55
use zksync_multivm::{
6-
utils::{get_bootloader_encoding_space, get_bootloader_max_txs_in_batch},
6+
utils::{
7+
get_bootloader_encoding_space, get_bootloader_max_txs_in_batch, get_max_new_factory_deps,
8+
},
79
vm_latest::constants::MAX_VM_PUBDATA_PER_BATCH,
810
zk_evm_latest::zkevm_opcode_defs::{
911
circuit_prices::{
@@ -15,7 +17,7 @@ use zksync_multivm::{
1517
};
1618
use zksync_types::{
1719
IntrinsicSystemGasConstants, ProtocolVersionId, GUARANTEED_PUBDATA_IN_TX,
18-
L1_GAS_PER_PUBDATA_BYTE, MAX_NEW_FACTORY_DEPS, REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE,
20+
L1_GAS_PER_PUBDATA_BYTE, REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE,
1921
};
2022
use zksync_utils::env::Workspace;
2123

@@ -73,7 +75,7 @@ pub fn generate_l1_contracts_system_config(gas_constants: &IntrinsicSystemGasCon
7375
l1_tx_delta_544_encoding_bytes: gas_constants.l1_tx_delta_544_encoding_bytes,
7476
l1_tx_delta_factory_deps_l2_gas: gas_constants.l1_tx_delta_factory_dep_gas,
7577
l1_tx_delta_factory_deps_pubdata: gas_constants.l1_tx_delta_factory_dep_pubdata,
76-
max_new_factory_deps: MAX_NEW_FACTORY_DEPS as u32,
78+
max_new_factory_deps: get_max_new_factory_deps(ProtocolVersionId::latest().into()) as u32,
7779
required_l2_gas_price_per_pubdata: REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE,
7880
};
7981

0 commit comments

Comments
 (0)