You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Solidity uses bitmask (0xffffffffffffffffffffffffffffffffffffffff) to sanity clean address value.
It compiles that into this code:
PUSH20 0xffffffffffffffffffffffffffffffffffffffff
This requires 21 bytes and 3 gas for each situation address is used. (70+ times in some example ERC20 bytecode).
I propose much shorter approach for the case the optimiser is set to optimise bytecode length.
Solution
Compile to this instead (in the case the optimiser is set to optimise bytecode length):
PUSH0
NOT
PUSH1 12
SHR
This results into 5 bytes code and 11 gas.
In some common ERC20 bytecode it has impact on being 1100+ bytes shorter. Wrt to functions - there can be just +40 gas needed in the case the address is sanity cleaned 5 times within 1 call.
Backwards Compatibility
The optimised bytecode is shorter (-16 bytes), but has +8 gas. Functionally the same.
The text was updated successfully, but these errors were encountered:
Abstract and Motivation
Solidity uses bitmask (0xffffffffffffffffffffffffffffffffffffffff) to sanity clean address value.
It compiles that into this code:
This requires 21 bytes and 3 gas for each situation address is used. (70+ times in some example ERC20 bytecode).
I propose much shorter approach for the case the optimiser is set to optimise bytecode length.
Solution
Compile to this instead (in the case the optimiser is set to optimise bytecode length):
This results into 5 bytes code and 11 gas.
In some common ERC20 bytecode it has impact on being 1100+ bytes shorter. Wrt to functions - there can be just +40 gas needed in the case the address is sanity cleaned 5 times within 1 call.
Backwards Compatibility
The optimised bytecode is shorter (-16 bytes), but has +8 gas. Functionally the same.
The text was updated successfully, but these errors were encountered: