{"eip":684,"title":"Revert creation in case of collision","description":"Revert contract creation if address already has code","authors":["Vitalik Buterin (@vbuterin)","Renan Rodrigues de Souza (@RenanSouza2)"],"status":"Final","type":"Standards Track","category":"Core","created":"2023-03-20","discussionsTo":"https://ethereum-magicians.org/t/eip-revert-on-address-collision/13442","repo":"EIPs","label":"EIP-684","officialUrl":"https://eips.ethereum.org/EIPS/eip-684","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-684.md","url":"https://eips.huatuo.xyz/eip-684/","tldr":{"en":"Makes contract creation fail if the target address already has code or a nonzero nonce, so deployed code can never be silently replaced by a second \"creation\" at the same address.","ja":"作成先のアドレスにすでにコードまたは 0 でない nonce がある場合、コントラクト作成を失敗させる。デプロイ済みのコードが、同じアドレスでの 2 回目の「作成」によって黙って置き換えられることを防ぐ。","ko":"대상 주소에 이미 코드가 있거나 nonce가 0이 아니면 컨트랙트 생성을 실패시킨다. 배포된 코드가 같은 주소에서의 두 번째 \"생성\"으로 조용히 교체되는 일이 없게 한다.","zh":"如果目标地址已有代码或 nonce 不为零，合约创建就会失败，使已部署的代码绝不可能被同一地址上的第二次\"创建\"悄悄替换。"},"tags":["evm","create2","security","core"],"explainers":{"en":{"lang":"en","tldr":"Makes contract creation fail if the target address already has code or a nonzero nonce, so deployed code can never be silently replaced by a second \"creation\" at the same address.","tags":["evm","create2","security","core"],"related":[1014,7610,6780,161,3607],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-684/","markdown":"## What problem does it solve?\n\nA basic promise of smart contracts is that the code at an address does not change. Contract addresses come from a hash: the sender and nonce for `CREATE`, or the deployer, salt and init code hash for [`CREATE2`](/eip-1014/). If two different creations could land on the same address and the second one overwrote the first, an attacker with enough computing power could find such a collision. They could then deploy harmless-looking code, win users' trust and funds, and later swap in malicious code.\n\nEIP-684 closes that door: an address that is already \"in use\" cannot be created again.\n\n## How it works\n\nFor **every** kind of contract creation (a creation transaction, `CREATE`, `CREATE2`, or anything else):\n\n- if the destination address has a **nonzero nonce**, or\n- if the destination address has **nonzero code length**,\n\nthe creation fails exactly **as if the first byte of the init code were an invalid opcode**. All gas given to the creation is used up, the caller gets `0` (the zero address) on the stack, and no state changes.\n\nThe rule applies **retroactively from genesis**. It is not a new behaviour: it began as GitHub issue #684, and [EIP-1014](/eip-1014/) (2018) already quotes it as the rule for collisions. The EIP document itself was written up in 2023 to record it formally.\n\nAn account that only has a balance (nonce 0, no code) is not a collision. ETH sent to a future `CREATE2` address in advance does not block deployment.\n\n## Sample code\n\nDeploying twice with the same `CREATE2` salt. The second attempt hits the EIP-684 rule:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Child {}\n\ncontract Factory {\n    function deploy(bytes32 salt) external returns (address) {\n        return address(new Child{salt: salt}());\n    }\n}\n\n// factory.deploy(0x01)  -\u003e succeeds, returns 0xAbC...\n// factory.deploy(0x01)  -\u003e reverts: address already has code and nonce 1\n```\n\nThe same check written as client pseudocode:\n\n```python\ndef can_create_at(state, addr) -\u003e bool:\n    acct = state.get(addr)\n    return acct.nonce == 0 and len(acct.code) == 0\n```\n\n## Things to know\n\n- Because a newly created contract's nonce starts at 1 ([EIP-161](/eip-161/)), a second creation at the same address in the same transaction always fails, even before any code is stored.\n- `SELFDESTRUCT` used to clear the account, which allowed \"metamorphic\" contracts: destroy, then `CREATE2` again with the same salt and different code. [EIP-6780](/eip-6780/) removed this, except when both happen in the same transaction.\n- [EIP-7610](/eip-7610/) (in Last Call) extends the rule to addresses that have **non-empty storage**.\n- The opposite case, where a transaction is sent *from* an address that has code, is handled by [EIP-3607](/eip-3607/).\n"},"ja":{"lang":"ja","tldr":"作成先のアドレスにすでにコードまたは 0 でない nonce がある場合、コントラクト作成を失敗させる。デプロイ済みのコードが、同じアドレスでの 2 回目の「作成」によって黙って置き換えられることを防ぐ。","tags":["evm","create2","security","core"],"related":[1014,7610,6780,161,3607],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-684/","markdown":"## 何を解決するのか\n\nスマートコントラクトの基本的な約束は、アドレス上のコードが変わらないことです。コントラクトのアドレスはハッシュから決まります。`CREATE` では送信者と nonce、[`CREATE2`](/eip-1014/) ではデプロイヤー、salt、init code のハッシュです。もし 2 つの異なる作成が同じアドレスに行き着き、2 つ目が 1 つ目を上書きできるとしたら、十分な計算能力を持つ攻撃者はそのような衝突を見つけられます。そして無害に見えるコードをデプロイしてユーザーの信頼と資金を集め、後から悪意のあるコードに差し替えることができます。\n\nEIP-684 はこの抜け道をふさぎます。すでに「使用中」のアドレスは、再び作成できません。\n\n## 仕組み\n\n**あらゆる**種類のコントラクト作成（作成トランザクション、`CREATE`、`CREATE2`、その他）について:\n\n- 作成先のアドレスの **nonce が 0 でない**場合、または\n- 作成先のアドレスの**コード長が 0 でない**場合、\n\n作成は、**init code の最初のバイトが無効な opcode であった場合とまったく同様に**失敗します。作成に渡されたすべての gas が消費され、呼び出し元にはスタック上で `0`（ゼロアドレス）が返り、状態は一切変わりません。\n\nこのルールは**ジェネシスまで遡って**適用されます。新しい挙動ではありません。GitHub の issue #684 として始まり、[EIP-1014](/eip-1014/)（2018 年）が衝突時のルールとしてすでに引用しています。EIP の文書自体は、これを正式に記録するため 2023 年に書かれました。\n\n残高だけを持つアカウント（nonce が 0 でコードなし）は衝突ではありません。将来の `CREATE2` アドレスに ETH を事前に送っておいても、デプロイは妨げられません。\n\n## サンプルコード\n\n同じ `CREATE2` の salt で 2 回デプロイする例。2 回目は EIP-684 のルールに引っかかります。\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Child {}\n\ncontract Factory {\n    function deploy(bytes32 salt) external returns (address) {\n        return address(new Child{salt: salt}());\n    }\n}\n\n// factory.deploy(0x01)  -\u003e succeeds, returns 0xAbC...\n// factory.deploy(0x01)  -\u003e reverts: address already has code and nonce 1\n```\n\n同じチェックをクライアントの擬似コードで書くと:\n\n```python\ndef can_create_at(state, addr) -\u003e bool:\n    acct = state.get(addr)\n    return acct.nonce == 0 and len(acct.code) == 0\n```\n\n## 知っておくべきこと\n\n- 新しく作成されたコントラクトの nonce は 1 から始まる（[EIP-161](/eip-161/)）ため、同じトランザクション内で同じアドレスに 2 回目の作成を行うと、コードが保存される前でも必ず失敗します。\n- 以前は `SELFDESTRUCT` がアカウントを消去できたため、「メタモルフィック」コントラクトが可能でした。破棄してから、同じ salt で異なるコードを `CREATE2` し直す手法です。[EIP-6780](/eip-6780/) は、両方が同じトランザクション内で起きる場合を除き、これを不可能にしました。\n- [EIP-7610](/eip-7610/)（Last Call）は、このルールを**空でないストレージ**を持つアドレスにも拡張します。\n- 逆のケース、つまりコードを持つアドレス*から*トランザクションが送信される場合は、[EIP-3607](/eip-3607/) が扱います。\n"},"ko":{"lang":"ko","tldr":"대상 주소에 이미 코드가 있거나 nonce가 0이 아니면 컨트랙트 생성을 실패시킨다. 배포된 코드가 같은 주소에서의 두 번째 \"생성\"으로 조용히 교체되는 일이 없게 한다.","tags":["evm","create2","security","core"],"related":[1014,7610,6780,161,3607],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-684/","markdown":"## 어떤 문제를 해결하나요?\n\n스마트 컨트랙트의 기본 약속은 주소에 있는 코드가 바뀌지 않는다는 것입니다. 컨트랙트 주소는 해시에서 나옵니다. `CREATE`는 발신자와 nonce, [`CREATE2`](/eip-1014/)는 배포자, salt, init code 해시를 씁니다. 서로 다른 두 생성이 같은 주소에 도달할 수 있고 두 번째가 첫 번째를 덮어쓸 수 있다면, 충분한 연산 능력을 가진 공격자가 그런 충돌을 찾을 수 있습니다. 그러면 무해해 보이는 코드를 배포해 사용자의 신뢰와 자금을 얻은 뒤, 나중에 악성 코드로 바꿔치기할 수 있습니다.\n\nEIP-684는 이 문을 닫습니다. 이미 \"사용 중\"인 주소는 다시 생성할 수 없습니다.\n\n## 어떻게 동작하나요?\n\n**모든** 종류의 컨트랙트 생성(생성 트랜잭션, `CREATE`, `CREATE2`, 그 밖의 어떤 방식이든)에 대해:\n\n- 대상 주소의 **nonce가 0이 아니거나**,\n- 대상 주소의 **코드 길이가 0이 아니면**,\n\n생성은 **init code의 첫 바이트가 유효하지 않은 옵코드인 것과 똑같이** 실패합니다. 생성에 전달된 gas는 모두 소모되고, 호출자는 스택에서 `0`(제로 주소)을 받으며, 상태는 전혀 바뀌지 않습니다.\n\n이 규칙은 **제네시스부터 소급해서** 적용됩니다. 새로운 동작이 아닙니다. GitHub 이슈 #684로 시작되었고, [EIP-1014](/eip-1014/)(2018년)가 이미 충돌 시 규칙으로 인용합니다. EIP 문서 자체는 이를 공식적으로 기록하려고 2023년에 작성되었습니다.\n\n잔액만 있는 계정(nonce 0, 코드 없음)은 충돌이 아닙니다. 미래의 `CREATE2` 주소로 ETH를 미리 보내 두어도 배포가 막히지 않습니다.\n\n## 샘플 코드\n\n같은 `CREATE2` salt로 두 번 배포하는 예입니다. 두 번째 시도는 EIP-684 규칙에 걸립니다.\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Child {}\n\ncontract Factory {\n    function deploy(bytes32 salt) external returns (address) {\n        return address(new Child{salt: salt}());\n    }\n}\n\n// factory.deploy(0x01)  -\u003e succeeds, returns 0xAbC...\n// factory.deploy(0x01)  -\u003e reverts: address already has code and nonce 1\n```\n\n같은 검사를 클라이언트 의사 코드로 쓰면:\n\n```python\ndef can_create_at(state, addr) -\u003e bool:\n    acct = state.get(addr)\n    return acct.nonce == 0 and len(acct.code) == 0\n```\n\n## 알아둘 점\n\n- 새로 생성된 컨트랙트의 nonce는 1에서 시작하므로([EIP-161](/eip-161/)), 같은 트랜잭션 안에서 같은 주소에 두 번째 생성을 하면 코드가 저장되기 전이라도 항상 실패합니다.\n- `SELFDESTRUCT`는 예전에는 계정을 지웠기 때문에 \"메타모픽\" 컨트랙트가 가능했습니다. 파괴한 뒤 같은 salt와 다른 코드로 다시 `CREATE2`하는 방식입니다. [EIP-6780](/eip-6780/)은 둘이 같은 트랜잭션에서 일어나는 경우를 제외하고 이를 없앴습니다.\n- [EIP-7610](/eip-7610/)(Last Call)은 이 규칙을 **스토리지가 비어 있지 않은** 주소로 확장합니다.\n- 반대의 경우, 즉 코드가 있는 주소*에서* 트랜잭션을 보내는 경우는 [EIP-3607](/eip-3607/)이 다룹니다.\n"},"zh":{"lang":"zh","tldr":"如果目标地址已有代码或 nonce 不为零，合约创建就会失败，使已部署的代码绝不可能被同一地址上的第二次\"创建\"悄悄替换。","tags":["evm","create2","security","core"],"related":[1014,7610,6780,161,3607],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-684/","markdown":"## 它解决什么问题？\n\n智能合约的一个基本承诺是：某个地址上的代码不会改变。合约地址由哈希得出：`CREATE` 使用发送者和 nonce，[`CREATE2`](/eip-1014/) 使用部署者、salt 和 init code 哈希。如果两次不同的创建可能落在同一个地址上，并且第二次可以覆盖第一次，那么拥有足够算力的攻击者就能找到这样的碰撞。随后他们可以部署看似无害的代码，赢得用户的信任和资金，再换成恶意代码。\n\nEIP-684 堵上了这扇门：已经\"被占用\"的地址不能被再次创建。\n\n## 它如何运作\n\n对于**每一种**合约创建（创建交易、`CREATE`、`CREATE2` 或其他任何方式）：\n\n- 如果目标地址的 **nonce 不为零**，或者\n- 如果目标地址的**代码长度不为零**，\n\n创建就会失败，其效果**与 init code 的第一个字节是无效操作码时完全一样**。分配给创建的所有 gas 都被耗尽，调用者在栈上得到 `0`（零地址），状态不发生任何改变。\n\n该规则**从创世区块起追溯适用**。它并不是新的行为：它起源于 GitHub issue #684，而 [EIP-1014](/eip-1014/)（2018 年）已经把它引用为碰撞时的规则。EIP 文档本身是 2023 年为了正式记录这一点而撰写的。\n\n只有余额的账户（nonce 为 0、没有代码）不算碰撞。提前向未来的 `CREATE2` 地址发送 ETH 不会阻碍部署。\n\n## 示例代码\n\n用同一个 `CREATE2` salt 部署两次。第二次尝试会触发 EIP-684 的规则：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Child {}\n\ncontract Factory {\n    function deploy(bytes32 salt) external returns (address) {\n        return address(new Child{salt: salt}());\n    }\n}\n\n// factory.deploy(0x01)  -\u003e succeeds, returns 0xAbC...\n// factory.deploy(0x01)  -\u003e reverts: address already has code and nonce 1\n```\n\n用客户端伪代码写出的同一检查：\n\n```python\ndef can_create_at(state, addr) -\u003e bool:\n    acct = state.get(addr)\n    return acct.nonce == 0 and len(acct.code) == 0\n```\n\n## 需要注意\n\n- 由于新创建合约的 nonce 从 1 开始（[EIP-161](/eip-161/)），在同一笔交易中对同一地址进行第二次创建总会失败，即使还没有存储任何代码也是如此。\n- `SELFDESTRUCT` 过去会清除账户，这使得\"变形\"（metamorphic）合约成为可能：先销毁，再用同一个 salt 和不同的代码再次 `CREATE2`。[EIP-6780](/eip-6780/) 取消了这一点，除非两者发生在同一笔交易中。\n- [EIP-7610](/eip-7610/)（Last Call）把该规则扩展到**存储非空**的地址。\n- 相反的情况，即交易是从一个有代码的地址*发出*的，由 [EIP-3607](/eip-3607/) 处理。\n"}},"requiredBy":[7620,8037,8253,8360]}
