Skip to main content

GasRefund

GasRefund represents gas refunded after transaction execution. Post-London (EIP-3529), refunds are capped at gasUsed / 5.

Type Definition

Branded bigint representing gas refund (always non-negative).

Gas Refund Mechanics

Pre-London (Before EIP-3529)

Large refunds were possible from:
  • SSTORE clear: 15,000 gas (clearing storage slot)
  • SELFDESTRUCT: 24,000 gas (destroying contract)
Problem: Caused “gas tokens” - exploiting refunds for profit.

Post-London (EIP-3529)

Refunds significantly reduced:
  • Cap: Maximum refund = gasUsed / 5 (20% of gas used)
  • SSTORE clear: Still generates 15,000 refund, but capped
  • SELFDESTRUCT: No longer gives refund
Effect: Eliminated gas token exploits, simplified gas economics.

API

Constructors

from(value)

Create GasRefund from number, bigint, or string.
Throws: InvalidFormatError if value is negative.

Conversions

toNumber(refund)

Convert to number.

toBigInt(refund)

Convert to bigint (identity operation).

toHex(refund)

Convert to hex string.

Comparisons

equals(ref1, ref2)

Check equality.

Utilities

cappedRefund(refund, gasUsed)

Apply EIP-3529 refund cap.
Post-London enforcement: min(refund, gasUsed / 5)

Usage Examples

Calculate Effective Gas Cost

Compare Pre/Post London

Multiple Storage Clears

Refund Sources

SSTORE Operations

SELFDESTRUCT

EIP-3529 Rationale

Problems with Old Refund System

  1. Gas Tokens: Exploited refunds for profit
    • Store data when gas cheap
    • Clear data when gas expensive
    • Get refund at high gas price
  2. Block Variability: Large refunds caused unpredictable block gas usage
  3. Complexity: Made gas economics hard to reason about

Post-3529 Benefits

  1. No Gas Tokens: Capped refunds eliminate exploit
  2. Predictable Costs: Users pay closer to actual gas used
  3. Simpler Economics: Easier to estimate transaction costs
  4. Faster State Growth: Reduced incentive to keep unnecessary storage

Refund Cap Formula

Where:
  • totalRefund: Sum of all refunds from SSTORE operations
  • gasUsed: Actual gas consumed by transaction
  • Division rounds down (integer division)

Usage Patterns

Check if Refund is Capped

Calculate Maximum Possible Refund

London Hard Fork

Date: August 5, 2021 (Block 12,965,000) Changes:
  • EIP-3529: Refund reduction
  • EIP-1559: Fee market change
  • EIP-3198: BASEFEE opcode
  • EIP-3541: Reject new contracts starting with 0xEF
Impact: Most transactions now have zero or minimal refunds.

See Also