ethereum / eth-abi

Ethereum ABI utilities for python
MIT License
248 stars 269 forks source link

Byte value of length 32b results in decoding error using 'decode' #190

Closed JanRuettinger closed 2 years ago

JanRuettinger commented 2 years ago

If this is a bug report, please fill in the following sections. If this is a feature request, delete and describe what you would like with examples.

What was wrong?

Code that produced the error

from eth_abi import decode
from hexbytes import HexBytes

# Link to tx: https://etherscan.io/vmtrace?txhash=0x3e92d87a2d60f3bf4747141580ec46a40e5995d543b8614fe650324b41925429&type=parity (1. trace)
# Doesn't work
output_raw = "0x0000000000000000000000000000000000000000000000000516c923c8144bbf"
output_hex_bytes = HexBytes(output_raw)
to_decode_types = ['bytes']
decoded = decode(to_decode_types, output_hex_bytes)
print(decoded) # Error: Tried to read 32 bytes.  Only got 0 bytes

# Works
output_raw = "0x0000000000000000000000000000000000000000000000000000000000000000"
output_hex_bytes = HexBytes(output_raw)
to_decode_types = ['bytes']
decoded = decode(to_decode_types, output_hex_bytes)
print(decoded)

Full error output

Tried to read 32 bytes.  Only got 0 bytes

Environment

# run this:
$ python -m eth_utils

# then copy the output here:
Python version:
3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53) 
[Clang 6.0 (clang-600.0.57)]

Operating System: macOS-10.16-x86_64-i386-64bit

pip freeze result:
anyio==3.6.1
appnope==0.1.3
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
asttokens==2.0.8
attrs==22.1.0
Babel==2.10.3
backcall==0.2.0
beautifulsoup4==4.11.1
bleach==5.0.1
certifi==2022.9.14
cffi==1.15.1
charset-normalizer==2.1.1
cytoolz==0.12.0
debugpy==1.6.3
decorator==5.1.1
defusedxml==0.7.1
entrypoints==0.4
eth-abi==3.0.1
eth-hash==0.3.3
eth-typing==3.2.0
eth-utils==2.0.0
executing==1.0.0
fastjsonschema==2.16.1
hexbytes==0.3.0
idna==3.4
importlib-metadata==4.12.0
importlib-resources==5.9.0
ipykernel==6.15.3
ipython==8.5.0
ipython-genutils==0.2.0
jedi==0.18.1
Jinja2==3.1.2
json5==0.9.10
jsonschema==4.16.0
jupyter-core==4.11.1
jupyter-server==1.18.1
jupyter_client==7.3.5
jupyterlab==3.4.7
jupyterlab-pygments==0.2.2
jupyterlab_server==2.15.1
lxml==4.9.1
MarkupSafe==2.1.1
matplotlib-inline==0.1.6
mistune==2.0.4
nbclassic==0.4.3
nbclient==0.6.8
nbconvert==7.0.0
nbformat==5.5.0
nest-asyncio==1.5.5
notebook==6.4.12
notebook-shim==0.1.0
packaging==21.3
pandocfilters==1.5.0
parsimonious==0.8.1
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
pkgutil_resolve_name==1.3.10
prometheus-client==0.14.1
prompt-toolkit==3.0.31
psutil==5.9.2
ptyprocess==0.7.0
pure-eval==0.2.2
pycparser==2.21
Pygments==2.13.0
pyparsing==3.0.9
pyrsistent==0.18.1
python-dateutil==2.8.2
pytz==2022.2.1
pyzmq==24.0.0
requests==2.28.1
Send2Trash==1.8.0
six==1.16.0
sniffio==1.3.0
soupsieve==2.3.2.post1
stack-data==0.5.0
terminado==0.15.0
tinycss2==1.1.1
tomli==2.0.1
toolz==0.12.0
tornado==6.2
traitlets==5.4.0
urllib3==1.26.12
wcwidth==0.2.5
webencodings==0.5.1
websocket-client==1.4.1
zipp==3.8.1
fselmo commented 2 years ago

@JanRuettinger I'm not sure I see what you are trying to decode in the link you provided. Can you provide any more details of what you're trying to do?

fselmo commented 2 years ago

Without more context, I believe what you're trying to decode is an int type, not bytes which does work in this case. Closing this but feel free to ask to re-open if you can provide more context and this is the wrong assumption.