{"eip":7778,"title":"Block Gas Accounting without Refunds","description":"Prevent Block Gas Limit Circumvention by Excluding Refunds from Block Gas Accounting","authors":["Ben Adams (@benaadams)","Toni Wahrstätter (@nerolation)"],"status":"Last Call","type":"Standards Track","category":"Core","created":"2024-10-01","discussionsTo":"https://ethereum-magicians.org/t/eip-7778-prevent-block-gas-smuggling/21234","repo":"EIPs","label":"EIP-7778","officialUrl":"https://eips.ethereum.org/EIPS/eip-7778","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7778.md","url":"https://eips.huatuo.xyz/eip-7778/","tldr":{"en":"Stops gas refunds from reducing the gas counted against the block gas limit, so blocks cannot carry more real work than the limit allows, while users still get their refunds.","ja":"ガスの払い戻し（refund）が、ブロックのガスリミットに対してカウントされるガスを減らさないようにする。これによりブロックはリミットが許す以上の実作業を載せられなくなり、ユーザーは引き続き払い戻しを受け取れる。","ko":"가스 환급(refund)이 블록 가스 한도에 계산되는 가스를 줄이지 못하게 해, 블록이 한도가 허용하는 것보다 많은 실제 작업을 담을 수 없게 하면서도 사용자는 여전히 환급을 받는다.","zh":"阻止 gas 退款减少计入区块 gas 上限的 gas，使区块无法携带超出上限允许的实际工作量，同时用户仍然能拿到退款。"},"tags":["gas","refunds","block-limit","core","dos"],"explainers":{"en":{"lang":"en","tldr":"Stops gas refunds from reducing the gas counted against the block gas limit, so blocks cannot carry more real work than the limit allows, while users still get their refunds.","tags":["gas","refunds","block-limit","core","dos"],"related":[7623,3529,2200,1559],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7778/","markdown":"## What problem does it solve?\n\nSome operations, most notably setting a storage slot back to zero with `SSTORE`, earn a **gas refund**. Today that refund is subtracted twice: from what the user pays, and from the gas the transaction counts toward the **block gas limit**.\n\nThe second part is the problem. The block gas limit exists to cap how much computation a block contains. If refunds shrink the counted gas, a block can include more actual work than the limit intends. The spec cites mainnet block `20878522`: 28.5M net gas used, but 4.01M of refunds, so about 32.5M gas of real work in a block whose limit was 30M.\n\nThat gap can be used for oversized blocks and denial-of-service attempts, and makes block processing time less predictable.\n\n## How it works\n\nThe EIP separates what the user pays from what the block counts.\n\n**User side (unchanged):**\n\n```\ngas_spent = max(tx_gas_used - gas_refund, calldata_floor_gas_cost)\n```\n\n**Block side (new):** refunds are not subtracted.\n\n```\nblock.gas_used += max(tx_gas_used, calldata_floor_gas_cost)\n```\n\nThe `calldata_floor_gas_cost` term comes from [EIP-7623](/eip-7623/).\n\nOnly *refunds* are excluded. Discounts that reflect genuinely less work, such as warm storage access or restoring a slot to its original value under net gas metering ([EIP-2200](/eip-2200/)), still count at their discounted cost.\n\n## Sample code\n\nPseudocode for applying a transaction during block building:\n\n```python\ndef apply_transaction(block, tx):\n    result = execute(tx)                      # result.gas_used is before refunds\n    floor = calldata_floor_gas_cost(tx)       # EIP-7623\n\n    # What the sender pays: refunds still apply\n    user_gas = max(result.gas_used - result.gas_refund, floor)\n    charge_sender(tx, user_gas)\n\n    # What counts toward the block gas limit: refunds ignored\n    block_gas = max(result.gas_used, floor)\n    if block.gas_used + block_gas \u003e block.gas_limit:\n        raise InvalidBlock(\"gas limit exceeded\")\n    block.gas_used += block_gas\n```\n\n## Things to know\n\n- **Status: Last Call** (deadline 2026-11-01). It is not yet Final and requires a hard fork to activate.\n- Individual users see no difference in what they pay; refunds work as today.\n- Block builders must change transaction selection. A block that is \"full\" by the old net accounting may exceed the limit under the new rule, so refund-heavy transactions take more block space than before.\n- After the change the header's `gasUsed` is no longer the sum of what users were charged, which matters for tools that assume the two are equal.\n- Refunds were already capped by [EIP-3529](/eip-3529/); this EIP removes their effect on block capacity entirely.\n"},"ja":{"lang":"ja","tldr":"ガスの払い戻し（refund）が、ブロックのガスリミットに対してカウントされるガスを減らさないようにする。これによりブロックはリミットが許す以上の実作業を載せられなくなり、ユーザーは引き続き払い戻しを受け取れる。","tags":["gas","refunds","block-limit","core","dos"],"related":[7623,3529,2200,1559],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7778/","markdown":"## 何を解決するのか\n\n一部の操作、特に `SSTORE` でストレージスロットをゼロに戻す操作は、**ガスの払い戻し**を得られます。現在、この払い戻しは 2 回差し引かれます。ユーザーが支払う額から、そしてトランザクションが**ブロックのガスリミット**に対してカウントするガスからです。\n\n問題なのは 2 つ目です。ブロックのガスリミットは、ブロックに含まれる計算量に上限を設けるためのものです。払い戻しによってカウントされるガスが減ると、ブロックにはリミットの意図より多くの実作業が含まれ得ます。仕様はメインネットのブロック `20878522` を例に挙げています。ネットで使用されたガスは 2,850 万でしたが、払い戻しが 401 万あったため、リミットが 3,000 万のブロックに約 3,250 万ガス分の実作業が入っていたことになります。\n\nこの差は、過大なブロックやサービス拒否（DoS）の試みに使われ得るほか、ブロック処理時間の予測も難しくします。\n\n## 仕組み\n\nこの EIP は、ユーザーが支払う額と、ブロックがカウントする量を分離します。\n\n**ユーザー側（変更なし）:**\n\n```\ngas_spent = max(tx_gas_used - gas_refund, calldata_floor_gas_cost)\n```\n\n**ブロック側（新規）:** 払い戻しは差し引かれません。\n\n```\nblock.gas_used += max(tx_gas_used, calldata_floor_gas_cost)\n```\n\n`calldata_floor_gas_cost` の項は [EIP-7623](/eip-7623/) に由来します。\n\n除外されるのは*払い戻し*だけです。ウォーム状態のストレージアクセスや、ネットガスメータリング（[EIP-2200](/eip-2200/)）でスロットを元の値に戻す場合のように、実際に作業量が少ないことを反映した割引は、割引後のコストでカウントされ続けます。\n\n## サンプルコード\n\nブロック構築中にトランザクションを適用する擬似コード:\n\n```python\ndef apply_transaction(block, tx):\n    result = execute(tx)                      # result.gas_used is before refunds\n    floor = calldata_floor_gas_cost(tx)       # EIP-7623\n\n    # What the sender pays: refunds still apply\n    user_gas = max(result.gas_used - result.gas_refund, floor)\n    charge_sender(tx, user_gas)\n\n    # What counts toward the block gas limit: refunds ignored\n    block_gas = max(result.gas_used, floor)\n    if block.gas_used + block_gas \u003e block.gas_limit:\n        raise InvalidBlock(\"gas limit exceeded\")\n    block.gas_used += block_gas\n```\n\n## 知っておくべきこと\n\n- **ステータス: Last Call**（期限 2026-11-01）。まだ Final ではなく、有効化にはハードフォークが必要です。\n- 個々のユーザーにとって、支払う額に違いはありません。払い戻しは現在と同じように機能します。\n- ブロックビルダーはトランザクションの選択方法を変える必要があります。従来のネット計算では「満杯」のブロックが、新しいルールではリミットを超える可能性があり、払い戻しの多いトランザクションは以前よりブロック容量を多く使います。\n- 変更後は、ヘッダーの `gasUsed` が、ユーザーに課金された額の合計とは一致しなくなります。両者が等しいと仮定しているツールでは問題になります。\n- 払い戻しはすでに [EIP-3529](/eip-3529/) で上限が設けられていましたが、この EIP はブロック容量への影響を完全に取り除きます。\n"},"ko":{"lang":"ko","tldr":"가스 환급(refund)이 블록 가스 한도에 계산되는 가스를 줄이지 못하게 해, 블록이 한도가 허용하는 것보다 많은 실제 작업을 담을 수 없게 하면서도 사용자는 여전히 환급을 받는다.","tags":["gas","refunds","block-limit","core","dos"],"related":[7623,3529,2200,1559],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7778/","markdown":"## 어떤 문제를 해결하나요?\n\n일부 연산, 그중에서도 `SSTORE`로 스토리지 슬롯을 0으로 되돌리는 연산은 **가스 환급**을 받습니다. 현재 이 환급은 두 번 차감됩니다. 사용자가 내는 금액에서 한 번, 그리고 트랜잭션이 **블록 가스 한도**에 산입하는 가스에서 한 번입니다.\n\n문제는 두 번째입니다. 블록 가스 한도는 블록에 담기는 연산량의 상한을 두기 위한 것입니다. 환급이 산입되는 가스를 줄이면 블록은 한도가 의도한 것보다 많은 실제 작업을 담을 수 있습니다. 명세는 메인넷 블록 `20878522`를 예로 듭니다. 순 사용 가스는 2,850만이었지만 환급이 401만이었으므로, 한도가 3,000만인 블록에 약 3,250만 가스의 실제 작업이 들어간 셈입니다.\n\n이 차이는 지나치게 큰 블록이나 서비스 거부 공격 시도에 쓰일 수 있고, 블록 처리 시간을 예측하기도 어렵게 만듭니다.\n\n## 어떻게 동작하나요?\n\n이 EIP는 사용자가 내는 금액과 블록이 계산하는 양을 분리합니다.\n\n**사용자 쪽(변경 없음):**\n\n```\ngas_spent = max(tx_gas_used - gas_refund, calldata_floor_gas_cost)\n```\n\n**블록 쪽(신규):** 환급을 차감하지 않습니다.\n\n```\nblock.gas_used += max(tx_gas_used, calldata_floor_gas_cost)\n```\n\n`calldata_floor_gas_cost` 항은 [EIP-7623](/eip-7623/)에서 가져온 것입니다.\n\n제외되는 것은 *환급*뿐입니다. 웜 스토리지 접근이나 순 가스 계량([EIP-2200](/eip-2200/))에서 슬롯을 원래 값으로 복원하는 경우처럼 실제로 작업량이 적음을 반영하는 할인은 여전히 할인된 비용으로 계산됩니다.\n\n## 샘플 코드\n\n블록을 구성하는 동안 트랜잭션을 적용하는 의사 코드:\n\n```python\ndef apply_transaction(block, tx):\n    result = execute(tx)                      # result.gas_used is before refunds\n    floor = calldata_floor_gas_cost(tx)       # EIP-7623\n\n    # What the sender pays: refunds still apply\n    user_gas = max(result.gas_used - result.gas_refund, floor)\n    charge_sender(tx, user_gas)\n\n    # What counts toward the block gas limit: refunds ignored\n    block_gas = max(result.gas_used, floor)\n    if block.gas_used + block_gas \u003e block.gas_limit:\n        raise InvalidBlock(\"gas limit exceeded\")\n    block.gas_used += block_gas\n```\n\n## 알아둘 점\n\n- **상태: Last Call**(기한 2026-11-01). 아직 Final이 아니며 활성화하려면 하드 포크가 필요합니다.\n- 개별 사용자가 내는 금액에는 차이가 없습니다. 환급은 지금처럼 동작합니다.\n- 블록 빌더는 트랜잭션 선택 방식을 바꿔야 합니다. 기존의 순 계산으로는 \"가득 찬\" 블록이 새 규칙에서는 한도를 넘을 수 있으므로, 환급이 많은 트랜잭션은 이전보다 더 많은 블록 공간을 차지합니다.\n- 변경 후에는 헤더의 `gasUsed`가 더 이상 사용자에게 청구된 금액의 합과 같지 않으며, 둘이 같다고 가정하는 도구에서 문제가 됩니다.\n- 환급은 이미 [EIP-3529](/eip-3529/)로 상한이 정해져 있었고, 이 EIP는 블록 용량에 미치는 영향을 완전히 없앱니다.\n"},"zh":{"lang":"zh","tldr":"阻止 gas 退款减少计入区块 gas 上限的 gas，使区块无法携带超出上限允许的实际工作量，同时用户仍然能拿到退款。","tags":["gas","refunds","block-limit","core","dos"],"related":[7623,3529,2200,1559],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7778/","markdown":"## 它解决什么问题？\n\n有些操作，最典型的是用 `SSTORE` 把存储槽重置为零，会获得 **gas 退款**。目前这笔退款被扣了两次：一次从用户支付的费用中扣除，另一次从该交易计入**区块 gas 上限**的 gas 中扣除。\n\n问题出在第二次。区块 gas 上限的作用是限制一个区块所包含的计算量。如果退款缩减了被计入的 gas，区块就可能包含比上限本意更多的实际工作。规范引用了主网区块 `20878522`：净使用 gas 为 2850 万，但退款有 401 万，所以在上限为 3000 万的区块里实际工作量约为 3250 万 gas。\n\n这个差距可能被用来制造超大区块和拒绝服务攻击，也让区块处理时间更难预测。\n\n## 它如何运作\n\n该 EIP 把用户支付的部分与区块计入的部分分开。\n\n**用户侧（不变）：**\n\n```\ngas_spent = max(tx_gas_used - gas_refund, calldata_floor_gas_cost)\n```\n\n**区块侧（新）：**不扣除退款。\n\n```\nblock.gas_used += max(tx_gas_used, calldata_floor_gas_cost)\n```\n\n`calldata_floor_gas_cost` 这一项来自 [EIP-7623](/eip-7623/)。\n\n只有*退款*被排除在外。真正反映工作量减少的折扣，例如热存储访问，或在净 gas 计量（[EIP-2200](/eip-2200/)）下把某个槽恢复为原始值，仍然按折后成本计入。\n\n## 示例代码\n\n构建区块时应用一笔交易的伪代码：\n\n```python\ndef apply_transaction(block, tx):\n    result = execute(tx)                      # result.gas_used is before refunds\n    floor = calldata_floor_gas_cost(tx)       # EIP-7623\n\n    # What the sender pays: refunds still apply\n    user_gas = max(result.gas_used - result.gas_refund, floor)\n    charge_sender(tx, user_gas)\n\n    # What counts toward the block gas limit: refunds ignored\n    block_gas = max(result.gas_used, floor)\n    if block.gas_used + block_gas \u003e block.gas_limit:\n        raise InvalidBlock(\"gas limit exceeded\")\n    block.gas_used += block_gas\n```\n\n## 需要注意\n\n- **状态：Last Call**（截止日期 2026-11-01）。尚未 Final，激活需要一次硬分叉。\n- 单个用户支付的费用没有任何区别；退款与现在一样生效。\n- 区块构建者必须改变交易选择方式。按旧的净额计算\"已满\"的区块，在新规则下可能超过上限，因此退款多的交易会比以前占用更多区块空间。\n- 变更之后，区块头中的 `gasUsed` 不再等于用户被收取的费用之和，这对假定两者相等的工具有影响。\n- 退款此前已被 [EIP-3529](/eip-3529/) 设置了上限；本 EIP 则彻底消除了退款对区块容量的影响。\n"}},"requiredBy":[3298,7782,8007,8141]}
