LPsLux Proposals
EVM & Execution
LP-5620

GPU-Native EVM Execution

Final

GPU-resident EVM with a per-transaction bytecode fiber VM, Block-STM parallel scheduling, and asynchronous cold-state page faults

LP-5620: GPU-Native EVM Execution

Abstract

This LP defines the GPU-native EVM (cevm) for Lux Network: a C++ EVM that executes the full bytecode interpreter on GPU as a per-tx fiber VM, with Block-STM parallel scheduling and asynchronous cold-state page faults. Production backends ship for Apple Metal (M1/M2/M3 silicon), NVIDIA CUDA, and Dawn/WebGPU.

The headline mechanism is the fiber VM: 118 opcodes running the full per-tx interpreter on GPU with proper suspend/resume semantics, so EVM contracts can issue cold SLOAD/SSTORE without stalling the wave.

Architecture

Two execution surfaces

CEVM ships two GPU-native execution surfaces:

  1. Wave-dispatch one-shot (§One-shot wave) — one Metal/CUDA dispatch per wave, one workgroup per tx, simple opcode coverage. Used by the standalone evm-bench-kernel and evm-test-pipeline binaries. Proven model: 32K-tx waves complete in 1 ms on M1 Max.

  2. QuasarGPU wave-tick scheduler (lp-5622) — bounded scheduler kernel with service rings. Includes the EVM fiber VM in drain_exec, Block-STM in drain_validate / drain_repair, async page faults via StateRequest/StateResp, and per-lane Quasar cert verification. This is the production execution path for Quasar-certified rounds.

Fiber VM model

struct FiberSlot {
    uint32_t tx_index, pc, sp, status;
    uint64_t gas;
    uint32_t rw_count, incarnation;
    uint32_t pending_key_lo_lo, pending_key_lo_hi;   // SLOAD suspend slot
    uint32_t pending_key_hi_lo, pending_key_hi_hi;
    uint32_t msize;                                  // memory size
    RWSetEntry rw[8];
    uint64_t  stack[64 * 4];          // 64 entries × 4 limbs (256-bit)
    uint8_t   memory[1024];           // per-fiber scratch
    uint32_t  blob_offset, blob_size; // bytecode pointer (host-shared buffer)
};

Fiber state machine:

StateMeaning
0 (Ready)not yet executing
1 (Running)currently in drain_exec
2 (WaitingState)suspended on cold-state SLOAD
3 (Committable)exec done, awaiting Block-STM validate
4 (Reverted)EVM REVERT or runtime fault

A single fiber occupies ~3.4 KB; 4096 fibers fit in ~13.9 MB device memory.

256-bit arithmetic in MSL/CUDA

struct U256 { ulong v[4]; };  // little-endian limbs

Implemented:

  • add / sub with carry propagation across limbs
  • mul — 4×4 schoolbook multiply (16 partial products)
  • div / mod / sdiv / smod — bit-at-a-time (256 iterations) for correctness; specialized fast paths for divisor < 2^64
  • shl / shr / sar — limb-level shift + bit shift, sign-extending SAR
  • eq / lt / gt / slt / sgt / iszero — straight comparisons
  • bitwise AND / OR / XOR / NOT / BYTE — per-limb

Tests confirm exact match against the CPU reference on EIP-150 vectors.

Opcode coverage (118 ops)

ClassOpcodes
ArithmeticADD, SUB, MUL, DIV, SDIV, MOD, SMOD, ADDMOD, MULMOD, EXP, NOT, AND, OR, XOR, BYTE, SHL, SHR, SAR
ComparisonLT, GT, SLT, SGT, EQ, ISZERO
StackPUSH0..PUSH32, POP, DUP1..DUP16, SWAP1..SWAP16
MemoryMLOAD, MSTORE, MSTORE8, MSIZE
StorageSLOAD (cold-miss suspend), SSTORE (MVCC write)
ControlJUMP, JUMPI, JUMPDEST, PC, GAS
EnvADDRESS, CALLER, ORIGIN, CALLVALUE, CALLDATALOAD, CALLDATASIZE, CALLDATACOPY, CHAINID, GASLIMIT, NUMBER, TIMESTAMP
HashKECCAK256 (inline keccak-f[1600])
HaltSTOP, RETURN, REVERT, INVALID

