Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
Free 30-min Web3 Consultation
Book Consultation
Smart Contract Security Audits
View Audit Services
Custom DeFi Protocol Development
Explore DeFi
Full-Stack Web3 dApp Development
View App Services
LABS
Glossary

Storage Slot

A storage slot is a fixed, 256-bit position in a smart contract's persistent storage, identified by a unique index, where a single piece of data (a state variable) is stored.
Chainscore Ā© 2026
definition
BLOCKCHAIN DATA STRUCTURE

What is a Storage Slot?

A storage slot is the fundamental, fixed-size unit of persistent data storage in a smart contract on the Ethereum Virtual Machine (EVM) and compatible blockchains.

In the context of the Ethereum Virtual Machine (EVM), a storage slot is a 32-byte (256-bit) word that holds the persistent state of a smart contract. Each contract has its own independent storage, which is a sparse, key-value mapping where both keys and values are 32-byte words. This storage is persistent across transactions and is the most expensive form of on-chain data, costing gas for both writes and, in some contexts, reads. The layout of data into specific slots is deterministically calculated by the EVM compiler based on the order and type of the contract's state variable declarations.

The mapping of state variables to specific storage slots follows specific packing rules to optimize gas usage. The EVM compiler attempts to pack multiple, smaller-sized state variables (like uint8, bool) into a single 32-byte slot if they fit consecutively. For complex data types like mappings and dynamically-sized arrays, the slot calculation uses keccak256 hashing to derive pseudo-random, collision-resistant locations, ensuring data is spread across the contract's storage space. This deterministic yet seemingly random distribution is a core security feature, preventing storage collisions between different data structures.

Understanding storage layout is critical for low-level contract interactions, security auditing, and gas optimization. Developers and auditors often inspect a contract's storage directly using tools like eth_getStorageAt to verify state or debug issues. Furthermore, patterns like storage pointers and delegatecall proxies rely on precise knowledge of slot positions to correctly access and modify logic and data. Incorrect slot calculations can lead to critical vulnerabilities where data is overwritten or accessed incorrectly.

For example, in a simple contract with uint256 public count; and address public owner;, the count variable occupies storage slot 0 and the owner occupies storage slot 1. If the contract instead declared bool public paused; followed by uint248 public value;, both variables could be packed into storage slot 0 because their combined size is less than 32 bytes. This packing directly reduces the gas cost of writing to these variables.

The concept extends beyond simple state. EIP-1967 standardizes specific storage slots for proxy patterns, reserving slots like 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc for the implementation address. This prevents clashes with the logic contract's own storage layout. Similarly, EIP-7201 defines a namespace for storing structured data, further formalizing how decentralized applications manage persistent state in this sparse, addressable memory space.

how-it-works
EVM STORAGE PRIMER

How Storage Slots Work

A technical deep dive into the foundational storage model of the Ethereum Virtual Machine (EVM), explaining how smart contracts persistently store and access data on-chain.

A storage slot is the fundamental, 256-bit (32-byte) unit of persistent data storage for a smart contract on the Ethereum Virtual Machine (EVM) and compatible blockchains. Each contract's storage is a sparse, key-value mapping of 2^256 slots, where each slot is uniquely identified by a 256-bit index. This persistent state is written to the blockchain and is accessible across transactions, unlike volatile memory (memory) or call data (calldata). The location of a specific piece of data within this massive array is deterministically calculated based on the declaration order of state variables and their types, a process defined by the EVM storage layout.

The mapping of high-level Solidity variables to specific storage slots follows a set of packing rules to optimize gas costs. Sequential state variables that occupy less than 256 bits are packed into a single storage slot, starting from the least significant bits. For example, a uint128 followed by a uint128 will share slot 0. Complex types like mappings and dynamically-sized arrays use a Keccak-256 hash of the slot index and key to compute a pseudo-random storage location, preventing collisions. This deterministic yet dispersed layout ensures data integrity while making direct slot inspection a specialized task for developers and auditors.

Accessing and modifying storage is the most expensive operation in terms of gas, with SSTORE and SLOAD opcodes costing thousands of gas units. This cost model incentivizes efficient data structure design. Developers can inspect a contract's storage layout using tools like the solc compiler's --storage-layout flag or directly read raw slot data using eth_getStorageAt via an RPC node. Understanding slot calculation is crucial for low-level optimizations, writing upgradeable proxies (which delegate storage), and conducting security audits to verify that sensitive data is stored and accessed as intended.

key-features
EVM STORAGE

Key Features of Storage Slots

Storage slots are the persistent, on-chain memory of a smart contract, forming the backbone of its state. Understanding their mechanics is crucial for gas optimization, security, and contract design.

01

Deterministic Location

