In this track: Advanced security reasoning
advanced · 4 MIN READ

Delegatecall storage collisions

Different slot interpretations can turn an ordinary write into corruption.

LET’S PICTURE IT

A borrowed manual can label the same drawer as both owner and counter.

SEE IT FOR YOURSELF
Pack small values into Solidity storage slotsStep 1 / 4
Pack small values into Solidity storage slotsFirstuint128 A16 bytesSeconduint128 B16 bytesThirduint256 C32 bytesSimple elementary types only; not a complete compiler layoutSlot 0 · 32 bytesUnused · 16 BA · 16 BHigh-order bytes ← → low-order bytesSlot 0 · fullB · 16 BA · 16 BDeclaration order and sizes determine this packingSlot 0BASlot 1C · 32 bytesTry different sequences in the storage-layout tool

In this simple default-layout example, two uint128 values come before one uint256. Each slot holds thirty-two bytes.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Separate code and state

Delegated code uses the caller’s storage. The implementation’s source declaration does not allocate an independent safe cabinet during delegate execution.

Compare field positions

If one layout treats slot zero as an address and another treats it as an integer, a write can change the wrong logical field. Packed offsets create similar risks within one slot.

Include every inherited field

Compatibility checks need the complete compiled layout, not just newly added declarations. Base contracts and struct changes can alter existing positions.

Test an actual upgrade state

Populate representative old state, apply the proposed upgrade locally and assert preserved meanings. Passing compilation alone does not establish compatibility.

Work through the boundary

Proxy slot 0: owner
Delegated code slot 0: counter
write counter → may overwrite owner bits

A simplified local review scenario. The example establishes a question to test, not a guarantee of production safety.

QUICK CHECK · NO PRESSURE

Does delegatecall isolate writes in implementation storage?

Your progress stays in this browser.
Keep exploring the original referenceSolidity documentation ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.