EIP-1930 Strict gas forwarding CALL (CALLs with strict gas semantic. Revert if not enough gas available.)

Hegota Proposed for Inclusion · EVM & execution · EIP status Stagnant · created 2019-04-10

EIP-1930 adds new behavior to CALL-family calls that either forwards exactly the specified gas or, if that is not possible, reverts the entire call.

Why it is needed

Currently, the gas value specified for CALL, DELEGATECALL, and STATICCALL is only an upper bound. Because of EIP-150's 1/64 retention rule, a call can proceed even if the gas actually forwarded to the external call is less than the specified value, and the current transaction can still succeed on the remaining gas alone. This is a serious problem for cases like meta-transactions or smart contract wallets, where the call must fail if the gas specified by the signer is not used exactly. When checking interface support via EIP-165, a case with less than 30,000 gas can also be incorrectly judged as unsupported. This problem has actually been found in Gnosis Safe and OpenZeppelin's ERC165Checker.

What changes

Today

After EIP-1930

Who is affected

In depth

Two implementation approaches: option a) and option b)

The source text presents two solutions. Option a) adds new opcode variants that strictly enforce the gas for each of CALL, DELEGATECALL, and STATICCALL. If the gas is insufficient, the current call reverts without executing the external call. This has the advantage of not affecting existing contracts, but it adds three opcodes. It mentions that if EIP-1702 is adopted, the existing opcodes could be made obsolete and replaced.

Option b): distinguishing modes by bits in the gas value

Option b) distinguishes modes using the bit pattern of the forwarded gas value itself, without any new opcode. If the most significant bit is 1, the remaining 31 bits are interpreted as the strict gas amount and the same revert rule as option a) applies; if the second most significant bit is 0, the value is treated as an upper bound as before. This is based on the premise that no contract has ever specified a gas value of 0x8000...000 or higher, and it explains that Solidity also does not use values like 0xFFFF...FFFF, which would make gas more expensive. The main advantage is that no new opcode is needed.

The formula for the strict gas rule

The criterion for strict gas behavior is based on EIP-150. Letting G be the remaining gas at the time of the call (excluding the cost of the call itself) and I be the specified gas, if G is less than I x 64/63, the call does not proceed and reverts. The source text cites go-ethereum's gas.go code to show a structure where, in strict mode, insufficient gas returns errNotEnoughGas instead of the previous behavior of forwarding as much as possible and continuing.

Why this is needed: EIP-150's 1/64 retention problem

Under EIP-150, at most G - floor(G/64) is forwarded to the external call, and the remaining floor(G/64) stays with the current call. For example, if G is 6,400,000, 100,000 gas remains with the current call, which in many cases is enough for the transaction to still succeed. So even if the external call fails due to insufficient gas, the overall transaction can appear to succeed. This gap is critical for meta-transactions or smart contract wallets, which must guarantee that exactly the gas specified by the signer was used.

Real-world cases: Gnosis Safe and EIP-165 implementations

The source text states that this problem has already occurred in real code. Gnosis Safe did not account for EIP-150's behavior, so gas verification did not work properly, and to avoid this, wallet owners had to add an unnecessarily large amount of gas to the signed message (see gnosis/safe-contracts#100). It also points out that EIP-165's example implementation and OpenZeppelin's ERC165Checker library have the same vulnerability, since they do not check whether there is enough gas before calling supportsInterface with 30,000 gas.

Two currently possible workarounds and their limitations

The source text describes two workarounds that can be used without any opcode change. The pre-call check calculates in advance whether the value of gasleft() minus an estimated cost E satisfies the 64/63 rule, but E must be estimated accurately in line with changes in gas prices. The post-call check tests gasleft() > txGas/63, which depends less on the gas price structure, but if the called code returns early or succeeds early due to its own gas checks (for example, a meta-transaction nested inside a meta-transaction), the check can pass even though the gas was actually insufficient. It concludes that both methods are inferior to an opcode-level solution.

Compatibility and current status

Option a) adds entirely new opcodes, so it does not affect existing contracts. Option b) is considered compatible because it uses a gas value range that no contract has used so far, but the source text itself notes that this is "to be verified." It states that the implementation remains at the level of citing go-ethereum code as an example, and that there is no fully implemented case. This EIP's status is Stagnant, and there is no record of it being included in any fork.

Original EIP · ← EIPs