Documentation

CslibFrontier.Crypto.Protocols.UC.Machine

Interactive machines with private coins #

An interactive machine M : UC.Machine I E is a stateful probabilistic program that exports the interface E and imports the interface I. It samples an initial private state with M.init, and each activation M.handle q answers one query q of E: it may draw private coins, call I, and update its state. Activations are ProbOracleComp I programs, so a machine is a program in the sense of CslibFrontier/Languages/Probabilistic/Semantics.lean, not a distribution. A machine importing OracleSpec.empty is closed.

These machines are the parties, protocols, ideal functionalities, adversaries and simulators of the universal-composability (UC) execution in CslibFrontier.Crypto.Protocols.UC.Execution. Their composition follows the package algebra of state-separating proofs: Machine.comp A P answers each query of A by running A's activation with its imported calls answered by P, and Machine.link M Z runs a program Z over E with its calls answered by M, which removes the interface E.

A budget M.IsBounded t says that the initial sampler and every activation make at most t calls on every path, counting private samples and calls to I alike (OracleComp.IsQueryBounded). As everywhere in this library, a call budget bounds interaction, not running time: pure computation between calls, message sizes and state growth are free.

Main definitions #

Main results #

References #

structure Cslib.Crypto.Protocols.UC.Machine {ιI ιE : Type} (I : ιI → Type) (E : ιE → Type) :

An interactive machine exporting the interface E and importing the interface I: a private state sampled by init, and for each query q of E an activation that answers it with private coins, calls to I and an updated state.

def Cslib.Crypto.Protocols.UC.Machine.handler {ιI ιE : Type} {I : ιI → Type} {E : ιE → Type} (M : Machine I E) (q : ℕ ⊕ ιE) :

The stateful handler for programs calling M: private samples of the program stay private samples, and calls to the exported interface run M's activations.

def Cslib.Crypto.Protocols.UC.Machine.runFrom {ιI ιE : Type} {I : ιI → Type} {E : ιE → Type} {α : Type} (M : Machine I E) (program : ProbOracleComp E α) (s : M.State) :

Run a program over E against M from the state s, returning its result and M's final state.

def Cslib.Crypto.Protocols.UC.Machine.comp {ιI ιJ ιE : Type} {I : ιI → Type} {J : ιJ → Type} {E : ιE → Type} (A : Machine J E) (P : Machine I J) :

Sequential composition: A.comp P answers a query of A's exported interface by running A's activation, whose calls to the interface J are answered by P. The imported machine P is initialized first, as when a program is linked against A and the result against P.

def Cslib.Crypto.Protocols.UC.Machine.id {ιE : Type} (E : ιE → Type) :

The stateless machine forwarding every query of E to its imported copy of E.

A program with private coins and no external calls, as a closed probabilistic program.

def Cslib.Crypto.Protocols.UC.Machine.run {ιE : Type} {E : ιE → Type} {α : Type} (M : Machine OracleSpec.empty E) (program : ProbOracleComp E α) :

The closed probabilistic program of a program over E run against the closed machine M.

Running programs against machines #

@[simp]
theorem Cslib.Crypto.Protocols.UC.Machine.runFrom_pure {ιI ιE : Type} {I : ιI → Type} {E : ιE → Type} {α : Type} (M : Machine I E) (a : α) (s : M.State) :
M.runFrom (pure a) s = pure (a, s)

A returned value makes no call and leaves the machine's state unchanged.

@[simp]
theorem Cslib.Crypto.Protocols.UC.Machine.runFrom_bind {ιI ιE : Type} {I : ιI → Type} {E : ιE → Type} {α β : Type} (M : Machine I E) (program : ProbOracleComp E α) (next : α → ProbOracleComp E β) (s : M.State) :
M.runFrom (program >>= next) s = do let x ← M.runFrom program s M.runFrom (next x.1) x.2

Sequencing runs the second program from the state the first one reached.

