Skip to content

Commit 7bcf275

Browse files
authored
fix: remove zksync_contracts dep from zkstack_cli (#4400)
## What ❔ - removes zksync_contracts dep from zkstack_cli <!-- 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 ❔ - zkstack_cli breaks due to path issue when used outside of zksync_era repo <!-- 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 - [x] 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 3b61f62 commit 7bcf275

File tree

7 files changed

+152
-46
lines changed

7 files changed

+152
-46
lines changed

zkstack_cli/Cargo.lock

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

zkstack_cli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ zksync_basic_types = { path = "../core/lib/basic_types" }
3131
zksync_system_constants = { path = "../core/lib/constants" }
3232
zksync_types = { path = "../core/lib/types" }
3333
zksync_web3_decl = { path = "../core/lib/web3_decl" }
34-
zksync_contracts = { path = "../core/lib/contracts" }
3534
zksync_consensus_roles = "=0.13"
3635
zksync_consensus_crypto = "=0.13"
3736

zkstack_cli/crates/zkstack/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ zksync_consensus_roles.workspace = true
4444
zksync_consensus_crypto.workspace = true
4545
zksync_web3_decl.workspace = true
4646
zksync_system_constants.workspace = true
47-
zksync_contracts.workspace = true
4847
prost.workspace = true
4948
reqwest.workspace = true
5049
sha2.workspace = true

zkstack_cli/crates/zkstack/src/abi.rs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ abigen!(
1010
function ctmAssetIdFromChainId(uint256)(bytes32)
1111
function baseTokenAssetId(uint256)(bytes32)
1212
function chainTypeManager(uint256)(address)
13+
function chainAssetHandler() external view returns (address)
1314
]"
1415
);
1516

@@ -49,3 +50,103 @@ abigen!(
4950
function validators(uint256 _chainId, address _validator)(bool)
5051
]"
5152
);
53+
54+
abigen!(
55+
IChainAssetHandlerAbi,
56+
r"[
57+
event MigrationStarted(uint256 indexed chainId, bytes32 indexed assetId, uint256 indexed settlementLayerChainId)
58+
]"
59+
);
60+
61+
// These ABIs are defined in JSON format rather than human-readable form because
62+
// ethers v2 cannot parse complex nested tuple parameters (e.g., tuple[] inside tuple)
63+
// from the human-readable syntax
64+
65+
abigen!(
66+
ChainTypeManagerUpgradeFnAbi,
67+
r#"[
68+
{
69+
"type": "function",
70+
"name": "upgradeChainFromVersion",
71+
"stateMutability": "nonpayable",
72+
"inputs": [
73+
{ "name": "version", "type": "uint256" },
74+
{
75+
"name": "cfg",
76+
"type": "tuple",
77+
"components": [
78+
{
79+
"name": "validators",
80+
"type": "tuple[]",
81+
"components": [
82+
{ "name": "addr", "type": "address" },
83+
{ "name": "weight", "type": "uint8" },
84+
{ "name": "active", "type": "bool" },
85+
{ "name": "selectors", "type": "bytes4[]" }
86+
]
87+
},
88+
{ "name": "admin", "type": "address" },
89+
{ "name": "data", "type": "bytes" }
90+
]
91+
}
92+
],
93+
"outputs": []
94+
}
95+
]"#
96+
);
97+
98+
abigen!(
99+
DiamondCutAbi,
100+
r#"[
101+
{
102+
"type": "function",
103+
"name": "diamondCut",
104+
"stateMutability": "nonpayable",
105+
"inputs": [
106+
{
107+
"name": "_diamondCut",
108+
"type": "tuple",
109+
"components": [
110+
{
111+
"name": "facetCuts",
112+
"type": "tuple[]",
113+
"components": [
114+
{ "name": "facet", "type": "address" },
115+
{ "name": "action", "type": "uint8" },
116+
{ "name": "isFreezable", "type": "bool" },
117+
{ "name": "selectors", "type": "bytes4[]" }
118+
]
119+
},
120+
{ "name": "initAddress", "type": "address" },
121+
{ "name": "initCalldata", "type": "bytes" }
122+
]
123+
}
124+
],
125+
"outputs": []
126+
}
127+
]"#
128+
);
129+
130+
abigen!(
131+
ChainAdminOwnableAbi,
132+
r#"[
133+
{
134+
"type": "function",
135+
"name": "multicall",
136+
"stateMutability": "payable",
137+
"inputs": [
138+
{
139+
"name": "_calls",
140+
"type": "tuple[]",
141+
"components": [
142+
{ "name": "target", "type": "address" },
143+
{ "name": "value", "type": "uint256" },
144+
{ "name": "data", "type": "bytes" }
145+
]
146+
},
147+
{ "name": "_requireSuccess", "type": "bool" }
148+
],
149+
"outputs": []
150+
}
151+
]"#
152+
);

