Documentation

GaudisCrypt.Logic.Fel

EasyCrypt's fel (the failure event lemma), once #

EC's

fel init cntr step q bad [O₁: pre₁, …] inv

bounds the probability of a failure event bad after an abstract module's run by ∑_{i ∈ [init, q)} step i: each oracle call that may set bad (its preᵢ holds) does so with probability at most step cntr and increases the counter cntr; the other calls leave bad and cntr alone; inv holds throughout.

Here the same premises, for the oracles of Module.app D O with D abstract, give the bound, by Module.ewp_app_le (the supermartingale abstract call) on one potential, felPotential, once for all games: ⊤ off the invariant, 1 once bad holds, else the bound still to pay, ∑_{i ∈ [cntr, q)} step i. The state the premises talk about is the view L.get g of the globals through a lens L that D does not touch (the counter, the variables of bad and inv).

Deviation from EC: bad must persist (FelOracle.keep), where EC's conclusion is about bad at the end however it got there; the events of the SHA-3 games are monotone. The premises are Hoare and pHL judgments about the oracle procedures, proven with the usual tactics.

theorem GaudisCrypt.Procedure.ewp_mono_of_hoare {sig : ProcedureSignature} {A : sig.ParamType → VariableAssignment → Prop} {p : Procedure sig} {B : sig.ret → VariableAssignment → Prop} (h : hoareProc A p B) {args : sig.ParamType} {σ : VariableAssignment} (hA : A args σ) {F G : sig.ret → VariableAssignment → ENNReal} (hFG : ∀ (v : sig.ret) (g : VariableAssignment), B v g → F v g ≤ G v g) :
p.ewp args F σ ≤ p.ewp args G σ

A procedure's expectation is monotone in the function on the outcomes a Hoare triple allows.

noncomputable def GaudisCrypt.felPotential {Ω : Type} (cntr : Ω → ℤ) (step : ℤ → ENNReal) (q : ℤ) (bad inv : Ω → Prop) (s : Ω) :

The potential of EC's fel: ⊤ off the invariant, 1 once bad holds, else the bound still to pay for the calls from cntr to q.

