Documentation

CslibFrontier.Languages.Probabilistic.RandomOracle.Programming

Random-oracle min-entropy programming and birthday collision bounds #

Two quantitative patterns recur throughout random-oracle security proofs:

  1. Min-entropy programming (toOuterMeasure_exists_mem_fst_eq_le, lazyProgramHandler, overwriteProgramHandler): an oracle handler (such as a Fiat–Shamir signer or NIZK simulator) samples pre-challenge coins ts whose hash query point req ts has guessing probability at most δ, and programs (point req ts) ↦ c with a fresh c ← dist instead of querying the lazy random oracle memoize (fun _ => dist). By withBadFlag and the two-cost triangular union bound OracleComp.toOuterMeasure_bad_choose_two_cost_le, an adaptive program making at most q_S programming calls and q_H direct random-oracle calls hits an already-cached point during programming with probability at most (q_S * cache.length + q_S * q_H + q_S.choose 2) * δ (hence (q_S * q_H + q_S.choose 2) * δ ≤ q_S * (q_S + q_H) * δ from an empty cache), bounding the CloseTo distance between lazy and programmed executions for both OracleComp and ProbOracleComp.runWith.
  2. Random-function output-collision birthday bound (HasOutputCollision, toOuterMeasure_collision_memoize_uniform_le, toOuterMeasure_hasOutputCollision_memoize_uniform_le): an adaptive q-query OracleComp or ProbOracleComp interacting with memoize (fun _ => PMF.uniformOfFintype Digest) from an empty cache observes two distinct queried keys with the same digest (HasOutputCollision, equivalent on duplicate-free key caches to ¬(cache.map Prod.snd).Nodup) with probability at most q.choose 2 / Fintype.card Digest.

Main definitions #

Main results #

References #

Min-entropy cache-lookup bounds #

theorem Cslib.RandomOracle.toOuterMeasure_exists_mem_fst_eq_le {α : Type u_1} {Query : Type u_2} {Value : Type u_3} {μ : PMF α} {f : α → Query} {δ : ENNReal} (hμ : ∀ (q : Query), (PMF.map f μ) q ≤ δ) (cache : List (Query × Value)) :
μ.toOuterMeasure {a : α | ∃ e ∈ cache, e.1 = f a} ≤ ↑cache.length * δ

Min-entropy list-key collision bound: if every value of f occurs under μ with probability at most δ (∀ q, (μ.map f) q ≤ δ), then f a matches the key of some entry in cache with probability at most cache.length * δ.

theorem Cslib.RandomOracle.map_comp_apply_le_of_injective {α : Type u_1} {β : Type u_2} {Query : Type u_3} {μ : PMF α} {g : α → β} {emb : β → Query} (hemb : Function.Injective emb) {δ : ENNReal} (hμ : ∀ (b : β), (PMF.map g μ) b ≤ δ) (q : Query) :
(PMF.map (emb ∘ g) μ) q ≤ δ

Composing g : α → β with an injective map emb : β → Query preserves any pointwise probability upper bound ∀ b, (μ.map g) b ≤ δ.

Adaptive random-oracle programming hop #

noncomputable def Cslib.RandomOracle.lazyProgramHandler {Req Query Digest Log : Type} {Reply Coins : Req → Type} [BEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) (q : Req ⊕ Query) :
StateT (List (Query × Digest) × Log) PMF (OracleSpec.sum Reply (fun (x : Query) => Digest) q)

Two-channel handler on List (Query × Digest) × Log whose active .inl req calls sample ts ← samplePre req, query the lazy random oracle memoize (fun _ => dist) at point req ts for c, and return finish req ts c; .inr q calls query memoize (fun _ => dist) q.

noncomputable def Cslib.RandomOracle.overwriteProgramHandler {Req Query Digest Log : Type} {Reply Coins : Req → Type} (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) [BEq Query] (q : Req ⊕ Query) :
StateT (List (Query × Digest) × Log) PMF (OracleSpec.sum Reply (fun (x : Query) => Digest) q)

Two-channel programmable-ROM handler matching lazyProgramHandler except that active .inl req calls draw a fresh c ← dist and overwrite (point req ts, c) at the front of cache without checking for an existing entry.

