From 754efb106d33dab7a4531079e2e8640009fbaaeb Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Thu, 1 Oct 2026 16:40:58 -0500 Subject: [PATCH] FORMAL-2/3: pinned Lean 4.34.1 oracle bootstrap and AEGIS capability model, theorems, mutants Development oracle only (permanent_lineage = false). Core Lean, no Mathlib. Includes Rust vs C capability discrepancy note. Co-Authored-By: Claude Opus 5.5 --- bootstrap/formal-oracles/lean/.gitignore | 2 + bootstrap/formal-oracles/lean/AienCap.lean | 3 + .../formal-oracles/lean/AienCap/Corpus.lean | 48 +++++++++++ .../formal-oracles/lean/AienCap/Model.lean | 69 ++++++++++++++++ .../formal-oracles/lean/AienCap/Theorems.lean | 81 +++++++++++++++++++ .../formal-oracles/lean/DISCREPANCIES.md | 16 ++++ .../formal-oracles/lean/MutantDepthClaim.lean | 9 +++ .../lean/MutantExpiryClaim.lean | 9 +++ .../formal-oracles/lean/MutantModels.lean | 51 ++++++++++++ .../formal-oracles/lean/MutantScopeClaim.lean | 9 +++ .../formal-oracles/lean/lake-manifest.json | 6 ++ bootstrap/formal-oracles/lean/lakefile.toml | 25 ++++++ bootstrap/formal-oracles/lean/lean-toolchain | 1 + bootstrap/formal-oracles/lean/oracle.toml | 38 +++++++++ .../formal-oracles/lean/run-cap-formal.sh | 47 +++++++++++ 15 files changed, 414 insertions(+) create mode 100644 bootstrap/formal-oracles/lean/.gitignore create mode 100644 bootstrap/formal-oracles/lean/AienCap.lean create mode 100644 bootstrap/formal-oracles/lean/AienCap/Corpus.lean create mode 100644 bootstrap/formal-oracles/lean/AienCap/Model.lean create mode 100644 bootstrap/formal-oracles/lean/AienCap/Theorems.lean create mode 100644 bootstrap/formal-oracles/lean/DISCREPANCIES.md create mode 100644 bootstrap/formal-oracles/lean/MutantDepthClaim.lean create mode 100644 bootstrap/formal-oracles/lean/MutantExpiryClaim.lean create mode 100644 bootstrap/formal-oracles/lean/MutantModels.lean create mode 100644 bootstrap/formal-oracles/lean/MutantScopeClaim.lean create mode 100644 bootstrap/formal-oracles/lean/lake-manifest.json create mode 100644 bootstrap/formal-oracles/lean/lakefile.toml create mode 100644 bootstrap/formal-oracles/lean/lean-toolchain create mode 100644 bootstrap/formal-oracles/lean/oracle.toml create mode 100755 bootstrap/formal-oracles/lean/run-cap-formal.sh diff --git a/bootstrap/formal-oracles/lean/.gitignore b/bootstrap/formal-oracles/lean/.gitignore new file mode 100644 index 0000000..bacbb2b --- /dev/null +++ b/bootstrap/formal-oracles/lean/.gitignore @@ -0,0 +1,2 @@ +.lake/ +build/ diff --git a/bootstrap/formal-oracles/lean/AienCap.lean b/bootstrap/formal-oracles/lean/AienCap.lean new file mode 100644 index 0000000..02369ca --- /dev/null +++ b/bootstrap/formal-oracles/lean/AienCap.lean @@ -0,0 +1,3 @@ +import AienCap.Model +import AienCap.Theorems +import AienCap.Corpus diff --git a/bootstrap/formal-oracles/lean/AienCap/Corpus.lean b/bootstrap/formal-oracles/lean/AienCap/Corpus.lean new file mode 100644 index 0000000..707ea9e --- /dev/null +++ b/bootstrap/formal-oracles/lean/AienCap/Corpus.lean @@ -0,0 +1,48 @@ +import AienCap.Theorems +namespace AienCap + +/-! Small positive and negative corpus for the model. Each is a checked theorem. -/ + +def root : Token := { id := 0, parent := none, auth := [1, 2], depth := 2, expiry := 10 } +def g0 : Graph := { tokens := [root], revoked := [] } + +private theorem root_valid : Valid g0 10 root := by + refine ⟨by simp [g0], ?_, by simp [root]⟩ + intro h + cases h <;> simp_all [root] + +/-- positive: narrower authority, one less depth, same expiry is accepted -/ +theorem pos_narrower : + Derive g0 10 0 1 [1] { id := 1, parent := some 0, auth := [1], depth := 1, expiry := 10 } := + ⟨root, by simp [g0, Graph.find, root], root_valid, by simp [root], + by intro a ha; simp at ha; simp [root, ha], by simp [root]⟩ + +/-- positive: equal authority is accepted (containment is non-strict) -/ +theorem pos_equal : + Derive g0 10 0 1 [1, 2] { id := 1, parent := some 0, auth := [1, 2], depth := 1, expiry := 10 } := + ⟨root, by simp [g0, Graph.find, root], root_valid, by simp [root], + by intro a ha; simpa [root] using ha, by simp [root]⟩ + +/-- negative: asking for an atom the parent lacks is refused -/ +theorem neg_widen (c : Token) : ¬ Derive g0 10 0 1 [1, 3] c := by + rintro ⟨p, hf, _, _, hs, _⟩ + have hp : p = root := by simp [g0, Graph.find, root] at hf; exact hf.symm + subst hp + have := hs 3 (by simp) + simp [root] at this + +/-- negative: a depth-zero parent cannot delegate -/ +theorem neg_depth_zero (c : Token) : + ¬ Derive { tokens := [{ root with depth := 0 }], revoked := [] } 10 0 1 [1] c := + depth_zero_cannot_delegate (p := { root with depth := 0 }) (by simp [Graph.find, root]) rfl + +/-- negative: an expired token is invalid -/ +theorem neg_expired : ¬ Valid g0 11 root := expired_invalid (by simp [root]) + +/-- negative: after revocation the revoked token is invalid -/ +theorem neg_revoked : ¬ Valid (g0.revoke 0) 5 root := revoke_rejects_target 0 rfl + +/-- positive: a token is still valid exactly at its expiry (Rust uses `>`) -/ +theorem pos_expiry_boundary : Valid g0 10 root := root_valid + +end AienCap diff --git a/bootstrap/formal-oracles/lean/AienCap/Model.lean b/bootstrap/formal-oracles/lean/AienCap/Model.lean new file mode 100644 index 0000000..fc0e457 --- /dev/null +++ b/bootstrap/formal-oracles/lean/AienCap/Model.lean @@ -0,0 +1,69 @@ +/-! +# Abstract model of the Rust AEGIS capability graph (DEVELOPMENT_ORACLE) + +Source modelled: aien-dev/aienos `crates/aienos-aegis/src/capability.rs` at 2ee61b4 +(functions `derive_child_token`, `revoke`, `validate_token`). + +Abstraction: authority is a finite set of atoms; expiry and depth are naturals; +revocation is a list of ids. Cryptography (the HMAC signature) is an ASSUMPTION: +every token in a graph is taken to carry a valid signature, so signature +checking is not modelled. The graph is assumed acyclic (parents precede children). +`CapabilityScope::contains` is abstracted to set inclusion (`Auth.Sub`). + +Invariants: AIEN.INV.CAP.ATTENUATION.V1, AIEN.INV.CAP.REVOCATION_CLOSURE.V1. +Lean names here do not identify invariants; the manifest IDs do. +-/ +namespace AienCap + +abbrev Atom := Nat +/-- Authority as a finite set of atomic permissions. -/ +abbrev Auth := List Atom + +/-- Authority containment (the neutral "authority subset" relation). -/ +def Auth.Sub (c p : Auth) : Prop := ∀ a, a ∈ c → a ∈ p + +structure Token where + id : Nat + parent : Option Nat + auth : Auth + depth : Nat + expiry : Nat + +structure Graph where + tokens : List Token + revoked : List Nat + +/-- Lookup by id. Newest insertion shadows older ones, as the Rust HashMap insert overwrites. -/ +def Graph.find (g : Graph) (i : Nat) : Option Token := + g.tokens.find? (fun t => t.id == i) + +def Graph.put (g : Graph) (t : Token) : Graph := { g with tokens := t :: g.tokens } + +/-- Abstract revoke: marks the target id. The Rust code also marks every descendant in +`child_map`; that is redundant for validity because `validate_token` also walks ancestors. +This model is therefore a lower bound on what Rust rejects, which is the safe direction. -/ +def Graph.revoke (g : Graph) (a : Nat) : Graph := { g with revoked := a :: g.revoked } + +/-- Some ancestor, found by walking `parent` links through the graph, is revoked +(Rust: the "Cascading ancestor revocation check" loop in `validate_token`). -/ +inductive AncRev (g : Graph) : Token → Prop + | direct {t : Token} {p : Nat} : t.parent = some p → p ∈ g.revoked → AncRev g t + | up {t pt : Token} {p : Nat} : t.parent = some p → g.find p = some pt → AncRev g pt → AncRev g t + +/-- `validate_token` succeeds (signature assumed). Expiry boundary is inclusive: +expired only when `now > expiry`, so `now = expiry` is still valid (Rust `>`). -/ +def Valid (g : Graph) (now : Nat) (t : Token) : Prop := + t.id ∉ g.revoked ∧ ¬ AncRev g t ∧ now ≤ t.expiry + +/-- Success of `derive_child_token`: the parent exists and is valid, has positive depth, +contains the child scope, and the child gets parent expiry exactly and depth minus one. -/ +def Derive (g : Graph) (now pid cid : Nat) (auth : Auth) (c : Token) : Prop := + ∃ p, g.find pid = some p ∧ Valid g now p ∧ 0 < p.depth ∧ Auth.Sub auth p.auth ∧ + c = { id := cid, parent := some pid, auth := auth, depth := p.depth - 1, expiry := p.expiry } + +/-- `t` descends from `a` by parent links. -/ +inductive Desc (g : Graph) (a : Nat) : Token → Prop + | direct {t : Token} : t.parent = some a → Desc g a t + | up {t pt : Token} {p : Nat} : t.parent = some p → g.find p = some pt → Desc g a pt → Desc g a t + +end AienCap diff --git a/bootstrap/formal-oracles/lean/AienCap/Theorems.lean b/bootstrap/formal-oracles/lean/AienCap/Theorems.lean new file mode 100644 index 0000000..0a65ec7 --- /dev/null +++ b/bootstrap/formal-oracles/lean/AienCap/Theorems.lean @@ -0,0 +1,81 @@ +import AienCap.Model +namespace AienCap + +/-! ## Attenuation (AIEN.INV.CAP.ATTENUATION.V1) -/ + +/-- child authority is a subset of parent authority -/ +theorem derive_auth_subset {g : Graph} {now pid cid : Nat} {auth : Auth} {c : Token} + (h : Derive g now pid cid auth c) : + ∃ p, g.find pid = some p ∧ Auth.Sub c.auth p.auth := by + obtain ⟨p, hf, _, _, hs, rfl⟩ := h + exact ⟨p, hf, hs⟩ + +/-- child expiry is no later than parent expiry -/ +theorem derive_expiry_le {g : Graph} {now pid cid : Nat} {auth : Auth} {c : Token} + (h : Derive g now pid cid auth c) : + ∃ p, g.find pid = some p ∧ c.expiry ≤ p.expiry := by + obtain ⟨p, hf, _, _, _, rfl⟩ := h + exact ⟨p, hf, Nat.le_refl _⟩ + +/-- child remaining delegation depth is strictly less than the parent's -/ +theorem derive_depth_lt {g : Graph} {now pid cid : Nat} {auth : Auth} {c : Token} + (h : Derive g now pid cid auth c) : + ∃ p, g.find pid = some p ∧ c.depth < p.depth := by + obtain ⟨p, hf, _, hd, _, rfl⟩ := h + exact ⟨p, hf, by simp only []; omega⟩ + +/-- a parent with depth zero cannot delegate -/ +theorem depth_zero_cannot_delegate {g : Graph} {now pid cid : Nat} {auth : Auth} {c : Token} + {p : Token} (hf : g.find pid = some p) (h0 : p.depth = 0) : + ¬ Derive g now pid cid auth c := by + rintro ⟨q, hq, _, hd, _, _⟩ + rw [hf] at hq + cases hq + omega + +/-- delegation from an invalid (revoked, ancestor-revoked, or expired) parent is refused -/ +theorem derive_parent_valid {g : Graph} {now pid cid : Nat} {auth : Auth} {c : Token} + (h : Derive g now pid cid auth c) : + ∃ p, g.find pid = some p ∧ Valid g now p := by + obtain ⟨p, hf, hv, _⟩ := h + exact ⟨p, hf, hv⟩ + +/-! ## Revocation and expiry (AIEN.INV.CAP.REVOCATION_CLOSURE.V1) -/ + +/-- a revoked token is rejected -/ +theorem revoked_invalid {g : Graph} {now : Nat} {t : Token} (h : t.id ∈ g.revoked) : + ¬ Valid g now t := fun hv => hv.1 h + +/-- an expired token is rejected -/ +theorem expired_invalid {g : Graph} {now : Nat} {t : Token} (h : t.expiry < now) : + ¬ Valid g now t := fun hv => by have := hv.2.2; omega + +/-- revoking a token rejects that token -/ +theorem revoke_rejects_target {g : Graph} {now : Nat} {t : Token} (a : Nat) (h : t.id = a) : + ¬ Valid (g.revoke a) now t := + revoked_invalid (by simp [Graph.revoke, h]) + +private theorem desc_ancRev {g : Graph} {a : Nat} {t : Token} (h : Desc g a t) : + AncRev (g.revoke a) t := by + induction h with + | direct hp => exact AncRev.direct hp (by simp [Graph.revoke]) + | up hp hf _ ih => exact AncRev.up hp hf ih + +/-- revocation invalidates every descendant, at any depth -/ +theorem revoke_invalidates_descendants {g : Graph} {now : Nat} {a : Nat} {t : Token} + (h : Desc g a t) : ¬ Valid (g.revoke a) now t := + fun hv => hv.2.1 (desc_ancRev h) + +private theorem ancRev_mono {g : Graph} {a : Nat} {t : Token} (h : AncRev g t) : + AncRev (g.revoke a) t := by + induction h with + | direct hp hm => exact AncRev.direct hp (by simp [Graph.revoke, hm]) + | up hp hf _ ih => exact AncRev.up hp hf ih + +/-- revocation never turns an invalid token into a valid one -/ +theorem revoke_never_validates {g : Graph} {now a : Nat} {t : Token} + (hv : Valid (g.revoke a) now t) : Valid g now t := by + obtain ⟨h1, h2, h3⟩ := hv + exact ⟨fun h => h1 (by simp [Graph.revoke, h]), fun h => h2 (ancRev_mono h), h3⟩ + +end AienCap diff --git a/bootstrap/formal-oracles/lean/DISCREPANCIES.md b/bootstrap/formal-oracles/lean/DISCREPANCIES.md new file mode 100644 index 0000000..3f85b45 --- /dev/null +++ b/bootstrap/formal-oracles/lean/DISCREPANCIES.md @@ -0,0 +1,16 @@ +# Rust versus C capability semantics (FORMAL-3 prep) + +Observed on aien-dev/aienos main 2ee61b4. Read only. This note records what each implementation does. The Lean model in `AienCap/Model.lean` models the Rust code only. + +| Topic | Rust `crates/aienos-aegis/src/capability.rs` | C `native/capability/aienos_capability.c` | +|---|---|---| +| Authority | `CapabilityScope::contains` (typed scope, per kind rules), checked at line 280 | Rights bitmask. `r->rights & ~auth->rights` refuses with `AIENOS_CAP_ERR_AMPLIFY` (line 253). Privileged right is never delegable (line 254). Resource must be equal (line 252) | +| Child expiry | Not an argument. Child gets parent expiry exactly (line 288) | Child lease is `clock + lease_ticks`, chosen by caller. If parent expiry is nonzero, child must be nonzero and `<= parent` or `ERR_AMPLIFY` (lines 257 to 261). If parent expiry is 0 (no expiry) any child expiry is allowed | +| Expiry boundary | Expired only when `now > valid_until` (line 354). Equal is still valid | Expired when `lease_expiry != 0 && clock >= lease_expiry` (line 97). Equal is expired | +| Depth | Per-token counter. Child depth = parent depth - 1 (line 287). Parent depth 0 refuses `DelegationDepthExceeded` (line 276) | No counter. Absolute chain cap `AIENOS_CAP_MAX_DEPTH = 8` (header line 23), enforced by `ancestor_hops(...) >= AIENOS_CAP_MAX_DEPTH` returning `ERR_CHAIN` (line 255). Delegation also needs the DELEGATE right (line 250) | +| Validity check order | revoked, ancestor revoked (lines 345 to 352), expired, signature | State based slot validity with generation and cascade revoke (`cascade_revoke`), no signature | +| Revocation | `revoke` marks the token and all `child_map` descendants (line 319); `validate_token` also walks ancestors | Revokes live descendants by cascade over slots | +| Duplicate child id | `derive_child_token` does not check `child_id`. `self.tokens.insert(child_id, ...)` at line 312 silently overwrites an existing token and `child_map` gets a second entry at line 313. The caller supplies `child_id` | Slots are allocated by the authority (first free slot, generation counter), the caller does not choose the id | +| Holder | `new_holder` is not checked against the parent holder | Authority must equal parent reference (lines 244 to 246) | + +Consequence for the Lean model: the Rust "child expiry <= parent" and "child depth < parent depth" hold by construction (equality, and minus one). The C rules differ in kind. They are separate takeover items, not assumed equal. The overwrite behaviour affects identity uniqueness, not attenuation, and is not modelled (the model lets a newer token shadow an older one with the same id). diff --git a/bootstrap/formal-oracles/lean/MutantDepthClaim.lean b/bootstrap/formal-oracles/lean/MutantDepthClaim.lean new file mode 100644 index 0000000..3707328 --- /dev/null +++ b/bootstrap/formal-oracles/lean/MutantDepthClaim.lean @@ -0,0 +1,9 @@ +import MutantModels +namespace AienCap +/-- Real-model theorem restated for the no-decrement mutant. MUST FAIL to check. -/ +theorem mutant_depth_claim {g : Graph} {now pid cid : Nat} {auth : Auth} {c : Token} + (h : DeriveNoDecrement g now pid cid auth c) : + ∃ p, g.find pid = some p ∧ c.depth < p.depth := by + obtain ⟨p, hf, _, hd, _, rfl⟩ := h + exact ⟨p, hf, by omega⟩ +end AienCap diff --git a/bootstrap/formal-oracles/lean/MutantExpiryClaim.lean b/bootstrap/formal-oracles/lean/MutantExpiryClaim.lean new file mode 100644 index 0000000..74dea4f --- /dev/null +++ b/bootstrap/formal-oracles/lean/MutantExpiryClaim.lean @@ -0,0 +1,9 @@ +import MutantModels +namespace AienCap +/-- Real-model theorem restated for the expiry-extension mutant. MUST FAIL to check. -/ +theorem mutant_expiry_claim {g : Graph} {now pid cid exp : Nat} {auth : Auth} {c : Token} + (h : DeriveLongLived g now pid cid auth exp c) : + ∃ p, g.find pid = some p ∧ c.expiry ≤ p.expiry := by + obtain ⟨p, hf, _, _, _, rfl⟩ := h + exact ⟨p, hf, Nat.le_refl _⟩ +end AienCap diff --git a/bootstrap/formal-oracles/lean/MutantModels.lean b/bootstrap/formal-oracles/lean/MutantModels.lean new file mode 100644 index 0000000..fdd68e7 --- /dev/null +++ b/bootstrap/formal-oracles/lean/MutantModels.lean @@ -0,0 +1,51 @@ +import AienCap.Theorems +/-! +# Deliberate mutants of `Derive` (each must violate attenuation) + +These are WRONG on purpose. They exist so the oracle can show it kills privilege widening. +Each mutant model compiles; the matching claim file must not. +-/ +namespace AienCap + +/-- MUTANT 1 (scope_expansion): the containment check is removed. -/ +def DeriveWiden (g : Graph) (now pid cid : Nat) (auth : Auth) (c : Token) : Prop := + ∃ p, g.find pid = some p ∧ Valid g now p ∧ 0 < p.depth ∧ + c = { id := cid, parent := some pid, auth := auth, depth := p.depth - 1, expiry := p.expiry } + +/-- MUTANT 2 (expiration_extension): child expiry is chosen freely, not capped by the parent. -/ +def DeriveLongLived (g : Graph) (now pid cid : Nat) (auth : Auth) (exp : Nat) (c : Token) : Prop := + ∃ p, g.find pid = some p ∧ Valid g now p ∧ 0 < p.depth ∧ Auth.Sub auth p.auth ∧ + c = { id := cid, parent := some pid, auth := auth, depth := p.depth - 1, expiry := exp } + +/-- MUTANT 3 (delegation_depth_increase): child keeps the parent's depth (no decrement). -/ +def DeriveNoDecrement (g : Graph) (now pid cid : Nat) (auth : Auth) (c : Token) : Prop := + ∃ p, g.find pid = some p ∧ Valid g now p ∧ 0 < p.depth ∧ Auth.Sub auth p.auth ∧ + c = { id := cid, parent := some pid, auth := auth, depth := p.depth, expiry := p.expiry } + +def mroot : Token := { id := 0, parent := none, auth := [1], depth := 1, expiry := 10 } +def mg : Graph := { tokens := [mroot], revoked := [] } + +private theorem mroot_valid : Valid mg 5 mroot := by + refine ⟨by simp [mg], ?_, by simp [mroot]⟩ + intro h + cases h <;> simp_all [mroot] + +/-- witness: the widening mutant accepts a child holding atom 2 that the parent lacks -/ +theorem widen_witness : + ∃ c, DeriveWiden mg 5 0 1 [1, 2] c ∧ ¬ Auth.Sub c.auth mroot.auth := + ⟨_, ⟨mroot, by simp [mg, Graph.find, mroot], mroot_valid, by simp [mroot], rfl⟩, + fun h => by have := h 2 (by simp); simp [mroot] at this⟩ + +/-- witness: the long-lived mutant accepts a child expiring after its parent -/ +theorem long_lived_witness : + ∃ c, DeriveLongLived mg 5 0 1 [1] 99 c ∧ ¬ c.expiry ≤ mroot.expiry := + ⟨_, ⟨mroot, by simp [mg, Graph.find, mroot], mroot_valid, by simp [mroot], + by intro a ha; simpa [mroot] using ha, rfl⟩, by simp [mroot]⟩ + +/-- witness: the no-decrement mutant accepts a child whose depth is not below the parent's -/ +theorem no_decrement_witness : + ∃ c, DeriveNoDecrement mg 5 0 1 [1] c ∧ ¬ c.depth < mroot.depth := + ⟨_, ⟨mroot, by simp [mg, Graph.find, mroot], mroot_valid, by simp [mroot], + by intro a ha; simpa [mroot] using ha, rfl⟩, by simp [mroot]⟩ + +end AienCap diff --git a/bootstrap/formal-oracles/lean/MutantScopeClaim.lean b/bootstrap/formal-oracles/lean/MutantScopeClaim.lean new file mode 100644 index 0000000..7e3a8e9 --- /dev/null +++ b/bootstrap/formal-oracles/lean/MutantScopeClaim.lean @@ -0,0 +1,9 @@ +import MutantModels +namespace AienCap +/-- Real-model theorem restated for the widening mutant. MUST FAIL to check. -/ +theorem mutant_scope_claim {g : Graph} {now pid cid : Nat} {auth : Auth} {c : Token} + (h : DeriveWiden g now pid cid auth c) : + ∃ p, g.find pid = some p ∧ Auth.Sub c.auth p.auth := by + obtain ⟨p, hf, _, _, rfl⟩ := h + exact ⟨p, hf, by intro a ha; assumption⟩ +end AienCap diff --git a/bootstrap/formal-oracles/lean/lake-manifest.json b/bootstrap/formal-oracles/lean/lake-manifest.json new file mode 100644 index 0000000..c450569 --- /dev/null +++ b/bootstrap/formal-oracles/lean/lake-manifest.json @@ -0,0 +1,6 @@ +{"version": "1.2.0", + "packagesDir": ".lake/packages", + "packages": [], + "name": "aien_formal_oracle", + "lakeDir": ".lake", + "fixedToolchain": false} diff --git a/bootstrap/formal-oracles/lean/lakefile.toml b/bootstrap/formal-oracles/lean/lakefile.toml new file mode 100644 index 0000000..d075c2f --- /dev/null +++ b/bootstrap/formal-oracles/lean/lakefile.toml @@ -0,0 +1,25 @@ +name = "aien_formal_oracle" +defaultTargets = ["AienCap"] + +# Core Lean only. No Mathlib, no Batteries, no other dependency: builds offline. + +[[lean_lib]] +name = "AienCap" + +[[lean_lib]] +name = "MutantModels" +globs = ["MutantModels"] + +# Each claim file states a real-model theorem against a mutant model. +# It must FAIL to build. The runner checks that. +[[lean_lib]] +name = "MutantScopeClaim" +globs = ["MutantScopeClaim"] + +[[lean_lib]] +name = "MutantExpiryClaim" +globs = ["MutantExpiryClaim"] + +[[lean_lib]] +name = "MutantDepthClaim" +globs = ["MutantDepthClaim"] diff --git a/bootstrap/formal-oracles/lean/lean-toolchain b/bootstrap/formal-oracles/lean/lean-toolchain new file mode 100644 index 0000000..ba8ebf2 --- /dev/null +++ b/bootstrap/formal-oracles/lean/lean-toolchain @@ -0,0 +1 @@ +leanprover/lean4:v4.34.1 diff --git a/bootstrap/formal-oracles/lean/oracle.toml b/bootstrap/formal-oracles/lean/oracle.toml new file mode 100644 index 0000000..712e344 --- /dev/null +++ b/bootstrap/formal-oracles/lean/oracle.toml @@ -0,0 +1,38 @@ +# Lean bootstrap oracle declaration (ARCH-0027, FORMAL-2). Disposable. Not part of permanent AIEN lineage. +schema_version = 0 +name = "aien-formal-oracle-lean" +classification = "DEVELOPMENT_ORACLE" +permanent_lineage = false +deprecation_target = "OMEGA_FORMAL_CLOSURE" +governing_adr = "docs/adr/0027-formal-oracle-lean-bootstrap.md" +severance_gate = "LEAN_SEVERANCE" + +[toolchain] +lean_toolchain_file = "lean-toolchain" +lean_version = "4.34.1" +lean_release_tag = "v4.34.1" +lean_release_published = "2026-09-24" # GitHub release leanprover/lean4 v4.34.1 (latest stable, non-prerelease) +lean_commit = "5045d0056413266e57c625dcd7c365b10e377c52" +lake_version = "5.0.0-src+5045d00" +platform_verified = "aarch64-unknown-linux-gnu" +elan_version = "4.2.4" +elan_release_published = "2026-08-25" # GitHub release leanprover/elan v4.2.4 +elan_archive = "elan-aarch64-unknown-linux-gnu.tar.gz" +elan_archive_sha256 = "05febd124d84ebf994b2e7479922a5650b1e950c17ae3bd1ddd776b65bb72bf9" +verified_on = "2026-10-01" +install = "elan installed in the user home (~/.elan), no sudo, no system packages" +mathlib = false +external_dependencies = [] + +[[covers]] +invariant = "AIEN.INV.CAP.ATTENUATION.V1" +manifest = "formal/invariants/capability-attenuation-v1.toml" + +[[covers]] +invariant = "AIEN.INV.CAP.REVOCATION_CLOSURE.V1" +manifest = "formal/invariants/capability-revocation-v1.toml" + +[run] +script = "run-cap-formal.sh" +result_line = "CAP_FORMAL_BOOTSTRAP: PASS|FAIL|NOT_RUN" +note = "A PASS is one evidence input bound to a source and model revision. It is not authority (ARCH-0027 point 6)." diff --git a/bootstrap/formal-oracles/lean/run-cap-formal.sh b/bootstrap/formal-oracles/lean/run-cap-formal.sh new file mode 100755 index 0000000..26ba517 --- /dev/null +++ b/bootstrap/formal-oracles/lean/run-cap-formal.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# FORMAL-2/3: capability formal bootstrap runner (DEVELOPMENT_ORACLE, not permanent lineage). +# Builds the real model (must PASS) and each deliberate mutant claim (must FAIL). +# Last stdout line: CAP_FORMAL_BOOTSTRAP: PASS | FAIL | NOT_RUN +# No network needed after the toolchain is installed (core Lean only, no dependencies). +set -u +here=$(cd "$(dirname "$0")" && pwd) +cd "$here" || exit 2 +PATH="$HOME/.elan/bin:$PATH"; export PATH + +quiet="${AIEN_SPARK_QUIET_FLAG:-$HOME/workspace/.spark-quiet}" +if [ -e "$quiet" ]; then + echo "quiet flag present ($quiet): not building" + echo "CAP_FORMAL_BOOTSTRAP: NOT_RUN" + exit 3 +fi +command -v lake >/dev/null 2>&1 || { echo "lake not found (install elan)"; echo "CAP_FORMAL_BOOTSTRAP: NOT_RUN"; exit 3; } + +log=$(mktemp); trap 'rm -f "$log"' EXIT +echo "toolchain: $(cat lean-toolchain) / $(lean --version)" +fail=0 + +lake build AienCap >"$log" 2>&1; rc=$? +if [ $rc -eq 0 ] && ! grep -qi "sorry" "$log"; then + echo "real_model: PASS" +else + echo "real_model: FAIL (rc=$rc)"; tail -20 "$log"; fail=1 +fi + +lake build MutantModels >"$log" 2>&1; rc=$? +if [ $rc -eq 0 ] && ! grep -qi "sorry" "$log"; then + echo "mutant_models_compile: PASS" +else + echo "mutant_models_compile: FAIL (rc=$rc)"; tail -20 "$log"; fail=1 +fi + +for m in MutantScopeClaim MutantExpiryClaim MutantDepthClaim; do + lake build "$m" >"$log" 2>&1; rc=$? + if [ $rc -ne 0 ] && grep -q "^error: $m.lean:" "$log" && ! grep -q "^error: MutantModels.lean" "$log"; then + echo "$m: FAIL_AS_EXPECTED (mutant killed)" + else + echo "$m: UNEXPECTED_BUILD_SUCCESS_OR_NO_ERROR (rc=$rc), mutant survived"; fail=1 + fi +done + +if [ $fail -eq 0 ]; then echo "CAP_FORMAL_BOOTSTRAP: PASS"; else echo "CAP_FORMAL_BOOTSTRAP: FAIL"; fi +exit $fail