fix(traces): scope function lookup by called address to fix selector collisions#14787
Closed
figtracer wants to merge 1 commit into
Closed
fix(traces): scope function lookup by called address to fix selector collisions#14787figtracer wants to merge 1 commit into
figtracer wants to merge 1 commit into
Conversation
…collisions
When two contracts in the same project define a function with the same selector
(e.g. `items(uint256)` mapping getters or accessor functions) but with
different return-type metadata (different struct/field names), trace decoding
could format the return value using the wrong contract's ABI.
The decoder kept all known functions in a single `HashMap<Selector, Vec<Function>>`
and disambiguated collisions by trying `abi_decode_input` against each candidate.
When the inputs were identical, the first registered function won and its
return-type metadata was used to format the trace output, producing wrong
struct/field names like `MuchWowStruct({ c: 11, d: 22 })` for a call to
`Wow::items(0)` returning `WowStruct`.
Add a parallel `functions_by_address: HashMap<Address, HashMap<Selector, Function>>`
populated in `collect_abi` and prefer it in `decode_function` when the called
contract is identified. The legacy collision heuristic still runs for unknown
addresses or selectors that aren't bound to a specific contract.
Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019e2cbe-2eb1-7643-b8f3-71b02f08cb85
0004267 to
5d02f21
Compare
Collaborator
Author
|
superseded by #14788 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Two contracts sharing a function selector but with different return struct types caused trace decoding to use the wrong struct/field names.
Cause
self.functionsis a globalHashMap<Selector, Vec<Function>>. On collisions,select_contract_functiononly disambiguates by trying to decode the inputs; identical input types → first registered candidate wins → its return ABI is used to format the output.Fix
Add a per-address
functions_by_address: HashMap<Address, HashMap<Selector, Function>>, populated incollect_abi, and consult it first indecode_function. Falls back to the existing collision heuristic for unknown addresses.After:
Includes a regression test.