interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / bootstrap / formal-oracles / lean / MutantModels.lean

51 lines · 2683 bytes Raw Blame History
1import AienCap.Theorems
2/-!
3# Deliberate mutants of `Derive` (each must violate attenuation)
4
5These are WRONG on purpose. They exist so the oracle can show it kills privilege widening.
6Each mutant model compiles; the matching claim file must not.
7-/
8namespace AienCap
9
10/-- MUTANT 1 (scope_expansion): the containment check is removed. -/
11def DeriveWiden (g : Graph) (now pid cid : Nat) (auth : Auth) (c : Token) : Prop :=
12 ∃ p, g.find pid = some p ∧ Valid g now p ∧ 0 < p.depth ∧
13 c = { id := cid, parent := some pid, auth := auth, depth := p.depth - 1, expiry := p.expiry }
14
15/-- MUTANT 2 (expiration_extension): child expiry is chosen freely, not capped by the parent. -/
16def DeriveLongLived (g : Graph) (now pid cid : Nat) (auth : Auth) (exp : Nat) (c : Token) : Prop :=
17 ∃ p, g.find pid = some p ∧ Valid g now p ∧ 0 < p.depth ∧ Auth.Sub auth p.auth ∧
18 c = { id := cid, parent := some pid, auth := auth, depth := p.depth - 1, expiry := exp }
19
20/-- MUTANT 3 (delegation_depth_increase): child keeps the parent's depth (no decrement). -/
21def DeriveNoDecrement (g : Graph) (now pid cid : Nat) (auth : Auth) (c : Token) : Prop :=
22 ∃ p, g.find pid = some p ∧ Valid g now p ∧ 0 < p.depth ∧ Auth.Sub auth p.auth ∧
23 c = { id := cid, parent := some pid, auth := auth, depth := p.depth, expiry := p.expiry }
24
25def mroot : Token := { id := 0, parent := none, auth := [1], depth := 1, expiry := 10 }
26def mg : Graph := { tokens := [mroot], revoked := [] }
27
28private theorem mroot_valid : Valid mg 5 mroot := by
29 refine ⟨by simp [mg], ?_, by simp [mroot]⟩
30 intro h
31 cases h <;> simp_all [mroot]
32
33/-- witness: the widening mutant accepts a child holding atom 2 that the parent lacks -/
34theorem widen_witness :
35 ∃ c, DeriveWiden mg 5 0 1 [1, 2] c ∧ ¬ Auth.Sub c.auth mroot.auth :=
36 ⟨_, ⟨mroot, by simp [mg, Graph.find, mroot], mroot_valid, by simp [mroot], rfl⟩,
37 fun h => by have := h 2 (by simp); simp [mroot] at this⟩
38
39/-- witness: the long-lived mutant accepts a child expiring after its parent -/
40theorem long_lived_witness :
41 ∃ c, DeriveLongLived mg 5 0 1 [1] 99 c ∧ ¬ c.expiry ≤ mroot.expiry :=
42 ⟨_, ⟨mroot, by simp [mg, Graph.find, mroot], mroot_valid, by simp [mroot],
43 by intro a ha; simpa [mroot] using ha, rfl⟩, by simp [mroot]⟩
44
45/-- witness: the no-decrement mutant accepts a child whose depth is not below the parent's -/
46theorem no_decrement_witness :
47 ∃ c, DeriveNoDecrement mg 5 0 1 [1] c ∧ ¬ c.depth < mroot.depth :=
48 ⟨_, ⟨mroot, by simp [mg, Graph.find, mroot], mroot_valid, by simp [mroot],
49 by intro a ha; simpa [mroot] using ha, rfl⟩, by simp [mroot]⟩
50
51end AienCap