Confirm.lean
Lean 4 source (Lean 4 core, no Mathlib). 23 theorems. Download Confirm.lean.
Theorems in this file
rel_rfanyRel_rfgain_rfshown_is_askno_confirmation_no_gainrefuser_gets_facts_onlyconfirmed_were_acceptedauthority_boundoutcome_is_log_functionreachable_by_declaringfacts_growshown_releasesstep_releasesno_second_questionlog_length_le_oneone_round_sufficesscreen_is_exactendorsed_releaseconsequence_guaranteemenu_reading_freemenu_robuststeeringsteering_blocked
/- The confirm loop as a game (25 November 2026). `Strict.lean` proves that for given facts the release does not depend on readings, and that a confirmation question is asked only when the proposed declaration would release (`confirm_is_sound`). It says nothing about the loop ask -> confirm -> decide again, in which a confirmed declaration becomes a fact. Review 1 (open item 2): injected text controls the readings, hence which question is shown, hence what is declassified. This file models that loop and proves what does and does not hold. The game, for one request (asset anchors `m`, asked form `q`, candidate forms `fs`): * the ATTACKER chooses the readings of every round (`Nat → Rd → Bool`); it therefore chooses which proposal the decision point shows; * the decision point shows the first proposal (in the order of `props`) that the model read and whose declaration would release something, and only when nothing is released on the facts (SEMANTICS §2.6; core.py `decide`). The screen carries the declaration and the forms that would then be released; * the CONFIRMER is a principal, modelled as a predicate on screens: it confirms or refuses; * a confirmed declaration becomes a fact (`withFact`), and the request is decided again. Results (English statements in ../CONFIRM.md): * `no_confirmation_no_gain`, `refuser_gets_facts_only` (i) no confirmation, no gain; * `confirmed_were_accepted`, `authority_bound`, `reachable_by_declaring`, `outcome_is_log_function` (ii) attacker power is bounded by the confirmer's own declarations; * `endorsed_release` (iii) every released form was on a screen the confirmer accepted; * `log_length_le_one`, `one_round_suffices`, `facts_grow` (iv) the loop ends after one confirmation; facts only grow; * `steering` NOT protected: with a confirmer who confirms any declaration it holds, readings choose the released form; * `screen_is_exact`, `consequence_guarantee`, `steering_blocked` mitigation 1: show the consequence; held declarations only; * `menu_reading_free`, `menu_robust` mitigation 2: a menu of every held declaration, readings only trigger. Lean 4 core only, no Mathlib. Imports Strict.lean (build its .olean first; see ../CONFIRM.md). -/ import Strict namespace AccessConfirm open AccessStrict /-- One request in one deployment: the rule set, the decision point's proposals (a reading paired with the declaration the requester would make by confirming it), the asked form, and the finite list of candidate forms the decision point considers. -/ structure Setting (F Rd A Fm : Type) where O : FormOrder Fm m : A → Bool R : List (Rule F Rd A Fm) props : List (Rd × F) q : Fm fs : List Fm /-- What the confirmer sees: the declaration proposed and the forms that would be released. -/ structure Screen (F Fm : Type) where decl : F gain : List Fm variable {F Rd A Fm : Type} [DecidableEq F] namespace Setting variable (S : Setting F Rd A Fm) def rel (φ : F → Bool) (ρ : Rd → Bool) (f : Fm) : Bool := release S.O S.m φ ρ S.R S.q f /-- Something is released under these facts. -/ def anyRel (φ : F → Bool) (ρ : Rd → Bool) : Bool := S.fs.any (S.rel φ ρ) /-- The forms that would be released after declaring `d`: the consequence. -/ def gain (φ : F → Bool) (ρ : Rd → Bool) (d : F) : List Fm := S.fs.filter (S.rel (withFact φ d) ρ) /-- A proposal is shown if the model read it, its declaration is admissible (`held`), and the declaration would release something. Naive strict mode: `held := fun _ => true`. -/ def useful (held : F → Bool) (φ : F → Bool) (ρ : Rd → Bool) (p : Rd × F) : Bool := ρ p.1 && held p.2 && S.anyRel (withFact φ p.2) ρ /-- The declaration the decision point proposes, if any. -/ def shown (held : F → Bool) (φ : F → Bool) (ρ : Rd → Bool) : Option F := if S.anyRel φ ρ then none else (S.props.find? (S.useful held φ ρ)).map Prod.snd /-- One round: the declaration that becomes a fact, if the confirmer accepts the screen. -/ def step (held : F → Bool) (C : Screen F Fm → Bool) (φ : F → Bool) (ρ : Rd → Bool) : Option F := match S.shown held φ ρ with | none => none | some d => if C ⟨d, S.gain φ ρ d⟩ then some d else none /-- The confirmed declarations over at most `n` rounds; the attacker's readings per round. -/ def log (held : F → Bool) (C : Screen F Fm → Bool) : Nat → (F → Bool) → (Nat → Rd → Bool) → List F | 0, _, _ => [] | n + 1, φ, A => match S.step held C φ (A 0) with | none => [] | some d => d :: log held C n (withFact φ d) (fun i => A (i + 1)) end Setting /-- Add declarations one by one. -/ def applyAll (φ : F → Bool) : List F → F → Bool | [] => φ | d :: ds => applyAll (withFact φ d) ds namespace Setting variable (S : Setting F Rd A Fm) /-- The facts at the end of the game. -/ def final (held : F → Bool) (C : Screen F Fm → Bool) (n : Nat) (φ : F → Bool) (A : Nat → Rd → Bool) : F → Bool := applyAll φ (S.log held C n φ A) /-! ## Reading-freedom of every ingredient (from Strict.lean) -/ omit [DecidableEq F] in theorem rel_rf (hR : strictOK S.R = true) (φ : F → Bool) (ρ ρ' : Rd → Bool) : S.rel φ ρ = S.rel φ ρ' := by funext f exact release_reading_free_of_check S.O S.m φ ρ ρ' S.R hR S.q f omit [DecidableEq F] in theorem anyRel_rf (hR : strictOK S.R = true) (φ : F → Bool) (ρ ρ' : Rd → Bool) : S.anyRel φ ρ = S.anyRel φ ρ' := by unfold anyRel; rw [S.rel_rf hR φ ρ ρ'] theorem gain_rf (hR : strictOK S.R = true) (φ : F → Bool) (ρ ρ' : Rd → Bool) (d : F) : S.gain φ ρ d = S.gain φ ρ' d := by unfold gain; rw [S.rel_rf hR (withFact φ d) ρ ρ'] /-! ## The loop asks what Strict.lean's verdict asks -/ /-- If the loop shows a declaration, Strict.lean's `decide'` answers `ask` at some candidate form. -/ theorem shown_is_ask (held : F → Bool) (φ : F → Bool) (ρ : Rd → Bool) (d : F) (h : S.shown held φ ρ = some d) : ∃ f ∈ S.fs, decide' S.O S.m φ ρ S.R S.props S.q f = .ask := by unfold shown at h by_cases ha : S.anyRel φ ρ = true · simp [ha] at h · simp only [ha] at h simp only [Bool.false_eq_true, ite_false, Option.map_eq_some_iff] at h obtain ⟨p, hp, _⟩ := h have hmem := List.mem_of_find?_eq_some hp have hu := List.find?_some hp simp only [useful, Bool.and_eq_true] at hu obtain ⟨⟨hρ, _⟩, hany⟩ := hu simp only [anyRel, List.any_eq_true] at hany obtain ⟨f, hf, hrel⟩ := hany refine ⟨f, hf, ?_⟩ have hno : release S.O S.m φ ρ S.R S.q f = false := by cases hh : release S.O S.m φ ρ S.R S.q f with | false => rfl | true => exfalso; apply ha simp only [anyRel, List.any_eq_true] exact ⟨f, hf, hh⟩ have hp2 : S.props.any (fun p => ρ p.1 && release S.O S.m (withFact φ p.2) ρ S.R S.q f) = true := by simp only [List.any_eq_true, Bool.and_eq_true] exact ⟨p, hmem, hρ, hrel⟩ unfold decide' simp [hno, hp2] /-! ## (i) No confirmation, no gain -/ /-- If nothing was confirmed, the final facts are the initial facts, so the release is the facts-only release, under every readings. -/ theorem no_confirmation_no_gain (held : F → Bool) (C : Screen F Fm → Bool) (n : Nat) (φ : F → Bool) (A : Nat → Rd → Bool) (h : S.log held C n φ A = []) : S.final held C n φ A = φ := by unfold final; rw [h]; rfl /-- A confirmer who refuses every screen ends with the facts it started with, whatever the attacker reads, in any number of rounds. -/ theorem refuser_gets_facts_only (held : F → Bool) (n : Nat) (φ : F → Bool) (A : Nat → Rd → Bool) : S.final held (fun _ => false) n φ A = φ := by apply S.no_confirmation_no_gain cases n with | zero => rfl | succ n => simp only [log, step] cases S.shown held φ (A 0) <;> rfl /-! ## (ii) Attacker power is bounded by the confirmer's authority -/ /-- Every confirmed declaration was on a screen the confirmer accepted, and is admissible. -/ theorem confirmed_were_accepted (held : F → Bool) (C : Screen F Fm → Bool) : ∀ (n : Nat) (φ : F → Bool) (A : Nat → Rd → Bool), ∀ d ∈ S.log held C n φ A, held d = true ∧ ∃ g, C ⟨d, g⟩ = true | 0, _, _, d, hd => by simp [log] at hd | n + 1, φ, A, d, hd => by simp only [log] at hd cases hs : S.step held C φ (A 0) with | none => simp [hs] at hd | some e => simp only [hs, List.mem_cons] at hd cases hd with | inl he => subst he simp only [step] at hs cases hsh : S.shown held φ (A 0) with | none => simp [hsh] at hs | some e' => simp only [hsh] at hs by_cases hc : C ⟨e', S.gain φ (A 0) e'⟩ = true · simp only [hc, ite_true, Option.some.injEq] at hs subst hs refine ⟨?_, _, hc⟩ simp only [shown] at hsh by_cases ha : S.anyRel φ (A 0) = true · simp [ha] at hsh · simp only [ha, Bool.false_eq_true, ite_false, Option.map_eq_some_iff] at hsh obtain ⟨p, hp, hpe⟩ := hsh have hu := List.find?_some hp simp only [useful, Bool.and_eq_true] at hu rw [← hpe]; exact hu.1.2 · simp [hc] at hs | inr hd => exact confirmed_were_accepted held C n _ _ d hd /-- **Authority bound.** If the confirmer accepts only declarations it is authorised (or willing) to make, every confirmed declaration is one of those, whatever the attacker reads. -/ theorem authority_bound (held : F → Bool) (C : Screen F Fm → Bool) (willing : F → Bool) (hC : ∀ s, C s = true → willing s.decl = true) (n : Nat) (φ : F → Bool) (A : Nat → Rd → Bool) : ∀ d ∈ S.log held C n φ A, willing d = true := by intro d hd obtain ⟨_, g, hg⟩ := S.confirmed_were_accepted held C n φ A d hd exact hC ⟨d, g⟩ hg /-- **The final release is a function of the confirmed declarations alone**: two attackers that lead to the same confirmations lead to the same release, under every readings. -/ theorem outcome_is_log_function (hR : strictOK S.R = true) (held : F → Bool) (C : Screen F Fm → Bool) (n n' : Nat) (φ : F → Bool) (A A' : Nat → Rd → Bool) (h : S.log held C n φ A = S.log held C n' φ A') (ρ ρ' : Rd → Bool) : S.rel (S.final held C n φ A) ρ = S.rel (S.final held C n' φ A') ρ' := by unfold final; rw [h]; exact S.rel_rf hR _ ρ ρ' /-- **Every release the attacker can reach, the confirmer could have obtained by declaring directly**: there is a list of declarations, each one the confirmer is willing to make and admissible, whose direct declaration gives the same release under every readings. -/ theorem reachable_by_declaring (hR : strictOK S.R = true) (held : F → Bool) (C : Screen F Fm → Bool) (willing : F → Bool) (hC : ∀ s, C s = true → willing s.decl = true) (n : Nat) (φ : F → Bool) (A : Nat → Rd → Bool) : ∃ D : List F, (∀ d ∈ D, willing d = true ∧ held d = true) ∧ ∀ ρ ρ' : Rd → Bool, S.rel (S.final held C n φ A) ρ = S.rel (applyAll φ D) ρ' := by refine ⟨S.log held C n φ A, ?_, ?_⟩ · intro d hd exact ⟨S.authority_bound held C willing hC n φ A d hd, (S.confirmed_were_accepted held C n φ A d hd).1⟩ · intro ρ ρ'; unfold final; exact S.rel_rf hR _ ρ ρ' /-! ## (iv) Termination and monotonicity -/ /-- Facts only grow along the game. -/ theorem facts_grow : ∀ (ds : List F) (φ : F → Bool) (x : F), φ x = true → applyAll φ ds x = true | [], _, _, h => h | d :: ds, φ, x, h => facts_grow ds (withFact φ d) x (by simp [withFact, h]) theorem shown_releases (held : F → Bool) (φ : F → Bool) (ρ : Rd → Bool) (d : F) (h : S.shown held φ ρ = some d) : S.anyRel (withFact φ d) ρ = true := by unfold shown at h by_cases ha : S.anyRel φ ρ = true · simp [ha] at h · simp only [ha, Bool.false_eq_true, ite_false, Option.map_eq_some_iff] at h obtain ⟨p, hp, hpe⟩ := h have hu := List.find?_some hp simp only [useful, Bool.and_eq_true] at hu rw [← hpe]; exact hu.2 theorem step_releases (held : F → Bool) (C : Screen F Fm → Bool) (φ : F → Bool) (ρ : Rd → Bool) (d : F) (h : S.step held C φ ρ = some d) : S.anyRel (withFact φ d) ρ = true := by unfold step at h cases hs : S.shown held φ ρ with | none => simp [hs] at h | some e => simp only [hs] at h by_cases hc : C ⟨e, S.gain φ ρ e⟩ = true · simp only [hc, ite_true, Option.some.injEq] at h subst h; exact S.shown_releases held φ ρ e hs · simp [hc] at h /-- After a confirmation something is released, so nothing more is shown, whatever is read next. -/ theorem no_second_question (hR : strictOK S.R = true) (held : F → Bool) (C : Screen F Fm → Bool) (φ : F → Bool) (ρ ρ' : Rd → Bool) (d : F) (h : S.step held C φ ρ = some d) : S.step held C (withFact φ d) ρ' = none := by have hr := S.step_releases held C φ ρ d h rw [S.anyRel_rf hR _ ρ ρ'] at hr simp [step, shown, hr] /-- **The loop confirms at most one declaration**, whatever the attacker reads and however many rounds it is given. -/ theorem log_length_le_one (hR : strictOK S.R = true) (held : F → Bool) (C : Screen F Fm → Bool) : ∀ (n : Nat) (φ : F → Bool) (A : Nat → Rd → Bool), (S.log held C n φ A).length ≤ 1 | 0, _, _ => by simp [log] | n + 1, φ, A => by simp only [log] cases hs : S.step held C φ (A 0) with | none => simp | some d => cases n with | zero => simp [log] | succ n => simp [log, S.no_second_question hR held C φ (A 0) (A 1) d hs] /-- **One round suffices**: more rounds change nothing. -/ theorem one_round_suffices (hR : strictOK S.R = true) (held : F → Bool) (C : Screen F Fm → Bool) (n : Nat) (φ : F → Bool) (A : Nat → Rd → Bool) : S.log held C (n + 1) φ A = S.log held C 1 φ A := by simp only [log] cases hs : S.step held C φ (A 0) with | none => rfl | some d => cases n with | zero => rfl | succ n => simp [log, S.no_second_question hR held C φ (A 0) (A 1) d hs] /-! ## (iii) Mitigation 1: the screen shows the consequence -/ /-- **The screen is exact.** The forms listed on the screen are exactly the forms released after the confirmation, under every readings; the attacker cannot make the screen understate. -/ theorem screen_is_exact (hR : strictOK S.R = true) (φ : F → Bool) (ρ ρ' : Rd → Bool) (d : F) (f : Fm) (hf : f ∈ S.fs) : f ∈ S.gain φ ρ d ↔ S.rel (withFact φ d) ρ' f = true := by rw [S.gain_rf hR φ ρ ρ' d] simp [gain, List.mem_filter, hf] /-- **Consequence guarantee (robust-declassification style).** Assume only this of the human: it accepts a screen only if it endorses every form the screen lists (`endorse` is the requester's own judgement about this request, e.g. "aggregates are fine, rows are not"). Then, whatever the attacker reads, in any number of rounds, every released form is released on the facts alone or endorsed by the confirmer. -/ theorem endorsed_release (hR : strictOK S.R = true) (held : F → Bool) (C : Screen F Fm → Bool) (endorse : Fm → Bool) (hC : ∀ s, C s = true → ∀ f ∈ s.gain, endorse f = true) : ∀ (n : Nat) (φ : F → Bool) (A : Nat → Rd → Bool) (ρ : Rd → Bool), ∀ f ∈ S.fs, S.rel (S.final held C n φ A) ρ f = true → S.rel φ ρ f = true ∨ endorse f = true | 0, _, _, _, _, _, h => Or.inl h | n + 1, φ, A, ρ, f, hf, h => by unfold final at h simp only [log] at h cases hs : S.step held C φ (A 0) with | none => simp only [hs] at h; exact Or.inl h | some d => simp only [hs, applyAll] at h have ih := endorsed_release hR held C endorse hC n (withFact φ d) (fun i => A (i + 1)) ρ f hf h cases ih with | inr he => exact Or.inr he | inl hw => right unfold step at hs cases hsh : S.shown held φ (A 0) with | none => simp [hsh] at hs | some e => simp only [hsh] at hs by_cases hc : C ⟨e, S.gain φ (A 0) e⟩ = true · simp only [hc, ite_true, Option.some.injEq] at hs subst hs apply hC _ hc f exact (S.screen_is_exact hR φ (A 0) ρ e f hf).2 hw · simp [hc] at hs /-- The same, named for the statement the paper needs. -/ theorem consequence_guarantee (hR : strictOK S.R = true) (held : F → Bool) (C : Screen F Fm → Bool) (endorse : Fm → Bool) (hC : ∀ s, C s = true → ∀ f ∈ s.gain, endorse f = true) (n : Nat) (φ : F → Bool) (A : Nat → Rd → Bool) (ρ : Rd → Bool) (f : Fm) (hf : f ∈ S.fs) (hnot : S.rel φ ρ f = false) (h : S.rel (S.final held C n φ A) ρ f = true) : endorse f = true := by cases S.endorsed_release hR held C endorse hC n φ A ρ f hf h with | inl h' => rw [hnot] at h'; exact absurd h' (by decide) | inr he => exact he /-! ## Mitigation 2: a menu of every admissible declaration; readings only trigger it -/ /-- Every admissible declaration that would release, with its consequence. No reading in it. -/ def menu (held : F → Bool) (φ : F → Bool) (ρ : Rd → Bool) : List (F × List Fm) := (S.props.filter (fun p => held p.2 && S.anyRel (withFact φ p.2) ρ)).map (fun p => (p.2, S.gain φ ρ p.2)) theorem menu_reading_free (hR : strictOK S.R = true) (held : F → Bool) (φ : F → Bool) (ρ ρ' : Rd → Bool) : S.menu held φ ρ = S.menu held φ ρ' := by have h1 : ∀ ψ, S.anyRel ψ ρ = S.anyRel ψ ρ' := fun ψ => S.anyRel_rf hR ψ ρ ρ' have h2 : ∀ d, S.gain φ ρ d = S.gain φ ρ' d := fun d => S.gain_rf hR φ ρ ρ' d simp only [menu, h1, h2] /-- The menu round: a reading only decides whether the menu is offered; the confirmer chooses from the menu (`choose`). -/ def menuStep (held : F → Bool) (choose : List (F × List Fm) → Option F) (φ : F → Bool) (ρ : Rd → Bool) : Option F := if S.anyRel φ ρ then none else if S.props.any (S.useful held φ ρ) then choose (S.menu held φ ρ) else none /-- What the confirmer would choose with no attacker at all (computed under no readings). -/ def menuChoice (held : F → Bool) (choose : List (F × List Fm) → Option F) (φ : F → Bool) : Option F := if S.anyRel φ (fun _ => false) then none else choose (S.menu held φ (fun _ => false)) /-- **Robust declassification for the menu.** Whatever the attacker reads, the round either declassifies nothing or declassifies exactly what the confirmer chooses from a menu that does not depend on the readings. The attacker can withhold the question; it cannot change the answer. -/ theorem menu_robust (hR : strictOK S.R = true) (held : F → Bool) (choose : List (F × List Fm) → Option F) (φ : F → Bool) (ρ : Rd → Bool) : S.menuStep held choose φ ρ = none ∨ S.menuStep held choose φ ρ = S.menuChoice held choose φ := by unfold menuStep menuChoice rw [S.anyRel_rf hR φ ρ (fun _ => false), S.menu_reading_free hR held φ ρ (fun _ => false)] by_cases ha : S.anyRel φ (fun _ => false) = true · simp [ha] · by_cases ht : S.props.any (S.useful held φ ρ) = true · simp [ha, ht] · simp [ha, ht] end Setting /-! ## What is NOT protected: steering among held declarations -/ /-- Facts: `d1` = declared(r, audit), `d2` = declared(r, payroll). The requester holds both. -/ inductive Fct where | d1 | d2 deriving DecidableEq, Repr /-- Readings: the model read use case audit / payroll. -/ inductive Rdg where | r1 | r2 deriving DecidableEq, Repr /-- Forms: `false` = aggregated, `true` = raw rows (`boolOrder`: aggregated ≤ raw). Permit aggregated under the audit declaration, raw under the payroll declaration. -/ def ex : Setting Fct Rdg Unit Bool where O := boolOrder m := fun _ => true R := [⟨[], .permit false (.fact .d1)⟩, ⟨[], .permit true (.fact .d2)⟩] props := [(.r1, .d1), (.r2, .d2)] q := true fs := [false, true] def noFacts : Fct → Bool := fun _ => false def honest : Nat → Rdg → Bool := fun _ r => r == .r1 -- the requester's own words: audit def injected : Nat → Rdg → Bool := fun _ r => r == .r2 -- a retrieved document: "payroll" def holdsBoth : Fct → Bool := fun _ => true /-- The weak human: confirms any declaration it holds, without reading the consequence. -/ def rubberStamp : Screen Fct Bool → Bool := fun s => holdsBoth s.decl /-- **Counterexample.** The rule set passes the strict check. With the same confirmer, the honest run releases aggregates only; the injected run releases raw rows. The readings chose what was declassified, inside the confirmer's authority. -/ theorem steering : strictOK ex.R = true ∧ ex.rel (ex.final holdsBoth rubberStamp 2 noFacts honest) (fun _ => false) false = true ∧ ex.rel (ex.final holdsBoth rubberStamp 2 noFacts honest) (fun _ => false) true = false ∧ ex.rel (ex.final holdsBoth rubberStamp 2 noFacts injected) (fun _ => false) true = true := by decide /-- The requester's purpose is the audit: aggregates are fine, rows are not. -/ def wantsAggregates : Bool → Bool := fun f => !f /-- The mitigated human: accepts only if every listed form is one it endorses. -/ def readsConsequence : Screen Fct Bool → Bool := fun s => s.gain.all wantsAggregates /-- **The mitigation blocks it.** Same attacker; the confirmer reads the consequence. The honest run still releases aggregates; the injected run releases nothing (the attacker can deny service, not steer the release). -/ theorem steering_blocked : ex.rel (ex.final holdsBoth readsConsequence 2 noFacts honest) (fun _ => false) false = true ∧ ex.rel (ex.final holdsBoth readsConsequence 2 noFacts injected) (fun _ => false) true = false ∧ ex.rel (ex.final holdsBoth readsConsequence 2 noFacts injected) (fun _ => false) false = false := by decide end AccessConfirm