Deferred to v0.40+, with a documented fallthrough returning Error: CALL family, CREATE/CREATE2, LOGn, EXTCODE*, RETURNDATA*, TLOAD/TSTORE, MCOPY, BLOBHASH/BLOBBASEFEE, SIGNEXTEND, BASEFEE, COINBASE, BLOCKHASH, SELFBALANCE.

Gas accounting

Per-opcode gas costs (Berlin-class):

OpcodeGas
Default arithmetic / compare / stack / env3
MLOAD / MSTORE / MSTORE83
KECCAK25630 + 6/word
SLOAD100 (warm), 2100 (cold, pre-suspend)
SSTORE5000 baseline
JUMPDEST1
Floor (per-tx receipt)21000

Memory-expansion gas is tracked in v0.40; before that it is a fixed budget at kFiberMemoryBytes.

SLOAD cold-miss suspend/resume protocol

on SLOAD slot=k:
    look up MvccSlot for k
    if slot empty (key_lo == 0 && key_hi == 0):
        // cold miss
        set fiber.status = WaitingState
        pack k into fiber.pending_key_*
        push StateRequest{tx_index, k} onto StateRequest ring
        leave fiber.pc at the SLOAD opcode (resume re-runs)
        return out of drain_exec for this fiber

on host StatePage arrival:
    drain_state_resp claims the MvccSlot for k, sets last_writer_tx |= 0x80000000
    re-injects the fiber into Crypto/Exec
    resume sees status==WaitingState; advances to next instr after SLOAD
    next SLOAD finds slot warm, proceeds normally

The high bit of last_writer_tx is the "loaded" sentinel — it distinguishes never-loaded from legitimately-loaded-zero. See lp-5622 §Async cold-state page faults.

Block-STM integration

drain_exec populates each fiber's RWSetEntry rw[8] with read and write versions for every storage, memory, or state access. drain_validate walks the RW set and compares observed versions against current MVCC versions; a mismatch is a conflict, which goes to the repair queue with a bumped incarnation.

Measured behaviour on contention: 16 same-key txs → 120 conflicts → 120 repairs → 16 commits — textbook Block-STM.

Backends

BackendPlatformStatusFile
Apple MetalmacOS/iOS (M1/M2/M3)Productioncevm/lib/consensus/quasar/gpu/quasar_wave.metal
NVIDIA CUDALinux/Windows (CC ≥ 8.0)Productioncevm/lib/consensus/quasar/gpu/quasar_wave.cu
WebGPU/Dawncross-platformReady on the legacy one-shot path; Dawn shim pendingcevm/lib/evm/gpu/kernel/evm_kernel.metal

Runtime dispatcher: QuasarGPUEngine::create() selects Metal on __APPLE__, CUDA on EVM_CUDA, else returns nullptr.

Benchmarks

One-shot wave dispatch (synthetic loop)

10K transactions × 5K loop iterations (550M opcodes), retained as a sanity benchmark:

BackendM ops / secSpeedup vs CPU
C++ CPU1931.0×
Metal GPU (one-shot)2,30312.1×

Gas match: byte-identical CPU vs GPU.

Wave-tick scheduler (production path)

End-to-end stress on quasar-gpu-engine-test, Apple M1 Max:

WorkloadThroughput / latency
1024 disjoint-key txs8 wave ticks, ~150 ms (~6,800 tx/s end-to-end including roots + cert checks)
16 same-key contending txs120 conflicts + 120 repairs, all commit
64 fast-path + 16 cold-state txshost page-fault round trip works, slot finalizes
Determinismbyte-identical roots across two engine instances

End-to-end TPS includes ingress, decode, admission, EVM exec, Block-STM validate, commit, receipt keccak chain, cert verify, and quorum aggregation. Pure-execution micro-benchmarks are higher; these numbers are honest end-to-end.

Gas-rate and opcode-rate baselines

Measured on the cevm benchmark harness. The Ggas/s rows measure end-to-end execution with full state access; the opcode-kernel row measures raw opcode dispatch and uses the CPU opcode kernel as its 1.0× baseline — the two rows are not comparable to each other.

