Hi all,
I am resurrecting EIP-1930 from Stagnant to Draft, with an updated specification: ethereum/EIPs#12791. The original discussion was in ethereum/EIPs#1930; as requested by the editors back then, this thread replaces it.
What it does
It adds STRICTCALL, STRICTDELEGATECALL and STRICTSTATICCALL (provisionally 0xe0 to 0xe2). They behave exactly like their counterparts, except that the gas argument is a requirement instead of a maximum: if, after all the charges the call makes before entering the callee, the calling frame cannot forward the requested gas under the 63/64 rule of EIP-150, the calling frame halts as if out of gas. It also halts when the call would abort before entering the callee (insufficient balance, depth limit). So when a strict call returns 0, the callee ran with exactly the gas that was asked for and failed on its own.
Under EIP-8037 the guarantee is on execution gas (gas_left); the state-gas reservoir is forwarded on top, as it already is. Since state charges come out of gas_left when the reservoir is empty, a requirement sized for an empty reservoir is enough whatever the transaction gas limit.
In EIP-8141 frame transactions, state gas comes only from the frame’s own state budget, which the transaction signer picks. So STRICTCALL and STRICTDELEGATECALL also take a state_gas requirement, right after gas: in a frame transaction the calling frame halts if state_gas_left is below it. Outside frame transactions it is not checked. Contracts pass gas = execution + state and state_gas = state, which is correct in both. STRICTSTATICCALL is unchanged. (Added 2 Dec, see the update below.)
Why now
“Do not rely on gas pricing” has been good advice for years. But a contract that needs a call to receive a given amount of gas (a meta-transaction forwarder, a smart account, a relayer, a bridge executor, a keeper, an ERC-165 check) has had no way to get that guarantee without relying on gas pricing. The only technique is a gasleft() check before the call with an overhead constant that bounds every charge between the check and the callee, and that constant is the gas schedule.
The Glamsterdam changes (EIP-8037 and EIP-8038) make this concrete. The list of invariants published for auditors includes several that come from this gap, and its guide to handling call failures recommends exactly this pre-call check (rule D), with a governance-adjustable overhead because the next repricing will change it. This EIP lets the EVM do that check at the one point where every charge is known. To be clear about the scope:
- It addresses INV-6, the starvation part of INV-1, the “why did the call fail” half of INV-3, and the nonce part of INV-7, for contracts that use it.
- It does not address INV-2, INV-4, INV-5, INV-8, stipends, reserves for work after the call, or unchecked CREATE.
- It does nothing for contracts already deployed. It is for the contracts written from now on.
Design choices I would like feedback on
- New opcodes rather than a flag bit in the gas argument (the “option B” of the old draft). Option B would change the meaning of deployed bytecode that passes gas values with the top bit set, and would hide the guarantee from static analysis. EOF is Stagnant and its
EXTCALLdropped the gas argument altogether, so the legacy space is where this has to live. Opcode numbers are provisional. - Exceptional halt of the calling frame (not a
REVERT-like return of the remaining gas). - Halting also on the insufficient-balance and depth-limit aborts, so a 0 result has a single meaning.
eth_estimateGasneeds no change: estimators that search for the smallest non-failing gas limit converge above the requirement, because an unmet requirement makes the transaction fail. A non-normative note describes how a client can compute the implied gas limit in one run (the idea of my oldREQUIRE_GASproposal).- No strict
CALLCODE.
Answers to the 2019 objections
- “Niche”: see the list of use cases and invariants above.
- “Can be done with
require(gasleft() >= X)”: that ignores the 63/64 rule, and the correct check depends on the gas schedule. - “Gas costs will not go up”: they have, several times, and they need to. That is why contracts need a way to state their requirements that does not depend on prices.
- “Opcode space”: three opcodes in the legacy space, see point 1.
Prototype
There is a prototype on top of the execution specs (post-Amsterdam development fork), with consensus tests that fill against it, including boundary cases (exact gas and one gas short, for all three variants and their counterparts) and account creation with and without a reservoir, and frame transactions with a state budget exactly at the requirement and one short: wighawag/execution-specs, branch eips/bogota/eip-1930.
Background reading: Ethereum, the concept of gas and its dangers (2020) and gnosis/safe-contracts#100.
Feedback very welcome, especially from client teams on opcode allocation and from contract and compiler developers on whether this is the primitive you would use.