Builtin for base slot of storage layout
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
## Abstract
The base slot of the storage layout should be available as a constant usable in both compile-time and runtime expressions.
## Motivation
From https://github.com/ethereum/solidity/issues/597#issuecomment-2568003933:
> A potential issue is that contracts that manually implement custom storage locations will be unaffected by Solidity's native layout rerooting.
>
> For example: https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/dfe0973e94e137277cae220ef54eb66df60cbf92/contracts/access/OwnableUpgradeable.sol#L27-L34
>
> In a sense this should be expected because it's a very low level operation. But it would be good if Solidity provided some way for this kind of logic to adapt to a potentially rerooted layout... For example, if the base of the layout was available as a constant. Maybe something like `type(Contract).layoutBase` that could be used in constants.
## Specification
Define `type(C).storageBase` that returns the value of contact's base slot expression.
- The type is `uint256`.
- The value is zero if the contract does not have a layout specifier.
- The value is undefined (compilation error) for contracts which cannot have a layout specifier:
- ones not at the top level of the inheritance hierarchy
- abstract contracts
- interfaces
- libraries
The value should be a compile-time constant (via [`isPure` annotation](https://github.com/ethereum/solidity/blob/v0.8.28/libsolidity/ast/ASTAnnotations.h#L277)) and usable in:
- Constant initializers: `uint constant X = type(C).storageBase + 0x1000;`
- Layout specifiers: `contract D layout at type(C).storageBase + 0x1000 {}`
- Array sizes: `uint[type(B).storageBase - type(A).storageBase] array;`
## Backwards Compatibility
Fully backwards compatible.
Contributor guide
Research direction
Start with the specification and the isPure annotation referenced in libsolidity/ast/ASTAnnotations.h. Trace how the compiler handles type expressions, constant initializers, and layout specifiers, then verify the requested storageBase behavior for each listed contract kind and usage; done means the feature follows the stated type, value, and compilation-error rules.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, solidity
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100