A storage slot's address is deterministically calculated based on the variable's declared position and, for mappings and dynamic arrays, the key or index. This ensures that any node can compute the exact storage location of any piece of data, enabling state synchronization across the network.

  • Example: For a mapping mapping(address => uint256) balances, the slot for balances[0x123...] is keccak256(abi.encodePacked(0x123..., uint256(1))) if the mapping is at slot 1.
02

Fixed 32-Byte Size

Each storage slot is exactly 32 bytes (256 bits). This fixed size is a fundamental constraint of the EVM storage model.

  • Packing: Smaller types (like uint8, bool) can be packed into a single slot if declared consecutively to save gas.
  • Overflow: Values exceeding 32 bytes (e.g., strings, large bytes) span multiple consecutive slots, with the first slot storing the length for dynamic types.
03

Persistence & Cost

Data in storage slots is persistent across transactions and is the most expensive resource to modify. The high cost of SSTORE operations (vs. memory or calldata) is a primary security and economic feature.

  • Gas Costs: Writing a non-zero value to a new slot costs ~20,000 gas. Subsequent modifications cost less (~5,000 gas for a non-zero to non-zero change).
  • Refunds: Setting a storage slot from a non-zero value to zero not only consumes gas but can also grant a gas refund (up to 4,800 gas per slot).
04

State Root & Merkleization

All contract storage slots are organized into a Merkle Patricia Trie. The root hash of this trie (the storage root) is included in the account state and ultimately in the global state root of the blockchain.

  • Light Client Proofs: This structure allows efficient cryptographic proofs (Merkle proofs) that a specific key-value pair exists in the contract's storage without needing the entire state.
  • State Commitment: The state root in the block header commits to the entire world state, including every storage slot.
05

Inheritance & Layout

In Solidity, storage layout is determined by inheritance order and declaration order. State variables are placed into slots sequentially according to the C3 linearization of the inheritance graph.

  • Rule: Variables are packed into a slot if they fit within 32 bytes, but a new storage slot is always started for each new struct or array element.
  • Critical for Upgrades: Understanding the layout is essential for upgradeable proxy patterns to avoid storage collisions between the proxy and implementation.
06

Access via `sload` & `sstore`

At the EVM opcode level, storage is accessed exclusively through two instructions:

  • SLOAD (0x54): Reads 32 bytes from a specified storage slot onto the stack. Cost varies based on prior access.
  • SSTORE (0x55): Writes 32 bytes from the stack to a specified storage slot. Cost is high and depends on the previous and new values.

These low-level operations underpin all high-level Solidity storage variable interactions.

storage-layout
GLOSSARY

Storage Layout & Slot Calculation

This section details the foundational mechanics of how data is persistently stored and organized within a smart contract on the Ethereum Virtual Machine (EVM).

A storage slot is the fundamental 256-bit (32-byte) unit of persistent data storage for a smart contract on the Ethereum Virtual Machine (EVM). Each slot is identified by a unique index, starting from 0, and the layout of these slots is deterministically calculated at compile time based on the order and type of the contract's state variables. This deterministic mapping is critical for low-level operations like SLOAD (read) and SSTORE (write), enabling the EVM to locate any piece of state data with its corresponding slot number. Understanding this layout is essential for gas optimization, security audits, and advanced techniques like storage proofs.

The calculation of a variable's storage slot follows specific packing and alignment rules to maximize efficiency. Static-sized types like uint256, address, and fixed-size arrays occupy one full slot each. Smaller types, such as uint128 or bytes32, can be packed together within a single slot if they are declared consecutively, provided they fit within the 32-byte boundary. For example, two uint128 variables declared one after the other will share slot 0. In contrast, dynamically-sized types like mappings and dynamic arrays use a more complex, hash-based derivation. The slot for a mapping key's value is computed as keccak256(abi.encode(key, mappingSlot)), where mappingSlot is the slot index of the mapping declaration itself.

For nested data structures, slot calculation becomes recursive. Within a struct, members are packed according to the same rules, and the struct's starting slot is determined by its declaration order. A mapping inside a struct uses the struct's base slot in its keccak256 hash. Dynamic arrays reserve their declared slot to store the array's length, while the array elements themselves are stored starting at the slot index derived from keccak256(abi.encode(arraySlot)). This predictable, albeit complex, system allows any external actor—such as block explorers, indexers, or other contracts—to inspect and verify a contract's state purely from its bytecode and storage proofs, forming the basis for trustless interoperability and state verification.

code-example
ETHEREUM STORAGE

Code Example: Slot Assignment

A practical demonstration of how data is physically stored in a smart contract by assigning values to specific storage slots.

