Skip to main content
This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.

Overview

Opcode: 0x55 Introduced: Frontier (EVM genesis) Updated: Istanbul (EIP-2200), Berlin (EIP-2929), London (EIP-3529) SSTORE writes a 256-bit value to persistent storage. Unlike SLOAD, SSTORE has complex gas pricing:
  • Sentry check: Requires >= 2300 gas remaining (EIP-2200)
  • Cost varies: Depends on current value, original value, and warm/cold access
  • Refunds: Up to 4800 gas refunded for clearing slots (EIP-3529)
This operation commits data to blockchain state and powers smart contract state management.

Specification

Stack Input:
Stack Output:
Gas Cost: Complex (see detailed table below)
  • Base: 100-5000 gas depending on operation type
  • Cold access: Additional 2100 gas for first-time write
  • Sentry: Requires >= 2300 gas remaining
  • Refund: Up to 4800 gas refunded when clearing
Operation:

Behavior

SSTORE modifies an account’s storage and marks the slot as changed in the transaction:
  1. Pop key and value from stack
  2. Check sentry - Requires >= 2300 gas remaining (EIP-2200)
  3. Prevent state modification in static calls - Return WriteProtection error
  4. Compute gas cost based on:
    • Current value (what’s stored now)
    • Original value (what was before transaction)
    • Whether slot is cold/warm (EIP-2929)
  5. Consume gas or return OutOfGas error
  6. Apply refunds for clearing (max 4800)
  7. Write to storage and increment PC

EIP-2200 Gas Metering

Modern gas metering (Istanbul+) tracks two values:
CaseCurrentOriginalValueCostRefundNotes
Set00non-zero200000New entry
Updatenon-zeronon-zerodifferent50000Modify existing
Clearnon-zeronon-zero050004800Refund on delete
Restorenon-zeronon-zerooriginal50004800Return to original
Noop00000Already zero

Cold/Warm Access (EIP-2929)

Additional gas added for cold (first-access) writes:
AccessCostNotes
WarmBase costAlready accessed in transaction
ColdBase + 2100First access in transaction

Refund Mechanics (EIP-3529)

Refunds apply when clearing slots:
Refund limit: Maximum refund is 1/5 of total gas consumed in transaction.

Examples

Basic Storage Write

Zero to Non-Zero (Set)

Modify Existing (Update)

Clear Storage (With Refund)

Restore to Original (Refund Path)

Insufficient Gas (Sentry Check)

Static Call Protection

Gas Cost

Cost Matrix

ScenarioCurrentOriginalValueGasRefundEIP
Set (new)00≠0200000-
Update≠0≠0≠0,≠current50000-
Clear≠0≠00500048003529
Restore original≠0Xoriginal500048003529
Noop00000-
Cold set00≠02210002929
Cold update≠0≠0≠0,≠current710002929

Gas Evolution (EIP Timeline)

Pre-Istanbul (Frontier-Petersburg):
  • Zero → non-zero: 20000 gas
  • Otherwise: 5000 gas
  • Refund: 15000 gas for clearing
Istanbul (EIP-2200):
  • Added sentry check (>= 2300 gas required)
  • Complex metering based on original value
  • Reduced refund to 4800 (EIP-3529)
Berlin (EIP-2929):
  • Added cold/warm access tracking
  • First write to slot: +2100 gas
London (EIP-3529):
  • Reduced refunds from 15000 to 4800
  • Max refund limited to 1/5 of total gas

Edge Cases

Noop Write (Already Zero)

Max Value Write

Refund Limit

Common Usage

State Variable Storage

Mapping Updates

Batch Updates

Gas-Efficient Clearing

Implementation

Testing

Test Coverage

Security

Sentry Check (EIP-2200)

The sentry ensures SSTORE cannot be called with insufficient gas to complete state modifications:
Solution: Sentry check (>= 2300 gas) prevents this:

Static Call Protection

SSTORE correctly rejects all writes in STATICCALL context:

Reentrancy with Storage

Refund Manipulation

Attacker might try to maximize refunds:

Gas Cost Calculation Errors

Benchmarks

Storage write costs:
  • Set (0 → non-zero): 20000 gas
  • Update (non-zero → different): 5000 gas
  • Clear (non-zero → 0): 5000 gas + 4800 refund
  • Cold access penalty: +2100 gas (EIP-2929)
Relative performance:
  • MSTORE (memory): 3 gas
  • Warm SLOAD: 100 gas
  • Cold SLOAD: 2100 gas
  • Warm SSTORE update: 5000 gas
  • SSTORE set: 20000 gas (4x more expensive than update)
Optimization tactics:

References