EIP-3541 · Final · Core · 2021-03-16
EIP-3541: Reject new contract code starting with the 0xEF byte
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.
What problem does it solve?
Developers wanted to introduce the EVM Object Format (EOF, 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.
EIP-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.
How it works
After 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.
- It is the deployed code that is checked, not the initcode.
- The failure behaves like any other exceptional abort during creation: all gas given to the creation is consumed and no contract is deployed.
- Existing code that already starts with
0xEFis unaffected. Since0xEFwas an undefined opcode, such code would abort as soon as it ran anyway.
Why 0xEF? It reads as "Executable Format", 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.
EIP-3541 went live on mainnet in the London upgrade (August 2021), alongside EIP-1559.
Sample code
These initcodes come from the spec's test cases. Each stores one byte in memory and returns it as the contract code:
0x60ef60005360016000f3 ; PUSH1 0xef PUSH1 0 MSTORE8 PUSH1 1 PUSH1 0 RETURN
; returns code 0xef -> creation fails
0x60fe60005360016000f3 ; same, but returns 0xfe -> creation succeeds
Seeing it from ethers v6 on a test network (the first deployment succeeds, the second is mined but fails and uses all its gas):
import { Wallet, JsonRpcProvider } from "ethers";
const wallet = new Wallet(process.env.PRIVATE_KEY!, new JsonRpcProvider(process.env.RPC_URL));
const ok = await wallet.sendTransaction({ data: "0x60fe60005360016000f3", gasLimit: 100_000 });
console.log((await ok.wait())?.contractAddress); // new contract with code 0xfe
const bad = await wallet.sendTransaction({ data: "0x60ef60005360016000f3", gasLimit: 100_000 });
await bad.wait().catch((e) => console.log(e.code)); // "CALL_EXCEPTION": code starts with 0xEF
Things to know
- Status: Final, active on mainnet since London.
- 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-0xEFbyte, such as aSTOP(0x00), to be safe. - The reserved prefix has since been used for more than EOF: EIP-7702 delegation designators set on EOAs start with
0xef0100. Those are written by the protocol, not deployed throughCREATE. - If EOF were never adopted, the spec notes the restriction could simply be lifted later.