Documentation

GaudisCrypt.Logic.ECSp

EasyCrypt's sp: deterministic code at the start, into the precondition #

stmt_sp          -- EC's `sp`: on every side, as long as the first statement is deterministic
stmt_sp{i}       -- EC's `sp` on side `i` of a relational judgment
stmt_sp n        -- EC's `sp n` (`stmt_sp{i} n`): `n` statements (on each side)

EC's sp moves the precondition forward over the assignments at the start of the code: P becomes exists x₀, P[x₀/x] /\ x = e[x₀/x]. Here, for a deterministic statement d running as the update upd (Stmt.Det d upd, assignments and the resets inlining leaves among them), the precondition A becomes fun σ => ∃ τ, A τ ∧ σ = upd τ (hoareStmt_sp, phoareStmt_sp, prhlStmt_sp_left/_right). A phoare bound is a function of the state: sp needs it unchanged by upd (a constant bound, as EC's usually are; left as a goal otherwise).

theorem GaudisCrypt.programDenotation_seq_det {d : Stmt} {upd : ProgramState → ProgramState} (hd : d.Det upd) (s : Stmt) (σ : ProgramState) :
programDenotation (GaudiProg[ stmt d; stmt s; ]) σ = programDenotation s (upd σ)

A deterministic statement, then s: s from the updated state.

theorem GaudisCrypt.hoareStmt_sp {d s : Stmt} {upd : ProgramState → ProgramState} {A B : ProgramState → Prop} (hd : d.Det upd) (h : hoare[ let σ := CurrentState.state; ∃ (τ : ProgramState), A τ ∧ σ = upd τ ==> B CurrentState.state ] { stmt s; }) :
hoare[ A CurrentState.state ==> B CurrentState.state ] { stmt d; stmt s; }

EC's sp on a Hoare triple: the first statement, deterministic, into the precondition.

theorem GaudisCrypt.phoareStmt_sp {d s : Stmt} {upd : ProgramState → ProgramState} {A : ProgramState → Prop} {g : ProgramState → ENNReal} {ρ : ENNReal → ENNReal → Prop} {r : ProgramState → ENNReal} (hd : d.Det upd) (hr : ∀ (τ : ProgramState), A τ → r (upd τ) = r τ) (h : phoareStmt (fun (σ : ProgramState) => ∃ (τ : ProgramState), A τ ∧ σ = upd τ) s g ρ r) :
phoareStmt A (GaudiProg[ stmt d; stmt s; ]) g ρ r

EC's sp on a phoare judgment, its bound unchanged by the update.

theorem GaudisCrypt.hoareStmt_sp_keep {d s : Stmt} {upd : ProgramState → ProgramState} {A B : ProgramState → Prop} (hd : d.Det upd) (hA : ∀ (τ : ProgramState), A τ → A (upd τ)) (h : hoare[ let σ := CurrentState.state; A σ ∧ ∃ (τ : ProgramState), A τ ∧ σ = upd τ ==> B CurrentState.state ] { stmt s; }) :
hoare[ A CurrentState.state ==> B CurrentState.state ] { stmt d; stmt s; }

hoareStmt_sp, the precondition kept on the new state when the update cannot change it (an assignment to a variable it does not read): EC's P /\ x = e where P does not mention x.

theorem GaudisCrypt.phoareStmt_sp_keep {d s : Stmt} {upd : ProgramState → ProgramState} {A : ProgramState → Prop} {g : ProgramState → ENNReal} {ρ : ENNReal → ENNReal → Prop} {r : ProgramState → ENNReal} (hd : d.Det upd) (hr : ∀ (τ : ProgramState), A τ → r (upd τ) = r τ) (hA : ∀ (τ : ProgramState), A τ → A (upd τ)) (h : phoareStmt (fun (σ : ProgramState) => A σ ∧ ∃ (τ : ProgramState), A τ ∧ σ = upd τ) s g ρ r) :
phoareStmt A (GaudiProg[ stmt d; stmt s; ]) g ρ r

phoareStmt_sp, the precondition kept on the new state (as hoareStmt_sp_keep).

The resets inlining leaves: not EC's statements #

