Presets
Playback
Proxy design
Where the proxy keeps its implementation and admin addresses.
Logic contract
Declaration order of the logic variables and the version it is upgraded to.
Mapping probe
Where a mapping entry is stored.
Camera
Quality
Layers
Model checks
The science
How the EVM lays out storage
A contract's persistent storage is a huge array of 32-byte slots, addressed by a 256-bit index. The Solidity compiler places state variables in declaration order: value types smaller than 32 bytes are packed side by side into the current slot (a bool takes 1 byte, a uint64 8, an address 20, a uint128 16), and a variable that does not fit in the bytes left starts a new slot. A uint256 or a mapping always takes a whole slot. The number of slots a layout uses is therefore order-dependent: twenty uint8 flags fit in one slot, but alternating them with uint256 values wastes 31 bytes each time. The first graph draws the slot count of 3,000 random declaration orders of the same nine variables.
Mapping entries live far away
The entry balances[key] is stored at keccak256(pad32(key) . pad32(p)), where p is the slot of the mapping itself. The page computes this with its own Keccak-256 (original padding byte 0x01, not NIST SHA-3). A hash of 256 random-looking bits is about 2255 slots away from slot 0, so it cannot land in the small sequential region used by ordinary variables.
Why a proxy can collide with its logic contract
An upgradeable proxy forwards calls with delegatecall: the logic contract's code runs, but every read and write hits the proxy's storage. If the proxy itself keeps implementation and admin in slots 0 and 1, and the logic contract's first variables are also in slots 0 and 1, the two contracts disagree about what those bytes mean: an owner write by the logic code silently changes the proxy's pointer. The page finds this by byte-range overlap and then confirms it by really writing all-ones into each logic variable and checking which proxy variables changed.
The fix: unstructured storage slots (EIP-1967)
EIP-1967 stores the proxy's own variables at keccak256("eip1967.proxy.implementation") - 1 and keccak256("eip1967.proxy.admin") - 1. The - 1 removes the known preimage, so no Solidity layout can be made to reach those slots. The page recomputes both constants from the text labels and compares them with the published values. A second hazard remains for upgrades: if logic V2 inserts a variable before existing ones, every later variable shifts and old data is misread; appending keeps all old positions.
Honest simplifications: only value types and one mapping are modelled; structs, arrays, inheritance linearisation, transient storage, gas refunds and compiler optimisations are left out, and the gas figures (22,100 for a first write of a slot, 5,000 for a later write) are round illustrative numbers, not a gas estimator. The addresses and values are made up. The page shows a layout hazard and its standard defence; it contains no exploit code and is not affiliated with any blockchain or tooling project.
What to try
- Leave Naive proxy, loose logic running:
initialize()writesownerand the proxy admin cell turns red and the proxy lamp starts flashing. - Press Packed order and see the slot count drop from 7 to 5, but notice the collision moves: now
owneroverlaps the implementation bytes. - Choose EIP-1967: hashed slots: the two proxy variables jump to the distant vault rows and the overlap readout falls to 0 B.
- Pick V2: insert at top after some calls and read how many variables moved; compare with V2: append.
- Drag the mapping key and watch
keccak256(key . slot)change completely.