Combine packing, derived slots and data-location boundaries.
LET’S PICTURE IT
A good cabinet map distinguishes the drawer number, inner compartment and separate working desk.
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.
Challenge one: predict packing
For uint128 a, uint128 b and uint256 c under a simple default layout, identify each slot and byte offset. Explain why c begins a second word.
Challenge two: derive an entry
For an address-keyed mapping at a declared slot, write both full words of the hash input. Explain why a twenty-byte packed address is not interchangeable here.
Challenge three: compare locations
Explain why a string’s ABI encoding, short storage encoding and memory representation cannot be substituted for each other merely because the text looks identical.
Check against actual output
Use compiler storage layout for real declarations, then compare the simple subset with the local visualizer. State the tool’s exclusions before applying its result to structs or inheritance.
Inspect the layout
a: slot 0, offset 0
b: slot 0, offset 16
c: slot 1, offset 0
Assumptions: uint128, uint128, uint256; no inherited state or custom base.
Explain the assumptions alongside the answer, then inspect the compiler layout for more complex declarations.