Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow get_event_data to handle invalid padding bytes #2489

Open
cwelton opened this issue May 27, 2022 · 1 comment
Open

Allow get_event_data to handle invalid padding bytes #2489

cwelton opened this issue May 27, 2022 · 1 comment

Comments

@cwelton
Copy link

cwelton commented May 27, 2022

  • Version: 4.7.2
  • Python: 3.9.11
  • OS: osx/linux
  • pip freeze output
attrdict==2.0.1
certifi==2022.5.18.1
charset-normalizer==2.0.12
cytoolz==0.11.2
eth-abi==1.3.0
eth-account==0.3.0
eth-hash==0.3.2
eth-keyfile==0.5.1
eth-keys==0.2.4
eth-rlp==0.2.1
eth-typing==2.3.0
eth-utils==1.10.0
hexbytes==0.2.2
idna==3.3
lru-dict==1.1.7
parsimonious==0.8.1
pycryptodome==3.14.1
requests==2.27.1
rlp==2.0.1
six==1.16.0
toolz==0.11.2
urllib3==1.26.9
web3==4.7.2
websockets==6.0

What was wrong?

Trying to decode an event with bad padding causes a NonEmptyPaddingBytes exception

Note the above linked event is a Transfer event with a to_address of 0x0000000000000000000000010000000000000000000000000000000000000006, which has invalid data in the padding bytes, but is a real event in the blockchain.

  • The code which produced the error
from web3.utils.events import get_event_data
from hexbytes import HexBytes


TRANSFER_ABI = {"name":"Transfer","type":"event","anonymous":False,"inputs":[{"indexed":True,"name":"from","type":"address"},{"indexed":True,"name":"to","type":"address"},{"indexed":False,"name":"raw_value","type":"uint256"}]}

myevent = {
  'log_index': 0,
  'transaction_hash': HexBytes('0x93f2a3e74d2d6d636c14d5f63348dbd03e256f4e35f222814554881ce7b2d26a'),
  'transaction_index': 7,
  'block_hash': HexBytes('0xe87449740310af0b5b819b4978694a72bf1a959ac88e387749b8f73c0d7481fb'),
  'block_number': 4086410,
  'address': '0x48c80f1f4d53d5951e5d5438b54cba84f29f32a5',
  'data': HexBytes('0x0000000000000000000000000000000000000000000000000de0b6b3a7640000'),
  'topics': [
    HexBytes('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'),
    HexBytes('0x0000000000000000000000007e614ec62cfd5761f20a9c5a2fe2bc0ac7431918'),
    HexBytes('0x0000000000000000000000010000000000000000000000000000000000000006')
  ]
}
get_event_data(TRANSFER_ABI, myevent)
  • The full output of the error
Traceback (most recent call last):
  File "/Users/cwelton/projects/definitive/foo/repo.py", line 24, in <module>
    get_event_data(TRANSFER_ABI, myevent)
  File "/Users/cwelton/.pyenv/versions/3.9.11/lib/python3.9/site-packages/web3/utils/events.py", line 195, in get_event_data
    decoded_topic_data = [
  File "/Users/cwelton/.pyenv/versions/3.9.11/lib/python3.9/site-packages/web3/utils/events.py", line 196, in <listcomp>
    decode_single(topic_type, topic_data)
  File "/Users/cwelton/.pyenv/versions/3.9.11/lib/python3.9/site-packages/eth_abi/abi.py", line 80, in decode_single
    return decoder(stream)
  File "/Users/cwelton/.pyenv/versions/3.9.11/lib/python3.9/site-packages/eth_abi/decoding.py", line 118, in __call__
    return self.decode(stream)
  File "/Users/cwelton/.pyenv/versions/3.9.11/lib/python3.9/site-packages/eth_abi/decoding.py", line 189, in decode
    self.validate_padding_bytes(value, padding_bytes)
  File "/Users/cwelton/.pyenv/versions/3.9.11/lib/python3.9/site-packages/eth_abi/decoding.py", line 320, in validate_padding_bytes
    raise NonEmptyPaddingBytes(
eth_abi.exceptions.NonEmptyPaddingBytes: Padding bytes were not empty: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
  • What type of node you were connecting to?

Not needed to reproduce

How can it be fixed?

Provide an optional flag to get_event_data (or alternatively always) that would allow parse with warning rather than failing to parse.

@kclowes
Copy link
Collaborator

kclowes commented May 27, 2022

We could put this in our queue, but I'm not sure when we'll be able to get to it. I assume you've seen the processReceipt docs? You can pass a flag to processReceipt. Also a word of caution: get_event_data isn't part of the public API, so it may change in minor version releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants