Documentation

CslibFrontier.Languages.Probabilistic.Oracle.RunState

Running an oracle program against a stateful or logging oracle #

A.runState O runs A : ProbOracleComp spec α against a stateful oracle O: each private sample is a fresh uniform draw, and each external query q runs O q, a program that reads and updates the oracle's state. The result is a StateT program, so (A.runState O).run s is the closed sampler that starts the oracle in state s and returns the result with the final state.

A.runLog O runs A against the oracle O and records every query with its reply, oldest first. This is the challenger of a forgery experiment, which later checks a forgery against the log of signing or tagging queries. A.runLogWith O lets the oracle read the log so far and refuse a query: O log q = none answers default and records nothing, as a one-time signing oracle does after its first query. A memoryless oracle O gives runLogWith fun _ q => some (O q), which is runLog O.

On every supported run, a program with at most n queries leaves a log of length at most n. This is the instance, for the log length, of a general bound: if each query raises a measure of the oracle state by at most its cost, a run raises it by at most the program's cost budget.

Main definitions #

Main results #

Stateful oracles #

def Cslib.ProbOracleComp.runState {Query α σ : Type} {spec : Query → Type} (A : ProbOracleComp spec α) (O : (q : Query) → StateT σ ProbComp (spec q)) :

Run A with fresh uniform private coins, answering each external query q with the stateful program O q.

@[simp]
theorem Cslib.ProbOracleComp.runState_pure {Query α σ : Type} {spec : Query → Type} (a : α) (O : (q : Query) → StateT σ ProbComp (spec q)) :

Returning a value makes no call, draws no coins and keeps the state.

@[simp]
theorem Cslib.ProbOracleComp.runState_bind {Query α β σ : Type} {spec : Query → Type} (A : ProbOracleComp spec α) (next : α → ProbOracleComp spec β) (O : (q : Query) → StateT σ ProbComp (spec q)) :
(A >>= next).runState O = do let a ← A.runState O (next a).runState O

A sequenced program runs its first part, then the continuation from the state it reached.

@[simp]
theorem Cslib.ProbOracleComp.runState_map {Query α β σ : Type} {spec : Query → Type} (f : α → β) (A : ProbOracleComp spec α) (O : (q : Query) → StateT σ ProbComp (spec q)) :
(f <$> A).runState O = f <$> A.runState O

Deterministic postprocessing commutes with running.

@[simp]
theorem Cslib.ProbOracleComp.runState_query {Query σ : Type} {spec : Query → Type} (q : Query) (O : (q : Query) → StateT σ ProbComp (spec q)) :
(query q).runState O = O q

A single external query is answered by the oracle from the current state.

@[simp]
theorem Cslib.ProbOracleComp.runState_sample {Query α σ : Type} {spec : Query → Type} (program : ProbComp α) (O : (q : Query) → StateT σ ProbComp (spec q)) :
(sample program).runState O = StateT.lift program

A private sample is the sampled program, and it keeps the state.

theorem Cslib.ProbOracleComp.eval_runState {Query α σ : Type} {spec : Query → Type} (A : ProbOracleComp spec α) (O : (q : Query) → StateT σ ProbComp (spec q)) (s : σ) :
((A.runState O).run s).eval = runWith (fun (q : Query) (state : σ) => (O q state).eval) A s

The law of a stateful run is runWith against the evaluated oracle.

theorem Cslib.ProbOracleComp.runState_lift {Query α σ : Type} {spec : Query → Type} (A : ProbOracleComp spec α) (O : (q : Query) → ProbComp (spec q)) (s : σ) :
(A.runState fun (q : Query) => StateT.lift (O q)).run s = (fun (x : α) => (x, s)) <$> A.run O

Against a memoryless oracle, the stateful run is run, and the state is unchanged.

theorem Cslib.ProbOracleComp.measure_runState_le {Query α σ : Type} {spec : Query → Type} {cost : Query → ℕ} {A : ProbOracleComp spec α} {n : ℕ} (h : OracleComp.IsCostBounded (Sum.elim (fun (x : ℕ) => 0) cost) A n) (O : (q : Query) → StateT σ ProbComp (spec q)) (μ : σ → ℕ) (hstep : ∀ (q : Query) (s : σ), ∀ z ∈ ((O q).run s).eval.support, μ z.2 ≤ μ s + cost q) (s : σ) (z : α × σ) :
z ∈ ((A.runState O).run s).eval.support → μ z.2 ≤ μ s + n

If each query q raises the measure μ of the oracle state by at most cost q, a run of a program whose queries cost at most n raises it by at most n. Private samples keep the state. This is OracleComp.IsCostBounded.measure_le for the handler of runState.

Logging oracles #

