{"eip":161,"title":"State trie clearing (invariant-preserving alternative)","authors":["Gavin Wood (@gavofyork)"],"status":"Final","type":"Standards Track","category":"Core","created":"2016-10-24","repo":"EIPs","label":"EIP-161","officialUrl":"https://eips.ethereum.org/EIPS/eip-161","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-161.md","url":"https://eips.huatuo.xyz/eip-161/","tldr":{"en":"Spurious Dragon rule that deletes empty accounts when a transaction touches them and stops new ones from being created, cleaning up the state bloat left by the 2016 DoS attacks.","ja":"Spurious Dragon のルール。トランザクションが空のアカウントに触れると削除し、新たな空アカウントの作成も防ぐことで、2016 年の DoS 攻撃が残したステート肥大化を解消する。","ko":"트랜잭션이 빈 계정을 건드리면 삭제하고 새로운 빈 계정이 생성되는 것도 막아, 2016년 DoS 공격이 남긴 상태 비대화를 정리한 Spurious Dragon 규칙.","zh":"Spurious Dragon 规则：当交易触及空账户时将其删除，并阻止创建新的空账户，从而清理 2016 年 DoS 攻击留下的状态膨胀。"},"tags":["state","core","spurious-dragon","accounts","dos"],"explainers":{"en":{"lang":"en","tldr":"Spurious Dragon rule that deletes empty accounts when a transaction touches them and stops new ones from being created, cleaning up the state bloat left by the 2016 DoS attacks.","tags":["state","core","spurious-dragon","accounts","dos"],"related":[158,607,150,684],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-161/","markdown":"## What problem does it solve?\n\nIn autumn 2016, attackers exploited cheap opcodes to fill the state trie with millions of **empty accounts**: accounts with no code, a zero nonce and a zero balance. Each one was nearly free to create. For example, a zero-value `CALL` or `SUICIDE` to an unused address created it. Every node still had to store and process them, which slowed the whole network.\n\n[EIP-158](/eip-158/) proposed clearing these accounts. EIP-161 is the version that was adopted. It reaches the same goal while preserving some important invariants. It went live in the Spurious Dragon hard fork at block 2,675,000.\n\n## How it works\n\nThe spec defines three terms:\n\n- **Empty**: no code, zero nonce and zero balance.\n- **Dead**: either non-existent or empty.\n- **Touched**: involved in any potentially state-changing operation, even a zero-value transfer.\n\nIt then adds four rules:\n\n1. **Contracts start at nonce 1.** `CREATE` and contract-creation transactions raise the new account's nonce by one before running init code. A contract that is still being created is therefore never \"empty\" and can never be swept away.\n2. **The new-account charge is targeted.** `CALL` and `SUICIDE` used to charge 25,000 gas whenever the destination did not exist. Now the charge applies only when the call **sends non-zero value** to a **dead** account.\n3. **Nothing new becomes empty.** An account may not go from non-existent to existent-but-empty. If an operation would do that, the account stays non-existent.\n4. **Touched empty accounts are deleted.** At the end of each transaction, after self-destructs run, every touched account that is empty is removed from the state.\n\nRule 4 is how the network cleaned up after itself. Once Spurious Dragon was live, sending zero-value calls to the attack accounts touched them and deleted them.\n\n## Sample code\n\nPseudocode for the end-of-transaction sweep:\n\n```python\ndef is_empty(acct):\n    return acct.code == b\"\" and acct.nonce == 0 and acct.balance == 0\n\ndef finalize_transaction(state, touched):\n    run_selfdestructs(state)\n    for addr in touched:\n        acct = state.get(addr)\n        if acct is not None and is_empty(acct):\n            state.delete(addr)     # account becomes non-existent\n    return state.root()            # root used for the receipt\n```\n\nGas rule for a value-transferring call:\n\n```python\nif value \u003e 0 and is_dead(state, to):\n    gas_cost += 25_000   # new-account charge\n```\n\n## Things to know\n\n- Spurious Dragon's other changes are listed in [EIP-607](/eip-607/). It followed Tangerine Whistle, whose [EIP-150](/eip-150/) repriced the IO-heavy opcodes behind the same attacks.\n- An addendum clarifies that **deletions are undone when the state is reverted**. On 2016-11-24 Geth and Parity disagreed on this case, which caused a consensus bug. Out-of-gas calls to precompiles were part of the trouble.\n- Starting contracts at nonce 1 is why the first address a contract derives with `CREATE` uses nonce 1, not 0.\n- Address collisions during contract creation are handled separately by [EIP-684](/eip-684/).\n"},"ja":{"lang":"ja","tldr":"Spurious Dragon のルール。トランザクションが空のアカウントに触れると削除し、新たな空アカウントの作成も防ぐことで、2016 年の DoS 攻撃が残したステート肥大化を解消する。","tags":["state","core","spurious-dragon","accounts","dos"],"related":[158,607,150,684],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-161/","markdown":"## 何を解決するのか\n\n2016 年の秋、攻撃者は安価なオペコードを悪用し、ステートトライを何百万もの**空のアカウント**で埋め尽くしました。空のアカウントとは、コードがなく、nonce がゼロで、残高もゼロのアカウントです。1 つひとつの作成コストはほぼゼロでした。たとえば、未使用のアドレスへの value ゼロの `CALL` や `SUICIDE` によって、そのアドレスが作成されました。それでもすべてのノードがこれらを保存して処理する必要があり、ネットワーク全体が遅くなりました。\n\n[EIP-158](/eip-158/) はこれらのアカウントの消去を提案しました。EIP-161 は採用されたバージョンです。重要な不変条件をいくつか維持しながら、同じ目的を達成します。2,675,000 ブロックで、Spurious Dragon ハードフォークとして本番稼働しました。\n\n## 仕組み\n\n仕様は 3 つの用語を定義しています。\n\n- **Empty（空）**: コードがなく、nonce がゼロで、残高がゼロ。\n- **Dead（死）**: 存在しないか、空であること。\n- **Touched（接触済み）**: value ゼロの送金も含め、ステートを変更しうる何らかの操作に関与したこと。\n\nそのうえで、4 つのルールを追加します。\n\n1. **コントラクトは nonce 1 から始まる。** `CREATE` とコントラクト作成トランザクションは、init コードの実行前に新しいアカウントの nonce を 1 増やします。そのため、作成途中のコントラクトが「空」になることはなく、削除されることもありません。\n2. **新規アカウント課金の対象を絞る。** `CALL` と `SUICIDE` は、宛先が存在しないときに常に 25,000 ガスを課金していました。今は、**dead** アカウントへ**ゼロでない value を送る**呼び出しの場合にのみ課金します。\n3. **新たに空になるものはない。** アカウントが「存在しない」状態から「存在するが空」の状態になってはいけません。操作がそうなるはずの場合、そのアカウントは存在しないままです。\n4. **接触済みの空アカウントは削除される。** 各トランザクションの終了時、自己破壊の実行後に、接触済みで空のアカウントはすべてステートから削除されます。\n\nルール 4 が、ネットワークが自らを掃除した仕組みです。Spurious Dragon が稼働すると、攻撃用アカウントへ value ゼロの呼び出しを送ることでそれらに触れ、削除できました。\n\n## サンプルコード\n\nトランザクション終了時のスイープの疑似コード:\n\n```python\ndef is_empty(acct):\n    return acct.code == b\"\" and acct.nonce == 0 and acct.balance == 0\n\ndef finalize_transaction(state, touched):\n    run_selfdestructs(state)\n    for addr in touched:\n        acct = state.get(addr)\n        if acct is not None and is_empty(acct):\n            state.delete(addr)     # account becomes non-existent\n    return state.root()            # root used for the receipt\n```\n\nvalue を伴う呼び出しのガスルール:\n\n```python\nif value \u003e 0 and is_dead(state, to):\n    gas_cost += 25_000   # new-account charge\n```\n\n## 知っておくべきこと\n\n- Spurious Dragon のその他の変更は [EIP-607](/eip-607/) に一覧があります。これは Tangerine Whistle に続くもので、Tangerine Whistle の [EIP-150](/eip-150/) は同じ攻撃の背景にあった IO 負荷の高いオペコードの価格を見直しました。\n- 補遺では、**ステートがリバートされると削除も取り消される**ことが明確にされています。2016-11-24 に Geth と Parity がこのケースで食い違い、コンセンサスのバグが発生しました。プリコンパイルへのガス切れ呼び出しも問題の一部でした。\n- コントラクトを nonce 1 から始めるため、コントラクトが `CREATE` で最初に導出するアドレスは nonce 0 ではなく 1 を使います。\n- コントラクト作成時のアドレス衝突は、[EIP-684](/eip-684/) で別途扱われます。\n"},"ko":{"lang":"ko","tldr":"트랜잭션이 빈 계정을 건드리면 삭제하고 새로운 빈 계정이 생성되는 것도 막아, 2016년 DoS 공격이 남긴 상태 비대화를 정리한 Spurious Dragon 규칙.","tags":["state","core","spurious-dragon","accounts","dos"],"related":[158,607,150,684],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-161/","markdown":"## 어떤 문제를 해결하나요?\n\n2016년 가을, 공격자들은 저렴한 opcode를 악용해 상태 트라이를 수백만 개의 **빈 계정**으로 채웠습니다. 빈 계정이란 코드가 없고 nonce가 0이며 잔액도 0인 계정입니다. 하나하나 만드는 비용은 거의 0에 가까웠습니다. 예를 들어 사용된 적 없는 주소로 value 0의 `CALL`이나 `SUICIDE`를 보내면 그 주소가 생성되었습니다. 그래도 모든 노드가 이들을 저장하고 처리해야 했고, 이는 네트워크 전체를 느리게 만들었습니다.\n\n[EIP-158](/eip-158/)은 이런 계정을 정리하자고 제안했습니다. EIP-161은 채택된 버전입니다. 몇 가지 중요한 불변 조건을 지키면서 같은 목표를 달성합니다. Spurious Dragon 하드 포크의 일부로 블록 2,675,000에서 시작되었습니다.\n\n## 어떻게 동작하나요?\n\n명세는 세 가지 용어를 정의합니다.\n\n- **Empty(빈)**: 코드가 없고, nonce가 0이며, 잔액이 0.\n- **Dead(죽은)**: 존재하지 않거나 비어 있음.\n- **Touched(접촉된)**: value 0의 전송을 포함해, 상태를 바꿀 가능성이 있는 어떤 연산에든 관여함.\n\n그리고 네 가지 규칙을 추가합니다.\n\n1. **컨트랙트는 nonce 1에서 시작한다.** `CREATE`와 컨트랙트 생성 트랜잭션은 init 코드를 실행하기 전에 새 계정의 nonce를 1 올립니다. 따라서 생성 중인 컨트랙트는 \"빈\" 계정이 될 수 없고 정리되지도 않습니다.\n2. **신규 계정 요금은 대상이 한정된다.** `CALL`과 `SUICIDE`는 목적지가 존재하지 않을 때마다 25,000 가스를 부과했습니다. 이제는 호출이 **dead** 계정에 **0이 아닌 value를 보낼** 때만 부과합니다.\n3. **새로 비게 되는 것은 없다.** 계정이 존재하지 않음에서 존재하지만 빈 상태로 바뀌어서는 안 됩니다. 어떤 연산이 그렇게 만들 경우 그 계정은 존재하지 않는 상태로 남습니다.\n4. **접촉된 빈 계정은 삭제된다.** 각 트랜잭션이 끝날 때, 셀프디스트럭트가 실행된 뒤에 접촉된 빈 계정은 모두 상태에서 제거됩니다.\n\n규칙 4가 네트워크가 스스로 청소한 방법입니다. Spurious Dragon이 가동된 뒤, 공격용 계정에 value 0의 호출을 보내면 그 계정들을 건드려 삭제할 수 있었습니다.\n\n## 샘플 코드\n\n트랜잭션 종료 시 정리(sweep)의 의사 코드:\n\n```python\ndef is_empty(acct):\n    return acct.code == b\"\" and acct.nonce == 0 and acct.balance == 0\n\ndef finalize_transaction(state, touched):\n    run_selfdestructs(state)\n    for addr in touched:\n        acct = state.get(addr)\n        if acct is not None and is_empty(acct):\n            state.delete(addr)     # account becomes non-existent\n    return state.root()            # root used for the receipt\n```\n\nvalue를 전송하는 호출의 가스 규칙:\n\n```python\nif value \u003e 0 and is_dead(state, to):\n    gas_cost += 25_000   # new-account charge\n```\n\n## 알아둘 점\n\n- Spurious Dragon의 다른 변경 사항은 [EIP-607](/eip-607/)에 나열되어 있습니다. 이는 Tangerine Whistle 다음에 이어졌으며, Tangerine Whistle의 [EIP-150](/eip-150/)은 같은 공격의 배경이 된 IO 부하가 큰 opcode의 가격을 재조정했습니다.\n- 부록에서는 **상태가 되돌려지면 삭제도 취소된다**는 점을 명확히 합니다. 2016-11-24에 Geth와 Parity가 이 경우에 대해 의견이 갈려 합의 버그가 발생했습니다. 프리컴파일에 대한 out-of-gas 호출도 문제의 일부였습니다.\n- 컨트랙트가 nonce 1에서 시작하기 때문에, 컨트랙트가 `CREATE`로 처음 파생하는 주소는 nonce 0이 아니라 1을 사용합니다.\n- 컨트랙트 생성 중의 주소 충돌은 [EIP-684](/eip-684/)에서 별도로 다룹니다.\n"},"zh":{"lang":"zh","tldr":"Spurious Dragon 规则：当交易触及空账户时将其删除，并阻止创建新的空账户，从而清理 2016 年 DoS 攻击留下的状态膨胀。","tags":["state","core","spurious-dragon","accounts","dos"],"related":[158,607,150,684],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-161/","markdown":"## 它解决什么问题？\n\n2016 年秋天，攻击者利用廉价的操作码，用数百万个**空账户**填满了状态树。空账户即没有代码、nonce 为零且余额为零的账户。每个账户的创建成本几乎为零。例如，向一个未使用的地址发起 value 为零的 `CALL` 或 `SUICIDE` 就会创建该地址。每个节点仍然必须存储和处理这些账户，这拖慢了整个网络。\n\n[EIP-158](/eip-158/) 提议清除这些账户。EIP-161 是最终被采纳的版本。它在保留一些重要不变量的同时达成了同样的目标。它随 Spurious Dragon 硬分叉在区块 2,675,000 上线。\n\n## 它如何运作\n\n规范定义了三个术语：\n\n- **Empty（空）**：没有代码，nonce 为零，余额为零。\n- **Dead（死）**：不存在或为空。\n- **Touched（被触及）**：参与了任何可能改变状态的操作，即使是 value 为零的转账。\n\n然后增加了四条规则：\n\n1. **合约从 nonce 1 开始。** `CREATE` 和合约创建交易在运行初始化代码之前，会将新账户的 nonce 加一。因此，仍在创建中的合约永远不会是\"空\"的，也不会被清除。\n2. **新账户收费有针对性。** `CALL` 和 `SUICIDE` 过去只要目标不存在就收取 25,000 gas。现在只有当调用向一个 **dead** 账户**发送非零 value** 时才收取。\n3. **不会新增空账户。** 账户不能从不存在变为存在但为空。如果某项操作会导致这种情况，该账户保持不存在。\n4. **被触及的空账户会被删除。** 在每笔交易结束时，自毁执行之后，所有被触及且为空的账户都会从状态中移除。\n\n规则 4 就是网络自我清理的方式。Spurious Dragon 上线后，向攻击账户发送 value 为零的调用会触及并删除它们。\n\n## 示例代码\n\n交易结束时清扫的伪代码：\n\n```python\ndef is_empty(acct):\n    return acct.code == b\"\" and acct.nonce == 0 and acct.balance == 0\n\ndef finalize_transaction(state, touched):\n    run_selfdestructs(state)\n    for addr in touched:\n        acct = state.get(addr)\n        if acct is not None and is_empty(acct):\n            state.delete(addr)     # account becomes non-existent\n    return state.root()            # root used for the receipt\n```\n\n转移 value 的调用的 gas 规则：\n\n```python\nif value \u003e 0 and is_dead(state, to):\n    gas_cost += 25_000   # new-account charge\n```\n\n## 需要注意\n\n- Spurious Dragon 的其他变更列在 [EIP-607](/eip-607/) 中。它紧随 Tangerine Whistle 之后，后者的 [EIP-150](/eip-150/) 重新定价了这些攻击所利用的 IO 密集型操作码。\n- 一份附录澄清了：**状态回滚时，删除也会被撤销**。2016-11-24，Geth 和 Parity 在这一情形上出现分歧，引发了共识漏洞。对预编译合约的 out-of-gas 调用也是问题的一部分。\n- 合约从 nonce 1 开始，这就是合约通过 `CREATE` 派生的第一个地址使用 nonce 1 而不是 0 的原因。\n- 合约创建期间的地址冲突由 [EIP-684](/eip-684/) 单独处理。\n"}},"requiredBy":[607,1052,2926,4747,7523,7702,8037,8246,8253,8357,8358,8360]}
