Skip to content

Audit of all 32 axioms (upstream-base variant) - #18

Closed
vasnesterov wants to merge 2 commits into
upstream-basefrom
upstream-docs/axiom-audit
Closed

vasnesterov wants to merge 2 commits into
upstream-basefrom
upstream-docs/axiom-audit

Conversation

@vasnesterov

Copy link
Copy Markdown
Owner

Staged against upstream-base (a copy of digama0/master), not against our master — these fixes are already on master. This is the same work rebuilt on the upstream base so it is reviewable here and ready if you ever choose to send it on. Nothing has been submitted anywhere.


Adds docs/axiom-audit.md — an audit of all 32 axioms in Lean4Lean/Verify/Axioms.lean, against toolchain v4.33.0-rc2 and the C++ kernel at master. This is the evidence behind the inconsistent-axioms PR and the false-axioms PR.

Each axiom gets a verdict:

  • inconsistent — a machine-checked proof of False exists (2 axioms; each alone)
  • 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 (2 of them; Std.TreeMap.all_eq_all_toList and any_eq_any_toList follow from existing upstream lemmas)

11 of the 32 fail. Where a fix exists it is stated; the inconsistent-axioms PR and the false-axioms PR implement them.

The audit is read-only: it changes nothing under Lean4Lean/.

Also updates bugs-found.md

Eight numbered kernel/checker defects, with reproductions. These are present in this repository — checkPrimitiveDef, VEnv.HasPrimitives, TrEnv', Aligned, SExpr.Params and CtorBundle all exist here. They are marked "Fixed downstream" because the fixes live on branches of the fork, not in this PR.

Notes for review

  • §0 and §9 are framed in terms of Verify/Guard.lean's axiom whitelist and a kernel_sound theorem, neither of which exists in this repository — they are fork constructs. A note at the head says so. Every verdict is nonetheless a property of Verify/Axioms.lean as it stands here.
  • The two docstrings added by the inconsistent-axioms PR reference this file. If this PR is not taken, those two links should be dropped from that one.

🤖 Generated with Claude Code

vasnesterov and others added 2 commits August 23, 2026 05:03
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]>
(cherry picked from commit ce8cc4e)
The audit was written inside a fork that carries two files this repository
does not have -- `Verify/Soundness.lean`, stating an end-to-end
`kernel_sound`, and `Verify/Guard.lean`, a build-time check pinning that
theorem's axiom cone to a whitelist. Landed unedited, the document would
name machinery a reader here cannot find, and `bugs-found.md` would report
fixes as done that in fact live only on downstream branches.

Three corrections, no change to any verdict:

* A note at the head of `docs/axiom-audit.md` says where `Guard.lean`,
  `Soundness.lean` and `kernel_sound` come from, and which sections (§0,
  §9) are written in those terms. Everything else is a property of
  `Verify/Axioms.lean` as it stands here -- the two inconsistent axioms
  prove `False` in this tree too.
* Every "**Fixed**" in `bugs-found.md`'s two lean4lean sections becomes
  "**Fixed downstream**", with a lead-in on each section saying those
  fixes are separate changes not included here, so the defects are still
  present in this tree. The bugs themselves are real here: the constructs
  they name -- `checkPrimitiveDef`, `VEnv.HasPrimitives`, `TrEnv'`,
  `Aligned`, `SExpr.Params`, `CtorBundle` -- all exist in this repository.
* The "In the 32 frozen axioms" section said "Not yet audited ... an audit
  is in progress", which the same commit contradicts. It now states the
  result: 11 of the 32 do not hold as stated, two of them provably `False`
  on their own.

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

Copy link
Copy Markdown
Owner Author

Already on master — see #16. 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 29, 2026
…Inv alone

New `Theory/Typing/PropConv.lean` (~810 lines, sorry-free), plus a
**docstring-only** withdrawal of `PropShadow.lean`'s `PropUniq`
placement. Axioms whitelisted throughout; no `sorry`, none added.

