EIPs Explained

EIP-1930 · Stagnant · Core · 2019-04-10

EIP-1930: CALLs with strict gas semantic. Revert if not enough gas available.

Proposes CALL variants that give the callee exactly the gas requested or revert the caller, closing a 63/64-rule loophole that lets relayers make meta-transactions and ERC-165 checks fail on purpose.

What problem does it solve?

The gas argument of CALL, DELEGATECALL and STATICCALL is only a maximum. Since EIP-150, a call forwards at most G - floor(G/64) of the gas left G, keeping 1/64 back for the caller. If the caller asks for more than that, the callee silently gets less, and the caller keeps running.

That matters when the callee's failure must reflect real behaviour, not a lack of gas:

  • Meta-transactions and smart-contract wallets. A relayer submits a call signed by a user with a specified gas amount. By supplying just too little gas, a malicious relayer can make the inner call fail while the outer transaction still succeeds (and, for example, the nonce is used up or a fee is paid).
  • ERC-165 checks. supportsInterface is called with 30,000 gas. If less is actually forwarded, it can fail and the caller wrongly concludes the interface is unsupported.

Developers can work around this with manual gasleft() checks, but these depend on exact gas pricing and are easy to get wrong.

How it works

The EIP offers two alternatives:

  • Option a: add strict variants of CALL, DELEGATECALL and STATICCALL. If the gas left (after the call's own cost) is not enough to forward the requested amount, the current frame reverts.
  • Option b: reuse the existing opcodes. If the most significant bit of the gas argument is set, the remaining bits are a strict gas amount; otherwise behaviour is unchanged. This relies on no existing contract passing such huge gas values.

In both cases the strict rule is: revert unless G >= I * 64/63, where G is gas left at the call and I the requested amount. In Geth terms, the branch that silently caps gas would instead return an out-of-gas error.

Sample code

The workaround contracts use today, which this EIP would make unnecessary:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract Forwarder {
    /// Call `to` with exactly `txGas`, or revert.
    function execute(address to, bytes calldata data, uint256 txGas)
        external returns (bool success, bytes memory ret)
    {
        (success, ret) = to.call{gas: txGas}(data);

        // Post-call check from the EIP: if the callee was starved,
        // less than txGas/63 can remain, so revert the whole thing.
        if (gasleft() <= txGas / 63) {
            assembly { invalid() } // consume all gas, like a real out-of-gas
        }
    }
}

The post-call check still has a gap: if the callee returned early after being given too little gas, enough gas may remain to pass it. That is why the author argues for an EVM-level fix.

Things to know

  • Status is Stagnant. No strict-gas call opcode exists on mainnet, so the workarounds above remain necessary.
  • Libraries such as OpenZeppelin's meta-transaction forwarder include this kind of gas check; prefer an audited implementation over hand-rolled code.
  • Option a mentions EIP-1702 (account versioning) as a way to retire the old opcodes; that proposal is also stagnant.
  • A strict-gas opcode would also decouple such contracts from EIP-150's exact forwarding rule, so the rule could change later without breaking them.

#evm #gas #opcode #meta-transactions #core

Details

Authors
Ronan Sandford (@wighawag)
Status
Stagnant
Type
Standards Track / Core
Created
2019-04-10

Machine-readable: Markdown · JSON