Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines EIP-3541, which prohibits deploying new contract code beginning with the 0xEF byte in preparation for deployment-time validation of contracts conforming to the EVM Object Format (EOF).

The explanation below translates, summarizes, and expands on the original proposal.

I also cover a range of other EIPs.

Overview

The proposal prohibits deploying new code beginning with a particular byte, 0xEF. Existing code beginning with that byte in the account trie, a blockchain data structure, is unaffected.

Restricting new code deployments

Under the proposal, new code beginning with the 0xEF byte cannot be deployed to the blockchain.

Existing code remains unaffected

The change does not affect code already on the blockchain. Code beginning with 0xEF that was deployed before the rule changed retains its previous behavior. This provision avoids unnecessarily affecting existing systems and applications.

Semantic impact

Being semantically unaffected means that the change does not alter the behavior or meaning of existing code. The functionality and logic of already deployed contracts remain unchanged.

The proposal establishes a new deployment rule for a specific code format without changing existing code. It aims to improve blockchain security and consistency while preserving the behavior of previously deployed code.

Motivation

The proposal relates to a new Ethereum contract format known as the EVM Object Format (EOF).

EVM Object Format (EOF)

EVM stands for Ethereum Virtual Machine, the virtual machine that executes Ethereum smart contracts. EOF is a proposed format for smart contracts running on the EVM.

Traditional smart contracts are compiled into binary bytecode and deployed directly to the EVM, making their internal structure difficult to identify at a glance. EOF aims to address this by defining a more structured contract format that the EVM can interpret more readily.

The principal features of EOF are as follows.

Structured format Contract code and data are explicitly separated, making the format easier to understand and manage. This can help developers inspect and debug contracts.

Easier validation and optimization Contracts using EOF can undergo stricter validation before deployment. The format may also facilitate EVM execution optimizations and potentially reduce transaction execution costs.

Versioning support EOF includes version information to facilitate future upgrades of the EVM and contract format. Contracts can therefore adapt more readily as the Ethereum platform evolves.

Improved security A more explicit code structure makes it easier to detect certain potential security issues in advance, supporting safer smart contracts.

EOF is a proposed format intended to make deploying and executing Ethereum smart contracts more efficient and secure. It may simplify contract development and reduce transaction costs for users.

Validating EOF contracts

Contracts conforming to EOF are validated at deployment. This is intended to ensure that all deployed EOF contracts use a valid format.

Distinguishing existing contracts

Previously deployed and unvalidated contracts must not be mistaken for EOF contracts. The proposal uses a particular byte sequence known as a magic value to make the distinction. This magic value is a unique marker chosen so that it does not occur at the beginning of existing contracts.

Limiting the search space

To avoid having to inspect an ever-growing set of existing contracts when introducing the format, the proposal prohibits new contract code from beginning with the first byte of the magic value. This limits the analysis to contracts existing before the fork and prevents the search space from expanding.

Future flexibility

If EOF is ultimately not deployed, the magic value can be reserved for another feature or another mechanism that depends on versioning. If versioning becomes unnecessary, the restriction can be reversed by allowing contracts beginning with 0xEF to be deployed again.

The proposal prepares for validating new EOF contracts while retaining compatibility with existing contracts and allowing flexibility for future changes.

Specification

The proposal changes the rules governing deployment of Ethereum smart contracts. Starting at a specified block number called HF_BLOCK, creating a contract through a create transaction or a CREATE or CREATE2 instruction results in an exceptional halt if the first byte of the resulting contract code is 0xEF.

The role of initcode

initcode is the code executed during contract creation. When executed through CREATE or CREATE2, it returns the new contract's code using the RETURN instruction. The returned code is inserted into the account and becomes its contract code.

Handling the 0xEF opcode

At the time of the proposal, opcode 0xEF was undefined. Executing it does not pop or push stack items and causes an exceptional halt. Thus, executing initcode or previously deployed code beginning with 0xEF continues to cause an exceptional halt under these rules.

Exceptional halt behavior

An exceptional halt caused by returned code beginning with 0xEF behaves like other exceptional halts that can occur during initcode execution. When a CREATE operation or contract creation transaction halts exceptionally, all gas supplied to that operation is consumed.

Such restrictions can help maintain protocol consistency and prevent unexpected or malicious behavior. They also encourage developers to design contract code carefully and avoid relying on undefined instructions.

Rationale

This section explains why the particular byte value 0xEF was chosen for Ethereum smart contract code.

