In this track: Inside the EVM
advanced · 4 MIN READ

SLOAD and SSTORE

Storage access uses slot keys in the current storage context.

LET’S PICTURE IT

A persistent cabinet is addressed by drawer key rather than working-table byte position.

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.

Read a slot word

SLOAD uses a slot key and returns the full stored word. Extracting a packed Solidity field requires additional masking or shifting.

Write the full word

SSTORE updates the word at a slot in the current storage context. Manual code must preserve other packed fields when changing only one logical value.

Respect execution restrictions

A write in static context is prohibited. Storage access cost also depends on contextual factors, so a single constant cost does not describe every SSTORE.

Account for rollback

A later revert in the applicable scope rolls back its storage changes. An attempted write in a trace is not proof of a surviving state update.

Trace the idea

slot 0 contains packed fields a and b
SLOAD(0) → full word
extract a and b with their known widths and offsets

Stack examples list the bottom first and the top last. These small traces omit gas and surrounding dispatch unless stated.

QUICK CHECK · NO PRESSURE

What width does SLOAD return?

Your progress stays in this browser.
Keep exploring the original referenceethereum.org ↗

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