Skip to content

Commit 36cd668

Browse files
Raid5594Deniallugo
andauthored
feat: split zkstack cli command (#4418)
## What ❔ <!-- What are the changes this PR brings about? --> <!-- Example: This PR adds a PR template to the repo. --> <!-- (For bigger PRs adding more context is appreciated) --> ## 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`. --------- Signed-off-by: Danil <[email protected]> Co-authored-by: Danil <[email protected]>
1 parent 1045edc commit 36cd668

File tree

21 files changed

+1276
-315
lines changed

21 files changed

+1276
-315
lines changed

.github/workflows/ci-core-reusable.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ jobs:
247247
--chain gateway \
248248
--validium-type no-da
249249
250+
ci_run zkstack chain gateway create-tx-filterer --chain gateway --ignore-prerequisites
250251
ci_run zkstack chain gateway convert-to-gateway --chain gateway --ignore-prerequisites
251252
252253
- name: Run gateway

zkstack_cli/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,47 @@ zkstack ecosystem init --dev
9696
If the process gets stuck, resume it with `--resume`. This flag keeps track of already sent transactions and sends new
9797
ones with provided params.
9898

99+
To create only the ecosystem:
100+
101+
```bash
102+
zkstack ecosystem init-core-contracts --l1-rpc-url <L1_RPC_ENDPOINT>
103+
```
104+
105+
If the ecosystem has already been initialized, you can create a new ctm and rigester it in the existing bridgehub.
106+
107+
This command create a new ctm and all related contracts:
108+
109+
```bash
110+
zkstack ecosystem init-new-ctm --l1-rpc-url <L1_RPC_ENDPOINT> --bridgehub <BRIDGEHUB_CONTRACT_ADDRESS>
111+
```
112+
113+
This should be called afterwards to register the created ctm in the bridgehub:
114+
115+
```bash
116+
zkstack ecosystem register-ctm --l1-rpc-url <L1_RPC_ENDPOINT>
117+
```
118+
119+
#### Gateway
120+
121+
If the want to convert the newly created gateway chain to become the settlement layer for local testing:
122+
123+
```bash
124+
zkstack chain gateway convert-to-gateway --chain <GATEWAY_CHAIN_NAME>
125+
```
126+
127+
If we want to deploy a CTM on gateway for an existing settlement layer, please provide the bridgehub address and id of
128+
the chain, whose ctm you want to deploy:
129+
130+
```bash
131+
zkstack chain gateway convert-to-gateway --chain <GATEWAY_CHAIN_NAME> --ignore-prerequisites --bridgehub-addr <BRIDGEHUB_CONTRACT_ADDRESS> --ctm-chain-id <CHAIN_ID_FOR_CTM>
132+
```
133+
134+
To migrate the chain on top of gateway afterwards:
135+
136+
```bash
137+
zkstack chain gateway migrate-to-gateway --chain <NAME_OF_CHAIN_TO_MIGRATE> --gateway-chain-name <GATEWAY_CHAIN_NAME>
138+
```
139+
99140
#### Verifying Contracts
100141

101142
To verify contracts, use the `--verify` flag.

zkstack_cli/crates/config/src/forge_interface/script_params.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ pub const DEPLOY_ECOSYSTEM_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams
3030
script_path: "deploy-scripts/DeployL1.s.sol",
3131
};
3232

33+
pub const DEPLOY_ECOSYSTEM_CORE_CONTRACTS_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams {
34+
input: "script-config/config-deploy-l1.toml",
35+
output: "script-out/output-deploy-l1.toml",
36+
script_path: "deploy-scripts/DeployL1CoreContracts.s.sol",
37+
};
38+
39+
pub const REGISTER_CTM_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams {
40+
input: "script-config/config-deploy-l1.toml",
41+
output: "script-out/output-deploy-l1.toml",
42+
script_path: "deploy-scripts/RegisterCTM.s.sol",
43+
};
44+
3345
pub const DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams {
3446
input: "script-config/config-deploy-l2-contracts.toml",
3547
output: "script-out/output-deploy-l2-contracts.toml",

zkstack_cli/crates/zkstack/src/abi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ abigen!(
1111
function baseTokenAssetId(uint256)(bytes32)
1212
function chainTypeManager(uint256)(address)
1313
function chainAssetHandler() external view returns (address)
14+
function owner()(address)
1415
]"
1516
);
1617

zkstack_cli/crates/zkstack/src/admin_functions.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,25 @@ pub async fn make_permanent_rollup(
152152
pub async fn governance_execute_calls(
153153
shell: &Shell,
154154
ecosystem_config: &EcosystemConfig,
155-
governor: &Wallet,
155+
mode: AdminScriptMode,
156156
encoded_calls: Vec<u8>,
157157
forge_args: &ForgeScriptArgs,
158158
l1_rpc_url: String,
159-
) -> anyhow::Result<()> {
159+
governance_address: Option<Address>,
160+
) -> anyhow::Result<AdminScriptOutput> {
160161
// resume doesn't properly work here.
161162
let mut forge_args = forge_args.clone();
162163
forge_args.resume = false;
163164

164-
let governance_address = ecosystem_config.get_contracts_config()?.l1.governance_addr;
165+
let governance_address = match governance_address {
166+
Some(addr) => addr,
167+
None => {
168+
let cfg = ecosystem_config
169+
.get_contracts_config()
170+
.context("Failed to fetch contracts config to resolve governance address")?;
171+
cfg.l1.governance_addr
172+
}
173+
};
165174

166175
let calldata = ADMIN_FUNCTIONS
167176
.encode(
@@ -177,9 +186,25 @@ pub async fn governance_execute_calls(
177186
)
178187
.with_ffi()
179188
.with_rpc_url(l1_rpc_url)
180-
.with_broadcast()
181189
.with_calldata(&calldata);
182-
accept_ownership(shell, governor, forge).await
190+
191+
let description = "executing governance calls";
192+
let (forge, spinner_text) = match mode {
193+
AdminScriptMode::OnlySave => (forge, format!("Preparing calldata for {description}")),
194+
AdminScriptMode::Broadcast(wallet) => {
195+
let forge = forge.with_broadcast();
196+
let forge = fill_forge_private_key(forge, Some(&wallet), WalletOwner::Governor)?;
197+
check_the_balance(&forge).await?;
198+
(forge, format!("Executing {description}"))
199+
}
200+
};
201+
202+
let spinner = Spinner::new(&spinner_text);
203+
forge.run(shell)?;
204+
spinner.finish();
205+
206+
let output_path = ACCEPT_GOVERNANCE_SCRIPT_PARAMS.output(&foundry_contracts_path);
207+
Ok(AdminScriptOutputInner::read(shell, output_path)?.into())
183208
}
184209

185210
#[allow(clippy::too_many_arguments)]
@@ -369,6 +394,7 @@ async fn accept_ownership(
369394
Ok(())
370395
}
371396

397+
#[derive(Clone)]
372398
pub enum AdminScriptMode {
373399
OnlySave,
374400
Broadcast(Wallet),

0 commit comments

Comments
 (0)