Skip to main content

StorageDiff

Storage slot changes for a single contract address during transaction execution.

Overview

StorageDiff tracks before/after values for storage slots. Used extensively with debug_traceTransaction prestateTracer to analyze state modifications.

Type Definition

Usage

Creating Storage Diffs

Querying Changes

Storage Changes

New Slots

Slot created during execution:

Updates

Existing slot modified:

Deletions

Slot cleared (SSTORE 0):

Debug Tracing

StorageDiff used with prestateTracer:

Gas Analysis

Storage operations have significant gas costs:

SSTORE Gas Costs

  • Set (0 → non-zero): 20,000 gas
  • Update (non-zero → non-zero): 5,000 gas
  • Clear (non-zero → 0): 15,000 gas refund
  • Cold access: +2,100 gas

Common Patterns

State Variable Tracking

Map contract state variables to storage slots:

Mapping Storage

Solidity mappings use keccak256(key || slot):

API Reference

Constructors

  • StorageDiff.from(address, changes) - Create from address and changes

Methods

  • StorageDiff.getChange(diff, key) - Get change for specific slot
  • StorageDiff.getKeys(diff) - Get all changed slots
  • StorageDiff.size(diff) - Count changed slots

See Also