Storage Slots
sload(slot) | sstore(slot, value) | (variable name).slot
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;
contract StorageBasics {
uint256 x = 2;
uint256 y = 13;
uint256 z = 54;
uint256 p;
function getYstorage() external pure returns (uint256 ret) {
assembly{
ret := y.slot //returns storage slot of y variable (slot 1). not the value.
}
}
// input slot number. returns the value stored in the slot as hexadecimal
function getVarYul(uint256 slot) external view returns (bytes32 ret) {
assembly {
ret := sload(slot)
}
}
function setVarYul(uint256 slot, uint256 value) external {
assembly {
sstore(slot, value)
}
}
}Compacted storage variables

a at the end, b at the middle
How do we load their values if there are in the same slot

right-shift:
To remove the 1:
TBC
Last updated