{"eip":7791,"title":"GAS2ETH opcode","description":"Introduces a new opcode, `GAS2ETH`, to convert gas to ETH","authors":["Charles Cooper (@charles-cooper)","pcaversaccio (@pcaversaccio)"],"status":"Draft","type":"Standards Track","category":"Core","created":"2024-08-13","requires":[2929],"discussionsTo":"https://ethereum-magicians.org/t/eip-7791-gas2eth-opcode/21418","repo":"EIPs","label":"EIP-7791","officialUrl":"https://eips.ethereum.org/EIPS/eip-7791","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7791.md","url":"https://eips.huatuo.xyz/eip-7791/","tldr":{"en":"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.","ja":"コントラクトが呼び出し元に追加の gas を課し、それを ETH として任意のアドレスに支払えるようにする opcode のドラフト。コントラクトの作者に、利用量に応じた収益源を与える。","ko":"컨트랙트가 호출자에게 가스를 추가로 부과하고 이를 ETH로 임의의 주소에 지급할 수 있게 하는 opcode 초안. 컨트랙트 저자에게 사용량 기반 수익원을 제공한다.","zh":"草案操作码：让合约向调用者额外收取 gas，并以 ETH 形式支付给任意地址，为合约作者提供按使用量计费的收入来源。"},"tags":["evm","opcode","core","fees","public-goods"],"explainers":{"en":{"lang":"en","tldr":"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.","tags":["evm","opcode","core","fees","public-goods"],"related":[5920,2929,4895],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7791/","markdown":"## What problem does it solve?\n\nPopular 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.\n\n`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.\n\n## How it works\n\nA new opcode `GAS2ETH` (`0xFC`):\n\n1. Pops `addr` and `gas_amount`.\n2. Caps `gas_amount` at the remaining local allowance of the current call and the remaining transaction-wide budget.\n3. Computes `wei_val = gas_amount * gas_price` (the transaction's effective gas price).\n4. Credits `wei_val` to `addr` without running any code there (like a beacon withdrawal; the transfer cannot fail).\n5. Pushes `wei_val`.\n\n**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.\n\n**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`.\n\n**Cost.** The opcode itself costs the same as the proposed `PAY` opcode ([EIP-5920](/eip-5920/)): warm/cold account access per [EIP-2929](/eip-2929/), plus new-account and value-transfer surcharges when applicable.\n\n## Sample code\n\nThere is no Solidity keyword for it; a contract would use inline assembly with a raw opcode once a compiler supports it. Illustrative only:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract MeteredLibrary {\n    address public immutable author;\n    uint256 public constant ROYALTY_GAS = 2_000;\n\n    constructor(address _author) { author = _author; }\n\n    function compute(uint256 x) external returns (uint256) {\n        address recipient = author;\n        // Hypothetical: needs a compiler that exposes GAS2ETH (0xFC), which\n        // pops addr then gas_amount and pushes the wei actually paid.\n        // assembly { pop(gas2eth(recipient, ROYALTY_GAS)) }\n        recipient; // silence unused-variable warning until then\n        return x * x;\n    }\n}\n```\n\nWhat the caller pays, in plain arithmetic:\n\n```ts\n// effective gas price 20 gwei, contract charges 2,000 gas via GAS2ETH\nconst paidToAuthor = 2_000n * 20_000_000_000n; // 4e13 wei = 0.00004 ETH\n```\n\n## Things to know\n\n- Status is **Draft**. Test cases and a reference implementation are still `TBD`, and no fork has scheduled it.\n- The opcode silently caps rather than failing when budgets are exhausted, because a contract cannot read its remaining allowance.\n- 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.\n- 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.\n"},"ja":{"lang":"ja","tldr":"コントラクトが呼び出し元に追加の gas を課し、それを ETH として任意のアドレスに支払えるようにする opcode のドラフト。コントラクトの作者に、利用量に応じた収益源を与える。","tags":["evm","opcode","core","fees","public-goods"],"related":[5920,2929,4895],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7791/","markdown":"## 何を解決するのか\n\n人気のあるコントラクト、コンパイラ、ライブラリは大きな価値を生み、ブロックスペースの需要を押し上げていますが、その作者が利用から収益を得るための組み込みの手段はありません。プロジェクトは独自の手数料、トークン、寄付に頼り、それぞれが独自の UX を持っています。\n\n`GAS2ETH` を使うと、コントラクトは「この呼び出しは追加で N gas かかり、アドレス X に支払われる」と宣言できます。ユーザーはすでに gas を払うことを理解しており、ウォレットもすでにそれを見積もっており、作者の収入はネットワークの需要に応じて自動的に増減します。\n\n## 仕組み\n\n新しい opcode `GAS2ETH`（`0xFC`）:\n\n1. `addr` と `gas_amount` を pop します。\n2. `gas_amount` を、現在の呼び出しの残りのローカル許容量と、トランザクション全体の残り予算で上限を切ります。\n3. `wei_val = gas_amount * gas_price`（トランザクションの実効 gas 価格）を計算します。\n4. そのアドレスのコードを実行せずに、`wei_val` を `addr` に入金します（ビーコンチェーンの引き出しと同様で、送金は失敗しません）。\n5. `wei_val` を push します。\n\n**予算。** 各トランザクションは、gas 上限に等しいグローバルな `GAS2ETH` 予算を持ちます。各コールフレームは、そのフレームに転送された gas に等しい（グローバル予算で上限が切られた）ローカル許容量を得ます。`DELEGATECALL` は呼び出し元の許容量を共有します。フレームが revert した場合、そのフレームの支払いは取り消され、両方の予算に戻されます。使われなかった許容量は、通常の return 時に戻ります。\n\n**会計。** `GAS2ETH` で変換された gas は、ブロックで使用された gas にはカウントされず、base fee やバーンにも影響せず、ブロック生成者の手数料にも含まれません。これはトランザクション署名者から `addr` への直接の支払いです。\n\n**コスト。** opcode 自体のコストは、提案されている `PAY` opcode（[EIP-5920](/eip-5920/)）と同じです。[EIP-2929](/eip-2929/) に従うウォーム/コールドなアカウントアクセスに、該当する場合は新規アカウントと価値移転の追加料金が加わります。\n\n## サンプルコード\n\nSolidity にこのためのキーワードはありません。コンパイラが対応した時点で、コントラクトは生の opcode を使ったインラインアセンブリを使うことになるでしょう。説明用のみです。\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract MeteredLibrary {\n    address public immutable author;\n    uint256 public constant ROYALTY_GAS = 2_000;\n\n    constructor(address _author) { author = _author; }\n\n    function compute(uint256 x) external returns (uint256) {\n        address recipient = author;\n        // Hypothetical: needs a compiler that exposes GAS2ETH (0xFC), which\n        // pops addr then gas_amount and pushes the wei actually paid.\n        // assembly { pop(gas2eth(recipient, ROYALTY_GAS)) }\n        recipient; // silence unused-variable warning until then\n        return x * x;\n    }\n}\n```\n\n呼び出し元が支払う額を、単純な算術で示すと:\n\n```ts\n// effective gas price 20 gwei, contract charges 2,000 gas via GAS2ETH\nconst paidToAuthor = 2_000n * 20_000_000_000n; // 4e13 wei = 0.00004 ETH\n```\n\n## 知っておくべきこと\n\n- ステータスは **Draft** です。テストケースとリファレンス実装はまだ `TBD` で、どのフォークにも予定されていません。\n- この opcode は、予算が尽きたときに失敗せず、黙って上限で切り詰めます。コントラクトは自分の残りの許容量を読み取れないためです。\n- これは新たな嫌がらせ（グリーフィング）のインセンティブを生みます。信頼できない呼び出し先が、転送された gas のできるだけ多くを自分のための ETH に変換できてしまいます。未知のコントラクトを呼ぶときは、必要な gas だけを転送してください。\n- 1 トランザクションでの支払総額はその gas 上限で制限されるため、ユーザーは無制限の課金から保護されますが、ウォレットはこのコストを明確に表示する必要があります。\n"},"ko":{"lang":"ko","tldr":"컨트랙트가 호출자에게 가스를 추가로 부과하고 이를 ETH로 임의의 주소에 지급할 수 있게 하는 opcode 초안. 컨트랙트 저자에게 사용량 기반 수익원을 제공한다.","tags":["evm","opcode","core","fees","public-goods"],"related":[5920,2929,4895],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7791/","markdown":"## 어떤 문제를 해결하나요?\n\n인기 있는 컨트랙트, 컴파일러, 라이브러리는 많은 가치를 만들고 블록 공간 수요를 이끌지만, 저자가 사용량으로 수익을 얻을 내장 수단은 없습니다. 프로젝트들은 자체 수수료, 토큰, 기부에 의존하며 저마다 UX가 다릅니다.\n\n`GAS2ETH`를 쓰면 컨트랙트가 \"이 호출은 N 가스가 추가로 들고, 주소 X에 지급된다\"고 말할 수 있습니다. 사용자는 이미 가스를 내는 것을 이해하고 있고, 지갑도 이미 이를 추정하며, 저자의 수입은 네트워크 수요에 따라 자동으로 오르내립니다.\n\n## 어떻게 동작하나요?\n\n새 opcode `GAS2ETH`(`0xFC`):\n\n1. `addr`과 `gas_amount`를 pop합니다.\n2. `gas_amount`를 현재 호출에 남은 로컬 허용량과 트랜잭션 전체의 남은 예산으로 제한합니다.\n3. `wei_val = gas_amount * gas_price`(트랜잭션의 유효 가스 가격)를 계산합니다.\n4. 그 주소에서 아무 코드도 실행하지 않고 `wei_val`을 `addr`에 입금합니다(비콘 체인 인출과 같으며, 전송은 실패하지 않습니다).\n5. `wei_val`을 push합니다.\n\n**예산.** 각 트랜잭션은 가스 한도와 같은 전역 `GAS2ETH` 예산을 갖습니다. 각 호출 프레임은 자신에게 전달된 가스(전역 예산으로 제한)와 같은 로컬 허용량을 받습니다. `DELEGATECALL`은 호출자의 허용량을 공유합니다. 프레임이 revert되면 그 프레임의 지급은 취소되어 두 예산 모두에 돌아갑니다. 쓰지 않은 허용량은 정상 반환 시 되돌아갑니다.\n\n**회계.** `GAS2ETH`로 변환된 가스는 블록 사용 가스로 집계되지 않고, base fee나 소각에 영향을 주지 않으며, 블록 생산자의 수수료에도 포함되지 않습니다. 트랜잭션 서명자가 `addr`에 직접 지급하는 것입니다.\n\n**비용.** opcode 자체의 비용은 제안된 `PAY` opcode([EIP-5920](/eip-5920/))와 같습니다. [EIP-2929](/eip-2929/)에 따른 warm/cold 계정 접근에, 해당될 때는 신규 계정 및 가치 전송 추가 요금이 붙습니다.\n\n## 샘플 코드\n\n이를 위한 Solidity 키워드는 없습니다. 컴파일러가 지원하게 되면 컨트랙트는 raw opcode를 쓰는 인라인 어셈블리를 사용할 것입니다. 설명용일 뿐입니다.\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract MeteredLibrary {\n    address public immutable author;\n    uint256 public constant ROYALTY_GAS = 2_000;\n\n    constructor(address _author) { author = _author; }\n\n    function compute(uint256 x) external returns (uint256) {\n        address recipient = author;\n        // Hypothetical: needs a compiler that exposes GAS2ETH (0xFC), which\n        // pops addr then gas_amount and pushes the wei actually paid.\n        // assembly { pop(gas2eth(recipient, ROYALTY_GAS)) }\n        recipient; // silence unused-variable warning until then\n        return x * x;\n    }\n}\n```\n\n호출자가 내는 금액을 단순한 산술로 보면 다음과 같습니다.\n\n```ts\n// effective gas price 20 gwei, contract charges 2,000 gas via GAS2ETH\nconst paidToAuthor = 2_000n * 20_000_000_000n; // 4e13 wei = 0.00004 ETH\n```\n\n## 알아둘 점\n\n- 상태는 **Draft**입니다. 테스트 케이스와 레퍼런스 구현은 아직 `TBD`이고, 어떤 포크에도 예정되어 있지 않습니다.\n- 이 opcode는 예산이 소진되어도 실패하지 않고 조용히 상한으로 잘라냅니다. 컨트랙트가 자신의 남은 허용량을 읽을 수 없기 때문입니다.\n- 새로운 그리핑(방해) 유인이 생깁니다. 신뢰할 수 없는 피호출자가 전달받은 가스를 최대한 많이 자신을 위한 ETH로 바꿀 수 있습니다. 알 수 없는 컨트랙트를 호출할 때는 필요한 만큼의 가스만 전달하세요.\n- 한 트랜잭션의 총 지급액은 가스 한도로 제한되므로 사용자는 무제한 과금으로부터 보호되지만, 지갑은 이 비용을 명확히 보여 줘야 합니다.\n"},"zh":{"lang":"zh","tldr":"草案操作码：让合约向调用者额外收取 gas，并以 ETH 形式支付给任意地址，为合约作者提供按使用量计费的收入来源。","tags":["evm","opcode","core","fees","public-goods"],"related":[5920,2929,4895],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7791/","markdown":"## 它解决什么问题？\n\n热门的合约、编译器和库创造了大量价值，也推动了区块空间需求，但其作者没有内置的方式从使用中获得收入。项目只能求助于自定义费用、代币或捐赠，每种方式都有各自的用户体验。\n\n`GAS2ETH` 让合约可以声明\"这次调用额外花费 N gas，支付给地址 X\"。用户本来就理解支付 gas，钱包本来就会估算它，作者的收入也会随网络需求自动涨落。\n\n## 它如何运作\n\n新增操作码 `GAS2ETH`（`0xFC`）：\n\n1. 弹出 `addr` 和 `gas_amount`。\n2. 把 `gas_amount` 限制在当前调用剩余的本地额度和整笔交易剩余预算之内。\n3. 计算 `wei_val = gas_amount * gas_price`（交易的有效 gas 价格）。\n4. 把 `wei_val` 记入 `addr` 的账户，且不在那里运行任何代码（类似信标链提款，转账不会失败）。\n5. 压入 `wei_val`。\n\n**预算。** 每笔交易有一个全局 `GAS2ETH` 预算，等于其 gas 上限。每个调用帧获得一个本地额度，等于转发给它的 gas（受全局预算限制）；`DELEGATECALL` 共享调用者的额度。如果该帧回滚，它的支付会被撤销，并退回到两个预算中。未用完的额度会在正常返回时流回。\n\n**记账。** 由 `GAS2ETH` 转换的 gas 不计入区块已用 gas，不影响基础费用或销毁，也不属于区块生产者的费用。它是交易签名者向 `addr` 的直接支付。\n\n**成本。** 该操作码本身的成本与提议中的 `PAY` 操作码（[EIP-5920](/eip-5920/)）相同：按 [EIP-2929](/eip-2929/) 区分热/冷账户访问，并在适用时加上新账户和价值转移的附加费用。\n\n## 示例代码\n\nSolidity 中没有对应的关键字；等编译器支持后，合约会使用带原始操作码的内联汇编。仅作示意：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract MeteredLibrary {\n    address public immutable author;\n    uint256 public constant ROYALTY_GAS = 2_000;\n\n    constructor(address _author) { author = _author; }\n\n    function compute(uint256 x) external returns (uint256) {\n        address recipient = author;\n        // Hypothetical: needs a compiler that exposes GAS2ETH (0xFC), which\n        // pops addr then gas_amount and pushes the wei actually paid.\n        // assembly { pop(gas2eth(recipient, ROYALTY_GAS)) }\n        recipient; // silence unused-variable warning until then\n        return x * x;\n    }\n}\n```\n\n用简单算术表示调用者要支付的金额：\n\n```ts\n// effective gas price 20 gwei, contract charges 2,000 gas via GAS2ETH\nconst paidToAuthor = 2_000n * 20_000_000_000n; // 4e13 wei = 0.00004 ETH\n```\n\n## 需要注意\n\n- 状态为 **Draft**。测试用例和参考实现仍是 `TBD`，也没有任何分叉计划纳入它。\n- 预算耗尽时，该操作码会静默截断而不是失败，因为合约无法读取自己剩余的额度。\n- 它带来了新的\"捣乱\"（griefing）动机：不受信任的被调用方可以把转发给它的 gas 尽可能多地转成自己的 ETH。调用未知合约时，只转发你需要的 gas。\n- 单笔交易中的总支付额以其 gas 上限为界，因此用户不会被无限收费，但钱包需要清楚地展示这一成本。\n"}}}
