{"eip":689,"title":"Address Collision of Contract Address Causes Exceptional Halt","description":"This EIP proposes to make contract creation fail on an account with nonempty code or non-zero nonce.","authors":["Yoichi Hirai \u003ci@yoichihirai.com\u003e"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2017-08-15","repo":"EIPs","label":"EIP-689","officialUrl":"https://eips.ethereum.org/EIPS/eip-689","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-689.md","url":"https://eips.huatuo.xyz/eip-689/","tldr":{"en":"A stagnant proposal to make contract creation fail outright when the target address already has code or a non-zero nonce; the same rule was adopted through EIP-684.","ja":"対象アドレスにすでにコードまたは 0 以外の nonce がある場合、コントラクト作成を即座に失敗させるという停滞中の提案。同じルールは EIP-684 を通じて採用された。","ko":"대상 주소에 이미 코드가 있거나 nonce가 0이 아니면 컨트랙트 생성을 즉시 실패시키자는, 정체 상태의 제안. 같은 규칙이 EIP-684를 통해 채택되었다.","zh":"一项处于停滞状态的提案：当目标地址已有代码或 nonce 非零时，让合约创建直接失败；同样的规则已通过 EIP-684 被采纳。"},"tags":["evm","create","core","consensus","stagnant"],"explainers":{"en":{"lang":"en","tldr":"A stagnant proposal to make contract creation fail outright when the target address already has code or a non-zero nonce; the same rule was adopted through EIP-684.","tags":["evm","create","core","consensus","stagnant"],"related":[684,7610,161,1014,86],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-689/","markdown":"## What problem does it solve?\n\nA contract's address is derived from a hash. In theory, a new contract could be deployed at an address that already holds code. The Yellow Paper said creation would then start from empty code and the initial nonce, which means it would **overwrite** the existing contract.\n\nOn mainnet this practically never happens, because it needs a keccak256 collision. But the consensus test suite included such cases, and clients disagreed on how to handle them. Supporting \"overwrite, and undo the overwrite if creation reverts\" just to pass tests made clients more complex for no real benefit.\n\nEIP-689 proposed a simple rule: **if the address is already in use, creation fails.**\n\n## How it works\n\nFrom genesis (`block.number \u003e= 0`):\n\n- If a contract creation targets an account with a **non-zero nonce** or **non-empty code**, creation fails **as if the init code hit an exceptional halt**.\n- This applies both to contract-creation transactions and to the `CREATE` opcode.\n\nThe spec gives two benefits:\n\n- **Simpler testing.** Clients no longer need to revert a code overwrite.\n- **Simpler reasoning.** It creates an invariant: once an account has code, that code is never modified by another creation.\n\nBecause applying the rule from genesis changes nothing in mainnet history, the spec says it is backwards compatible.\n\n## Sample code\n\nPseudocode for the check at the start of contract creation:\n\n```python\ndef create_contract(state, sender, address, init_code, value, gas):\n    target = state.get(address)\n    if target is not None and (target.nonce != 0 or len(target.code) \u003e 0):\n        # Collision: behave like an exceptional halt in init code\n        return Failure(gas_used=gas)     # all supplied gas consumed\n    state.increment_nonce(address)       # EIP-161: new contracts start at nonce 1\n    return run_init_code(state, sender, address, init_code, value, gas)\n```\n\nFrom Solidity, a collided `CREATE2` deployment simply returns the zero address:\n\n```solidity\naddress a;\nassembly { a := create2(0, add(code, 0x20), mload(code), salt) }\nrequire(a != address(0), \"create2 failed (e.g. address already in use)\");\n```\n\n## Things to know\n\n- **This proposal is Stagnant and was never adopted as written.** The same collision rule is part of Final [EIP-684](/eip-684/) (Revert creation in case of collision), which clients apply retroactively. [EIP-7610](/eip-7610/) extends the check to accounts with non-empty storage.\n- The spec says the rule was already covered by [EIP-86](/eip-86/) for the planned Constantinople fork. EIP-86 itself is now Stagnant.\n- The rule matters more once addresses are predictable. With `CREATE2` ([EIP-1014](/eip-1014/)), deploying the same init code with the same salt twice from one factory fails the second time.\n- The spec names the BlockchainTest `createJS_ExampleContract_d0g0v0_EIP158` as a test that tells implementing clients apart from others.\n"},"ja":{"lang":"ja","tldr":"対象アドレスにすでにコードまたは 0 以外の nonce がある場合、コントラクト作成を即座に失敗させるという停滞中の提案。同じルールは EIP-684 を通じて採用された。","tags":["evm","create","core","consensus","stagnant"],"related":[684,7610,161,1014,86],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-689/","markdown":"## 何を解決するのか\n\nコントラクトのアドレスはハッシュから導出されます。理論上は、すでにコードを持つアドレスに新しいコントラクトをデプロイできてしまいます。イエローペーパーでは、その場合の作成は空のコードと初期 nonce から始まるとされており、既存のコントラクトを**上書き**することになります。\n\nメインネットで実際にこれが起きることはまずありません。keccak256 の衝突が必要だからです。しかしコンセンサステストスイートにはそのようなケースが含まれており、クライアントごとに扱いが異なっていました。テストを通すためだけに「上書きし、作成が revert されたら上書きを元に戻す」ことをサポートするのは、実益がないままクライアントを複雑にしていました。\n\nEIP-689 は単純なルールを提案しました。**アドレスがすでに使われているなら、作成は失敗する**というものです。\n\n## 仕組み\n\nジェネシスから（`block.number \u003e= 0`）:\n\n- コントラクト作成の対象が **0 以外の nonce** または**空でないコード**を持つアカウントの場合、作成は**初期化コードが例外的な停止に至ったかのように**失敗します。\n- これはコントラクト作成トランザクションにも `CREATE` opcode にも適用されます。\n\n仕様は 2 つの利点を挙げています。\n\n- **テストが単純になる。** クライアントはコードの上書きを元に戻す必要がなくなります。\n- **推論が単純になる。** 不変条件が生まれます。アカウントがいったんコードを持てば、そのコードが別の作成によって変更されることはありません。\n\nこのルールをジェネシスから適用してもメインネットの履歴は何も変わらないため、仕様は後方互換性があるとしています。\n\n## サンプルコード\n\nコントラクト作成の冒頭で行うチェックの疑似コード:\n\n```python\ndef create_contract(state, sender, address, init_code, value, gas):\n    target = state.get(address)\n    if target is not None and (target.nonce != 0 or len(target.code) \u003e 0):\n        # Collision: behave like an exceptional halt in init code\n        return Failure(gas_used=gas)     # all supplied gas consumed\n    state.increment_nonce(address)       # EIP-161: new contracts start at nonce 1\n    return run_init_code(state, sender, address, init_code, value, gas)\n```\n\nSolidity からは、衝突した `CREATE2` のデプロイは単にゼロアドレスを返します。\n\n```solidity\naddress a;\nassembly { a := create2(0, add(code, 0x20), mload(code), salt) }\nrequire(a != address(0), \"create2 failed (e.g. address already in use)\");\n```\n\n## 知っておくべきこと\n\n- **この提案は Stagnant で、記載のままの形では採用されませんでした。** 同じ衝突ルールは Final の [EIP-684](/eip-684/)（衝突時に作成を revert する）に含まれており、クライアントはそれを遡及的に適用しています。[EIP-7610](/eip-7610/) は、このチェックをストレージが空でないアカウントにも拡張します。\n- 仕様によれば、このルールは予定されていた Constantinople フォークに向けた [EIP-86](/eip-86/) ですでにカバーされていました。EIP-86 自体は現在 Stagnant です。\n- アドレスが予測可能になると、このルールはより重要になります。`CREATE2`（[EIP-1014](/eip-1014/)）では、同じファクトリーから同じ初期化コードと同じ salt で 2 回デプロイすると、2 回目は失敗します。\n- 仕様は、実装しているクライアントとそうでないクライアントを見分けるテストとして、BlockchainTest の `createJS_ExampleContract_d0g0v0_EIP158` を挙げています。\n"},"ko":{"lang":"ko","tldr":"대상 주소에 이미 코드가 있거나 nonce가 0이 아니면 컨트랙트 생성을 즉시 실패시키자는, 정체 상태의 제안. 같은 규칙이 EIP-684를 통해 채택되었다.","tags":["evm","create","core","consensus","stagnant"],"related":[684,7610,161,1014,86],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-689/","markdown":"## 어떤 문제를 해결하나요?\n\n컨트랙트 주소는 해시에서 도출됩니다. 이론적으로는 이미 코드가 있는 주소에 새 컨트랙트를 배포할 수 있습니다. 옐로 페이퍼는 이 경우 생성이 빈 코드와 초기 nonce에서 시작한다고 하며, 이는 기존 컨트랙트를 **덮어쓴다**는 뜻입니다.\n\n메인넷에서는 keccak256 충돌이 필요하므로 사실상 일어나지 않습니다. 하지만 합의 테스트 스위트에는 이런 사례가 포함되어 있었고, 클라이언트마다 처리 방식이 달랐습니다. 테스트를 통과하기 위해서만 \"덮어쓰고, 생성이 revert되면 덮어쓰기를 되돌리기\"를 지원하는 것은 실질적인 이득 없이 클라이언트를 복잡하게 만들었습니다.\n\nEIP-689는 단순한 규칙을 제안했습니다. **주소가 이미 사용 중이면 생성은 실패한다**는 것입니다.\n\n## 어떻게 동작하나요?\n\n제네시스부터(`block.number \u003e= 0`):\n\n- 컨트랙트 생성의 대상이 **0이 아닌 nonce** 또는 **비어 있지 않은 코드**를 가진 계정이면, 생성은 **초기화 코드가 예외적 중단에 걸린 것처럼** 실패합니다.\n- 이는 컨트랙트 생성 트랜잭션과 `CREATE` opcode 모두에 적용됩니다.\n\n명세는 두 가지 이점을 듭니다.\n\n- **테스트가 단순해집니다.** 클라이언트가 더 이상 코드 덮어쓰기를 되돌릴 필요가 없습니다.\n- **추론이 단순해집니다.** 불변식이 생깁니다. 계정에 일단 코드가 생기면 그 코드는 다른 생성에 의해 수정되지 않습니다.\n\n이 규칙을 제네시스부터 적용해도 메인넷 이력은 아무것도 바뀌지 않으므로, 명세는 하위 호환된다고 말합니다.\n\n## 샘플 코드\n\n컨트랙트 생성 시작 시점의 검사에 대한 의사 코드:\n\n```python\ndef create_contract(state, sender, address, init_code, value, gas):\n    target = state.get(address)\n    if target is not None and (target.nonce != 0 or len(target.code) \u003e 0):\n        # Collision: behave like an exceptional halt in init code\n        return Failure(gas_used=gas)     # all supplied gas consumed\n    state.increment_nonce(address)       # EIP-161: new contracts start at nonce 1\n    return run_init_code(state, sender, address, init_code, value, gas)\n```\n\nSolidity에서는 충돌한 `CREATE2` 배포가 단순히 제로 주소를 반환합니다.\n\n```solidity\naddress a;\nassembly { a := create2(0, add(code, 0x20), mload(code), salt) }\nrequire(a != address(0), \"create2 failed (e.g. address already in use)\");\n```\n\n## 알아둘 점\n\n- **이 제안은 Stagnant 상태이며 쓰여 있는 그대로는 채택되지 않았습니다.** 같은 충돌 규칙은 Final 상태의 [EIP-684](/eip-684/)(충돌 시 생성 revert)에 포함되어 있으며, 클라이언트는 이를 소급 적용합니다. [EIP-7610](/eip-7610/)은 이 검사를 스토리지가 비어 있지 않은 계정까지 확장합니다.\n- 명세에 따르면 이 규칙은 예정되어 있던 Constantinople 포크를 위한 [EIP-86](/eip-86/)에서 이미 다루어졌습니다. EIP-86 자체는 현재 Stagnant입니다.\n- 주소를 예측할 수 있게 되면 이 규칙은 더 중요해집니다. `CREATE2`([EIP-1014](/eip-1014/))에서는 같은 팩토리가 같은 salt로 같은 초기화 코드를 두 번 배포하면 두 번째가 실패합니다.\n- 명세는 이 규칙을 구현한 클라이언트와 그렇지 않은 클라이언트를 구분하는 테스트로 BlockchainTest의 `createJS_ExampleContract_d0g0v0_EIP158`을 꼽습니다.\n"},"zh":{"lang":"zh","tldr":"一项处于停滞状态的提案：当目标地址已有代码或 nonce 非零时，让合约创建直接失败；同样的规则已通过 EIP-684 被采纳。","tags":["evm","create","core","consensus","stagnant"],"related":[684,7610,161,1014,86],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-689/","markdown":"## 它解决什么问题？\n\n合约地址由哈希推导而来。理论上，新合约可以部署到已有代码的地址上。黄皮书规定，这时创建将从空代码和初始 nonce 开始，也就是说会**覆盖**已有的合约。\n\n在主网上这几乎不会发生，因为这需要 keccak256 碰撞。但共识测试套件包含了这类用例，而各客户端对其处理方式不一致。仅仅为了通过测试而支持“覆盖，并在创建回滚时撤销覆盖”，使客户端变得更复杂，却没有实际收益。\n\nEIP-689 提出了一条简单的规则：**如果地址已被占用，创建失败。**\n\n## 它如何运作\n\n从创世区块起（`block.number \u003e= 0`）：\n\n- 如果合约创建的目标账户的 **nonce 非零**或**代码非空**，创建会失败，**就像初始化代码遇到异常停止一样**。\n- 这既适用于合约创建交易，也适用于 `CREATE` 操作码。\n\n规范给出了两点好处：\n\n- **测试更简单。** 客户端不再需要回退代码覆盖。\n- **推理更简单。** 它建立了一个不变式：账户一旦有了代码，该代码就不会被另一次创建修改。\n\n由于从创世区块起应用此规则不会改变主网历史中的任何内容，规范称其向后兼容。\n\n## 示例代码\n\n合约创建开始时检查的伪代码：\n\n```python\ndef create_contract(state, sender, address, init_code, value, gas):\n    target = state.get(address)\n    if target is not None and (target.nonce != 0 or len(target.code) \u003e 0):\n        # Collision: behave like an exceptional halt in init code\n        return Failure(gas_used=gas)     # all supplied gas consumed\n    state.increment_nonce(address)       # EIP-161: new contracts start at nonce 1\n    return run_init_code(state, sender, address, init_code, value, gas)\n```\n\n在 Solidity 中，发生冲突的 `CREATE2` 部署只会返回零地址：\n\n```solidity\naddress a;\nassembly { a := create2(0, add(code, 0x20), mload(code), salt) }\nrequire(a != address(0), \"create2 failed (e.g. address already in use)\");\n```\n\n## 需要注意\n\n- **该提案处于 Stagnant 状态，并未按原文被采纳。** 同样的冲突规则是 Final 状态的 [EIP-684](/eip-684/)（冲突时回滚创建）的一部分，客户端对其追溯适用。[EIP-7610](/eip-7610/) 把该检查扩展到存储非空的账户。\n- 规范指出，该规则在计划中的 Constantinople 分叉里已由 [EIP-86](/eip-86/) 涵盖。EIP-86 本身现在也是 Stagnant。\n- 一旦地址可以预测，这条规则就更重要。使用 `CREATE2`（[EIP-1014](/eip-1014/)），同一个工厂用相同的 salt 部署相同的初始化代码两次，第二次会失败。\n- 规范点名了 BlockchainTest 中的 `createJS_ExampleContract_d0g0v0_EIP158`，它可以用来区分已实现该规则的客户端和未实现的客户端。\n"}}}
