aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
aien-architecture-mv / bootstrap / formal-oracles / lean / AienCap / Corpus.lean
| 1 | import AienCap.Theorems |
| 2 | namespace AienCap |
| 3 | |
| 4 | /-! Small positive and negative corpus for the model. Each is a checked theorem. -/ |
| 5 | |
| 6 | def root : Token := { id := 0, parent := none, auth := [1, 2], depth := 2, expiry := 10 } |
| 7 | def g0 : Graph := { tokens := [root], revoked := [] } |
| 8 | |
| 9 | private theorem root_valid : Valid g0 10 root := by |
| 10 | refine ⟨by simp [g0], ?_, by simp [root]⟩ |
| 11 | intro h |
| 12 | cases h <;> simp_all [root] |
| 13 | |
| 14 | /-- positive: narrower authority, one less depth, same expiry is accepted -/ |
| 15 | theorem pos_narrower : |
| 16 | Derive g0 10 0 1 [1] { id := 1, parent := some 0, auth := [1], depth := 1, expiry := 10 } := |
| 17 | ⟨root, by simp [g0, Graph.find, root], root_valid, by simp [root], |
| 18 | by intro a ha; simp at ha; simp [root, ha], by simp [root]⟩ |
| 19 | |
| 20 | /-- positive: equal authority is accepted (containment is non-strict) -/ |
| 21 | theorem pos_equal : |
| 22 | Derive g0 10 0 1 [1, 2] { id := 1, parent := some 0, auth := [1, 2], depth := 1, expiry := 10 } := |
| 23 | ⟨root, by simp [g0, Graph.find, root], root_valid, by simp [root], |
| 24 | by intro a ha; simpa [root] using ha, by simp [root]⟩ |
| 25 | |
| 26 | /-- negative: asking for an atom the parent lacks is refused -/ |
| 27 | theorem neg_widen (c : Token) : ¬ Derive g0 10 0 1 [1, 3] c := by |
| 28 | rintro ⟨p, hf, _, _, hs, _⟩ |
| 29 | have hp : p = root := by simp [g0, Graph.find, root] at hf; exact hf.symm |
| 30 | subst hp |
| 31 | have := hs 3 (by simp) |
| 32 | simp [root] at this |
| 33 | |
| 34 | /-- negative: a depth-zero parent cannot delegate -/ |
| 35 | theorem neg_depth_zero (c : Token) : |
| 36 | ¬ Derive { tokens := [{ root with depth := 0 }], revoked := [] } 10 0 1 [1] c := |
| 37 | depth_zero_cannot_delegate (p := { root with depth := 0 }) (by simp [Graph.find, root]) rfl |
| 38 | |
| 39 | /-- negative: an expired token is invalid -/ |
| 40 | theorem neg_expired : ¬ Valid g0 11 root := expired_invalid (by simp [root]) |
| 41 | |
| 42 | /-- negative: after revocation the revoked token is invalid -/ |
| 43 | theorem neg_revoked : ¬ Valid (g0.revoke 0) 5 root := revoke_rejects_target 0 rfl |
| 44 | |
| 45 | /-- positive: a token is still valid exactly at its expiry (Rust uses `>`) -/ |
| 46 | theorem pos_expiry_boundary : Valid g0 10 root := root_valid |
| 47 | |
| 48 | end AienCap |