EIP-1706 Disallowing SSTORE below the call stipend (Disable SSTORE with gasleft lower than call stipend)
No call decision · Security & privacy · EIP status Withdrawn · created 2019-01-15
This proposal causes a call to fail with out-of-gas if the gas remaining when SSTORE executes is at or below 2300 (the call stipend). This was meant to block the reentrancy risk created when EIP-1283 lowered the cost of storage writes.
Why it is needed
EIP-1283 significantly lowered the cost of writing values to contract storage. However, Solidity's transfer and send functions forward only 2300 gas to the called contract by default, an amount deliberately too small to change state, which has served as a reentrancy guard. Once EIP-1283 lowered SSTORE's cost, 2300 gas became enough to modify storage, exposing many contracts written under the assumption of safety to a new reentrancy attack vector. Because so much already-deployed contract code is hard to modify, a way to preserve this assumption without changing the code was needed.
What changes
Today
- SSTORE cost dropped sharply after EIP-1283
- A path opened for modifying storage with only the 2300 gas stipend
- The implicit reentrancy protection provided by Solidity's transfer/send was broken
After EIP-1706
- Executing SSTORE with 2300 or less gas remaining causes the call frame to fail with an out-of-gas exception
- The implicit reentrancy protection effect of transfer/send is preserved as before
- SSTORE never previously executed with less than 5000 gas, so there is no mainnet compatibility issue
Who is affected
- Users: Reduces the risk of exposure to reentrancy attacks when interacting with contracts whose storage write costs have been lowered.
- Smart contract developers: Provides a safety net so that existing logic relying on the 2300 gas stipend from transfer/send does not need to be re-audited.
- Client implementation teams: A condition must be added to the SSTORE gas calculation logic, and gas estimation features must reflect this as well.
In depth
Proposal content
A condition is added to the gas cost calculation for the SSTORE opcode. If gasleft (the gas remaining in the current call frame) is at or below 2300, SSTORE does not execute and the current call frame fails with an out-of-gas exception. This check is added separately from the SSTORE cost calculation changed by EIP-1283.
Background: EIP-1283 and reentrancy risk
EIP-1283 significantly lowered the cost of SSTORE when a storage slot had already been changed (a dirty slot). Solidity forwards only 2300 gas by default when calling an external contract via transfer or send, an amount originally too small to allow any state change. After EIP-1283 took effect, that same 2300 gas became enough to execute SSTORE, opening a new reentrancy attack vector that was flagged during the Constantinople upgrade.
Rationale: preserving implicit reentrancy protection
This proposal is based on the premise that preserving the reentrancy guard that existing contracts implicitly relied on requires disallowing state changes whenever the remaining gas is less than the 2300 gas stipend provided by Solidity's transfer/send. This lets existing security assumptions continue to hold without modifying any code.
Other alternatives considered
The source document considered and rejected several alternatives. Withdrawing EIP-1283 would mean giving up a meaningful improvement in its own right. Adding a new call context that allows LOG but blocks state changes would add yet another call type. Raising the cost of dirty-slot SSTORE above 2300 would greatly reduce the benefit of net gas metering. Reducing the stipend itself would make the stipend nearly useless. Restoring the dirty-slot write cost to 5000 and refunding 4800 would require callers to supply more gas upfront and would not make the assumption explicit either. Adding per-contract EVM version metadata was also considered.
Backward compatibility
The proposal explains that since SSTORE never previously executed with less than 5000 gas, this does not introduce any new incompatibility on mainnet. However, gas estimation logic must reflect this new requirement.
Requirements and current status
This proposal depends on EIP-1283 (requires: 1283). Test cases and implementation are left as TODO in the source and remain unfinished. The status is Withdrawn, and the stated reason for withdrawal is that the authors prefer EIP-2200. In other words, this proposal itself is no longer being pursued, and the same problem is addressed instead by EIP-2200.