Documentation

CslibFrontier.Languages.Probabilistic.RandomOracle.Sum

Random-oracle caches on a sum of interfaces #

Several independent lazy random oracles are one lazy random oracle on the sum of their interfaces, answered by OracleComp.sumHandler. RandomOracle.Cache.sum joins one cache per side into a cache of the joined interface, and a lazy call on one side of a joined cache is a lazy call on that side's cache (answer_sum_inl, answer_sum_inr). A game that keeps one cache per oracle can therefore be read as one represented lazy oracle.

A protocol in the random-oracle model often queries two independent oracles, such as a Merkle hash and a Fiat–Shamir challenge oracle. RandomOracle.memoizeSum answers the calls of spec₁ ⊕ₒ spec₂ by memoizing each side in its own association list, so that a soundness proof can reason about the two lists separately. It implements the lazy random oracle answer (sumHandler dist₁ dist₂) on the joined cache of the two lists (run_interpret_memoizeSum). A program over one side touches only that side's list (run_interpret_memoizeSum_liftLeft), and properties of each list preserved by single memoized calls hold after every run (mem_support_run_interpret_memoizeSum).

Main definitions #

Main results #

def Cslib.RandomOracle.Cache.sum {ι₁ ι₂ : Type u} {spec₁ : OracleSpec ι₁} {spec₂ : OracleSpec ι₂} (c₁ : Cache spec₁) (c₂ : Cache spec₂) :
Cache (spec₁.sum spec₂)

The cache of the joined interface spec₁ ⊕ₒ spec₂: left queries read c₁, right queries read c₂.

@[simp]
theorem Cslib.RandomOracle.Cache.sum_inl {ι₁ ι₂ : Type u} {spec₁ : OracleSpec ι₁} {spec₂ : OracleSpec ι₂} (c₁ : Cache spec₁) (c₂ : Cache spec₂) (q : ι₁) :
c₁.sum c₂ (Sum.inl q) = c₁ q
@[simp]
theorem Cslib.RandomOracle.Cache.sum_inr {ι₁ ι₂ : Type u} {spec₁ : OracleSpec ι₁} {spec₂ : OracleSpec ι₂} (c₁ : Cache spec₁) (c₂ : Cache spec₂) (q : ι₂) :
c₁.sum c₂ (Sum.inr q) = c₂ q
instance Cslib.RandomOracle.instFiniteSum {ι₁ ι₂ : Type u} {spec₁ : OracleSpec ι₁} {spec₂ : OracleSpec ι₂} [∀ (q : ι₁), Finite (spec₁ q)] [∀ (q : ι₂), Finite (spec₂ q)] (q : ι₁ ⊕ ι₂) :
Finite (spec₁.sum spec₂ q)

The responses of a joined interface are finite when both sides' responses are.

theorem Cslib.RandomOracle.Cache.update_sum_inl {ι₁ ι₂ : Type u} {spec₁ : OracleSpec ι₁} {spec₂ : OracleSpec ι₂} [DecidableEq ι₁] [DecidableEq ι₂] (c₁ : Cache spec₁) (c₂ : Cache spec₂) (q : ι₁) (v : spec₁ q) :
Function.update (c₁.sum c₂) (Sum.inl q) (some v) = sum (Function.update c₁ q (some v)) c₂

Recording a left answer in a joined cache records it in the left cache.

theorem Cslib.RandomOracle.Cache.update_sum_inr {ι₁ ι₂ : Type u} {spec₁ : OracleSpec ι₁} {spec₂ : OracleSpec ι₂} [DecidableEq ι₁] [DecidableEq ι₂] (c₁ : Cache spec₁) (c₂ : Cache spec₂) (q : ι₂) (v : spec₂ q) :
Function.update (c₁.sum c₂) (Sum.inr q) (some v) = c₁.sum (Function.update c₂ q (some v))

Recording a right answer in a joined cache records it in the right cache.

theorem Cslib.RandomOracle.answer_sum_inl {ι₁ ι₂ : Type u} {spec₁ : OracleSpec ι₁} {spec₂ : OracleSpec ι₂} [DecidableEq ι₁] [DecidableEq ι₂] (d₁ : (q : ι₁) → PMF (spec₁ q)) (d₂ : (q : ι₂) → PMF (spec₂ q)) (c₁ : Cache spec₁) (c₂ : Cache spec₂) (q : ι₁) :
answer (OracleComp.sumHandler d₁ d₂) (Sum.inl q) (c₁.sum c₂) = PMF.map (fun (z : spec₁ q × Cache spec₁) => (z.1, z.2.sum c₂)) (answer d₁ q c₁)

A lazy call on the left side of a joined cache is a lazy call on the left cache.