noncomputable def Cslib.RandomOracle.flaggedLazyProgramHandler {Req Query Digest Log : Type} {Reply Coins : Req → Type} [BEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) (q : Req ⊕ Query) :
StateT ((List (Query × Digest) × Log) × Bool) PMF (OracleSpec.sum Reply (fun (x : Query) => Digest) q)

Flagged version of lazyProgramHandler latching FlagBad whenever an active .inl req call samples a point point req ts already present in cache.

noncomputable def Cslib.RandomOracle.flaggedOverwriteProgramHandler {Req Query Digest Log : Type} {Reply Coins : Req → Type} [BEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) (q : Req ⊕ Query) :
StateT ((List (Query × Digest) × Log) × Bool) PMF (OracleSpec.sum Reply (fun (x : Query) => Digest) q)

Flagged version of overwriteProgramHandler latching FlagBad whenever an active .inl req call overwrites a point point req ts already present in cache.

theorem Cslib.RandomOracle.flaggedLazyProgramHandler_apply_inl {Req Query Digest Log : Type} {Reply Coins : Req → Type} [BEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) (req : Req) (cache : List (Query × Digest)) (log : Log) (b : Bool) :
flaggedLazyProgramHandler dist active inactive samplePre point finish (Sum.inl req) ((cache, log), b) = if h : active req = true then (samplePre req).bind fun (ts : Coins req) => PMF.map (fun (res : Digest × List (Query × Digest)) => ((finish req ts res.1 log).1, (res.2, (finish req ts res.1 log).2), b || (List.lookup (point req ts) cache).isSome)) (memoize (fun (x : Query) => dist) (point req ts) cache) else PMF.map (fun (res : Reply req × Log) => (res.1, (cache, res.2), b)) (inactive req ⋯ log)

Explicit .inl transition equation for flaggedLazyProgramHandler.

theorem Cslib.RandomOracle.flaggedLazyProgramHandler_apply_inr {Req Query Digest Log : Type} {Reply Coins : Req → Type} [BEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) (q : Query) (cache : List (Query × Digest)) (log : Log) (b : Bool) :
flaggedLazyProgramHandler dist active inactive samplePre point finish (Sum.inr q) ((cache, log), b) = PMF.map (fun (res : Digest × List (Query × Digest)) => (res.1, (res.2, log), b)) (memoize (fun (x : Query) => dist) q cache)

Explicit .inr transition equation for flaggedLazyProgramHandler.

theorem Cslib.RandomOracle.identicalUntilBad_flaggedProgramHandlers {Req Query Digest Log : Type} {Reply Coins : Req → Type} [BEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) :
OracleComp.IdenticalUntilBad (flaggedLazyProgramHandler dist active inactive samplePre point finish) (flaggedOverwriteProgramHandler dist active inactive samplePre point finish) OracleComp.FlagBad

flaggedLazyProgramHandler and flaggedOverwriteProgramHandler agree until FlagBad.

theorem Cslib.RandomOracle.run_flaggedLazyProgramHandler_map_fst {Req Query Digest Log α : Type} {Reply Coins : Req → Type} [BEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) (program : OracleComp (OracleSpec.sum Reply fun (x : Query) => Digest) α) (st : List (Query × Digest) × Log) (b : Bool) :
PMF.map (Prod.map id Prod.fst) ((OracleComp.interpret (flaggedLazyProgramHandler dist active inactive samplePre point finish) program).run (st, b)) = (OracleComp.interpret (lazyProgramHandler dist active inactive samplePre point finish) program).run st

Dropping FlagBad on flaggedLazyProgramHandler recovers lazyProgramHandler.

theorem Cslib.RandomOracle.run_flaggedOverwriteProgramHandler_map_fst {Req Query Digest Log α : Type} {Reply Coins : Req → Type} [BEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) (program : OracleComp (OracleSpec.sum Reply fun (x : Query) => Digest) α) (st : List (Query × Digest) × Log) (b : Bool) :
PMF.map (Prod.map id Prod.fst) ((OracleComp.interpret (flaggedOverwriteProgramHandler dist active inactive samplePre point finish) program).run (st, b)) = (OracleComp.interpret (overwriteProgramHandler dist active inactive samplePre point finish) program).run st

Dropping FlagBad on flaggedOverwriteProgramHandler recovers overwriteProgramHandler.

