In this track: Storage, memory and layout
advanced · 4 MIN READ

Inheritance and storage ordering

Inherited declarations participate in the final instance layout.

LET’S PICTURE IT

A combined filing cabinet incorporates drawers inherited from earlier cabinet designs.

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.

Follow linearized ordering

Solidity derives state-variable order using inheritance linearization. Reading only the most-derived contract’s own declarations misses earlier inherited storage.

Allow compatible cross-contract packing

Under ordinary layout rules, suitable small fields from different contracts in that ordering can share one slot. Contract boundaries do not always create fresh slot boundaries.

Avoid guessing diamond inheritance

Multiple inheritance can produce an order that is not obvious from a quick visual scan. Use the actual compiled storage layout for the exact source hierarchy.

Recheck after a structural change

Changing bases or declarations can move existing fields. In upgradeable systems, such changes can reinterpret live state even when the new contract compiles successfully.

Inspect the layout

contract Base { uint128 a; }
contract Child is Base { uint128 b; }
// In this simple default layout: a and b share slot 0.

A declaration sketch; inspect compiler output for complex inheritance or custom base layouts.

TURN UNDERSTANDING INTO PRACTICEOpen the Storage layout →
QUICK CHECK · NO PRESSURE

Is a contract boundary always a new storage-slot boundary?

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.