theorem Cslib.RandomOracle.answer_sum_inr {ι₁ ι₂ : Type u} {spec₁ : OracleSpec ι₁} {spec₂ : OracleSpec ι₂} [DecidableEq ι₁] [DecidableEq ι₂] (d₁ : (q : ι₁) → PMF (spec₁ q)) (d₂ : (q : ι₂) → PMF (spec₂ q)) (c₁ : Cache spec₁) (c₂ : Cache spec₂) (q : ι₂) :
answer (OracleComp.sumHandler d₁ d₂) (Sum.inr q) (c₁.sum c₂) = PMF.map (fun (z : spec₂ q × Cache spec₂) => (z.1, c₁.sum z.2)) (answer d₂ q c₂)

A lazy call on the right side of a joined cache is a lazy call on the right cache.

Two lazy random oracles memoized in two lists #

noncomputable def Cslib.RandomOracle.memoizeSum {ι₁ ι₂ R₁ R₂ : Type} [BEq ι₁] [BEq ι₂] (dist₁ : ι₁ → PMF R₁) (dist₂ : ι₂ → PMF R₂) (q : ι₁ ⊕ ι₂) :
StateT (List (ι₁ × R₁) × List (ι₂ × R₂)) PMF (OracleSpec.sum (fun (x : ι₁) => R₁) (fun (x : ι₂) => R₂) q)

Answer the calls of (fun _ => R₁) ⊕ₒ (fun _ => R₂) by memoizing the left calls in the first list, sampling from dist₁, and the right calls in the second, sampling from dist₂.

theorem Cslib.RandomOracle.memoizeSum_inl {ι₁ ι₂ R₁ R₂ : Type} [BEq ι₁] [BEq ι₂] (dist₁ : ι₁ → PMF R₁) (dist₂ : ι₂ → PMF R₂) (q : ι₁) (tr₁ : List (ι₁ × R₁)) (tr₂ : List (ι₂ × R₂)) :
memoizeSum dist₁ dist₂ (Sum.inl q) (tr₁, tr₂) = PMF.map (fun (x : R₁ × List (ι₁ × R₁)) => match x with | (ans, tr₁') => (ans, tr₁', tr₂)) (memoize dist₁ q tr₁)

A left call memoizes on the first list and leaves the second unchanged.

theorem Cslib.RandomOracle.memoizeSum_inr {ι₁ ι₂ R₁ R₂ : Type} [BEq ι₁] [BEq ι₂] (dist₁ : ι₁ → PMF R₁) (dist₂ : ι₂ → PMF R₂) (q : ι₂) (tr₁ : List (ι₁ × R₁)) (tr₂ : List (ι₂ × R₂)) :
memoizeSum dist₁ dist₂ (Sum.inr q) (tr₁, tr₂) = PMF.map (fun (x : R₂ × List (ι₂ × R₂)) => match x with | (ans, tr₂') => (ans, tr₁, tr₂')) (memoize dist₂ q tr₂)

A right call memoizes on the second list and leaves the first unchanged.

