EIP.tools

EIP.tools

⚠️ DraftStandards Track: Core

EIP-8442: 64-bit Opcodes for the EVM

Single-byte opcodes for 64-bit arithmetic, comparison, bitwise, and memory operations

Authors
Created2026-10-14
Discussion Linkhttps://ethereum-magicians.org/t/eip-8442-64-bit-opcodes-for-the-evm/29982

Markdown

https://raw.githubusercontent.com/ethereum/EIPs/re...
Pull Request#12504PR open

EIP-GPT summary

Contents
AbstractMotivationSpecificationThe instructionsCostsAnalysisRationaleAre there real-time performance gains?Why these instructions?Why these costs?Backwards CompatibilityTest CasesReference ImplementationSecurity ConsiderationsCopyright

Abstract

Not every computation needs 256 bits. Counters, offsets, lengths, and the inner loops of hashes and big-number arithmetic fit in 64, and the EVM makes them pay for 256 at every step. This proposal adds twenty-eight instructions that compute on the low 64 bits of their operands: each is the twin of an existing arithmetic, comparison, bitwise, or memory instruction — the same operation at the same cost tier, one step down — at the existing opcode plus 0xC0. The instructions take no immediate data and enter no mode: they mix freely with the rest of the instruction set, and every result is an ordinary 256-bit word.

Note: Significant assistance from AI is acknowledged, primarily for the reference implementation and its tests.

Motivation

Most of the values a contract computes with fit in 64 bits. On the 64-bit machines that run the EVM a 256-bit addition is four limbs and three carries, a multiplication ten partial products, a comparison up to four; the same work on a 64-bit value is one instruction. An interpreter hides most of the difference behind its dispatch. Compiled code does not, and neither does a zero-knowledge (ZK) virtual machine, where the prover pays per RISC-V instruction executed. These instructions let code that fits in 64 bits pay for 64.

Measured in EIP-7979's harness, they alone make a program 1.1x to 1.5x cheaper interpreted and 2.8x to 11x cheaper compiled. Together with validated static control flow they compound: compiled code executes 19x to 51x fewer RISC-V instructions than today's interpreted EVM, and a ZK prover's cost falls with it. The measurements are in the Rationale.

Specification

The key words MUST and MUST NOT in this Specification are to be interpreted as described in RFC 2119 and RFC 8174.

The EVM's machine state includes a data stack of 256-bit words. These instructions leave it so. Each reads only the low 64 bits of its operands — the operand modulo 2^64 — and pushes a 64-bit result zero-extended to 256 bits: the high 192 bits of every result are zero. Signed instructions read the low 64 bits as a two's-complement integer. No mode is entered or left; the instructions may appear anywhere, in any mix with the rest of the instruction set.

Note: the zero high bits describe the result, not its storage. An implementation may keep a 64-bit value in one machine word and supply the zeros when a 256-bit instruction reads it.

The instructions

Each instruction is the twin of an existing one — the same operation on 64-bit operands — at the existing opcode plus 0xC0. In the table, a is the top of the data stack, b the item beneath it, and N the third, each read modulo 2^64; every result is reduced modulo 2^64; division truncates toward zero and division by zero yields zero.

