{"eip":3978,"title":"Gas refunds on reverts","description":"Reprice reverted SSTORE/CREATE/SELFDESTRUCT/LOGX operations gas via gas refund mechanism","authors":["Anton Bukov (@k06a)","Mikhail Melnik (@ZumZoom)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2021-09-16","requires":[2929],"discussionsTo":"https://ethereum-magicians.org/t/eip-3978-gas-refunds-on-reverts/7071/","repo":"EIPs","label":"EIP-3978","officialUrl":"https://eips.ethereum.org/EIPS/eip-3978","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3978.md","url":"https://eips.huatuo.xyz/eip-3978/","tldr":{"en":"Proposed that when a call reverts, users get back the gas paid for state changes that were thrown away (storage writes, logs, contract creation), keeping only the cost of access.","ja":"呼び出しが revert したとき、破棄されたステート変更（ストレージ書き込み、ログ、コントラクト作成）に支払ったガスをユーザーに返し、アクセスのコストだけを残す提案。","ko":"호출이 revert될 때, 버려진 상태 변경(스토리지 쓰기, 로그, 컨트랙트 생성)에 대해 지불한 가스를 사용자에게 돌려주고 접근 비용만 남기자는 제안.","zh":"提议当调用回滚（revert）时，把为被丢弃的状态变更（存储写入、日志、合约创建）所支付的 gas 退还给用户，只保留访问成本。"},"tags":["gas","refunds","revert","evm","core"],"explainers":{"en":{"lang":"en","tldr":"Proposed that when a call reverts, users get back the gas paid for state changes that were thrown away (storage writes, logs, contract creation), keeping only the cost of access.","tags":["gas","refunds","revert","evm","core"],"related":[2929,3298,3529],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-3978/","markdown":"## What problem does it solve?\n\nWhen a transaction or a sub-call reverts, every state change it made is discarded. But the gas for those changes has already been charged as if they had persisted: a reverted `SSTORE` still costs the full write price, a reverted `CREATE` still costs 32,000 gas, and so on.\n\nWorse, a revert also wipes out any gas refund the call had accumulated. The authors point out that it can be cheaper to undo work manually (for example, transfer tokens back) than to revert, just to keep the refund. That is the opposite of what a well-designed fee schedule should encourage.\n\n## How it works\n\nEach call frame tracks a new counter, `revert_gas_refund`, starting at 0. Whenever one of these state-modifying operations runs, the counter grows by the operation's cost minus the warm-read cost (`WARM_STORAGE_READ_COST`, 100 gas, from [EIP-2929](/eip-2929/)):\n\n- `SSTORE`\n- `LOG0` to `LOG4`\n- `CALL` (the value-transfer and new-account surcharges)\n- `CREATE`, `CREATE2`\n- `SELFDESTRUCT`\n\nIf the frame reverts, the existing behaviour (dropping that frame's normal refund) still happens, and then `revert_gas_refund` is credited to the transaction's refund. The net effect is that a reverted modification costs roughly what a read costs, about 100 gas, instead of its full price.\n\nThe motivation also suggests charging `CREATE`/`CREATE2`'s 32,000 gas only when the returned bytecode is non-empty, though the specification section does not define this.\n\n## Sample code\n\nPseudocode of the accounting, adapted from the spec:\n\n```javascript\n// on each SSTORE / LOGx / CALL / CREATE / CREATE2 / SELFDESTRUCT\ncall.revert_gas_refund += operation.gas - WARM_STORAGE_READ_COST; // 100\n\n// when a call frame finishes\nif (call.reverted) {\n  tx.gas_refund -= call.gas_refund;        // existing behaviour\n  tx.gas_refund += call.revert_gas_refund; // new: refund discarded modifications\n}\n```\n\n## Things to know\n\n- Status: **Stagnant**. It was not adopted; reverted operations are still charged in full on Ethereum.\n- Test cases, reference implementation and security considerations were left as \"TBD\" in the spec.\n- Refunds on Ethereum are capped as a fraction of gas used ([EIP-3529](/eip-3529/) tightened this and removed most refund sources), so any revert refund would be subject to that cap as written.\n- Related history: [EIP-3298](/eip-3298/) proposed removing refunds; EIP-3529 is what shipped in London.\n"},"ja":{"lang":"ja","tldr":"呼び出しが revert したとき、破棄されたステート変更（ストレージ書き込み、ログ、コントラクト作成）に支払ったガスをユーザーに返し、アクセスのコストだけを残す提案。","tags":["gas","refunds","revert","evm","core"],"related":[2929,3298,3529],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-3978/","markdown":"## 何を解決するのか\n\nトランザクションやサブコールが revert すると、それが行ったすべてのステート変更は破棄されます。しかし、それらの変更に対するガスは、あたかも保持されたかのようにすでに課金されています。revert された `SSTORE` でも書き込みの満額がかかり、revert された `CREATE` でも 32,000 ガスがかかる、という具合です。\n\nさらに悪いことに、revert は、その呼び出しが積み上げたガス返金もすべて消し去ります。著者らは、返金を守るためだけに、revert するよりも手作業で処理を巻き戻す（たとえばトークンを送り返す）ほうが安くなりうることを指摘しています。これは、よく設計された手数料体系が促すべきこととは正反対です。\n\n## 仕組み\n\n各コールフレームは、0 から始まる新しいカウンター `revert_gas_refund` を追跡します。次のステートを変更する操作が実行されるたびに、このカウンターは、その操作のコストからウォームな読み取りコスト（[EIP-2929](/eip-2929/) の `WARM_STORAGE_READ_COST`、100 ガス）を引いた分だけ増えます。\n\n- `SSTORE`\n- `LOG0` から `LOG4`\n- `CALL`（value 転送と新規アカウントの追加料金）\n- `CREATE`、`CREATE2`\n- `SELFDESTRUCT`\n\nフレームが revert した場合、既存の挙動（そのフレームの通常の返金を破棄する）は今までどおり行われ、そのうえで `revert_gas_refund` がトランザクションの返金に加算されます。正味の効果として、revert された変更のコストは満額ではなく、読み取りのコストとほぼ同じ、約 100 ガスになります。\n\n動機の節は、`CREATE`/`CREATE2` の 32,000 ガスを、返されたバイトコードが空でない場合にのみ課金することも示唆していますが、仕様の節ではこれは定義されていません。\n\n## サンプルコード\n\n仕様から改変した、会計処理の疑似コード:\n\n```javascript\n// on each SSTORE / LOGx / CALL / CREATE / CREATE2 / SELFDESTRUCT\ncall.revert_gas_refund += operation.gas - WARM_STORAGE_READ_COST; // 100\n\n// when a call frame finishes\nif (call.reverted) {\n  tx.gas_refund -= call.gas_refund;        // existing behaviour\n  tx.gas_refund += call.revert_gas_refund; // new: refund discarded modifications\n}\n```\n\n## 知っておくべきこと\n\n- ステータス: **Stagnant**。採用されず、Ethereum では revert された操作も引き続き満額が課金されます。\n- テストケース、リファレンス実装、セキュリティ上の考慮事項は、仕様では「TBD」のままです。\n- Ethereum の返金は使用ガスの一定割合に上限があり（[EIP-3529](/eip-3529/) がこれを厳しくし、返金の大半の発生源を廃止しました）、revert 時の返金も、書かれているとおりならその上限の対象になります。\n- 関連する経緯: [EIP-3298](/eip-3298/) は返金の廃止を提案し、London で出荷されたのは EIP-3529 です。\n"},"ko":{"lang":"ko","tldr":"호출이 revert될 때, 버려진 상태 변경(스토리지 쓰기, 로그, 컨트랙트 생성)에 대해 지불한 가스를 사용자에게 돌려주고 접근 비용만 남기자는 제안.","tags":["gas","refunds","revert","evm","core"],"related":[2929,3298,3529],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-3978/","markdown":"## 어떤 문제를 해결하나요?\n\n트랜잭션이나 하위 호출이 revert되면 그것이 만든 모든 상태 변경은 버려집니다. 하지만 그 변경에 대한 가스는 마치 유지된 것처럼 이미 부과된 상태입니다. revert된 `SSTORE`도 쓰기 전체 가격을 치르고, revert된 `CREATE`도 32,000 가스를 치르는 식입니다.\n\n더 나쁜 점은 revert가 그 호출이 쌓아 둔 가스 환급도 모두 지워 버린다는 것입니다. 작성자들은 환급을 지키려고 revert하는 것보다 수작업으로 작업을 되돌리는 편(예: 토큰을 도로 전송)이 더 쌀 수 있다고 지적합니다. 이는 잘 설계된 수수료 체계가 장려해야 할 것과 정반대입니다.\n\n## 어떻게 동작하나요?\n\n각 호출 프레임은 0에서 시작하는 새 카운터 `revert_gas_refund`를 추적합니다. 다음 상태 변경 연산 중 하나가 실행될 때마다 카운터는 그 연산의 비용에서 warm 읽기 비용([EIP-2929](/eip-2929/)의 `WARM_STORAGE_READ_COST`, 100 가스)을 뺀 만큼 증가합니다.\n\n- `SSTORE`\n- `LOG0`부터 `LOG4`까지\n- `CALL`(value 전송과 새 계정 추가 요금)\n- `CREATE`, `CREATE2`\n- `SELFDESTRUCT`\n\n프레임이 revert되면 기존 동작(해당 프레임의 일반 환급을 버림)은 그대로 일어나고, 그다음 `revert_gas_refund`가 트랜잭션의 환급에 더해집니다. 결과적으로 revert된 변경은 전체 가격 대신 읽기 비용과 비슷한 약 100 가스만 듭니다.\n\n동기 부분에서는 `CREATE`/`CREATE2`의 32,000 가스를 반환된 바이트코드가 비어 있지 않을 때만 부과하자는 제안도 하지만, 명세 절에서는 이를 정의하지 않습니다.\n\n## 샘플 코드\n\n명세에서 가져와 다듬은 회계 처리 의사 코드:\n\n```javascript\n// on each SSTORE / LOGx / CALL / CREATE / CREATE2 / SELFDESTRUCT\ncall.revert_gas_refund += operation.gas - WARM_STORAGE_READ_COST; // 100\n\n// when a call frame finishes\nif (call.reverted) {\n  tx.gas_refund -= call.gas_refund;        // existing behaviour\n  tx.gas_refund += call.revert_gas_refund; // new: refund discarded modifications\n}\n```\n\n## 알아둘 점\n\n- 상태: **Stagnant**. 채택되지 않았으며, 이더리움에서 revert된 연산은 여전히 전액이 부과됩니다.\n- 테스트 케이스, 레퍼런스 구현, 보안 고려 사항은 명세에서 \"TBD\"로 남아 있습니다.\n- 이더리움의 환급은 사용한 가스의 일정 비율로 상한이 있어([EIP-3529](/eip-3529/)가 이를 더 조이고 대부분의 환급 원천을 없앴습니다), 명세에 쓰인 대로라면 revert 환급도 그 상한의 적용을 받습니다.\n- 관련 역사: [EIP-3298](/eip-3298/)은 환급 폐지를 제안했고, London에서 출시된 것은 EIP-3529입니다.\n"},"zh":{"lang":"zh","tldr":"提议当调用回滚（revert）时，把为被丢弃的状态变更（存储写入、日志、合约创建）所支付的 gas 退还给用户，只保留访问成本。","tags":["gas","refunds","revert","evm","core"],"related":[2929,3298,3529],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-3978/","markdown":"## 它解决什么问题？\n\n当一笔交易或子调用 revert 时，它做出的所有状态变更都会被丢弃。但这些变更的 gas 已经按它们被保留下来的情形收取了：被 revert 的 `SSTORE` 仍然要付完整的写入价格，被 revert 的 `CREATE` 仍然要付 32,000 gas，等等。\n\n更糟的是，revert 还会抹掉该调用已累积的任何 gas 退款。作者们指出，为了保住退款，手动撤销操作（例如把代币转回去）有时比 revert 更便宜。这与设计良好的费用表应当鼓励的行为恰恰相反。\n\n## 它如何运作\n\n每个调用帧都会跟踪一个新的计数器 `revert_gas_refund`，初始为 0。每当执行下面这些修改状态的操作之一时，该计数器就增加该操作的成本减去热读取成本（`WARM_STORAGE_READ_COST`，100 gas，来自 [EIP-2929](/eip-2929/)）：\n\n- `SSTORE`\n- `LOG0` 到 `LOG4`\n- `CALL`（转账和新账户附加费）\n- `CREATE`、`CREATE2`\n- `SELFDESTRUCT`\n\n如果该帧 revert，现有行为（丢弃该帧的常规退款）仍会发生，然后 `revert_gas_refund` 会被记入交易的退款。净效果是，一次被 revert 的修改大致只花费一次读取的成本，约 100 gas，而不是其全价。\n\n动机部分还建议只在返回的字节码非空时，才收取 `CREATE`/`CREATE2` 的 32,000 gas，不过规范部分并未对此作出定义。\n\n## 示例代码\n\n改编自规范的会计处理伪代码：\n\n```javascript\n// on each SSTORE / LOGx / CALL / CREATE / CREATE2 / SELFDESTRUCT\ncall.revert_gas_refund += operation.gas - WARM_STORAGE_READ_COST; // 100\n\n// when a call frame finishes\nif (call.reverted) {\n  tx.gas_refund -= call.gas_refund;        // existing behaviour\n  tx.gas_refund += call.revert_gas_refund; // new: refund discarded modifications\n}\n```\n\n## 需要注意\n\n- 状态：**Stagnant**。它没有被采纳；在以太坊上，被 revert 的操作仍然全额收费。\n- 测试用例、参考实现和安全考量在规范中都留作“TBD”。\n- 以太坊上的退款有按已用 gas 一定比例设定的上限（[EIP-3529](/eip-3529/) 收紧了这一点，并取消了大部分退款来源），因此按规范所写，任何 revert 退款都将受该上限约束。\n- 相关历史：[EIP-3298](/eip-3298/) 提议取消退款；在 London 中上线的是 EIP-3529。\n"}}}