@[simp]
theorem Cslib.Crypto.Protocols.UC.Machine.runFrom_map {ιI ιE : Type} {I : ιI → Type} {E : ιE → Type} {α β : Type} (M : Machine I E) (f : α → β) (program : ProbOracleComp E α) (s : M.State) :
M.runFrom (f <$> program) s = Prod.map f _root_.id <$> M.runFrom program s

Postprocessing the result keeps the machine's final state.

@[simp]
theorem Cslib.Crypto.Protocols.UC.Machine.runFrom_query {ιI ιE : Type} {I : ιI → Type} {E : ιE → Type} (M : Machine I E) (q : ιE) (s : M.State) :

An exported call is one activation of the machine.

@[simp]
theorem Cslib.Crypto.Protocols.UC.Machine.runFrom_sample {ιI ιE : Type} {I : ιI → Type} {E : ιE → Type} {α : Type} (M : Machine I E) (program : ProbComp α) (s : M.State) :
M.runFrom (ProbOracleComp.sample program) s = (fun (a : α) => (a, s)) <$> ProbOracleComp.sample program

A private sample of the program stays a private sample and leaves the machine untouched.

@[simp]

Closing a returned value returns it.

@[simp]
theorem Cslib.Crypto.Protocols.UC.Machine.closeProgram_bind {α β : Type} (program : ProbOracleComp OracleSpec.empty α) (next : α → ProbOracleComp OracleSpec.empty β) :
closeProgram (program >>= next) = do let a ← closeProgram program closeProgram (next a)

Closing commutes with sequencing.

@[simp]
theorem Cslib.Crypto.Protocols.UC.Machine.closeProgram_map {α β : Type} (f : α → β) (program : ProbOracleComp OracleSpec.empty α) :
closeProgram (f <$> program) = f <$> closeProgram program

Closing commutes with postprocessing.

@[simp]

An embedded closed program is unchanged by closing.

Close an empty-spec probabilistic computation and return its PMF.

@[simp]

Closing a pure program yields PMF.pure.

@[simp]

Closing a bind distributes over PMF.bind.

@[simp]

Closing a mapped program maps the PMF.

@[simp]

Closing a sampled ProbComp evaluates it directly.

Support of closeEval (p >>= next).

theorem Cslib.Crypto.Protocols.UC.Machine.mem_support_closeEval_map {α β : Type} {f : α → β} {p : ProbOracleComp OracleSpec.empty α} {y : β} :
y ∈ (closeEval (f <$> p)).support ↔ ∃ a ∈ (closeEval p).support, f a = y

Support of closeEval (f <$> p).

theorem Cslib.Crypto.Protocols.UC.Machine.closeEval_bind_le {α β : Type} (p : ProbOracleComp OracleSpec.empty α) (f g : α → ProbOracleComp OracleSpec.empty β) (y : β) (h : ∀ (a : α), (closeEval (f a)) y ≤ (closeEval (g a)) y) :
(closeEval (p >>= f)) y ≤ (closeEval (p >>= g)) y

Pointwise monotonicity of closeEval across a shared prefix p.

theorem Cslib.Crypto.Protocols.UC.Machine.mem_support_closeEval_runFrom_invariant {ιE : Type} {E : ιE → Type} {α : Type} (M : Machine OracleSpec.empty E) (Inv : ιE → Prop) (R : M.State → M.State → Prop) (hR_refl : ∀ (s : M.State), R s s) (hR_trans : ∀ {a b c : M.State}, R a b → R b c → R a c) (prog : ProbOracleComp E α) (hinv : OracleComp.QueriesSatisfy (Sum.elim (fun (x : ℕ) => True) Inv) prog) (s : M.State) {x : α × M.State} (hx : x ∈ (closeEval (M.runFrom prog s)).support) (hstep : ∀ (q : ιE) (s' : M.State) {y : E q × M.State}, Inv q → y ∈ (closeEval ((M.handle q).run s')).support → R s' y.2) :
R s x.2

