EVMTools

Storage Slot Calculator

Calculate Solidity storage slots for variables, mappings, and nested mappings using keccak256.

Solidity Storage Layout Reference

Simple Variables

Stored sequentially starting at slot 0. Each slot is 32 bytes. Multiple small variables can be packed into one slot.

Mappings

The value for mapping(keyType => valueType) at slot p with key k is at: keccak256(abi.encode(k, p))

Nested Mappings

For mapping(k1Type => mapping(k2Type => valueType)) at slot p: compute keccak256(abi.encode(k2, keccak256(abi.encode(k1, p))))

Dynamic Arrays

Length is stored at slot p. Element i is at keccak256(p) + i.

How to Use This Storage Slot Calculator

This tool calculates the exact storage slot location for Solidity state variables, including simple variables, mappings, and nested mappings. It uses keccak256 hashing to replicate the EVM's storage layout rules.

  1. Select the storage type — choose between a simple variable (direct slot number), a mapping, or a nested mapping.
  2. Enter the base slot number — this is the position of the variable in your contract's storage layout (starting from 0 for the first state variable).
  3. Enter the mapping key(s) — for mappings, provide the key value (address, uint256, etc.) to calculate the specific storage location.
  4. View the computed slot — the tool shows the resulting 32-byte slot hash that you can use with eth_getStorageAt to read the value directly from the blockchain.

All calculations run locally in your browser using standard keccak256 hashing and ABI encoding.

Common Use Cases

  • Reading contract state directly — Calculate slot locations to read private variables using eth_getStorageAt RPC calls without needing public getter functions.
  • Security auditing — Verify storage layouts during smart contract audits to ensure variables are stored where expected and proxy storage does not collide.
  • Proxy contract verification — Confirm that implementation and proxy contracts use compatible storage layouts to prevent storage collision bugs.
  • Forensic analysis — Investigate contract state at specific block heights by reading raw storage slots for post-incident analysis.
  • Gas optimization — Understand variable packing to optimize storage layout and reduce gas costs for SSTORE and SLOAD operations.

Related Tools

Frequently Asked Questions

How does EVM storage work?

The EVM stores contract state in a key-value store where both keys (slots) and values are 32 bytes (256 bits). Each slot is addressed by a 256-bit integer. State variables declared in Solidity are assigned sequential slot numbers starting from 0, with multiple small variables packed into a single slot when possible.

How are mapping storage slots calculated?

For a mapping at slot p, the storage slot for a key k is computed as keccak256(abi.encode(k, p)). The key and slot number are concatenated (ABI-encoded) and hashed with keccak256. This produces a unique slot for each key that is virtually guaranteed not to collide with other storage slots.

How do nested mapping slots work?

For a nested mapping like mapping(address => mapping(uint256 => value)), the slot is computed in two steps. First, compute the slot for the outer key: slot1 = keccak256(abi.encode(outerKey, baseSlot)). Then compute the final slot using the inner key: slot2 = keccak256(abi.encode(innerKey, slot1)).

How are dynamic array elements stored?

For a dynamic array at slot p, the array length is stored at slot p itself. The array elements start at slot keccak256(p), with element i located at slot keccak256(p) + i. Each element occupies one or more consecutive slots depending on the element size.

What is storage variable packing in Solidity?

Solidity packs multiple state variables into a single 32-byte storage slot when they fit. For example, two uint128 variables declared consecutively share one slot. Variables larger than 16 bytes (like address or uint256) always start a new slot. Understanding packing is essential for gas optimization and correct slot calculation.