Core.lean
Lean 4 source (Lean 4 core, no Mathlib). 24 theorems. Download Core.lean.
Theorems in this file
noninterferencecaps_holdrelease_reading_freebounded_damagePG.monoowed_monoduty_neutrallocalitysame_rules_same_answercapAllows_downpermitsAt_downdownward_closedagent_boundreleaseX_subnoninterference_Xcaps_hold_XreleaseX_reading_freeForm.le_reflForm.le_transForm.le_antisymmForm.meet_le_leftForm.meet_le_rightForm.le_meetsummary_is_not_rows
/- Machine-checked core of the access language (step 7 of the research plan). Revised 22 November 2026 for the decisions in the design decisions: * Decision 1, strict mode. `permit` carries a facts-only guard (`FG`), like `forbid`, `cap` and `boundary`. Readings may appear only in `ask` and `duty`, which never release. So the release decision does not depend on readings at all (`release_reading_free`). * Decision 2, forms are a partial order, not a line. Everything general is proved for any `FormOrder` (reflexive, transitive); the seven forms of the language are one instance, and that instance is shown to be a lattice (`Form.meet` is a greatest lower bound). * Decision 4, duties. A sixth effect, `duty`, which never changes a release (`duty_neutral`) and which readings can only add to (`owed_mono`). The model follows the Semantics page with these simplifications, stated in the proofs overview: * a guard is a Boolean formula over ground fact atoms and reading atoms (the Datalog evaluation of §1.6 is assumed to have produced those atoms); * defaults by class are written as permit and forbid rules over labels, each guarded by "no permit touches the request and no ask applies" (written as plain permits they disagree with the interpreter: the differential test of interpreter against Lean, 25 November 2026); * the verdict `ask` (including "please confirm") is not modelled: it never releases. Restriction N is not a check here: it is the type of the effects. Any rule set that type-checks satisfies it. Lean 4 core only, no Mathlib. -/ namespace AccessCore /-! ## Forms: any partial order -/ /-- A preorder on forms is all the general theorems need. -/ structure FormOrder (Fm : Type) where le : Fm → Fm → Bool refl : ∀ a, le a a = true trans : ∀ a b c, le a b = true → le b c = true → le a c = true /-! ## Guards -/ /-- Guards over facts only. -/ inductive FG (F : Type) where | tt : FG F | ff : FG F | fact : F → FG F | nfact : F → FG F | and : FG F → FG F → FG F | or : FG F → FG F → FG F /-- Guards that may also use readings, positively only. -/ inductive PG (F Rd : Type) where | base : FG F → PG F Rd | read : Rd → PG F Rd | and : PG F Rd → PG F Rd → PG F Rd | or : PG F Rd → PG F Rd → PG F Rd variable {F Rd A Fm : Type} def FG.eval (φ : F → Bool) : FG F → Bool | .tt => true | .ff => false | .fact a => φ a | .nfact a => !φ a | .and g h => g.eval φ && h.eval φ | .or g h => g.eval φ || h.eval φ def PG.eval (φ : F → Bool) (ρ : Rd → Bool) : PG F Rd → Bool | .base g => g.eval φ | .read b => ρ b | .and g h => g.eval φ ρ && h.eval φ ρ | .or g h => g.eval φ ρ || h.eval φ ρ /-! ## Effects and rules -/ /-- The six effects. Only `ask` and `duty` may read; neither releases anything. -/ inductive Effect (F Rd Fm : Type) where | permit : Fm → FG F → Effect F Rd Fm -- strict mode: facts only | ask : PG F Rd → Effect F Rd Fm | forbid : FG F → Effect F Rd Fm | cap : Fm → FG F → Effect F Rd Fm | boundary : FG F → FG F → Effect F Rd Fm -- applies when, lifted when | duty : Nat → PG F Rd → Effect F Rd Fm -- an obligation on what is released /-- A rule: its anchors (the hyperedge) and its effect. -/ structure Rule (F Rd A Fm : Type) where anchors : List A eff : Effect F Rd Fm /-- A request is known to the core only through which anchors it matches (SEMANTICS §2.1). -/ def touches (m : A → Bool) (r : Rule F Rd A Fm) : Bool := r.anchors.all m def protects (φ : F → Bool) : Effect F Rd Fm → Bool | .forbid g => g.eval φ | .boundary g l => g.eval φ && !l.eval φ | _ => false def capAllows (O : FormOrder Fm) (φ : F → Bool) (f : Fm) : Effect F Rd Fm → Bool | .cap c g => !g.eval φ || O.le f c | _ => true def permitsAt (O : FormOrder Fm) (φ : F → Bool) (f : Fm) : Effect F Rd Fm → Bool | .permit p g => g.eval φ && O.le f p | _ => false /-- Some touching forbid or unlifted boundary applies. -/ def blocked (m : A → Bool) (φ : F → Bool) (R : List (Rule F Rd A Fm)) : Bool := R.any fun r => touches m r && protects φ r.eff def capsOK (O : FormOrder Fm) (m : A → Bool) (φ : F → Bool) (R : List (Rule F Rd A Fm)) (f : Fm) : Bool := R.all fun r => !touches m r || capAllows O φ f r.eff def permitted (O : FormOrder Fm) (m : A → Bool) (φ : F → Bool) (R : List (Rule F Rd A Fm)) (f : Fm) : Bool := R.any fun r => touches m r && permitsAt O φ f r.eff /-- May data be released at form `f`, when form `q` was asked for? (SEMANTICS §2.3) The readings `ρ` are an argument so that the theorems can quantify over them; in strict mode no part of the release decision reads them. -/ def release (O : FormOrder Fm) (m : A → Bool) (φ : F → Bool) (_ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) (q f : Fm) : Bool := !blocked m φ R && capsOK O m φ R f && permitted O m φ R f && O.le f q /-- Duty number `n` is owed on this request. -/ def owed (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) (n : Nat) : Bool := R.any fun r => touches m r && match r.eff with | .duty k g => decide (k = n) && g.eval φ ρ | _ => false variable (O : FormOrder Fm) /-! ## T4. Non-interference -/ /-- If protection applies, nothing is released, whatever the model read. -/ theorem noninterference (m : A → Bool) (φ : F → Bool) (R : List (Rule F Rd A Fm)) (q : Fm) (h : blocked m φ R = true) : ∀ (ρ : Rd → Bool) (f : Fm), release O m φ ρ R q f = false := by intro ρ f simp [release, h] /-- Whatever the model read, a released form satisfies every cap. -/ theorem caps_hold (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) (q f : Fm) (h : release O m φ ρ R q f = true) : capsOK O m φ R f = true := by simp [release] at h exact h.1.1.2 /-! ## T5 (strict). Readings never release anything -/ /-- Decision 1. In strict mode the release decision is the same for every assignment of readings: no model, however wrong or manipulated, changes what is released. -/ theorem release_reading_free (m : A → Bool) (φ : F → Bool) (ρ ρ' : Rd → Bool) (R : List (Rule F Rd A Fm)) (q f : Fm) : release O m φ ρ R q f = release O m φ ρ' R q f := rfl /-- Bounded damage, now a corollary: the most any model can obtain is what the facts alone give, i.e. what a model that reads nothing obtains. -/ theorem bounded_damage (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) (q f : Fm) (h : release O m φ ρ R q f = true) : release O m φ (fun _ => false) R q f = true := by rw [release_reading_free O m φ (fun _ => false) ρ R q f]; exact h /-! ## Readings only add (to asks and duties) -/ def le (ρ ρ' : Rd → Bool) : Prop := ∀ b, ρ b = true → ρ' b = true theorem PG.mono (φ : F → Bool) {ρ ρ' : Rd → Bool} (hle : le ρ ρ') : ∀ g : PG F Rd, g.eval φ ρ = true → g.eval φ ρ' = true | .base _, h => by simpa [PG.eval] using h | .read b, h => hle b h | .and g k, h => by simp [PG.eval] at h ⊢ exact ⟨PG.mono φ hle g h.1, PG.mono φ hle k h.2⟩ | .or g k, h => by simp [PG.eval] at h ⊢ cases h with | inl h => exact Or.inl (PG.mono φ hle g h) | inr h => exact Or.inr (PG.mono φ hle k h) /-- More readings can only add duties, never remove one. -/ theorem owed_mono (m : A → Bool) (φ : F → Bool) {ρ ρ' : Rd → Bool} (hle : le ρ ρ') (R : List (Rule F Rd A Fm)) (n : Nat) (h : owed m φ ρ R n = true) : owed m φ ρ' R n = true := by simp only [owed, List.any_eq_true, Bool.and_eq_true] at h ⊢ obtain ⟨r, hr, ht, he⟩ := h refine ⟨r, hr, ht, ?_⟩ cases hc : r.eff with | duty k g => rw [hc] at he simp only [Bool.and_eq_true] at he ⊢ exact ⟨he.1, PG.mono φ hle g he.2⟩ | permit _ _ => rw [hc] at he; exact he | ask _ => rw [hc] at he; exact he | forbid _ => rw [hc] at he; exact he | cap _ _ => rw [hc] at he; exact he | boundary _ _ => rw [hc] at he; exact he /-! ## Duties never change a release -/ /-- Decision 4. Adding a duty rule to a rule set changes no release. -/ theorem duty_neutral (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) (as : List A) (n : Nat) (g : PG F Rd) (q f : Fm) : release O m φ ρ (R ++ [⟨as, .duty n g⟩]) q f = release O m φ ρ R q f := by simp [release, blocked, capsOK, permitted, List.any_append, List.all_append, protects, capAllows, permitsAt] /-! ## T1 with A1. Locality: only touching rules matter -/ theorem locality (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) (q f : Fm) : release O m φ ρ R q f = release O m φ ρ (R.filter (touches m)) q f := by simp only [release, blocked, capsOK, permitted] congr 1 congr 1 · congr 1 · congr 1 apply Bool.eq_iff_iff.mpr simp only [List.any_eq_true, List.mem_filter] constructor · rintro ⟨r, hr, h⟩ simp at h exact ⟨r, ⟨hr, h.1⟩, by simp [h.1, h.2]⟩ · rintro ⟨r, ⟨hr, _⟩, h⟩ exact ⟨r, hr, h⟩ · apply Bool.eq_iff_iff.mpr simp only [List.all_eq_true, List.mem_filter] constructor · intro h r hr; exact h r hr.1 · intro h r hr cases ht : touches m r · simp · have := h r ⟨hr, ht⟩ simpa [ht] using this · apply Bool.eq_iff_iff.mpr simp only [List.any_eq_true, List.mem_filter] constructor · rintro ⟨r, hr, h⟩ simp at h exact ⟨r, ⟨hr, h.1⟩, by simp [h.1, h.2]⟩ · rintro ⟨r, ⟨hr, _⟩, h⟩ exact ⟨r, hr, h⟩ /-! ## T2. Order and repetition do not matter -/ theorem same_rules_same_answer (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R R' : List (Rule F Rd A Fm)) (hR : ∀ r, r ∈ R ↔ r ∈ R') (q f : Fm) : release O m φ ρ R q f = release O m φ ρ R' q f := by have hany : ∀ p : Rule F Rd A Fm → Bool, R.any p = R'.any p := by intro p apply Bool.eq_iff_iff.mpr simp only [List.any_eq_true] exact ⟨fun ⟨r, hr, h⟩ => ⟨r, (hR r).1 hr, h⟩, fun ⟨r, hr, h⟩ => ⟨r, (hR r).2 hr, h⟩⟩ have hall : ∀ p : Rule F Rd A Fm → Bool, R.all p = R'.all p := by intro p apply Bool.eq_iff_iff.mpr simp only [List.all_eq_true] exact ⟨fun h r hr => h r ((hR r).2 hr), fun h r hr => h r ((hR r).1 hr)⟩ simp only [release, blocked, capsOK, permitted, hany, hall] /-! ## Weakest form: a weaker form is released whenever a stronger one is -/ theorem capAllows_down (φ : F → Bool) {f g : Fm} (hgf : O.le g f = true) : ∀ e : Effect F Rd Fm, capAllows O φ f e = true → capAllows O φ g e = true | .cap c g', h => by simp only [capAllows, Bool.or_eq_true] at h ⊢ rcases h with h | h · exact Or.inl h · exact Or.inr (O.trans g f c hgf h) | .permit _ _, _ => rfl | .ask _, _ => rfl | .forbid _, _ => rfl | .boundary _ _, _ => rfl | .duty _ _, _ => rfl theorem permitsAt_down (φ : F → Bool) {f g : Fm} (hgf : O.le g f = true) : ∀ e : Effect F Rd Fm, permitsAt O φ f e = true → permitsAt O φ g e = true | .permit p g', h => by simp only [permitsAt, Bool.and_eq_true] at h ⊢ exact ⟨h.1, O.trans g f p hgf h.2⟩ | .ask _, h => by simp [permitsAt] at h | .forbid _, h => by simp [permitsAt] at h | .cap _ _, h => by simp [permitsAt] at h | .boundary _ _, h => by simp [permitsAt] at h | .duty _ _, h => by simp [permitsAt] at h theorem downward_closed (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) (q f g : Fm) (hgf : O.le g f = true) (h : release O m φ ρ R q f = true) : release O m φ ρ R q g = true := by simp only [release, capsOK, permitted, Bool.and_eq_true, List.all_eq_true, List.any_eq_true, Bool.or_eq_true] at h ⊢ obtain ⟨⟨⟨hb, hc⟩, ⟨r, hr, ht, hp⟩⟩, hq⟩ := h refine ⟨⟨⟨hb, ?_⟩, ⟨r, hr, ht, permitsAt_down O φ hgf r.eff hp⟩⟩, O.trans g f q hgf hq⟩ intro r' hr' rcases hc r' hr' with h | h · exact Or.inl h · exact Or.inr (capAllows_down O φ hgf r'.eff h) /-! ## T6. The agent never exceeds its person -/ def releaseVia (ms ma : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (Rs Ra : List (Rule F Rd A Fm)) (actsFor : Bool) (q f : Fm) : Bool := actsFor && release O ms φ ρ Rs q f && release O ma φ ρ Ra q f theorem agent_bound (ms ma : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (Rs Ra : List (Rule F Rd A Fm)) (af : Bool) (q f : Fm) (h : releaseVia O ms ma φ ρ Rs Ra af q f = true) : release O ms φ ρ Rs q f = true ∧ release O ma φ ρ Ra q f = true ∧ af = true := by simp [releaseVia] at h exact ⟨h.1.2, h.2, h.1.1⟩ /-! ## Extra checks that only remove releases keep every guarantee The token check (C039, C059), the release budget (C057-b), "which use case?" (C031), "drop the denied parts" (C022) and a failed permit condition (decision 5) each add a condition that a release must also meet, computed from facts and the history only. -/ /-- A release with an extra condition `extra`, which may depend on the facts but not on readings. -/ def releaseX (extra : Bool) (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) (q f : Fm) : Bool := release O m φ ρ R q f && extra theorem releaseX_sub (extra : Bool) (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) (q f : Fm) (h : releaseX O extra m φ ρ R q f = true) : release O m φ ρ R q f = true := by simp [releaseX] at h; exact h.1 theorem noninterference_X (extra : Bool) (m : A → Bool) (φ : F → Bool) (R : List (Rule F Rd A Fm)) (q : Fm) (h : blocked m φ R = true) : ∀ (ρ : Rd → Bool) (f : Fm), releaseX O extra m φ ρ R q f = false := by intro ρ f; simp [releaseX, noninterference O m φ R q h ρ f] theorem caps_hold_X (extra : Bool) (m : A → Bool) (φ : F → Bool) (ρ : Rd → Bool) (R : List (Rule F Rd A Fm)) (q f : Fm) (h : releaseX O extra m φ ρ R q f = true) : capsOK O m φ R f = true := caps_hold O m φ ρ R q f (releaseX_sub O extra m φ ρ R q f h) theorem releaseX_reading_free (extra : Bool) (m : A → Bool) (φ : F → Bool) (ρ ρ' : Rd → Bool) (R : List (Rule F Rd A Fm)) (q f : Fm) : releaseX O extra m φ ρ R q f = releaseX O extra m φ ρ' R q f := rfl /-! ## The seven forms of the language are a lattice (decision 2) -/ inductive Form where | metadata | count | aggregated | anonymised | pseudonymised | summarised | raw deriving DecidableEq, Repr /-- Rows (anonymised, pseudonymised) and summaries are not comparable; both sit between aggregated and raw. -/ def Form.le : Form → Form → Bool | .metadata, _ => true | _, .raw => true | .count, .metadata => false | .count, _ => true | .aggregated, .metadata => false | .aggregated, .count => false | .aggregated, _ => true | .anonymised, .anonymised => true | .anonymised, .pseudonymised => true | .pseudonymised, .pseudonymised => true | .summarised, .summarised => true | _, _ => false theorem Form.le_refl : ∀ a : Form, a.le a = true := by intro a; cases a <;> decide theorem Form.le_trans : ∀ a b c : Form, a.le b = true → b.le c = true → a.le c = true := by intro a b c; cases a <;> cases b <;> cases c <;> decide theorem Form.le_antisymm : ∀ a b : Form, a.le b = true → b.le a = true → a = b := by intro a b; cases a <;> cases b <;> decide def formOrder : FormOrder Form := ⟨Form.le, Form.le_refl, Form.le_trans⟩ /-- The greatest lower bound. The only incomparable pairs are a row form and a summary; their meet is `aggregated`. -/ def Form.meet (a b : Form) : Form := if a.le b then a else if b.le a then b else .aggregated theorem Form.meet_le_left : ∀ a b : Form, (a.meet b).le a = true := by intro a b; cases a <;> cases b <;> decide theorem Form.meet_le_right : ∀ a b : Form, (a.meet b).le b = true := by intro a b; cases a <;> cases b <;> decide theorem Form.le_meet : ∀ a b c : Form, c.le a = true → c.le b = true → c.le (a.meet b) = true := by intro a b c; cases a <;> cases b <;> cases c <;> decide /-- The case that forced decision 2 (C002-b): a summary does not release pseudonymised rows. -/ theorem summary_is_not_rows : Form.le .pseudonymised .summarised = false ∧ Form.le .summarised .pseudonymised = false ∧ Form.meet .pseudonymised .summarised = .aggregated := by decide end AccessCore