EIPs Explained

EIP-7937 · Draft · Core · 2025-04-23

EIP-7937: EVM64 - 64-bit mode EVM opcodes

Adds a `C0` prefix byte that switches the next opcode into a cheaper 64-bit mode, so arithmetic, comparisons, bitwise ops and jumps that don't need 256 bits run with fewer cycles and less gas.

What problem does it solve?

Every EVM stack item is 256 bits wide, and every arithmetic opcode works on the full width. That suits hashes and token amounts, but most loop counters, indexes, offsets and many algorithms only need 64 bits. On real 64-bit CPUs a 256-bit add is several machine operations, while a 64-bit add is one. Contracts doing heavy computation pay for width they never use.

EVM64 introduces a "64-bit mode" for common opcodes, priced lower to reflect the cheaper work, while using only a single new byte of opcode space.

How it works

  • Prefix byte C0. When the interpreter meets C0, it reads the next byte and executes that operation in 64-bit mode, then advances PC by 2. An unknown second byte is an out-of-gas failure.
  • Semantics. Inputs are taken modulo 2^64 (the upper 192 bits are ignored) and results are pushed with the upper 192 bits zero. Implementations can keep a typed stack internally and only widen values back to 256 bits when a normal opcode reads them.
  • Covered opcodes (second byte reuses the normal opcode number):
    • Arithmetic C001–C00B: ADD, MUL, SUB, DIV, SDIV, MOD, SMOD, ADDMOD, MULMOD, EXP, SIGNEXTEND
    • Comparison/bitwise C010–C019, C01B–C01D: LT, GT, SLT, SGT, EQ, ISZERO, AND, OR, XOR, NOT, SHL, SHR, SAR
    • Flow: JUMP C056, JUMPI C057
  • Gas. New constants: G_BASE64 = 1, G_VERYLOW64 = 2, G_LOW64 = 3, G_MID64 = 5, G_HIGH64 = 7; EXP64 costs 5 + 25 per exponent byte. So a 64-bit ADD costs 2 instead of 3.
  • Not included: BYTE, memory loads/stores and PUSH, because their behaviour depends on endianness. POP, DUP and SWAP need no 64-bit variant.

Sample code

A loop counter decrement in 64-bit mode (assembly-style bytecode listing):

// stack: [i]
PUSH1 0x01      // [1, i]
SWAP1           // [i, 1]
C0 03           // SUB64  -> [i - 1 mod 2^64], 2 gas
DUP1            // [i-1, i-1]
C0 15           // ISZERO64
PUSH2 0x0040    // loop exit
C0 57           // JUMPI64, 7 gas

Raw bytes for the arithmetic part: 6001 90 c003 80 c015.

Things to know

  • Status: Draft. Reference implementation and security considerations are still "to be added".
  • 64-bit EQ and ISZERO only look at the low 64 bits, so two different 256-bit values can compare equal. Compilers must only use 64-bit mode where values are known to fit.
  • Each 64-bit opcode is two bytes, so contract code gets larger (more deployment gas); the saving comes from executing it many times.
  • C0 JUMPDEST still marks a valid jump destination during analysis, but executing it fails, since there is no 64-bit JUMPDEST.
  • The author suggests reserving C0–CF for future "mode" prefixes, e.g. an overflow-checking mode.

#evm #opcodes #performance #gas #core

Details

Authors
Wei Tang (@sorpaas)
Status
Draft
Type
Standards Track / Core
Created
2025-04-23
Required by

Machine-readable: Markdown · JSON