What's the significance of Custom Storage Layouts?
By default, Solidity starts all storage variables at slot 0. For example, if you have this contract:
contract Example {
uint256 x;
uint256 y;
}
then reading x will compile to SLOAD with a key of 0x00, and reading y will compile to an SLOAD with a key of 0x01.
(If you have smaller values, such as two uint128's, then Solidity will compact those into the same storage slot. But that's a discussion for another day!)
Essentially, all your storage variables live right next to each other, starting at zero and incrementing onwards.
However...
with Custom Storage Layouts, you can now start at a *different* point than zero!
contract Example layout at 0xFAFA {
uint256 x;
uint256 y;
}
In this modified example, reading x now compiles to SLOAD with a key of 0xFAFA, and y now compiles to an SLOAD with a key of 0xFAFB!
This is useful for EIP-7702, which allows an EOA to "become" a smart contract! The EOA can change which smart contract it becomes multiple times, so it's important for each one to have its own isolated storage space to avoid clashing.
Solidity just added support for Custom Storage Layouts!
This allows specifying that your contract storage starts at a point *other than* zero.
However, this still doesn't cover the popular Namespaced Storage Layout that modern contracts often use (EIP-7201). For now, you will need to continue using the verbose (but useful!) Solidity pattern to support custom storage for inherited contracts.
Hopefully we get this feature soon!