{"eip":1283,"title":"Net gas metering for SSTORE without dirty maps","description":"This EIP proposes net gas metering changes for SSTORE opcode, enabling new usages for contract storage, and reducing excessive gas costs where it doesn't match how most implementations work.","authors":["Wei Tang (@sorpaas)"],"status":"Final","type":"Standards Track","category":"Core","created":"2018-08-01","discussionsTo":"https://github.com/sorpaas/EIPs/issues/1","repo":"EIPs","label":"EIP-1283","officialUrl":"https://eips.ethereum.org/EIPS/eip-1283","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1283.md","url":"https://eips.huatuo.xyz/eip-1283/","tldr":{"en":"Net gas metering for SSTORE: writing the same storage slot several times in one transaction costs only 200 gas after the first write, with refunds when a slot is restored. Pulled from Constantinople over a reentrancy risk and later reshipped as EIP-2200.","ja":"SSTORE のネットガス計測。1 つのトランザクション内で同じストレージスロットに複数回書き込むと、最初の書き込み以降は 200 gas だけになり、スロットが元に戻されると払い戻しがある。リエントランシーのリスクのため Constantinople から外され、のちに EIP-2200 として再出荷された。","ko":"SSTORE의 순 gas 계량. 한 트랜잭션에서 같은 스토리지 슬롯에 여러 번 쓰면 첫 번째 쓰기 이후에는 200 gas만 들고, 슬롯이 원래 값으로 복원되면 환급이 있다. 재진입 위험 때문에 Constantinople에서 빠졌고 나중에 EIP-2200으로 다시 배포되었다.","zh":"SSTORE 的净 gas 计量：在同一笔交易中多次写入同一个存储槽，首次写入之后每次只需 200 gas，槽被恢复原值时还有退款。因重入风险被撤出 Constantinople，后来以 EIP-2200 重新上线。"},"tags":["gas","sstore","storage","core","constantinople"],"explainers":{"en":{"lang":"en","tldr":"Net gas metering for SSTORE: writing the same storage slot several times in one transaction costs only 200 gas after the first write, with refunds when a slot is restored. Pulled from Constantinople over a reentrancy risk and later reshipped as EIP-2200.","tags":["gas","sstore","storage","core","constantinople"],"related":[2200,1087,1706,1716,1153],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-1283/","markdown":"## What problem does it solve?\n\nBefore this proposal, every `SSTORE` that changed a slot cost 5,000 gas (or 20,000 when setting a zero slot), no matter how many times the slot had already been written in the same transaction. Common patterns paid heavily for that:\n\n- a reentrancy lock set to 1 and back to 0 paid for two full writes,\n- a contract updating a counter several times in one call paid for each write,\n- contracts passing values between call frames via storage paid as if each value were persisted.\n\nClients do not actually write to disk on every `SSTORE`; they commit at the end. EIP-1283 makes gas reflect that, using only information most clients already track: the slot's **original** value (at the start of the transaction) and its **current** value.\n\n## How it works\n\nFor each `SSTORE` compare *original*, *current* and *new* values:\n\n- **No-op** (`current == new`): 200 gas.\n- **Fresh** slot (`original == current`, first change in this transaction):\n  - original is 0: 20,000 gas;\n  - otherwise 5,000 gas, plus a 15,000 refund if new is 0.\n- **Dirty** slot (`original != current`, already changed): 200 gas, and the refund counter is adjusted:\n  - if original ≠ 0 and current is 0, take back the 15,000 clear refund; if new is 0, grant it;\n  - if new == original (slot reset), refund 19,800 (original 0) or 4,800 (original ≠ 0).\n\nExamples from the spec:\n\n- Empty slot set to 1 then back to 0: `20000 + 200 - 19800 = 400` gas.\n- Empty slot incremented 5 times: `20000 + 5 × 200 = 21000` gas.\n\nIt never charges more than the old scheme, and it gives roughly the effect of transient storage without a separate \"dirty map\".\n\n## Sample code\n\nThe cost rule as Python-style pseudocode:\n\n```python\ndef sstore_cost(original, current, new, refund):\n    if current == new:\n        return 200, refund\n    if original == current:\n        if original == 0:\n            return 20000, refund\n        if new == 0:\n            refund += 15000\n        return 5000, refund\n    # dirty slot\n    if original != 0:\n        if current == 0:\n            refund -= 15000\n        if new == 0:\n            refund += 15000\n    if original == new:\n        refund += 19800 if original == 0 else 4800\n    return 200, refund\n```\n\n## Things to know\n\n- EIP-1283 was scheduled for Constantinople but was pulled just before activation after a reentrancy issue was found: a dirty-slot `SSTORE` costing 200 gas fits inside the 2,300 gas stipend of Solidity's `transfer`/`send`, which existing contracts assumed was too little to change state. The [Petersburg](/eip-1716/) upgrade removed it from the fork.\n- Its status reads **Final**, but it is not active on mainnet in this form. The same logic shipped in Istanbul as [EIP-2200](/eip-2200/), combined with [EIP-1706](/eip-1706/)'s rule that `SSTORE` fails if gas left is at or below the stipend.\n- Refund numbers changed again later; see EIP-2200 for the current lineage. For truly temporary values, [EIP-1153](/eip-1153/) transient storage is now the purpose-built tool.\n"},"ja":{"lang":"ja","tldr":"SSTORE のネットガス計測。1 つのトランザクション内で同じストレージスロットに複数回書き込むと、最初の書き込み以降は 200 gas だけになり、スロットが元に戻されると払い戻しがある。リエントランシーのリスクのため Constantinople から外され、のちに EIP-2200 として再出荷された。","tags":["gas","sstore","storage","core","constantinople"],"related":[2200,1087,1706,1716,1153],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-1283/","markdown":"## 何を解決するのか\n\nこの提案以前は、スロットを変更する `SSTORE` は、同じトランザクション内でそのスロットがすでに何回書き込まれていても、1 回あたり 5,000 gas（ゼロのスロットに設定する場合は 20,000 gas）かかっていました。一般的なパターンは、そのせいで大きな負担を強いられていました。\n\n- リエントランシーロックを 1 にして 0 に戻すと、フルの書き込み 2 回分を支払っていた\n- 1 回の呼び出しでカウンターを何度も更新するコントラクトは、書き込みのたびに支払っていた\n- ストレージを介して呼び出しフレーム間で値を受け渡すコントラクトは、各値が永続化されるかのように支払っていた\n\nクライアントは、実際には `SSTORE` のたびにディスクへ書き込むわけではなく、最後にコミットします。EIP-1283 は、ガスにそれを反映させます。使うのは、ほとんどのクライアントがすでに追跡している情報だけ、つまりスロットの**元の**値（トランザクション開始時点）と**現在の**値です。\n\n## 仕組み\n\n各 `SSTORE` で、*元の*値、*現在の*値、*新しい*値を比較します。\n\n- **何もしない**（`current == new`）: 200 gas。\n- **新しい**スロット（`original == current`、このトランザクションで最初の変更）:\n  - 元の値が 0: 20,000 gas。\n  - それ以外は 5,000 gas。新しい値が 0 なら 15,000 の払い戻しが加わる。\n- **変更済み**スロット（`original != current`、すでに変更済み）: 200 gas。払い戻しカウンターが調整される。\n  - 元の値が 0 以外で現在の値が 0 の場合、クリアの払い戻し 15,000 を取り消す。新しい値が 0 なら、それを付与する。\n  - 新しい値が元の値と同じ（スロットのリセット）なら、19,800（元の値が 0）または 4,800（元の値が 0 以外）を払い戻す。\n\n仕様書の例:\n\n- 空のスロットを 1 にして 0 に戻す: `20000 + 200 - 19800 = 400` gas。\n- 空のスロットを 5 回インクリメントする: `20000 + 5 × 200 = 21000` gas。\n\n従来の方式より多く課金することはなく、別個の「dirty map」なしで、一時ストレージとほぼ同じ効果が得られます。\n\n## サンプルコード\n\nコストのルールを Python 風の疑似コードで示します。\n\n```python\ndef sstore_cost(original, current, new, refund):\n    if current == new:\n        return 200, refund\n    if original == current:\n        if original == 0:\n            return 20000, refund\n        if new == 0:\n            refund += 15000\n        return 5000, refund\n    # dirty slot\n    if original != 0:\n        if current == 0:\n            refund -= 15000\n        if new == 0:\n            refund += 15000\n    if original == new:\n        refund += 19800 if original == 0 else 4800\n    return 200, refund\n```\n\n## 知っておくべきこと\n\n- EIP-1283 は Constantinople に予定されていましたが、有効化の直前にリエントランシーの問題が見つかり、外されました。200 gas で済む変更済みスロットの `SSTORE` は、Solidity の `transfer`/`send` の 2,300 gas のスタイペンドに収まってしまいます。既存のコントラクトは、これでは状態を変更するには少なすぎると想定していました。[Petersburg](/eip-1716/) アップグレードが、このフォークからそれを取り除きました。\n- ステータスは **Final** となっていますが、この形ではメインネットで有効になっていません。同じロジックは、`SSTORE` が残りガスがスタイペント以下なら失敗するという [EIP-1706](/eip-1706/) のルールと組み合わされて、Istanbul で [EIP-2200](/eip-2200/) として出荷されました。\n- 払い戻しの数値は後にまた変更されました。現在の系譜は EIP-2200 を参照してください。本当に一時的な値には、現在は [EIP-1153](/eip-1153/) の一時ストレージ（transient storage）が専用のツールです。\n"},"ko":{"lang":"ko","tldr":"SSTORE의 순 gas 계량. 한 트랜잭션에서 같은 스토리지 슬롯에 여러 번 쓰면 첫 번째 쓰기 이후에는 200 gas만 들고, 슬롯이 원래 값으로 복원되면 환급이 있다. 재진입 위험 때문에 Constantinople에서 빠졌고 나중에 EIP-2200으로 다시 배포되었다.","tags":["gas","sstore","storage","core","constantinople"],"related":[2200,1087,1706,1716,1153],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-1283/","markdown":"## 어떤 문제를 해결하나요?\n\n이 제안 이전에는 슬롯을 바꾸는 `SSTORE`가 같은 트랜잭션에서 그 슬롯이 이미 몇 번 쓰였는지와 상관없이 매번 5,000 gas(0인 슬롯에 설정할 때는 20,000 gas)가 들었습니다. 흔한 패턴들이 이 때문에 큰 비용을 치렀습니다.\n\n- 재진입 락을 1로 설정했다가 0으로 되돌리면 전체 쓰기 비용을 두 번 냈습니다.\n- 한 번의 호출에서 카운터를 여러 번 갱신하는 컨트랙트는 쓸 때마다 비용을 냈습니다.\n- 스토리지를 통해 호출 프레임 간에 값을 주고받는 컨트랙트는 각 값이 영구 저장되는 것처럼 비용을 냈습니다.\n\n클라이언트는 실제로 `SSTORE`마다 디스크에 쓰지 않고 마지막에 커밋합니다. EIP-1283은 gas가 이를 반영하도록 만듭니다. 대부분의 클라이언트가 이미 추적하는 정보, 즉 슬롯의 **원래** 값(트랜잭션 시작 시점)과 **현재** 값만 사용합니다.\n\n## 어떻게 동작하나요?\n\n각 `SSTORE`에서 *원래* 값, *현재* 값, *새* 값을 비교합니다.\n\n- **변화 없음**(`current == new`): 200 gas.\n- **새** 슬롯(`original == current`, 이 트랜잭션에서 첫 변경):\n  - 원래 값이 0: 20,000 gas.\n  - 그 외에는 5,000 gas이며, 새 값이 0이면 15,000 환급이 더해집니다.\n- **더티** 슬롯(`original != current`, 이미 변경됨): 200 gas이며 환급 카운터가 조정됩니다.\n  - 원래 값이 0이 아니고 현재 값이 0이면 삭제 환급 15,000을 회수하고, 새 값이 0이면 이를 부여합니다.\n  - 새 값이 원래 값과 같으면(슬롯 초기화) 19,800(원래 값이 0) 또는 4,800(원래 값이 0이 아님)을 환급합니다.\n\n명세서의 예:\n\n- 빈 슬롯을 1로 설정했다가 0으로 되돌리기: `20000 + 200 - 19800 = 400` gas.\n- 빈 슬롯을 5번 증가시키기: `20000 + 5 × 200 = 21000` gas.\n\n기존 방식보다 더 많이 부과하는 일이 없으며, 별도의 \"dirty map\" 없이 일시적 스토리지와 비슷한 효과를 냅니다.\n\n## 샘플 코드\n\n비용 규칙을 Python 스타일 의사 코드로 나타낸 것:\n\n```python\ndef sstore_cost(original, current, new, refund):\n    if current == new:\n        return 200, refund\n    if original == current:\n        if original == 0:\n            return 20000, refund\n        if new == 0:\n            refund += 15000\n        return 5000, refund\n    # dirty slot\n    if original != 0:\n        if current == 0:\n            refund -= 15000\n        if new == 0:\n            refund += 15000\n    if original == new:\n        refund += 19800 if original == 0 else 4800\n    return 200, refund\n```\n\n## 알아둘 점\n\n- EIP-1283은 Constantinople에 예정되어 있었지만 활성화 직전에 재진입 문제가 발견되어 빠졌습니다. 200 gas가 드는 더티 슬롯 `SSTORE`는 Solidity `transfer`/`send`의 2,300 gas 스티펜드 안에 들어가는데, 기존 컨트랙트는 그 정도로는 상태를 바꾸기에 부족하다고 가정했습니다. [Petersburg](/eip-1716/) 업그레이드가 이 포크에서 이를 제거했습니다.\n- 상태는 **Final**로 표시되어 있지만 이 형태로는 메인넷에서 활성화되어 있지 않습니다. 같은 로직이 Istanbul에서 [EIP-2200](/eip-2200/)으로 배포되었으며, 남은 gas가 스티펜드 이하이면 `SSTORE`가 실패한다는 [EIP-1706](/eip-1706/)의 규칙과 결합되었습니다.\n- 환급 수치는 나중에 다시 바뀌었습니다. 현재의 계보는 EIP-2200을 참고하세요. 정말로 일시적인 값에는 이제 [EIP-1153](/eip-1153/)의 일시적 스토리지(transient storage)가 전용 도구입니다.\n"},"zh":{"lang":"zh","tldr":"SSTORE 的净 gas 计量：在同一笔交易中多次写入同一个存储槽，首次写入之后每次只需 200 gas，槽被恢复原值时还有退款。因重入风险被撤出 Constantinople，后来以 EIP-2200 重新上线。","tags":["gas","sstore","storage","core","constantinople"],"related":[2200,1087,1706,1716,1153],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-1283/","markdown":"## 它解决什么问题？\n\n在这项提案之前，每个改变存储槽的 `SSTORE` 都要花 5,000 gas（对为零的槽进行设置则为 20,000 gas），不管该槽在同一笔交易中已经被写入过多少次。常见的模式因此付出了高昂的代价：\n\n- 重入锁先设为 1 再设回 0，要为两次完整的写入付费，\n- 合约在一次调用中多次更新计数器，每次写入都要付费，\n- 通过存储在调用帧之间传递值的合约，按每个值都会被持久化来付费。\n\n客户端实际上并不会在每次 `SSTORE` 时都写磁盘，而是在最后统一提交。EIP-1283 让 gas 反映这一点，只使用大多数客户端已经在跟踪的信息：该存储槽的**原始**值（交易开始时）和**当前**值。\n\n## 它如何运作\n\n对于每次 `SSTORE`，比较*原始*值、*当前*值和*新*值：\n\n- **空操作**（`current == new`）：200 gas。\n- **全新**的槽（`original == current`，这笔交易中的首次修改）：\n  - 原始值为 0：20,000 gas；\n  - 否则为 5,000 gas，如果新值为 0，则另有 15,000 的退款。\n- **脏**槽（`original != current`，已被修改过）：200 gas，并调整退款计数器：\n  - 如果原始值 ≠ 0 且当前值为 0，收回 15,000 的清除退款；如果新值为 0，则给予该退款；\n  - 如果新值等于原始值（槽被重置），退款 19,800（原始值为 0）或 4,800（原始值 ≠ 0）。\n\n规范中的例子：\n\n- 空槽先设为 1 再设回 0：`20000 + 200 - 19800 = 400` gas。\n- 空槽递增 5 次：`20000 + 5 × 200 = 21000` gas。\n\n它收取的费用从不高于旧方案，并且无需单独的\"dirty map\"，就大致达到了瞬态存储的效果。\n\n## 示例代码\n\n用类 Python 伪代码表示的费用规则：\n\n```python\ndef sstore_cost(original, current, new, refund):\n    if current == new:\n        return 200, refund\n    if original == current:\n        if original == 0:\n            return 20000, refund\n        if new == 0:\n            refund += 15000\n        return 5000, refund\n    # dirty slot\n    if original != 0:\n        if current == 0:\n            refund -= 15000\n        if new == 0:\n            refund += 15000\n    if original == new:\n        refund += 19800 if original == 0 else 4800\n    return 200, refund\n```\n\n## 需要注意\n\n- EIP-1283 原本计划纳入 Constantinople，但在激活前夕因发现重入问题而被撤出：花费 200 gas 的脏槽 `SSTORE` 可以装进 Solidity `transfer`/`send` 的 2,300 gas 补贴之内，而现有合约曾假设这点 gas 不足以改变状态。[Petersburg](/eip-1716/) 升级把它从该分叉中移除了。\n- 它的状态显示为 **Final**，但以这种形式并未在主网上生效。同样的逻辑在 Istanbul 中以 [EIP-2200](/eip-2200/) 上线，并结合了 [EIP-1706](/eip-1706/) 的规则：如果剩余 gas 小于等于补贴，`SSTORE` 就会失败。\n- 退款数值后来又有变化；当前的演进脉络请参阅 EIP-2200。对于真正临时的值，如今 [EIP-1153](/eip-1153/) 的瞬态存储（transient storage）是专门为此设计的工具。\n"}},"requiredBy":[1013,1706,1716,5283,8133]}