theorem Cslib.RandomOracle.mem_support_memoizeSum_inl {ι₁ ι₂ R₁ R₂ : Type} [BEq ι₁] [BEq ι₂] {dist₁ : ι₁ → PMF R₁} {dist₂ : ι₂ → PMF R₂} {q : ι₁} {tr₁ : List (ι₁ × R₁)} {tr₂ : List (ι₂ × R₂)} {ans : R₁} {st' : List (ι₁ × R₁) × List (ι₂ × R₂)} :
(ans, st') ∈ (memoizeSum dist₁ dist₂ (Sum.inl q) (tr₁, tr₂)).support ↔ ∃ (tr₁' : List (ι₁ × R₁)), (ans, tr₁') ∈ (memoize dist₁ q tr₁).support ∧ st' = (tr₁', tr₂)

The supported outcomes of a left call are those of memoize dist₁ on the first list, with the second list unchanged.

theorem Cslib.RandomOracle.mem_support_memoizeSum_inr {ι₁ ι₂ R₁ R₂ : Type} [BEq ι₁] [BEq ι₂] {dist₁ : ι₁ → PMF R₁} {dist₂ : ι₂ → PMF R₂} {q : ι₂} {tr₁ : List (ι₁ × R₁)} {tr₂ : List (ι₂ × R₂)} {ans : R₂} {st' : List (ι₁ × R₁) × List (ι₂ × R₂)} :
(ans, st') ∈ (memoizeSum dist₁ dist₂ (Sum.inr q) (tr₁, tr₂)).support ↔ ∃ (tr₂' : List (ι₂ × R₂)), (ans, tr₂') ∈ (memoize dist₂ q tr₂).support ∧ st' = (tr₁, tr₂')

The supported outcomes of a right call are those of memoize dist₂ on the second list, with the first list unchanged.

theorem Cslib.RandomOracle.run_interpret_memoizeSum_liftLeft {ι₁ ι₂ R₁ R₂ : Type} [BEq ι₁] [BEq ι₂] (dist₁ : ι₁ → PMF R₁) (dist₂ : ι₂ → PMF R₂) {β : Type} (prog : OracleComp (fun (x : ι₁) => R₁) β) (tr₁ : List (ι₁ × R₁)) (tr₂ : List (ι₂ × R₂)) :
(OracleComp.interpret (memoizeSum dist₁ dist₂) prog.liftLeft).run (tr₁, tr₂) = PMF.map (fun (x : β × List (ι₁ × R₁)) => match x with | (res, tr₁') => (res, tr₁', tr₂)) ((OracleComp.interpret (memoize dist₁) prog).run tr₁)

Running a left program under memoizeSum runs it under memoize dist₁ on the first list and leaves the second list unchanged.

theorem Cslib.RandomOracle.run_interpret_memoizeSum_liftRight {ι₁ ι₂ R₁ R₂ : Type} [BEq ι₁] [BEq ι₂] (dist₁ : ι₁ → PMF R₁) (dist₂ : ι₂ → PMF R₂) {β : Type} (prog : OracleComp (fun (x : ι₂) => R₂) β) (tr₁ : List (ι₁ × R₁)) (tr₂ : List (ι₂ × R₂)) :
(OracleComp.interpret (memoizeSum dist₁ dist₂) prog.liftRight).run (tr₁, tr₂) = PMF.map (fun (x : β × List (ι₂ × R₂)) => match x with | (res, tr₂') => (res, tr₁, tr₂')) ((OracleComp.interpret (memoize dist₂) prog).run tr₂)

Running a right program under memoizeSum runs it under memoize dist₂ on the second list and leaves the first list unchanged.

theorem Cslib.RandomOracle.mem_support_run_interpret_memoizeSum {ι₁ ι₂ R₁ R₂ : Type} [BEq ι₁] [BEq ι₂] (dist₁ : ι₁ → PMF R₁) (dist₂ : ι₂ → PMF R₂) (P₁ : List (ι₁ × R₁) → Prop) (P₂ : List (ι₂ × R₂) → Prop) (h₁ : ∀ (q : ι₁) (tr tr' : List (ι₁ × R₁)) (ans : R₁), P₁ tr → (ans, tr') ∈ (memoize dist₁ q tr).support → P₁ tr') (h₂ : ∀ (q : ι₂) (tr tr' : List (ι₂ × R₂)) (ans : R₂), P₂ tr → (ans, tr') ∈ (memoize dist₂ q tr).support → P₂ tr') {β : Type} (prog : OracleComp (OracleSpec.sum (fun (x : ι₁) => R₁) fun (x : ι₂) => R₂) β) {st st' : List (ι₁ × R₁) × List (ι₂ × R₂)} {res : β} (hst : P₁ st.1 ∧ P₂ st.2) (hmem : (res, st') ∈ ((OracleComp.interpret (memoizeSum dist₁ dist₂) prog).run st).support) :
P₁ st'.1 ∧ P₂ st'.2

If single memoized calls preserve a property P₁ of the first list and a property P₂ of the second, then every supported run of memoizeSum preserves both.

theorem Cslib.RandomOracle.run_interpret_memoizeSum {ι₁ ι₂ R₁ R₂ : Type} [BEq ι₁] [BEq ι₂] [LawfulBEq ι₁] [LawfulBEq ι₂] [DecidableEq ι₁] [DecidableEq ι₂] (dist₁ : ι₁ → PMF R₁) (dist₂ : ι₂ → PMF R₂) {β : Type} (prog : OracleComp (OracleSpec.sum (fun (x : ι₁) => R₁) fun (x : ι₂) => R₂) β) (st : List (ι₁ × R₁) × List (ι₂ × R₂)) :
PMF.map (fun (x : β × List (ι₁ × R₁) × List (ι₂ × R₂)) => match x with | (res, st') => (res, (ofList st'.1).sum (ofList st'.2))) ((OracleComp.interpret (memoizeSum dist₁ dist₂) prog).run st) = OracleComp.runWith (answer (OracleComp.sumHandler dist₁ dist₂)) prog ((ofList st.1).sum (ofList st.2))

memoizeSum dist₁ dist₂ implements the lazy random oracle answer (sumHandler dist₁ dist₂) on the joined cache of its two lists, preserving the result and represented final cache of every adaptive program.

theorem Cslib.RandomOracle.map_fst_run_interpret_memoizeSum_nil {ι₁ ι₂ R₁ R₂ : Type} [BEq ι₁] [BEq ι₂] [LawfulBEq ι₁] [LawfulBEq ι₂] [DecidableEq ι₁] [DecidableEq ι₂] (dist₁ : ι₁ → PMF R₁) (dist₂ : ι₂ → PMF R₂) {β : Type} (prog : OracleComp (OracleSpec.sum (fun (x : ι₁) => R₁) fun (x : ι₂) => R₂) β) :
PMF.map Prod.fst ((OracleComp.interpret (memoizeSum dist₁ dist₂) prog).run ([], [])) = PMF.map Prod.fst (OracleComp.runWith (answer (OracleComp.sumHandler dist₁ dist₂)) prog fun (x : ι₁ ⊕ ι₂) => none)

From two empty lists, memoizeSum dist₁ dist₂ has the output distribution of the lazy random oracle answer (sumHandler dist₁ dist₂) started from the empty cache.