theorem Cslib.RandomOracle.toOuterMeasure_bad_flaggedLazyProgramHandler_choose_two_le {Req Query Digest Log α : Type} {Reply Coins : Req → Type} [BEq Query] [LawfulBEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) {δ : ENNReal} (hminEnt : ∀ (req : Req), active req = true → ∀ (q : Query), (PMF.map (point req) (samplePre req)) q ≤ δ) {program : OracleComp (OracleSpec.sum Reply fun (x : Query) => Digest) α} {q_S q_H : ℕ} (hqS : OracleComp.IsCostBounded (Sum.elim (fun (x : Req) => 1) fun (x : Query) => 0) program q_S) (hqH : OracleComp.IsCostBounded (Sum.elim (fun (x : Req) => 0) fun (x : Query) => 1) program q_H) (cache : List (Query × Digest)) (log : Log) :
((OracleComp.interpret (flaggedLazyProgramHandler dist active inactive samplePre point finish) program).run ((cache, log), false)).toOuterMeasure {x : α × (List (Query × Digest) × Log) × Bool | OracleComp.FlagBad x.2} ≤ ↑(q_S * cache.length + q_S * q_H + q_S.choose 2) * δ

Sharpened adaptive RO programming collision bound (OracleComp): for a program making at most q_S .inl calls and q_H .inr random-oracle calls from (cache, log), the probability that an active .inl call hits an already-cached point is at most (q_S * cache.length + q_S * q_H + q_S.choose 2) * δ.

theorem Cslib.RandomOracle.toOuterMeasure_bad_flaggedLazyProgramHandler_le {Req Query Digest Log α : Type} {Reply Coins : Req → Type} [BEq Query] [LawfulBEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) {δ : ENNReal} (hminEnt : ∀ (req : Req), active req = true → ∀ (q : Query), (PMF.map (point req) (samplePre req)) q ≤ δ) {program : OracleComp (OracleSpec.sum Reply fun (x : Query) => Digest) α} {q_S q_H : ℕ} (hqS : OracleComp.IsCostBounded (Sum.elim (fun (x : Req) => 1) fun (x : Query) => 0) program q_S) (hqH : OracleComp.IsCostBounded (Sum.elim (fun (x : Req) => 0) fun (x : Query) => 1) program q_H) (cache : List (Query × Digest)) (log : Log) :
((OracleComp.interpret (flaggedLazyProgramHandler dist active inactive samplePre point finish) program).run ((cache, log), false)).toOuterMeasure {x : α × (List (Query × Digest) × Log) × Bool | OracleComp.FlagBad x.2} ≤ ↑(q_S * (cache.length + q_S + q_H)) * δ

Rectangular adaptive RO programming collision bound (OracleComp): corollary of toOuterMeasure_bad_flaggedLazyProgramHandler_choose_two_le bounding the collision probability from (cache, log) by (q_S * (cache.length + q_S + q_H)) * δ.

theorem Cslib.RandomOracle.closeTo_run_lazyProgramHandler_overwriteProgramHandler_choose_two {Req Query Digest Log α : Type} {Reply Coins : Req → Type} [BEq Query] [LawfulBEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) {δ : ENNReal} (hminEnt : ∀ (req : Req), active req = true → ∀ (q : Query), (PMF.map (point req) (samplePre req)) q ≤ δ) {program : OracleComp (OracleSpec.sum Reply fun (x : Query) => Digest) α} {q_S q_H : ℕ} (hqS : OracleComp.IsCostBounded (Sum.elim (fun (x : Req) => 1) fun (x : Query) => 0) program q_S) (hqH : OracleComp.IsCostBounded (Sum.elim (fun (x : Req) => 0) fun (x : Query) => 1) program q_H) (cache : List (Query × Digest)) (log : Log) :
Probability.CloseTo ((OracleComp.interpret (lazyProgramHandler dist active inactive samplePre point finish) program).run (cache, log)) ((OracleComp.interpret (overwriteProgramHandler dist active inactive samplePre point finish) program).run (cache, log)) (↑(q_S * cache.length + q_S * q_H + q_S.choose 2) * δ)

Sharpened adaptive RO programming CloseTo hop (OracleComp): replacing lazy oracle reads at point req ts with fresh overwrites changes the joint (α × (List (Query × Digest) × Log)) distribution by at most (q_S * cache.length + q_S * q_H + q_S.choose 2) * δ.

