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

Dynamic array base slots

The declared slot holds length while a hash-derived region holds elements.

LET’S PICTURE IT

An index drawer stores a list count and points conceptually to a separately located shelf.

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.

Locate the declared slot

For a dynamic storage array at slot p, that slot stores its length. The actual element region does not begin at p plus one.

Compute the element base

The element region starts at Keccak-256 of the thirty-two-byte encoding of p. For an array declared at slot three, hash that full encoded word.

Apply the element layout

For uint256 elements, index i is stored at base plus i, with slot arithmetic in the 256-bit space. Smaller element types may pack several values per word.

Distinguish nested arrays

A dynamic array of dynamic arrays needs a length and hash-derived region at each relevant level. Do not reuse a flat uint256-array formula for every nested type.

Inspect the layout

uint256[] items; // suppose declared slot p = 3
base = keccak256(ABI uint256(3))
base = 0xc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b
items[i] slot = base + i

The numeric slot assumption is explicit; inspect compiler output before applying it to a real contract.

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

What is stored directly in the declared dynamic-array slot?

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.