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 / AienCap / Model.lean

69 lines · 3232 bytes Raw Blame History
1/-!
2# Abstract model of the Rust AEGIS capability graph (DEVELOPMENT_ORACLE)
3
4Source modelled: aien-dev/aienux `crates/aienos-aegis/src/capability.rs` at 2ee61b4
5(functions `derive_child_token`, `revoke`, `validate_token`).
6
7Abstraction: authority is a finite set of atoms; expiry and depth are naturals;
8revocation is a list of ids. Cryptography (the HMAC signature) is an ASSUMPTION:
9every token in a graph is taken to carry a valid signature, so signature
10checking is not modelled. The graph is assumed acyclic (parents precede children).
11`CapabilityScope::contains` is abstracted to set inclusion (`Auth.Sub`).
12
13Invariants: AIEN.INV.CAP.ATTENUATION.V1, AIEN.INV.CAP.REVOCATION_CLOSURE.V1.
14Lean names here do not identify invariants; the manifest IDs do.
15-/
16namespace AienCap
17
18abbrev Atom := Nat
19/-- Authority as a finite set of atomic permissions. -/
20abbrev Auth := List Atom
21
22/-- Authority containment (the neutral "authority subset" relation). -/
23def Auth.Sub (c p : Auth) : Prop := ∀ a, a ∈ c → a ∈ p
24
25structure Token where
26 id : Nat
27 parent : Option Nat
28 auth : Auth
29 depth : Nat
30 expiry : Nat
31
32structure Graph where
33 tokens : List Token
34 revoked : List Nat
35
36/-- Lookup by id. Newest insertion shadows older ones, as the Rust HashMap insert overwrites. -/
37def Graph.find (g : Graph) (i : Nat) : Option Token :=
38 g.tokens.find? (fun t => t.id == i)
39
40def Graph.put (g : Graph) (t : Token) : Graph := { g with tokens := t :: g.tokens }
41
42/-- Abstract revoke: marks the target id. The Rust code also marks every descendant in
43`child_map`; that is redundant for validity because `validate_token` also walks ancestors.
44This model is therefore a lower bound on what Rust rejects, which is the safe direction. -/
45def Graph.revoke (g : Graph) (a : Nat) : Graph := { g with revoked := a :: g.revoked }
46
47/-- Some ancestor, found by walking `parent` links through the graph, is revoked
48(Rust: the "Cascading ancestor revocation check" loop in `validate_token`). -/
49inductive AncRev (g : Graph) : Token → Prop
50 | direct {t : Token} {p : Nat} : t.parent = some p → p ∈ g.revoked → AncRev g t
51 | up {t pt : Token} {p : Nat} : t.parent = some p → g.find p = some pt → AncRev g pt → AncRev g t
52
53/-- `validate_token` succeeds (signature assumed). Expiry boundary is inclusive:
54expired only when `now > expiry`, so `now = expiry` is still valid (Rust `>`). -/
55def Valid (g : Graph) (now : Nat) (t : Token) : Prop :=
56 t.id ∉ g.revoked ∧ ¬ AncRev g t ∧ now ≤ t.expiry
57
58/-- Success of `derive_child_token`: the parent exists and is valid, has positive depth,
59contains the child scope, and the child gets parent expiry exactly and depth minus one. -/
60def Derive (g : Graph) (now pid cid : Nat) (auth : Auth) (c : Token) : Prop :=
61 ∃ p, g.find pid = some p ∧ Valid g now p ∧ 0 < p.depth ∧ Auth.Sub auth p.auth ∧
62 c = { id := cid, parent := some pid, auth := auth, depth := p.depth - 1, expiry := p.expiry }
63
64/-- `t` descends from `a` by parent links. -/
65inductive Desc (g : Graph) (a : Nat) : Token → Prop
66 | direct {t : Token} : t.parent = some a → Desc g a t
67 | up {t pt : Token} {p : Nat} : t.parent = some p → g.find p = some pt → Desc g a pt → Desc g a t
68
69end AienCap