Documentation

GaudisCrypt.Logic.ExpectationFrame

The syntactic frame for expectations: concrete supermartingales #

EasyCrypt's fel bounds a bad event through the oracles: each call increases the potential (the bad event plus what remains to be paid) by at most nothing in expectation. For a concrete oracle that changes the potential's state only through a few sampling procedures (Gcol.sample_c), the step lemma of those procedures is all that matters: every other write keeps the state.

StmtWithHoles.ExpDecr G φ s says that of s: each write keeps G of the globals, and each call either is to a procedure that does not increase φ ∘ G in expectation or has a body of which ExpDecr holds again. Stmt.ewp_le_of_expDecr concludes that s does not increase φ ∘ G (loops with φ ∘ G as the invariant). The tactic exp_decr reduces an ExpDecr goal to the single writes as writes_keep does, closing a call by a step lemma from the context when one applies.

def GaudisCrypt.StmtWithHoles.ExpDecr {β : Type u_1} (G : VariableAssignment → β) (φ : β → ENNReal) {h : HoleSigs} :

Each write of the statement keeps G of the globals, and each call either is to a procedure that does not increase φ ∘ G in expectation or satisfies ExpDecr itself.

Equations
Instances For
    theorem GaudisCrypt.Procedure.ewp_eq_body {sig : ProcedureSignature} (p : Procedure sig) (a : sig.ParamType) (F : VariableAssignment → ENNReal) (g : VariableAssignment) :
    p.ewp a (fun (x : sig.ret) (g' : VariableAssignment) => F g') g = Stmt.ewp p.body (fun (τ : ProgramState) => F τ.globals) { globals := g, locals := ProcedureWithHoles.initLocals p a }

    A procedure's expectation, as its body's from the initial locals.

    theorem GaudisCrypt.Stmt.ewp_le_of_expDecr {β : Type u_1} (G : VariableAssignment → β) (φ : β → ENNReal) (s : Stmt) :
    StmtWithHoles.ExpDecr G φ s → ∀ (σ : ProgramState), s.ewp (fun (τ : ProgramState) => φ (G τ.globals)) σ ≤ φ (G σ.globals)

    The syntactic frame for expectations: a statement satisfying ExpDecr G φ does not increase the expectation of φ ∘ G.

    theorem GaudisCrypt.Procedure.ewp_le_of_expDecr {sig : ProcedureSignature} {β : Type u_1} (G : VariableAssignment → β) (φ : β → ENNReal) (p : Procedure sig) (hp : StmtWithHoles.ExpDecr G φ p.body) (a : sig.ParamType) (g : VariableAssignment) :
    p.ewp a (fun (x : sig.ret) (g' : VariableAssignment) => φ (G g')) g ≤ φ (G g)

    Stmt.ewp_le_of_expDecr for a procedure.

    Split a goal StmtWithHoles.ExpDecr G φ s down to its single writes, as stmtPredSplit does for WritesKeep; at a call, first try to close the step-lemma alternative by a hypothesis.

    Close ∀ v σ, L.get ((x.set v σ).globals) = L.get σ.globals (a write to a global lens X) by touched_set_of_le_compl with a hypothesis X.footprint ≤ (L.footprint)ᶜ from the context, trying the hypotheses one by one (the written lens is only known once the term is elaborated).

    Equations
    Instances For

      exp_decr: on a goal StmtWithHoles.ExpDecr G φ s, the conditions on the single writes of s, callees included; a call is closed by a step lemma in the context when one matches. Writes to local variables are closed by rfl, writes to a global lens X (for G = L.get) by touched_set_of_le_compl with a hypothesis X.footprint ≤ (L.footprint)ᶜ from the context (exp_decr_write).

      Equations
      Instances For