Storage access uses slot keys in the current storage context.
LET’S PICTURE IT
A persistent cabinet is addressed by drawer key rather than working-table byte position.
SEE IT FOR YOURSELF
Pack small values into Solidity storage slotsStep 1 / 4
In this simple default-layout example, two uint128 values come before one uint256. Each slot holds thirty-two bytes.
In this simple default-layout example, two uint128 values come before one uint256. Each slot holds thirty-two bytes.The first sixteen-byte value occupies the low-order half of slot zero. Low-order bytes are shown on the right.The second uint128 fits in the remaining sixteen bytes. Both values now share slot zero.C needs a complete thirty-two-byte slot, so it begins at slot one. Two packed small values plus C use two slots.
Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.
Read a slot word
SLOAD uses a slot key and returns the full stored word. Extracting a packed Solidity field requires additional masking or shifting.
Write the full word
SSTORE updates the word at a slot in the current storage context. Manual code must preserve other packed fields when changing only one logical value.
Respect execution restrictions
A write in static context is prohibited. Storage access cost also depends on contextual factors, so a single constant cost does not describe every SSTORE.
Account for rollback
A later revert in the applicable scope rolls back its storage changes. An attempted write in a trace is not proof of a surviving state update.
Trace the idea
slot 0 contains packed fields a and b
SLOAD(0) → full word
extract a and b with their known widths and offsets
Stack examples list the bottom first and the top last. These small traces omit gas and surrounding dispatch unless stated.
QUICK CHECK · NO PRESSURE
What width does SLOAD return?
The compiler interprets fields within the returned word.