Skip to content

Verification

Shogo Toda edited this page Oct 19, 2026 · 5 revisions

Verification

Every claim the compiler makes is measured against something that does not share its code.

The reference interpreter

src/interp.rs executes a program directly from the language's rules, generic over the number type (f64, f32, fixed point). It is the meaning of a program. It is slow and simple on purpose.

The differential test

difftest generates random programs — several inputs, folds, scans, lifts, turns, gathers, rolls, functions with bodies, ⇒ loops — compiles each at f64 and f32 with every sweep split across three threads, runs it through both C entrypoints, and compares the cells with the interpreter bit for bit. It also takes whatever the ! check claimed about the program and holds it to the run: a claim the run contradicts is reported as unsound. CI runs six seeds on every push; locally, ./target/release/difftest 20260909 300.

seed 20260909: compared 235 (86 with two inputs, 101 iterating, 51 through a function),
  skipped 65, mismatches 0, f32 mismatches 0, claims checked 156, unsound 0

Integer programs

DIFFTEST_MODQ=1 generates programs over integers mod q = 3329 shaped like an ML-KEM kernel: products and sums under tracked bounds, floors, division by a power of two and by q, the folding and conditional subtraction of a reduction, comparisons whose ind masks a term, and a ⌷ by a public permutation. Each is held to the interpreter at binary64; the interpreter in 32-bit fixed point is held to the one in binary64, so a value that passes 2^31 shows as the two parting; the constant-time rules are checked; and with DIFFTEST_SV=1 the circuit at --fixed 32.0 is simulated against the fixed-point interpreter. With the bound loosened to 2^40 the mode reports fixed point parting from binary64 in 9 of 300 programs; at 2^31, none.

seed 20260909 (integers mod q): compared 300, skipped 0, mismatches 0,
  fixed point parted from binary64 0, constant-time refusals 0

and with DIFFTEST_SV=1 over 20 rounds, the circuits as written and, where fusing changes them, fused:

seed 20260909 (integers mod q): compared 20, skipped 0, mismatches 0,
  fixed point parted from binary64 0, constant-time refusals 0
  circuit at 32.0: 37 compared (17 of them fused), 0 mismatches, 0 failed

The circuit leg and the JAX test

DIFFTEST_SV=1 adds a leg that emits each program as a circuit, simulates it with Verilator and compares the cells with the interpreter, again bit for bit (87 of 88 generated programs at the last count; the one left is a construct the emitter refuses with a line). Where fusing changes the circuit (--fuse), the fused circuit is simulated and compared too: 21 of 28 programs in the last 40 rounds. Fixed-point circuits are compared with the fixed-point interpreter. The JAX module is held to the interpreter bit for bit where XLA allows, and within one ulp at the scale of the space where XLA reorders a fold or uses its own exp; the tolerances were measured, not assumed.

What ! checks

! (expr) asserts a property of every cell for every input, at compile time. The check is interval arithmetic over binary64 rounding (binary32 under --f32): every operation's result is the exact one times (1 ± 2⁻⁵³), so a claim that only holds over the reals is not accepted.

[Phase 3] Static Constraint Solver (!) Validation...
  └─ Backend: interval at f64
  └─ [proved]   (OUTPUT >= 0)
  └─ [unproven] ((△ - ▽) / (△ + ▽)) — the denominator ranges over [-inf, +inf], which includes zero
  └─ Output ∈ [0, +inf]

proved means the interval argument closes; unproven means it does not, and the build continues; VIOLATED means the claim is false for some cell and the build stops. The check assumes no overflow, subnormals or NaN. It is refuted, never trusted: the differential test compares its claims with real runs.

Determinism and threads

The same source gives byte-identical IR (CI checks two builds); the result does not depend on the number of threads or the grain (the threads test builds the same program for 1, 4, 7 and all threads and compares the bits); ? is a hash, so a Monte Carlo run is reproducible.

Where to look

  • tests/compiler_test.rs — 168 tests: the language, the ABI, threads, fusion, kept scratch, the circuit (Verilator; skipped when it is not installed), the JAX module (skipped when JAX is not importable), the command line, the diagnostics
  • src/bin/difftest.rs — the generator and the comparison
  • .github/workflows/ci.yml — what runs on every push

Clone this wiki locally