-
Notifications
You must be signed in to change notification settings - Fork 269
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
Investigate and resolve discrepancies with solidity's abi.encode() #158
Investigate and resolve discrepancies with solidity's abi.encode() #158
Conversation
212f4c8
to
072486a
Compare
072486a
to
85fc4f6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
85fc4f6
to
b4069f5
Compare
- Empty values for dynamic encoders had extra 32-byte zero padding when compared to Solidity's abi.encode() method. This led to correct instructions for the EVM but also required more gas than necessary and ultimately led to differing hashes, etc. - Add more tests. Decode tuple test values not just as separate list of types but as a tuple type with nested values for encode_abi() tests for tuples. - Eliminate padding for empty dynamic arrays as well. If an array is static or if it is dynamic and empty do not pad with 32-byte zero padding.
b4069f5
to
75ead60
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Thanks for digging in here!
Thx! Any idea when this gets officially released (and even used by web3py)? |
We'll probably release |
No chance of a patch release for web3py 5.28.*? Really struggling issue right now... |
I'm hesitant to pull it into web3py 5.28 because this is technically a breaking change (though arguably it's a bugfix which is a little less black and white). Most of the breaking changes in web3 v6 right now are dependency-related, so I hope it won't be too bad to update. The other big breaking change is dropping support for python 3.6. Any chance you can try updating to web3 v6 and let me know how it goes? If you run into issues, let me know and I'll consider releasing a patch. |
Hi, ran into this again on |
What was wrong?
Related issues:
bytes
#151encode_abi()
does not yield the same result as Solidity'sabi.encode()
#157How was it fixed?
It seems that, for
encode_abi()
, extra 32-byte zero padding was happening in a few places, compared to what Solidity'sabi.encode()
returns. This seems to be the case when dealing with empty dynamic types, including empty dynamic arrays.i.e.
encode_abi(['string'], [''])
vs Solidityabi.encode('')
encode_abi(['string[]'], [[]])
vs Soliditystring[] sl; abi.encode(sl);
These discrepancies still yielded correct instructions for the EVM but ultimately led to different hashes and higher gas values for transactions encoded this way.
To-Do
Cute Animal Picture