EIPs Explained

EIP-7791 · Draft · Core · 2024-08-13

EIP-7791: GAS2ETH opcode

Draft opcode that lets a contract charge the caller extra gas and pay it as ETH to any address, giving contract authors a usage-based revenue stream.

What problem does it solve?

Popular contracts, compilers and libraries create a lot of value and drive demand for blockspace, but there is no built-in way for their authors to earn from usage. Projects resort to custom fees, tokens or donations, each with its own UX.

GAS2ETH lets a contract say "this call costs N extra gas, paid to address X". Users already understand paying gas, wallets already estimate it, and the author's income automatically rises and falls with network demand.

How it works

A new opcode GAS2ETH (0xFC):

  1. Pops addr and gas_amount.
  2. Caps gas_amount at the remaining local allowance of the current call and the remaining transaction-wide budget.
  3. Computes wei_val = gas_amount * gas_price (the transaction's effective gas price).
  4. Credits wei_val to addr without running any code there (like a beacon withdrawal; the transfer cannot fail).
  5. Pushes wei_val.

Budgets. Each transaction has a global GAS2ETH budget equal to its gas limit. Each call frame gets a local allowance equal to the gas forwarded to it (capped by the global budget); DELEGATECALL shares the caller's allowance. If the frame reverts, its payouts are undone and returned to both budgets. Unused allowance flows back on normal return.

Accounting. Gas converted by GAS2ETH does not count as block gas used, does not affect the base fee or burn, and is not part of the block producer's fee. It is a direct payment from the transaction signer to addr.

Cost. The opcode itself costs the same as the proposed PAY opcode (EIP-5920): warm/cold account access per EIP-2929, plus new-account and value-transfer surcharges when applicable.

Sample code

There is no Solidity keyword for it; a contract would use inline assembly with a raw opcode once a compiler supports it. Illustrative only:

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

contract MeteredLibrary {
    address public immutable author;
    uint256 public constant ROYALTY_GAS = 2_000;

    constructor(address _author) { author = _author; }

    function compute(uint256 x) external returns (uint256) {
        address recipient = author;
        // Hypothetical: needs a compiler that exposes GAS2ETH (0xFC), which
        // pops addr then gas_amount and pushes the wei actually paid.
        // assembly { pop(gas2eth(recipient, ROYALTY_GAS)) }
        recipient; // silence unused-variable warning until then
        return x * x;
    }
}

What the caller pays, in plain arithmetic:

// effective gas price 20 gwei, contract charges 2,000 gas via GAS2ETH
const paidToAuthor = 2_000n * 20_000_000_000n; // 4e13 wei = 0.00004 ETH

Things to know

  • Status is Draft. Test cases and a reference implementation are still TBD, and no fork has scheduled it.
  • The opcode silently caps rather than failing when budgets are exhausted, because a contract cannot read its remaining allowance.
  • It creates a new griefing incentive: an untrusted callee can convert as much of its forwarded gas as possible into ETH for itself. Forward only the gas you need when calling unknown contracts.
  • The total payout in one transaction is bounded by its gas limit, so users are protected from unbounded charges, but wallets would need to show this cost clearly.

#evm #opcode #core #fees #public-goods

Details

Authors
Charles Cooper (@charles-cooper), pcaversaccio (@pcaversaccio)
Status
Draft
Type
Standards Track / Core
Created
2024-08-13
Requires

Machine-readable: Markdown · JSON