theorem Cslib.RandomOracle.closeTo_run_lazyProgramHandler_overwriteProgramHandler {Req Query Digest Log α : Type} {Reply Coins : Req → Type} [BEq Query] [LawfulBEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) {δ : ENNReal} (hminEnt : ∀ (req : Req), active req = true → ∀ (q : Query), (PMF.map (point req) (samplePre req)) q ≤ δ) {program : OracleComp (OracleSpec.sum Reply fun (x : Query) => Digest) α} {q_S q_H : ℕ} (hqS : OracleComp.IsCostBounded (Sum.elim (fun (x : Req) => 1) fun (x : Query) => 0) program q_S) (hqH : OracleComp.IsCostBounded (Sum.elim (fun (x : Req) => 0) fun (x : Query) => 1) program q_H) (cache : List (Query × Digest)) (log : Log) :
Probability.CloseTo ((OracleComp.interpret (lazyProgramHandler dist active inactive samplePre point finish) program).run (cache, log)) ((OracleComp.interpret (overwriteProgramHandler dist active inactive samplePre point finish) program).run (cache, log)) (↑(q_S * (cache.length + q_S + q_H)) * δ)

Rectangular adaptive RO programming CloseTo hop (OracleComp): replacing lazy oracle reads with fresh overwrites from (cache, log) changes the joint result-and-state distribution by at most (q_S * (cache.length + q_S + q_H)) * δ.

theorem Cslib.RandomOracle.closeTo_run_lazyProgramHandler_overwriteProgramHandler_of_isQueryBounded {Req Query Digest Log α : Type} {Reply Coins : Req → Type} [BEq Query] [LawfulBEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) {δ : ENNReal} (hminEnt : ∀ (req : Req), active req = true → ∀ (q : Query), (PMF.map (point req) (samplePre req)) q ≤ δ) {program : OracleComp (OracleSpec.sum Reply fun (x : Query) => Digest) α} {q_S Q : ℕ} (hqS : OracleComp.IsCostBounded (Sum.elim (fun (x : Req) => 1) fun (x : Query) => 0) program q_S) (hQ : program.IsQueryBounded Q) (cache : List (Query × Digest)) (log : Log) :
Probability.CloseTo ((OracleComp.interpret (lazyProgramHandler dist active inactive samplePre point finish) program).run (cache, log)) ((OracleComp.interpret (overwriteProgramHandler dist active inactive samplePre point finish) program).run (cache, log)) (↑(q_S * (cache.length + Q)) * δ)

Total-query adaptive RO programming CloseTo hop (OracleComp): when a program makes at most q_S .inl calls and Q calls in total (IsQueryBounded program Q), lazy and fresh-overwrite executions from (cache, log) are within (q_S * (cache.length + Q)) * δ.

theorem Cslib.RandomOracle.closeTo_runWith_lazyProgramHandler_overwriteProgramHandler_choose_two {Req Query Digest Log α : Type} {Reply Coins : Req → Type} [BEq Query] [LawfulBEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) {δ : ENNReal} (hminEnt : ∀ (req : Req), active req = true → ∀ (q : Query), (PMF.map (point req) (samplePre req)) q ≤ δ) {program : ProbOracleComp (OracleSpec.sum Reply fun (x : Query) => Digest) α} {q_S q_H : ℕ} (hqS : OracleComp.IsCostBounded (Sum.elim (fun (x : ℕ) => 0) (Sum.elim (fun (x : Req) => 1) fun (x : Query) => 0)) program q_S) (hqH : OracleComp.IsCostBounded (Sum.elim (fun (x : ℕ) => 0) (Sum.elim (fun (x : Req) => 0) fun (x : Query) => 1)) program q_H) (cache : List (Query × Digest)) (log : Log) :
Probability.CloseTo (ProbOracleComp.runWith (lazyProgramHandler dist active inactive samplePre point finish) program (cache, log)) (ProbOracleComp.runWith (overwriteProgramHandler dist active inactive samplePre point finish) program (cache, log)) (↑(q_S * cache.length + q_S * q_H + q_S.choose 2) * δ)

Sharpened adaptive RO programming CloseTo hop (ProbOracleComp.runWith): lifts closeTo_run_lazyProgramHandler_overwriteProgramHandler_choose_two to adversaries with private randomness.

