{"eip":3541,"title":"Reject new contract code starting with the 0xEF byte","description":"Disallow new code starting with the 0xEF byte to be deployed. Code already existing in the account trie starting with 0xEF byte is not affected semantically by this change.","authors":["Alex Beregszaszi (@axic)","Paweł Bylica (@chfast)","Andrei Maiboroda (@gumb0)","Alexey Akhunov (@AlexeyAkhunov)","Christian Reitwiessner (@chriseth)","Martin Swende (@holiman)"],"status":"Final","type":"Standards Track","category":"Core","created":"2021-03-16","discussionsTo":"https://ethereum-magicians.org/t/evm-object-format-eof/5727","repo":"EIPs","label":"EIP-3541","officialUrl":"https://eips.ethereum.org/EIPS/eip-3541","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3541.md","url":"https://eips.huatuo.xyz/eip-3541/","tldr":{"en":"Since the London upgrade, any new contract whose code starts with the byte 0xEF is rejected, reserving that prefix for the EVM Object Format (EOF) and future code versioning.","ja":"London アップグレード以降、コードがバイト 0xEF で始まる新しいコントラクトは拒否され、そのプレフィックスは EVM Object Format（EOF）と将来のコードバージョン管理のために予約される。","ko":"London 업그레이드 이후, 코드가 바이트 0xEF로 시작하는 새 컨트랙트는 거부되며, 이 접두사는 EVM Object Format(EOF)과 향후의 코드 버전 관리를 위해 예약된다.","zh":"自 London 升级起，任何代码以字节 0xEF 开头的新合约都会被拒绝，该前缀被保留给 EVM 对象格式（EOF）和未来的代码版本管理。"},"tags":["evm","eof","contract-creation","core","london"],"explainers":{"en":{"lang":"en","tldr":"Since the London upgrade, any new contract whose code starts with the byte 0xEF is rejected, reserving that prefix for the EVM Object Format (EOF) and future code versioning.","tags":["evm","eof","contract-creation","core","london"],"related":[3540,3670,3860,7702],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-3541/","markdown":"## What problem does it solve?\n\nDevelopers wanted to introduce the EVM Object Format (EOF, [EIP-3540](/eip-3540/)): a structured container for contract code with a header, separate code and data sections, and validation at deploy time. To recognise EOF code, clients look for a magic prefix at the start. For that to be safe, no existing contract may already begin with the same bytes, or old, unvalidated code could be mistaken for EOF.\n\nEIP-3541 reserves the prefix ahead of time. By forbidding new code starting with `0xEF`, it guarantees that the only contracts in the state starting with that byte are the ones that existed before the fork, which can be checked once.\n\n## How it works\n\nAfter the fork block, contract creation via a create transaction, `CREATE` or `CREATE2` fails with an exceptional abort if the **returned runtime code** has `0xEF` as its first byte.\n\n- It is the deployed code that is checked, not the initcode.\n- The failure behaves like any other exceptional abort during creation: all gas given to the creation is consumed and no contract is deployed.\n- Existing code that already starts with `0xEF` is unaffected. Since `0xEF` was an undefined opcode, such code would abort as soon as it ran anyway.\n\nWhy `0xEF`? It reads as \"**E**xecutable **F**ormat\", it was unassigned (unlike `0xFD` `REVERT`, `0xFE` `INVALID`, `0xFF` `SELFDESTRUCT`), and an analysis of about 18 million contracts in May 2021 found none starting with `0xEF`.\n\nEIP-3541 went live on mainnet in the London upgrade (August 2021), alongside [EIP-1559](/eip-1559/).\n\n## Sample code\n\nThese initcodes come from the spec's test cases. Each stores one byte in memory and returns it as the contract code:\n\n```text\n0x60ef60005360016000f3   ; PUSH1 0xef PUSH1 0 MSTORE8 PUSH1 1 PUSH1 0 RETURN\n                         ; returns code 0xef -\u003e creation fails\n0x60fe60005360016000f3   ; same, but returns 0xfe -\u003e creation succeeds\n```\n\nSeeing it from ethers v6 on a test network (the first deployment succeeds, the second is mined but fails and uses all its gas):\n\n```ts\nimport { Wallet, JsonRpcProvider } from \"ethers\";\n\nconst wallet = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(process.env.RPC_URL));\n\nconst ok = await wallet.sendTransaction({ data: \"0x60fe60005360016000f3\", gasLimit: 100_000 });\nconsole.log((await ok.wait())?.contractAddress);      // new contract with code 0xfe\n\nconst bad = await wallet.sendTransaction({ data: \"0x60ef60005360016000f3\", gasLimit: 100_000 });\nawait bad.wait().catch((e) =\u003e console.log(e.code));  // \"CALL_EXCEPTION\": code starts with 0xEF\n```\n\n## Things to know\n\n- **Status: Final**, active on mainnet since London.\n- The rule also blocks \"data contracts\" (contracts used purely to store bytes, e.g. via SSTORE2-style patterns) whose data happens to start with `0xEF`. Prepend a non-`0xEF` byte, such as a `STOP` (`0x00`), to be safe.\n- The reserved prefix has since been used for more than EOF: [EIP-7702](/eip-7702/) delegation designators set on EOAs start with `0xef0100`. Those are written by the protocol, not deployed through `CREATE`.\n- If EOF were never adopted, the spec notes the restriction could simply be lifted later.\n"},"ja":{"lang":"ja","tldr":"London アップグレード以降、コードがバイト 0xEF で始まる新しいコントラクトは拒否され、そのプレフィックスは EVM Object Format（EOF）と将来のコードバージョン管理のために予約される。","tags":["evm","eof","contract-creation","core","london"],"related":[3540,3670,3860,7702],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-3541/","markdown":"## 何を解決するのか\n\n開発者は EVM Object Format（EOF、[EIP-3540](/eip-3540/)）を導入したいと考えていました。ヘッダー、独立したコードセクションとデータセクションを持ち、デプロイ時に検証される、コントラクトコードの構造化されたコンテナです。EOF のコードを認識するために、クライアントは先頭のマジックプレフィックスを探します。これを安全にするには、既存のコントラクトが同じバイト列で始まっていてはなりません。そうでないと、古くて検証されていないコードが EOF と誤認されかねません。\n\nEIP-3541 は、このプレフィックスを事前に予約します。`0xEF` で始まる新しいコードを禁止することで、ステート内でそのバイトで始まるコントラクトは、フォーク前から存在していたものだけだと保証され、それは一度確認すれば済みます。\n\n## 仕組み\n\nフォークブロックの後は、作成トランザクション、`CREATE`、`CREATE2` によるコントラクト作成は、**返されたランタイムコード**の最初のバイトが `0xEF` である場合、例外的中断で失敗します。\n\n- チェックされるのはデプロイされるコードであり、initcode ではありません。\n- 失敗は、作成中のほかの例外的中断と同じように動作します。作成に渡されたガスはすべて消費され、コントラクトはデプロイされません。\n- すでに `0xEF` で始まっている既存のコードには影響しません。`0xEF` は未定義のオペコードだったため、そのようなコードはどのみち実行されたとたんに中断されます。\n\nなぜ `0xEF` なのか。「**E**xecutable **F**ormat」と読めること、未割り当てだったこと（`0xFD` の `REVERT`、`0xFE` の `INVALID`、`0xFF` の `SELFDESTRUCT` とは違って）、そして 2021 年 5 月に約 1,800 万のコントラクトを分析したところ `0xEF` で始まるものが 1 つもなかったことが理由です。\n\nEIP-3541 は、London アップグレード（2021 年 8 月）で [EIP-1559](/eip-1559/) と一緒にメインネットで有効になりました。\n\n## サンプルコード\n\nこれらの initcode は仕様のテストケースのものです。それぞれ 1 バイトをメモリに保存し、それをコントラクトコードとして返します。\n\n```text\n0x60ef60005360016000f3   ; PUSH1 0xef PUSH1 0 MSTORE8 PUSH1 1 PUSH1 0 RETURN\n                         ; returns code 0xef -\u003e creation fails\n0x60fe60005360016000f3   ; same, but returns 0xfe -\u003e creation succeeds\n```\n\nテストネットで ethers v6 から確認する例です（1 回目のデプロイは成功し、2 回目はマイニングされますが失敗してガスをすべて使います）。\n\n```ts\nimport { Wallet, JsonRpcProvider } from \"ethers\";\n\nconst wallet = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(process.env.RPC_URL));\n\nconst ok = await wallet.sendTransaction({ data: \"0x60fe60005360016000f3\", gasLimit: 100_000 });\nconsole.log((await ok.wait())?.contractAddress);      // new contract with code 0xfe\n\nconst bad = await wallet.sendTransaction({ data: \"0x60ef60005360016000f3\", gasLimit: 100_000 });\nawait bad.wait().catch((e) =\u003e console.log(e.code));  // \"CALL_EXCEPTION\": code starts with 0xEF\n```\n\n## 知っておくべきこと\n\n- **ステータス：Final**。London 以降、メインネットで有効です。\n- このルールは、データがたまたま `0xEF` で始まる「データコントラクト」（SSTORE2 方式のパターンなど、純粋にバイト列を保存するために使われるコントラクト）も阻止します。安全のため、`STOP`（`0x00`）のような `0xEF` 以外のバイトを先頭に付けてください。\n- 予約されたプレフィックスは、その後 EOF 以外にも使われています。EOA に設定される [EIP-7702](/eip-7702/) の委任指定子は `0xef0100` で始まります。これらはプロトコルによって書き込まれるもので、`CREATE` を通じてデプロイされるものではありません。\n- EOF が採用されなかった場合は、この制限を後で単に解除できると仕様は述べています。\n"},"ko":{"lang":"ko","tldr":"London 업그레이드 이후, 코드가 바이트 0xEF로 시작하는 새 컨트랙트는 거부되며, 이 접두사는 EVM Object Format(EOF)과 향후의 코드 버전 관리를 위해 예약된다.","tags":["evm","eof","contract-creation","core","london"],"related":[3540,3670,3860,7702],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-3541/","markdown":"## 어떤 문제를 해결하나요?\n\n개발자들은 EVM Object Format(EOF, [EIP-3540](/eip-3540/))을 도입하고 싶어 했습니다. 헤더, 별도의 코드 섹션과 데이터 섹션을 갖추고 배포 시점에 검증되는 컨트랙트 코드용 구조화된 컨테이너입니다. EOF 코드를 알아보기 위해 클라이언트는 시작 부분의 매직 접두사를 찾습니다. 이것이 안전하려면 기존 컨트랙트가 같은 바이트로 시작해서는 안 됩니다. 그렇지 않으면 오래되고 검증되지 않은 코드가 EOF로 오인될 수 있습니다.\n\nEIP-3541은 이 접두사를 미리 예약합니다. `0xEF`로 시작하는 새 코드를 금지함으로써, 상태에서 그 바이트로 시작하는 컨트랙트는 포크 이전에 이미 존재하던 것뿐임을 보장하며, 이는 한 번만 확인하면 됩니다.\n\n## 어떻게 동작하나요?\n\n포크 블록 이후에는 생성 트랜잭션, `CREATE`, `CREATE2`를 통한 컨트랙트 생성이, **반환된 런타임 코드**의 첫 바이트가 `0xEF`이면 예외적 중단으로 실패합니다.\n\n- 검사되는 것은 배포되는 코드이지 initcode가 아닙니다.\n- 실패는 생성 중의 다른 예외적 중단과 똑같이 동작합니다. 생성에 주어진 모든 가스가 소모되고 컨트랙트는 배포되지 않습니다.\n- 이미 `0xEF`로 시작하는 기존 코드는 영향을 받지 않습니다. `0xEF`는 정의되지 않은 옵코드였기 때문에, 그런 코드는 어차피 실행되자마자 중단됩니다.\n\n왜 `0xEF`일까요? \"**E**xecutable **F**ormat\"으로 읽히고, 할당되지 않은 값이었으며(`0xFD` `REVERT`, `0xFE` `INVALID`, `0xFF` `SELFDESTRUCT`와 달리), 2021년 5월에 약 1,800만 개의 컨트랙트를 분석했을 때 `0xEF`로 시작하는 것이 하나도 없었기 때문입니다.\n\nEIP-3541은 London 업그레이드(2021년 8월)에서 [EIP-1559](/eip-1559/)와 함께 메인넷에 적용되었습니다.\n\n## 샘플 코드\n\n이 initcode들은 명세의 테스트 케이스에서 가져온 것입니다. 각각 바이트 하나를 메모리에 저장하고 그것을 컨트랙트 코드로 반환합니다.\n\n```text\n0x60ef60005360016000f3   ; PUSH1 0xef PUSH1 0 MSTORE8 PUSH1 1 PUSH1 0 RETURN\n                         ; returns code 0xef -\u003e creation fails\n0x60fe60005360016000f3   ; same, but returns 0xfe -\u003e creation succeeds\n```\n\n테스트 네트워크에서 ethers v6로 확인해 보기(첫 번째 배포는 성공하고, 두 번째는 채굴되지만 실패하며 가스를 전부 소모합니다):\n\n```ts\nimport { Wallet, JsonRpcProvider } from \"ethers\";\n\nconst wallet = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(process.env.RPC_URL));\n\nconst ok = await wallet.sendTransaction({ data: \"0x60fe60005360016000f3\", gasLimit: 100_000 });\nconsole.log((await ok.wait())?.contractAddress);      // new contract with code 0xfe\n\nconst bad = await wallet.sendTransaction({ data: \"0x60ef60005360016000f3\", gasLimit: 100_000 });\nawait bad.wait().catch((e) =\u003e console.log(e.code));  // \"CALL_EXCEPTION\": code starts with 0xEF\n```\n\n## 알아둘 점\n\n- **상태: Final**, London 이후 메인넷에서 활성화되어 있습니다.\n- 이 규칙은 데이터가 우연히 `0xEF`로 시작하는 \"데이터 컨트랙트\"(바이트를 저장하는 용도로만 쓰이는 컨트랙트, 예: SSTORE2 방식 패턴)도 막습니다. 안전하게 `STOP`(`0x00`) 같은 `0xEF`가 아닌 바이트를 앞에 붙이세요.\n- 예약된 접두사는 이후 EOF 외에도 쓰였습니다. EOA에 설정되는 [EIP-7702](/eip-7702/)의 위임 지정자는 `0xef0100`으로 시작합니다. 이들은 프로토콜이 기록하는 것이며 `CREATE`로 배포되는 것이 아닙니다.\n- EOF가 끝내 채택되지 않는다면 이 제한은 나중에 그냥 해제하면 된다고 명세는 언급합니다.\n"},"zh":{"lang":"zh","tldr":"自 London 升级起，任何代码以字节 0xEF 开头的新合约都会被拒绝，该前缀被保留给 EVM 对象格式（EOF）和未来的代码版本管理。","tags":["evm","eof","contract-creation","core","london"],"related":[3540,3670,3860,7702],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-3541/","markdown":"## 它解决什么问题？\n\n开发者想引入 EVM 对象格式（EOF，[EIP-3540](/eip-3540/)）：一种带有头部、独立的代码段和数据段，并在部署时验证的合约代码结构化容器。要识别 EOF 代码，客户端会查找开头的魔数前缀。为了保证这一点安全，现有合约不能已经以相同的字节开头，否则旧的、未经验证的代码可能被误认为 EOF。\n\nEIP-3541 提前保留了这个前缀。通过禁止新代码以 `0xEF` 开头，它保证状态中以该字节开头的合约只有分叉之前就存在的那些，而这一点只需检查一次。\n\n## 它如何运作\n\n分叉区块之后，通过创建交易、`CREATE` 或 `CREATE2` 创建合约时，如果**返回的运行时代码**的第一个字节是 `0xEF`，创建会以异常中止的方式失败。\n\n- 被检查的是部署的代码，而不是 initcode。\n- 这种失败的行为与创建过程中其他异常中止相同：给予创建的所有 gas 被消耗，且不会部署任何合约。\n- 已经以 `0xEF` 开头的现有代码不受影响。由于 `0xEF` 原本是未定义的操作码，这类代码一运行就会中止。\n\n为什么选 `0xEF`？它读起来像\"**E**xecutable **F**ormat\"，它当时未被分配（不同于 `0xFD` `REVERT`、`0xFE` `INVALID`、`0xFF` `SELFDESTRUCT`），而且 2021 年 5 月对约 1800 万个合约的分析发现，没有一个以 `0xEF` 开头。\n\nEIP-3541 在 London 升级（2021 年 8 月）中随 [EIP-1559](/eip-1559/) 一起在主网上线。\n\n## 示例代码\n\n这些 initcode 来自规范的测试用例。每个都把一个字节存入内存，并把它作为合约代码返回：\n\n```text\n0x60ef60005360016000f3   ; PUSH1 0xef PUSH1 0 MSTORE8 PUSH1 1 PUSH1 0 RETURN\n                         ; returns code 0xef -\u003e creation fails\n0x60fe60005360016000f3   ; same, but returns 0xfe -\u003e creation succeeds\n```\n\n在测试网上用 ethers v6 观察（第一次部署成功，第二次被打包但失败，并耗尽它的全部 gas）：\n\n```ts\nimport { Wallet, JsonRpcProvider } from \"ethers\";\n\nconst wallet = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(process.env.RPC_URL));\n\nconst ok = await wallet.sendTransaction({ data: \"0x60fe60005360016000f3\", gasLimit: 100_000 });\nconsole.log((await ok.wait())?.contractAddress);      // new contract with code 0xfe\n\nconst bad = await wallet.sendTransaction({ data: \"0x60ef60005360016000f3\", gasLimit: 100_000 });\nawait bad.wait().catch((e) =\u003e console.log(e.code));  // \"CALL_EXCEPTION\": code starts with 0xEF\n```\n\n## 需要注意\n\n- **状态：Final**，自 London 起在主网生效。\n- 该规则也会阻止\"数据合约\"（纯粹用于存储字节的合约，例如 SSTORE2 风格的模式），只要其数据恰好以 `0xEF` 开头。为稳妥起见，请在前面加一个非 `0xEF` 的字节，例如 `STOP`（`0x00`）。\n- 这个保留前缀后来的用途已不止 EOF：设置在 EOA 上的 [EIP-7702](/eip-7702/) 委托标识符以 `0xef0100` 开头。它们由协议写入，而不是通过 `CREATE` 部署。\n- 规范指出，如果 EOF 最终没有被采用，这一限制以后可以直接取消。\n"}},"requiredBy":[3540,7620,7702,8164,8337]}