def Cslib.ProbOracleComp.logOracle {Q R : Type} [Inhabited R] (O : List (Q × R) → Q → Option (ProbComp R)) (q : Q) :

The logging oracle of runLogWith: answer q with O log q and append (q, reply) to the log, or answer default and keep the log when O log q = none.

@[simp]
theorem Cslib.ProbOracleComp.logOracle_run {Q R : Type} [Inhabited R] (O : List (Q × R) → Q → Option (ProbComp R)) (q : Q) (log : List (Q × R)) :
(logOracle O q).run log = match O log q with | some reply => (fun (r : R) => (r, log ++ [(q, r)])) <$> reply | none => pure (default, log)

One call of the logging oracle runs O log q and appends the answered pair, or answers default and keeps the log when O log q = none.

def Cslib.ProbOracleComp.runLogWith {α Q R : Type} [Inhabited R] (A : ProbOracleComp (fun (x : Q) => R) α) (O : List (Q × R) → Q → Option (ProbComp R)) :
ProbComp (α × List (Q × R))

Run A against an oracle that reads the log so far, returning the result and the log of answered queries with their replies, oldest first. A refused query (O log q = none) is answered with default and not logged.

def Cslib.ProbOracleComp.runLog {α Q R : Type} (A : ProbOracleComp (fun (x : Q) => R) α) (O : Q → ProbComp R) :
ProbComp (α × List (Q × R))

Run A against the oracle O, returning the result and the log of its queries with their replies, oldest first.

@[simp]
theorem Cslib.ProbOracleComp.runLog_sample {α Q R : Type} (p : ProbComp α) (O : Q → ProbComp R) :
(sample p).runLog O = (fun (a : α) => (a, [])) <$> p

A program that only samples asks nothing: its log is empty.

theorem Cslib.ProbOracleComp.runLogWith_some {α Q R : Type} [Inhabited R] (A : ProbOracleComp (fun (x : Q) => R) α) (O : Q → ProbComp R) :
(A.runLogWith fun (x : List (Q × R)) (q : Q) => some (O q)) = A.runLog O

An oracle that never refuses and ignores the log is runLog.

theorem Cslib.ProbOracleComp.runLogWith_map {α β Q R : Type} [Inhabited R] (f : α → β) (A : ProbOracleComp (fun (x : Q) => R) α) (O : List (Q × R) → Q → Option (ProbComp R)) :

Mapping the program's result maps the result of the logged run and keeps the log.

theorem Cslib.ProbOracleComp.IsQueryBounded.length_runLogWith_le {α Q R : Type} [Inhabited R] {A : ProbOracleComp (fun (x : Q) => R) α} {n : ℕ} (h : A.IsQueryBounded n) (O : List (Q × R) → Q → Option (ProbComp R)) (z : α × List (Q × R)) :
z ∈ (A.runLogWith O).eval.support → z.2.length ≤ n

On every supported run, a program with at most n queries leaves a log of length at most n.

theorem Cslib.ProbOracleComp.IsQueryBounded.length_runLog_le {α Q R : Type} {A : ProbOracleComp (fun (x : Q) => R) α} {n : ℕ} (h : A.IsQueryBounded n) (O : Q → ProbComp R) (z : α × List (Q × R)) :
z ∈ (A.runLog O).eval.support → z.2.length ≤ n

On every supported run, a program with at most n queries leaves a log of length at most n.

theorem Cslib.ProbOracleComp.forall_mem_runLogWith {α Q R : Type} [Inhabited R] {O : List (Q × R) → Q → Option (ProbComp R)} {P : Q × R → Prop} (hO : ∀ (log : List (Q × R)) (q : Q) (program : ProbComp R), O log q = some program → ∀ r ∈ program.eval.support, P (q, r)) (A : ProbOracleComp (fun (x : Q) => R) α) {z : α × List (Q × R)} (hz : z ∈ (A.runLogWith O).eval.support) (p : Q × R) :
p ∈ z.2 → P p

Every logged pair is a possible reply: a property of query-reply pairs that holds for every reply of every program the oracle runs holds for every pair in the log of runLogWith.

theorem Cslib.ProbOracleComp.forall_mem_runLog {Q R α : Type} {O : Q → ProbComp R} {P : Q × R → Prop} (hO : ∀ (q : Q), ∀ r ∈ (O q).eval.support, P (q, r)) (A : ProbOracleComp (fun (x : Q) => R) α) {z : α × List (Q × R)} (hz : z ∈ (A.runLog O).eval.support) (p : Q × R) :
p ∈ z.2 → P p

Every logged pair is a possible reply: a property of query-reply pairs that holds for every reply of a memoryless oracle O holds for every pair in the log of runLog.