Support invariant for closeEval (M.runFrom prog s) under a reflexive, transitive state relation preserved by every allowed machine query.

State-intertwining for runFrom #

theorem Cslib.Crypto.Protocols.UC.Machine.runFrom_interpret_intertwine {ιI : Type} {I : ιI → Type} {α ι₁ ι₂ ι β : Type} {E₁ : ι₁ → Type} {E₂ : ι₂ → Type} {O : ι → Type} (M₁ : Machine I E₁) (M₂ : Machine I E₂) (h₁ : (q : ι) → ProbOracleComp E₁ (O q)) (h₂ : (q : ι) → ProbOracleComp E₂ (O q)) (Inv : ι → Prop) (R : M₁.State → M₂.State → Prop) (prog : ProbOracleComp O α) (hinv : OracleComp.QueriesSatisfy (Sum.elim (fun (x : ℕ) => True) Inv) prog) (s₁ : M₁.State) (s₂ : M₂.State) (hR : R s₁ s₂) (f : α × M₁.State → ProbOracleComp I β) (g : α × M₂.State → ProbOracleComp I β) (hfg : ∀ (a : α) (s₁' : M₁.State) (s₂' : M₂.State), R s₁' s₂' → f (a, s₁') = g (a, s₂')) (hstep : ∀ (q : ι) (s₁' : M₁.State) (s₂' : M₂.State) (k₁ : O q × M₁.State → ProbOracleComp I β) (k₂ : O q × M₂.State → ProbOracleComp I β), Inv q → R s₁' s₂' → (∀ (r : O q) (s₁'' : M₁.State) (s₂'' : M₂.State), R s₁'' s₂'' → k₁ (r, s₁'') = k₂ (r, s₂'')) → M₁.runFrom (h₁ q) s₁' >>= k₁ = M₂.runFrom (h₂ q) s₂' >>= k₂) :
M₁.runFrom (OracleComp.interpret (OracleComp.sumHandler (fun (k : ℕ) => OracleComp.query (Sum.inl k)) h₁) prog) s₁ >>= f = M₂.runFrom (OracleComp.interpret (OracleComp.sumHandler (fun (k : ℕ) => OracleComp.query (Sum.inl k)) h₂) prog) s₂ >>= g

Two machines M₁ and M₂ sharing an imported interface I, a state invariant R, and a query invariant Inv produce related post-run continuations when translating an O-program via h₁ and h₂ preserves R at each Inv-satisfying query.

theorem Cslib.Crypto.Protocols.UC.Machine.runFrom_intertwine {ιI ιE : Type} {I : ιI → Type} {E : ιE → Type} {α β : Type} (M₁ M₂ : Machine I E) (Inv : ιE → Prop) (R : M₁.State → M₂.State → Prop) (prog : ProbOracleComp E α) (hinv : OracleComp.QueriesSatisfy (Sum.elim (fun (x : ℕ) => True) Inv) prog) (s₁ : M₁.State) (s₂ : M₂.State) (hR : R s₁ s₂) (f : α × M₁.State → ProbOracleComp I β) (g : α × M₂.State → ProbOracleComp I β) (hfg : ∀ (a : α) (s₁' : M₁.State) (s₂' : M₂.State), R s₁' s₂' → f (a, s₁') = g (a, s₂')) (hstep : ∀ (q : ιE) (s₁' : M₁.State) (s₂' : M₂.State) (k₁ : E q × M₁.State → ProbOracleComp I β) (k₂ : E q × M₂.State → ProbOracleComp I β), Inv q → R s₁' s₂' → (∀ (r : E q) (s₁'' : M₁.State) (s₂'' : M₂.State), R s₁'' s₂'' → k₁ (r, s₁'') = k₂ (r, s₂'')) → (M₁.handle q).run s₁' >>= k₁ = (M₂.handle q).run s₂' >>= k₂) :
M₁.runFrom prog s₁ >>= f = M₂.runFrom prog s₂ >>= g

