Skip to main content
schutzevm
succinctlabs/sp1CompletenessRust · zkVM · x86-64 JIT

Stale compile-time register cache causes jalr miscompilation across control-flow edges in x86-64 native executor

Disclosure ChannelDirect ([email protected])
Target Filescrates/core/jit/src/backends/x86/instruction_impl.rs, crates/core/jit/src/backends/x86/mod.rs

Summary

SP1’s single-pass x86-64 JIT transpiler tracks compile-time constant register values during linear instruction emission and used them to emit unconditional direct jumps for jalr instructions.

When a jalr instruction was reachable via a control-flow edge that bypassed or overwrote the register value recorded linearly at compile time (for example, a branch skipping an intermediate auipc or a loop back-edge), the JIT unconditionally jumped to the stale static target instead of the runtime target PC, causing native x86-64 execution to diverge from RISC-V semantics.

Root Cause

  1. During single-pass x86-64 code generation, the transpiler cached compile-time register constants (such as auipc outputs) without invalidating them across incoming control-flow merges reaching a jalr.
  2. ControlFlowInstructions::jalr computed a static jump_target from that cached register value and passed it to TranspilerBackend::end_branch(jump_target).
  3. end_branch emitted an unconditional jump to the static label whenever jump_target resolved to a known PC, ignoring the runtime target PC computed into CONTEXT + PC_OFFSET.

Remediation

Fixed in #3056 (e56c838): jalr retains the runtime target PC in RAX across clock/trace checks and calls a dedicated TranspilerBackend::end_jalr(jump_target) helper, which guards the direct-jump fast path with a runtime comparison (cmp rax, target_pc; je =>label, supporting both 32-bit sign-extended and wide 64-bit targets) and falls back to dynamic dispatch (self.jump_to_pc()) on mismatch.

Archive

Showing 18 of 18 records

MockZK RollupAUDITHalo2 · Rust · Solidity

PDF-only staging audit fixture (no HTML route; tests direct PDF modal preview and external raw PDF link).

— / —