ABI: Event selectors do not distinguish indexed arguments
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
Event selectors are calculated as the hash of the event name and the canonical types of its arguments:
>`topics[0]`: `keccak(EVENT_NAME+"("+EVENT_ARGS.map(canonical_type_of).join(",")+")")` (`canonical_type_of` is a function that simply returns the canonical type of a given argument, e.g. for `uint indexed foo`, it would return `uint256`).
([Source](https://github.com/ethereum/solidity/blob/e97f9b6ba85b5cf5d347f1771524d0b0973e00bb/docs/abi-spec.rst#events))
This means that the "indexedness" of its arguments is not reflected in the selector. Put another way, each event selector maps to many ways of decoding a log, and in general there is no way to know which is the correct one. (This is true regardless of this issue because of hash collisions, but that's a separate thing, and I believe this is more serious.)
For example, the logs corresponding to `Foo(address a, address indexed b)` would be indistinguishable from `Foo(address indexed a, address b)`. I think this incompatibility should be visible in the event selector.
A related problem is that, as of Solidity 0.4.24, redefining an event of a parent contract with different indexedness will not results in errors or warnings.
If we agree that this is a problem with the ABI, we may want to tackle it for 0.5.0, since the fix will probably be backwards-incompatible.
Contributor guide
Research direction
The issue points to docs/abi-spec.rst and its event-selector rules; start by reading that section and the linked canonical_type_of definition. No implementation file or test is named. Done would require an agreed decision on indexedness in selectors, redeclaration diagnostics, and the backwards-compatibility scope before implementation can be scoped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity
- Domain
- blockchain, compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100