In Ethereum's EVM, a smart contract's persistent state is stored in a key-value store where the key is a storage slot—a 256-bit (32-byte) location indexed from 0. This example shows the fundamental operation of writing to a slot using the sstore opcode. The statement sstore(0, 0x1234...) instructs the EVM to store the 32-byte hexadecimal value 0x1234... at slot 0 in the contract's storage trie. This low-level operation is the foundation for all higher-level state variables.

The mapping from high-level Solidity variables to these slots follows specific layout rules. Simple, sequentially-defined state variables like uint256, address, or bool are packed into slots contiguously. For instance, the first variable occupies slot 0, the second slot 1, and so on. However, for variables smaller than 32 bytes, the EVM may employ storage packing, where multiple variables are combined into a single slot to optimize gas costs, though this requires careful consideration of alignment.

Complex data structures like mappings and dynamically-sized arrays use more sophisticated, deterministic hashing algorithms to calculate their storage slots. For a mapping mapping(key => value), the slot for a given key is computed as keccak256(abi.encode(key, slot)) where slot is the position of the mapping itself. This ensures a uniform distribution of storage locations and prevents collisions. Dynamically-sized arrays store their length at a known slot and their elements starting at the slot derived from hashing that position.

Understanding slot assignment is critical for gas optimization, as storage operations are among the most expensive on the EVM. Techniques include minimizing storage writes, using packed variables effectively, and leveraging transient storage or memory where possible. It is also essential for low-level tasks like storage proofs, where external parties must verify the value at a specific slot, and for delegatecall patterns, where two contracts share the same storage layout.

Developers can inspect storage slots directly using tools like cast storage from Foundry or by examining a contract on a block explorer. For the contract at address 0x... and slot 0, the command cast storage 0x... 0 would return the raw 32-byte value. This direct access is invaluable for debugging, writing upgradeable proxies that depend on consistent storage layouts, and creating off-chain tools that need to read contract state without executing a transaction.

ecosystem-usage
STORAGE SLOT

Ecosystem Usage & Importance

A storage slot is the fundamental unit of persistent data storage in the Ethereum Virtual Machine (EVM), representing a single 32-byte (256-bit) location within a smart contract's state. Its deterministic mapping and gas cost structure are critical for security, efficiency, and interoperability across the ecosystem.

01

Deterministic State Mapping (Keccak256)

The location of a variable's storage slot is deterministically calculated using the Keccak256 hash function. For a mapping like mapping(address => uint256) balances, the slot for balances[0x123...] is keccak256(abi.encode(0x123..., slot_index_of_mapping)). This ensures:

  • Consistent state roots across all nodes.
  • No state collisions when variables are accessed.
  • The ability for external tools to inspect and verify contract state without the ABI.
02

Gas Cost & Optimization

Accessing and modifying storage slots is the most expensive operation in terms of gas costs. Key costs (pre-EIP-1559 approximations):

  • SLOAD (Read): ~800 gas
  • SSTORE (Write to zero): ~20,000 gas
  • SSTORE (Write to non-zero): ~5,000 gas This incentivizes developers to optimize by:
  • Using packed variables (multiple small types in one slot).
  • Employing transient storage (EIP-1153) for within-transaction state.
  • Caching storage reads in memory.
03

Security & Attack Vectors

Storage layout is a primary attack surface. Key vulnerabilities include:

  • Storage Collisions: Incorrectly calculated slots in proxy patterns or delegatecall can lead to destructive overwrites.
  • Uninitialized Pointers: Complex types in storage (like structs, arrays) if not properly initialized can point to sensitive slots.
  • Front-running via SLOAD: The visibility of pending state changes in the mempool can be exploited. Secure patterns like the Checks-Effects-Interactions model and using private/internal variables are essential defenses.
04

Tooling & Developer Experience

A suite of tools relies on understanding storage slots:

  • Block Explorers (Etherscan): Decode and display contract state by reading slot data.
  • Development Frameworks (Foundry, Hardhat): Use vm.load() or getStorageAt for testing and debugging.
  • Upgradeable Proxies (UUPS, Transparent): Depend on specific slot reservations (e.g., _IMPLEMENTATION_SLOT) to avoid clashes.
  • State Proofs & Indexers: Services like The Graph or oracle networks use slot proofs to verify off-chain data.
06

Real-World Example: Uniswap V3 Positions

Uniswap V3's NonfungiblePositionManager stores each liquidity position's data in a highly optimized way using storage slots. Key details are packed into a single uint256 slot per position, including:

  • Tick Lower & Upper (int24).
  • Liquidity (uint128).
  • Fee Growth Inside (uint256 - uses two slots). This design minimizes SSTORE operations during position minting/modification, drastically reducing gas costs for users—a direct application of slot-level optimization impacting millions of dollars in daily transaction fees.
