alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
763 stars 137 forks source link

fix(sol-macro): correctly determine whether event parameters are hashes #735

Closed DaniPopes closed 1 week ago

DaniPopes commented 1 week ago

Currently we're determining whether an indexed parameter is encoded as a hash (B256) by checking whether it is abi-dynamic. However this:

  1. does not account for custom types, so UDVTs are treated as a hash when they shouldn't;
  2. is not entirely correct as it will accept elementary fixed arrays such as address[2].

This is fixed by accounting for custom types and using is_value_type instead of whether it is ABI-dynamic. The Solidity ABI spec states:

For all types of length at most 32 bytes, the EVENT_INDEXED_ARGS array contains the value directly, padded or sign-extended (for signed integers) to 32 bytes, just as for regular ABI encoding. However, for all “complex” types or types of dynamic length, including all arrays, string, bytes and structs, EVENT_INDEXED_ARGS will contain the Keccak hash of a special in-place encoded value (see Encoding of Indexed Event Parameters), rather than the encoded value directly.

Fixes #734.