OpenZeppelin / OpenZeppelin/openzeppelin-contracts
Redundant SLOADs in Initializable
Nobody has claimed this yet.
- Dominant language
- Solidity
- Stars
- 27.2k
- Forks
- 12.4k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 33
Description
Opening issue as mentioned in https://github.com/OpenZeppelin/openzeppelin-contracts/pull/4576#discussion_r1316443220
📝 Details
Since InitializableStorage is a struct with two fields packed in one storage slot, compiler need to load this slot when writing new value only for one of the fields, like here:
Since (when) we know values for other fields, explicit usage of known values can let the compiler to prevent excessive SLOADs before SSTORE. Example:
$._initialized = 1;
$._initializing = false;
PS: this is applicable not only in this place, but also in some other contracts.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in contracts/proxy/utils/Initializable.sol, reading InitializableStorage and the writes around lines 127-130, then review the linked pull request discussion for the compiler behavior. Compare the generated storage operations for the known field values and identify other affected contracts. Done means redundant SLOADs are avoided without changing initialization behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity
- Domain
- blockchain, performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100