OpcodeInstructionPopsPushesCostResult
0xC1ADD6421verylow64a + b
0xC2MUL6421low64a × b
0xC3SUB6421verylow64a - b
0xC4DIV6421low64a / b
0xC5SDIV6421low64a / b, signed
0xC6MOD6421low64a mod b
0xC7SMOD6421low64a mod b, signed, with the sign of a
0xC8ADDMOD6431mid64(a + b) mod N, the sum not reduced; 0 if N = 0
0xC9MULMOD6431mid64(a × b) mod N, the product not reduced; 0 if N = 0
0xCAEXP6421exp64a to the power b
0xCBSIGNEXTEND6421low64b sign-extended from bit 8a + 7; b if a > 6
0xCCCALLDATALOAD6411verylow64CALLDATALOAD of a, modulo 2^64
0xCDMLOAD6411verylow64 + memoryMLOAD of a, modulo 2^64
0xCEMSTORE6420verylow64 + memoryMSTORE of b modulo 2^64 at a
0xD0LT6421verylow641 if a < b, else 0
0xD1GT6421verylow641 if a > b, else 0
0xD2SLT6421verylow641 if a < b, signed, else 0
0xD3SGT6421verylow641 if a > b, signed, else 0
0xD4EQ6421verylow641 if a = b, else 0
0xD5ISZERO6411verylow641 if a = 0, else 0
0xD6AND6421verylow64a and b, bitwise
0xD7OR6421verylow64a or b, bitwise
0xD8XOR6421verylow64a xor b, bitwise
0xD9NOT6411verylow64not a, bitwise
0xDBSHL6421verylow64b shifted left a bits; 0 if a > 63
0xDCSHR6421verylow64b shifted right a bits; 0 if a > 63
0xDDSAR6421verylow64b shifted right a bits, signed, filling with the sign of b
0xDECLZ6411low64the number of leading zero bits of a; 64 if a = 0

0xC0, 0xCF, 0xDA, and 0xDF are left unassigned.

The three load and store instructions are their twins reduced modulo 2^64: the same 32-byte window at the same offset, the same memory expansion, the same bytes. MLOAD64 reads the low eight bytes of the word MLOAD would read, so it reads back what MSTORE stored of a 64-bit value; CALLDATALOAD64 reads the low eight bytes of a calldata word, so it reads an ABI-encoded 64-bit argument in place. MSTORE64 writes the full 32-byte word, its high 24 bytes zero.

Costs

Four new tiers, each a step below the tier of the twin: verylow64 is 2 where verylow is 3, low64 is 3 where low is 5, mid64 is 5 where mid is 8, and exp64 is 5 plus 25 per byte of the exponent — the exponent being b modulo 2^64, so at most eight bytes — where EXP is 10 plus 50. MLOAD64 and MSTORE64 pay memory expansion exactly as MLOAD and MSTORE do.

The discounts reflect the work: one machine word where the twin handles four, with no carries between limbs. Benchmarking will be needed to tell if the costs are well-balanced.

Analysis

None of the instructions takes immediate data, so JUMPDEST analysis is unchanged. Each has the fixed stack effect the table gives, so any validator or translator that works from an opcode table covers them by adding rows.

Rationale

Are there real-time performance gains?

Yes, measured. EIP-7979's assets count executed RISC-V instructions exactly, on five kernels, each exercising a different part of the machine: mul chain, the multiplier on a dependent chain; call tree, calls and returns, seven of each per iteration; xorshift, the shifter and the logic unit; euclid, the divider in a data-dependent loop; and store and sum, the memory unit alone. Their code is in the assets. The arithmetic and comparison instructions are at the opcodes proposed here, the memory instructions at placeholders. The counts are rounded; the parentheses give each cell's gain over the status quo, the stack VM at 256 bits. Within each pair of rows, the upper is today's instruction set and the lower the same program with these instructions: read within a pair for what the 64-bit instructions buy, and down the pairs for what static control flow buys, each pair a cheaper execution tier that validation permits.

mul chaincall treexorshifteuclidstore and sum
stack VM 2566M8M6M8M9M
stack VM 644M (1.4x)7M (1.1x)4M (1.3x)7M (1.2x)6M (1.5x)
register VM 2564M (1.5x)4M (2.1x)4M (1.4x)5M (1.7x)6M (1.5x)
register VM 642M (3.3x)2M (3.2x)2M (2.8x)3M (3.0x)3M (3.1x)
RISC-V 2561M (4.7x)1M (7.0x)1M (4.8x)1M (5.8x)2M (4.2x)
RISC-V 64121K (51x)406K (19x)148K (37x)234K (35x)397K (23x)
RISC-V -O231K (200x)8K (971x)31K (180x)70K (117x)274K (33x)

