Documentation

GaudisCrypt.Logic.ECProc

EasyCrypt's proc: a procedure judgment as the judgment about its body #

phoare_proc     -- EC's `proc` on `phoare[ M.f : P ==> Q ] ⋈ r`
hoare_proc      -- EC's `proc` on `hoare[ M.f : P ==> Q ]`
equiv_proc      -- EC's `proc` on `equiv[ M₁.f ~ M₂.g : P ==> Q ]`

The goal becomes the judgment about the procedure's body, its parameters local variables under their own names, the postcondition read at the return value: no call, no copies of the arguments, no reset of the callee's frame, so that EC's statement counts (seq 1, wp 2) are ours.

Sound as EC's proc is: the body's judgment is proven from every state whose parameter variables hold the arguments, whatever the other locals hold (phoareProc_of_body_anyLocals); the run of the procedure starts from one of them (its other locals at their initial values). It is unprovable only for a body reading a local before writing it, as in EC.

theorem GaudisCrypt.Procedure.ewp_eq_body_ret {sig : ProcedureSignature} (p : Procedure sig) (args : sig.ParamType) (G : sig.ret → VariableAssignment → ENNReal) (st : VariableAssignment) :
p.ewp args G st = Stmt.ewp p.body (fun (σ : ProgramState) => G (p.return_val.get σ) σ.globals) { globals := st, locals := ProcedureWithHoles.initLocals p args }

The expectation of a procedure is its body's, from its initial locals, read at the return value (Procedure.ewp_eq_body for an expectation of the result too).

theorem GaudisCrypt.phoareProc_of_body_anyLocals {sig : ProcedureSignature} (argsL : Lens sig.ParamType VariableAssignment) {A : sig.ParamType → VariableAssignment → Prop} {p : Procedure sig} {G : sig.ret → VariableAssignment → ENNReal} {ρ : ENNReal → ENNReal → Prop} {r : sig.ParamType → VariableAssignment → ENNReal} (hargs : ∀ (args : sig.ParamType), argsL.get (ProcedureWithHoles.initLocals p args) = args) (h : phoareStmt (fun (σ : ProgramState) => A (argsL.get σ.locals) σ.globals) p.body (fun (σ : ProgramState) => G (p.return_val.get σ) σ.globals) ρ fun (σ : ProgramState) => r (argsL.get σ.locals) σ.globals) :
phoareProc A p G ρ r

EC's proc for phoare: the judgment about the body, from any state whose parameter variables (argsL, read back from the initial locals by hargs) satisfy the precondition.

theorem GaudisCrypt.hoareProc_of_body_anyLocals {sig : ProcedureSignature} (argsL : Lens sig.ParamType VariableAssignment) {A : sig.ParamType → VariableAssignment → Prop} {p : Procedure sig} {B : sig.ret → VariableAssignment → Prop} (hargs : ∀ (args : sig.ParamType), argsL.get (ProcedureWithHoles.initLocals p args) = args) (h : hoareStmt (fun (σ : ProgramState) => A (argsL.get σ.locals) σ.globals) p.body fun (σ : ProgramState) => B (p.return_val.get σ) σ.globals) :
hoareProc A p B

EC's proc for Hoare triples, as phoareProc_of_body_anyLocals (hoareProc_of_body, from the initial locals only, with the precondition strengthened).

theorem GaudisCrypt.prhlProc_of_body_anyLocals {sig₁ sig₂ : ProcedureSignature} {A : sig₁.ParamType → VariableAssignment → sig₂.ParamType → VariableAssignment → Prop} {p₁ : Procedure sig₁} {p₂ : Procedure sig₂} {B : sig₁.ret → VariableAssignment → sig₂.ret → VariableAssignment → Prop} (argsL₁ : Lens sig₁.ParamType VariableAssignment) (argsL₂ : Lens sig₂.ParamType VariableAssignment) (hargs₁ : ∀ (args : sig₁.ParamType), argsL₁.get (ProcedureWithHoles.initLocals p₁ args) = args) (hargs₂ : ∀ (args : sig₂.ParamType), argsL₂.get (ProcedureWithHoles.initLocals p₂ args) = args) (h : prhlStmt (fun (σ₁ σ₂ : ProgramState) => A (argsL₁.get σ₁.locals) σ₁.globals (argsL₂.get σ₂.locals) σ₂.globals) p₁.body p₂.body fun (σ₁ σ₂ : ProgramState) => B (p₁.return_val.get σ₁) σ₁.globals (p₂.return_val.get σ₂) σ₂.globals) :
prhlProc A p₁ p₂ B

EC's proc for pRHL, as phoareProc_of_body_anyLocals: the judgment about the two bodies, from any states whose parameter variables satisfy the precondition.

One procedure, prepared for EC's proc: its literal p' (Flatten.unfoldProcedure, proof of p = p'), body, return value, the lens of its parameter variables over the locals and their slots in the program state, and the proof that the lens reads the arguments back from the initial locals.

Instances For

    Side of the procedure p of signature sig.

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

      EC's proc on the goal g: a phoareProc, hoareProc or prhlProc judgment becomes the judgment about the bodies (phoareProc_of_body_anyLocals, hoareProc_of_body_anyLocals, prhlProc_of_body_anyLocals), the conditions in the shape the statement notation builds (as hoareProcToStmt does). The new goal is returned.

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

        A module's procedure read off a module built from a record (DPRIMITIVE.f (DPRIMITIVE.mk { f := P.f, … }), what a module type's view leaves at a call) or out of a Module.pair, read off (T.f.mk_simp, Module.fst_pair', …) everywhere in the goal: the two sides of a call then name the same procedure (P.f), as EC's sim sees them.

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

          A call of a procedure alias (proc f = c; of a module, @[gaudiModuleAlias]) is a call of the aliased procedure, as in EC (an alias is that procedure): every callee M.procedure whose evaluation by the module steps (Flatten.moduleStep?) passes through an alias is rewritten to what that step gives (FM(C, P).get ↦ C(P).f). Callees whose evaluation meets no alias are left as they are, and so is a goal that mentions no alias.

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

            EC's proc on phoare[ M.f : P ==> Q ] ⋈ r: see the module docstring.

            Equations
            Instances For

              EC's proc on hoare[ M.f : P ==> Q ]: see the module docstring.

              Equations
              Instances For

                EC's proc on equiv[ M₁.f ~ M₂.g : P ==> Q ]: see the module docstring.

                Equations
                Instances For

                  module_norm: read the procedures off module views in the goal (ECProc.accessorNorm: DPRIMITIVE.f (DPRIMITIVE.mk { f := P.f, … }) is P.f), as *_proc and sim do.

                  Equations
                  Instances For