Skip to content

docs: audit of all 32 frozen axioms — two prove False on their own - #3

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

Documentation only. This is the evidence behind the axiom fix PRs, which cite it
by section.

What it is

Every one of the 32 axioms in Lean4Lean/Verify/Axioms.lean gets a verdict
backed by an attempted refutation, not by inspection. Method: read the C++
and Lean source for the function each axiom describes, then try to break it —
differential testing over a 1456-expression corpus, 21,523,360 levels for
normalize_eq, Level.beq against structural equality on 3280² pairs, and
PersistentHashMap over 300-key maps with engineered low-bit collisions plus
deliberately malformed nodes.

Results

verdict count
inconsistent on their own 2
jointly inconsistent (argued) 3
false of the implementation 4
true only under an unstated side condition 2
true 21 (of which 2 are provable outright today)

The two that prove False unaided:

  • Lean.Expr.looseBVarRange_eq — equates a 20-bit field read, which is
    provably < 2^20 with no axiom at all, against an unbounded model.
    (Expr.bvar 1048575).looseBVarRange' = 2^20.
  • Lean.Level.mkLevelIMaxCore_eq — the model carries an extra
    || u matches .succ .zero disjunct that upstream has in neither
    v4.33.0-rc2 nor master, and mkLevelIMaxCore is a plain private def, so
    the equation is decidable and false.

Why this matters

Guard 2 of Lean4Lean/Verify/Guard.lean whitelists these axioms by name. An
inconsistent axiom therefore makes kernel_sound provable vacuously while the
guard reports success. The guard cannot be the thing that catches this, and
consistency is not checkable in general — which is why the audit exists.

Today it is latent, not exploited: Verify/Soundness.lean imports nothing from
the refinement layer, so kernel_sound's cone is currently just
{propext, sorryAx, Classical.choice, Quot.sound}.

Also recorded

  • A guard-coverage gap. Guard 1 scans only Axioms.lean, so it cannot see
    the 9 axioms declared elsewhere in the repo — seven _native.bv_decide.ax_*
    from the bv_decide calls in Verify/{Expr,Level}.lean, plus
    Lean4Lean.ptrEqExpr_eq and ptrEqConstantInfo_eq. None is whitelisted, and
    guard 2 will fail on all nine the moment kernel_sound is wired to the
    refinement layer.
  • Two free wins. Std.TreeMap.all_eq_all_toList and any_eq_any_toList are
    provable today from upstream's Impl.all_eq_all_toListModel. Removing them,
    plus the mkLevelIMaxCore_eq fix, takes the trusted base from 32 to 29.
  • A rule worth keeping. Both outright inconsistencies come from equating a
    model with something not opaque. An axiom about an @[extern]/partial
    constant can only be wrong about the implementation; one about a transparent
    constant can be wrong about mathematics.

bugs-found.md is restructured into four sections — Lean's own 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 (positivity checked
on the whnf of an un-normalised stored type; mutual blocks whose types cannot
mention each other; borrow annotations on the Nat primitives' declared types).

No Lean file is touched by this PR.

🤖 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

Create a PR with fix for each problem. This PR is not needed

@vasnesterov

Copy link
Copy Markdown
Owner Author

Closing as requested — the audit will not land as a document. Each finding it contains is being opened as its own fix PR instead, with the machine-checked witness and the proposed correction inline in the PR body so nothing depends on this file.

Tracking, one PR per problem:

  • Lean.Level.mkLevelIMaxCore_eq proves False alone — fix: mkLevelIMaxCore_eq is a false axiom (proves False) #1 (merged)
  • Lean.Expr.looseBVarRange_eq proves False alone
  • Lean.Level.mkData_eq / Lean.Expr.mkData_eq assert a return value where the C function aborts, and the first is jointly inconsistent with hasParam_eq/hasMVar_eq
  • Lean.Expr.instantiate_eq — simultaneous vs sequential
  • Lean.Expr.abstract_eq — capture, and last-wins on duplicates
  • Lean.PersistentArray.toList'_push — missing WF
  • Lean.Expr.instantiateRange_eq / instantiateRevRange_eq — missing side condition

Two further items from the audit are not bugs and so are not being filed as fixes: Std.TreeMap.all_eq_all_toList and any_eq_any_toList are now provable outright from upstream, and guard 1 scans only Axioms.lean so it cannot see the nine axioms declared elsewhere in the repo. Say the word if you want either as a PR.

@vasnesterov
vasnesterov deleted the docs/axiom-audit branch August 22, 2026 12:39
@vasnesterov
vasnesterov restored the docs/axiom-audit branch August 23, 2026 03:31
vasnesterov pushed a commit that referenced this pull request Aug 23, 2026
…d a guard class the audit missed

**The systemic finding: a guard class §6/§7.1 did not account for.** Every
`@[extern]` C entry point in scope that takes a `Nat` begins with a
**`lean_is_scalar` bignum test -- before** the range test the audit
records. `LEAN_MAX_SMALL_NAT = SIZE_MAX >> 1`, so it fires at `2^63`.
§6 describes `lean_expr_instantiate_range` as "starts with
`if (b > e || e > sz) lean_internal_panic`" -- that is the function's
**second** statement, not its first. **Seven axioms in scope sit on that
guard**, and it resolves four different ways.