theorem Cslib.RandomOracle.closeTo_runWith_lazyProgramHandler_overwriteProgramHandler {Req Query Digest Log α : Type} {Reply Coins : Req → Type} [BEq Query] [LawfulBEq Query] (dist : PMF Digest) (active : Req → Bool) (inactive : (req : Req) → active req = false → Log → PMF (Reply req × Log)) (samplePre : (req : Req) → PMF (Coins req)) (point : (req : Req) → Coins req → Query) (finish : (req : Req) → Coins req → Digest → Log → Reply req × Log) {δ : ENNReal} (hminEnt : ∀ (req : Req), active req = true → ∀ (q : Query), (PMF.map (point req) (samplePre req)) q ≤ δ) {program : ProbOracleComp (OracleSpec.sum Reply fun (x : Query) => Digest) α} {q_S q_H : ℕ} (hqS : OracleComp.IsCostBounded (Sum.elim (fun (x : ℕ) => 0) (Sum.elim (fun (x : Req) => 1) fun (x : Query) => 0)) program q_S) (hqH : OracleComp.IsCostBounded (Sum.elim (fun (x : ℕ) => 0) (Sum.elim (fun (x : Req) => 0) fun (x : Query) => 1)) program q_H) (cache : List (Query × Digest)) (log : Log) :
Probability.CloseTo (ProbOracleComp.runWith (lazyProgramHandler dist active inactive samplePre point finish) program (cache, log)) (ProbOracleComp.runWith (overwriteProgramHandler dist active inactive samplePre point finish) program (cache, log)) (↑(q_S * (cache.length + q_S + q_H)) * δ)

Rectangular adaptive RO programming CloseTo hop (ProbOracleComp.runWith): corollary giving the (q_S * (cache.length + q_S + q_H)) * δ bound.

Random-function output-collision birthday bounds #

def Cslib.RandomOracle.HasOutputCollision {Query : Type u_1} {Digest : Type u_2} (cache : List (Query × Digest)) :

A random-oracle association-list cache contains an output collision when two entries with distinct keys map to the same digest.

theorem Cslib.RandomOracle.nodup_fst_of_mem_support_run_memoize {Query Digest α : Type} [BEq Query] [LawfulBEq Query] (distribution : Query → PMF Digest) (program : OracleComp (fun (x : Query) => Digest) α) {cache cache' : List (Query × Digest)} (hcache : (List.map Prod.fst cache).Nodup) {result : α} (hmem : (result, cache') ∈ ((OracleComp.interpret (memoize distribution) program).run cache).support) :

memoize preserves key distinctness (cache.map Prod.fst).Nodup across every adaptive execution, because cache hits reuse existing entries without prepending a duplicate key.

theorem Cslib.RandomOracle.hasOutputCollision_iff_not_nodup_snd {Query : Type u_1} {Digest : Type u_2} {cache : List (Query × Digest)} (hfst : (List.map Prod.fst cache).Nodup) :

On any cache with distinct keys ((cache.map Prod.fst).Nodup), HasOutputCollision cache is equivalent to ¬(cache.map Prod.snd).Nodup.

theorem Cslib.RandomOracle.toOuterMeasure_not_nodup_snd_memoize_le {Query Digest α : Type} [BEq Query] (dist : PMF Digest) {δ : ENNReal} (hdist : ∀ (y : Digest), dist y ≤ δ) {program : OracleComp (fun (x : Query) => Digest) α} {q : ℕ} (hq : program.IsQueryBounded q) {cache : List (Query × Digest)} (hcache : (List.map Prod.snd cache).Nodup) :
((OracleComp.interpret (memoize fun (x : Query) => dist) program).run cache).toOuterMeasure {x : α × List (Query × Digest) | ¬(List.map Prod.snd x.2).Nodup} ≤ ↑(q * cache.length + q.choose 2) * δ

