Skip to content

Audit of all 32 axioms in Verify/Axioms.lean - #14

Closed
vasnesterov wants to merge 1 commit into
masterfrom
docs/axiom-audit
Closed

vasnesterov wants to merge 1 commit into
masterfrom
docs/axiom-audit

Conversation

@vasnesterov

Copy link
Copy Markdown
Owner

Adds docs/axiom-audit.md — an audit of all 32 axioms that were in Lean4Lean/Verify/Axioms.lean, against toolchain v4.33.0-rc2 and the C++ kernel at master. This is the evidence behind the fixes already on master (which is why the whitelist is now 31, not 32).

Verdicts assigned per axiom:

  • inconsistent — a machine-checked proof of False exists (2 axioms, each on its own)
  • false (runtime) — a #eval counterexample exists
  • false (source) — the divergence is at an input where the C code aborts, so no value is observable
  • true* — true only under a side condition the axiom does not state
  • true — no counterexample under differential testing plus a reading of the C++/Lean source
  • provable now — should not be an axiom at all

11 of the 32 failed. The audit is read-only: it changes nothing under Lean4Lean/.

Why it matters beyond the fixes

Verify/Guard.lean check 2 whitelists axioms by name. It asks which axioms kernel_sound uses, never whether that set is consistent — so a whitelisted axiom proving False would make kernel_sound provable vacuously while the guard printed "proof COMPLETE". §0 documents that gap in the guard itself, which is worth keeping on record independently of the two axioms that exercised it.

Still open, per the audit

Two axioms are provable now and could become theorems: Std.TreeMap.all_eq_all_toList and any_eq_any_toList, both from existing upstream lemmas (the second after a ~10-line mirror of the all case). That would take the whitelist 31 → 29.

Also updates bugs-found.md

Eight numbered kernel/checker defects with reproductions.

🤖 Generated with Claude Code

Every axiom in Verify/Axioms.lean gets a verdict backed by an attempted
refutation rather than by inspection -- differential testing over a
1456-expression corpus, twenty-one million levels for normalize_eq, and
PersistentHashMap over 300-key maps with engineered low-bit collisions
and malformed nodes.

Two prove False on their own: Expr.looseBVarRange_eq, which equates a
20-bit field read with an unbounded model, and Level.mkLevelIMaxCore_eq,
whose model carries a disjunct upstream does not have. Three more are
jointly inconsistent, four are false of the implementation with #eval
counterexamples, and two are true only under a side condition they do not
state. Twenty-one are true, of which two are now provable outright from
upstream.

This matters because guard 2 whitelists the axioms *by name*. An
inconsistent one makes kernel_sound provable vacuously while the guard
reports success -- so the guard cannot be the thing that catches this.

Each non-true axiom has a written-out corrected statement, its call
sites, and a dischargeability verdict. Also records an adjacent gap:
guard 1 scans only Axioms.lean, so it cannot see the nine axioms declared
elsewhere in the repo, seven from bv_decide and two pointer-equality
ones, none of which is whitelisted.

bugs-found.md is restructured into four sections -- Lean's kernel, the
lean4lean kernel implementation, the proof infrastructure, and the frozen
axioms -- and records three pieces of upstream behaviour that constrain
the specification and would otherwise be assumed the other way.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@vasnesterov

Copy link
Copy Markdown
Owner Author

Closing — superseded, content already on master.

docs/axiom-audit.md on master is byte-identical to this branch's copy (landed as 0bf1e6c). The bugs-found.md conflict is likewise master being ahead: it carries 5 numbered items where this branch has 4.

Nothing here is new. Branch kept.

vasnesterov pushed a commit that referenced this pull request Aug 23, 2026
…ide condition