## #21 `Lean.Expr.liftLooseBVars_eq` is FALSE

    if (!lean_is_scalar(s) || !lean_is_scalar(d)) { lean_inc(e); return e; }

Witness `e := .bvar 0`, `s := 0`, `d := 2^63`. Both halves
machine-checked, deliberately **by different instruments**:

- C side, differential test on compiled code:
  `#eval idx ((Expr.bvar 0).liftLooseBVars 0 (2^63))` prints `"bvar 0"`.
- Model side, kernel reduction:
  `liftLooseBVars' (.bvar 0) 0 (2^63) = .bvar (2^63)`, and `≠ .bvar 0`.

So the axiom asserts `.bvar 0 = .bvar (2^63)`.

Worse than #26/digama0#27 in one specific way: **the call completes.** No
panic, no exotic input -- `2^63` is an ordinary literal and `.bvar 0` an
ordinary `Expr`. Only the *model's* output is not runtime-constructible,
which is why the two sides cannot be evaluated in one expression
(`#eval` of the model's answer trips `lean_expr_mk_data`'s own panic --
observed).

**Not an inconsistency**: `liftLooseBVars` is `opaque @[extern]` and the
toolchain has no core theorem about it, so there is no second fact to
contradict. Same category as #12/#17. Fix is `d < 2^63` or a `USize`
restatement -- frozen file, needs sign-off.

## Three failed attacks, recorded as failed attacks

- **#22, digama0#30** carry the same guard and **survive**: the C fallback
  coincides with the model on every input a real `Expr` can supply,
  with machine-checked agreement lemmas for both. One of the stream's
  own witnesses was wrong -- `(.bvar 7).lowerLooseBVars (2^63) 1`
  returns `bvar 7` from *both* sides -- and the correction is recorded
  rather than quietly dropped.
- **digama0#29 `abstractRange_eq`**, the only unconditional range axiom, also
  survives: its fallback uses `lean_array_size` and `Array.extract 0 n`
  clamps to the same thing, agreeing at **every** input, logical or not.
  Verdict unchanged, for a reason §7.1 did not state.

## #26/digama0#27: the side condition is necessary but NOT sufficient

`start ≤ stop ≤ subst.size` excludes the second guard, not the first --
`stop` may be non-scalar provided `subst.size` is too, which needs
`subst.size ≥ 2^63`: expressible, not constructible. Strictly weaker
than #21, no differential test possible. **Source reading only, and
marked as such.**

## The two other priority targets, answered

- **#17 `Expr.mkData_eq` -- no analogous consequence.**
  `lean_expr_mk_data` panics twice, and its hypothesis implies **both**
  are passed; the `approxDepth` clamp matches too. Unlike #12, correctly
  guarded.
- **#3 `PersistentArray.toList'_push` -- hypothesis adequate**, in the
  strongest available sense: `WF` is generated by `empty`/`push` only,
  and a reverse scan shows lean4lean uses **no other `PersistentArray`
  operation**. So `WF` is exactly the reachable set, not an
  approximation.

Not reached: #4-#7. **digama0#31's dependency on #15 deliberately not pursued**
-- #15 belongs to another stream's section, and a cross-section attack
run from one side only is the weaker version of the test.

**No `False` was derived.** §11.9 keeps the evidence strengths separate:
differential-test-plus-source, source-only, and proof are three
different things, and none of this is a proof.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
vasnesterov pushed a commit that referenced this pull request Sep 4, 2026
…exact edit, in writing

I had queued 'close census holes #3 and #4, 13 -> 11' and recorded that it was my call and I was taking it,
on the grounds that a hole which can be honestly closed should be. Opening the file to apply it, both sorry
sites begin 'Still sorry, deliberately' and name the exact proof term my audit proposed.

Their argument is better than mine on every point. The close is not honest: the producer does not mention
the first term at all, so the conclusion would hold for a completely arbitrary translation of it — it proves
the branch is dead, not that the checker is sound on it, and 'honestly closable' was my whole justification.
The producer is a deliberate tripwire, kept live because it goes red the moment the nested construction gains
constructors, which is when the obligation becomes real — closing the hole trades a loud failure for a silent
one at exactly that moment. And the real statement is already in the file: the hole is that statement with
its two hypotheses removed, neither provable today.

Cancelled, not deferred, with the queue entry struck through rather than deleted so the reversal stays
visible.

Three things I take from it. My audit read the producers and not the holes — it verified the one-line close
elaborates and ranked it first without reading the docstring attached to the very sorry it proposed to fill,
and its one piece of restraint (leave the third hole alone, its sorry carries information) was right for a
reason that applies verbatim to the other two. 'Look at the target before overwriting' is the only reason
this did not land: a census number would have improved and the project would have been worse. And I had the
trade backwards — a census that counts vacuous closes is worse than one that overstates, because two of
those thirteen entries are load-bearing tripwires and the source says so.

Standing brief line added: before proposing a proof for a hole, read that hole's own docstring and quote it.

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