Within a pair: on their own the instructions buy 1.1x to 1.5x in the stack VM, where dispatch dominates; 1.5x to 2.2x in the register VM; and 2.8x to 11x compiled to RISC-V, where there is nothing left to pay for but the arithmetic. Down the pairs: what static control flow buys. The two together, validated code compiled, executes 19x to 51x fewer instructions than today's interpreted EVM — more than the product of the two gains, because a stack slot can live in a machine register only when its offset is proven static and its value fits. The last row is the ceiling: the same code through LLVM at -O2, 33x to 971x, from a compiler no mainnet client can run at deploy, since nothing in LLVM is bounded, but one a client can run at build time on precompiles written as EVM code, and a chain that does not pay for compile time can run at deploy. That holds in ZK proving as in execution: run in the Zisk zkVM, the call tree and mul chain programs cost the prover their executed-instruction counts plus a fixed startup, so the ratios are ratios of proving cost.

Storage dominates most transactions and lies outside these kernels, so such gains would be most visible where overhead can be minimal: precompiles, layer 2 chains, and EVM-compatible chains.

Why these instructions?

The arithmetic row 0x01–0x0B and the comparison and bitwise row 0x10–0x1E, less BYTE, plus three loads and stores; the rows 0xC1–0xCB and 0xD0–0xDE make the encoding mechanical, twin plus 0xC0, and the three memory instructions take spare slots beside the arithmetic.

BYTE already indexes a big-endian word, so byte j of a 64-bit value is BYTE of 24 + j; a twin would save one gas. CLZ is in: it is the kind of thing 64-bit code does, and it counts to 64 rather than 256.

Twins of JUMP and JUMPI are out. A destination already fits in 64 bits, and JUMPI tests for nonzero, which gives the same answer on a zero-extended value; the twins would save gas only. PUSH needs no twin: a push of up to eight bytes already pushes a 64-bit value with zero high bits. DUP, SWAP, and POP move words; there is nothing to narrow.

The loads and stores are the twins modulo 2^64 rather than eight-byte accesses. Eight-byte windows would pack arrays four times denser, but they would be the first instructions to touch memory at anything but the word, would need their own expansion rule, and would read ABI-encoded calldata 24 bytes off. The window chosen here reads back what existing code and existing compilers store, in place. Denser packing is a different proposal.

Packing four 64-bit values into one word serves lane-parallel bitwise code already — one XOR mixes four lanes, a uniform rotation costs five instructions for four — and cannot serve the scalar code these instructions are for: a counter, an offset, or a dependent chain of multiplies has no lanes to fill, a product of packed lanes mixes them, and every carry needs fixing.

Why these costs?

A step below the twin's tier, and approximate: the saving is in the arithmetic, not in dispatch or gas accounting, and under an interpreter it is modest, as the measurements show. The right costs will come from benchmarking.

Backwards Compatibility

The opcodes 0xC0–0xDF are unassigned. Executing one today halts exceptionally and consumes all gas; code that does so was always broken, and after this change twenty-eight of them execute instead. Existing code's semantics are otherwise unchanged: no existing instruction changes, no instruction takes immediate data, and JUMPDEST analysis is the same.

These changes do not preclude running the EVM in zero knowledge, nor foreclose EOF, RISC-V, or other changes.

Test Cases

Inputs are listed top of stack first; every output is a 256-bit word whose high 192 bits are zero. 0x10000000000000005 is 2^64 + 5: the high bits are garbage to be ignored.