Min-entropy random-oracle output-collision bound (OracleComp): if ∀ y, dist y ≤ δ and program makes at most q queries starting from cache with (cache.map Prod.snd).Nodup, then ¬(cache'.map Prod.snd).Nodup occurs with probability at most (q * cache.length + q.choose 2) * δ.

theorem Cslib.RandomOracle.toOuterMeasure_not_nodup_snd_runWith_memoize_le {Query Digest α : Type} [BEq Query] (dist : PMF Digest) {δ : ENNReal} (hdist : ∀ (y : Digest), dist y ≤ δ) {program : ProbOracleComp (fun (x : Query) => Digest) α} {q : ℕ} (hq : program.IsQueryBounded q) {cache : List (Query × Digest)} (hcache : (List.map Prod.snd cache).Nodup) :
(ProbOracleComp.runWith (memoize fun (x : Query) => dist) program cache).toOuterMeasure {x : α × List (Query × Digest) | ¬(List.map Prod.snd x.2).Nodup} ≤ ↑(q * cache.length + q.choose 2) * δ

Min-entropy random-oracle output-collision bound (ProbOracleComp.runWith): lifts toOuterMeasure_not_nodup_snd_memoize_le to adversaries with private randomness.

theorem Cslib.RandomOracle.toOuterMeasure_collision_memoize_uniform_le {Query Digest α : Type} [BEq Query] [Fintype Digest] [Nonempty Digest] {program : OracleComp (fun (x : Query) => Digest) α} {q : ℕ} (hq : program.IsQueryBounded q) :
((OracleComp.interpret (memoize fun (x : Query) => Probability.PMF.uniformOfFintype Digest) program).run []).toOuterMeasure {x : α × List (Query × Digest) | ¬(List.map Prod.snd x.2).Nodup} ≤ ↑(q.choose 2) / ↑(Fintype.card Digest)

Random-oracle birthday bound (OracleComp, Nodup form): a q-query adaptive program against memoize (fun _ => PMF.uniformOfFintype Digest) starting from [] produces duplicate stored digests with probability at most q.choose 2 / Fintype.card Digest.

theorem Cslib.RandomOracle.toOuterMeasure_collision_runWith_memoize_uniform_le {Query Digest α : Type} [BEq Query] [Fintype Digest] [Nonempty Digest] {program : ProbOracleComp (fun (x : Query) => Digest) α} {q : ℕ} (hq : program.IsQueryBounded q) :
(ProbOracleComp.runWith (memoize fun (x : Query) => Probability.PMF.uniformOfFintype Digest) program []).toOuterMeasure {x : α × List (Query × Digest) | ¬(List.map Prod.snd x.2).Nodup} ≤ ↑(q.choose 2) / ↑(Fintype.card Digest)

Random-oracle birthday bound (ProbOracleComp.runWith, Nodup form): a q-query adaptive randomized program against memoize (fun _ => PMF.uniformOfFintype Digest) starting from [] produces duplicate stored digests with probability at most q.choose 2 / Fintype.card Digest.

theorem Cslib.RandomOracle.toOuterMeasure_hasOutputCollision_memoize_uniform_le {Query Digest α : Type} [BEq Query] [LawfulBEq Query] [Fintype Digest] [Nonempty Digest] {program : OracleComp (fun (x : Query) => Digest) α} {q : ℕ} (hq : program.IsQueryBounded q) :
((OracleComp.interpret (memoize fun (x : Query) => Probability.PMF.uniformOfFintype Digest) program).run []).toOuterMeasure {x : α × List (Query × Digest) | HasOutputCollision x.2} ≤ ↑(q.choose 2) / ↑(Fintype.card Digest)

Random-oracle birthday bound (OracleComp, distinct-key HasOutputCollision form): a q-query adaptive program against memoize (fun _ => PMF.uniformOfFintype Digest) from [] observes two distinct queried keys with the same digest with probability at most q.choose 2 / Fintype.card Digest.

theorem Cslib.RandomOracle.toOuterMeasure_hasOutputCollision_runWith_memoize_uniform_le {Query Digest α : Type} [BEq Query] [LawfulBEq Query] [Fintype Digest] [Nonempty Digest] {program : ProbOracleComp (fun (x : Query) => Digest) α} {q : ℕ} (hq : program.IsQueryBounded q) :
(ProbOracleComp.runWith (memoize fun (x : Query) => Probability.PMF.uniformOfFintype Digest) program []).toOuterMeasure {x : α × List (Query × Digest) | HasOutputCollision x.2} ≤ ↑(q.choose 2) / ↑(Fintype.card Digest)

Random-oracle birthday bound (ProbOracleComp.runWith, distinct-key HasOutputCollision form): a q-query adaptive randomized program against memoize (fun _ => PMF.uniformOfFintype Digest) from [] observes two distinct queried keys with the same digest with probability at most q.choose 2 / Fintype.card Digest.