Skip to content

Commit ea3c161

Browse files
feat: split gw ctm deployer (#4615)
## What ❔ For the purposes of zksync os integration, we had to split GatewayCTMDeployer into multiple contracts. Also, we had to adapt some of the scripts to work fine with the latest zksync os workflows ## Why ❔ <!-- Why are these changes done? What goal do they contribute to? What are the principles behind them? --> <!-- The `Why` has to be clear to non-Matter Labs entities running their own ZK Chain --> <!-- Example: PR templates ensure PR reviewers, observers, and future iterators are in context about the evolution of repos. --> ## Is this a breaking change? - [ ] Yes - [ ] No ## Operational changes <!-- Any config changes? Any new flags? Any changes to any scripts? --> <!-- Please add anything that non-Matter Labs entities running their own ZK Chain may need to know --> ## 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 1032e2a commit ea3c161

File tree

11 files changed

+213
-76
lines changed

11 files changed

+213
-76
lines changed

contracts

Submodule contracts updated 84 files

zkstack_cli/crates/config/src/forge_interface/gateway_vote_preparation/input.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use std::str::FromStr;
2-
31
use ethers::types::{Address, H256, U256};
42
use serde::{Deserialize, Serialize};
53

64
use crate::{
75
forge_interface::deploy_ecosystem::input::InitialDeploymentConfig, traits::FileConfigTrait,
8-
ContractsConfig, ContractsGenesisConfig,
6+
ContractsConfig,
97
};
108

119
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -16,13 +14,6 @@ pub struct GatewayContractsConfig {
1614
pub create2_factory_salt: H256,
1715
pub create2_factory_addr: Option<Address>,
1816
pub validator_timelock_execution_delay: U256,
19-
pub genesis_root: H256,
20-
pub genesis_rollup_leaf_index: U256,
21-
pub genesis_batch_commitment: H256,
22-
pub latest_protocol_version: U256,
23-
pub default_aa_hash: H256,
24-
pub bootloader_hash: H256,
25-
pub evm_emulator_hash: Option<H256>,
2617
pub avail_l1_da_validator: Option<Address>,
2718
pub bridgehub_proxy_address: Address,
2819
}
@@ -52,15 +43,14 @@ impl GatewayVotePreparationConfig {
5243
#[allow(clippy::too_many_arguments)]
5344
pub fn new(
5445
initial_deployment_config: &InitialDeploymentConfig,
55-
genesis_input: &ContractsGenesisConfig,
56-
external_contracts_config: &ContractsConfig, // from external context
46+
external_contracts_config: &ContractsConfig,
5747
era_chain_id: U256,
5848
gateway_chain_id: U256,
5949
owner_address: Address,
6050
testnet_verifier: bool,
6151
is_zk_sync_os: bool,
6252
refund_recipient: Address,
63-
) -> anyhow::Result<Self> {
53+
) -> Self {
6454
let contracts = GatewayContractsConfig {
6555
governance_security_council_address: Address::zero(),
6656
governance_min_delay: U256::from(initial_deployment_config.governance_min_delay),
@@ -70,17 +60,6 @@ impl GatewayVotePreparationConfig {
7060
validator_timelock_execution_delay: U256::from(
7161
initial_deployment_config.validator_timelock_execution_delay,
7262
),
73-
genesis_root: H256::from_str(&genesis_input.genesis_root_hash()?)?,
74-
genesis_rollup_leaf_index: U256::from(genesis_input.rollup_last_leaf_index()?),
75-
genesis_batch_commitment: H256::from_str(&genesis_input.genesis_commitment()?)?,
76-
latest_protocol_version: genesis_input.protocol_semantic_version()?.pack(),
77-
default_aa_hash: H256::from_str(&genesis_input.default_aa_hash()?)?,
78-
bootloader_hash: H256::from_str(&genesis_input.bootloader_hash()?)?,
79-
evm_emulator_hash: genesis_input
80-
.evm_emulator_hash()?
81-
.as_ref()
82-
.map(|hash| H256::from_str(&hash.to_string()))
83-
.transpose()?,
8463
avail_l1_da_validator: external_contracts_config.l1.avail_l1_da_validator_addr,
8564
bridgehub_proxy_address: external_contracts_config
8665
.ecosystem_contracts
@@ -91,7 +70,7 @@ impl GatewayVotePreparationConfig {
9170
token_weth_address: initial_deployment_config.token_weth_address,
9271
};
9372

94-
Ok(Self {
73+
Self {
9574
era_chain_id,
9675
owner_address,
9776
testnet_verifier,
@@ -107,6 +86,6 @@ impl GatewayVotePreparationConfig {
10786
.force_deployments_data
10887
.clone()
10988
.unwrap_or_default(),
110-
})
89+
}
11190
}
11291
}

zkstack_cli/crates/zkstack/src/commands/chain/args/init/da_configs.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ pub enum ValidiumTypeInternal {
3131
EigenDA,
3232
}
3333

34+
impl ValidiumTypeInternal {
35+
pub fn as_str(&self) -> &str {
36+
match self {
37+
ValidiumTypeInternal::NoDA => "NoDA",
38+
ValidiumTypeInternal::Avail => "Avail",
39+
ValidiumTypeInternal::EigenDA => "EigenDA",
40+
}
41+
}
42+
}
43+
3444
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, EnumIter, Display, ValueEnum)]
3545
pub enum AvailClientTypeInternal {
3646
FullClient,

zkstack_cli/crates/zkstack/src/commands/chain/gateway/convert_to_gateway.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ pub struct ConvertToGatewayArgs {
5050

5151
#[clap(long, default_value_t = false)]
5252
pub only_save_calldata: bool,
53+
54+
/// L1 RPC URL. If not provided, will be read from chain secrets config.
55+
#[clap(long)]
56+
pub l1_rpc_url: Option<String>,
57+
58+
/// Skip applying gateway config overrides (overrides/gateway.yaml).
59+
/// By default, the gateway.yaml file is required.
60+
#[clap(long, default_value_t = false)]
61+
pub no_gateway_overrides: bool,
5362
}
5463

5564
fn parse_decimal_u256(s: &str) -> Result<U256, String> {
@@ -60,21 +69,26 @@ fn parse_decimal_u256(s: &str) -> Result<U256, String> {
6069
}
6170

6271
pub async fn run(convert_to_gw_args: ConvertToGatewayArgs, shell: &Shell) -> anyhow::Result<()> {
63-
let args = convert_to_gw_args.forge_args;
72+
let args = convert_to_gw_args.forge_args.clone();
6473
let ecosystem_config = ZkStackConfig::ecosystem(shell)?;
6574
let chain_config = ecosystem_config
6675
.load_current_chain()
6776
.context(MSG_CHAIN_NOT_INITIALIZED)?;
68-
let l1_url = chain_config.get_secrets_config().await?.l1_rpc_url()?;
77+
let l1_url = match convert_to_gw_args.l1_rpc_url {
78+
Some(url) => url,
79+
None => chain_config.get_secrets_config().await?.l1_rpc_url()?,
80+
};
6981
let chain_contracts_config = chain_config.get_contracts_config()?;
70-
let contracts_config = chain_config.get_contracts_genesis_config().await?;
71-
override_config(
72-
shell,
73-
&ecosystem_config
74-
.default_configs_path_for_ctm(chain_config.vm_option)
75-
.join(PATH_TO_GATEWAY_OVERRIDE_CONFIG),
76-
&chain_config,
77-
)?;
82+
83+
if !convert_to_gw_args.no_gateway_overrides {
84+
override_config(
85+
shell,
86+
&ecosystem_config
87+
.default_configs_path_for_ctm(chain_config.vm_option)
88+
.join(PATH_TO_GATEWAY_OVERRIDE_CONFIG),
89+
&chain_config,
90+
)?;
91+
}
7892

7993
let chain_deployer_wallet = chain_config
8094
.get_wallets_config()?
@@ -141,15 +155,14 @@ pub async fn run(convert_to_gw_args: ConvertToGatewayArgs, shell: &Shell) -> any
141155
&chain_deployer_wallet,
142156
GatewayVotePreparationConfig::new(
143157
&ecosystem_config.get_initial_deployment_config().unwrap(),
144-
&contracts_config,
145158
&chain_contracts_config,
146159
ecosystem_config.era_chain_id.as_u64().into(),
147160
chain_config.chain_id.as_u64().into(),
148161
ecosystem_config.get_contracts_config()?.l1.governance_addr,
149162
ecosystem_config.prover_version == ProverMode::NoProofs,
150163
chain_config.vm_option.is_zksync_os(),
151164
chain_deployer_wallet.address,
152-
)?,
165+
),
153166
l1_url.clone(),
154167
convert_to_gw_args
155168
.ctm_chain_id

zkstack_cli/crates/zkstack/src/commands/chain/gateway/create_tx_filterer.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use anyhow::Context;
2+
use clap::Parser;
23
use ethers::contract::BaseContract;
34
use lazy_static::lazy_static;
5+
use serde::{Deserialize, Serialize};
46
use xshell::Shell;
57
use zkstack_cli_common::{
68
config::global_config,
@@ -28,13 +30,28 @@ lazy_static! {
2830
BaseContract::from(DEPLOYGATEWAYTRANSACTIONFILTERERABI_ABI.clone());
2931
}
3032

31-
pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
33+
#[derive(Debug, Serialize, Deserialize, Parser)]
34+
pub struct CreateTxFiltererArgs {
35+
/// All ethereum environment related arguments
36+
#[clap(flatten)]
37+
#[serde(flatten)]
38+
pub forge_args: ForgeScriptArgs,
39+
40+
/// L1 RPC URL. If not provided, will be read from chain secrets config.
41+
#[clap(long)]
42+
pub l1_rpc_url: Option<String>,
43+
}
44+
45+
pub async fn run(args: CreateTxFiltererArgs, shell: &Shell) -> anyhow::Result<()> {
3246
let chain_name = global_config().chain_name.clone();
3347
let ecosystem_config = ZkStackConfig::ecosystem(shell)?;
3448
let chain_config = ecosystem_config
3549
.load_chain(chain_name)
3650
.context(MSG_CHAIN_NOT_INITIALIZED)?;
37-
let l1_url = chain_config.get_secrets_config().await?.l1_rpc_url()?;
51+
let l1_url = match args.l1_rpc_url {
52+
Some(url) => url,
53+
None => chain_config.get_secrets_config().await?.l1_rpc_url()?,
54+
};
3855
let mut chain_contracts_config = chain_config.get_contracts_config()?;
3956

4057
let chain_deployer_wallet = chain_config
@@ -44,7 +61,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
4461

4562
let output: GatewayTxFiltererOutput = deploy_gateway_tx_filterer(
4663
shell,
47-
args.clone(),
64+
args.forge_args.clone(),
4865
&chain_config,
4966
&chain_deployer_wallet,
5067
&chain_contracts_config,
@@ -54,7 +71,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
5471

5572
set_transaction_filterer(
5673
shell,
57-
&args,
74+
&args.forge_args,
5875
&chain_config.path_to_foundry_scripts(),
5976
AdminScriptMode::Broadcast(chain_config.get_wallets_config()?.governor),
6077
chain_config.chain_id.as_u64(),

zkstack_cli/crates/zkstack/src/commands/chain/gateway/finalize_chain_migration_to_gateway.rs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use crate::{
3434
abi::GATEWAYUTILSABI_ABI,
3535
admin_functions::AdminScriptMode,
3636
commands::chain::{
37+
args::init::da_configs::ValidiumTypeInternal,
3738
gateway::{
3839
gateway_common::{extract_and_wait_for_priority_ops, get_migration_transaction},
3940
migrate_from_gateway::{
@@ -63,6 +64,18 @@ pub struct FinalizeChainMigrationToGatewayArgs {
6364
pub deploy_paymaster: Option<bool>,
6465
#[clap(long, default_missing_value = "true", num_args = 0..=1)]
6566
pub tx_status: Option<bool>,
67+
68+
/// L1 RPC URL. If not provided, will be read from chain secrets config.
69+
#[clap(long)]
70+
pub l1_rpc_url: Option<String>,
71+
72+
/// Gateway RPC URL. If not provided, will be read from gateway chain's general config.
73+
#[clap(long)]
74+
pub gateway_rpc_url: Option<String>,
75+
76+
/// Validium type for the chain. If not provided, will be read from chain's general config.
77+
#[clap(long)]
78+
pub validium_type: Option<ValidiumTypeInternal>,
6679
}
6780

6881
lazy_static! {
@@ -83,6 +96,9 @@ impl FinalizeChainMigrationToGatewayArgs {
8396
gateway_chain_name: self.gateway_chain_name,
8497
deploy_paymaster,
8598
tx_status: self.tx_status.unwrap_or(true),
99+
l1_rpc_url: self.l1_rpc_url,
100+
gateway_rpc_url: self.gateway_rpc_url,
101+
validium_type: self.validium_type,
86102
}
87103
}
88104
}
@@ -93,6 +109,9 @@ pub struct FinalizeChainMigrationToGatewayArgsFinal {
93109
pub gateway_chain_name: String,
94110
pub deploy_paymaster: bool,
95111
pub tx_status: bool,
112+
pub l1_rpc_url: Option<String>,
113+
pub gateway_rpc_url: Option<String>,
114+
pub validium_type: Option<ValidiumTypeInternal>,
96115
}
97116

98117
pub async fn run(args: FinalizeChainMigrationToGatewayArgs, shell: &Shell) -> anyhow::Result<()> {
@@ -131,14 +150,22 @@ pub async fn run_inner(
131150
chain_config: &ChainConfig,
132151
gateway_chain_config: &ChainConfig,
133152
) -> anyhow::Result<()> {
134-
let l1_rpc_url = chain_config.get_secrets_config().await?.l1_rpc_url()?;
153+
let l1_rpc_url = match &args.l1_rpc_url {
154+
Some(url) => url.clone(),
155+
None => chain_config.get_secrets_config().await?.l1_rpc_url()?,
156+
};
135157
let l1_provider = get_ethers_provider(&l1_rpc_url)?;
136158

137-
let general_config = gateway_chain_config.get_general_config().await?;
138159
let gateway_chain_id = gateway_chain_config.chain_id.as_u64();
139-
let gw_rpc_url = general_config.l2_http_url()?;
140-
let gateway_provider = get_ethers_provider(&gw_rpc_url)?;
141-
let gateway_zk_client = get_zk_client(&gw_rpc_url, chain_config.chain_id.as_u64())?;
160+
let gateway_rpc_url = match &args.gateway_rpc_url {
161+
Some(url) => url.clone(),
162+
None => {
163+
let general_config = gateway_chain_config.get_general_config().await?;
164+
general_config.l2_http_url()?
165+
}
166+
};
167+
let gateway_provider = get_ethers_provider(&gateway_rpc_url)?;
168+
let gateway_zk_client = get_zk_client(&gateway_rpc_url, chain_config.chain_id.as_u64())?;
142169

143170
let mut contracts_config = chain_config.get_contracts_config()?;
144171

@@ -217,13 +244,21 @@ pub async fn run_inner(
217244
ecosystem_config,
218245
&mut contracts_config,
219246
&args.forge_args,
220-
l1_rpc_url,
247+
l1_rpc_url.clone(),
221248
args.deploy_paymaster,
249+
args.validium_type.clone(),
222250
)
223251
.await?;
224252

225253
// Set the DA validator pair on the Gateway
226-
let context = get_migrate_to_gateway_context(chain_config, gateway_chain_config, true).await?;
254+
let context = get_migrate_to_gateway_context(
255+
chain_config,
256+
gateway_chain_config,
257+
true,
258+
l1_rpc_url,
259+
gateway_rpc_url,
260+
)
261+
.await?;
227262

228263
let (_, l2_da_validator_commitment_scheme) =
229264
context.l1_zk_chain.get_da_validator_pair().await?;

zkstack_cli/crates/zkstack/src/commands/chain/gateway/gateway_common.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ impl MigrationDirection {
5050
}
5151
}
5252

53+
#[derive(Debug, clap::Parser)]
54+
pub struct NotifyServerArgs {
55+
/// All ethereum environment related arguments
56+
#[clap(flatten)]
57+
pub forge_args: ForgeScriptArgs,
58+
59+
/// L1 RPC URL. If not provided, will be read from chain secrets config.
60+
#[clap(long)]
61+
pub l1_rpc_url: Option<String>,
62+
}
63+
5364
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
5465
pub enum NotificationReceivedState {
5566
NotAllBatchesCommitted,
@@ -469,18 +480,21 @@ pub(crate) async fn await_for_tx_to_complete(
469480
}
470481

471482
pub(crate) async fn notify_server(
472-
args: ForgeScriptArgs,
483+
args: NotifyServerArgs,
473484
shell: &Shell,
474485
direction: MigrationDirection,
475486
) -> anyhow::Result<()> {
476487
let chain_config = ZkStackConfig::current_chain(shell)?;
477488

478-
let l1_url = chain_config.get_secrets_config().await?.l1_rpc_url()?;
489+
let l1_url = match args.l1_rpc_url {
490+
Some(url) => url,
491+
None => chain_config.get_secrets_config().await?.l1_rpc_url()?,
492+
};
479493
let contracts = chain_config.get_contracts_config()?;
480494

481495
let calls = get_notify_server_calls(
482496
shell,
483-
&args,
497+
&args.forge_args,
484498
&chain_config.path_to_foundry_scripts(),
485499
NotifyServerCallsArgs {
486500
l1_bridgehub_addr: contracts.ecosystem_contracts.bridgehub_proxy_addr,

0 commit comments

Comments
 (0)