Documentation

GaudisCrypt.Logic.ECConseqFrame

EasyCrypt's conseq keeps what the code does not modify #

EC's conseq (_: P' ==> Q') on c₁ ~ c₂ : P ==> Q asks P => P' and forall &1 &2, P => forall (modified variables), Q' => Q: the variables the code does not write keep their values from the precondition. Here that is a frame on each side (prhlStmt_conseq_frame): the variables Q reads whose writes the code commutes with (Stmt.CommutesWith, shown as for stmt_swap; such code keeps them, Stmt.satisfies_keep) keep their values from the start, and the side goal is ∀ σ₁ σ₂, P σ₁ σ₂ → ∀ τ₁ τ₂, (frames) → Q' τ₁ τ₂ → Q τ₁ τ₂. equiv_conseq (: P ==> Q) on statements is this rule (Logic/ECConseq.lean).

theorem GaudisCrypt.Stmt.satisfies_keep {α : Type} (x : Lens α ProgramState) {s : Stmt} (h : ∀ (v : α), s.CommutesWith (x.set v)) (σ : ProgramState) :
(programDenotation s σ).satisfies fun (r : Unit × ProgramState) => x.get r.2 = x.get σ

A statement that commutes with every write to x keeps x.

s keeps x: every run ends with x as it started.

