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-2327.

The proposal defines BEGINDATA, an opcode marking the boundary between executable instructions and trailing data in contract bytecode. Subsequent bytes remain readable but cannot be executed or jumped to.

The existing illustrations are retained and may contain Japanese labels.

Overview

Contract bytecode may contain constants, compiler metadata, and runtime code used during initialization, in addition to executable instructions. The traditional EVM does not distinguish trailing bytes as data, so analyzers process them as instructions through the end of the bytecode.

EIP-2327 assigns BEGINDATA to byte value 0xb6. Everything after the first BEGINDATA is treated as data and excluded from execution and valid JUMPDEST analysis.

Separating executable code and data with BEGINDATA

The boundary changes how the EVM interprets subsequent bytes, not where the data is stored. The data remains part of the code and can be read through CODECOPY and EXTCODECOPY.

Motivation

A data region may contain 0x5b without the developer intending it to be a jump destination. Without a boundary, disassemblers, block explorers, and static analyzers process such bytes as part of the instruction sequence.

Calculating valid JUMPDEST locations therefore includes data that is never intended to execute. Disassembly may display meaningless instructions, and control-flow verification processes unnecessary bytes.

Analysis with and without a data boundary

Stopping analysis at the first BEGINDATA prevents data from being included in the candidate control flow. The proposal also mentions reducing unnecessary jump analysis when verifying transactions from another chain on-chain.

Specification

Only the first BEGINDATA instruction defines the boundary. Neither the boundary position nor any subsequent position is a valid jump destination.

Stopping JUMPDEST analysis at the first BEGINDATA

BEGINDATA

js
BEGINDATA // 0xb6

BEGINDATA indicates the end of executable instructions. Computation of valid JUMPDEST locations stops when the first BEGINDATA is reached.

  1. Read bytecode from the beginning. The analyzer processes instructions and records valid JUMPDEST locations until it reaches BEGINDATA.
  2. Stop at the first boundary. Neither the boundary itself nor later positions are added to the set of valid jump destinations.
  3. Stop the execution frame when reached. Execution reaching BEGINDATA terminates the current call frame with the same semantics as STOP.

Execution conditions

  • Jumping to BEGINDATA causes BAD_JUMP_DESTINATION.
  • BEGINDATA costs zero gas.

Execution stops when BEGINDATA is reached

Even if bytecode contains multiple 0xb6 values, only the first BEGINDATA instruction stops analysis. Later bytes are not interpreted as instructions, so subsequent occurrences have no special meaning.

Properties Retained by the Data Region

BEGINDATA does not remove trailing bytes; it marks them as non-executable. Copy instructions and code-size behavior remain unchanged.

Readable but non-executable data region

  • CODECOPY and EXTCODECOPY can read the trailing bytes, including the data region.
  • CODESIZE and EXTCODESIZE return the size of the entire code, including the data region.
  • A 0x5b byte in the data region is not a valid JUMPDEST.

Additional Considerations

BEGINDATA previously appeared in EIP-615, concerning subroutines and static jumps, as a way to identify jump table locations. EIP-2327 defines it independently, focusing on separating code from data.

BEGINDATA as a standalone code-data boundary

EIP-2327 has Stagnant status. It has not been adopted by Ethereum, so BEGINDATA should not be assumed to be available in the current EVM or Solidity output.

Test Cases

The proposal tests analysis and execution separately.

Testing rejected jumps and execution termination separately

  1. Jump to 0x5b inside the data region. Jumping to 0x5b after BEGINDATA causes BAD_JUMP_DESTINATION.
  2. Reach BEGINDATA through execution. The current call frame stops.

Reading trailing data through copy instructions and including it in code size should also be checked separately. Rejecting a jump destination alone does not verify those rules.

Backward Compatibility

Affected bytecode is code containing the previously unused 0xb6 byte as data while jumping over that position to later executable instructions. Solidity did not generate this structure according to the proposal, so ordinary compiler output did not depend on it.

Ordinary output and bytecode that jumps over 0xb6

For hand-written bytecode or specialized generators, check the positions of 0xb6 and jump destinations. A structure that jumps over the first BEGINDATA boundary cannot work in an environment implementing the proposal.

Reference Implementation

The proposal does not include a reference implementation. An implementation should separately verify termination of JUMPDEST analysis, STOP behavior on execution, copy instructions, and code sizes.

EVM behavior to verify without a reference implementation

Check that CODECOPY and EXTCODECOPY can read data and that CODESIZE and EXTCODESIZE remain unchanged, independently of jump destination tests.

Security

Correct control-flow verification requires that a 0x5b byte occurring in the data region is not mistaken for a valid JUMPDEST. Analysis stops at the first BEGINDATA, and a jump to the boundary itself is also rejected.

Data remains public even when excluded from execution

Non-executable data is not confidential. The data remains readable through CODECOPY and EXTCODECOPY and must not be used to store private keys or confidential inputs.

Conclusion

EIP-2327 proposes retaining trailing bytecode as data while excluding it from execution and jump destination analysis. Implementations must verify boundary analysis, termination on reaching the boundary, and access to trailing data separately. The proposal is Stagnant and does not define an opcode currently available on Ethereum.

Further reading and author links: