Documentation

CslibFrontier.Languages.Probabilistic.UntilBad.Flag

Stateful ProbOracleComp identical-until-bad hops and monotone bad-flag combinators #

Cryptographic game hops on stateful oracle handlers typically augment a base state σ to σ × Bool with a sticky Boolean bad flag (FlagBad), proving that two handlers agree on good transitions and that dropping the flag recovers the unflagged executions. Meanwhile, adversaries with private randomness (ProbOracleComp spec) run against OracleComp.sumHandler with stateless uniform coin draws on the left, which preserve oracle state and never trigger bad events.

This module eliminates both sources of per-proof boilerplate:

  1. All-events CloseTo and sumHandler lifting for OracleComp.IdenticalUntilBad: IdenticalUntilBad.closeTo_run upgrades the difference lemma to CloseTo on the joint result-and-state distribution PMF (α × σ), and IdenticalUntilBad.sumHandler_lift_left lifts any external IdenticalUntilBad across memoryless left calls.
  2. Monotone Boolean bad-flag combinators (FlagBad, IsFlagMonotone, IdenticalUntilBad.of_flag, withBadFlag): IsFlagMonotone discharges absorption once for any handler that keeps true latched; IdenticalUntilBad.of_flag reduces IdenticalUntilBad to latched; IdenticalUntilBad.of_flag reduces IdenticalUntilBad to agreement on (s, false) transitions into (s', false); run_interpret_map_fst_of_flag drops a flag whose marginal on (a, s') is independent of the flag bit; and withBadFlag packages a per-step (a, (s', b')) kernel into a monotone flagged handler automatically.
  3. ProbOracleComp.IdenticalUntilBad and ProbOracleComp.runWith bad-event bounds: lifts run_apply, symm, bind_apply_le, bad_eq, abs_sub_le, closeTo_run, closeTo_bind, runWith_map_fst, toOuterMeasure_bad_le, toOuterMeasure_bad_choose_two_cost_le, and toOuterMeasure_bad_choose_two_le directly to ProbOracleComp.runWith under external query budgets (ProbOracleComp.IsQueryBounded / OracleComp.IsCostBounded), with no manual Sum.inl case splits.

Main definitions #

Main results #

References #

theorem Cslib.OracleComp.IdenticalUntilBad.closeTo_run {ι σ α : Type} {spec : ι → Type} {first second : (q : ι) → StateT σ PMF (spec q)} {bad : σ → Prop} (h : IdenticalUntilBad first second bad) (program : OracleComp spec α) (s : σ) :
Probability.CloseTo ((interpret first program).run s) ((interpret second program).run s) (((interpret first program).run s).toOuterMeasure {x : α × σ | bad x.2})

All-events difference lemma: handlers that agree until bad induce joint output-and-state distributions within CloseTo error equal to the probability of reaching a bad state.

theorem Cslib.OracleComp.IdenticalUntilBad.closeTo_bind {ι σ α β : Type} {spec : ι → Type} {first second : (q : ι) → StateT σ PMF (spec q)} {bad : σ → Prop} (h : IdenticalUntilBad first second bad) (program : OracleComp spec α) (s : σ) (next : α × σ → PMF β) :
Probability.CloseTo (((interpret first program).run s).bind next) (((interpret second program).run s).bind next) (((interpret first program).run s).toOuterMeasure {x : α × σ | bad x.2})

All-events difference lemma for continuations: postprocessing two identical-until-bad runs by a shared randomized continuation next preserves CloseTo within the bad-event probability.

theorem Cslib.OracleComp.IdenticalUntilBad.sumHandler_lift_left {ι σ : Type} {spec : ι → Type} {first second : (q : ι) → StateT σ PMF (spec q)} {bad : σ → Prop} {ι₁ : Type} {spec₁ : ι₁ → Type} (left : (q : ι₁) → PMF (spec₁ q)) (h : IdenticalUntilBad first second bad) :
IdenticalUntilBad (sumHandler (fun (q : ι₁) => StateT.lift (left q)) first) (sumHandler (fun (q : ι₁) => StateT.lift (left q)) second) bad

Lifting a memoryless handler on the left of sumHandler preserves IdenticalUntilBad on the right.

Monotone Boolean bad-flag combinators #

@[reducible, inline]
abbrev Cslib.OracleComp.FlagBad {σ : Type} (st : σ × Bool) :