security-considerations
STORAGE SLOT

Security Considerations

Understanding the security implications of storage slots is critical for developers and auditors to prevent exploits and protect smart contract state.

01

Storage Collisions

A storage collision occurs when two variables unintentionally map to the same storage slot, leading to data corruption. This is a critical risk in upgradeable contracts using delegatecall or in contracts where storage layout is not carefully managed. For example, appending a new variable in a parent contract can overwrite a variable in a derived contract if their storage layouts are not aligned.

  • Cause: Incorrect calculation of storage positions in inheritance or assembly.
  • Impact: Unauthorized state changes and potential loss of funds.
  • Prevention: Use structured storage layouts, like the unstructured storage pattern, and thorough testing.
02

Uninitialized Pointers

In Solidity, complex variables (like structs, arrays, mappings) declared inside functions are stored in memory by default. If the storage keyword is omitted when intending to write to a state variable, the code will write to an unintended, often zero, storage slot. This can corrupt critical contract data or create vulnerabilities.

  • Example: someStruct myVar; inside a function creates a memory pointer. Assignment without storage does not persist.
  • Risk: Silent data loss or manipulation of slot 0.
  • Mitigation: Explicitly use the storage keyword and perform code audits.
04

Slot Manipulation via Assembly

Direct storage manipulation using inline assembly (Yul/assembly {}) provides low-level control but bypasses Solidity's safety checks. Incorrect slot calculations or writes can have irreversible consequences.

  • Power & Peril: Allows for gas optimization and complex patterns but is error-prone.
  • Common Errors: Miscalculating keccak256 hashes for dynamic types, writing to arbitrary slots.
  • Best Practice: Isolate assembly in well-tested libraries, use constant slot calculations, and implement extensive property-based testing (e.g., with Foundry).
06

Verification & Audit Tools

Several tools exist to analyze and verify storage slot integrity, helping to identify the vulnerabilities listed above before deployment.

  • Slither: A static analysis framework that can detect storage collisions and incorrect storage layouts in inheritance hierarchies.
  • Scribble: A specification language and runtime verification tool that can instrument code to assert properties about storage states.
  • Foundry/Forge: A testing framework allowing direct inspection and manipulation of storage slots via vm.load() and vm.store() for comprehensive unit and invariant testing.
  • Manual Review: Auditors manually trace storage layouts, especially for upgradeable contracts and assembly code.
EVM DATA STORAGE

Storage Slot vs. Other Data Locations

A comparison of persistent and transient data storage locations in the Ethereum Virtual Machine (EVM), highlighting their purpose, cost, and lifecycle.

FeatureStorage Slot (Persistent)Memory (volatile)Calldata (immutable)Stack (ephemeral)

Primary Purpose

Long-term state persistence

Temporary data within a call

Immutable function arguments

Immediate operands & addresses

Gas Cost (Write)

High (20,000 gas for cold, 100 gas for warm)

Medium (scales with allocation)

None (read-only)

Negligible

Gas Cost (Read)

High (2,100 gas for cold, 100 gas for warm)

Low (3 gas per 32-byte word)

Low (negligible)

Negligible

Data Persistence

Persists between transactions

Cleared after function execution

Exists for duration of call

Cleared after opcode execution

Mutability

Read/Write

Read/Write

Read-Only

Read/Write

Location Scope

Contract instance

Function execution

Transaction/External call

Current execution context

Max Capacity

2²⁵⁶ slots (virtually unlimited)

Expands as needed, limited by block gas

Limited by block gas limit

1024 items, 32 bytes each

Typical Use Case

Contract state variables

Local variables, intermediate calculations

Function parameters, especially for external calls

Holding operands for EVM opcodes

STORAGE SLOT

Frequently Asked Questions (FAQ)

A storage slot is the fundamental unit of data storage in the Ethereum Virtual Machine (EVM). These questions address its technical mechanics, optimization, and security implications.

A storage slot is the fundamental, 256-bit (32-byte) unit of persistent data storage for a smart contract on the Ethereum Virtual Machine (EVM). Each contract has its own independent storage, which is a key-value mapping from a 256-bit slot index to a 256-bit slot value. This storage is persistent across transactions and is the most expensive resource to read from and write to, measured in gas. The EVM organizes all contract state—from simple uint256 variables to complex structs and mappings—into this array of slots using specific storage layout rules defined by the Solidity compiler.

ENQUIRY

Get In Touch
today.

Our experts will offer a free quote and a 30min call to discuss your project.

NDA Protected
24h Response
Directly to Engineering Team
10+
Protocols Shipped
$20M+
TVL Overall
NDA Protected Directly to Engineering Team
What is a Storage Slot? | Blockchain Glossary | ChainScore Glossary