← All papers
First page of SafeJIT: A Speculating JIT Engine Verified Down to the Machine Code

SafeJIT: A Speculating JIT Engine Verified Down to the Machine Code

Gabriel Ebner

cs.PL Nov 21, 2026 · v1
Machine-checked Lean 4 proof, using iris-lean separation logic over Sail ISA models, that the SafeJIT RISC-V and x86-64 binaries never crash.
JIT compilers are among the most attacked components of modern software. They compile attacker-chosen programs, speculate on attacker-influenced type feedback, and run the result at full native privilege. A single wrongly eliminated guard or a missing deoptimization becomes memory corruption. We present SafeJIT, a small JavaScript engine with a speculating baseline JIT, together with a machine-checked proof in Lean 4 that its statically linked RISC-V and x86-64 executables never crash, on any input, in a model of a Linux user process. The theorem is about the shipped binaries, executed instruction by instruction on Sail ISA models (for RISC-V, the official one), and it covers everything in them: the parser and bytecode compiler, the interpreter and its type-feedback recording, the JIT compiler, all machine code the JIT can generate for any program and any feedback (type guards, guard elimination, loop type facts, register allocation with deoptimization metadata, inline caches, deoptimization and on-stack replacement), a mark-sweep garbage collector, the runtime, and a freestanding libc. The C compiler, assembler and linker are not trusted, and neither is floating-point arithmetic. The proof uses separation logic (iris-lean) over a model of a Linux user process whose stuck states are exactly the ways a process can crash, including fetching code that has not been made executable or whose instruction cache has not been flushed.

JIT compilers compile attacker-chosen programs and speculate on attacker-influenced type feedback, so a single optimizer logic error becomes exploitable memory corruption. Prior verified JITs did not handle speculation, deoptimization or feedback, and did not reach the shipped machine code.

SafeJIT is a small JavaScript engine in C with a speculating baseline JIT. It comes with a Lean 4 proof that its statically linked RISC-V and x86-64 executables never get stuck, in a process model whose stuck states are exactly the ways a Linux process can crash, including stale instruction caches. Sail ISA models are compiled to Lean, and one bridge lemma per instruction form is proved with a symbolic-execution tactic (twalk). Iris separation logic (iris-lean) is then used over whole instructions, with the JIT handled by a Lean functional model of the compiler plus a refinement proof against the binary.

The development comprises about 6,500 lines of C and 485,000 lines of Lean, with no sorry, built over four weeks with heavy AI-agent assistance. Making the trusted model faithful exposed two real bugs: an unchecked instruction-cache flush result and an address-space size assumption. The JIT runs 2-25x faster than the interpreter.

benchRV interpRV JITx86 interpx86 JIT
fib0.290.130.0370.014
loop7.752.270.4380.148
mandel5.100.220.3620.039
sieve3.770.150.4590.057
Benchmark times (s): interpreter vs JIT (RISC-V under qemu; x86-64)