Skip to content
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

feat(cast): decode external lib sigs from cached selectors #9399

Merged
merged 3 commits into from
Nov 28, 2024

Conversation

grandizzy
Copy link
Collaborator

Motivation

Closes #5950

  • external libraries ABIs does not add functions in abi but they are listed as methodIdentifiers, e.g. abi for
library ExternalLib {
    function update(uint256 a, uint256 counter) public {}
}

contains fields as

"abi":[]
"methodIdentifiers":{"update(uint256,uint256)":"2fb565e8"}"
forge clone 0xBb02bCCE1bdcc0b07E7870346D8b2ad9397D0fAC --etherscan-api-key $ETHERSCAN_KEY
forge selectors cache
cast run --rpc-url $RPC_URL 0x07a6ad95d76f4c1318d38564439347b39a47b126a7cbd3fe0b58a980392d4a35

image

  • as a follow up (ideally) we would use methods identifiers for forge test traces too (that is without need of forge selectors cache being issued)

Solution

  • forge selectors cache to use contract's methodIdentifiers as well
  • fix panic if event decoded with different sigs (e.g. Transfer(from, to) decoded with Transfer(address indexed from, address indexed to, uint256 indexed tokenId))

@grandizzy grandizzy marked this pull request as ready for review November 25, 2024 08:14
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm

Comment on lines +692 to +695
// Prevent panic of event `Transfer(from, to)` decoded with a signature
// `Transfer(address indexed from, address indexed to, uint256 indexed tokenId)` by making
// sure the event inputs is not higher than decoded indexed / un-indexed values.
if input.indexed && indexed < decoded.indexed.len() {
Copy link
Member

Choose a reason for hiding this comment

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

ah nice find

@grandizzy grandizzy enabled auto-merge (squash) November 28, 2024 06:02
@grandizzy grandizzy merged commit 16a013f into foundry-rs:master Nov 28, 2024
21 checks passed
@grandizzy grandizzy deleted the issue-5950 branch November 28, 2024 06:47
rplusq pushed a commit to rplusq/foundry that referenced this pull request Nov 29, 2024
@grandizzy grandizzy added T-feature Type: feature C-cast Command: cast labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cast Command: cast T-feature Type: feature
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

cast run does not decode calldata for library (delegate-)call.
2 participants