Direct (uninterpreted) state-intertwining specialization of Machine.runFrom_interpret_intertwine for two machines sharing an exported interface E.

theorem Cslib.Crypto.Protocols.UC.Machine.runFrom_interpret_stripNoop {ιI ιE : Type} {I : ιI → Type} {E : ιE → Type} {α : Type} (M : Machine I E) (strip : (q : ιE) → ProbOracleComp E (E q)) (hstrip : ∀ (q : ιE) (s : M.State), M.runFrom (strip q) s = (M.handle q).run s) (prog : ProbOracleComp E α) (s : M.State) :

Interpreting a program through a handler strip whose runs from every state agree with M.handle leaves M.runFrom unchanged.

theorem Cslib.Crypto.Protocols.UC.Machine.run_interpret_stripNoop {ιE : Type} {E : ιE → Type} {α : Type} (M : Machine OracleSpec.empty E) (strip : (q : ιE) → ProbOracleComp E (E q)) (hstrip : ∀ (q : ιE) (s : M.State), M.runFrom (strip q) s = (M.handle q).run s) (prog : ProbOracleComp E α) :
M.run (OracleComp.interpret (OracleComp.sumHandler (fun (k : ℕ) => OracleComp.query (Sum.inl k)) strip) prog) = M.run prog

Interpreting a program through a handler strip whose runs from every state agree with M.handle (for instance, replacing state-preserving pure no-op queries with pure) leaves M.run unchanged.

