Issue #1593: Write down the semantics of the reduced Nikaia subset that copy-and-patch stencils are proved against

Open and answer this issue on GitHub.

emitter, blocked, future · opened 2026-11-14 · updated 2026-11-21 · 1 comment

The goal

#1235 may build a copy-and-patch backend: machine code made by copying precompiled pieces (“stencils”, one per construct and operand shape, with holes for registers, constants, addresses and jump targets) and patching the holes. This issue records how that backend is verified, so the plan is not lost. It is filed for the future (owner, 2026-11-14): it is not an open decision, it waits for the backend, and it changes no part of the specification now.

The idea: a copy-and-patch backend is built from a fixed, finite set of pieces. So it can be verified once, piece by piece, instead of checking every program it compiles. Together with what Nikaia already proves about a program, the result is that the machine code behaves as the checked program says.

Not decided here, on purpose: whether the Rust backend ever gets an outside verifier (Kani, Creusot, Verus, Aeneas/Lean or another method). That stays open; this issue is about the copy-and-patch backend only.

Where it belongs

No intermediate representation

Nikaia has no IR on purpose. The stencils are chosen from the checked tree, after it has been reduced and optimised as #1235 describes, onto a subset of Nikaia itself. So the prover and the emitter work on the same tree, and there is no gap between where a program is proved and what the backend reads. The semantics this plan needs is the semantics of that reduced subset, not of a second language.

What is to be proved: five obligations

  1. A formal semantics of the reduced subset of Nikaia that the stencils are chosen from: what each construct means, step by step. This is the large intellectual piece; it is kept small by keeping the subset small (#1235).
  2. Each stencil does what its construct means, for every value in its holes. The stencil’s finished machine code is run symbolically against a formal model of the processor (the official Sail models for Arm and RISC-V, symbolic evaluation with Isla), with the holes kept symbolic; a solver shows over bitvectors that the result matches the semantics of 1. Stencils are short and nearly branch-free, so each goal is small. Because the finished code is checked, the C compiler that produced the stencils (clang) is not trusted.
  3. The stencils fit together. A relation is fixed between the program’s values and the machine state (“value v is in register r or stack slot s”); every stencil must keep it from its entry to its exit. Correctness of any sequence of stencils then follows by induction: one small general proof (the simulation argument known from CompCert); the work per construct is all in 2.
  4. The patcher is right. It copies bytes and writes values into holes of each relocation kind (absolute 64-bit, relative 32-bit, …): every value fits its field (a rel32 jump reaches only so far), every offset stays inside the buffer. A few hundred lines, written in Nikaia and proved by Nikaia’s own prover.
  5. The choice of stencil is right. The table “construct and operand shape → stencil variant” chooses a variant only where it applies; small, checked in full.

Proofs checked by our own checker

The goals of 2 can be bit-blasted to SAT, and the solver asked for an LRAT proof. The certificate checker already replays LRAT-like clause steps (ADR-270 D5). So the stencil proofs can be checked by our own small checker, without trusting the solver that found them.

What the result says, and what it does not

Done when

The semantics of the reduced subset of Nikaia (obligation 1) is written down construct by construct, covering at least the constructs the step 7 prototype of #1235 covers, as the reference the stencil proofs of #2549 state their goals against; the report gives a Found: line per finding.

To build (once #1235 has the backend)

  1. Write down the semantics of the reduced subset (obligation 1), construct by construct, as the reference the stencil proofs are stated against; first the constructs the step 7 prototype of #1235 covers.

The other steps moved to their own issues (see Split below): the stencil prover and its replay (old 2, 3), the relation (old 4), the patcher and the table (old 5, 6), the build refusing an unproved stencil (old 7).

Files and limits

Ruled out

References

Split (2026-11-21)

Comments

keywan-ghadami, 2026-11-21

Split into run-sized issues (2026-11-21)

Found built: nothing. The copy-and-patch backend does not exist yet (#1235 is a note, no stencil in the tree, git log --grep stencil shows only a supervisor note), so every step still waits on it.

Where the steps went:

All parts keep blocked and Needs #1235.


Generated by Claude Code

Back to Open Issues