Skip to content

fix(keccak): pad bytesN values in solidity_keccak (#3906) - #3911

Open
user-Param wants to merge 1 commit into
ApeWorX:mainfrom
user-Param:fix/3906-3833-keccak-padding-wei-arith
Open

user-Param wants to merge 1 commit into
ApeWorX:mainfrom
user-Param:fix/3906-3833-keccak-padding-wei-arith

Conversation

@user-Param

Copy link
Copy Markdown

Fixes #3906 and #3833.

solidity_keccak: Pad bytesN values to N bytes as Solidity does.
Previously solidity_keccak(["bytes2"], [b"a"]) hashed 0x61 instead of 0x6100.

Wei/Gwei: Changed from NewType aliases to int subclasses that preserve
type through arithmetic operators (iadd, isub, etc.), allowing
augmented assignment without mypy errors.

  • Verified syntax with python3 ast.parse

hex_encode_abi_type did not pad fixed-size bytesN values, so
solidity_keccak(["bytes2"], [b"a"]) hashed 0x61 instead of 0x6100.
Now pads bytesN values to N bytes as Solidity does.

fix(types): Wei and Gwei preserve type through arithmetic (ApeWorX#3833)

Changed Wei and Gwei from NewType aliases to int subclasses that
override arithmetic operators (__iadd__, __isub__, __add__, etc.) to
return the same type. This allows augmented assignment (x += Wei(1))
without mypy errors.

Fixes ApeWorX#3906 and ApeWorX#3833.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

solidity_keccak hashes short bytesN values without padding

2 participants