Skip to content

Commit f00f085

Browse files
committed
fix(encode-args-length mismatch): validate inputs length match args length before encode args
1 parent 391f37f commit f00f085

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

crates/cast/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,10 +1762,7 @@ impl SimpleCast {
17621762
let func = get_func(sig)?;
17631763
match encode_function_args(&func, args) {
17641764
Ok(res) => Ok(hex::encode_prefixed(&res[4..])),
1765-
Err(e) => eyre::bail!(
1766-
"Could not ABI encode the function and arguments. Did you pass in the right types?\nError\n{}",
1767-
e
1768-
),
1765+
Err(e) => eyre::bail!("{}", e),
17691766
}
17701767
}
17711768

crates/common/src/abi.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ where
1515
I: IntoIterator<Item = S>,
1616
S: AsRef<str>,
1717
{
18+
let args: Vec<S> = args.into_iter().collect();
19+
20+
if inputs.len() != args.len() {
21+
eyre::bail!(
22+
"encode length mismatch: expected {} types, got {}",
23+
inputs.len(),
24+
args.len()
25+
)
26+
}
27+
1828
std::iter::zip(inputs, args)
1929
.map(|(input, arg)| coerce_value(&input.selector_type(), arg.as_ref()))
2030
.collect()

0 commit comments

Comments
 (0)