A reset (reset_vars S, the callee's locals set to their initial values) is no statement of EC's, whose inlining has none; past it the precondition is kept as it is, when the reset cannot change it (A reads none of S), and the reset forgotten — its values are never read before the callee's code assigns them.

theorem GaudisCrypt.hoareStmt_sp_drop {d s : Stmt} {upd : ProgramState → ProgramState} {A B : ProgramState → Prop} (hd : d.Det upd) (hA : ∀ (τ : ProgramState), A τ → A (upd τ)) (h : hoare[ A CurrentState.state ==> B CurrentState.state ] { stmt s; }) :
hoare[ A CurrentState.state ==> B CurrentState.state ] { stmt d; stmt s; }

hoareStmt_sp_keep, the update forgotten.

theorem GaudisCrypt.phoareStmt_sp_drop {d s : Stmt} {upd : ProgramState → ProgramState} {A : ProgramState → Prop} {g : ProgramState → ENNReal} {ρ : ENNReal → ENNReal → Prop} {r : ProgramState → ENNReal} (hd : d.Det upd) (hr : ∀ (τ : ProgramState), A τ → r (upd τ) = r τ) (hA : ∀ (τ : ProgramState), A τ → A (upd τ)) (h : phoareStmt A s g ρ r) :
phoareStmt A (GaudiProg[ stmt d; stmt s; ]) g ρ r

phoareStmt_sp_keep, the update forgotten.

EC's P /\ x = e: an assignment as a read #

For an assignment x <- e (the update upd τ = x.set (e τ) τ) that changes neither P nor e, the precondition after it is P ∧ x = e, a fact about reads (EC's), rather than the equation of states σ = upd τ: reads go through the later steps (the inliner's renamings among them).

theorem GaudisCrypt.hoareStmt_sp_read {d s : Stmt} {upd : ProgramState → ProgramState} {α : Type} {A B : ProgramState → Prop} (X : Lens α ProgramState) (E : ProgramState → α) (hd : d.Det upd) (hupd : ∀ (τ : ProgramState), upd τ = X.set (E τ) τ) (hA : ∀ (τ : ProgramState), A τ → A (upd τ)) (hE : ∀ (τ : ProgramState), E (upd τ) = E τ) (h : hoare[ A CurrentState.state ∧ §X = E CurrentState.state ==> B CurrentState.state ] { stmt s; }) :
hoare[ A CurrentState.state ==> B CurrentState.state ] { stmt d; stmt s; }

hoareStmt_sp for an assignment: A ∧ x = e.

theorem GaudisCrypt.phoareStmt_sp_read {d s : Stmt} {upd : ProgramState → ProgramState} {α : Type} {A : ProgramState → Prop} {g : ProgramState → ENNReal} {ρ : ENNReal → ENNReal → Prop} {r : ProgramState → ENNReal} (X : Lens α ProgramState) (E : ProgramState → α) (hd : d.Det upd) (hupd : ∀ (τ : ProgramState), upd τ = X.set (E τ) τ) (hr : ∀ (τ : ProgramState), A τ → r (upd τ) = r τ) (hA : ∀ (τ : ProgramState), A τ → A (upd τ)) (hE : ∀ (τ : ProgramState), E (upd τ) = E τ) (h : phoareStmt (fun (σ : ProgramState) => A σ ∧ X.get σ = E σ) s g ρ r) :
phoareStmt A (GaudiProg[ stmt d; stmt s; ]) g ρ r

phoareStmt_sp for an assignment: A ∧ x = e.

EC's exists x0, P[x0/x] /\ x = e[x0/x]: an assignment reading its variable #

For x <- e with e reading x (C.c <- C.c + 1), the old value is existentially quantified (EC's sp, then elim *), not the whole state: the precondition stays a fact about reads.

theorem GaudisCrypt.hoareStmt_sp_exval {d s : Stmt} {upd : ProgramState → ProgramState} {α : Type} {A B : ProgramState → Prop} (X : Lens α ProgramState) (E : ProgramState → α) (hd : d.Det upd) (hupd : ∀ (τ : ProgramState), upd τ = X.set (E τ) τ) (h : hoare[ ∃ (v : α), A (X.set v CurrentState.state) ∧ §X = E (X.set v CurrentState.state) ==> B CurrentState.state ] { stmt s; }) :
hoare[ A CurrentState.state ==> B CurrentState.state ] { stmt d; stmt s; }

hoareStmt_sp for an assignment reading its variable: ∃ v, A[v/x] ∧ x = E[v/x].

theorem GaudisCrypt.phoareStmt_sp_exval {d s : Stmt} {upd : ProgramState → ProgramState} {α : Type} {A : ProgramState → Prop} {g : ProgramState → ENNReal} {ρ : ENNReal → ENNReal → Prop} {r : ProgramState → ENNReal} (X : Lens α ProgramState) (E : ProgramState → α) (hd : d.Det upd) (hupd : ∀ (τ : ProgramState), upd τ = X.set (E τ) τ) (hr : ∀ (τ : ProgramState), A τ → r (upd τ) = r τ) (h : phoareStmt (fun (σ : ProgramState) => ∃ (v : α), A (X.set v σ) ∧ X.get σ = E (X.set v σ)) s g ρ r) :
phoareStmt A (GaudiProg[ stmt d; stmt s; ]) g ρ r

phoareStmt_sp for an assignment reading its variable (as hoareStmt_sp_exval).

The lens an assignment's setter writes through (Lens.toSetter X, liftLens X), if any.

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

    The statement of side side? of the goal (the only one of a Hoare or phoare judgment).

    Equations
    Instances For

      One step of sp on side side?: the first statement, if deterministic, into the precondition; none if it is not.

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

        sp on side side?, n? statements (all deterministic ones at the start for none).

        EC's sp: see the module docstring.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem GaudisCrypt.while_lossless_of_phoare {I : ProgramState → ProgramState → Prop} {c : Getter Bool ProgramState} {body : Stmt} (h : ∀ (σ₂ : ProgramState), phoareStmt (fun (σ : ProgramState) => I σ σ₂ ∧ c.get σ = true) body (fun (x : ProgramState) => 1) Eq fun (x : ProgramState) => 1) (σ₂ σ : ProgramState) :
          I σ σ₂ → c.get σ = true → body.ewp (fun (x : ProgramState) => 1) σ = 1

          The losslessness goal of equiv_while{i} I V from a phoare judgment about the body (EC's while{i} goal on the body is a phoare … = 1).

          while_ll_phoare: the lossless goal of equiv_while{i} I V as ∀ σ₂, phoare[ I ∧ guard ==> 1 ] = 1 about the body, for the phoare tactics (EC's while{i} body goal: auto; sp; rcondt 1; …).

          Equations
          Instances For

            EC's sp n m on a relational judgment, with EC's code positions (TacticMisc.ecGapIn: EC's statements, the resets inlining leaves not counted): the statements before the gap n of the left side and before the gap m of the right forward (0: none; -k: up to and with the k-th statement from the end).

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