Documentation

GaudisCrypt.Logic.ECConseq

EasyCrypt's hoare and conseq #

phoare_hoare                  -- EC's `hoare`: `phoare[c : P ==> Q] ≤ r` (or `= 0`) from
                              --   `hoare[c : P ==> !Q]`
stmt_exists* e                -- EC's `exists* e`: `phoare[c : P ∧ e = h ==> Q]` for every
                              --   `h` (then `intro h`, EC's `elim* => h`)
hoare_conseq (: P ==> Q)      -- EC's `conseq (: P ==> Q)` on a Hoare triple (`_` keeps one)
phoare_conseq (: P ==> Q)     -- … on an upper bound `phoare[ … ] ≤ r`
equiv_conseq (: P ==> Q)      -- … on a relational judgment (`§x{1}`, `§x{2}`)

conseq's goals, as EC's: the implications, then the judgment with the new conditions. For an upper bound, the event may only grow: the old event implies the new one.

theorem GaudisCrypt.Stmt.ewp_eq_zero_of_hoare {A : ProgramState → Prop} {c : Stmt} {g : ProgramState → ENNReal} (h : hoare[ A CurrentState.state ==> g CurrentState.state = 0 ] { stmt c; }) {σ : ProgramState} (hA : A σ) :
c.ewp g σ = 0

A run after which g vanishes: its expectation of g is 0.

theorem GaudisCrypt.phoareStmt_le_of_hoare {A : ProgramState → Prop} {c : Stmt} {g r : ProgramState → ENNReal} (h : hoare[ A CurrentState.state ==> g CurrentState.state = 0 ] { stmt c; }) :
phoareStmt A c g (fun (x1 x2 : ENNReal) => x1 ≤ x2) r

EC's hoare on an upper bound: g vanishing after the run bounds its expectation by anything.

theorem GaudisCrypt.phoareStmt_eq_zero_of_hoare {A : ProgramState → Prop} {c : Stmt} {g : ProgramState → ENNReal} (h : hoare[ A CurrentState.state ==> g CurrentState.state = 0 ] { stmt c; }) :
phoare[ A CurrentState.state ==> g CurrentState.state ] = 0 { stmt c; }

EC's hoare on phoare[ … ] = 0.

theorem GaudisCrypt.phoareStmt_exists {A : ProgramState → Prop} {c : Stmt} {α : Type} (e : ProgramState → α) {g r : ProgramState → ENNReal} {ρ : ENNReal → ENNReal → Prop} (h : ∀ (v : α), phoareStmt (fun (σ : ProgramState) => A σ ∧ e σ = v) c g ρ r) :
phoareStmt A c g ρ r

EC's exists* e on a phoare judgment: the judgment for every value h of e at the start, the precondition with e = h.

theorem GaudisCrypt.prhlProc_exists {α : Type} {sig₁ sig₂ : ProcedureSignature} {p₁ : Procedure sig₁} {p₂ : Procedure sig₂} {A : sig₁.ParamType → VariableAssignment → sig₂.ParamType → VariableAssignment → Prop} {B : sig₁.ret → VariableAssignment → sig₂.ret → VariableAssignment → Prop} (e : sig₁.ParamType → VariableAssignment → sig₂.ParamType → VariableAssignment → α) (h : ∀ (v : α), prhlProc (fun (a₁ : sig₁.ParamType) (g₁ : VariableAssignment) (a₂ : sig₂.ParamType) (g₂ : VariableAssignment) => A a₁ g₁ a₂ g₂ ∧ e a₁ g₁ a₂ g₂ = v) p₁ p₂ B) :
prhlProc A p₁ p₂ B

EC's exists* e on a procedure judgment: e reads both sides' arguments and globals.

A marker: equiv_exists* on a procedure judgment reads e off the precondition existsMark e that equiv[ p₁ ~ p₂ : … ] elaborates.

Equations
Instances For
    theorem GaudisCrypt.hoareStmt_exists {A : ProgramState → Prop} {c : Stmt} {α : Type} (e : ProgramState → α) {B : ProgramState → Prop} (h : ∀ (v : α), hoare[ A CurrentState.state ∧ e CurrentState.state = v ==> B CurrentState.state ] { stmt c; }) :
    hoare[ A CurrentState.state ==> B CurrentState.state ] { stmt c; }

    EC's exists* e on a Hoare triple.

    EC's hoare on a phoare goal with an upper bound, or the bound 0: the Hoare triple that its event fails (phoareStmt_le_of_hoare, phoareStmt_eq_zero_of_hoare).

    Equations
    Instances For

      A condition on one state, written as the judgment's (§x, the code's variables by name).

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

        _: the condition kept.

        Equations
        Instances For

          Run refine stx; its goals tagged, the given ones in EC's order (then any others).

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

            EC's conseq (: P ==> Q) on a Hoare triple: goals pre (the precondition implies P), post, then the triple with P, Q; _ keeps a condition. post is EC's P => (frame) => Q' => Q: the variables the conditions read that the code does not modify keep their values from the start (hoareStmt_conseq_frame, as equiv_conseq), so the precondition's facts about them are there (EC's conseq (_: _ ==> Q') => //; move=> &m -> …).

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

              EC's conseq (: P ==> Q) on an upper bound phoare[ c : A ==> E ] ≤ r: goals pre, post (the old event's expectation below Q's indicator: for an event, E implies Q), then the judgment with P, Q; _ keeps a condition.

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

                EC's conseq (: P ==> Q) on a relational judgment (§x{1}, §x{2}): goals pre, post, then the judgment with P, Q; _ keeps a condition. On statements, post is EC's P => (frames) => Q' => Q: the variables Q reads that the code does not modify keep their values from the start (prhlStmt_conseq_frame).

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

                  EC's exists* e on a phoare judgment or a Hoare triple: e an expression of the state (§Preimage2.hash); the goal for every value of it, ∀ v, … : A ∧ e = v … (EC's elim* => h is intro h).

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

                    EC's exists* e₁, …, eₙ on a relational judgment: the eᵢ relational terms (§x{1}, §y{2}); the goal for all their values, ∀ v₁ … vₙ, equiv[ (A ∧ e₁ = v₁) ∧ … ∧ eₙ = vₙ ==> … ] (EC's elim* => v₁ … vₙ is intro v₁ … vₙ).

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

                      EC's conseq H on a relational judgment: the judgment H (about the same statements or procedures) for the goal's; goals pre (the goal's precondition implies H's) and post (H's postcondition implies the goal's), each closed when it is a matter of logic (the conditions the same up to equal arguments: as EC's conseq H closes them), else left.

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