Documentation

GaudisCrypt.Logic.SyntacticFrame

The syntactic frame: what a statement does not write, it keeps #

EasyCrypt frames a call's invariant syntactically. An oracle that writes none of D's variables keeps glob D, and the oracle premise of the abstract call rule then needs only the oracle's own relation (={arg} ∧ inv ==> ={res} ∧ inv). prhlProc_globInvF_of_confined does this from a footprint (inFootprint), which a concrete procedure does not come with.

The syntactic route instead looks at every write of the statement, its callees' bodies included: StmtWithHoles.WritesKeep G s says each of them keeps G of the globals. A write to a local variable keeps the globals outright. A write to a global lens outside a region F keeps F.touched_getter (touched_set_of_le_compl). hoareStmt_of_writesKeep turns that into a Hoare triple by induction over the statement. prhlProc_globInvF_of_writesKeep puts it into the oracle premise.

The tactic writes_keep reduces a WritesKeep goal to the conditions on single writes. It unfolds module procedures as the inliner does (Flatten.unfoldProcedure), closes the writes to local variables by rfl, and the writes to global lenses outside the region by touched_set_of_le_compl with a hypothesis from the context.

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

A procedure triple from a triple about its body, run on the initial locals.

Every write of the statement, its callees' included, keeps G of the globals.

Equations
Instances For
    theorem GaudisCrypt.hoareStmt_of_writesKeep {β : Type u_1} (G : VariableAssignment → β) (c : β) (s : Stmt) :
    StmtWithHoles.WritesKeep G s → hoareStmt (fun (σ : ProgramState) => G σ.globals = c) s fun (σ : ProgramState) => G σ.globals = c

    The syntactic frame: a statement whose writes keep G keeps it.

    theorem GaudisCrypt.hoareProc_of_writesKeep {sig : ProcedureSignature} {β : Type u_1} (G : VariableAssignment → β) (p : Procedure sig) (hp : StmtWithHoles.WritesKeep G p.body) (c : β) :
    hoareProc (fun (x : sig.ParamType) (g : VariableAssignment) => G g = c) p fun (x : sig.ret) (g : VariableAssignment) => G g = c

    A procedure whose writes keep G keeps it.

    hoareProc_of_writesKeep, as the runs of the procedure.

    theorem GaudisCrypt.prhlProc_globInvF_of_writesKeep {Ω : Type} (L : Lens Ω VariableAssignment) {F : Footprint VariableAssignment} {sig' : ProcedureSignature} {I : Ω → Ω → Prop} {o₁ o₂ : Procedure sig'} (h₁ : StmtWithHoles.WritesKeep F.touched_getter.get o₁.body) (h₂ : StmtWithHoles.WritesKeep F.touched_getter.get o₂.body) (h : prhlProc (fun (a₁ : sig'.ParamType) (g₁ : VariableAssignment) (a₂ : sig'.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ I (L.get g₁) (L.get g₂)) o₁ o₂ fun (r₁ : sig'.ret) (g₁ : VariableAssignment) (r₂ : sig'.ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ I (L.get g₁) (L.get g₂)) :
    prhlProc (fun (a₁ : sig'.ParamType) (g₁ : VariableAssignment) (a₂ : sig'.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ globInvF L F I g₁ g₂) o₁ o₂ fun (r₁ : sig'.ret) (g₁ : VariableAssignment) (r₂ : sig'.ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ globInvF L F I g₁ g₂

    EasyCrypt's oracle premise, by the syntactic frame: prhlProc_globInvF_of_confined for oracles whose writes keep the content of F.

    theorem GaudisCrypt.prhlProc_upto_of_writesKeep {Ω : Type} (L : Lens Ω VariableAssignment) {F : Footprint VariableAssignment} {sig' : ProcedureSignature} {I Q : Ω → Ω → Prop} {bad : Ω → Prop} {o₁ o₂ : Procedure sig'} (h₁ : StmtWithHoles.WritesKeep F.touched_getter.get o₁.body) (h₂ : StmtWithHoles.WritesKeep F.touched_getter.get o₂.body) (h : prhlProc (fun (a₁ : sig'.ParamType) (g₁ : VariableAssignment) (a₂ : sig'.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ I (L.get g₁) (L.get g₂) ∧ ¬bad (L.get g₂)) o₁ o₂ fun (r₁ : sig'.ret) (g₁ : VariableAssignment) (r₂ : sig'.ret) (g₂ : VariableAssignment) => bad (L.get g₂) ∧ Q (L.get g₁) (L.get g₂) ∨ r₁ = r₂ ∧ I (L.get g₁) (L.get g₂) ∧ ¬bad (L.get g₂)) :
    prhlProc (fun (a₁ : sig'.ParamType) (g₁ : VariableAssignment) (a₂ : sig'.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ syncInv L F I bad g₁ g₂) o₁ o₂ fun (r₁ : sig'.ret) (g₁ : VariableAssignment) (r₂ : sig'.ret) (g₂ : VariableAssignment) => badInv L bad Q g₁ g₂ ∨ r₁ = r₂ ∧ syncInv L F I bad g₁ g₂

    EasyCrypt's oracle premise up to bad, by the syntactic frame: the oracle premise of prhlProc_abstract_call_upto(_module) at F, for oracles whose writes keep the content of F, from a judgment about the L-contents (EC's call (: bad, invP, invQ) on concrete oracles, ={glob D} framed syntactically).

    partial def GaudisCrypt.stmtPredSplit (head : Lean.Name) (g : Lean.MVarId) (fuel : ℕ := 256) (onStuck? : Option (Lean.MVarId → Lean.MetaM Lean.MVarId) := none) :

    Split a goal head … s (a predicate on statements defined by recursion on them, such as StmtWithHoles.WritesKeep) down to its leaves, unfolding the procedures of modules (Flatten.unfoldProcedure) where the statement is a callee's body.

    stmtPredSplit for StmtWithHoles.WritesKeep.

    Equations
    Instances For

      writes_keep: on a goal StmtWithHoles.WritesKeep G s, the conditions on the single writes of s, callees included. Writes to local variables are closed by rfl, writes to a global lens X by touched_set_of_le_compl with a hypothesis X.footprint ≤ Fᶜ from the context.

      Equations
      Instances For