theorem Cslib.Crypto.Protocols.UC.Machine.closeEval_runFrom_interpret_le_intertwine {α ι₁ ι₂ ι β : Type} {E₁ : ι₁ → Type} {E₂ : ι₂ → Type} {O : ι → Type} (M₁ : Machine OracleSpec.empty E₁) (M₂ : Machine OracleSpec.empty E₂) (h₁ : (q : ι) → ProbOracleComp E₁ (O q)) (h₂ : (q : ι) → ProbOracleComp E₂ (O q)) (Inv : ι → Prop) (R : M₁.State → M₂.State → Prop) (Trap : M₁.State → Prop) (prog : ProbOracleComp O α) (hinv : OracleComp.QueriesSatisfy (Sum.elim (fun (x : ℕ) => True) Inv) prog) (s₁ : M₁.State) (s₂ : M₂.State) (hR : R s₁ s₂) (f : α × M₁.State → ProbOracleComp OracleSpec.empty β) (g : α × M₂.State → ProbOracleComp OracleSpec.empty β) (y : β) (hfg : ∀ (a : α) (s₁' : M₁.State) (s₂' : M₂.State), R s₁' s₂' → (closeEval (f (a, s₁'))) y ≤ (closeEval (g (a, s₂'))) y) (htrap_f : ∀ (a : α) (s₁' : M₁.State), Trap s₁' → (closeEval (f (a, s₁'))) y = 0) (htrap_step : ∀ (q : ι) (s₁' : M₁.State) {z : O q × M₁.State}, Inv q → Trap s₁' → z ∈ (closeEval (M₁.runFrom (h₁ q) s₁')).support → Trap z.2) (hstep : ∀ (q : ι) (s₁' : M₁.State) (s₂' : M₂.State) (k₁ : O q × M₁.State → ProbOracleComp OracleSpec.empty β) (k₂ : O q × M₂.State → ProbOracleComp OracleSpec.empty β), Inv q → R s₁' s₂' → (∀ (r : O q) (s₁'' : M₁.State) (s₂'' : M₂.State), R s₁'' s₂'' → (closeEval (k₁ (r, s₁''))) y ≤ (closeEval (k₂ (r, s₂''))) y) → (∀ (r : O q) (s₁'' : M₁.State), Trap s₁'' → (closeEval (k₁ (r, s₁''))) y = 0) → (closeEval (M₁.runFrom (h₁ q) s₁' >>= k₁)) y ≤ (closeEval (M₂.runFrom (h₂ q) s₂' >>= k₂)) y) :
(closeEval (M₁.runFrom (OracleComp.interpret (OracleComp.sumHandler (fun (k : ℕ) => OracleComp.query (Sum.inl k)) h₁) prog) s₁ >>= f)) y ≤ (closeEval (M₂.runFrom (OracleComp.interpret (OracleComp.sumHandler (fun (k : ℕ) => OracleComp.query (Sum.inl k)) h₂) prog) s₂ >>= g)) y

Sub-probability (clamped) state-intertwining for closeEval: two closed machines M₁ and M₂ sharing a state relation R, an absorbing trap predicate Trap on M₁ where f assigns zero mass to y, and a query invariant Inv satisfy the pointwise PMF bound at y whenever each Inv-satisfying query preserves the bound across R or lands in Trap.

theorem Cslib.Crypto.Protocols.UC.Machine.closeEval_runFrom_le_intertwine {ιE : Type} {E : ιE → Type} {α β : Type} (M₁ M₂ : Machine OracleSpec.empty E) (Inv : ιE → Prop) (R : M₁.State → M₂.State → Prop) (Trap : M₁.State → Prop) (prog : ProbOracleComp E α) (hinv : OracleComp.QueriesSatisfy (Sum.elim (fun (x : ℕ) => True) Inv) prog) (s₁ : M₁.State) (s₂ : M₂.State) (hR : R s₁ s₂) (f : α × M₁.State → ProbOracleComp OracleSpec.empty β) (g : α × M₂.State → ProbOracleComp OracleSpec.empty β) (y : β) (hfg : ∀ (a : α) (s₁' : M₁.State) (s₂' : M₂.State), R s₁' s₂' → (closeEval (f (a, s₁'))) y ≤ (closeEval (g (a, s₂'))) y) (htrap_f : ∀ (a : α) (s₁' : M₁.State), Trap s₁' → (closeEval (f (a, s₁'))) y = 0) (htrap_step : ∀ (q : ιE) (s₁' : M₁.State) {z : E q × M₁.State}, Inv q → Trap s₁' → z ∈ (closeEval ((M₁.handle q).run s₁')).support → Trap z.2) (hstep : ∀ (q : ιE) (s₁' : M₁.State) (s₂' : M₂.State) (k₁ : E q × M₁.State → ProbOracleComp OracleSpec.empty β) (k₂ : E q × M₂.State → ProbOracleComp OracleSpec.empty β), Inv q → R s₁' s₂' → (∀ (r : E q) (s₁'' : M₁.State) (s₂'' : M₂.State), R s₁'' s₂'' → (closeEval (k₁ (r, s₁''))) y ≤ (closeEval (k₂ (r, s₂''))) y) → (∀ (r : E q) (s₁'' : M₁.State), Trap s₁'' → (closeEval (k₁ (r, s₁''))) y = 0) → (closeEval ((M₁.handle q).run s₁' >>= k₁)) y ≤ (closeEval ((M₂.handle q).run s₂' >>= k₂)) y) :
(closeEval (M₁.runFrom prog s₁ >>= f)) y ≤ (closeEval (M₂.runFrom prog s₂ >>= g)) y

Direct (uninterpreted) specialization of Machine.closeEval_runFrom_interpret_le_intertwine for two closed machines sharing an exported interface E.

def Cslib.Crypto.Protocols.UC.Machine.IsBounded {ιI ιE : Type} {I : ιI → Type} {E : ιE → Type} (M : Machine I E) (t : ℕ) :

The per-activation call budget t: the initial sampler and every activation, from every state, make at most t calls on every path. Private samples and imported calls both count.

theorem Cslib.Crypto.Protocols.UC.Machine.IsBounded.mono {ιI ιE : Type} {I : ιI → Type} {E : ιE → Type} {M : Machine I E} {t t' : ℕ} (h : M.IsBounded t) (htt' : t ≤ t') :

A larger budget is still a budget.

The forwarding machine makes one call per activation and none at initialization.

Closing a program with no external imports preserves its query budget.