zkstack_cli/crates/zkstack/src/commands/chain/admin_call_builder.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
use std::path::Path;
22

33
use ethers::{
4-
abi::{decode, ParamType, Token},
4+
abi::{decode, Abi, ParamType, Token},
55
types::Bytes,
66
utils::hex,
77
};
88
use serde::Serialize;
99
use xshell::Shell;
1010
use zkstack_cli_common::forge::ForgeScriptArgs;
11-
use zksync_contracts::chain_admin_contract;
12-
use zksync_types::{ethabi, Address, U256};
11+
use zksync_types::{Address, U256};
12+
13+
use crate::abi::{
14+
CHAINADMINOWNABLEABI_ABI as CHAIN_ADMIN_OWNABLE_ABI,
15+
CHAINTYPEMANAGERUPGRADEFNABI_ABI as CHAIN_TYPE_MANAGER_UPGRADE_ABI,
16+
DIAMONDCUTABI_ABI as DIAMOND_CUT_ABI,
17+
};
1318

1419
#[derive(Debug, Clone, Serialize)]
1520
pub struct AdminCall {
@@ -83,14 +88,14 @@ where
8388
#[derive(Debug, Clone)]
8489
pub struct AdminCallBuilder {
8590
calls: Vec<AdminCall>,
86-
chain_admin_abi: ethabi::Contract,
91+
chain_admin_abi: Abi,
8792
}
8893

8994
impl AdminCallBuilder {
9095
pub fn new(calls: Vec<AdminCall>) -> Self {
9196
Self {
9297
calls,
93-
chain_admin_abi: chain_admin_contract(),
98+
chain_admin_abi: CHAIN_ADMIN_OWNABLE_ABI.clone(),
9499
}
95100
}
96101

@@ -149,19 +154,29 @@ impl AdminCallBuilder {
149154
protocol_version: u64,
150155
diamond_cut_data: zksync_types::web3::Bytes,
151156
) {
152-
let diamond_cut = zksync_contracts::DIAMOND_CUT
153-
.decode_input(&diamond_cut_data.0)
154-
.unwrap()[0]
155-
.clone();
156-
let zkchain_abi = zksync_contracts::hyperchain_contract();
157+
let diamond_cut_fn = DIAMOND_CUT_ABI
158+
.function("diamondCut")
159+
.expect("diamondCut ABI not found");
157160

158-
let data = zkchain_abi
161+
let upgrade_fn = CHAIN_TYPE_MANAGER_UPGRADE_ABI
159162
.function("upgradeChainFromVersion")
160-
.unwrap()
161-
.encode_input(&[Token::Uint(protocol_version.into()), diamond_cut])
162-
.unwrap();
163-
let description = "Executing upgrade:".to_string();
163+
.expect("upgradeChainFromVersion ABI not found");
164164

165+
let decoded = diamond_cut_fn
166+
.decode_input(diamond_cut_data.0.get(4..).unwrap_or(&diamond_cut_data.0))
167+
.or_else(|_| diamond_cut_fn.decode_input(&diamond_cut_data.0))
168+
.expect("invalid diamondCut calldata");
169+
170+
let cfg_tuple = decoded
171+
.into_iter()
172+
.next()
173+
.expect("diamondCut expects 1 argument (tuple)");
174+
175+
let data = upgrade_fn
176+
.encode_input(&[Token::Uint(U256::from(protocol_version)), cfg_tuple])
177+
.expect("encode upgradeChainFromVersion failed");
178+
179+
let description = "Executing upgrade:".to_string();
165180
let call = AdminCall {
166181
description,
167182
data: data.to_vec(),

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

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use chrono::Utc;
77
use ethers::{
88
providers::{Http, Middleware, Provider},
99
types::{Filter, TransactionReceipt},
10+
utils::keccak256,
1011
};
1112
use xshell::Shell;
1213
use zkstack_cli_common::{
@@ -16,7 +17,6 @@ use zkstack_cli_common::{
1617
};
1718
use zkstack_cli_config::EcosystemConfig;
1819
use zksync_basic_types::{Address, H256, U256, U64};
19-
use zksync_contracts::bridgehub_contract;
2020
use zksync_system_constants::L2_BRIDGEHUB_ADDRESS;
2121
use zksync_types::{
2222
server_notification::{GatewayMigrationNotification, GatewayMigrationState},
@@ -30,7 +30,7 @@ use super::{
3030
notify_server_calldata::{get_notify_server_calls, NotifyServerCallsArgs},
3131
};
3232
use crate::{
33-
abi::{BridgehubAbi, ChainTypeManagerAbi, ZkChainAbi},
33+
abi::{BridgehubAbi, ChainTypeManagerAbi, IChainAssetHandlerAbi, ZkChainAbi},
3434
commands::chain::{admin_call_builder::AdminCallBuilder, utils::send_tx},
3535
consts::DEFAULT_EVENTS_BLOCK_RANGE,
3636
messages::MSG_CHAIN_NOT_INITIALIZED,
@@ -118,32 +118,29 @@ pub(crate) async fn get_migration_transaction(
118118
.expect("Failed to fetch latest block")
119119
.as_u64();
120120

121-
let bridgehub_contract = bridgehub_contract();
121+
let bridgehub = BridgehubAbi::new(bridgehub_address, provider.clone());
122+
let chain_asset_handler_addr = bridgehub.chain_asset_handler().await?;
123+
let chain_asset_handler =
124+
IChainAssetHandlerAbi::new(chain_asset_handler_addr, provider.clone());
122125

123126
let max_interval_to_search = Utc::now() - MAX_SEARCHING_MIGRATION_TXS_INTERVAL;
124-
let latest_event_log = loop {
127+
let latest_tx_hash: Option<H256> = loop {
125128
let lower_bound = search_upper_bound.saturating_sub(DEFAULT_EVENTS_BLOCK_RANGE);
126129

127130
logger::info(format!(
128131
"Checking block range: {}..={}",
129132
lower_bound, search_upper_bound
130133
));
131134

132-
let filter = Filter::new()
133-
.address(bridgehub_address)
134-
.topic0(
135-
bridgehub_contract
136-
.event("MigrationStarted")
137-
.unwrap()
138-
.signature(),
139-
)
135+
let ev = chain_asset_handler
136+
.migration_started_filter()
137+
.topic1(U256::from(l2_chain_id))
140138
.from_block(lower_bound)
141-
.topic1(u256_to_h256(U256::from(l2_chain_id)))
142139
.to_block(search_upper_bound);
143140

144-
let result_logs = provider.get_logs(&filter).await?;
145-
if !result_logs.is_empty() {
146-
break result_logs.last().cloned();
141+
let results = ev.query_with_meta().await?;
142+
if let Some((_, meta)) = results.last() {
143+
break Some(meta.transaction_hash);
147144
}
148145

149146
if lower_bound == 0 {
@@ -162,11 +159,7 @@ pub(crate) async fn get_migration_transaction(
162159
search_upper_bound = lower_bound - 1;
163160
};
164161

165-
let Some(log) = latest_event_log else {
166-
return Ok(None);
167-
};
168-
169-
Ok(log.transaction_hash)
162+
Ok(latest_tx_hash)
170163
}
171164

172165
async fn get_batch_execution_status(
@@ -532,8 +525,9 @@ pub(crate) async fn extract_priority_ops(
532525
receipt: TransactionReceipt,
533526
expected_diamond_proxy: Address,
534527
) -> anyhow::Result<Vec<H256>> {
535-
let contract = zksync_contracts::hyperchain_contract();
536-
let expected_topic_0 = contract.event("NewPriorityRequest").unwrap().signature();
528+
let expected_topic_0: ethers::types::H256 = ethers::types::H256::from(keccak256(
529+
b"NewPriorityRequest(uint256,bytes32,uint64,(uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256[4],bytes,bytes,uint256[],bytes,bytes),bytes[])",
530+
));
537531

538532
let priority_ops = receipt
539533
.logs

zkstack_cli/crates/zkstack/src/commands/dev/commands/track_priority_txs.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ use cliclack::clear_screen;
77
use ethers::{
88
providers::{Http, Middleware, Provider},
99
types::{Filter, H256},
10+
utils::keccak256,
1011
};
1112
use zkstack_cli_common::{
1213
ethereum::{get_ethers_provider, get_zk_client_from_url},
1314
logger,
1415
};
1516
use zksync_basic_types::Address;
16-
use zksync_contracts::hyperchain_contract;
1717
use zksync_types::l1::L1Tx;
1818
use zksync_web3_decl::{
1919
client::{Client, L2},
@@ -92,10 +92,9 @@ async fn get_txs_status(
9292
l1_tx_hash: Option<H256>,
9393
l2_tx_hash: Option<H256>,
9494
) -> anyhow::Result<Vec<TxStatus>> {
95-
let topic = hyperchain_contract()
96-
.event("NewPriorityRequest")
97-
.unwrap()
98-
.signature();
95+
let topic: ethers::types::H256 = ethers::types::H256::from(keccak256(
96+
b"NewPriorityRequest(uint256,bytes32,uint64,(uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256[4],bytes,bytes,uint256[],bytes,bytes),bytes[])",
97+
));
9998

10099
// Get the latest block so we know how far we can go
101100
let latest_block = l1_provider

0 commit comments

Comments
 (0)