ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
5k stars 1.7k forks source link

web3py cannot match Event ABIs when indexed arguments are not placed first #3286

Closed DefiDebauchery closed 7 months ago

DefiDebauchery commented 7 months ago
eth_abi                   5.0.1
eth-account               0.11.0
eth-bloom                 3.0.0
eth-hash                  0.5.2
eth-keyfile               0.7.0
eth-keys                  0.5.0
eth-retry                 0.1.19
eth-rlp                   1.0.1
eth-typing                3.5.2
eth-utils                 2.3.1
web3                      6.15.1

What was wrong?

Somewhere in the library stack, .process_log() on Contract instances assume that ABI Event definitions always begin with their indexed arguments.

Circle's TokenMessenger Contract contains an event called DepositForBurn() where an indexed argument appears after an unindexed one. (See also the ABI for the contract)

The correct hashing method of this Event would be DepositForBurn(uint64,address,uint256,address,bytes32,uint32,bytes32,bytes32), or 0x2fa9ca894982930190727e75500a97d8dc500233a5065e0f3126c48fbe0343c0 (evidenced by any txn that emits the event)

However, when trying to process any log using contract.events.DepositForBurn().process_log(event), web3py throws a MismatchedABI exception. Debugging that call, it has somehow resolved topic0 to 0xfe7cd5fd79e991f2a72bb5f9aa66d76845cd7d1b8f205b6a264148cf0d1f8876, which happens to be the keccak of the event signature if indexed params are assumed to be first, like: DepositForBurn(uint64,address,address,uint256,bytes32,uint32,bytes32,bytes32)

How can it be fixed?

Unfortunately, I was unable to properly trace whether web3py, eth-abi, or eth-utils is altering the evaluated ABI in this manner. However, retaining exact order as published in the ABI will likely correct this issue.