EIP-2327 The BEGINDATA opcode (BEGINDATA opcode)

No call decision · EVM & execution · EIP status Stagnant · created 2019-10-28

Adds a new opcode, BEGINDATA, that separates the data region from the code region in contract bytecode, so that data is never executed or treated as a jump destination.

Why it is needed

Smart contracts often store data such as constructor arguments, constants, and compiler metadata directly inside the bytecode. However, since this data is not currently distinguished from code, the EVM interpreter runs JUMPDEST analysis over the data region as well. As a result, static analysis tools, disassemblers, chain explorers, and debuggers have no choice but to display the data region as a pile of INVALID opcodes. In addition, when verifying transactions from another chain on-chain (as used by the Optimism project), checking whether code follows a certain pattern requires a full jumpdest analysis, which also burdens scalability. BEGINDATA solves this problem and lays the groundwork for follow-up proposals such as banning unused opcodes and jump tables.

What changes

Today

After EIP-2327

Who is affected

In depth

Opcode definition and position

BEGINDATA is a new opcode added at byte 0xb6. It was first proposed in EIP-615 (Subroutines and Static Jumps for the EVM) as a way to mark jump table locations; this EIP splits it out into an independent proposal for the purpose of excluding data from JUMPDEST analysis. The value 0xb6 was chosen to align with EIP-615.

Change to JUMPDEST analysis

When computing a contract's list of valid JUMPDESTs, analysis stops upon encountering the first BEGINDATA. That is, any jump to a code position equal to or greater than the BEGINDATA position raises a BAD_JUMP_DESTINATION error. Even if the data region happens to contain 0x5b (the JUMPDEST byte), it cannot become a jump target.

Behavior during execution

When execution flow reaches BEGINDATA, the effect is identical to STOP: execution of the current call frame halts. The gas cost is zero. The Rationale notes that halting via out-of-gas instead of STOP was also considered, but the specification states that the STOP approach was chosen.

Relationship with CODESIZE and CODECOPY

Bytes after BEGINDATA can still be copied and read via CODECOPY and EXTCODECOPY. BEGINDATA also has no effect on the values returned by CODESIZE and EXTCODESIZE. In other words, the code length itself remains unchanged; only jumpability and executability change.

Backward compatibility

Most existing contracts are unaffected. However, contracts that hide data using unused opcodes designed to be skipped without execution could be affected. The Solidity compiler has never generated such code structures, but the original text notes that whether such cases exist in contracts produced by other means should be evaluated separately.

Purpose: static analysis and scalability

Excluding the data region from JUMPDEST analysis means static analysis tools, disassemblers, chain explorers, and debuggers no longer need to display data as a pile of INVALID opcodes. It also explains that this helps scalability, since verifying transactions from other chains on-chain (as used by the Optimism project) no longer requires a full jumpdest analysis to check whether code follows a certain pattern.

Relationship to follow-up proposals

The Motivation section notes that this EIP lays the groundwork for a proposal banning unused opcodes (EIP-1712), EIP-615 which deals with jump tables, and speculative proposals to ban deployment of contracts with stack usage violations.

Current status

This EIP's status is Stagnant, and the Implementation section remains empty, marked 'Not yet.' The test cases are only presented as a specification, with no actual implementation or inclusion progress made. The call records also show no confirmed fork inclusion decision for this EIP.

Original EIP · ← EIPs