Skip to content

Commit 0ad127a

Browse files
klkvrmattsse
andauthored
fix: some verify-bytecode fixes (#8513)
* fix: some verify-bytecode fixes * update constructor args handling * --encoded-constructor-args * warn on length mismatch --------- Co-authored-by: Matthias Seitz <[email protected]>
1 parent 6c58167 commit 0ad127a

File tree

4 files changed

+132
-128
lines changed

4 files changed

+132
-128
lines changed

Cargo.lock

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

crates/common/src/abi.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
//! ABI related helper functions.
22
33
use alloy_dyn_abi::{DynSolType, DynSolValue, FunctionExt, JsonAbiExt};
4-
use alloy_json_abi::{Event, Function};
4+
use alloy_json_abi::{Event, Function, Param};
55
use alloy_primitives::{hex, Address, LogData};
66
use eyre::{Context, ContextCompat, Result};
77
use foundry_block_explorers::{contract::ContractMetadata, errors::EtherscanError, Client};
88
use foundry_config::Chain;
99
use std::{future::Future, pin::Pin};
1010

11+
pub fn encode_args<I, S>(inputs: &[Param], args: I) -> Result<Vec<DynSolValue>>
12+
where
13+
I: IntoIterator<Item = S>,
14+
S: AsRef<str>,
15+
{
16+
std::iter::zip(inputs, args)
17+
.map(|(input, arg)| coerce_value(&input.selector_type(), arg.as_ref()))
18+
.collect()
19+
}
20+
1121
/// Given a function and a vector of string arguments, it proceeds to convert the args to alloy
1222
/// [DynSolValue]s and then ABI encode them.
1323
pub fn encode_function_args<I, S>(func: &Function, args: I) -> Result<Vec<u8>>
1424
where
1525
I: IntoIterator<Item = S>,
1626
S: AsRef<str>,
1727
{
18-
let params = std::iter::zip(&func.inputs, args)
19-
.map(|(input, arg)| coerce_value(&input.selector_type(), arg.as_ref()))
20-
.collect::<Result<Vec<_>>>()?;
21-
func.abi_encode_input(params.as_slice()).map_err(Into::into)
28+
Ok(func.abi_encode_input(&encode_args(&func.inputs, args)?)?)
2229
}
2330

2431
/// Given a function and a vector of string arguments, it proceeds to convert the args to alloy

crates/verify/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ serde_json.workspace = true
2222
alloy-json-abi.workspace = true
2323
alloy-primitives.workspace = true
2424
alloy-rpc-types.workspace = true
25+
alloy-dyn-abi.workspace = true
2526
revm-primitives.workspace = true
2627
serde.workspace = true
2728
eyre.workspace = true

0 commit comments

Comments
 (0)