Bad-state predicate on an augmented state σ × Bool testing whether the Boolean flag is true.

def Cslib.OracleComp.IsFlagMonotone {ι σ : Type} {spec : ι → Type} (handler : (q : ι) → StateT (σ × Bool) PMF (spec q)) :

A stateful handler on σ × Bool has a monotone bad flag when every supported transition from (s, true) preserves FlagBad.

theorem Cslib.OracleComp.IsFlagMonotone.absorb {ι σ : Type} {spec : ι → Type} {handler : (q : ι) → StateT (σ × Bool) PMF (spec q)} (h : IsFlagMonotone handler) (q : ι) (st : σ × Bool) :
FlagBad st → ∀ x ∈ (handler q st).support, FlagBad x.2

A monotone Boolean flag makes FlagBad absorbing on every state.

theorem Cslib.OracleComp.IdenticalUntilBad.of_flag {ι σ : Type} {spec : ι → Type} {first second : (q : ι) → StateT (σ × Bool) PMF (spec q)} (hfirst : IsFlagMonotone first) (hsecond : IsFlagMonotone second) (hagree : ∀ (q : ι) (s : σ) (a : spec q) (s' : σ), (first q (s, false)) (a, s', false) = (second q (s, false)) (a, s', false)) :

Construct IdenticalUntilBad on σ × Bool from flag monotonicity of both handlers and pointwise agreement on (s, false) transitions that remain at (s', false).

theorem Cslib.OracleComp.run_interpret_map_fst_of_flag {ι σ α : Type} {spec : ι → Type} (flagged : (q : ι) → StateT (σ × Bool) PMF (spec q)) (unflagged : (q : ι) → StateT σ PMF (spec q)) (hstep : ∀ (q : ι) (s : σ) (b : Bool), PMF.map (Prod.map id Prod.fst) (flagged q (s, b)) = unflagged q s) (program : OracleComp spec α) (s : σ) (b : Bool) :
PMF.map (Prod.map id Prod.fst) ((interpret flagged program).run (s, b)) = (interpret unflagged program).run s

Projecting away the Boolean flag of a handler on σ × Bool recovers an unflagged execution whenever each step's (a, s') marginal is independent of the input flag.

noncomputable def Cslib.OracleComp.withBadFlag {ι σ : Type} {spec : ι → Type} (step : (q : ι) → σ → PMF (spec q × σ × Bool)) (q : ι) :
StateT (σ × Bool) PMF (spec q)

Lift a step kernel step : (q : ι) → σ → PMF (spec q × (σ × Bool)) returning an answer, next state, and per-call bad indicator into a stateful handler on σ × Bool that latches the flag via ||.

@[simp]
theorem Cslib.OracleComp.withBadFlag_false {ι σ : Type} {spec : ι → Type} (step : (q : ι) → σ → PMF (spec q × σ × Bool)) (q : ι) (s : σ) :
withBadFlag step q (s, false) = step q s

Starting from b = false, one step of withBadFlag step has the exact law step q s.

theorem Cslib.OracleComp.isFlagMonotone_withBadFlag {ι σ : Type} {spec : ι → Type} (step : (q : ι) → σ → PMF (spec q × σ × Bool)) :

Every handler built with withBadFlag has a monotone Boolean bad flag.

theorem Cslib.OracleComp.identicalUntilBad_withBadFlag {ι σ : Type} {spec : ι → Type} (step₁ step₂ : (q : ι) → σ → PMF (spec q × σ × Bool)) (hagree : ∀ (q : ι) (s : σ) (a : spec q) (s' : σ), (step₁ q s) (a, s', false) = (step₂ q s) (a, s', false)) :

Two withBadFlag handlers are IdenticalUntilBad whenever their underlying kernels assign equal probability to every unflagged outcome (a, (s', false)).

@[simp]
theorem Cslib.OracleComp.withBadFlag_map_fst {ι σ : Type} {spec : ι → Type} (step : (q : ι) → σ → PMF (spec q × σ × Bool)) (q : ι) (s : σ) (b : Bool) :

Dropping the Boolean flag after one step of withBadFlag drops the per-step indicator, independently of the prior flag b.

theorem Cslib.OracleComp.run_interpret_withBadFlag_map_fst {ι σ α : Type} {spec : ι → Type} (step : (q : ι) → σ → PMF (spec q × σ × Bool)) (unflagged : (q : ι) → StateT σ PMF (spec q)) (hstep : ∀ (q : ι) (s : σ), PMF.map (Prod.map id Prod.fst) (step q s) = unflagged q s) (program : OracleComp spec α) (s : σ) (b : Bool) :
PMF.map (Prod.map id Prod.fst) ((interpret (withBadFlag step) program).run (s, b)) = (interpret unflagged program).run s

Dropping the Boolean flag of an adaptive withBadFlag execution recovers the unflagged execution whenever each step's (a, s') marginal matches unflagged.

def Cslib.ProbOracleComp.IdenticalUntilBad {Query State : Type} {spec : Query → Type} (first second : (q : Query) → StateT State PMF (spec q)) (bad : State → Prop) :

Two stateful external handlers agree until bad under ProbOracleComp.runWith: their lifted sumHandlers with private uniform coin sampling satisfy OracleComp.IdenticalUntilBad.

theorem Cslib.OracleComp.IdenticalUntilBad.probOracleComp {Query State : Type} {spec : Query → Type} {first second : (q : Query) → StateT State PMF (spec q)} {bad : State → Prop} (h : IdenticalUntilBad first second bad) :

Lift OracleComp.IdenticalUntilBad on external handlers to ProbOracleComp.IdenticalUntilBad across private uniform sampling.

theorem Cslib.ProbOracleComp.IdenticalUntilBad.toOracleComp {Query State : Type} {spec : Query → Type} {first second : (q : Query) → StateT State PMF (spec q)} {bad : State → Prop} (h : IdenticalUntilBad first second bad) :

Restrict ProbOracleComp.IdenticalUntilBad back to the external handlers.

theorem Cslib.ProbOracleComp.identicalUntilBad_iff {Query State : Type} {spec : Query → Type} {first second : (q : Query) → StateT State PMF (spec q)} {bad : State → Prop} :
IdenticalUntilBad first second bad ↔ OracleComp.IdenticalUntilBad first second bad

ProbOracleComp.IdenticalUntilBad holds if and only if the external handlers satisfy OracleComp.IdenticalUntilBad.

theorem Cslib.ProbOracleComp.IdenticalUntilBad.of_flag {Query State : Type} {spec : Query → Type} {first second : (q : Query) → StateT (State × Bool) PMF (spec q)} (hfirst : OracleComp.IsFlagMonotone first) (hsecond : OracleComp.IsFlagMonotone second) (hagree : ∀ (q : Query) (s : State) (a : spec q) (s' : State), (first q (s, false)) (a, s', false) = (second q (s, false)) (a, s', false)) :

Construct ProbOracleComp.IdenticalUntilBad on State × Bool from monotone Boolean flags on both external handlers and agreement on (s, false) ↦ (a, (s', false)).

theorem Cslib.ProbOracleComp.IdenticalUntilBad.symm {Query State : Type} {spec : Query → Type} {first second : (q : Query) → StateT State PMF (spec q)} {bad : State → Prop} (h : IdenticalUntilBad first second bad) :
IdenticalUntilBad second first bad

Symmetric relation for ProbOracleComp.IdenticalUntilBad.

theorem Cslib.ProbOracleComp.IdenticalUntilBad.run_apply {Query State α : Type} {spec : Query → Type} {first second : (q : Query) → StateT State PMF (spec q)} {bad : State → Prop} (h : IdenticalUntilBad first second bad) (program : ProbOracleComp spec α) (s : State) (a : α) (s' : State) (hs' : ¬bad s') :
(runWith first program s) (a, s') = (runWith second program s) (a, s')

Equal outcome probabilities at good final states under ProbOracleComp.runWith.

theorem Cslib.ProbOracleComp.IdenticalUntilBad.bind_apply_le {Query State α β : Type} {spec : Query → Type} {first second : (q : Query) → StateT State PMF (spec q)} {bad : State → Prop} (h : IdenticalUntilBad first second bad) (program : ProbOracleComp spec α) (s : State) (next : α × State → PMF β) (b : β) :
((runWith first program s).bind next) b ≤ ((runWith second program s).bind next) b + (runWith first program s).toOuterMeasure {x : α × State | bad x.2}

The difference lemma ([BS23], Theorem 4.7) for ProbOracleComp.runWith.

theorem Cslib.ProbOracleComp.IdenticalUntilBad.bad_eq {Query State α : Type} {spec : Query → Type} {first second : (q : Query) → StateT State PMF (spec q)} {bad : State → Prop} (h : IdenticalUntilBad first second bad) (program : ProbOracleComp spec α) (s : State) :
(runWith first program s).toOuterMeasure {x : α × State | bad x.2} = (runWith second program s).toOuterMeasure {x : α × State | bad x.2}

Both external handlers reach bad with equal probability under ProbOracleComp.runWith.

theorem Cslib.ProbOracleComp.IdenticalUntilBad.abs_sub_le {Query State α β : Type} {spec : Query → Type} {first second : (q : Query) → StateT State PMF (spec q)} {bad : State → Prop} (h : IdenticalUntilBad first second bad) (program : ProbOracleComp spec α) (s : State) (next : α × State → PMF β) (b : β) :
|(((runWith first program s).bind next) b).toReal - (((runWith second program s).bind next) b).toReal| ≤ ((runWith first program s).toOuterMeasure {x : α × State | bad x.2}).toReal

Two-sided difference lemma ([BS23], Theorem 4.7) for ProbOracleComp.runWith.

theorem Cslib.ProbOracleComp.IdenticalUntilBad.closeTo_run {Query State α : Type} {spec : Query → Type} {first second : (q : Query) → StateT State PMF (spec q)} {bad : State → Prop} (h : IdenticalUntilBad first second bad) (program : ProbOracleComp spec α) (s : State) :
Probability.CloseTo (runWith first program s) (runWith second program s) ((runWith first program s).toOuterMeasure {x : α × State | bad x.2})

All-events CloseTo difference lemma on joint (α × State) outcomes of ProbOracleComp.runWith.

theorem Cslib.ProbOracleComp.IdenticalUntilBad.closeTo_bind {Query State α β : Type} {spec : Query → Type} {first second : (q : Query) → StateT State PMF (spec q)} {bad : State → Prop} (h : IdenticalUntilBad first second bad) (program : ProbOracleComp spec α) (s : State) (next : α × State → PMF β) :
Probability.CloseTo ((runWith first program s).bind next) ((runWith second program s).bind next) ((runWith first program s).toOuterMeasure {x : α × State | bad x.2})

All-events CloseTo difference lemma across a continuation next after ProbOracleComp.runWith.

theorem Cslib.ProbOracleComp.identicalUntilBad_withBadFlag {Query State : Type} {spec : Query → Type} (step₁ step₂ : (q : Query) → State → PMF (spec q × State × Bool)) (hagree : ∀ (q : Query) (s : State) (a : spec q) (s' : State), (step₁ q s) (a, s', false) = (step₂ q s) (a, s', false)) :

Two external withBadFlag handlers satisfy ProbOracleComp.IdenticalUntilBad whenever their underlying kernels assign equal mass to unflagged outcomes (a, (s', false)).

theorem Cslib.ProbOracleComp.runWith_map_fst {Query State α : Type} {spec : Query → Type} (flagged : (q : Query) → StateT (State × Bool) PMF (spec q)) (unflagged : (q : Query) → StateT State PMF (spec q)) (hstep : ∀ (q : Query) (s : State) (b : Bool), PMF.map (Prod.map id Prod.fst) (flagged q (s, b)) = unflagged q s) (program : ProbOracleComp spec α) (s : State) (b : Bool) :
PMF.map (Prod.map id Prod.fst) (runWith flagged program (s, b)) = runWith unflagged program s

Projecting away the Boolean flag of an external handler on State × Bool recovers the unflagged ProbOracleComp.runWith execution whenever each step's (a, s') marginal is independent of b.

theorem Cslib.ProbOracleComp.runWith_withBadFlag_map_fst {Query State α : Type} {spec : Query → Type} (step : (q : Query) → State → PMF (spec q × State × Bool)) (unflagged : (q : Query) → StateT State PMF (spec q)) (hstep : ∀ (q : Query) (s : State), PMF.map (Prod.map id Prod.fst) (step q s) = unflagged q s) (program : ProbOracleComp spec α) (s : State) (b : Bool) :
PMF.map (Prod.map id Prod.fst) (runWith (OracleComp.withBadFlag step) program (s, b)) = runWith unflagged program s

Projecting away the Boolean flag of withBadFlag step under ProbOracleComp.runWith recovers runWith unflagged whenever each step's (a, s') marginal matches unflagged.

Bad-event union bounds for ProbOracleComp.runWith #

theorem Cslib.ProbOracleComp.toOuterMeasure_bad_le {Query State α : Type} {spec : Query → Type} {handler : (q : Query) → StateT State PMF (spec q)} {bad : State → Prop} (cost : Query → ℕ) (budget : State → ENNReal) (δ : ENNReal) (hstep : ∀ (q : Query) (s : State), ¬bad s → (handler q s).toOuterMeasure {x : spec q × State | bad x.2} ≤ ↑(cost q) * budget s) (hgrow : ∀ (q : Query) (s : State), ¬bad s → ∀ x ∈ (handler q s).support, ¬bad x.2 → budget x.2 ≤ budget s + δ) {program : ProbOracleComp spec α} {n k : ℕ} (hn : program.IsQueryBounded n) (hk : OracleComp.IsCostBounded (Sum.elim (fun (x : ℕ) => 0) cost) program k) {s : State} (hs : ¬bad s) :
(runWith handler program s).toOuterMeasure {x : α × State | bad x.2} ≤ ↑k * (budget s + ↑n * δ)

Accumulated probability of a bad state under ProbOracleComp.runWith. Let each external call q from a good state turn bad with probability at most cost q * budget s and raise budget by at most δ (while private coin draws cost nothing and leave state unchanged). Then a program making at most n external queries (program.IsQueryBounded n), whose external calls have cost at most k, reaches a bad state from s with probability at most k * (budget s + n * δ).

theorem Cslib.ProbOracleComp.toOuterMeasure_bad_choose_two_cost_le {Query State α : Type} {spec : Query → Type} {handler : (q : Query) → StateT State PMF (spec q)} {bad : State → Prop} (cost₁ cost₂ : Query → ℕ) (size : State → ℕ) (δ : ENNReal) (hstep : ∀ (q : Query) (s : State), ¬bad s → (handler q s).toOuterMeasure {x : spec q × State | bad x.2} ≤ ↑(cost₁ q * size s + (cost₁ q).choose 2) * δ) (hgrow : ∀ (q : Query) (s : State), ¬bad s → ∀ x ∈ (handler q s).support, ¬bad x.2 → size x.2 ≤ size s + cost₁ q + cost₂ q) {program : ProbOracleComp spec α} {k₁ k₂ : ℕ} (hk₁ : OracleComp.IsCostBounded (Sum.elim (fun (x : ℕ) => 0) cost₁) program k₁) (hk₂ : OracleComp.IsCostBounded (Sum.elim (fun (x : ℕ) => 0) cost₂) program k₂) {s : State} (hs : ¬bad s) :
(runWith handler program s).toOuterMeasure {x : α × State | bad x.2} ≤ ↑(k₁ * size s + k₁ * k₂ + k₁.choose 2) * δ

Two-cost triangular bad-state union bound under ProbOracleComp.runWith. When external calls carry budgets k₁ for cost₁ (charging (cost₁ q * size s + (cost₁ q).choose 2) * δ and growing size) and k₂ for cost₂ (growing size passively), runWith handler program s reaches bad with probability at most (k₁ * size s + k₁ * k₂ + k₁.choose 2) * δ. The (cost₁ q).choose 2 term covers a call that adds several points and may collide among them.

theorem Cslib.ProbOracleComp.toOuterMeasure_bad_choose_two_le {Query State α : Type} {spec : Query → Type} {handler : (q : Query) → StateT State PMF (spec q)} {bad : State → Prop} (size : State → ℕ) (δ : ENNReal) (hstep : ∀ (q : Query) (s : State), ¬bad s → (handler q s).toOuterMeasure {x : spec q × State | bad x.2} ≤ ↑(size s) * δ) (hgrow : ∀ (q : Query) (s : State), ¬bad s → ∀ x ∈ (handler q s).support, ¬bad x.2 → size x.2 ≤ size s + 1) {program : ProbOracleComp spec α} {n : ℕ} (hn : program.IsQueryBounded n) {s : State} (hs : ¬bad s) :
(runWith handler program s).toOuterMeasure {x : α × State | bad x.2} ≤ ↑(n * size s + n.choose 2) * δ

Triangular bad-state union bound under ProbOracleComp.runWith. If each external call from a good state s turns bad with probability at most size s * δ and increases size by at most 1, then a program making at most n external queries (program.IsQueryBounded n) reaches a bad state from s with probability at most (n * size s + n.choose 2) * δ.