{"eip":2200,"title":"Structured Definitions for Net Gas Metering","description":"This is an EIP that implements net gas metering. It's a combined version of [EIP-1283] and [EIP-1706], with a structured definition so as to make it interoperable with other gas changes such as [EIP-1884].","authors":["Wei Tang (@sorpaas)"],"status":"Final","type":"Standards Track","category":"Core","created":"2019-07-18","discussionsTo":"https://github.com/sorpaas/EIPs/issues/1","repo":"EIPs","label":"EIP-2200","officialUrl":"https://eips.ethereum.org/EIPS/eip-2200","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2200.md","url":"https://eips.huatuo.xyz/eip-2200/","tldr":{"en":"The net gas metering rules for SSTORE that went live in Istanbul: repeated writes to the same slot in a transaction are cheap, with refunds for restoring values and a stipend guard against reentrancy.","ja":"Istanbul で稼働した SSTORE のネットガスメータリング規則。同一トランザクション内で同じスロットへ繰り返し書き込むコストが安くなり、値を元に戻すとリファンドが得られ、リエントランシー対策としてスタイペンドのガードが設けられている。","ko":"Istanbul에서 적용된 SSTORE의 순 가스 계량 규칙. 한 트랜잭션 안에서 같은 슬롯에 반복해서 쓰는 비용이 저렴하고, 값을 되돌리면 환급을 받으며, 재진입을 막기 위한 스타이펜드 가드가 있다.","zh":"在 Istanbul 中上线的 SSTORE 净 gas 计量规则：同一交易内对同一槽位的重复写入很便宜，恢复原值可获得退款，并设有补贴额度（stipend）检查以防范重入。"},"tags":["gas","sstore","storage","core","istanbul"],"explainers":{"en":{"lang":"en","tldr":"The net gas metering rules for SSTORE that went live in Istanbul: repeated writes to the same slot in a transaction are cheap, with refunds for restoring values and a stipend guard against reentrancy.","tags":["gas","sstore","storage","core","istanbul"],"related":[1283,1706,1884,2929,3529],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-2200/","markdown":"## What problem does it solve?\n\nWriting a storage slot used to cost a full 5,000 or 20,000 gas every time, even if the same slot was written several times in one transaction. Reentrancy locks, counters and values passed between call frames all paid far more than the work clients actually did.\n\n[EIP-1283](/eip-1283/) fixed that with \"net gas metering\" but was pulled from Constantinople: a write to an already-changed slot cost only 200 gas, which fits inside the 2,300 gas stipend that Solidity's `transfer`/`send` gives the recipient. Contracts that relied on \"the stipend is too small to change state\" could become reentrant.\n\nEIP-2200 combines EIP-1283 with [EIP-1706](/eip-1706/)'s fix and rewrites the rules with named parameters so later repricings can plug in cleanly. It shipped in Istanbul (December 2019).\n\n## How it works\n\nParameters at Istanbul:\n\n| Name | Value |\n| --- | --- |\n| `SLOAD_GAS` | 800 (raised from 200, matching [EIP-1884](/eip-1884/)) |\n| `SSTORE_SET_GAS` | 20,000 |\n| `SSTORE_RESET_GAS` | 5,000 |\n| `SSTORE_CLEARS_SCHEDULE` | 15,000 |\n\nFor each `SSTORE`, using the slot's *original* value (start of transaction), *current* value and *new* value:\n\n0. If gas left ≤ 2,300 (the call stipend), fail with out-of-gas. This is the reentrancy guard.\n1. `current == new` (no-op): charge `SLOAD_GAS`.\n2. `original == current` (first change): charge `SSTORE_SET_GAS` if original is 0, else `SSTORE_RESET_GAS` (and refund `SSTORE_CLEARS_SCHEDULE` if new is 0).\n3. Otherwise the slot is dirty: charge `SLOAD_GAS` and adjust refunds: undo or grant the clear refund as the value moves to or from 0, and if `new == original` refund `SET_GAS − SLOAD_GAS` or `RESET_GAS − SLOAD_GAS`.\n\n## Sample code\n\nThe Istanbul rule as Python-style pseudocode:\n\n```python\nSLOAD_GAS, SET, RESET, CLEARS = 800, 20000, 5000, 15000\nSTIPEND = 2300\n\ndef sstore(gasleft, original, current, new, refund):\n    if gasleft \u003c= STIPEND:\n        raise OutOfGas()\n    if current == new:\n        return SLOAD_GAS, refund\n    if original == current:\n        if original == 0:\n            return SET, refund\n        if new == 0:\n            refund += CLEARS\n        return RESET, refund\n    if original != 0:\n        if current == 0:\n            refund -= CLEARS\n        if new == 0:\n            refund += CLEARS\n    if original == new:\n        refund += (SET - SLOAD_GAS) if original == 0 else (RESET - SLOAD_GAS)\n    return SLOAD_GAS, refund\n```\n\n## Things to know\n\n- Status is **Final** and it is the basis of today's `SSTORE` pricing, but the numbers have moved on. [EIP-2929](/eip-2929/) (Berlin) folded in cold/warm access costs, and [EIP-3529](/eip-3529/) (London) cut `SSTORE_CLEARS_SCHEDULE` to 4,800 and capped total refunds at one fifth of gas used.\n- The structure (no-op / fresh / dirty, original vs current value) is unchanged, which is exactly why the spec switched to named parameters.\n- Gas estimation must account for the stipend check: any `SSTORE` needs more than 2,300 gas left, even if the write itself is cheap.\n- Refunds are paid at the end of the transaction, not when the `SSTORE` runs.\n"},"ja":{"lang":"ja","tldr":"Istanbul で稼働した SSTORE のネットガスメータリング規則。同一トランザクション内で同じスロットへ繰り返し書き込むコストが安くなり、値を元に戻すとリファンドが得られ、リエントランシー対策としてスタイペンドのガードが設けられている。","tags":["gas","sstore","storage","core","istanbul"],"related":[1283,1706,1884,2929,3529],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-2200/","markdown":"## 何を解決するのか\n\nかつてストレージスロットへの書き込みは、同じトランザクション内で同じスロットに何度書いても毎回 5,000 または 20,000 ガスかかっていました。リエントランシーロック、カウンター、コールフレーム間で受け渡す値は、クライアントが実際に行う作業よりはるかに多く支払っていました。\n\n[EIP-1283](/eip-1283/) は「ネットガスメータリング」でこれを解決しましたが、Constantinople から取り下げられました。すでに変更されたスロットへの書き込みが 200 ガスしかかからず、Solidity の `transfer`/`send` が受信側に渡す 2,300 ガスのスタイペンドに収まってしまうためです。「スタイペンドは小さすぎて状態を変更できない」ことに依存していたコントラクトが、リエントラントになりうる状態でした。\n\nEIP-2200 は EIP-1283 と [EIP-1706](/eip-1706/) の修正を組み合わせ、後の価格見直しをきれいに差し込めるよう、名前付きパラメーターで規則を書き直したものです。Istanbul（2019 年 12 月）で稼働しました。\n\n## 仕組み\n\nIstanbul 時点のパラメーター:\n\n| 名前 | 値 |\n| --- | --- |\n| `SLOAD_GAS` | 800（200 から引き上げ、[EIP-1884](/eip-1884/) に合わせたもの） |\n| `SSTORE_SET_GAS` | 20,000 |\n| `SSTORE_RESET_GAS` | 5,000 |\n| `SSTORE_CLEARS_SCHEDULE` | 15,000 |\n\n各 `SSTORE` について、スロットの*元の*値（トランザクション開始時）、*現在の*値、*新しい*値を使います。\n\n0. 残りガスが 2,300（コールスタイペンド）以下なら、ガス不足で失敗します。これがリエントランシーのガードです。\n1. `current == new`（何も変わらない）: `SLOAD_GAS` を課金します。\n2. `original == current`（最初の変更）: original が 0 なら `SSTORE_SET_GAS`、そうでなければ `SSTORE_RESET_GAS` を課金します（new が 0 なら `SSTORE_CLEARS_SCHEDULE` をリファンドします）。\n3. それ以外はスロットが dirty な状態です。`SLOAD_GAS` を課金し、リファンドを調整します。値が 0 になる、または 0 から戻るのに応じてクリアのリファンドを取り消す、または付与します。`new == original` なら `SET_GAS − SLOAD_GAS` または `RESET_GAS − SLOAD_GAS` をリファンドします。\n\n## サンプルコード\n\nIstanbul の規則を Python 風の擬似コードで示します。\n\n```python\nSLOAD_GAS, SET, RESET, CLEARS = 800, 20000, 5000, 15000\nSTIPEND = 2300\n\ndef sstore(gasleft, original, current, new, refund):\n    if gasleft \u003c= STIPEND:\n        raise OutOfGas()\n    if current == new:\n        return SLOAD_GAS, refund\n    if original == current:\n        if original == 0:\n            return SET, refund\n        if new == 0:\n            refund += CLEARS\n        return RESET, refund\n    if original != 0:\n        if current == 0:\n            refund -= CLEARS\n        if new == 0:\n            refund += CLEARS\n    if original == new:\n        refund += (SET - SLOAD_GAS) if original == 0 else (RESET - SLOAD_GAS)\n    return SLOAD_GAS, refund\n```\n\n## 知っておくべきこと\n\n- ステータスは **Final** で、現在の `SSTORE` 価格設定の基礎ですが、数値は変わっています。[EIP-2929](/eip-2929/)（Berlin）がコールド/ウォームのアクセスコストを取り込み、[EIP-3529](/eip-3529/)（London）が `SSTORE_CLEARS_SCHEDULE` を 4,800 に引き下げ、リファンドの合計を使用ガスの 5 分の 1 に制限しました。\n- 構造（何も変わらない/初回/dirty、元の値と現在の値）は変わっていません。仕様が名前付きパラメーターに切り替えた理由はまさにそこにあります。\n- ガス見積もりではスタイペンドのチェックを考慮する必要があります。書き込み自体が安くても、どの `SSTORE` にも 2,300 ガスを超える残りが必要です。\n- リファンドは `SSTORE` の実行時ではなく、トランザクションの終了時に支払われます。\n"},"ko":{"lang":"ko","tldr":"Istanbul에서 적용된 SSTORE의 순 가스 계량 규칙. 한 트랜잭션 안에서 같은 슬롯에 반복해서 쓰는 비용이 저렴하고, 값을 되돌리면 환급을 받으며, 재진입을 막기 위한 스타이펜드 가드가 있다.","tags":["gas","sstore","storage","core","istanbul"],"related":[1283,1706,1884,2929,3529],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-2200/","markdown":"## 어떤 문제를 해결하나요?\n\n스토리지 슬롯에 쓰는 데는 한 트랜잭션에서 같은 슬롯에 여러 번 쓰더라도 매번 5,000 또는 20,000 가스가 들었습니다. 재진입 잠금, 카운터, 호출 프레임 사이에 전달되는 값은 클라이언트가 실제로 하는 작업보다 훨씬 많은 비용을 냈습니다.\n\n[EIP-1283](/eip-1283/)은 \"순 가스 계량(net gas metering)\"으로 이를 해결했지만 Constantinople에서 철회되었습니다. 이미 변경된 슬롯에 쓰는 비용이 200 가스에 불과해, Solidity의 `transfer`/`send`가 수신자에게 주는 2,300 가스 스타이펜드 안에 들어가기 때문입니다. \"스타이펜드는 너무 작아서 상태를 바꿀 수 없다\"는 점에 의존하던 컨트랙트가 재진입에 취약해질 수 있었습니다.\n\nEIP-2200은 EIP-1283과 [EIP-1706](/eip-1706/)의 수정을 합치고, 이후의 가격 조정이 깔끔하게 들어갈 수 있도록 이름 있는 매개변수로 규칙을 다시 썼습니다. Istanbul(2019년 12월)에 적용되었습니다.\n\n## 어떻게 동작하나요?\n\nIstanbul 시점의 매개변수:\n\n| 이름 | 값 |\n| --- | --- |\n| `SLOAD_GAS` | 800(200에서 상향, [EIP-1884](/eip-1884/)와 일치) |\n| `SSTORE_SET_GAS` | 20,000 |\n| `SSTORE_RESET_GAS` | 5,000 |\n| `SSTORE_CLEARS_SCHEDULE` | 15,000 |\n\n각 `SSTORE`마다 슬롯의 *원래* 값(트랜잭션 시작 시점), *현재* 값, *새* 값을 사용합니다.\n\n0. 남은 가스가 2,300(호출 스타이펜드) 이하이면 가스 부족으로 실패합니다. 이것이 재진입 방어 장치입니다.\n1. `current == new`(변화 없음): `SLOAD_GAS`를 부과합니다.\n2. `original == current`(첫 변경): original이 0이면 `SSTORE_SET_GAS`, 아니면 `SSTORE_RESET_GAS`를 부과합니다(new가 0이면 `SSTORE_CLEARS_SCHEDULE`을 환급합니다).\n3. 그 외에는 슬롯이 dirty 상태입니다. `SLOAD_GAS`를 부과하고 환급을 조정합니다. 값이 0이 되거나 0에서 벗어나는 데 따라 삭제 환급을 취소하거나 부여하며, `new == original`이면 `SET_GAS − SLOAD_GAS` 또는 `RESET_GAS − SLOAD_GAS`를 환급합니다.\n\n## 샘플 코드\n\nIstanbul 규칙을 Python 스타일 의사 코드로 나타냈습니다.\n\n```python\nSLOAD_GAS, SET, RESET, CLEARS = 800, 20000, 5000, 15000\nSTIPEND = 2300\n\ndef sstore(gasleft, original, current, new, refund):\n    if gasleft \u003c= STIPEND:\n        raise OutOfGas()\n    if current == new:\n        return SLOAD_GAS, refund\n    if original == current:\n        if original == 0:\n            return SET, refund\n        if new == 0:\n            refund += CLEARS\n        return RESET, refund\n    if original != 0:\n        if current == 0:\n            refund -= CLEARS\n        if new == 0:\n            refund += CLEARS\n    if original == new:\n        refund += (SET - SLOAD_GAS) if original == 0 else (RESET - SLOAD_GAS)\n    return SLOAD_GAS, refund\n```\n\n## 알아둘 점\n\n- 상태는 **Final**이며 오늘날 `SSTORE` 가격 책정의 기반이지만, 숫자는 달라졌습니다. [EIP-2929](/eip-2929/)(Berlin)가 콜드/웜 접근 비용을 포함시켰고, [EIP-3529](/eip-3529/)(London)가 `SSTORE_CLEARS_SCHEDULE`을 4,800으로 낮추고 총 환급액을 사용한 가스의 5분의 1로 제한했습니다.\n- 구조(변화 없음/최초/dirty, 원래 값 대 현재 값)는 그대로이며, 바로 그래서 사양이 이름 있는 매개변수로 바뀌었습니다.\n- 가스 추정은 스타이펜드 검사를 고려해야 합니다. 쓰기 자체가 저렴하더라도 모든 `SSTORE`에는 2,300 가스를 넘는 잔여 가스가 필요합니다.\n- 환급은 `SSTORE`가 실행될 때가 아니라 트랜잭션이 끝날 때 지급됩니다.\n"},"zh":{"lang":"zh","tldr":"在 Istanbul 中上线的 SSTORE 净 gas 计量规则：同一交易内对同一槽位的重复写入很便宜，恢复原值可获得退款，并设有补贴额度（stipend）检查以防范重入。","tags":["gas","sstore","storage","core","istanbul"],"related":[1283,1706,1884,2929,3529],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-2200/","markdown":"## 它解决什么问题？\n\n过去写入一个存储槽位每次都要花满 5,000 或 20,000 gas，即使同一笔交易中多次写同一个槽位也是如此。重入锁、计数器以及在调用帧之间传递的值，所付的费用远高于客户端实际做的工作。\n\n[EIP-1283](/eip-1283/) 用\"净 gas 计量\"解决了这个问题，但在 Constantinople 中被撤下：对已经被修改过的槽位再次写入只需 200 gas，这个数额落在 Solidity 的 `transfer`/`send` 给接收方的 2,300 gas 补贴额度之内。依赖\"补贴额度太小，无法改变状态\"的合约可能因此变得可重入。\n\nEIP-2200 把 EIP-1283 与 [EIP-1706](/eip-1706/) 的修复结合起来，并用命名参数重写规则，使后续的重新定价可以干净地接入。它随 Istanbul（2019 年 12 月）上线。\n\n## 它如何运作\n\nIstanbul 时的参数：\n\n| 名称 | 值 |\n| --- | --- |\n| `SLOAD_GAS` | 800（从 200 提高，与 [EIP-1884](/eip-1884/) 一致） |\n| `SSTORE_SET_GAS` | 20,000 |\n| `SSTORE_RESET_GAS` | 5,000 |\n| `SSTORE_CLEARS_SCHEDULE` | 15,000 |\n\n对每次 `SSTORE`，使用槽位的*原始*值（交易开始时）、*当前*值和*新*值：\n\n0. 如果剩余 gas ≤ 2,300（调用补贴额度），则以 out-of-gas 失败。这就是重入防护。\n1. `current == new`（空操作）：收取 `SLOAD_GAS`。\n2. `original == current`（首次修改）：如果 original 为 0，收取 `SSTORE_SET_GAS`，否则收取 `SSTORE_RESET_GAS`（如果 new 为 0，则退还 `SSTORE_CLEARS_SCHEDULE`）。\n3. 否则槽位为 dirty 状态：收取 `SLOAD_GAS` 并调整退款：随着值变为 0 或从 0 变回，撤销或授予清除退款；如果 `new == original`，则退还 `SET_GAS − SLOAD_GAS` 或 `RESET_GAS − SLOAD_GAS`。\n\n## 示例代码\n\nIstanbul 的规则，用 Python 风格的伪代码表示：\n\n```python\nSLOAD_GAS, SET, RESET, CLEARS = 800, 20000, 5000, 15000\nSTIPEND = 2300\n\ndef sstore(gasleft, original, current, new, refund):\n    if gasleft \u003c= STIPEND:\n        raise OutOfGas()\n    if current == new:\n        return SLOAD_GAS, refund\n    if original == current:\n        if original == 0:\n            return SET, refund\n        if new == 0:\n            refund += CLEARS\n        return RESET, refund\n    if original != 0:\n        if current == 0:\n            refund -= CLEARS\n        if new == 0:\n            refund += CLEARS\n    if original == new:\n        refund += (SET - SLOAD_GAS) if original == 0 else (RESET - SLOAD_GAS)\n    return SLOAD_GAS, refund\n```\n\n## 需要注意\n\n- 状态为 **Final**，它是当今 `SSTORE` 定价的基础，但具体数值已经变化。[EIP-2929](/eip-2929/)（Berlin）加入了冷/热访问成本，[EIP-3529](/eip-3529/)（London）把 `SSTORE_CLEARS_SCHEDULE` 降到 4,800，并把退款总额上限设为已用 gas 的五分之一。\n- 结构（空操作/首次/dirty，原始值与当前值）没有变化，这正是规范改用命名参数的原因。\n- gas 估算必须考虑补贴额度检查：任何 `SSTORE` 都需要剩余超过 2,300 gas，即使写入本身很便宜。\n- 退款在交易结束时发放，而不是在 `SSTORE` 执行时。\n"}},"requiredBy":[1153,1679,3529,7377,7519,7973,8125,8358]}