BackendThroughputSpeedup
Go EVM (baseline)4.2 Ggas/s1.0×
cevm C++, full state20.9 Ggas/s5.1×
cevm GPU opcode kernel (Metal)85.9 M op/s4.85× over the CPU opcode kernel

Throughput claim ladder

TierWorkloadPlausible throughput
1 — events/secorder placements, cancels, intents1 B aggregate, lane-isolated
2 — state transitions/secprecompile / EVM lane-local effects100 M cluster scale
3 — finalized settlement/seccertified roots with full audit1–10 M

The claim is billion-event throughput, EVM-settled, Quasar-certified — not 1 B EVM TPS on a single shared state machine. That is bounded by contention and data availability, not GPU compute.

Security

  • Gas equivalence. Gas accounting is identical between the CPU and GPU paths. GPU execution is an optimization; it does not change EVM semantics. A transaction costing X gas on CPU costs X gas on GPU, and the test suite validates gas and state-root equivalence bit-for-bit.
  • Transaction isolation. Each transaction's fiber stack and memory arena are private to that fiber. There is no cross-transaction data path in device memory.
  • No floating point. All EVM operations are integer arithmetic, so no GPU floating-point rounding can enter a consensus value.
  • Transparent CPU fallback. With no GPU present, cevm runs entirely on CPU with no behavioural change.
  • Fiber stack overflow: bounded by kFiberStackDepth = 64 × 4 limbs; reverts to status = Error if exceeded.
  • Memory expansion: bounded by kFiberMemoryBytes = 1024; larger expansion is deferred to v0.40 with proper gas accounting.
  • MVCC arena exhaustion: open-addressing with kDefaultMvccSlots = 8192 slots; a full arena returns kMvccInvalidIdx and the tx faults cleanly — no infinite probe loop.
  • No CPU compute on the round path — the host is doorbell and I/O only.
  • Sixteen findings across three adversarial review rounds of the one-shot path were fixed.

CEVM and QuasarGPU

┌───────────────────────────────────────────────────────┐
│  cevm: Ethereum-compatible EVM                        │
│                                                       │
│   cevm/lib/evm/                  the EVM core         │
│     vm.cpp, baseline_*.cpp, advanced_*.cpp            │
│                                                       │
│   cevm/lib/evm/gpu/             one-shot wave path    │
│     evm_kernel.metal                                  │
│     evm_kernel.cu                                     │
│     kernel/                                           │
│                                                       │
│   cevm/lib/consensus/quasar/gpu/                      │
│     ┌───────────────────────────────────────────┐     │
│     │  QuasarGPU wave-tick scheduler            │     │
│     │    quasar_wave.metal / .cu                │     │
│     │    drain_exec  ← runs the fiber VM        │     │
│     │    drain_validate / drain_repair          │     │
│     │    drain_cert_lane / drain_state_resp     │     │
│     └───────────────────────────────────────────┘     │
└───────────────────────────────────────────────────────┘

This LP covers the EVM proper. lp-5622 covers the wave-tick adapter that embeds the EVM fiber VM into Quasar consensus rounds. QuasarSTM covers the Block-STM scheduling fabric the fibers run under.

Implementation plan

VersionTheme
one-shotwave dispatch, 60+ opcodes, 12× speedup
v0.36fiber VM substrate — FiberSlot type, suspend/resume scaffolding
v0.39full EVM fiber VM in drain_exec, 118 opcodes, SLOAD cold-miss
v0.40CALL family, CREATE/CREATE2, LOGn, memory-expansion gas, SSTORE journaling
v0.41CUDA backend mirror complete
v0.42TLOAD/TSTORE, MCOPY, RETURNDATA*, full Cancun coverage
v0.43EIP-2929 cold/warm gas accounting in the fiber path
v0.44+precompile family, including the DEX matching precompile

References

ResourceLocation
EVM corecevm/lib/evm/
QuasarGPU substratecevm/lib/consensus/quasar/gpu/
Testscevm/test/unittests/quasar_gpu_engine_test.mm (13/13 PASS)
lp-0110Quasar consensus
lp-5607GPU acceleration framework
lp-5621Interchangeable EVM implementations
lp-5622QuasarGPU execution adapter
lp-9000DEX core — consumes the fiber VM

Copyright (C) Lux Industries Inc. All rights reserved.