{"eip":158,"title":"State clearing","authors":["Vitalik Buterin (@vbuterin)"],"status":"Final","type":"Standards Track","category":"Core","created":"2016-10-16","repo":"EIPs","label":"EIP-158","officialUrl":"https://eips.ethereum.org/EIPS/eip-158","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-158.md","url":"https://eips.huatuo.xyz/eip-158/","tldr":{"en":"Proposed deleting empty accounts from Ethereum's state and treating 'empty' as 'nonexistent', to clean up millions of junk accounts created by the 2016 DoS attacks.","ja":"2016 年の DoS 攻撃で作られた何百万もの不要アカウントを一掃するため、Ethereum のステートから空のアカウントを削除し、「空」を「存在しない」として扱うことを提案した。","ko":"2016년 DoS 공격으로 생긴 수백만 개의 쓰레기 계정을 정리하기 위해, 이더리움 상태에서 빈 계정을 삭제하고 '비어 있음'을 '존재하지 않음'으로 취급하자고 제안했다.","zh":"提议从以太坊状态中删除空账户，并把\"空\"视为\"不存在\"，以清理 2016 年 DoS 攻击制造的数百万个垃圾账户。"},"tags":["state","core","cleanup","spurious-dragon"],"explainers":{"en":{"lang":"en","tldr":"Proposed deleting empty accounts from Ethereum's state and treating 'empty' as 'nonexistent', to clean up millions of junk accounts created by the 2016 DoS attacks.","tags":["state","core","cleanup","spurious-dragon"],"related":[161,607,150],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-158/","markdown":"## What problem does it solve?\n\nIn autumn 2016, attackers exploited underpriced opcodes to cheaply create huge numbers of accounts with zero balance, zero nonce and no code. Each one still had to be stored in the state trie. State grew, disks filled and fast sync slowed down.\n\nEIP-158 proposes removing those \"empty\" accounts and making sure no new ones can be created. Once the junk is gone, \"empty\" and \"does not exist\" become the same thing, which simplifies the protocol for good.\n\n## How it works\n\nFrom the fork block onward:\n\n1. **Never save an empty account.** If a state change would leave an account with nonce 0, balance 0, no code (and, in the base version, no storage), the account is deleted instead.\n2. **Touching deletes.** If an existing empty account is \"touched\", it is deleted. A touch is anything that would have created the account if it did not exist: a zero-value `CALL`, a zero-value `SELFDESTRUCT` (then `SUICIDE`), being a transaction recipient, being created with empty code, or receiving fees as the miner.\n3. **Empty equals nonexistent.** Whenever the EVM asks \"does this account exist?\", an empty account answers no.\n4. **No surprise 25,000 gas.** Zero-value calls and self-destructs no longer pay the new-account creation cost.\n\nThe spec lists two variants: **1b** defines emptiness as balance, nonce and code only (storage ignored) to keep client caches simple, and **1c** replaces \"touching deletes\" with a sweep that removes 1,000 empty accounts per block in hash order.\n\n## Sample code\n\nThe emptiness check from variant 1b, and the rule applied after each state change (pseudocode):\n\n```python\ndef is_empty(acct):\n    return get_balance(acct) == 0 and get_code(acct) == b\"\" and get_nonce(acct) == 0\n\ndef after_state_change(addr):\n    if account_exists(addr) and is_empty(addr):\n        delete_account(addr)\n\ndef on_touch(addr):            # e.g. 0-value CALL to addr\n    if account_exists(addr) and is_empty(addr):\n        delete_account(addr)\n```\n\nClearing an empty account is as simple as sending it a zero-value call:\n\n```solidity\n(bool ok, ) = emptyAccount.call{value: 0}(\"\");  // touches and deletes it\n```\n\n## Things to know\n\n- EIP-158 is marked Final, but what actually shipped in the Spurious Dragon hard fork (November 2016, [EIP-607](/eip-607/)) was the revised version, [EIP-161](/eip-161/) \"State trie clearing\". Read EIP-161 for the exact rules clients implement.\n- The spec admits a temporary side effect: touching an existing empty account costs about 700 gas instead of the usual 5,000 for a state write, so block processing could be heavier until the cleanup finished.\n- After this change, contracts cannot distinguish \"never used\" from \"used but emptied\". Code that relies on `extcodesize` or balance to detect prior activity should not assume otherwise.\n- It is the follow-up to the gas repricing of [EIP-150](/eip-150/) (Tangerine Whistle), which closed the cheap attack vectors. EIP-158/161 then dealt with the leftover junk.\n"},"ja":{"lang":"ja","tldr":"2016 年の DoS 攻撃で作られた何百万もの不要アカウントを一掃するため、Ethereum のステートから空のアカウントを削除し、「空」を「存在しない」として扱うことを提案した。","tags":["state","core","cleanup","spurious-dragon"],"related":[161,607,150],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-158/","markdown":"## 何を解決するのか\n\n2016 年の秋、攻撃者は価格が安すぎるオペコードを悪用し、残高ゼロ、nonce ゼロ、コードなしのアカウントを安価に大量作成しました。これらはすべてステートトライに保存する必要がありました。ステートは肥大化し、ディスクは埋まり、fast sync は遅くなりました。\n\nEIP-158 は、こうした「空」のアカウントを削除し、新たに作られないようにすることを提案します。不要なものがなくなれば、「空」と「存在しない」は同じ意味になり、プロトコルが恒久的に単純になります。\n\n## 仕組み\n\nフォークブロック以降は次のようになります。\n\n1. **空のアカウントは決して保存しない。** ステートの変更によってアカウントが nonce 0、残高 0、コードなし（基本版ではストレージもなし）になる場合、そのアカウントは代わりに削除されます。\n2. **タッチすると削除される。** 既存の空のアカウントが「タッチ」されると、削除されます。タッチとは、そのアカウントが存在しなければ作成されていたはずの操作すべてを指します。具体的には、value がゼロの `CALL`、value がゼロの `SELFDESTRUCT`（当時は `SUICIDE`）、トランザクションの宛先になること、空のコードで作成されること、マイナーとして手数料を受け取ることです。\n3. **空は存在しないと同じ。** EVM が「このアカウントは存在するか」と尋ねたとき、空のアカウントは「いいえ」と答えます。\n4. **予想外の 25,000 gas がなくなる。** value がゼロの呼び出しや自己破壊では、新規アカウント作成のコストを支払わなくなります。\n\n仕様書には 2 つの変種があります。**1b** は、クライアントのキャッシュを単純にするため、空であることを残高・nonce・コードだけで定義します（ストレージは無視）。**1c** は「タッチすると削除される」を、ハッシュ順に 1 ブロックあたり 1,000 個の空のアカウントを削除するスイープに置き換えます。\n\n## サンプルコード\n\n変種 1b の空判定と、ステート変更のたびに適用されるルール（疑似コード）:\n\n```python\ndef is_empty(acct):\n    return get_balance(acct) == 0 and get_code(acct) == b\"\" and get_nonce(acct) == 0\n\ndef after_state_change(addr):\n    if account_exists(addr) and is_empty(addr):\n        delete_account(addr)\n\ndef on_touch(addr):            # e.g. 0-value CALL to addr\n    if account_exists(addr) and is_empty(addr):\n        delete_account(addr)\n```\n\n空のアカウントを消すのは、value ゼロの呼び出しを送るだけで済みます。\n\n```solidity\n(bool ok, ) = emptyAccount.call{value: 0}(\"\");  // touches and deletes it\n```\n\n## 知っておくべきこと\n\n- EIP-158 は Final とされていますが、Spurious Dragon ハードフォーク（2016 年 11 月、[EIP-607](/eip-607/)）で実際に出荷されたのは、改訂版の [EIP-161](/eip-161/)「State trie clearing」でした。クライアントが実装する正確なルールは EIP-161 を参照してください。\n- 仕様書は一時的な副作用を認めています。既存の空のアカウントをタッチするコストは、ステート書き込みの通常の 5,000 gas ではなく約 700 gas のため、クリーンアップが終わるまではブロック処理が重くなる可能性がありました。\n- この変更の後、コントラクトは「一度も使われていない」と「使われたが空になった」を区別できません。`extcodesize` や残高で過去の利用を検出するコードは、そうでないと仮定してはいけません。\n- これは、安価な攻撃手段を塞いだ [EIP-150](/eip-150/)（Tangerine Whistle）のガス再設定の続編です。EIP-158/161 は、その後に残った不要データを片付けました。\n"},"ko":{"lang":"ko","tldr":"2016년 DoS 공격으로 생긴 수백만 개의 쓰레기 계정을 정리하기 위해, 이더리움 상태에서 빈 계정을 삭제하고 '비어 있음'을 '존재하지 않음'으로 취급하자고 제안했다.","tags":["state","core","cleanup","spurious-dragon"],"related":[161,607,150],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-158/","markdown":"## 어떤 문제를 해결하나요?\n\n2016년 가을, 공격자들은 가격이 너무 낮게 책정된 오피코드를 악용해 잔액 0, nonce 0, 코드 없음인 계정을 저렴하게 대량으로 만들었습니다. 이 계정들은 각각 상태 트라이에 저장되어야 했습니다. 상태가 커지고, 디스크가 차고, fast sync가 느려졌습니다.\n\nEIP-158은 이런 \"빈\" 계정을 삭제하고 새로 만들어지지 않도록 하자고 제안합니다. 쓰레기가 사라지면 \"비어 있음\"과 \"존재하지 않음\"이 같은 의미가 되어, 프로토콜이 영구적으로 단순해집니다.\n\n## 어떻게 동작하나요?\n\n포크 블록부터 다음과 같이 바뀝니다.\n\n1. **빈 계정은 절대 저장하지 않습니다.** 상태 변경으로 계정이 nonce 0, 잔액 0, 코드 없음(기본 버전에서는 스토리지도 없음)이 되면, 그 계정은 대신 삭제됩니다.\n2. **터치하면 삭제됩니다.** 이미 존재하는 빈 계정이 \"터치\"되면 삭제됩니다. 터치란 계정이 존재하지 않았다면 그 계정을 만들었을 모든 동작을 말합니다. value가 0인 `CALL`, value가 0인 `SELFDESTRUCT`(당시에는 `SUICIDE`), 트랜잭션의 수신자가 되는 것, 빈 코드로 생성되는 것, 채굴자로서 수수료를 받는 것이 해당합니다.\n3. **비어 있음은 존재하지 않음과 같습니다.** EVM이 \"이 계정이 존재하나?\"라고 물을 때, 빈 계정은 아니라고 답합니다.\n4. **예상치 못한 25,000 gas가 없어집니다.** value가 0인 호출과 자폭은 더 이상 새 계정 생성 비용을 내지 않습니다.\n\n명세서에는 두 가지 변형이 있습니다. **1b**는 클라이언트 캐시를 단순하게 유지하기 위해 비어 있음을 잔액, nonce, 코드만으로 정의하고(스토리지는 무시), **1c**는 \"터치하면 삭제\"를 해시 순서대로 블록당 빈 계정 1,000개를 지우는 스윕으로 대체합니다.\n\n## 샘플 코드\n\n변형 1b의 빈 계정 판별과, 상태가 바뀔 때마다 적용되는 규칙(의사 코드):\n\n```python\ndef is_empty(acct):\n    return get_balance(acct) == 0 and get_code(acct) == b\"\" and get_nonce(acct) == 0\n\ndef after_state_change(addr):\n    if account_exists(addr) and is_empty(addr):\n        delete_account(addr)\n\ndef on_touch(addr):            # e.g. 0-value CALL to addr\n    if account_exists(addr) and is_empty(addr):\n        delete_account(addr)\n```\n\n빈 계정을 지우는 것은 value가 0인 호출을 보내는 것만큼 간단합니다.\n\n```solidity\n(bool ok, ) = emptyAccount.call{value: 0}(\"\");  // touches and deletes it\n```\n\n## 알아둘 점\n\n- EIP-158은 Final로 표시되어 있지만, Spurious Dragon 하드포크(2016년 11월, [EIP-607](/eip-607/))에서 실제로 배포된 것은 수정판인 [EIP-161](/eip-161/) \"State trie clearing\"이었습니다. 클라이언트가 구현하는 정확한 규칙은 EIP-161을 읽어 보세요.\n- 명세서는 일시적인 부작용을 인정합니다. 기존 빈 계정을 터치하는 비용은 상태 쓰기의 통상 비용인 5,000 gas가 아니라 약 700 gas이므로, 정리가 끝날 때까지 블록 처리가 더 무거울 수 있었습니다.\n- 이 변경 이후 컨트랙트는 \"한 번도 사용되지 않음\"과 \"사용되었지만 비워짐\"을 구분할 수 없습니다. `extcodesize`나 잔액으로 과거 활동을 감지하는 코드는 그렇지 않다고 가정해서는 안 됩니다.\n- 이는 저렴한 공격 경로를 막은 [EIP-150](/eip-150/)(Tangerine Whistle)의 gas 재가격 책정의 후속입니다. EIP-158/161은 그 뒤에 남은 쓰레기를 처리했습니다.\n"},"zh":{"lang":"zh","tldr":"提议从以太坊状态中删除空账户，并把\"空\"视为\"不存在\"，以清理 2016 年 DoS 攻击制造的数百万个垃圾账户。","tags":["state","core","cleanup","spurious-dragon"],"related":[161,607,150],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-158/","markdown":"## 它解决什么问题？\n\n2016 年秋，攻击者利用定价过低的操作码，以极低成本创建了大量余额为零、nonce 为零、没有代码的账户。每个账户仍然需要存储在状态树中。状态不断膨胀，磁盘被占满，快速同步也变慢了。\n\nEIP-158 提议删除这些\"空\"账户，并确保不会再创建新的空账户。垃圾清除之后，\"空\"与\"不存在\"就成了一回事，从而永久简化了协议。\n\n## 它如何运作\n\n从分叉区块起：\n\n1. **绝不保存空账户。** 如果某次状态变更会使账户的 nonce 为 0、余额为 0、没有代码（基础版本中还要没有存储），该账户就会被删除。\n2. **触碰即删除。** 如果一个已存在的空账户被\"触碰\"（touch），它就会被删除。触碰指的是：如果该账户不存在，这一操作本来会创建它。包括：value 为零的 `CALL`、value 为零的 `SELFDESTRUCT`（当时叫 `SUICIDE`）、成为交易接收方、以空代码被创建，或作为矿工收取手续费。\n3. **空等于不存在。** 每当 EVM 询问\"这个账户存在吗\"，空账户都回答\"不存在\"。\n4. **不再有意外的 25,000 gas。** value 为零的调用和自毁不再支付新账户创建费用。\n\n规范列出了两个变体：**1b** 为了让客户端缓存保持简单，仅用余额、nonce 和代码来定义\"空\"（忽略存储）；**1c** 则把\"触碰即删除\"替换为一种清扫机制，按哈希顺序每个区块删除 1,000 个空账户。\n\n## 示例代码\n\n变体 1b 中的空账户判断，以及每次状态变更后应用的规则（伪代码）：\n\n```python\ndef is_empty(acct):\n    return get_balance(acct) == 0 and get_code(acct) == b\"\" and get_nonce(acct) == 0\n\ndef after_state_change(addr):\n    if account_exists(addr) and is_empty(addr):\n        delete_account(addr)\n\ndef on_touch(addr):            # e.g. 0-value CALL to addr\n    if account_exists(addr) and is_empty(addr):\n        delete_account(addr)\n```\n\n清除一个空账户，只需向它发送一个 value 为零的调用：\n\n```solidity\n(bool ok, ) = emptyAccount.call{value: 0}(\"\");  // touches and deletes it\n```\n\n## 需要注意\n\n- EIP-158 被标记为 Final，但 Spurious Dragon 硬分叉（2016 年 11 月，[EIP-607](/eip-607/)）实际上线的是修订版 [EIP-161](/eip-161/)\"State trie clearing\"。客户端实际实现的确切规则请阅读 EIP-161。\n- 规范承认存在一个临时的副作用：触碰一个已存在的空账户约需 700 gas，而不是状态写入通常的 5,000 gas，因此在清理完成之前，区块处理可能更重。\n- 这一改动之后，合约无法区分\"从未使用过\"和\"用过但已被清空\"。依赖 `extcodesize` 或余额来检测账户过往活动的代码，不应假设情况并非如此。\n- 它是 [EIP-150](/eip-150/)（Tangerine Whistle）gas 重新定价的后续，后者封堵了廉价的攻击途径，而 EIP-158/161 随后处理了遗留的垃圾。\n"}}}