Neither possibility in the brief was right; the answer is a third.
**They are consistent** (the argued contradiction is dead), **they are
not provable** (their docstrings' claim is false), **and they become
provable under a side condition.**

New `Lean4Lean/Tests/AxiomConsistency.lean` (nothing imports it). It
works by **model exhibition** against `dataOf f` -- `Lean/Level.lean`'s
computed field with the opaque `mkData` replaced by `f` -- and checks
clause-by-clause by `rfl` that `dataOf mkData` is the real
`Level.data`.

- **§1** a clamping model (`min d (2^24-1)` instead of panic) validates
  **all three** of #12/#13/#14 by induction on `Level`. So they are
  **jointly consistent**, and §4's argument needed the *unconditional*
  `mkData_eq`: it dies with the `H : d < 2^24` repair.
- **§2** a zeroing model validates #12 but **refutes** #13/#14 on
  `succ^[2^24] (.param x)`. So **#13/#14 are independent of #12** --
  nothing constrains `mkData` at `d ≥ 2^24`, and they cannot be proved
  "using `mkData_eq` and friends" as their docstrings claim.
- **§3** `hasParam_eq_of_dep`, `hasMVar_eq_of_dep`, `depth_eq_of_dep`,
  each under `(h : dep l < 2^24)` -- proved **without** #13/#14. The
  hypothesis is verified load-bearing (§2 *is* the proof it must be) and
  satisfiable, and the qualified name was checked to be
  `Lean.Level.mkData_eq` rather than the `Expr` one.

**Joint-consistency survey (§12).** Mechanical: which free symbol each
axiom pins. The relation is a **DAG** -- verified no `X_eq : X = Total.X`
has `Total.X` reaching `X`. That splits the set:

- **Class (A), 23 axioms** -- each pins a free symbol to a total
  definable function. **Jointly consistent by topological
  interpretation.**
- **Class (B), 6 axioms** -- constrain a free symbol *through* a
  definable observation with provable properties. **Both historical
  `False`-proofs were in class (B)**, which is where attack effort
  belongs.

**Seven failed attacks recorded in §12.3, each with the step it fails
at**: #15+digama0#31 and digama0#30+digama0#31 (no shared constant -- independent opaques);
mutual definability of the ten substitution/abstraction primitives (all
independent opaques, the equivalences are **docstrings only**); #18 at
the `BVarBounded` boundary; off-by-one at both panic boundaries; #17's
unconditional form.

**The strongest single result:** an environment sweep over every
constant whose type mentions any of the 27 pinned opaques (private
manglings resolved, not grepped) returns 21 whitelisted axioms plus
exactly four auto-generated inert lemmas. **No theorem anywhere asserts
a behavioural property of any pinned opaque** -- so contradictions can
only arise *between* whitelisted axioms.

Unverified, stated as such: the `PersistentArray`/`PersistentHashMap`
three are the **highest residual risk** -- class (B), same shape as the
two that proved `False`; `WF` blocks the known counterexamples and no
new attack succeeded, but no model exists and building one means
proving the real HAMT algorithms correct. And the `Expr` analogue of §1
is hand-analysed, not mechanised.

Also noted: removing the two `TreeMap` axioms eliminated the only two
with **zero model freedom**.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
vasnesterov pushed a commit that referenced this pull request Aug 23, 2026
…nt guard-2 failure

**What those entries are: not certificates, axioms.**
`Lean.Meta.nativeEqTrue`, which `bv_decide` calls, builds an aux `def`,
`addAndCompile`s it, runs `unsafe evalConst Bool` -- **compiled machine
code** -- and on `true` calls `addDecl` on a fresh **`axiomDecl`**:

    …mkData'_hasParam._native.bv_decide.ax_1_8
      : Std.Tactic.BVDecide.Reflect.verifyBVExpr <expr> <cert> = true

**The kernel never checks it.** It is `native_decide`'s trust model --
compiler, runtime and LRAT checker all in the TCB -- and in one respect
worse than `Lean.ofReduceBool`: instead of one named, auditable axiom
shared by all uses, **each invocation mints a fresh anonymous axiom**
whose statement mentions two auto-generated definitions. The trust
surface grows silently per use and is **invisible to a by-name whitelist
review**.

**Re-proved without it; bit-blasting was convenience, not necessity.**
§0 of `Tests/AxiomConsistency.lean` is rewritten, the
`Std.Tactic.BVDecide` import gone, going through one packing lemma
(`mkData'_toNat`) plus one field-extraction lemma over an arbitrary
`UInt64`, using the standard `UInt64.toNat_*` lemmas,
`Nat.and_one_is_mod`, `Nat.shiftRight_eq_div_pow` and `omega`.

| | before | now |
|---|---|---|
| `mkData'_{depth,hasParam,hasMVar}` | `+ Classical.choice + 3 native` | **`[propext, Quot.sound]`** |
| §1/§2 models | `+ Classical.choice + native` | **`[propext, Quot.sound]`** |
| `hasParam_eq_of_dep` / `hasMVar_eq_of_dep` | `+ Classical.choice + native` | **`[propext, Quot.sound, Lean.Level.mkData_eq]`** |

Verified with `pp.fullNames` that it is `Lean.Level.mkData_eq`, not the
`Expr` one. All entries already whitelisted. **29 → 27 is a real
reduction now** -- no new trust, and `Classical.choice` drops out.

**The reason this mattered more than one file: the repo already contains
three of these axioms, unwhitelisted**, in `Verify/Level.lean`:

    Lean.Level.mkData_depth._native.bv_decide.ax_1_9
    Lean.Level.mkData_hasMVar._native.bv_decide.ax_1_8
    Lean.Level.mkData_hasParam._native.bv_decide.ax_1_8

They sit outside `kernel_sound`'s cone **only because that cone is
currently four constants wide** -- the proof is still mostly `sorryAx`.
**Guard 2 passes today by accident of incompleteness, and will fail the
build the moment those three lemmas enter the real proof.** The new §0
proofs are a drop-in replacement, same statements modulo one
`mkData_eq` rewrite.

> Standing check worth having wherever the guard lives: **no axiom whose
> name contains `_native` may appear in any cone**, whitelisted or not.
> A by-name whitelist cannot catch this family, because the names are
> generated.

Audit: §12.1 carries the corrected axiom list, new **§12.5** documents
the mechanism, the trade it would have concealed, the replacement, and
the latent guard-2 failure. §12.2 now ends with the operational
conclusion:

> Stop auditing the set for consistency and attack class (B). The 23
> class-(A) axioms cannot produce a contradiction -- each pins a free
> symbol to a total definable function and the pinning relation is
> acyclic. They can still be *false of the C++ kernel*, but falsity
> there is a testing problem, not a soundness-of-the-proof problem.
> Every route by which this set could make `kernel_sound` vacuous runs
> through class (B); #13 and #14 are now closed, leaving **four**.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant