Skip to main content
Utilities for calculating collision-resistant storage slots in upgradeable and modular smart contracts.
Implements ERC-7201 (Namespaced Storage Layout) and ERC-8042 (Diamond Storage).

Overview

Storage collisions are a critical issue in upgradeable proxies, libraries, and diamond patterns. When multiple contracts or versions share storage, overlapping slots cause data corruption. ERC-7201 and ERC-8042 solve this by deterministically calculating storage slots from namespace identifiers, ensuring each module has isolated storage regions.

Quick Start

When to Use Each Standard

ERC-7201 (Namespaced Storage Layout):
  • General purpose upgradeable contracts
  • UUPS proxies
  • Transparent proxies
  • Modular contract architectures
  • Extra collision resistance (last byte cleared)
ERC-8042 (Diamond Storage):
  • EIP-2535 Diamond Standard contracts
  • Multi-facet proxy patterns
  • Legacy diamond implementations
  • Simpler formula when compatibility required

API Documentation

Storage Collision Prevention

Without Namespaced Storage

// ❌ DANGEROUS: Storage collision risk
contract ProxyV1 {
  uint256 value;        // slot 0
  address owner;        // slot 1
}

contract ProxyV2 {
  address newOwner;     // slot 0 - COLLISION!
  uint256 value;        // slot 1 - COLLISION!
}

With ERC-7201

// ✅ SAFE: Isolated namespaced storage
contract ProxyV1 {
  struct V1Storage {
    uint256 value;
    address owner;
  }

  function getStorage() internal pure returns (V1Storage storage $) {
    assembly {
      $.slot := 0xabcd... // ERC-7201 slot
    }
  }
}

contract ProxyV2 {
  struct V2Storage {
    address newOwner;
    uint256 value;
  }

  function getStorage() internal pure returns (V2Storage storage $) {
    assembly {
      $.slot := 0x1234... // Different ERC-7201 slot
    }
  }
}

Specification References

  • Proxy - Proxy patterns using namespaced storage
  • Keccak256 - Hash function for slot calculation
  • Bytes - Storage slot byte manipulation