EIP-7791 The GAS2ETH Instruction, Converting Gas to ETH (GAS2ETH opcode)

No call decision · EVM & execution · EIP status Draft · created 2024-08-13

Adds a new instruction, GAS2ETH (0xFC), to the EVM that lets a contract convert a transaction's gas into ETH and send it directly to a specified address. This opens a path for contract developers to collect fees in the form of gas.

Why it is needed

Widely used smart contracts provide functionality to users and generate block space demand for the network, but the developers and compiler teams who built them have no good way to be rewarded in proportion to usage. Today, each contract designs its own fee structure or bolts on complex token economics, so monetization approaches vary from project to project, and projects with public-good characteristics find it especially hard to secure funding. This proposal lets a contract charge users in gas, a unit they are already familiar with. Charging in gas requires no changes to existing transaction creation and processing tools, and because developers earn more when the network is busy and less when it is quiet, their revenue naturally tracks network activity. It is an attempt to align the interests of contract developers, validators, and the network as a whole in the same direction.

What changes

Today

After EIP-7791

Who is affected

In depth

Execution Rules

GAS2ETH (0xFC) pops two values from the stack, in order addr and gas_amount. If there are fewer than two values, it fails with a stack underflow. gas_amount is deducted from both the current call frame's local allowance and the transaction's global budget, and if it exceeds the remaining limit it is truncated to min(gas_amount, remaining_local_allowance, remaining_global_GAS2ETH_budget). wei_val is calculated by multiplying gas_amount by the gas_price of the current transaction context; wei_val is then paid to addr and pushed onto the stack. The recipient account's code is not executed, and if the account does not exist, a new balance is simply added, so the transfer itself cannot fail. If a REVERT or an exceptional halt occurs, the portion paid out via GAS2ETH in that frame is refunded to both the global budget and the parent frame's budget.

The Dual Budget Model

A transaction maintains a single global GAS2ETH budget initialized to tx.gas_limit, and each call frame has a local allowance automatically derived from the gas it was forwarded. For CALL, CALLCODE, and STATICCALL, allowance = min(forwarded_gas, remaining_global_GAS2ETH_budget), while DELEGATECALL shares the caller's allowance directly. On revert, the frame's deduction is refunded to both the global budget and the parent frame; on a normal return, any unused local allowance goes back into the global budget. This structure means an untrusted callee can never spend more on GAS2ETH than the gas it was explicitly forwarded, and the total amount of GAS2ETH generated across a transaction is capped by the gas limit.

The Gas Cost of the Instruction Itself

The cost structure is the same as the proposed PAY opcode. If addr is in accessed_addresses, WARM_STORAGE_READ_COST is charged; otherwise COLD_ACCOUNT_ACCESS_COST is charged (EIP-2929). If addr is a non-existent account and the value sent is non-zero, GAS_NEW_ACCOUNT is added, and if the value is non-zero, GAS_CALL_VALUE is added. In short, sending to an already-accessed existing address is cheapest, and sending to a cold new account is most expensive.

Separation from Fee Accounting

GAS2ETH's gas consumption does not affect the base fee, burn, the block's gasUsed, or transaction fees at all. The converted ETH is treated, outside of block reward and fee accounting, as money paid directly by the transaction signer (tx.origin) to the recipient address, preventing a double creation of ETH from COINBASE rewards. According to the original text, GAS2ETH is designed on the intuition that since it does not actually consume computational resources, it should not affect block space accounting or the base fee. The reason for having a separate budget follows the same logic: to prevent GAS2ETH usage from taking gas actually needed for contract execution, which would cause a DoS where execution halts midway.

Rationale for design choices

The reason it charges gas instead of ETH is that charging ETH directly would complicate the user experience and prevent developers from directly participating in gas demand fluctuations. Direct charging was chosen over a pro-rata model because pro-rata would create an incentive to deliberately waste gas in order to inflate fees. Requiring a target address to be specified, rather than increasing the balance of the currently executing contract, is for the modularity of separating fee collection from contract functionality. gas_price uses the same value used to calculate transaction cost, aligning it with user expectations. The reason exceeding the budget truncates rather than halting with an exception is that the budget is a value not queryable from code, so a contract has no way to avoid the halt. The budget is set at 100% of the gas limit as a natural upper bound, and a future EIP-2718-based new transaction type where users explicitly specify a GAS2ETH budget is mentioned.

Security considerations

Like the PAY opcode (EIP-5920) or beacon withdrawals (EIP-4895), GAS2ETH moves ETH without executing the recipient account's code. Thanks to the per-frame allowance and global budget, a callee cannot spend more than the gas it was given, and total issuance is also bounded by the gas limit, but new risks arise. Gas-wasting griefing attacks that were previously unprofitable can become profitable with GAS2ETH, giving malicious contracts an economic incentive to exhaust the allowance as much as possible. The original text recommends (SHOULD) minimizing forwarded gas and GAS2ETH exposure when interacting with untrusted code.

Current status

This proposal was created on August 13, 2024, and its status is Draft. Test cases and the reference implementation are still TBD and empty. Since it is at the draft stage, details including the opcode number, budget model, and gas cost may change going forward. There is no core developer call decision yet on whether to include it in a fork.

Original EIP · ← EIPs