[optimisation] quick win - byte size optimised address mask
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
## Abstract and Motivation
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.
Contributor guide
Research direction
The issue names no file, test, or entry point; begin by locating the compiler code that emits the address mask and the optimizer's bytecode-length mode. Compare generated bytecode and gas for the proposed sequence against the current mask, including the ERC20 example; done means the shorter output is selected only for that mode while functional behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, solidity
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100