EIPs Explained

EIP-1706 · Withdrawn · Core · 2019-01-15

EIP-1706: Disable SSTORE with gasleft lower than call stipend

Proposed making SSTORE fail when 2300 gas or less remains, so cheaper storage writes could not break the reentrancy protection old contracts got from the transfer/send stipend; the idea was folded into EIP-2200.

What problem does it solve?

When a Solidity contract uses transfer or send to pay ETH, the recipient receives only a 2300 gas stipend. Many contracts relied on this, implicitly: with 2300 gas a malicious recipient could not write to storage, because SSTORE always cost at least 5000 gas. That made reentrancy through transfer effectively harmless.

EIP-1283 (net gas metering) made repeated writes to the same storage slot within a transaction much cheaper, as low as a few hundred gas. Shortly before the Constantinople upgrade, security researchers showed this let a recipient modify state within the 2300 stipend, opening a new reentrancy attack on existing contracts. Constantinople was postponed, and EIP-1283 was removed in the Petersburg fork (EIP-1716).

EIP-1706 proposed a way to keep cheap storage writes and the old safety assumption.

How it works

One extra rule in the SSTORE gas calculation:

  • If gasleft is less than or equal to 2300 when SSTORE executes, the current call frame fails with an out-of-gas exception.

Since a stipend-only call starts with exactly 2300 gas, any SSTORE it attempts fails, regardless of how cheap the write would otherwise be. Contracts that rely on the stipend stay safe, and normal calls with more gas are unaffected.

Because SSTORE had never been possible with less than 5000 gas, the authors argued nothing on mainnet would break.

Sample code

The rule as pseudocode, inserted before any other SSTORE gas accounting:

CALL_STIPEND = 2300

def sstore(evm, key, value):
    if evm.gas_left <= CALL_STIPEND:
        raise OutOfGas("SSTORE with gas left <= stipend")
    # ... normal net-metered SSTORE cost and refund logic follows

Why it matters for this pattern:

// Many contracts assumed `to` cannot change state during this call
payable(to).transfer(amount); // forwards only 2300 gas

Things to know

  • Status is Withdrawn. The authors preferred EIP-2200, which re-introduced net gas metering and includes the same "fail if gasleft ≤ 2300" sentinel. EIP-2200 shipped in Istanbul.
  • The episode is the main reason the 2300 stipend is still treated as a protocol-level invariant for SSTORE.
  • Do not rely on the stipend as a security mechanism in new code. Gas costs can change, and modern guidance is to use call with explicit reentrancy guards instead of transfer/send.

#gas #sstore #security #reentrancy #core

Details

Authors
Alex Forshtat <[email protected]>, Yoav Weiss <[email protected]>
Status
Withdrawn
Type
Standards Track / Core
Created
2019-01-15
Requires

Machine-readable: Markdown · JSON