OpInputs, top firstOutput
ADD640xffffffffffffffff, 0x10x0
ADD640x10000000000000005, 0x70xc
SUB640x0, 0x10xffffffffffffffff
MUL640x100000000, 0x1000000000x0
DIV640x10, 0x30x5
DIV640x1, 0x00x0
SDIV640xfffffffffffffff8, 0x20xfffffffffffffffc
SDIV640x8000000000000000, 0xffffffffffffffff0x8000000000000000
SDIV640x8000000000000000, 0x00x0
MOD640x11, 0x50x2
MOD640x11, 0x00x0
SMOD640xfffffffffffffff9, 0x30xffffffffffffffff
SMOD640xfffffffffffffff9, 0x00x0
ADDMOD640xffffffffffffffff, 0xffffffffffffffff, 0x70x2
ADDMOD640x1, 0x2, 0x00x0
MULMOD640x8000000000000000, 0x8000000000000000, 0xffffffffffffffff0x4000000000000000
MULMOD640x2, 0x3, 0x00x0
EXP640x2, 0x400x0
EXP640x3, 0x280xa8b8b452291fe821
SIGNEXTEND640x0, 0x800xffffffffffffff80
SIGNEXTEND640x1, 0x800x80
SIGNEXTEND640x7, 0x800x80
LT640x10000000000000005, 0x70x1
GT640x7, 0x100000000000000050x1
SLT640xffffffffffffffff, 0x00x1
SGT640x0, 0xffffffffffffffff0x1
EQ640x10000000000000005, 0x50x1
ISZERO640x100000000000000000x1
AND640x10000000000000005, 0xff0x5
OR640x10000000000000005, 0x20x7
XOR640xff, 0xf0xf0
NOT640x00xffffffffffffffff
SHL640x3f, 0x10x8000000000000000
SHL640x40, 0x10x0
SHL640x10000000000000001, 0x10x2
SHR640x1, 0x80000000000000000x4000000000000000
SHR640x40, 0x80000000000000000x0
SAR640x1, 0x80000000000000000xc000000000000000
SAR640x40, 0x80000000000000000xffffffffffffffff
SAR640x64, 0x80000000000000000xffffffffffffffff
CLZ640x10x3f
CLZ640x100000000000000000x40

The ADDMOD64 and MULMOD64 rows distinguish the unreduced sum and product from wrapped ones: 2^65 - 2 is 2 modulo 7 where 2^64 - 2 is 0, and 2^126 is 2^62 modulo 2^64 - 1 where the wrapped product is 0. Every division and modular instruction yields 0 for a zero divisor or modulus. The SLT64 row is 0 under SLT, which reads 2^64 - 1 as positive. Shift amounts are read modulo 2^64 like every operand: SHL64 by 2^64 + 1 shifts by 1, and a shift of 64 or more clears the word, or fills it with the sign under SAR64.

EXP64 costs 5 with an exponent of 0, 30 with 255, and 55 with 256. With an exponent of 2^64 it costs 5 and yields 1: the exponent is read modulo 2^64.

For the loads and stores, let the calldata, or memory, hold the forty bytes 0x00 to 0x27. CALLDATALOAD64 of 0 yields 0x18191a1b1c1d1e1f, of 8 yields 0x2021222324252627, of 16 yields 0, the window lying past the end, and of 2^64 yields what 0 yields, the offset being read modulo 2^64. MLOAD64 of 0 yields 0x18191a1b1c1d1e1f. MSTORE64 of 0x10000000000000005 at 0 leaves the word at 0 reading 5 under MLOAD and MLOAD64 alike, its first 24 bytes zero; MSTORE64 at 8 extends memory to 40 bytes, as MSTORE at 8 would.

Reference Implementation

evm64.py gives every instruction as a pure function on integers, with the opcode table of costs and stack effects; test_evm64.py checks each against an independent implementation of its 256-bit twin, on edge values and on random words with garbage high bits, and runs the vectors above.

Against the Ethereum Execution Layer Specifications (EELS), following its conventions, the instructions are their twins with the operands masked and the gas tiers renamed. Four of the twenty-eight:

U64_MAX_VALUE = Uint(2**64 - 1)
U64_CEIL_VALUE = Uint(2**64)