Equations
Instances For
    theorem GaudisCrypt.Stmt.Keeps.satisfies {α : Type} {x : Lens α ProgramState} {s : Stmt} (h : Keeps x s) (σ : ProgramState) :
    (programDenotation s σ).satisfies fun (r : Unit × ProgramState) => x.get r.2 = x.get σ
    theorem GaudisCrypt.Stmt.Keeps.skip {α : Type} {x : Lens α ProgramState} :
    Keeps x (GaudiProg[ skip; ])
    theorem GaudisCrypt.Stmt.Keeps.seq {α : Type} {x : Lens α ProgramState} {p q : Stmt} (hp : Keeps x p) (hq : Keeps x q) :
    Keeps x (GaudiProg[ stmt p; stmt q; ])
    theorem GaudisCrypt.Stmt.Keeps.ite {α : Type} {x : Lens α ProgramState} {b : Getter Bool ProgramState} {p q : Stmt} (hp : Keeps x p) (hq : Keeps x q) :
    Keeps x (GaudiProg[ if (§b) { stmt p; } else { stmt q; } ])
    theorem GaudisCrypt.Stmt.Keeps.while {α : Type} {x : Lens α ProgramState} {b : Getter Bool ProgramState} {body : Stmt} (h : Keeps x body) :
    Keeps x (GaudiProg[ while (§b) { stmt body; } ])
    theorem GaudisCrypt.Stmt.Keeps.assign {α : Type} {x : Lens α ProgramState} {β : Type} {y : Setter β ProgramState} {e : Getter β ProgramState} (hy : ∀ (v : β) (σ : ProgramState), x.get (y.set v σ) = x.get σ) :
    Keeps x (GaudiProg[ y <- §e; ])
    theorem GaudisCrypt.Stmt.Keeps.sample {α : Type} {x : Lens α ProgramState} {β : Type} {y : Setter β ProgramState} {e : Getter (SubProbability β) ProgramState} (hy : ∀ (v : β) (σ : ProgramState), x.get (y.set v σ) = x.get σ) :
    Keeps x (GaudiProg[ y <$ §e; ])
    theorem GaudisCrypt.Stmt.Keeps.call {α : Type} {x : Lens α ProgramState} {sig : ProcedureSignature} {y : Setter sig.ret ProgramState} {p : Procedure sig} {args : Getter sig.ParamType ProgramState} (hy : ∀ (r : sig.ret) (g : VariableAssignment) (σ : ProgramState), x.get (y.set r (ProgramState.globalL.set g σ)) = x.get σ) :
    Keeps x (GaudiProg[ y <- call p (§args); ])

    A call keeps what neither its result nor the globals it leaves hold (a local other than the result).

    theorem GaudisCrypt.Stmt.Keeps.call_frame {α : Type} {x : Lens α ProgramState} {sig : ProcedureSignature} {y : Setter sig.ret ProgramState} {p : Procedure sig} {args : Getter sig.ParamType ProgramState} {γ : Type} (L : Lens γ VariableAssignment) (hp : ∀ (a : sig.ParamType), (procedureDenotation p a).inFootprint L.footprintᶜ) (hy : ∀ (r : sig.ret) (g : VariableAssignment) (σ : ProgramState), L.get g = L.get σ.globals → x.get (y.set r (ProgramState.globalL.set g σ)) = x.get σ) :
    Keeps x (GaudiProg[ y <- call p (§args); ])

    A call keeps a global L outside the callee's footprint.

    theorem GaudisCrypt.Stmt.Keeps.call_global {sig : ProcedureSignature} {y : Setter sig.ret ProgramState} {p : Procedure sig} {args : Getter sig.ParamType ProgramState} {γ : Type} (L : Lens γ VariableAssignment) (hp : ∀ (a : sig.ParamType), (procedureDenotation p a).inFootprint L.footprintᶜ) (hy : ∀ (r : sig.ret) (σ : ProgramState), L.get (y.set r σ).globals = L.get σ.globals) :
    Keeps L.intoGlobal (GaudiProg[ y <- call p (§args); ])

    A call keeps a global L outside the callee's footprint, its result written elsewhere.

    theorem GaudisCrypt.Stmt.Keeps.call_writes {sig : ProcedureSignature} {y : Setter sig.ret ProgramState} {p : Procedure sig} {args : Getter sig.ParamType ProgramState} {γ : Type} (L : Lens γ VariableAssignment) (hp : StmtWithHoles.WritesKeep L.get p.body) (hy : ∀ (r : sig.ret) (σ : ProgramState), L.get (y.set r σ).globals = L.get σ.globals) :
    Keeps L.intoGlobal (GaudiProg[ y <- call p (§args); ])

    A call keeps a global L that every write of the callee keeps (EC's frame by writes: a callee that reads L, or whose module touches it elsewhere, without writing it), its result written elsewhere.

    theorem GaudisCrypt.Stmt.Keeps.call_app_writes {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) {γ : Type} (L : Lens γ VariableAssignment) (hdisj : FVP.fvP D ≤ L.footprintᶜ) (hc : ∀ {sig' : ProcedureSignature} (a : HoleIndex holes sig'), Countable sig'.ParamType) (O : T) (hO : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), StmtWithHoles.WritesKeep L.get ((ext O).lookup n).body) {y : Setter sig.ret ProgramState} {args : Getter sig.ParamType ProgramState} (hy : ∀ (r : sig.ret) (σ : ProgramState), L.get (y.set r σ).globals = L.get σ.globals) :
    Keeps L.intoGlobal (GaudiProg[ y <- call (Module.app D O).procedure (§args); ])

    A call of a declared module D on oracles O keeps a global L outside D that every write of every oracle procedure keeps (EC's frame by writes through an abstract call: the adversary does not touch L, its oracles read it at most), its result written elsewhere.

    s keeps the region F of the globals (EC's glob A, F = fvP A): every run ends with the same F.touched_getter of the globals as it started.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      theorem GaudisCrypt.Stmt.KeepsRegion.seq {F : Footprint VariableAssignment} {p q : Stmt} (hp : KeepsRegion F p) (hq : KeepsRegion F q) :
      KeepsRegion F (GaudiProg[ stmt p; stmt q; ])
      theorem GaudisCrypt.Stmt.KeepsRegion.ite {F : Footprint VariableAssignment} {b : Getter Bool ProgramState} {p q : Stmt} (hp : KeepsRegion F p) (hq : KeepsRegion F q) :
      KeepsRegion F (GaudiProg[ if (§b) { stmt p; } else { stmt q; } ])
      theorem GaudisCrypt.Stmt.KeepsRegion.while {F : Footprint VariableAssignment} {b : Getter Bool ProgramState} {body : Stmt} (h : KeepsRegion F body) :
      KeepsRegion F (GaudiProg[ while (§b) { stmt body; } ])
      theorem GaudisCrypt.Stmt.KeepsRegion.assign {F : Footprint VariableAssignment} {β : Type} {y : Setter β ProgramState} {e : Getter β ProgramState} (hy : ∀ (v : β) (σ : ProgramState), F.touched_getter.get (y.set v σ).globals = F.touched_getter.get σ.globals) :
      KeepsRegion F (GaudiProg[ y <- §e; ])
      theorem GaudisCrypt.Stmt.KeepsRegion.call {F : Footprint VariableAssignment} {sig : ProcedureSignature} {y : Setter sig.ret ProgramState} {M : Module.Proc sig} {args : Getter sig.ParamType ProgramState} (hF : F.FinitelySupported) (hM : FVP.fvP M ≤ F.globᶜ) (hy : ∀ (r : sig.ret) (σ : ProgramState), F.touched_getter.get (y.set r σ).globals = F.touched_getter.get σ.globals) :
      KeepsRegion F (GaudiProg[ y <- call M.procedure (§args); ])

      A call of a module's procedure staying out of F.glob keeps F (EC's glob A across a call of a concrete procedure outside A), its result written where F does not look.

      theorem GaudisCrypt.SubProbability.satisfies_and' {γ : Type u_1} {μ : SubProbability γ} {P Q : γ → Prop} (hP : μ.satisfies P) (hQ : μ.satisfies Q) :
      μ.satisfies fun (x : γ) => P x ∧ Q x
      theorem GaudisCrypt.SubProbability.satisfies_true' {γ : Type u_1} (μ : SubProbability γ) :
      μ.satisfies fun (x : γ) => True
      theorem GaudisCrypt.hoareStmt_of_satisfies {A B : ProgramState → Prop} {s : Stmt} (h : ∀ (σ : ProgramState), A σ → (programDenotation s σ).satisfies fun (u : Unit × ProgramState) => B u.2) :
      hoare[ A CurrentState.state ==> B CurrentState.state ] { stmt s; }

      A Hoare triple from what holds on every outcome (the converse of hoareStmt.satisfies).

      theorem GaudisCrypt.hoareStmt_conseq_frame {A A' B B' : ProgramState → Prop} {c : Stmt} (F : ProgramState → ProgramState → Prop) (hF : ∀ (σ : ProgramState), (programDenotation c σ).satisfies fun (r : Unit × ProgramState) => F σ r.2) (h : hoare[ A' CurrentState.state ==> B' CurrentState.state ] { stmt c; }) (hA : ∀ (σ : ProgramState), A σ → A' σ) (hB : ∀ (σ : ProgramState), A σ → ∀ (τ : ProgramState), F σ τ → B' τ → B τ) :
      hoare[ A CurrentState.state ==> B CurrentState.state ] { stmt c; }

      EC's conseq on a Hoare triple, with the frame: F relates the state at the start to the state at the end (what the code keeps).

      theorem GaudisCrypt.hoareStmt_seq_while_ec {A Q I : ProgramState → Prop} {s body : Stmt} {c : Getter Bool ProgramState} (F : ProgramState → ProgramState → Prop) (hF : ∀ (σ : ProgramState), (programDenotation (GaudiProg[ while (§c) { stmt body; } ]) σ).satisfies fun (r : Unit × ProgramState) => F σ r.2) (hb : hoare[ I CurrentState.state ∧ c.get CurrentState.state = true ==> I CurrentState.state ] { stmt body; }) (hpre : hoare[ A CurrentState.state ==> let σ := CurrentState.state; I σ ∧ ∀ (τ : ProgramState), F σ τ → I τ → c.get τ = false → Q τ ] { stmt s; }) :
      hoare[ A CurrentState.state ==> Q CurrentState.state ] { stmt s; while (§c) { stmt body; } }

      EC's while I on a Hoare triple whose code ends with a loop: the body keeps I, and the code before establishes I and, for every final state τ of the loop that its frame F allows (what the loop keeps), I and a false guard give the postcondition.

      Stmt.Keeps.call_app_writes for goal (Stmt.Keeps L.intoGlobal s, s a call of a declared module D on oracles O): D's representation from its declaration and the oracles' module type's T.ext (else its canonical one, as equiv_call's), D outside L (fp_disjoint), the oracles' arguments countable, every write of every oracle procedure keeping L (ECCallEquiv.writesKeepProof), the result elsewhere (StmtSwap.discharge).

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        A proof of Stmt.Keeps x s, by the statement's syntax: writes to other variables (the side equations by StmtSwap.discharge), calls keeping the caller's other locals, a global outside the callee's footprint (fp_disjoint), or a global no write of the callee's body touches (EC's frame by writes, ECCallEquiv.writesKeepProof).

        A write keeps the region: ∀ v σ, F.touched_getter.get (y.set v σ).globals = … — a local (the globals unchanged) or a global outside F (touched_set_of_le_compl, fp_disjoint).

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          A proof of the proposition ty by the tactic tac (no goal left, no error, no sorry).

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            A proof of Stmt.KeepsRegion F s, by the statement's syntax (calls of modules' procedures outside F.glob: Stmt.KeepsRegion.call).

            The regions F whose F.touched_getter the conditions es read (EC's glob A).

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              The frame of the statement s for the variables xs (lenses of the program state): those it keeps (keepsOf), as fun σ τ => x.get τ = x.get σ ∧ …, and the proof of ∀ σ, (programDenotation s σ).satisfies fun r => F σ r.2.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For