Choosing the 0xEF byte

The byte 0xEF was chosen because it suggests Executable Format. It serves as a marker indicating that executable code follows a particular standard or convention.

Using an unassigned opcode

Using unassigned opcodes in smart contracts carries a recognized risk: if the Ethereum protocol later assigns behavior to such an opcode, the meaning of the contract may change. Using an unassigned opcode such as 0xEF was therefore considered less disruptive than using assigned opcodes such as 0xFD (REVERT), 0xFE (INVALID), or 0xFF (SELFDESTRUCT).

Analysis of existing contracts

According to an analysis from May 2021, among approximately 18,084,433 contracts, none began with 0xEF. By comparison, 1, 4, and 12 contracts began with 0xFD, 0xFE, and 0xFF, respectively. This analysis suggested that choosing 0xEF would allow the new rule to be introduced without affecting existing contracts.

The rationale is to select 0xEF as a marker for a specific condition during new contract creation. The choice aims to avoid affecting existing contracts and minimize risks arising from the use of an unassigned opcode.

Test cases

The proposal describes test cases executed in different contexts: a create transaction, a CREATE instruction, and a CREATE2 instruction. These cases attempt to deploy new contract code beginning with a particular byte value, such as 0xEF or 0xFE. The Calldata column shows the data supplied to the transaction or instruction; the expected result describes the anticipated outcome.

  • create transaction
    • Creates a new contract without existing account code in the execution context.
  • CREATE instruction
    • Creates a new contract in a context with existing account code, here 0x6000356000523660006000f0151560165760006000fd5b.
  • CREATE2 instruction
    • Creates a new contract in a different context with existing account code, here 0x60003560005260003660006000f5151560185760006000fd5b.

Each test result indicates whether the deployment succeeds or fails for a specific reason, in this case because the first byte of the new code is 0xEF.

The following table lists the test cases and their expected results.

Case Calldata Expected result
deploy one byte ef 0x60ef60005360016000f3 new contract not deployed, transaction fails
deploy two bytes ef00 0x60ef60005360026000f3 new contract not deployed, transaction fails
deploy three bytes ef0000 0x60ef60005360036000f3 new contract not deployed, transaction fails
deploy 32 bytes ef00...00 0x60ef60005360206000f3 new contract not deployed, transaction fails
deploy one byte fe 0x60fe60005360016000f3 new contract deployed, transaction succeeds

As the table shows, all attempts to deploy new contract code beginning with 0xEF are expected to fail. The new protocol rule prohibits deployment of code with that prefix. By contrast, deployment of contract code beginning with 0xFE is expected to succeed. That prefix is not subject to the new restriction.

Backward compatibility

The change prohibits deploying new contract code starting with 0xEF. It is a breaking change because new contract creation attempts with that code prefix now fail. However, since execution begins at the first byte of the bytecode, code beginning with the undefined opcode 0xEF would not have been executable under the previous rules either.

Breaking change

New code beginning with 0xEF can no longer be deployed. The restriction is breaking because it changes the deployment process by disallowing a particular code pattern.

Non-executable code

Under the rules described in the proposal, code starting with 0xEF cannot execute from its first byte. This is because the byte represents an undefined instruction for which the EVM has no execution behavior.

Existing executable contracts remain unaffected

The change does not affect previously deployed executable contracts. Existing working contracts therefore retain their behavior.

Rejecting new data contract deployments

The change does, however, prevent deployment of new data contracts whose code begins with 0xEF. Data contracts are smart contracts used primarily to store or manage data. Because they often do not contain executable code, a leading 0xEF byte could previously have been useful as data. The new rule prevents deployment of such contracts.

The important distinction is that the change affects new contract deployments, not existing executable contracts.

Security considerations

The proposal identifies no particular security or denial-of-service (DoS) risks arising from the change.

Citation

Alex Beregszaszi (@axic), Paweł Bylica (@chfast), Andrei Maiboroda (@gumb0), Alexey Akhunov (@AlexeyAkhunov), Christian Reitwiessner (@chriseth), Martin Swende (@holiman), "EIP-3541: Reject new contract code starting with the 0xEF byte," Ethereum Improvement Proposals, no. 3541, March 2021. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-3541.

Conclusion

This article covered EIP-3541, a proposal prohibiting new contract code beginning with 0xEF in preparation for deployment-time validation of EOF contracts.

If you have any questions, feel free to reach out via Twitter DM.

Twitter @cardene777

I also publish on the following platforms.

https://chaldene.net/