**The headline, machine-checked: the handoff's verdict on `PropUniq` is
wrong.** `propUniq_of` closes **six of seven typing cases from `DefInv`
alone**, leaving only `app`. §5's table filed it as "endpoint-asserted,
`trans` fails, needs normalisation" -- but **that verdict is about the
route, not the statement**: §5 inverted both typings and **composed them
into a sort-sort conversion**, and *the composition manufactures the
arbitrary middle term*. Inducting on the **typing** judgment -- the same
manoeuvre `sortForallEDisjoint_of` already used in that file -- makes
`trans` a rule that never arises. **Trap #18.**

Consequences: a second, **unconditional** route (modulo `app`) to the
statement `SetModel/PropUniqFromFalse.lean` currently gets only from an
inhabitant of `falseProp`; and `PropTypeAgree`'s own `app` case consumes
`PropUniq`, so the syntactic side needed it too.

**`proofIrrel` and `eta`: one obstruction at `app`, two elsewhere.**
`eta` is **strictly cheaper** than recorded -- it applies
`SortForallEDisjoint` at `u = .zero` and nowhere else, and beyond
`DefInv` pays **nothing**. `proofIrrel` is **not irreducibly
self-referential**: it can be derived by typing induction from `DefInv`
plus one new, strictly weaker statement,

    SortNotProp : Γ ⊢ₙ A ≡ .sort u → Γ ⊢ₙ A : .sort .zero → False

machine-checked to follow from `PropConvInv` + `DefInv`, consumed in
exactly three cases.

**Why they differ, in one line, and it generalises: `DefInv` is a
*shape*-inversion principle.** A residual of the form "a term with a
sort type has no second type of kind `X`" is **free** at every
shape-pinned subject when `X` is a syntactic shape, and **not free**
when `X` is a *typing*, because `DefInv` transports no typing along a
conversion. Where they *are* one is at `app`, where the companion test
gives the same answer for both: the IH at the function is vacuous.

**The convergence: five statements, five `app` cases, one subject
shape** -- each **6 of 7** typing cases, and each `app` case
**equivalent to its own statement**, both directions machine-checked.
So the `app` position is **not a weaker sub-goal**, and that also
settles non-vacuity of the reductions. **Not claimed** that the five are
one statement: the natural unifier is **false**
(`typeShapeAgree_false`), and *reading result* -- that witness refutes
none of the five, since it gives one sort-shaped and one **stuck** type
while each case needs two.

Also landed: `PropConvInv` with all twelve cases -- **five close**,
seven named residuals, each closing from its residual and nothing else
(§5's "six of twelve" was an off-by-one, corrected). `PropTypeAgree`'s
`app` case priced exactly at `RegPi` + `InstLvl` + `PropUniq` +
`PropConvInv` -- the shadow's price **plus `RegPi`**, which its universe
formulation hid. `forallEDF` unpacked into `CtxConvProp` + `RegConv`,
the latter index-**preserving** and **not** what §15.2 refutes. **Every
statement and reduction is replayed at index 0**, so nothing is vacuous
-- with one flagged exception.

**Found false / not as expected.** **`extra` does *not* close
mechanically here** -- `DefInv`'s clauses use lhs-shape lemmas because
their *conclusion* is a shape; this conclusion is a **typing**, and a
rule's lhs can be a proposition. **Budget for it.** *Analysis*: even for
a δ-rule it needs an environment typing **at the index the rule
concludes at**, and environment facts enter `Stratified` only at *some*
index, with `mono` raising and nothing lowering. And **`RegPi` is not
shown satisfiable even at index 0** -- `Lookup` can return a Π-type
whose components were never typed, so it needs an `OnCtx` hypothesis the
targets do not carry; the one unsatisfied item, flagged at its
definition.

A definition detail that mattered: the five conversion-rule residuals
had to carry the rule's own conclusion as a premise -- without it one of
them is **false at `n = 0`**.

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