Verified primitives: a smaller trusted base than Lean
Status: design direction for review, 2026-10-29 (user direction: “more
powerful than Lean”). Concretes specifications/platform-proofs-and-simd-specification.md,
which already requires versioned instruction models (line 18), artifacts
that name “which lowering and instruction semantics were checked and which
backend stages remain trusted” (line 96), and prefers “proof certificates
checked by the language kernel” (line 98). Companion to
design/dependent-core-kernel.md (P7) and design/inline-target-ir.md
(P18). Bit-vectors are one domain of design/proof-automation.md, which
catalogues the other proof strategies (linear arithmetic, rewriting,
congruence closure, rings, induction, separation logic) and the shared
rule that search is untrusted and the kernel checks the result.
1 The problem
Representation instances and fast paths (design/layouts-and-specialization.md
section 7) are justified by proofs, and bit-level proofs (a bitset’s
view-cons) bottom out in facts about shifts and masks on machine integers.
Today those facts are prim laws that are justified or assumed. The goal is
to prove them, and to prove that the code that runs computes them.
2 Where Lean extends its trust
bv_decidebit-blasts aBitVecgoal to SAT and checks the solver’s LRAT certificate with a checker that has a soundness proof, but the check runs as compiled code and the tactic “adds the result of the compiled check as an axiom, thus adding the Lean compiler to the trusted code base” (Lean.Elab.Tactic.BVDecide).- Lean’s compiled code runs machine arithmetic (
UInt64and friends) through@[extern]native implementations. The kernel reasons about the pure definitions; nothing proves the native code computes them. Lean’s theorems are about the model, and the executed code is trusted to match it.
3 The chain, every link proven
- A model for every machine type.
I64,U32, … are defined by pure bit-vector models, and eachprim’s specification is its model function (checkedAddI64is addition modulo 2^64 with an overflow flag). Laws about shifts and masks are theorems over the models, proven in the kernel. - A decision procedure whose certificate the kernel checks. Bit-blast to
SAT, let an external solver produce a certificate (LRAT), and check it in
the kernel by evaluation, with no compiled-code axiom. Two explicit tiers:
- kernel-checked: the trusted base stays minimal; the default, and required for anything a safety profile cites;
- compiled-check: faster, with the Cinch compiler added to the trusted base and recorded in the manifest.
primbodies proven against their models. The subset of LLVM IR thatprimbodies use gets a formal semantics as Cinch definitions, versioned per the platform specification. “Thisprimbody computes its model” is then a bit-vector theorem discharged by link 2. This is Alive2’s translation validation for LLVM, ending in a kernel-checked proof instead of a trusted SMT verdict.asmbodies are proven against ISA models: Sail has ARMv8-A (derived from ARM’s specification) and RISC-V models to translate into Cinch definitions.- Everything above rests on links 1-3. Representation instances,
specialized bodies, rewrites and SIMD proofs need no assumed arithmetic
laws. The interface’s
assumptions.declaredlist shrinking to empty is the progress measure.
4 What stays trusted
| Lean today | Cinch with links 1-3 | |
|---|---|---|
| The kernel | trusted | trusted |
| The compiler, for proofs | trusted (bv_decide’s axiom) |
not trusted in kernel-checked mode |
| Native machine operations | trusted to match their model | proven against LLVM or ISA semantics |
| LLVM’s lowering from IR to machine code | trusted | trusted, except asm bodies proven against an ISA model |
| Fidelity of the instruction models | not applicable | trusted (platform specification line 100); Sail’s models are validated against hardware |
| Hardware | trusted | trusted |
A smaller trusted base than Lean for anything touching machine arithmetic, not zero trust.
5 Costs and mitigations
- Kernel-checked certificates are slow (why Lean took the axiom): store each
certificate in the content-addressed package store keyed by the goal’s
hash, so a fact is proven once and shipped with its package; trim
certificates; keep any kernel arithmetic acceleration small and audited,
since it joins the trusted base (as Lean’s accelerated
Natarithmetic does). - Bounded validation is not a theorem (the platform specification says a
bounded result cannot be relabeled as one).
primbodies are almost all straight-line and fully decidable; loops (SIMD reductions) need the induction proofs the platform specification describes. - The model semantics must be written: the LLVM instruction subset
primbodies use (transcribed from the LLVM language reference, for the instructions used), then ISA models (translated from Sail).
6 Sequencing
This belongs to the kernel slice (P7) and the prim slice (P18) and is
independent of reclamation:
- Bit-vector models for the integer
prims. - The kernel’s bit-blasting procedure and certificate checker.
- LLVM semantics for the instructions existing
primbodies use. - Discharge the currently assumed
primlaws one at a time. - ISA models for
asmbodies.
7 Open decisions
- Certificate format (LRAT proposed, as Lean uses) and how certificates are stored and shipped.
- How far kernel evaluation is accelerated, and how the acceleration is audited.
- Whether the compiled-check tier exists at all, or kernel-checked only.
- The LLVM semantics’ source of truth and versioning against LLVM releases.
8 Context for later agents
- The user’s direction, verbatim: “I’d like this to be even more powerful than e.g. Lean, and I think you can prove that with them”, in reply to the observation that bit-level representation proofs would otherwise rest on “a small, explicitly listed set of assumed arithmetic laws”.
- What exists today (2026-10-29): a dependent core with
Eq,refl,congr,decideand structural induction (design/dependent-core-kernel.md, status “design draft for implementation”);rewrite ... justifychecked as kernel evidence or a citable classlaw, undischarged ones recorded inassumptions.declared(D55,compiler/CONFORMANCE.md);examples/source/03-map-fusion.cinchcarries its ownmapFusionproof and cites it;examples/source/08-platform-simd.cinchstates an instruction law as an obligation (D228);primbodies havejustify/assumed tiers (specifications/primitive-operations-and-inline-target-ir-specification.md,design/inline-target-ir.md). Class laws are checked sample-wise by the P18 law layer. - Where this plugs in: specialization’s justification rule
(
design/layouts-and-specialization.mdsection 7) uses these proofs; the prims whose laws need discharging are thecinch.prim.*intrinsics (PrimOp::Arith/Shift/Bit/Cmpincompiler/src/core.rs), lowered inline to LLVM instructions andllvm.*intrinsics (llvm.sadd.with.overflow.i64and friends) incompiler/src/codegen.rs. - Prior art to read first: Lean’s
bv_decidearchitecture (bit-blasting verified in Lean, CaDiCaL, a verified LRAT checker, the compiled-check axiom), Alive2 (its LLVM IR semantics is the closest existing formalization of the instruction subset), and the Sail models (ARM, RISC-V) for theasmpath.
