Skip to content
storage layout

Storage Slots & Layout

How variables map to slots.

In Solidity, state variables are mapped to 32-byte storage slots starting from index 0. If multiple variables can fit into a single 32-byte slot (like two uint128s), the compiler will "pack" them to save gas. For dynamic types like mappings and arrays, the storage slot is determined by hashing the key or the index using Keccak-256.

Execution Simulation

Assistant Note

"Currently at PUSH instruction. It's going to place a value on top of the stack."

Program

10 bytes
0000
PUSH10x01
Place 1-byte item on stack
0002
PUSH10x00
0004
SSTORE
0005
PUSH10x02
0007
PUSH10x01
0009
SSTORE

Stack

LIFO
0 / 1024
Stack is empty

Most opcodes pop their arguments from here.

Storage

Persistent
Storage is empty

Use SSTORE to persist data across transactions.

Storage is a key-value store. In Solidity, variables are mapped to slots (0, 1, 2...) or hashed for mappings/arrays.

Gas Meter

Consumed0 / 1,000,000
Last Op Cost
-0
Refund
0
* Gas prevents infinite loops and DDoS. SSTORE is the most expensive opcode (20,000 gas for new slots).