Skip to content

Fix/cast abi strict args #11189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

simon0820s
Copy link

@simon0820s simon0820s commented Aug 1, 2025

Motivation

Fixes #5053

Solution

Add validation that arguments exactly match parameters before encode arguments and add tests for this validation.

PR Checklist

  • [✅] Added Tests
  • [✅] Added Documentation
  • [❌] Breaking changes

@@ -1809,10 +1809,7 @@ impl SimpleCast {
let func = get_func(sig)?;
match encode_function_args(&func, args) {
Ok(res) => Ok(hex::encode_prefixed(&res[4..])),
Err(e) => eyre::bail!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also handle the abi_encode_packed branch in CastSubcommand::AbiEncode

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invoked by cast abi-encode "<signature>" <value> --packed

"Could not ABI encode the function and arguments. Did you pass in the right types?\nError\n{}",
e
),
Err(e) => eyre::bail!("{}", e),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Err(e) => eyre::bail!("{}", e),
Err(e) => eyre::bail!(
"Could not ABI encode the function and arguments: {}",
e
),

@zerosnacks
Copy link
Member

Hi @simon0820s thanks for your PR!

Glad to see #5053 being fixed, the current behavior of silently accepting additional arguments can be a footgun

Some small notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

abi-encode and calldata accept redundant arguments
3 participants