From 34870a48b46c862cc99f8f4be41691374a08b922 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:05:17 +0000 Subject: [PATCH 1/5] Prove APP-1's middle clause in Agda, Rocq and Lean MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Owner ruling 2026-11-17: prove APP-1 as stated rather than narrow it. The claim reads: "A verdict is 'no' on a known breach and otherwise missing when any value it depends on is missing; it is never 'yes' then." breach-decides gave the first clause, and verdict-yes gave the third only by contraposition. The middle clause was stated by no declaration (audit finding 33). In each prover, following its existing naming: - verdict-missing / verdict_missing: with no known breach, a verdict is missing when any per-period value it depends on is missing. Its hypothesis is the negation of breach-decides's hypothesis, so the two theorems split the cases between them. - verdict-not-false: with no known breach the verdict is never a known "no". This is the invariant the middle clause needs. - verdict-not-yes: some value missing means the verdict is never "yes". The third clause is now a declaration, not a contrapositive. - Helpers: ∧-false-inv, ∧-missing-left/right, missing≢given and All-Any-⊥ (Rocq/Lean: kand_false_inv, kand_missing_left/right, forall_exists_absurd). No definition changes. Checked locally with scripts/check-proofs.sh: agda Agda 2.7.0.1 PASS; postulates: none in the cone coq coqc 8.18.0 PASS; Cohort.v closed under the global context for 89 theorems (was 82, +7) lean4 Lean 4.29.0 PASS; Cohort.lean no axioms for 102 (98dc76e3c0a9) theorems (was 95, +7) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDf73vaDJwGZ3qMSeH3 --- verification/proofs/agda/Applied/Missing.agda | 65 +++++++++++++++++ verification/proofs/coq/Cohort.v | 70 +++++++++++++++++++ verification/proofs/lean4/Cohort.lean | 61 ++++++++++++++++ 3 files changed, 196 insertions(+) diff --git a/verification/proofs/agda/Applied/Missing.agda b/verification/proofs/agda/Applied/Missing.agda index 969b310..b804b48 100644 --- a/verification/proofs/agda/Applied/Missing.agda +++ b/verification/proofs/agda/Applied/Missing.agda @@ -12,6 +12,11 @@ -- is missing (APP-1): it is the constructor `missing`, never a number such -- as zero. Read the other way, an output is never more certain than an -- input it depends on (APP-4). +-- +-- The verdicts are three-valued (Kleene conjunction): breach-decides gives +-- "no" on a known breach; verdict-missing gives "missing" when there is no +-- known breach and a value the verdict depends on is missing; verdict-yes +-- and verdict-not-yes give that it is never "yes" then. module Applied.Missing where @@ -46,6 +51,12 @@ All-map : ∀ {A} {P Q : A → Set} → (∀ {x} → P x → Q x) → ∀ xs → All-map f [] _ = tt All-map f (x ∷ xs) (p , ps) = f p , All-map f xs ps +-- A property every element has and one some element has cannot clash. +All-Any-⊥ : ∀ {A} {P Q : A → Set} xs → All P xs → Any Q xs → (∀ {x} → P x → Q x → ⊥) → ⊥ +All-Any-⊥ [] _ () _ +All-Any-⊥ (x ∷ xs) (p , _) (inj₁ q) k = k p q +All-Any-⊥ (x ∷ xs) (_ , ps) (inj₂ q) k = All-Any-⊥ xs ps q k + if-false : ∀ {A : Set} {b : Bool} {x y : A} → b ≡ false → (if b then x else y) ≡ y if-false refl = refl @@ -140,6 +151,31 @@ module Proofs (N : Number) where ∧-false-right {given s true} {t = t} refl = s ⊓ t , refl ∧-false-right {missing} {t = t} refl = t , refl + -- A known "no" comes from a known "no" on one side. + ∧-false-inv : ∀ {x y s} → x ∧ᵏ y ≡ given s false → + Σ Status (λ s′ → x ≡ given s′ false) ⊎ Σ Status (λ t → y ≡ given t false) + ∧-false-inv {given s′ false} eq = inj₁ (s′ , refl) + ∧-false-inv {given s′ true} {given t b} eq = inj₂ (t , cong (given t) (cong truth eq)) + ∧-false-inv {given s′ true} {missing} () + ∧-false-inv {missing} {given t false} eq = inj₂ (t , refl) + ∧-false-inv {missing} {given t true} () + ∧-false-inv {missing} {missing} () + + -- A missing side gives a missing result, unless the other side is a + -- known "no". + ∧-missing-left : ∀ {x y} → x ≡ missing → (∀ t → y ≡ given t false → ⊥) → x ∧ᵏ y ≡ missing + ∧-missing-left {y = given t false} refl nf = ⊥-elim (nf t refl) + ∧-missing-left {y = given t true} refl nf = refl + ∧-missing-left {y = missing} refl nf = refl + + ∧-missing-right : ∀ {x y} → (∀ s → x ≡ given s false → ⊥) → y ≡ missing → x ∧ᵏ y ≡ missing + ∧-missing-right {given s false} nf refl = ⊥-elim (nf s refl) + ∧-missing-right {given s true} nf refl = refl + ∧-missing-right {missing} nf refl = refl + + missing≢given : ∀ {s} {b : Bool} → missing ≡ given s b → ⊥ + missing≢given () + module _ (i : Inputs) where open Inputs i open Run i @@ -221,6 +257,35 @@ module Proofs (N : Number) where breach-decides f (r ∷ rs) (inj₂ p) with breach-decides f rs p ... | t , eq = ∧-false-right {f r} {verdict f rs} eq + -- With no known breach, the verdict is never a known "no". + verdict-not-false : ∀ (f : Row → Val Bool) rs → + (Any (λ r → Σ Status (λ s → f r ≡ given s false)) rs → ⊥) → + ∀ s → verdict f rs ≡ given s false → ⊥ + verdict-not-false f [] nb s eq = false≢true (sym (cong truth eq)) + verdict-not-false f (r ∷ rs) nb s eq with ∧-false-inv {f r} {verdict f rs} eq + ... | inj₁ b = nb (inj₁ b) + ... | inj₂ (t , e) = verdict-not-false f rs (λ p → nb (inj₂ p)) t e + + -- APP-1, the middle clause: with no known breach, a verdict is missing + -- when any value it depends on is missing. + verdict-missing : ∀ (f : Row → Val Bool) rs → + (Any (λ r → Σ Status (λ s → f r ≡ given s false)) rs → ⊥) → + Any (λ r → f r ≡ missing) rs → verdict f rs ≡ missing + verdict-missing f [] nb () + verdict-missing f (r ∷ rs) nb (inj₁ m) = + ∧-missing-left {f r} {verdict f rs} m (verdict-not-false f rs (λ p → nb (inj₂ p))) + verdict-missing f (r ∷ rs) nb (inj₂ p) = + ∧-missing-right {f r} {verdict f rs} (λ s e → nb (inj₁ (s , e))) + (verdict-missing f rs (λ q → nb (inj₂ q)) p) + + -- And it is never "yes" then: a "yes" needs every value it depends on + -- to be a known "yes" (verdict-yes). + verdict-not-yes : ∀ {u} (f : Row → Val Bool) rs → + Any (λ r → f r ≡ missing) rs → verdict f rs ≡ given u true → ⊥ + verdict-not-yes f rs m eq = + All-Any-⊥ rs (verdict-yes f rs eq) m + (λ { (s , ey , _) em → missing≢given (subst (λ v → v ≡ given s true) em ey) }) + -- The funding gap is given only when every shortfall is given, with a -- status at least that of the gap. gap-needs : ∀ {u} rs → Covers u (worst rs) → All (λ r → Covers u (Row.shortfall r)) rs diff --git a/verification/proofs/coq/Cohort.v b/verification/proofs/coq/Cohort.v index 24a94b9..736363a 100644 --- a/verification/proofs/coq/Cohort.v +++ b/verification/proofs/coq/Cohort.v @@ -311,6 +311,30 @@ Proof. - exists s. reflexivity. Qed. +(** A known "no" comes from a known "no" on one side. *) +Lemma kand_false_inv : forall x y s, kand x y = given s false -> + (exists s', x = given s' false) \/ (exists t, y = given t false). +Proof. + intros [|s' [|]] [|t [|]] s e; simpl in e; try discriminate; + first [ left; eexists; reflexivity | right; eexists; reflexivity ]. +Qed. + +(** A missing side gives a missing result, unless the other side is a known + "no". *) +Lemma kand_missing_left : forall x y, x = missing -> + (forall t, y <> given t false) -> kand x y = missing. +Proof. + intros x [|t [|]] -> nf; simpl; try reflexivity. + exfalso. exact (nf t eq_refl). +Qed. + +Lemma kand_missing_right : forall x y, (forall s, x <> given s false) -> + y = missing -> kand x y = missing. +Proof. + intros [|s [|]] y nf ->; simpl; try reflexivity. + exfalso. exact (nf s eq_refl). +Qed. + Section Model. Variable N : Number. @@ -469,6 +493,52 @@ Proof. - destruct (IH p) as [t e]. exact (kand_false_right _ _ _ e). Qed. +(** With no known breach, the verdict is never a known "no". *) +Lemma verdict_not_false : forall (f : Row -> Val bool) rs, + ~ Exists' (fun r => exists s, f r = given s false) rs -> + forall s, verdict f rs <> given s false. +Proof. + intro f. induction rs as [|r rs IH]; simpl; intros nb s e; [discriminate|]. + destruct (kand_false_inv _ _ _ e) as [b | [t e']]. + - exact (nb (or_introl b)). + - exact (IH (fun p => nb (or_intror p)) t e'). +Qed. + +(** APP-1, the middle clause: with no known breach, a verdict is missing when + any value it depends on is missing. *) +Lemma verdict_missing : forall (f : Row -> Val bool) rs, + ~ Exists' (fun r => exists s, f r = given s false) rs -> + Exists' (fun r => f r = missing) rs -> verdict f rs = missing. +Proof. + intro f. induction rs as [|r rs IH]; simpl; intros nb m; [destruct m|]. + destruct m as [m | p]. + - apply kand_missing_left; [exact m|]. + exact (verdict_not_false f rs (fun p => nb (or_intror p))). + - apply kand_missing_right. + + intros s e. exact (nb (or_introl (ex_intro _ s e))). + + exact (IH (fun q => nb (or_intror q)) p). +Qed. + +(** A property every element has and one some element has cannot clash. *) +Lemma forall_exists_absurd : forall {A : Type} (P Q : A -> Prop) xs, + Forall' P xs -> Exists' Q xs -> (forall x, P x -> Q x -> False) -> False. +Proof. + intros A P Q xs. induction xs as [|x xs IH]; simpl; intros all ex k; [exact ex|]. + destruct all as [px rest]. destruct ex as [qx | ex]. + - exact (k x px qx). + - exact (IH rest ex k). +Qed. + +(** And it is never "yes" then: a "yes" needs every value it depends on to be + a known "yes" (verdict_yes). *) +Lemma verdict_not_yes : forall (f : Row -> Val bool) rs u, + Exists' (fun r => f r = missing) rs -> verdict f rs <> given u true. +Proof. + intros f rs u m e. + apply (forall_exists_absurd _ _ rs (verdict_yes f rs u e) m). + intros r [s [ey _]] em. rewrite em in ey. discriminate. +Qed. + Lemma gap_needs : forall u rs, Covers u (worst rs) -> Forall' (fun r => Covers u (shortfall r)) rs. Proof. intro u. induction rs as [|r rs IH]; simpl; intro c; [exact I|]. diff --git a/verification/proofs/lean4/Cohort.lean b/verification/proofs/lean4/Cohort.lean index a0212fd..5eda5da 100644 --- a/verification/proofs/lean4/Cohort.lean +++ b/verification/proofs/lean4/Cohort.lean @@ -495,6 +495,31 @@ theorem kand_false_right : ∀ {x y : Val Bool} {t : Status}, y = given t false | given s true, _, t, rfl => ⟨meet s t, rfl⟩ | missing, _, t, rfl => ⟨t, rfl⟩ +/-- A known "no" comes from a known "no" on one side. -/ +theorem kand_false_inv : ∀ {x y : Val Bool} {s : Status}, kand x y = given s false → + (∃ s', x = given s' false) ∨ (∃ t, y = given t false) + | given s' false, _, _, _ => Or.inl ⟨s', rfl⟩ + | given _ true, given t false, _, _ => Or.inr ⟨t, rfl⟩ + | given _ true, given _ true, _, e => nomatch e + | given _ true, missing, _, e => nomatch e + | missing, given t false, _, _ => Or.inr ⟨t, rfl⟩ + | missing, given _ true, _, e => nomatch e + | missing, missing, _, e => nomatch e + +/-- A missing side gives a missing result, unless the other side is a known +"no". -/ +theorem kand_missing_left : ∀ {x y : Val Bool}, x = missing → + (∀ t, y ≠ given t false) → kand x y = missing + | _, given t false, rfl, nf => absurd rfl (nf t) + | _, given _ true, rfl, _ => rfl + | _, missing, rfl, _ => rfl + +theorem kand_missing_right : ∀ {x y : Val Bool}, (∀ s, x ≠ given s false) → + y = missing → kand x y = missing + | given s false, _, nf, _ => absurd rfl (nf s) + | given _ true, _, _, rfl => rfl + | missing, _, _, rfl => rfl + theorem breach_decides (f : Row N → Val Bool) : ∀ rs, Exists' (fun r => ∃ s, f r = given s false) rs → ∃ u, verdict f rs = given u false | [], h => nomatch h @@ -503,6 +528,42 @@ theorem breach_decides (f : Row N → Val Bool) : match breach_decides f rs p with | ⟨_, e⟩ => kand_false_right e +/-- With no known breach, the verdict is never a known "no". -/ +theorem verdict_not_false (f : Row N → Val Bool) : + ∀ rs, ¬ Exists' (fun r => ∃ s, f r = given s false) rs → + ∀ s, verdict f rs ≠ given s false + | [], _, _, e => nomatch e + | _ :: rs, nb, _, e => + match kand_false_inv e with + | Or.inl b => nb (Or.inl b) + | Or.inr ⟨t, h⟩ => verdict_not_false f rs (fun p => nb (Or.inr p)) t h + +/-- APP-1, the middle clause: with no known breach, a verdict is missing when +any value it depends on is missing. -/ +theorem verdict_missing (f : Row N → Val Bool) : + ∀ rs, ¬ Exists' (fun r => ∃ s, f r = given s false) rs → + Exists' (fun r => f r = missing) rs → verdict f rs = missing + | [], _, m => nomatch m + | _ :: rs, nb, Or.inl m => + kand_missing_left m (verdict_not_false f rs (fun p => nb (Or.inr p))) + | _ :: rs, nb, Or.inr p => + kand_missing_right (fun s e => nb (Or.inl ⟨s, e⟩)) + (verdict_missing f rs (fun q => nb (Or.inr q)) p) + +/-- A property every element has and one some element has cannot clash. -/ +theorem forall_exists_absurd {α : Type} {P Q : α → Prop} : + ∀ xs, Forall P xs → Exists' Q xs → (∀ x, P x → Q x → False) → False + | [], _, h, _ => nomatch h + | _ :: _, ⟨p, _⟩, Or.inl q, k => k _ p q + | _ :: xs, ⟨_, ps⟩, Or.inr h, k => forall_exists_absurd xs ps h k + +/-- And it is never "yes" then: a "yes" needs every value it depends on to be +a known "yes" (`verdict_yes`). -/ +theorem verdict_not_yes {u : Status} (f : Row N → Val Bool) (rs : List (Row N)) + (m : Exists' (fun r => f r = missing) rs) : verdict f rs ≠ given u true := + fun e => forall_exists_absurd rs (verdict_yes f rs e) m + (fun _ ⟨_, ey, _⟩ em => nomatch em.symm.trans ey) + theorem gap_needs {u : Status} : ∀ rs : List (Row N), Covers u (worst rs) → Forall (fun r => Covers u r.shortfall) rs | [], _ => True.intro From 206d0732a81bad580bb78d4aa8b319f7ae99d14b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:07:10 +0000 Subject: [PATCH 2/5] Audit definitions too, and refuse an empty audit (closes THY-1's Lean hole) Proof audit 2026-11-16, finding 31: THY-1's Lean leg recorded "no axiom" from an audit that inspected none of its results. The leg is Type-valued, as the Agda is, so reachMono, absentBelow, onMono, onMonoAll, edgeMono and absentUnderAllFeatures are all `def`s, and the Lean audit kept only theorems. The defect is in the gate, not only in that file. Measured on main b075e44 with tests/proofs/gate_controls_test.sh's harness, the gate PASSED each of these: Lean `def planted : 2 + 2 = 5 := sorry` "axioms: none for 0" Lean `axiom bad : False` + a def using it "axioms: none for 0" Rocq `Definition planted : 2 + 2 = 5. Admitted.` "no theorem declared" Rocq `Axiom bad : False.` + a Definition using it "no theorem declared" Fix, at source (scripts/check-proofs.sh): - lean4: audit every theorem AND every definition that carries a source range (Lean.collectAxioms, as #print axioms). That includes the definitions Lean generates for an inductive with its range, so the receipt note says "with a source range", not "declared". - coq: Print Assumptions also for Example, Definition, Fixpoint and CoFixpoint. - Both: an audit that inspects nothing FAILS instead of passing. tests/proofs/gate_controls_test.sh plants, for Rocq and Lean, an escape inside a definition and a module with nothing to audit. All four new controls FAIL against the pre-fix gate and are caught by the fixed one. THY-1's Lean leg needed no restatement. Its results were never axiom-dependent (`#print axioms` reports none for each of the six, Lean 4.29.0). What was missing was evidence, and the gate now produces it: FeatureReachability.lean axioms: none for 2 theorem(s) and 48 definition(s) with a source range, THY-1's six results among them FeatureReachability.v closed under the global context for 11 declarations (was 1 theorem) Cohort.lean none for 102 theorems and 128 definitions Cohort.v closed for 134 declarations (was 89) check-proofs.sh agda|coq|lean4 and gate_controls_test.sh agda|coq|lean4 all exit 0 locally (Agda 2.7.0.1, coqc 8.18.0, Lean 4.29.0). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDf73vaDJwGZ3qMSeH3 --- scripts/check-proofs.sh | 61 +++++++++++++++++++----------- tests/proofs/gate_controls_test.sh | 18 ++++++++- 2 files changed, 55 insertions(+), 24 deletions(-) diff --git a/scripts/check-proofs.sh b/scripts/check-proofs.sh index f341e3f..8e57090 100755 --- a/scripts/check-proofs.sh +++ b/scripts/check-proofs.sh @@ -100,12 +100,22 @@ check_one() { # agda : the first-party modules of the import cone that Agda itself reports # go through scan-postulates.sh (the reference gate of januskey). # coq : `Print Assumptions` for every Theorem, Lemma, Corollary, Proposition, -# Fact and Remark of the file must print "Closed under the global -# context". -# lean4: every theorem the source declares must depend on no axiom -# (Lean.collectAxioms, the function behind #print axioms). The -# lemmas Lean generates for an inductive are not witnesses. -# Each audit fails closed: if it cannot show that it ran, the module fails. +# Fact, Remark, Example, Definition, Fixpoint and CoFixpoint of the +# file must print "Closed under the global context". +# lean4: every theorem and every definition that carries a source range +# must depend on no axiom (Lean.collectAxioms, the function behind +# #print axioms). That covers each declaration of the source, and +# the definitions Lean generates for an inductive with its range +# (casesOn, recOn, below, brecOn, ...), which are counted too. The +# lemmas Lean generates (injEq, inj, sizeOf_spec) carry no range. +# Definitions are audited as well as theorems because a development can +# carry its results as definitions: THY-1's Lean leg is Type-valued, so every +# result there is a `def`, and an audit of theorems alone inspected none of +# them (proof audit 2026-11-16, finding 31). Measured before this fix: a Lean +# module whose only declaration was `def planted : 2 + 2 = 5 := sorry`, or a +# Rocq file whose only declaration was an Admitted Definition, PASSED. +# Each audit fails closed: if it cannot show that it ran, or if it inspected +# no declaration at all, the module fails. An empty audit is not a clean one. # Both axiom reports are transitive: a theorem's report covers every Fixpoint, # Definition or def it uses. A declaration that no audited theorem uses is not # reported; Lean still warns on its sorry, and Rocq still compiles its Admitted. @@ -145,11 +155,11 @@ audit_one() { s = $0; sub(/^[ \t]*Module[ \t]+/, "", s); sub(/[^A-Za-z0-9_'\''].*/, "", s); stack[++d] = "M:" s; next } /^[ \t]*Section[ \t]/ { stack[++d] = "S:"; next } /^[ \t]*End[ \t]/ { if (d > 0) d--; next } - /^[ \t]*(Theorem|Lemma|Corollary|Proposition|Fact|Remark)[ \t]/ { + /^[ \t]*(Theorem|Lemma|Corollary|Proposition|Fact|Remark|Example|Definition|Fixpoint|CoFixpoint)[ \t]/ { s = $0; sub(/^[ \t]*[A-Za-z]+[ \t]+/, "", s); sub(/[^A-Za-z0-9_'\''].*/, "", s) q = ""; for (i = 1; i <= d; i++) if (stack[i] ~ /^M:/) q = q substr(stack[i], 3) "." print q s }' "$ROOT/$root/$rel")" - if [ -z "$names" ]; then rm -rf "$dir"; LAST_OUT=""; AUDIT_NOTE="no theorem declared"; return 0; fi + if [ -z "$names" ]; then rm -rf "$dir"; LAST_OUT="axiom audit: no theorem or definition declared, so nothing was audited"; return 1; fi { cat "$ROOT/$root/$rel"; echo; while IFS= read -r n; do echo "Print Assumptions $n."; done <<<"$names"; } \ >"$ROOT/$root/$copy.v" set +e; out="$(cd "$ROOT/$root" && coqc "$copy.v" 2>&1)"; rc=$?; set -e @@ -157,8 +167,8 @@ audit_one() { expect="$(grep -c . <<<"$names")" got="$(grep -c '^Closed under the global context' <<<"$out" || true)" if [ "$rc" -eq 0 ] && [ "$got" -eq "$expect" ]; then rc=0 - AUDIT_NOTE="Print Assumptions: closed under the global context for $expect theorem(s): $(tr '\n' ' ' <<<"$names")" - else rc=1; out="axiom audit: $got of $expect theorem(s) closed under the global context"$'\n'"$out"; fi + AUDIT_NOTE="Print Assumptions: closed under the global context for $expect declaration(s): $(tr '\n' ' ' <<<"$names")" + else rc=1; out="axiom audit: $got of $expect declaration(s) closed under the global context"$'\n'"$out"; fi ;; lean4) { echo "import Lean"; cat "$ROOT/$root/$rel"; cat <<'LEAN' @@ -167,23 +177,30 @@ open Lean Elab Command in #eval show CommandElabM Unit from do let env ← getEnv let mut n := 0 + let mut m := 0 for (name, ci) in env.constants.map₂.toList do - -- Only theorems the source declares: the lemmas Lean generates for an - -- inductive (injEq, inj, sizeOf_spec) carry no declaration range. - if let .thmInfo _ := ci then - if (← liftCoreM (findDeclarationRanges? name)).isNone then continue - n := n + 1 - let axs ← Lean.collectAxioms name - unless axs.isEmpty do - logInfo m!"GATE-AXIOMS {name}: {axs.toList}" - logInfo m!"GATE-AUDIT-DONE {n}" + -- Theorems and definitions the source declares: the declarations Lean + -- generates (injEq, inj, sizeOf_spec, match_1, …) carry no range. + let isThm := match ci with | .thmInfo _ => true | _ => false + let isDef := match ci with | .defnInfo _ => true | .opaqueInfo _ => true | _ => false + unless isThm || isDef do continue + if (← liftCoreM (findDeclarationRanges? name)).isNone then continue + if isThm then n := n + 1 else m := m + 1 + let axs ← Lean.collectAxioms name + unless axs.isEmpty do + logInfo m!"GATE-AXIOMS {name}: {axs.toList}" + logInfo m!"GATE-AUDIT-DONE {n} {m}" LEAN } >"$dir/Audit.lean" set +e; out="$(cd "$ROOT/$root" && lean "$dir/Audit.lean" 2>&1)"; rc=$?; set -e - if [ "$rc" -ne 0 ] || ! grep -q 'GATE-AUDIT-DONE' <<<"$out" || grep -q 'GATE-AXIOMS' <<<"$out"; then - rc=1; out="axiom audit: a theorem depends on an axiom, or the audit did not run"$'\n'"$(grep -E 'GATE-|error' <<<"$out" || printf '%s' "$out")" + thms="$(sed -n 's/.*GATE-AUDIT-DONE \([0-9]*\) \([0-9]*\).*/\1/p' <<<"$out")" + defs="$(sed -n 's/.*GATE-AUDIT-DONE \([0-9]*\) \([0-9]*\).*/\2/p' <<<"$out")" + if [ "$rc" -ne 0 ] || [ -z "$thms" ] || grep -q 'GATE-AXIOMS' <<<"$out"; then + rc=1; out="axiom audit: a declaration depends on an axiom, or the audit did not run"$'\n'"$(grep -E 'GATE-|error' <<<"$out" || printf '%s' "$out")" + elif [ $((thms + defs)) -eq 0 ]; then + rc=1; out="axiom audit: no theorem or definition declared, so nothing was audited" fi - [ "$rc" -eq 0 ] && AUDIT_NOTE="axioms: none for $(sed -n 's/.*GATE-AUDIT-DONE \([0-9]*\).*/\1/p' <<<"$out") declared theorem(s)" + [ "$rc" -eq 0 ] && AUDIT_NOTE="axioms: none for $thms theorem(s) and $defs definition(s) with a source range" ;; *) rc=0; out="" ;; esac diff --git a/tests/proofs/gate_controls_test.sh b/tests/proofs/gate_controls_test.sh index 27a4fb1..434da7d 100755 --- a/tests/proofs/gate_controls_test.sh +++ b/tests/proofs/gate_controls_test.sh @@ -4,6 +4,9 @@ # without it (re-anchoring plan WO 1.3): an Agda `postulate`, a Rocq # `Admitted`, a Lean `sorry`. Each of these compiled, or would have, before # the axiom audit. A decoy in a comment must not fail the gate. +# For Rocq and Lean the escape is also planted in a DEFINITION, and a module +# with nothing to audit is planted too. Before the audit covered definitions +# and refused an empty domain, all four of those passed (measured 2026-11-17). # Usage: bash tests/proofs/gate_controls_test.sh agda|coq|lean4 # Needs the prover on PATH; an absent prover fails, as in the gate itself. set -euo pipefail @@ -20,10 +23,15 @@ data N : Set where postulate X : Set' ;; coq) ext=v; clean='(* Admitted. in a comment *) Theorem clean : 1 + 1 = 2. Proof. reflexivity. Qed.' - planted='Theorem planted : 2 + 2 = 5. Admitted.' ;; + planted='Theorem planted : 2 + 2 = 5. Admitted.' + planted_def='Definition planted : 2 + 2 = 5. +Admitted.' + empty='(* nothing to audit *)' ;; lean4) ext=lean; clean='-- sorry in a comment theorem clean : 1 + 1 = 2 := rfl' - planted='theorem planted : 2 + 2 = 5 := by sorry' ;; + planted='theorem planted : 2 + 2 = 5 := by sorry' + planted_def='def planted : 2 + 2 = 5 := sorry' + empty='-- nothing to audit' ;; *) echo "unknown prover: $prover" >&2; exit 2 ;; esac run() { # name body -> exit status of the gate on a tree holding that module @@ -39,4 +47,10 @@ if run Clean "$clean"; then echo "PASS: $prover clean control passes" else echo "FAIL: $prover clean control failed"; cat "$t/Clean.log"; fail=1; fi if run Planted "$planted"; then echo "FAIL: $prover planted escape passed the gate"; cat "$t/Planted.log"; fail=1 else echo "PASS: $prover planted escape fails the gate"; fi +if [ -n "${planted_def:-}" ]; then + if run PlantedDef "$planted_def"; then echo "FAIL: $prover escape planted in a definition passed the gate"; cat "$t/PlantedDef.log"; fail=1 + else echo "PASS: $prover escape planted in a definition fails the gate"; fi + if run Empty "$empty"; then echo "FAIL: $prover module with nothing to audit passed the gate"; cat "$t/Empty.log"; fail=1 + else echo "PASS: $prover module with nothing to audit fails the gate"; fi +fi exit "$fail" From d0128e2aaad238837954d9323e67f83746018c7f Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 03:08:00 +0000 Subject: [PATCH 3/5] Record APP-1's middle clause and the corrected THY-1 Lean axiom evidence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PROOF-STATUS: - APP-1: one theorem per clause of the verdict sentence, named. - The Rocq and Lean APP rows give the new audit counts and say which theorems the current receipt covers. - THY-1's Lean leg: says plainly that the recorded empty (axioms) rested on an audit that inspected none of THY-1's results, what the fixed gate now reports, and that no axiom was present to remove. - Changelog row for 2026-11-17. PROOF-NEEDS: the APP-1 row names verdict-missing. No grade, receipt or claim pin is changed. The receipt and the pins predate these theorems, and they move only after CI earns a receipt on this change (PROOF-POLICY §8.4 rules 2 and 4). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDf73vaDJwGZ3qMSeH3 --- docs/status/PROOF-NEEDS.adoc | 4 +++- docs/status/PROOF-STATUS.adoc | 45 +++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/docs/status/PROOF-NEEDS.adoc b/docs/status/PROOF-NEEDS.adoc index 104efd4..f03bf21 100644 --- a/docs/status/PROOF-NEEDS.adoc +++ b/docs/status/PROOF-NEEDS.adoc @@ -42,7 +42,9 @@ missing input is missing, in every period after it too, and never zero. A verdict is "no" on a known breach and otherwise missing when any value it depends on is missing; it is never "yes" then |Agda, re-checked in Rocq and Lean -|Proved in Agda, Rocq and Lean; the receipt derives `PWG-1` (WO 4.2) +|Proved in Agda, Rocq and Lean; the receipt derives `PWG-1` (WO 4.2). The +middle clause ("otherwise missing") is `verdict-missing`, proved 2026-11-17; +its receipt is still to be earned |`verification/proofs/agda/Applied/Missing.agda`; Rocq and Lean: `Cohort.v`, `Cohort.lean` |APP-2 diff --git a/docs/status/PROOF-STATUS.adoc b/docs/status/PROOF-STATUS.adoc index 74a64da..66b16ce 100644 --- a/docs/status/PROOF-STATUS.adoc +++ b/docs/status/PROOF-STATUS.adoc @@ -135,6 +135,22 @@ missing crate as missing from every build. * CI receipt (current): Lean 4.29.0 in the pinned Guix (`8edb9da`), same invocation, at commit `336768958d01`, run 42896264290. The file SHA-256 is unchanged, and no declared theorem depends on an axiom. +* Axiom evidence, corrected 2026-11-17. Every THY-1 result in this file is a + `def` (the leg is Type-valued, like the Agda), and until 2026-11-17 the + gate audited theorems only. So the empty `(axioms)` element of the Lean + receipts, and "no declared theorem depends on an axiom" above, were true + of an audit that inspected none of THY-1's results (proof audit + 2026-11-16, finding 31). The gate now audits every definition with a + source range as well, and fails on an empty audit. Run locally on Lean + 4.29.0 (`98dc76e3c0a9`), `scripts/check-proofs.sh lean4` reports "axioms: + none for 2 theorem(s) and 48 definition(s) with a source range" for this + file. Those are the six results (`reachMono`, `absentBelow`, `onMono`, + `onMonoAll`, `edgeMono`, `absentUnderAllFeatures`), their helpers, and + the definitions Lean generates for the inductives. The two theorems are + the projections `Edge.src` and `Edge.dst`. No axiom was found, so none had + to be removed. A CI receipt under the fixed gate is still to be earned: + until it is, the current receipt's axiom evidence for this leg stays the + vacuous one. |Why neither leg is transported |Lambdapi's Rocq and Lean exports translate before elaboration and drop @@ -227,19 +243,29 @@ each unit's graph. |`verification/proofs/agda/Applied/`: `Cohort` (the model), `Status` and `Missing` (APP-1, APP-4), `Cash` (APP-2, APP-3, for any ordered abelian group), `IntNumber` and `IntLaws` (the integer instance and its laws). +APP-1's verdict sentence has one theorem per clause, in each prover: +"no" on a known breach (`breach-decides`); otherwise missing when any value +it depends on is missing (`verdict-missing`, added 2026-11-17, with the +invariant `verdict-not-false`); never "yes" then (`verdict-yes`, and +`verdict-not-yes` stated directly). Before 2026-11-17 the middle clause was +stated by no declaration (proof audit 2026-11-16, finding 33). `--safe --without-K --cubical-compatible`; no postulate in any import cone. |Rocq leg |`PROVEN`, route `re-proved`. `verification/proofs/coq/Cohort.v`, Rocq -8.18.0. The gate's `Print Assumptions` finds all 82 theorems closed under -the global context. The standard library's `PeanoNat` and `Lia` prove the +8.18.0. The gate's `Print Assumptions` finds all 89 theorems closed under +the global context, and since 2026-11-17 every definition and fixpoint as +well: 134 declarations in all (82 theorems at the current receipt; the +seven added for APP-1's middle clause have no receipt yet). The standard library's `PeanoNat` and `Lia` prove the natural-number arithmetic; `Unset Lia Cache` keeps `lia` from writing a file. |Lean leg |`PROVEN`, route `re-proved`. `verification/proofs/lean4/Cohort.lean`, -Lean 4.29.0, core only. The gate's audit finds no axiom in any of the 95 -theorems. No `simp`, `omega` or `ac_rfl`: each brings `propext` in. +Lean 4.29.0, core only. The gate's audit finds no axiom in any of the 102 +theorems or in the 128 definitions with a source range (95 theorems at the +current receipt; the seven added for APP-1's middle clause have no receipt +yet). No `simp`, `omega` or `ac_rfl`: each brings `propext` in. |Statement correspondence (§2.2) |Compared by reading, item by item. Each target restates every Agda @@ -293,6 +319,17 @@ bash tests/proofs/gate_controls_test.sh agda |=== |Date |Change +|2026-11-17 +|APP-1's middle clause is proved in Agda, Rocq and Lean (`verdict-missing`, +`verdict-not-false`, `verdict-not-yes`; owner ruling: prove, not narrow). +The gate's axiom audit now covers definitions as well as theorems, and an +audit that inspects nothing fails. Before this, a Lean `def` built on +`sorry` and a Rocq `Admitted` Definition each passed, and THY-1's Lean +results were never inspected. All three gates and their controls pass +locally. No receipt is earned yet: the receipt and the claim pins still name +`a1388fc`/`034f215`, which predate these theorems, and they move only once +CI has run on this change. + |2026-11-14 |The claim pins of THY-1 and APP-1 to APP-4 name the receipt at main `a1388fc`. APP-1 to APP-4 are on the applied shelf. The claims registry From ce09d8dd82cf8e12cd73188abfbb6f27446a28ce Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 04:33:05 +0000 Subject: [PATCH 4/5] State THY-1's Lean results as propositions too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Owner ruling 2026-11-17: the gate fix plus theorem wrappers. THY-1's Lean results are Type-valued defs, like the Agda, and a Lean `theorem` must be a proposition. So each result is also stated about inhabitation and proved by the def it names: reach_mono, absent_below, on_mono, edge_mono, absent_under_all_features (Nonempty / ¬ Nonempty) not'_iff Nonempty (Not' A) ↔ ¬ Nonempty A No definition changes. not'_iff shows the propositional headline is the Type-valued one read as a proposition. The six theorems carry every definition in their own #print axioms cone, as the Rocq leg's Theorem absent_under_all_features does. The gate (previous commits) also audits the definitions directly. scripts/check-proofs.sh lean4 (Lean 4.29.0): "axioms: none for 8 theorem(s) and 48 definition(s) with a source range" for this file. That is 6 new theorems plus the Edge.src/Edge.dst projections. #print axioms: none for each of the six. All three gates and their controls pass. PROOF-STATUS records the correspondence (encoding only, Lean only) and the new audit line; the MANIFEST note says the results are defs that are also stated as Prop theorems. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDf73vaDJwGZ3qMSeH3 --- docs/status/PROOF-STATUS.adoc | 22 +++++++-- .../proofs/lean4/FeatureReachability.lean | 49 +++++++++++++++++++ verification/proofs/lean4/MANIFEST | 2 +- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/docs/status/PROOF-STATUS.adoc b/docs/status/PROOF-STATUS.adoc index 66b16ce..cdb4ca5 100644 --- a/docs/status/PROOF-STATUS.adoc +++ b/docs/status/PROOF-STATUS.adoc @@ -144,10 +144,15 @@ missing crate as missing from every build. source range as well, and fails on an empty audit. Run locally on Lean 4.29.0 (`98dc76e3c0a9`), `scripts/check-proofs.sh lean4` reports "axioms: none for 2 theorem(s) and 48 definition(s) with a source range" for this - file. Those are the six results (`reachMono`, `absentBelow`, `onMono`, - `onMonoAll`, `edgeMono`, `absentUnderAllFeatures`), their helpers, and - the definitions Lean generates for the inductives. The two theorems are - the projections `Edge.src` and `Edge.dst`. No axiom was found, so none had + file, before the propositional theorems below were added. Those are the + six results (`reachMono`, `absentBelow`, `onMono`, `onMonoAll`, + `edgeMono`, `absentUnderAllFeatures`), their helpers, and the + definitions Lean generates for the inductives. The two theorems are the + projections `Edge.src` and `Edge.dst`. With the propositional theorems + (owner ruling 2026-11-17: the gate fix and theorem wrappers), the report + is "axioms: none for 8 theorem(s) and 48 definition(s) with a source + range". `absent_under_all_features` and the other five carry each + definition in their own `#print axioms` cone as well. No axiom was found, so none had to be removed. A CI receipt under the fixed gate is still to be earned: until it is, the current receipt's axiom evidence for this leg stays the vacuous one. @@ -200,6 +205,15 @@ same hypotheses and conclusions. The differences are encoding only: no proof inspects. * `_⊑_` takes the feature implicitly in Agda and Lean, and explicitly in Rocq. +* Lean only, added 2026-11-17: a `theorem` must be a proposition, and + each Lean result is a Type-valued `def`. So `reach_mono`, `absent_below`, + `on_mono`, `edge_mono` and `absent_under_all_features` restate the + results about inhabitation (`Nonempty`, and `¬ Nonempty` for absence), + each proved by the definition it names. `not'_iff` shows that `Not' A` + is inhabited exactly when `¬ Nonempty A`, so for the headline the two + readings coincide. The definitions are unchanged; these are additions, + and they play the part that `Theorem absent_under_all_features` plays + in the Rocq leg. Residual assumptions: none in any leg. diff --git a/verification/proofs/lean4/FeatureReachability.lean b/verification/proofs/lean4/FeatureReachability.lean index 5b3b7c7..d09c141 100644 --- a/verification/proofs/lean4/FeatureReachability.lean +++ b/verification/proofs/lean4/FeatureReachability.lean @@ -16,6 +16,14 @@ Correspondence choices, all mirrored from the Agda source: fields of `Edge`, where proof relevance plays no part. - `All (On S)` is nested inside `On`, as in the Agda. +Every result is therefore a `def`, and a Lean `theorem` must be a +proposition. So each result is also stated about inhabitation (`Nonempty`) +as a `theorem` proved by the definition it names (sections 1 and 2, under +"As propositions"). Absence reads the same either way (`not'_iff`), and the +theorems put every definition here inside a theorem's axiom report, as the +Rocq leg's `Theorem absent_under_all_features` does. The gate also audits +the definitions directly. + Only Lean core is used: no `import`, no Mathlib. -/ @@ -27,6 +35,10 @@ inductive All {α : Type u} (P : α → Type v) : List α → Type (max u v) | nil : All P [] | cons {x : α} {xs : List α} : P x → All P xs → All P (x :: xs) +/-- `Not'` and `¬ Nonempty` say the same thing: absence is proof-irrelevant. -/ +theorem not'_iff {A : Type} : Nonempty (Not' A) ↔ ¬ Nonempty A := + ⟨fun ⟨n⟩ ⟨a⟩ => (n a).elim, fun h => ⟨fun a => (h ⟨a⟩).elim⟩⟩ + /-! ## 1. The abstract result -/ section Monotone @@ -51,6 +63,20 @@ def absentBelow (le : Ctx → Ctx → Type) (Edge : Ctx → Node → Node → Ty (absent : Not' (Reach Edge G root v)) : Not' (Reach Edge F root v) := fun r => absent (reachMono le Edge edgeMono h r) +/-! As propositions. -/ + +theorem reach_mono (le : Ctx → Ctx → Type) (Edge : Ctx → Node → Node → Type) + (edgeMono : ∀ {F G : Ctx} {u v : Node}, le F G → Edge F u v → Edge G u v) + {F G : Ctx} {root v : Node} (h : le F G) : + Nonempty (Reach Edge F root v) → Nonempty (Reach Edge G root v) := + fun ⟨r⟩ => ⟨reachMono le Edge edgeMono h r⟩ + +theorem absent_below (le : Ctx → Ctx → Type) (Edge : Ctx → Node → Node → Type) + (edgeMono : ∀ {F G : Ctx} {u v : Node}, le F G → Edge F u v → Edge G u v) + {F G : Ctx} {root v : Node} (h : le F G) + (absent : ¬ Nonempty (Reach Edge G root v)) : ¬ Nonempty (Reach Edge F root v) := + fun ⟨r⟩ => (absentBelow le Edge edgeMono h (fun r' => (absent ⟨r'⟩).elim) r).elim + end Monotone /-! ## 2. The Cargo-shaped instance -/ @@ -117,6 +143,29 @@ def absentUnderAllFeatures {root v : Node} (fun h e => edgeMono premises conclusion src' dst' guard targetOk t h e) (belowAll S) (absent t) +/-! As propositions. -/ + +theorem on_mono {S T : Request Feat} (h : Sub S T) {f : Feat} : + Nonempty (On premises conclusion S f) → Nonempty (On premises conclusion T f) := + fun ⟨o⟩ => ⟨onMono premises conclusion h o⟩ + +theorem edge_mono (t : Target) {S T : Request Feat} {u v : Node} (h : Sub S T) : + Nonempty (Edge premises conclusion src' dst' guard targetOk t S u v) → + Nonempty (Edge premises conclusion src' dst' guard targetOk t T u v) := + fun ⟨e⟩ => ⟨edgeMono premises conclusion src' dst' guard targetOk t h e⟩ + +/-- The watch page's rule, per target, as a proposition. -/ +theorem absent_under_all_features {root v : Node} + (absent : ∀ t : Target, + ¬ Nonempty (Reach (Edge premises conclusion src' dst' guard targetOk t) + allFeatures root v)) : + ∀ (t : Target) (S : Request Feat), + ¬ Nonempty (Reach (Edge premises conclusion src' dst' guard targetOk t) + S root v) := + fun t S ⟨r⟩ => + (absentUnderAllFeatures premises conclusion src' dst' guard targetOk + (fun t' r' => (absent t' ⟨r'⟩).elim) t S r).elim + end Cargo end FeatureReachability diff --git a/verification/proofs/lean4/MANIFEST b/verification/proofs/lean4/MANIFEST index cc5da5e..b88e5fe 100644 --- a/verification/proofs/lean4/MANIFEST +++ b/verification/proofs/lean4/MANIFEST @@ -1,5 +1,5 @@ # Lean4 proof manifest — read by scripts/check-proofs.sh lean4 # Format: ||gated|quarantine| # Ground-truthed 2026-07-17 with Lean leanprover/lean4:v4.15.0 (via elan). -verification/proofs/lean4|FeatureReachability.lean|gated| THY-1 Lean leg, re-proved; core only; #print axioms: none +verification/proofs/lean4|FeatureReachability.lean|gated| THY-1 Lean leg, re-proved; core only; results are defs, also stated as Prop theorems; #print axioms: none verification/proofs/lean4|Cohort.lean|gated| APP-1 to APP-4 Lean leg, re-proved, with the integer laws; core only; no axiom From 116f8fed19d10a1715be92dbdcc7d02a3c44c0a6 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 21:58:40 +0000 Subject: [PATCH 5/5] Audit Rocq with the kernel checker, and refuse a declared Lean axiom Review of this change (CodeRabbit, on #107) found that the Rocq axiom audit took its declaration names from the source text, so a declaration it did not spell out was never audited. Reproduced: with an unused `Local Definition planted : False. Admitted.` appended to Cohort.v, the gate printed RESULT: PASS. Graded theorems were not affected, because Print Assumptions follows dependencies, but the claim that every definition is audited was false. The Lean audit had the same kind of gap: a module with a clean theorem and an unused `axiom planted : False` passed. Rocq: the gate now also runs `coqchk -o`, Rocq's independent kernel checker, on the library that coqc has just compiled. It lists every assumption in the library and its import cone (the standard library included): axioms, an Admitted proof among them, type-in-type, unsafe (co)fixpoints and assumed positivity. coqchk exits 0 when it finds one, so the gate reads its summary: each list must be and Set predicative, and any other entry fails. A missing coqchk fails. Print Assumptions per declaration stays, as the record of what the receipt covers and the refusal of an empty file; its name reader now blanks comments and strings as Rocq's lexer does, and accepts the Local, Global, Program, Polymorphic, Monomorphic and #[...] prefixes. Lean: a constant the source declares as an axiom fails the module, used or not. Controls (tests/proofs/gate_controls_test.sh), each beside a clean theorem and each failing in the audit, not in compilation. Each of these passed the old gate: Rocq Local Definition, #[local] Definition, a Program obligation, an Instance, an unused Axiom and a guard bypass; Lean an unused axiom. Also added: an Admitted in a nested Module (the old gate caught it; kept as a guard), and controls that must pass: a definition-only module in Rocq and in Lean, and a Rocq declaration inside a comment, which the old gate failed. Local runs (Rocq 8.18.0, Lean 4.29.0 98dc76e3c0a9, Agda 2.7.0.1): check-proofs.sh coq, lean4 and agda pass on the repository's proofs (coqchk -o: no assumption in FeatureReachability or Cohort and their cones); gate_controls_test.sh coq 13/13, lean4 6/6, agda 2/2. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01J4QvDf73vaDJwGZ3qMSeH3 --- docs/status/PROOF-NEEDS.adoc | 8 ++- docs/status/PROOF-STATUS.adoc | 23 +++++-- scripts/check-proofs.sh | 77 +++++++++++++++++++++--- tests/proofs/gate_controls_test.sh | 97 ++++++++++++++++++++++-------- verification/proofs/coq/MANIFEST | 4 +- 5 files changed, 165 insertions(+), 44 deletions(-) diff --git a/docs/status/PROOF-NEEDS.adoc b/docs/status/PROOF-NEEDS.adoc index f03bf21..04049f8 100644 --- a/docs/status/PROOF-NEEDS.adoc +++ b/docs/status/PROOF-NEEDS.adoc @@ -100,9 +100,11 @@ re-anchoring plan. They were never Mathesis obligations. No proof file may contain an unproven escape: `postulate` (Agda), `Admitted` (Rocq), `sorry` (Lean), `believe_me` or `assert_total` -(Idris2). For Agda, Rocq and Lean, `scripts/check-proofs.sh` enforces this -in CI: it compiles each gated module, then audits its axioms, and -`tests/proofs/gate_controls_test.sh` shows that a planted escape fails. +(Idris2). Nor may a Rocq or Lean file declare an axiom of its own, used or +not. For Agda, Rocq and Lean, `scripts/check-proofs.sh` enforces this in +CI: it compiles each gated module, then audits its axioms (for Rocq, with +the kernel checker `coqchk -o` on the compiled library as well), and +`tests/proofs/gate_controls_test.sh` shows that each planted escape fails. == Proof file locations diff --git a/docs/status/PROOF-STATUS.adoc b/docs/status/PROOF-STATUS.adoc index cdb4ca5..33d0bf9 100644 --- a/docs/status/PROOF-STATUS.adoc +++ b/docs/status/PROOF-STATUS.adoc @@ -270,8 +270,11 @@ stated by no declaration (proof audit 2026-11-16, finding 33). 8.18.0. The gate's `Print Assumptions` finds all 89 theorems closed under the global context, and since 2026-11-17 every definition and fixpoint as well: 134 declarations in all (82 theorems at the current receipt; the -seven added for APP-1's middle clause have no receipt yet). The standard library's `PeanoNat` and `Lia` prove the -natural-number arithmetic; `Unset Lia Cache` keeps `lia` from writing a +seven added for APP-1's middle clause have no receipt yet). The kernel +checker `coqchk -o` finds no axiom, type-in-type, unsafe (co)fixpoint or +assumed positivity in the compiled library or its import cone, the +standard library included (gate, 2026-11-17). The standard library's +`PeanoNat` and `Lia` prove the natural-number arithmetic; `Unset Lia Cache` keeps `lia` from writing a file. |Lean leg @@ -279,7 +282,7 @@ file. Lean 4.29.0, core only. The gate's audit finds no axiom in any of the 102 theorems or in the 128 definitions with a source range (95 theorems at the current receipt; the seven added for APP-1's middle clause have no receipt -yet). No `simp`, `omega` or `ac_rfl`: each brings `propext` in. +yet), and the file declares no axiom of its own. No `simp`, `omega` or `ac_rfl`: each brings `propext` in. |Statement correspondence (§2.2) |Compared by reading, item by item. Each target restates every Agda @@ -339,8 +342,18 @@ bash tests/proofs/gate_controls_test.sh agda The gate's axiom audit now covers definitions as well as theorems, and an audit that inspects nothing fails. Before this, a Lean `def` built on `sorry` and a Rocq `Admitted` Definition each passed, and THY-1's Lean -results were never inspected. All three gates and their controls pass -locally. No receipt is earned yet: the receipt and the claim pins still name +results were never inspected. Review then found that the Rocq audit took +its declaration names from the source text, so an unused +`Local Definition planted : False. Admitted.` passed the gate (reproduced). +The Rocq audit now also runs the kernel checker `coqchk -o` on the compiled +library, which lists every assumption in the library and its import cone +however the source spells it, and the name reader skips comments. The Lean +audit now fails on any axiom the source declares, used or not; an unused +`axiom planted : False` passed it before (reproduced). Seven planted escapes +that passed the old gate (Rocq: Local, `#[local]`, Program, Instance, an +unused Axiom and a guard bypass; Lean: an unused axiom) now fail it, and a +declaration inside a comment no longer fails it. All three gates and their +controls pass locally. No receipt is earned yet: the receipt and the claim pins still name `a1388fc`/`034f215`, which predate these theorems, and they move only once CI has run on this change. diff --git a/scripts/check-proofs.sh b/scripts/check-proofs.sh index 8e57090..d9f1204 100755 --- a/scripts/check-proofs.sh +++ b/scripts/check-proofs.sh @@ -99,15 +99,32 @@ check_one() { # names an axiom. PROOF-POLICY §8.4: axioms travel with the grade. # agda : the first-party modules of the import cone that Agda itself reports # go through scan-postulates.sh (the reference gate of januskey). -# coq : `Print Assumptions` for every Theorem, Lemma, Corollary, Proposition, -# Fact, Remark, Example, Definition, Fixpoint and CoFixpoint of the -# file must print "Closed under the global context". +# coq : two checks, both required. +# (1) coqchk -o, Rocq's independent kernel checker, re-checks the +# compiled library and its whole import cone (the standard library +# included) and lists every assumption in it: axioms (an Admitted +# proof is one), type-in-type, unsafe (co)fixpoints and assumed +# positivity. Each list must be , and Set predicative. This +# reads the compiled library, not the source text, so no spelling +# escapes it: Local, #[local], Program, Instance, a nested Module, +# an unused Axiom and a guard bypass were each caught (measured +# 2026-11-17; the text matcher alone passed an unused +# `Local Definition planted : False. Admitted.`). +# (2) `Print Assumptions` for every Theorem, Lemma, Corollary, +# Proposition, Fact, Remark, Example, Definition, Fixpoint and +# CoFixpoint that the comment-free source declares (Local, Global, +# Program, Polymorphic, Monomorphic and #[...] prefixes allowed) must +# print "Closed under the global context". It names what the receipt +# covers, and it refuses a file that declares nothing. # lean4: every theorem and every definition that carries a source range # must depend on no axiom (Lean.collectAxioms, the function behind -# #print axioms). That covers each declaration of the source, and +# #print axioms), and the source may declare no axiom of its own, +# used or not. That covers each declaration of the source, and # the definitions Lean generates for an inductive with its range # (casesOn, recOn, below, brecOn, ...), which are counted too. The # lemmas Lean generates (injEq, inj, sizeOf_spec) carry no range. +# (Measured 2026-11-17: before the axiom rule, a module holding a +# clean theorem and an unused `axiom planted : False` passed.) # Definitions are audited as well as theorems because a development can # carry its results as definitions: THY-1's Lean leg is Type-valued, so every # result there is a `def`, and an audit of theorems alone inspected none of @@ -147,27 +164,62 @@ audit_one() { AUDIT_NOTE="postulates: none in the ${#own[@]} first-party module(s) of the import cone: $(sed -n 's/.*label="\([^"]*\)".*/\1/p' "$dir/cone.dot" | LC_ALL=C sort -u | tr '\n' ' ')" ;; coq) + if ! command -v coqchk >/dev/null 2>&1; then + rm -rf "$dir"; LAST_OUT="axiom audit: coqchk not on PATH (the kernel audit cannot run, so the module fails)"; return 1 + fi base="$(basename "$rel" .v)"; copy="GateAudit_${base}" + # Comments (nested, across lines) and string literals are blanked first, + # as Rocq's lexer reads them, so a declaration in a comment is not + # collected. Line breaks are kept, so the Module stack sees real lines. names="$(awk ' + { out = ""; n = length($0) + for (i = 1; i <= n; i++) { + c = substr($0, i, 1); two = substr($0, i, 2) + if (instr) { if (c == "\"") { if (substr($0, i + 1, 1) == "\"") i++; else instr = 0 }; continue } + if (c == "\"") { instr = 1; continue } + if (two == "(*") { depth++; i++; continue } + if (two == "*)" && depth > 0) { depth--; i++; continue } + if (depth == 0) out = out c } + print out }' "$ROOT/$root/$rel" | awk ' /^[ \t]*Module[ \t]+Type[ \t]/ { split($0, w, /[ \t.]+/); stack[++d] = "T:" w[4]; next } /^[ \t]*Module[ \t]+[A-Za-z_][A-Za-z0-9_'\'']*[ \t]*\.[ \t]*$/ || /^[ \t]*Module[ \t]+[A-Za-z_][A-Za-z0-9_'\'']*[ \t]*[:(<]/ && !/:=/ { s = $0; sub(/^[ \t]*Module[ \t]+/, "", s); sub(/[^A-Za-z0-9_'\''].*/, "", s); stack[++d] = "M:" s; next } /^[ \t]*Section[ \t]/ { stack[++d] = "S:"; next } /^[ \t]*End[ \t]/ { if (d > 0) d--; next } - /^[ \t]*(Theorem|Lemma|Corollary|Proposition|Fact|Remark|Example|Definition|Fixpoint|CoFixpoint)[ \t]/ { - s = $0; sub(/^[ \t]*[A-Za-z]+[ \t]+/, "", s); sub(/[^A-Za-z0-9_'\''].*/, "", s) + /^[ \t]*((Local|Global|Program|Polymorphic|Monomorphic|#\[[^]]*\])[ \t]+)*(Theorem|Lemma|Corollary|Proposition|Fact|Remark|Example|Definition|Fixpoint|CoFixpoint)[ \t]/ { + s = $0; sub(/^[ \t]*((Local|Global|Program|Polymorphic|Monomorphic|#\[[^]]*\])[ \t]+)*[A-Za-z]+[ \t]+/, "", s); sub(/[^A-Za-z0-9_'\''].*/, "", s) q = ""; for (i = 1; i <= d; i++) if (stack[i] ~ /^M:/) q = q substr(stack[i], 3) "." - print q s }' "$ROOT/$root/$rel")" + print q s }')" if [ -z "$names" ]; then rm -rf "$dir"; LAST_OUT="axiom audit: no theorem or definition declared, so nothing was audited"; return 1; fi { cat "$ROOT/$root/$rel"; echo; while IFS= read -r n; do echo "Print Assumptions $n."; done <<<"$names"; } \ >"$ROOT/$root/$copy.v" - set +e; out="$(cd "$ROOT/$root" && coqc "$copy.v" 2>&1)"; rc=$?; set -e + set +e; out="$(cd "$ROOT/$root" && coqc "$copy.v" 2>&1)"; rc=$? + # The kernel audit reads the library that coqc has just written. + chk=""; chk_rc=1 + [ "$rc" -eq 0 ] && { chk="$(cd "$ROOT/$root" && coqchk -silent -o -Q . "" "$copy" 2>&1)"; chk_rc=$?; } + set -e rm -f "$ROOT/$root/$copy".{v,vo,vok,vos,glob} "$ROOT/$root/.$copy".aux expect="$(grep -c . <<<"$names")" got="$(grep -c '^Closed under the global context' <<<"$out" || true)" - if [ "$rc" -eq 0 ] && [ "$got" -eq "$expect" ]; then rc=0 - AUDIT_NOTE="Print Assumptions: closed under the global context for $expect declaration(s): $(tr '\n' ' ' <<<"$names")" + # coqchk exits 0 when it finds an assumption; only its summary tells. + # A list that is not empty prints its header with no value and the + # names on the lines below, so every "* " line must be one of these. + summary="$(sed -n '/^CONTEXT SUMMARY/,$p' <<<"$chk" | sed 's/[[:space:]]*$//')" + kernel_ok=0 + if [ "$chk_rc" -eq 0 ] && [ -n "$summary" ] && + ! grep -E '^\* ' <<<"$summary" | grep -qvxE '\* (Theory: Set is predicative|[^:]+: )'; then + kernel_ok=1 + for h in "Axioms" "Constants/Inductives relying on type-in-type" \ + "Constants/Inductives relying on unsafe (co)fixpoints" "Inductives whose positivity is assumed"; do + grep -qxF "* $h: " <<<"$summary" || kernel_ok=0 + done + grep -qxF "* Theory: Set is predicative" <<<"$summary" || kernel_ok=0 + fi + if [ "$rc" -eq 0 ] && [ "$got" -eq "$expect" ] && [ "$kernel_ok" -eq 1 ]; then rc=0 + AUDIT_NOTE="coqchk -o: no axiom, type-in-type, unsafe (co)fixpoint or assumed positivity in the library or its import cone; Print Assumptions: closed under the global context for $expect declaration(s): $(tr '\n' ' ' <<<"$names")" + elif [ "$rc" -eq 0 ] && [ "$got" -eq "$expect" ]; then rc=1 + out="axiom audit: the kernel checker (coqchk -o) reports an assumption, or did not run (exit $chk_rc)"$'\n'"${summary:-$chk}" else rc=1; out="axiom audit: $got of $expect declaration(s) closed under the global context"$'\n'"$out"; fi ;; lean4) @@ -179,6 +231,11 @@ open Lean Elab Command in let mut n := 0 let mut m := 0 for (name, ci) in env.constants.map₂.toList do + -- An axiom the source declares fails the module even if nothing uses it. + if let .axiomInfo _ := ci then + if (← liftCoreM (findDeclarationRanges? name)).isSome then + logInfo m!"GATE-AXIOMS {name}: declared by the source" + continue -- Theorems and definitions the source declares: the declarations Lean -- generates (injEq, inj, sizeOf_spec, match_1, …) carry no range. let isThm := match ci with | .thmInfo _ => true | _ => false diff --git a/tests/proofs/gate_controls_test.sh b/tests/proofs/gate_controls_test.sh index 434da7d..a21bc14 100755 --- a/tests/proofs/gate_controls_test.sh +++ b/tests/proofs/gate_controls_test.sh @@ -7,31 +7,79 @@ # For Rocq and Lean the escape is also planted in a DEFINITION, and a module # with nothing to audit is planted too. Before the audit covered definitions # and refused an empty domain, all four of those passed (measured 2026-11-17). +# Rocq also gets the escapes that a reading of the source misses, each beside a +# clean theorem: a Local Definition, a #[local] attribute, a Program +# obligation, an Instance, an unused Axiom, a guard bypass and an Admitted in +# a nested Module (coqchk -o catches them; before it, an unused +# `Local Definition planted : False. Admitted.` passed). Lean gets an unused +# axiom beside a clean theorem, which also passed before 2026-11-17. A +# definition-only module must pass, so that the audit is not refusing a whole +# kind of declaration, and so must a declaration that sits in a comment. # Usage: bash tests/proofs/gate_controls_test.sh agda|coq|lean4 # Needs the prover on PATH; an absent prover fails, as in the gate itself. set -euo pipefail prover=${1:?usage: gate_controls_test.sh agda|coq|lean4} root=$(cd "$(dirname "$0")/../.." && pwd) t=$(mktemp -d); trap 'rm -rf "$t"' EXIT +# Each list holds "Name|body" entries; a body may span lines. +must_pass=() must_fail=() case "$prover" in - agda) ext=agda; clean='module Clean where + agda) ext=agda + must_pass+=('Clean|module Clean where -- postulate in a comment is not a postulate data N : Set where z : N - s : N → N' - planted='module Planted where -postulate X : Set' ;; - coq) ext=v; clean='(* Admitted. in a comment *) -Theorem clean : 1 + 1 = 2. Proof. reflexivity. Qed.' - planted='Theorem planted : 2 + 2 = 5. Admitted.' - planted_def='Definition planted : 2 + 2 = 5. + s : N → N') + must_fail+=('Planted|module Planted where +postulate X : Set') ;; + coq) ext=v + ok='Theorem clean : 1 + 1 = 2. Proof. reflexivity. Qed.' + must_pass+=("Clean|(* Admitted. in a comment *) +$ok" + 'CleanDef|Definition clean : nat := 0.' + "Commented|(* +Definition documentation_example := 0. +(* nested *) Lemma also_not_real : False. +*) +$ok") + must_fail+=('Planted|Theorem planted : 2 + 2 = 5. Admitted.' + 'PlantedDef|Definition planted : 2 + 2 = 5. Admitted.' - empty='(* nothing to audit *)' ;; - lean4) ext=lean; clean='-- sorry in a comment -theorem clean : 1 + 1 = 2 := rfl' - planted='theorem planted : 2 + 2 = 5 := by sorry' - planted_def='def planted : 2 + 2 = 5 := sorry' - empty='-- nothing to audit' ;; + 'Empty|(* nothing to audit *)' + "PlantedLocal|Definition clean_def : nat := 0. +$ok +Local Definition planted : False. +Admitted." + "PlantedAttr|$ok +#[local] Definition planted : nat. +Admitted." + "PlantedProgram|From Coq Require Import Program.Tactics. +$ok +Program Definition planted : False := _. +Next Obligation. Admitted." + "PlantedInstance|$ok +Class K := { k : False }. +Instance planted : K. +Admitted." + "PlantedAxiom|$ok +Axiom planted : False." + "PlantedGuard|$ok +#[bypass_check(guard)] Fixpoint loop (n : nat) : nat := loop n." + "PlantedModule|$ok +Module Inner. +Definition hidden : False. +Admitted. +End Inner.") ;; + lean4) ext=lean + ok='theorem clean : 1 + 1 = 2 := rfl' + must_pass+=("Clean|-- sorry in a comment +$ok" + 'CleanDef|def clean : Nat := 0') + must_fail+=('Planted|theorem planted : 2 + 2 = 5 := by sorry' + 'PlantedDef|def planted : 2 + 2 = 5 := sorry' + 'Empty|-- nothing to audit' + "PlantedAxiom|$ok +axiom planted : False") ;; *) echo "unknown prover: $prover" >&2; exit 2 ;; esac run() { # name body -> exit status of the gate on a tree holding that module @@ -43,14 +91,15 @@ run() { # name body -> exit status of the gate on a tree holding that module bash "$d/scripts/check-proofs.sh" "$prover" > "$d.log" 2>&1 } fail=0 -if run Clean "$clean"; then echo "PASS: $prover clean control passes" -else echo "FAIL: $prover clean control failed"; cat "$t/Clean.log"; fail=1; fi -if run Planted "$planted"; then echo "FAIL: $prover planted escape passed the gate"; cat "$t/Planted.log"; fail=1 -else echo "PASS: $prover planted escape fails the gate"; fi -if [ -n "${planted_def:-}" ]; then - if run PlantedDef "$planted_def"; then echo "FAIL: $prover escape planted in a definition passed the gate"; cat "$t/PlantedDef.log"; fail=1 - else echo "PASS: $prover escape planted in a definition fails the gate"; fi - if run Empty "$empty"; then echo "FAIL: $prover module with nothing to audit passed the gate"; cat "$t/Empty.log"; fail=1 - else echo "PASS: $prover module with nothing to audit fails the gate"; fi -fi +for e in "${must_pass[@]}"; do + name=${e%%|*} + if run "$name" "${e#*|}"; then echo "PASS: $prover control $name passes the gate" + else echo "FAIL: $prover control $name should pass the gate"; cat "$t/$name.log"; fail=1; fi +done +for e in "${must_fail[@]}"; do + name=${e%%|*} + if run "$name" "${e#*|}"; then echo "FAIL: $prover control $name passed the gate"; cat "$t/$name.log"; fail=1 + else echo "PASS: $prover control $name fails the gate"; fi +done +echo "$prover: ${#must_pass[@]} control(s) must pass, ${#must_fail[@]} must fail" exit "$fail" diff --git a/verification/proofs/coq/MANIFEST b/verification/proofs/coq/MANIFEST index 91e3048..fbb59ba 100644 --- a/verification/proofs/coq/MANIFEST +++ b/verification/proofs/coq/MANIFEST @@ -1,5 +1,5 @@ # Coq proof manifest — read by scripts/check-proofs.sh coq # Format: ||gated|quarantine| # Ground-truthed 2026-07-17 with coqc. -verification/proofs/coq|FeatureReachability.v|gated| THY-1 Rocq leg, re-proved; prelude only; Print Assumptions: closed -verification/proofs/coq|Cohort.v|gated| APP-1 to APP-4 Rocq leg, re-proved, with the integer laws; stdlib Lia only; Print Assumptions: closed +verification/proofs/coq|FeatureReachability.v|gated| THY-1 Rocq leg, re-proved; prelude only; Print Assumptions: closed; coqchk -o: no assumption +verification/proofs/coq|Cohort.v|gated| APP-1 to APP-4 Rocq leg, re-proved, with the integer laws; stdlib Lia only; Print Assumptions: closed; coqchk -o: no assumption