Skip to content

Commit 7c72273

Browse files
authored
chore: updates unmaintained deps to alloy alternatives (#559)
* chore: update test deps from ethers to alloy * chore: address lint, and fmt issues * chore: add back comments * chore: satisfy lint
1 parent a955a9b commit 7c72273

File tree

8 files changed

+1612
-1964
lines changed

8 files changed

+1612
-1964
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ zksync_web3_decl = { git = "https://github.com/matter-labs/zksync-era.git", rev
4444
anyhow = "1.0"
4545
alloy-signer-local = { version = "0.5.4", features = ["mnemonic"] }
4646
alloy-signer = { version = "0.5.4", default-features = false }
47+
alloy-dyn-abi = "0.5.4"
48+
alloy-primitives = { version = "0.5.4" }
49+
alloy-json-abi = "0.5.4"
4750
async-trait = "0.1.85"
4851
chrono = { version = "0.4.31", default-features = false }
4952
clap = { version = "4.2.4", features = ["derive", "env"] }
5053
colored = "2"
51-
ethabi = "16.0.0"
5254
eyre = "0.6"
5355
flate2 = "1.0"
5456
futures = { version = "0.3", features = ["compat"] }
@@ -85,8 +87,7 @@ url = "2.5.4"
8587
httptest = "0.15.4"
8688
tempdir = "0.3.7"
8789
maplit = "1.0.2"
88-
zksync-web3-rs = "0.1.1"
89-
ethers = { version = "2.0.4", features = ["rustls"] }
90+
alloy-zksync = "0.9.0"
9091
test-case = "3.3.1"
9192
backon = "1.3.0"
9293

crates/core/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ tokio.workspace = true
2323
futures.workspace = true
2424
once_cell.workspace = true
2525

26+
alloy-json-abi.workspace = true
27+
alloy-primitives.workspace = true
28+
alloy-dyn-abi.workspace = true
29+
2630
reqwest.workspace = true
2731
serde.workspace = true
2832
tracing.workspace = true
@@ -32,7 +36,6 @@ lazy_static.workspace = true
3236
eyre.workspace = true
3337
serde_json.workspace = true
3438
hex.workspace = true
35-
ethabi.workspace = true
3639
itertools.workspace = true
3740
rustc-hash.workspace = true
3841
indexmap.workspace = true
@@ -45,9 +48,8 @@ url.workspace = true
4548

4649
[dev-dependencies]
4750
maplit.workspace = true
48-
ethers.workspace = true
4951
httptest.workspace = true
5052
tempdir.workspace = true
51-
zksync-web3-rs.workspace = true
53+
alloy-zksync.workspace = true
5254
test-case.workspace = true
5355
backon.workspace = true

crates/core/src/console_log.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::{collections::HashMap, str::FromStr};
22

3+
use crate::utils::format_token;
4+
use alloy_dyn_abi::JsonAbiExt;
5+
use alloy_json_abi::{Function, Param, StateMutability};
6+
use alloy_primitives::Selector;
37
use colored::Colorize;
4-
use ethabi::param_type::Reader;
5-
use ethabi::{Function, Param, StateMutability};
68
use itertools::Itertools;
79
use zksync_multivm::interface::Call;
810
use zksync_types::H160;
@@ -15,7 +17,7 @@ use zksync_types::H160;
1517
pub struct ConsoleLogHandler {
1618
/// Map from the 4-byte function signature to function itself.
1719
// This contract has many 'log' methods (depending on argument type) - so we have a map here, to be able to parse the arguments.
18-
signature_map: HashMap<[u8; 4], Function>,
20+
signature_map: HashMap<Selector, Function>,
1921
/// The 'fake' hardcoded contract, whose calls with have to log.
2022
target_contract: H160,
2123
}
@@ -27,7 +29,7 @@ impl Default for ConsoleLogHandler {
2729
Self {
2830
signature_map: get_log_functions()
2931
.into_iter()
30-
.map(|func| (func.short_signature(), func))
32+
.map(|func| (func.selector(), func))
3133
.collect::<HashMap<_, _>>(),
3234
target_contract: H160::from_str(CONSOLE_ADDRESS).unwrap(),
3335
}
@@ -69,10 +71,10 @@ impl ConsoleLogHandler {
6971
self.signature_map
7072
.get(signature)
7173
.map_or("Unknown log call.".to_owned(), |func| {
72-
let tokens = func.decode_input(&current_call.input.as_slice()[4..]);
73-
74+
let tokens: Result<Vec<alloy_dyn_abi::DynSolValue>, alloy_dyn_abi::Error> =
75+
func.abi_decode_input(&current_call.input.as_slice()[4..], false);
7476
tokens.map_or("Failed to parse inputs for log.".to_owned(), |tokens| {
75-
tokens.iter().map(|t| format!("{}", t)).join(" ")
77+
tokens.iter().map(|t| format_token(t, false)).join(" ")
7678
})
7779
});
7880
Some(message)
@@ -89,25 +91,17 @@ fn get_log_functions() -> Vec<Function> {
8991
.split_once('(')
9092
.unwrap_or_else(|| panic!("unable to obtain function name for '{}'", func_decl));
9193

92-
#[allow(deprecated)] // for deprecated field `constant`
9394
Function {
9495
name: String::from(name),
9596
inputs: params
9697
.split(',')
97-
.enumerate()
98-
.map(|(index, param)| Param {
99-
name: format!("p{index}"),
100-
kind: Reader::read(param).unwrap_or_else(|err| {
101-
panic!(
102-
"failed deserializing type '{}' for '{}' : {:?}",
103-
param, func_decl, err
104-
)
105-
}),
106-
internal_type: Some(String::from(param)),
98+
.map(|param| {
99+
Param::parse(param).unwrap_or_else(|err| {
100+
panic!("Failed to parse parameter '{}': {:?}", param, err)
101+
})
107102
})
108103
.collect(),
109104
outputs: vec![],
110-
constant: false,
111105
state_mutability: StateMutability::View,
112106
}
113107
})

crates/core/src/node/debug.rs

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ impl InMemoryNode {
124124

125125
#[cfg(test)]
126126
mod tests {
127+
use alloy_dyn_abi::{DynSolValue, FunctionExt, JsonAbiExt};
128+
use alloy_json_abi::{Function, Param};
129+
use alloy_primitives::{Address as AlloyAddress, U256 as AlloyU256};
127130
use anvil_zksync_config::constants::DEFAULT_ACCOUNT_BALANCE;
128-
use ethers::abi::{short_signature, AbiEncode, HumanReadableParser, ParamType, Token};
129131
use zksync_types::{
130132
transaction_request::CallRequestBuilder, utils::deployed_address_create, Address,
131133
K256PrivateKey, L2BlockNumber, Nonce, H160, U256,
@@ -150,12 +152,16 @@ mod tests {
150152
include_bytes!("../deps/test-contracts/Secondary.json"),
151153
);
152154
let secondary_deployed_address = deployed_address_create(from_account, U256::zero());
155+
let alloy_secondary_address = AlloyAddress::from(secondary_deployed_address.0);
156+
let secondary_constructor_calldata =
157+
DynSolValue::Uint(AlloyU256::from(2), 256).abi_encode();
158+
153159
testing::deploy_contract(
154160
node,
155161
H256::repeat_byte(0x1),
156162
&private_key,
157163
secondary_bytecode,
158-
Some((U256::from(2),).encode()),
164+
Some(secondary_constructor_calldata),
159165
Nonce(0),
160166
)
161167
.await;
@@ -166,15 +172,19 @@ mod tests {
166172
include_bytes!("../deps/test-contracts/Primary.json"),
167173
);
168174
let primary_deployed_address = deployed_address_create(from_account, U256::one());
175+
let primary_constructor_calldata =
176+
DynSolValue::Address(alloy_secondary_address).abi_encode();
177+
169178
testing::deploy_contract(
170179
node,
171180
H256::repeat_byte(0x1),
172181
&private_key,
173182
primary_bytecode,
174-
Some((secondary_deployed_address).encode()),
183+
Some(primary_constructor_calldata),
175184
Nonce(1),
176185
)
177186
.await;
187+
178188
(primary_deployed_address, secondary_deployed_address)
179189
}
180190

@@ -184,9 +194,28 @@ mod tests {
184194

185195
let (primary_deployed_address, secondary_deployed_address) =
186196
deploy_test_contracts(&node).await;
187-
// trace a call to the primary contract
188-
let func = HumanReadableParser::parse_function("calculate(uint)").unwrap();
189-
let calldata = func.encode_input(&[Token::Uint(U256::from(42))]).unwrap();
197+
198+
let func = Function {
199+
name: "calculate".to_string(),
200+
inputs: vec![Param {
201+
name: "value".to_string(),
202+
ty: "uint256".to_string(),
203+
components: vec![],
204+
internal_type: None,
205+
}],
206+
outputs: vec![Param {
207+
name: "".to_string(),
208+
ty: "uint256".to_string(),
209+
components: vec![],
210+
internal_type: None,
211+
}],
212+
state_mutability: alloy_json_abi::StateMutability::NonPayable,
213+
};
214+
215+
let calldata = func
216+
.abi_encode_input(&[DynSolValue::Uint(AlloyU256::from(42), 256)])
217+
.expect("failed to encode function input");
218+
190219
let request = CallRequestBuilder::default()
191220
.to(Some(primary_deployed_address))
192221
.data(calldata.clone().into())
@@ -203,9 +232,14 @@ mod tests {
203232
assert!(trace.revert_reason.is_none());
204233

205234
// check that the call was successful
206-
let output =
207-
ethers::abi::decode(&[ParamType::Uint(256)], trace.output.0.as_slice()).unwrap();
208-
assert_eq!(output[0], Token::Uint(U256::from(84)));
235+
let output = func
236+
.abi_decode_output(trace.output.0.as_slice(), true)
237+
.expect("failed to decode output");
238+
assert_eq!(
239+
output[0],
240+
DynSolValue::Uint(AlloyU256::from(84), 256),
241+
"unexpected output"
242+
);
209243

210244
// find the call to primary contract in the trace
211245
let contract_call = trace
@@ -226,7 +260,12 @@ mod tests {
226260
let subcall = contract_call.calls.first().unwrap();
227261
assert_eq!(subcall.to, secondary_deployed_address);
228262
assert_eq!(subcall.from, primary_deployed_address);
229-
assert_eq!(subcall.output, U256::from(84).encode().into());
263+
assert_eq!(
264+
subcall.output,
265+
func.abi_encode_output(&[DynSolValue::Uint(AlloyU256::from(84), 256)])
266+
.expect("failed to encode function output")
267+
.into()
268+
);
230269
}
231270

232271
#[tokio::test]
@@ -236,8 +275,22 @@ mod tests {
236275
let (primary_deployed_address, _) = deploy_test_contracts(&node).await;
237276

238277
// trace a call to the primary contract
239-
let func = HumanReadableParser::parse_function("calculate(uint)").unwrap();
240-
let calldata = func.encode_input(&[Token::Uint(U256::from(42))]).unwrap();
278+
let func = Function {
279+
name: "calculate".to_string(),
280+
inputs: vec![Param {
281+
name: "value".to_string(),
282+
ty: "uint256".to_string(),
283+
components: vec![],
284+
internal_type: None,
285+
}],
286+
outputs: vec![],
287+
state_mutability: alloy_json_abi::StateMutability::NonPayable,
288+
};
289+
290+
let calldata = func
291+
.abi_encode_input(&[DynSolValue::Uint(AlloyU256::from(42), 256)])
292+
.expect("failed to encode function input");
293+
241294
let request = CallRequestBuilder::default()
242295
.to(Some(primary_deployed_address))
243296
.data(calldata.into())
@@ -273,10 +326,17 @@ mod tests {
273326

274327
let (primary_deployed_address, _) = deploy_test_contracts(&node).await;
275328

329+
let func = Function {
330+
name: "shouldRevert".to_string(),
331+
inputs: vec![],
332+
outputs: vec![],
333+
state_mutability: alloy_json_abi::StateMutability::NonPayable,
334+
};
335+
276336
// trace a call to the primary contract
277337
let request = CallRequestBuilder::default()
278338
.to(Some(primary_deployed_address))
279-
.data(short_signature("shouldRevert()", &[]).into())
339+
.data(func.selector().to_vec().into())
280340
.gas(80_000_000.into())
281341
.build();
282342
let trace = node

0 commit comments

Comments
 (0)