class GasCosts:
    ...
    VERY_LOW_64: Final[ExecutionGas] = ExecutionGas(Uint(2))
    LOW_64: Final[ExecutionGas] = ExecutionGas(Uint(3))
    MID_64: Final[ExecutionGas] = ExecutionGas(Uint(5))
    OPCODE_EXP64_BASE: Final[ExecutionGas] = ExecutionGas(Uint(5))
    OPCODE_EXP64_PER_BYTE: Final[ExecutionGas] = ExecutionGas(Uint(25))
    OPCODE_ADD64: Final[ExecutionGas] = VERY_LOW_64
    OPCODE_SDIV64: Final[ExecutionGas] = LOW_64
    OPCODE_MLOAD64_BASE: Final[ExecutionGas] = VERY_LOW_64
    OPCODE_MSTORE64_BASE: Final[ExecutionGas] = VERY_LOW_64

def low64(x: U256) -> Uint:
    """The low 64 bits of a word."""
    return Uint(x) & U64_MAX_VALUE

def signed64(x: U256) -> int:
    """The low 64 bits of a word, as a two's-complement integer."""
    v = int(low64(x))
    return v - 2**64 if v >> 63 else v

def add64(evm: Evm) -> None:
    # STACK
    x = low64(pop(evm.stack))
    y = low64(pop(evm.stack))
    # GAS
    charge_gas(evm, GasCosts.OPCODE_ADD64)
    # OPERATION
    push(evm.stack, U256((x + y) % U64_CEIL_VALUE))
    # PROGRAM COUNTER
    evm.pc += Uint(1)

def sdiv64(evm: Evm) -> None:
    # STACK
    dividend = signed64(pop(evm.stack))
    divisor = signed64(pop(evm.stack))
    # GAS
    charge_gas(evm, GasCosts.OPCODE_SDIV64)
    # OPERATION
    if divisor == 0:
        quotient = 0
    elif dividend == -(2**63) and divisor == -1:
        quotient = -(2**63)
    else:
        sign = get_sign(dividend * divisor)
        quotient = sign * (abs(dividend) // abs(divisor))
    push(evm.stack, U256(quotient % 2**64))
    # PROGRAM COUNTER
    evm.pc += Uint(1)

def mload64(evm: Evm) -> None:
    # STACK
    start_position = pop(evm.stack)
    # GAS
    extend_memory = calculate_gas_extend_memory(
        evm.memory, [(start_position, U256(32))]
    )
    charge_gas(evm, GasCosts.OPCODE_MLOAD64_BASE + extend_memory.cost)
    # OPERATION: the low eight bytes of the word MLOAD would read
    evm.memory += b"\x00" * extend_memory.expand_by
    value = U256.from_be_bytes(
        memory_read_bytes(evm.memory, start_position + U256(24), U256(8))
    )
    push(evm.stack, value)
    # PROGRAM COUNTER
    evm.pc += Uint(1)

def mstore64(evm: Evm) -> None:
    # STACK
    start_position = pop(evm.stack)
    value = U256(low64(pop(evm.stack))).to_be_bytes32()
    # GAS
    extend_memory = calculate_gas_extend_memory(
        evm.memory, [(start_position, U256(len(value)))]
    )
    charge_gas(evm, GasCosts.OPCODE_MSTORE64_BASE + extend_memory.cost)
    # OPERATION
    evm.memory += b"\x00" * extend_memory.expand_by
    memory_write(evm.memory, start_position, value)
    # PROGRAM COUNTER
    evm.pc += Uint(1)

Security Considerations

The instructions add no state and no resource: each does bounded work on one machine word, pays memory expansion exactly as its twin does, and offers nothing new to exhaust.

The hazards are for compilers. EQ64, ISZERO64, and the comparisons judge the low 64 bits only: two words that differ above bit 63 are equal to EQ64, and a word that is zero below bit 63 is zero to ISZERO64. Arithmetic wraps at 2^64, not 2^256, so overflow checks must be written for the width in use. A compiler that emits these instructions for values it has not proven to fit in 64 bits emits wrong code; one that has proven it emits code that is cheaper and no less safe.

Copyright and related rights waived via CC0.

EIP.tools

EIP.tools

Search, read, and map Ethereum improvement proposals, ERCs, RIPs, and CAIPs from one focused interface.

Farcaster
by @apoorveth