Skip to main content

calculateErc7201(keccak256: Function, id: string): Uint8Array

Calculates a collision-resistant storage slot using the ERC-7201 formula: keccak256(keccak256(id) - 1) & ~0xff. The last byte is cleared to provide an additional 256 slots for related storage variables. Parameters:
  • keccak256: (data: Uint8Array) => Uint8Array - Keccak256 hash function
  • id: string - Namespace identifier (recommend reverse domain notation)
Returns: Uint8Array - 32-byte storage slot with last byte cleared Example:
Defined in: src/primitives/Storage/calculateErc7201.js

Formula Breakdown

The formula provides:
  • Collision resistance: Double hash prevents preimage attacks
  • 256 slots: Last byte cleared provides slots 0x00-0xFF for related variables
  • Deterministic: Same ID always produces same slot

Usage Patterns

Solidity Storage Pattern

Namespace Conventions

Comparison with ERC-8042

FeatureERC-7201ERC-8042
Formulakeccak256(keccak256(id) - 1) & ~0xffkeccak256(id)
Related slots256 (last byte)None
Collision resistanceHigher (double hash)Standard (single hash)
Use caseGeneral upgradeable contractsDiamond Standard

See Also