EIPs Explained

EIP-4520 · Stagnant · Core · 2021-12-01

EIP-4520: Multi-byte opcodes prefixed by EB and EC.

Proposed reserving the unused opcodes 0xEB and 0xEC as prefixes for two- and three-byte opcodes, so the EVM could grow beyond 256 instructions.

What problem does it solve?

Every EVM instruction is a single byte, so there can be at most 256 opcodes. Many slots are already used, and new features (new arithmetic, new call variants, experimental instructions) keep competing for the remaining ones. Rarely used instructions don't really need to be one byte; spending a short opcode on them is wasteful.

EIP-4520 proposes an "escape hatch": keep single-byte opcodes for common operations and open a much larger space of multi-byte opcodes for everything else.

How it works

  • 0xEB and 0xEC are reserved as prefix bytes. A prefix plus one following byte forms a two-byte opcode, giving up to 2 × 255 = 510 new instructions.
  • The second byte can mirror an existing opcode for related functionality. The spec's examples: a new arithmetic op at 0xEC 01 (next to ADD) and a new call variant at 0xEB F4 (next to DELEGATECALL).
  • Doubling the prefix (0xEB EB, 0xEC EC, 0xEB EC, 0xEC EB) opens a three-byte space. The idea is to place experimental opcodes there first and promote them to shorter encodings later if they prove useful and safe.
  • The prefix bytes themselves do not touch the stack or memory. An undefined multi-byte opcode behaves like any undefined opcode: INVALID, not NOP.

Both bytes were chosen from the unassigned 0xE* range, which also contains 0xEF, the byte reserved for the EVM Object Format (EIP-3540).

Sample code

How a disassembler might decode the proposed scheme (pseudocode):

PREFIXES = {0xEB, 0xEC}

def next_opcode(code: bytes, pc: int) -> tuple[bytes, int]:
    """Return (opcode bytes, length) at pc under EIP-4520."""
    if code[pc] not in PREFIXES:
        return code[pc:pc + 1], 1                  # ordinary 1-byte opcode
    if pc + 1 < len(code) and code[pc + 1] in PREFIXES:
        return code[pc:pc + 3], 3                  # e.g. EB EB xx (3-byte)
    return code[pc:pc + 2], 2                      # e.g. EC 01 (2-byte)

# Any multi-byte opcode not yet defined executes as INVALID.

Things to know

  • Status: Stagnant. It was never scheduled for a network upgrade, and 0xEB/0xEC are not reserved as prefixes on mainnet.
  • Backwards-compatibility caveat from the spec: if 0xEB/0xEC were ever assigned meanings in deployed code, reinterpreting them could break that code.
  • Later work on extending the instruction set has mostly gone through EOF, which adds immediates and code validation instead of prefix bytes (e.g. EIP-663 DUPN/SWAPN).
  • With legacy (non-EOF) bytecode, multi-byte opcodes also complicate jump-destination analysis, because a byte might be the second half of an instruction.

#evm #opcodes #core #eof

Details

Authors
Brayton Goodall (@Spore-Druid-Bray), Mihir Faujdar (@uink45)
Status
Stagnant
Type
Standards Track / Core
Created
2021-12-01

Machine-readable: Markdown · JSON