Equations
Instances For
    structure GaudisCrypt.FelOracle {Ω : Type} (L : Lens Ω VariableAssignment) (cntr : Ω → ℤ) (step : ℤ → ENNReal) (q : ℤ) (bad inv : Ω → Prop) {sig : ProcedureSignature} (pre : Ω → Prop) (p : Procedure sig) :

    The premises of EC's fel for one oracle procedure p with precondition pre (the calls that may set bad), over the view L.get of the globals.

    Instances For
      theorem GaudisCrypt.felPotential_sum_anti {step : ℤ → ENNReal} {q c c' : ℤ} (h : c ≤ c') :
      ∑ i ∈ Finset.Ico c' q, step i ≤ ∑ i ∈ Finset.Ico c q, step i

      The sum still to pay shrinks as the counter grows.

      theorem GaudisCrypt.FelOracle.ewp_le {Ω : Type} {L : Lens Ω VariableAssignment} {cntr : Ω → ℤ} {step : ℤ → ENNReal} {q : ℤ} {bad inv : Ω → Prop} {sig : ProcedureSignature} {pre : Ω → Prop} {p : Procedure sig} (h : FelOracle L cntr step q bad inv pre p) (a : sig.ParamType) (g : VariableAssignment) :
      p.ewp a (fun (x : sig.ret) (g' : VariableAssignment) => felPotential cntr step q bad inv (L.get g')) g ≤ felPotential cntr step q bad inv (L.get g)

      The step of the potential: an oracle call with fel's premises does not increase the potential in expectation.

      theorem GaudisCrypt.Module.fel {Ω : Type} {L : Lens Ω VariableAssignment} {cntr : Ω → ℤ} {step : ℤ → ENNReal} {q : ℤ} {bad inv : Ω → Prop} {T : Type 1} [IsModule T] {sig : ProcedureSignature} {holes : HoleSigs} (D : Arr T (Proc sig)) (ext : T → holes.Instantiation) (hD : Representable D ext) (hdisj : FVP.fvP D ≤ L.footprintᶜ) (hc : ∀ {sig' : ProcedureSignature} (a : HoleIndex holes sig'), Countable sig'.ParamType) (O : T) (pre : {sig' : ProcedureSignature} → HoleIndex holes sig' → Ω → Prop) (horacle : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), FelOracle L cntr step q bad inv (pre n) ((ext O).lookup n)) (a : sig.ParamType) (g : VariableAssignment) (hi : inv (L.get g)) (hb : ¬bad (L.get g)) :
      (app D O).procedure.ewp a (fun (x : sig.ret) (g' : VariableAssignment) => indicatorE (bad (L.get g'))) g ≤ ∑ i ∈ Finset.Ico (cntr (L.get g)) q, step i

      EC's fel, for an abstract module: if every oracle satisfies fel's premises (FelOracle), then D applied to the oracles, started where inv holds and bad does not, ends in bad with probability at most ∑_{i ∈ [cntr, q)} step i (Module.ewp_app_le on felPotential).

      theorem GaudisCrypt.Module.hoare_app_inv {Ω : Type} {L : Lens Ω VariableAssignment} {T : Type 1} [IsModule T] {sig : ProcedureSignature} {holes : HoleSigs} (D : Arr T (Proc sig)) (ext : T → holes.Instantiation) (hD : Representable D ext) (hdisj : FVP.fvP D ≤ L.footprintᶜ) (hc : ∀ {sig' : ProcedureSignature} (a : HoleIndex holes sig'), Countable sig'.ParamType) (O : T) (I : Ω → Prop) (horacle : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), hoareProc (fun (x : sig'.ParamType) (g : VariableAssignment) => I (L.get g)) ((ext O).lookup n) fun (x : sig'.ret) (g' : VariableAssignment) => I (L.get g')) :
      hoareProc (fun (x : sig.ParamType) (g : VariableAssignment) => I (L.get g)) (app D O).procedure fun (x : sig.ret) (g' : VariableAssignment) => I (L.get g')

      EC's call (: inv) on an abstract module, for Hoare triples: if every oracle keeps the invariant I of the view L.get, so does D applied to them (Module.ewp_app_le on the indicator of ¬ I: 0 from where I holds, which the oracles keep).

      A statement about every oracle of a single-oracle module type: the one oracle.

      theorem GaudisCrypt.phoareStmt_fel {Ω : Type} {L : Lens Ω VariableAssignment} {cntr : Ω → ℤ} {step : ℤ → ENNReal} {q : ℤ} {bad inv : Ω → Prop} {T : Type 1} [IsModule T] {sig : ProcedureSignature} {holes : HoleSigs} (D : Module.Arr T (Module.Proc sig)) (ext : T → holes.Instantiation) (hD : Module.Representable D ext) (hdisj : FVP.fvP D ≤ L.footprintᶜ) (hc : ∀ {sig' : ProcedureSignature} (a : HoleIndex holes sig'), Countable sig'.ParamType) (O : T) (pre : {sig' : ProcedureSignature} → HoleIndex holes sig' → Ω → Prop) (horacle : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), FelOracle L cntr step q bad inv (pre n) ((ext O).lookup n)) {A : ProgramState → Prop} {s₀ : Stmt} {x : Setter sig.ret ProgramState} {e : Getter sig.ParamType ProgramState} {r : ENNReal} (hx : ∀ (v : sig.ret) (τ : ProgramState), L.get (x.set v τ).globals = L.get τ.globals) (hinit : hoareStmt A s₀ fun (τ : ProgramState) => inv (L.get τ.globals) ∧ ¬bad (L.get τ.globals) ∧ cntr (L.get τ.globals) = 0) (hsum : ∑ i ∈ Finset.Ico 0 q, step i ≤ r) :
      phoareStmt A (StmtWithHoles.seq s₀ (Stmt.call x (Module.app D O).procedure e)) (fun (τ : ProgramState) => indicatorE (bad (L.get τ.globals))) LE.le fun (x : ProgramState) => r

      EC's fel on a statement: if s₀ establishes the invariant, ¬ bad and cntr = 0, then after s₀; x <- call D(O) (D abstract, its oracles with fel's premises, the result x outside the view L) bad holds with probability at most ∑_{i ∈ [0, q)} step i, and so at most any r above it. The tactic fel (Logic/FelTactic.lean) applies it.

      theorem GaudisCrypt.hoareStmt_call_inv {Ω : Type} {L : Lens Ω VariableAssignment} {T : Type 1} [IsModule T] {sig : ProcedureSignature} {holes : HoleSigs} (D : Module.Arr T (Module.Proc sig)) (ext : T → holes.Instantiation) (hD : Module.Representable D ext) (hdisj : FVP.fvP D ≤ L.footprintᶜ) (hc : ∀ {sig' : ProcedureSignature} (a : HoleIndex holes sig'), Countable sig'.ParamType) (O : T) (I : Ω → Prop) (horacle : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), hoareProc (fun (x : sig'.ParamType) (g : VariableAssignment) => I (L.get g)) ((ext O).lookup n) fun (x : sig'.ret) (g' : VariableAssignment) => I (L.get g')) {A B : ProgramState → Prop} {s₀ : Stmt} {x : Setter sig.ret ProgramState} {e : Getter sig.ParamType ProgramState} (hpre : hoareStmt A s₀ fun (σ : ProgramState) => I (L.get σ.globals) ∧ ∀ (r : sig.ret) (g : VariableAssignment), I (L.get g) → B (x.set r (ProgramState.globalL.set g σ))) :

      EC's call (: inv) on an abstract module, for a Hoare triple about a statement: if the oracles keep inv (of the view L), then before x <- call D(O) it suffices that inv holds and that every result and globals keeping it give B.