EIP-7937 EVM64: 64-bit mode EVM instructions (EVM64 - 64-bit mode EVM opcodes)

No call decision · EVM & execution · EIP status Draft · created 2025-04-23

Adds dedicated 64-bit instructions to the EVM. These are 2-byte instructions formed by prefixing existing opcodes with the byte C0, and because they operate only on the lower 64 bits of a stack value, they cost less gas.

Why it is needed

The EVM (Ethereum Virtual Machine) treats every value as a 256-bit integer. In practice, however, many computations do not need the full 256-bit width, and each one wastes unnecessary execution cycles. Meanwhile, most of the hardware running the EVM is 64-bit, such as x86_64 or arm64, and internally splits 256-bit values into four 64-bit integers for storage. This EIP proposes dedicated instructions that compute only that last 64-bit chunk, to speed up execution. Instead of adding dozens of new opcodes, it introduces a single new prefix byte, C0, with the following byte indicating which 64-bit operation to perform. This way, the limited EVM opcode space is barely touched while still covering 64-bit versions of arithmetic, comparison, bitwise, and branch operations.

What changes

Today

After EIP-7937

Who is affected

In depth

Behavior of the prefix opcode C0

This EIP occupies only the single C0 slot in the EVM opcode space. When the interpreter encounters C0, it must read the next byte and execute it as a 64-bit mode operation, advancing the PC by 2 on success. If the second byte is not a valid 64-bit mode operation, it must be treated as OOG (out-of-gas failure). The source text explains that since C0 was previously an invalid opcode with almost no use, backward compatibility concerns are minimal.

General rules of 64-bit mode

Every operation in 64-bit mode targets only the lower (least significant) 64 bits of each stack value, discarding the upper 192 bits. When pushing a result back onto the stack, the upper 192 bits must be zero as far as observable effects go, but there is no need to actually reset them to zero on every single operation. If the next instruction is still in 64-bit mode, the upper 192 bits are not observed, so the interpreter only needs to restore the 256-bit value at the point where it leaves 64-bit mode and the value is read. The source text explains that if an entire computation-heavy section can be written purely in 64-bit mode, a noticeable performance gain is possible.

Gas constants and arithmetic instructions

The new gas constants are G_BASE64=1, G_VERYLOW64=2, G_LOW64=3, G_MID64=5, G_HIGH64=7, G_EXP64_STATIC=5, and G_EXP64_DYNAMIC=25. Arithmetic instructions are defined the same way as their non-64-bit counterparts, operating only on the lower 64 bits. ADD (C001) and SUB (C003) cost G_VERYLOW64; MUL (C002), DIV (C004), SDIV (C005), MOD (C006), SMOD (C007), and SIGNEXTEND (C00B) cost G_LOW64; ADDMOD (C008) and MULMOD (C009) cost G_MID64. EXP (C00A) is computed as static_gas = G_EXP64_STATIC, dynamic_gas = G_EXP64_DYNAMIC * exponent_byte_size.

Comparison and bitwise operations, and a semantic caveat

LT (C010), GT (C011), SLT (C012), SGT (C013), EQ (C014), AND (C016), OR (C017), XOR (C018), ISZERO (C015), NOT (C019), SHL (C01B), SHR (C01C), and SAR (C01D) are all defined with a cost of G_VERYLOW64. There are two caveats. 64-bit EQ (C014) compares only the lower 64 bits, so it can return true for two different 256-bit integers. 64-bit ISZERO (C015) can likewise return true for a nonzero 256-bit integer as long as its lower 64 bits are zero. BYTE (1A) has no 64-bit mode because it affects endianness (byte storage order).

JUMP, JUMPI, and JUMPDEST validation

JUMP (C056) reads only the lower 64 bits of the stack value as the destination, discarding the remaining 192 bits unread. Its gas cost is G_MID64. JUMPI (C057) reads only the lower 64 bits for both the destination and the condition check, and its gas cost is G_HIGH64. During JUMPDEST validation, C0 is treated as a distinct mode opcode: if the byte immediately following it is JUMPDEST, that location is marked as a valid jump destination. However, there is no such thing as a 64-bit JUMPDEST, so encountering C0 JUMPDEST during execution results in OOG.

Implementation optimization: typed stacks and excluding endianness-dependent opcodes

The source text proposes a typed stack that distinguishes stack entries as either Value U256 or Value64 U64. 64-bit instructions always output a Value64, and when a Value64 is read in non-64-bit mode, the upper 192 bits are zero-extended at that point. Under the assumption that most EVM implementations store 256-bit values as [u64; 4] on little-endian 64-bit architectures (x86_64, arm64, riscv64), the design only needs to operate on the last u64. Since 64-bit mode contains no endianness-dependent instructions at all, Value64 can be stored in whatever endianness suits the architecture. For the same reason, BYTE64, MLOAD64, MSTORE64, and PUSH*64 were left out of this proposal. The text mentions the option of extending to a little-endian 64-bit mode to add these, but the author recommends caution since it could cause significant confusion for developers. There is no reduction in memory usage.

Trade-offs and reserved space

A known drawback is increased binary size: each instruction grows from 1 byte to 2 bytes, adding 200 gas per byte at deployment. However, the source text calculates that since 64-bit instructions are generally cheaper, the cumulative gas becomes cheaper after at most about 200 calls. POP is automatically 64-bit since it only removes a value, and DUP* and SWAP* need no separate 64-bit versions either, since they simply copy or exchange already-optimized state. The source text recommends reserving the C0-CF range for prefix (mode) opcodes, citing as an example an OVERFLOW mode that would replace wrapping arithmetic with OOG on overflow, reducing the extra cycles SafeMath currently requires.

Current status: Draft

This EIP is in Draft status, so the specification may still change. The Reference Implementation and Security Considerations sections are empty and marked as to be added, and it states that the security aspects still need discussion. There is no core developer call decision yet on including it in any specific hard fork.

Original EIP · ← EIPs