Skip to content

Event ProcessReceipt fails for events with same id but different indexed attributes #1351

@Uxio0

Description

@Uxio0
  • Version: 4.9.2
  • Python: 3.7
  • OS: linux

What was wrong?

When I use rich_logs = erc721.events.Transfer().processReceipt(tx_receipt) I expect the relevant logs to be decoded and the others ignored. But if I try to process a tx with mixed ERC20 and ERC721 Transfer events (ERC721 has the third parameter of the event indexed, ERC20 not) it will fail decoding the event.

ERC20 Transfer Event event Transfer(address indexed from, address indexed to, uint256 value); = 3 topics
ERC721 Transfer Event event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); = 4 topics

Problem is that signature for Transfer is the same, but as tokenId is indexed for ERC721 it will have one more log topic than ERC20. When web3.py tries to decode an ERC20 event with the ERC721 contract, it will fail as it's expecting one topic more.

in
----> 1 erc721.events.Transfer().processReceipt(tx_receipt)

~/.virtualenvs/gnosis-py/lib/python3.7/site-packages/web3/utils/decorators.py in _wrapper(*args, **kwargs)
12 def _wrapper(*args, **kwargs):
13 if obj is not None:
---> 14 return self.method(obj, *args, **kwargs)
15 else:
16 return self.method(objtype, *args, **kwargs)

~/.virtualenvs/gnosis-py/lib/python3.7/site-packages/web3/contract.py in processReceipt(self, txn_receipt)
1277 @combomethod
1278 def processReceipt(self, txn_receipt):
-> 1279 return self._parse_logs(txn_receipt)
1280
1281 @to_tuple

~/.virtualenvs/gnosis-py/lib/python3.7/site-packages/eth_utils/functional.py in inner(*args, **kwargs)
44 @functools.wraps(fn)
45 def inner(*args, **kwargs) -> T: # type: ignore
---> 46 return callback(fn(*args, **kwargs))
47
48 return inner

~/.virtualenvs/gnosis-py/lib/python3.7/site-packages/web3/contract.py in _parse_logs(self, txn_receipt)
1283 for log in txn_receipt['logs']:
1284 try:
-> 1285 decoded_log = get_event_data(self.abi, log)
1286 except MismatchedABI:
1287 continue

~/.virtualenvs/gnosis-py/lib/python3.7/site-packages/web3/utils/events.py in get_event_data(event_abi, log_entry)
168 raise ValueError("Expected {0} log topics. Got {1}".format(
169 len(log_topic_types),
--> 170 len(log_topics),
171 ))
172

ValueError: Expected 3 log topics. Got 2

You can test it easily with rinkeby tx-hash 0x21381484d8f69dcd782560d1fd3cd818e743c79767985d01aec7e61c2a7f1de9, for example.

How can it be fixed?

  • Skip incorrect decoded logs, as they are not complaint with the contract interface
  • At least allow a flag in processReceipt to skip not complaint logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions