Documentation

GaudisCrypt.Logic.PRHLStmt

pRHL for statements and procedures #

The relational judgment on the statements and procedures of the language, EasyCrypt's equiv [ c₁ ~ c₂ : P ==> Q ]: from any two states related by P, the two runs can be coupled so that the final states are related by Q. It is the coupling judgment ProgramDenotation.prhl2 (Logic/PRHL2.lean) at the statements' denotations, so all its rules apply; this file states the ones the tactics use at the level of statements:

equiv[ A ==> B ] { c₁ } ~ { c₂ }: from states related by A, the runs of c₁ and c₂ can be coupled so that the final states are related by B.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    def GaudisCrypt.prhlProc {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) :

    equiv[ p₁ ~ p₂ : A ==> B ]: for all arguments, from globals related by A, the runs of the two procedures can be coupled so that the results and the final globals are related by B.

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

      Couplings, generically #

      theorem GaudisCrypt.SubProbability.mem_support_of_ne_zero {α : Type u} {μ : SubProbability α} {a : α} (h : ↑μ {a} ≠ 0) :

      A positive-mass point of a subprobability is in its support.

      theorem GaudisCrypt.SubProbability.marginal_fst_eq {X Y : Type u} {μ : SubProbability (X × Y)} {ν : SubProbability X} (h : ∀ (F : X → ENNReal), (μ.expected fun (x : X × Y) => F x.1) = ν.expected F) :
      (do let x ← μ pure x.1) = ν

      A statement's run, as its expectations: the subprobability is determined by them.

      theorem GaudisCrypt.SubProbability.marginal_snd_eq {X Y : Type u} {μ : SubProbability (X × Y)} {ν : SubProbability Y} (h : ∀ (F : Y → ENNReal), (μ.expected fun (x : X × Y) => F x.2) = ν.expected F) :
      (do let x ← μ pure x.2) = ν
      theorem GaudisCrypt.SubProbability.expected_fst_of_marginal {X Y : Type u} {μ : SubProbability (X × Y)} {ν : SubProbability X} (h : (do let x ← μ pure x.1) = ν) (F : X → ENNReal) :
      (μ.expected fun (x : X × Y) => F x.1) = ν.expected F

      The marginal conditions, as expectations.

      theorem GaudisCrypt.SubProbability.expected_snd_of_marginal {X Y : Type u} {μ : SubProbability (X × Y)} {ν : SubProbability Y} (h : (do let x ← μ pure x.2) = ν) (F : Y → ENNReal) :
      (μ.expected fun (x : X × Y) => F x.2) = ν.expected F
      theorem GaudisCrypt.SubProbability.expected_congr_satisfies {X : Type u} {μ : SubProbability X} {P : X → Prop} (hP : μ.satisfies P) {F G : X → ENNReal} (h : ∀ (x : X), P x → F x = G x) :
      μ.expected F = μ.expected G

      An expectation only depends on the function on the support.

      theorem GaudisCrypt.ProgramDenotation.prhl2.getG {α β : Type} {A : ProgramState → ProgramState → Prop} {g₁ : Getter α ProgramState} {g₂ : Getter β ProgramState} {B : α × ProgramState → β × ProgramState → Prop} (h : ∀ (σ₁ σ₂ : ProgramState), A σ₁ σ₂ → B (g₁.get σ₁, σ₁) (g₂.get σ₂, σ₂)) :

      Two reads coupled: a point mass.

      Basic rules #

      theorem GaudisCrypt.prhlStmt_conseq {A A' B B' : ProgramState → ProgramState → Prop} {c₁ c₂ : Stmt} (h : prhlStmt A' c₁ c₂ B') (hA : ∀ (σ₁ σ₂ : ProgramState), A σ₁ σ₂ → A' σ₁ σ₂) (hB : ∀ (σ₁ σ₂ : ProgramState), B' σ₁ σ₂ → B σ₁ σ₂) :
      prhlStmt A c₁ c₂ B

      Consequence: a stronger precondition, a weaker postcondition.

      theorem GaudisCrypt.prhlStmt_pre {A A' B : ProgramState → ProgramState → Prop} {c₁ c₂ : Stmt} (h : prhlStmt A' c₁ c₂ B) (hA : ∀ (σ₁ σ₂ : ProgramState), A σ₁ σ₂ → A' σ₁ σ₂) :
      prhlStmt A c₁ c₂ B

      Strengthening the precondition, the judgment first (as hoare_pre).

      theorem GaudisCrypt.prhlStmt_post {A B B' : ProgramState → ProgramState → Prop} {c₁ c₂ : Stmt} (h : prhlStmt A c₁ c₂ B') (hB : ∀ (σ₁ σ₂ : ProgramState), B' σ₁ σ₂ → B σ₁ σ₂) :
      prhlStmt A c₁ c₂ B

      Weakening the postcondition, the judgment first.

      theorem GaudisCrypt.prhlStmt.symm {A B : ProgramState → ProgramState → Prop} {c₁ c₂ : Stmt} (h : prhlStmt A c₁ c₂ B) :
      prhlStmt (fun (σ₂ σ₁ : ProgramState) => A σ₁ σ₂) c₂ c₁ fun (σ₂ σ₁ : ProgramState) => B σ₁ σ₂

      Symmetry: the two sides swapped.

      theorem GaudisCrypt.prhlStmt_of_symm {A B : ProgramState → ProgramState → Prop} {c₁ c₂ : Stmt} (h : prhlStmt (fun (σ₂ σ₁ : ProgramState) => A σ₁ σ₂) c₂ c₁ fun (σ₂ σ₁ : ProgramState) => B σ₁ σ₂) :
      prhlStmt A c₁ c₂ B

      Symmetry, backwards: the judgment with the sides swapped.

      theorem GaudisCrypt.prhlStmt_symm_iff {A B : ProgramState → ProgramState → Prop} {c₁ c₂ : Stmt} :
      prhlStmt A c₁ c₂ B ↔ prhlStmt (fun (σ₂ σ₁ : ProgramState) => A σ₁ σ₂) c₂ c₁ fun (σ₂ σ₁ : ProgramState) => B σ₁ σ₂
      theorem GaudisCrypt.prhlStmt_skip {A B : ProgramState → ProgramState → Prop} (h : ∀ (σ₁ σ₂ : ProgramState), A σ₁ σ₂ → B σ₁ σ₂) :

      skip ~ skip: the precondition implies the postcondition.

      theorem GaudisCrypt.prhlStmt_seq {A B C : ProgramState → ProgramState → Prop} {c₁ c₂ d₁ d₂ : Stmt} (h₂ : prhlStmt B d₁ d₂ C) (h₁ : prhlStmt A c₁ c₂ B) :
      prhlStmt A (StmtWithHoles.seq c₁ d₁) (StmtWithHoles.seq c₂ d₂) C

      Sequencing: an intermediate relation B. The second judgment comes first, so that the wp steps can fill B.

      theorem GaudisCrypt.prhlStmt_case {A B : ProgramState → ProgramState → Prop} {c₁ c₂ : Stmt} (P : ProgramState → ProgramState → Prop) (hp : prhlStmt (fun (σ₁ σ₂ : ProgramState) => A σ₁ σ₂ ∧ P σ₁ σ₂) c₁ c₂ B) (hn : prhlStmt (fun (σ₁ σ₂ : ProgramState) => A σ₁ σ₂ ∧ ¬P σ₁ σ₂) c₁ c₂ B) :
      prhlStmt A c₁ c₂ B

      Case analysis on a relation of the initial states.

      theorem GaudisCrypt.prhlStmt_exists_pre {B : ProgramState → ProgramState → Prop} {c₁ c₂ : Stmt} {ι : Sort u_1} {A : ι → ProgramState → ProgramState → Prop} (h : ∀ (i : ι), prhlStmt (A i) c₁ c₂ B) :
      prhlStmt (fun (σ₁ σ₂ : ProgramState) => ∃ (i : ι), A i σ₁ σ₂) c₁ c₂ B

      An existential in the precondition (EC's exists*/elim*).

      theorem GaudisCrypt.prhlStmt_seq_congr_left {A B : ProgramState → ProgramState → Prop} {c₂ a a' b : Stmt} (h : ∀ (σ₁ σ₂ : ProgramState), A σ₁ σ₂ → programDenotation a σ₁ = programDenotation a' σ₁) (h' : prhlStmt A (StmtWithHoles.seq a' b) c₂ B) :

      Replace the first statement on the left by one with the same runs from the states the precondition allows (EC's transitivity{1} with an equivalence proven denotationally).

      Replace the second statement on the right by one with the same runs.

      theorem GaudisCrypt.prhlStmt_fix_left {A B : ProgramState → ProgramState → Prop} {c₁ c₂ : Stmt} {β : Sort u_1} (f : ProgramState → β) (h : ∀ (v : β), prhlStmt (fun (σ₁ σ₂ : ProgramState) => A σ₁ σ₂ ∧ f σ₁ = v) c₁ c₂ B) :
      prhlStmt A c₁ c₂ B

      EC's exists* e{1}; elim* => v: fix the value of an expression of the left state.

      theorem GaudisCrypt.prhlStmt_fix_right {A B : ProgramState → ProgramState → Prop} {c₁ c₂ : Stmt} {β : Sort u_1} (f : ProgramState → β) (h : ∀ (v : β), prhlStmt (fun (σ₁ σ₂ : ProgramState) => A σ₁ σ₂ ∧ f σ₂ = v) c₁ c₂ B) :
      prhlStmt A c₁ c₂ B

      EC's exists* e{2}; elim* => v: fix the value of an expression of the right state.

      theorem GaudisCrypt.prhlStmt_false {B : ProgramState → ProgramState → Prop} {c₁ c₂ : Stmt} :
      prhlStmt (fun (x x_1 : ProgramState) => False) c₁ c₂ B

      A false precondition.

      One-sided tails #

      A statement at the end of one side only, matched against nothing on the other: it must terminate (the other side does nothing, so the coupling has to pair every run of it with the other side's final state), and the postcondition must hold on all its outcomes. Deterministic code and lossless samplings are the instances; EC's wp and rnd{1}.

      theorem GaudisCrypt.ProgramDenotation.prhl2.kill_left' {s₁ s₂ : Type 1} {A : s₁ → s₂ → Prop} {p₀ : ProgramDenotation s₁ Unit} {B : Unit × s₁ → Unit × s₂ → Prop} (h : ∀ (σ₁ : s₁) (σ₂ : s₂), A σ₁ σ₂ → p₀.wp (fun (x : Unit × s₁) => 1) σ₁ = 1 ∧ (p₀ σ₁).satisfies fun (u : Unit × s₁) => B u ((), σ₂)) :
      prhl2 A p₀ (pure ()) B

      A program run on the left only: lossless where the precondition holds, and the postcondition on all its outcomes. (ProgramDenotation.prhl2.kill_left, with losslessness only where it is needed.)

      theorem GaudisCrypt.prhlStmt_seq_left {A B : ProgramState → ProgramState → Prop} {s₁ s₂ d : Stmt} (h : prhlStmt A s₁ s₂ fun (σ₁ σ₂ : ProgramState) => (programDenotation d).wp (fun (x : Unit × ProgramState) => 1) σ₁ = 1 ∧ (programDenotation d σ₁).satisfies fun (u : Unit × ProgramState) => B u.2 σ₂) :
      prhlStmt A (StmtWithHoles.seq s₁ d) s₂ B

      One-sided tail, left: d at the end of the left side, nothing on the right.

      theorem GaudisCrypt.prhlStmt_seq_right {A B : ProgramState → ProgramState → Prop} {s₁ s₂ d : Stmt} (h : prhlStmt A s₁ s₂ fun (σ₁ σ₂ : ProgramState) => (programDenotation d).wp (fun (x : Unit × ProgramState) => 1) σ₂ = 1 ∧ (programDenotation d σ₂).satisfies fun (v : Unit × ProgramState) => B σ₁ v.2) :
      prhlStmt A s₁ (StmtWithHoles.seq s₂ d) B

      One-sided tail, right: the mirror of prhlStmt_seq_left.

      theorem GaudisCrypt.Stmt.Det.denotation {d : Stmt} {upd : ProgramState → ProgramState} (hd : d.Det upd) (σ : ProgramState) :

      A deterministic statement runs as a point mass.

      theorem GaudisCrypt.prhlStmt_seq_det_left {A B : ProgramState → ProgramState → Prop} {s₁ s₂ d : Stmt} {upd : ProgramState → ProgramState} (hd : d.Det upd) (h : prhlStmt A s₁ s₂ fun (σ₁ σ₂ : ProgramState) => B (upd σ₁) σ₂) :
      prhlStmt A (StmtWithHoles.seq s₁ d) s₂ B

      Deterministic tail, left (Stmt.Det): the postcondition after the update.

      theorem GaudisCrypt.prhlStmt_seq_det_right {A B : ProgramState → ProgramState → Prop} {s₁ s₂ d : Stmt} {upd : ProgramState → ProgramState} (hd : d.Det upd) (h : prhlStmt A s₁ s₂ fun (σ₁ σ₂ : ProgramState) => B σ₁ (upd σ₂)) :
      prhlStmt A s₁ (StmtWithHoles.seq s₂ d) B

      Deterministic tail, right.

      A sampling's run: draw, then write.

      theorem GaudisCrypt.prhlStmt_seq_sample_left {A B : ProgramState → ProgramState → Prop} {s₁ s₂ : Stmt} {α : Type} {x : Setter α ProgramState} {e : Getter (SubProbability α) ProgramState} (h : prhlStmt A s₁ s₂ fun (σ₁ σ₂ : ProgramState) => ((e.get σ₁).expected fun (x : α) => 1) = 1 ∧ ∀ a ∈ (e.get σ₁).support, B (x.set a σ₁) σ₂) :

      Sampling on the left only (EC's rnd{1}): a lossless distribution, and the postcondition for every value in its support.

      theorem GaudisCrypt.prhlStmt_seq_sample_right {A B : ProgramState → ProgramState → Prop} {s₁ s₂ : Stmt} {α : Type} {x : Setter α ProgramState} {e : Getter (SubProbability α) ProgramState} (h : prhlStmt A s₁ s₂ fun (σ₁ σ₂ : ProgramState) => ((e.get σ₂).expected fun (x : α) => 1) = 1 ∧ ∀ a ∈ (e.get σ₂).support, B σ₁ (x.set a σ₂)) :

      Sampling on the right only (EC's rnd{2}).

      theorem GaudisCrypt.Stmt.ewp_while_eq_one {c : Getter Bool ProgramState} {body : Stmt} (I : ProgramState → Prop) (V : ProgramState → ℕ) (hll : ∀ (σ : ProgramState), I σ → c.get σ = true → body.ewp (fun (x : ProgramState) => 1) σ = 1) (hvar : ∀ (k : ℕ), hoareStmt (fun (σ : ProgramState) => I σ ∧ c.get σ = true ∧ V σ = k) body fun (τ : ProgramState) => I τ ∧ V τ < k) (σ : ProgramState) (hI : I σ) :
      ewp (StmtWithHoles.while c body) (fun (x : ProgramState) => 1) σ = 1

      A loop terminates with probability 1 from the states of an invariant I under which its body is lossless and strictly decreases a variant V (EC's while{i} I V, the termination half).

      theorem GaudisCrypt.hoareStmt.satisfies {A B : ProgramState → Prop} {s : Stmt} (h : hoareStmt A s B) {σ : ProgramState} (hA : A σ) :
      (programDenotation s σ).satisfies fun (u : Unit × ProgramState) => B u.2

      What a Hoare triple guarantees holds on every outcome.

      theorem GaudisCrypt.prhlStmt_seq_congr_right_snd_on {A B : ProgramState → ProgramState → Prop} {c₁ a b b' : Stmt} (P Q : ProgramState → Prop) (hP : ∀ (σ₁ σ₂ : ProgramState), A σ₁ σ₂ → P σ₂) (ha : hoareStmt P a Q) (hb : ∀ (σ : ProgramState), Q σ → programDenotation b σ = programDenotation b' σ) (h' : prhlStmt A c₁ (StmtWithHoles.seq a b') B) :

      Replace the second statement on the right by one with the same runs from every state the first statement can reach (a Hoare postcondition Q of it): EC's transitivity{2} against a program proven equivalent denotationally after a.

      theorem GaudisCrypt.prhlStmt_seq_while_right {A B : ProgramState → ProgramState → Prop} {s₁ s₂ body : Stmt} {c : Getter Bool ProgramState} (I : ProgramState → ProgramState → Prop) (V : ProgramState → ProgramState → ℕ) (hll : ∀ (σ₁ σ : ProgramState), I σ₁ σ → c.get σ = true → body.ewp (fun (x : ProgramState) => 1) σ = 1) (hvar : ∀ (σ₁ : ProgramState) (k : ℕ), hoareStmt (fun (σ : ProgramState) => I σ₁ σ ∧ c.get σ = true ∧ V σ₁ σ = k) body fun (τ : ProgramState) => I σ₁ τ ∧ V σ₁ τ < k) (hexit : ∀ (σ₁ σ : ProgramState), I σ₁ σ → c.get σ = false → B σ₁ σ) (h : prhlStmt A s₁ s₂ I) :

      A loop on the right only (EC's while{2} I V for a trailing loop): from where the code before it establishes I (for the left state as it ends), the loop terminates (its body lossless and decreasing the variant V under I; both may depend on the left state), keeps I, and I with the failed test gives B.

      theorem GaudisCrypt.prhlStmt_seq_while_left {A B : ProgramState → ProgramState → Prop} {s₁ s₂ body : Stmt} {c : Getter Bool ProgramState} (I : ProgramState → ProgramState → Prop) (V : ProgramState → ProgramState → ℕ) (hll : ∀ (σ₂ σ : ProgramState), I σ σ₂ → c.get σ = true → body.ewp (fun (x : ProgramState) => 1) σ = 1) (hvar : ∀ (σ₂ : ProgramState) (k : ℕ), hoareStmt (fun (σ : ProgramState) => I σ σ₂ ∧ c.get σ = true ∧ V σ σ₂ = k) body fun (τ : ProgramState) => I τ σ₂ ∧ V τ σ₂ < k) (hexit : ∀ (σ₂ σ : ProgramState), I σ σ₂ → c.get σ = false → B σ σ₂) (h : prhlStmt A s₁ s₂ I) :

      A loop on the left only (EC's while{1} I V): prhlStmt_seq_while_right, mirrored.

      Two-sided sampling (EC's rnd f) #

      theorem GaudisCrypt.prhlStmt_seq_sample {A B : ProgramState → ProgramState → Prop} {s₁ s₂ : Stmt} {α β : Type} {x₁ : Setter α ProgramState} {x₂ : Setter β ProgramState} {e₁ : Getter (SubProbability α) ProgramState} {e₂ : Getter (SubProbability β) ProgramState} (f : ProgramState → ProgramState → α → β) (h : prhlStmt A s₁ s₂ fun (σ₁ σ₂ : ProgramState) => (do let a ← e₁.get σ₁ pure (f σ₁ σ₂ a)) = e₂.get σ₂ ∧ ∀ a ∈ (e₁.get σ₁).support, B (x₁.set a σ₁) (x₂.set (f σ₁ σ₂ a) σ₂)) :

      Coupled samplings: the two draws coupled along f (which may depend on the two states before the draws), which must push the left distribution to the right one; the postcondition for every left value in the support, paired with its image.

      theorem GaudisCrypt.prhlStmt_seq_sample_run_right {A B : ProgramState → ProgramState → Prop} {s₁ s₂ : Stmt} {α : Type} {x₁ x₂ : Setter α ProgramState} {e₁ : Getter (SubProbability α) ProgramState} {t : Stmt} (h : prhlStmt A s₁ s₂ fun (σ₁ σ₂ : ProgramState) => (programDenotation t σ₂ = (e₁.get σ₁).hbind fun (a : α) => pure ((), x₂.set a σ₂)) ∧ ∀ a ∈ (e₁.get σ₁).support, B (x₁.set a σ₁) (x₂.set a σ₂)) :

      A sampling against code that samples the same: x₁ <$ d on the left, on the right any statement t whose run (from the state before it) draws from d and writes the draw to x₂ (EC's rnd after rewriting the right side into one sampling, e.g. a two-step sampling).

      theorem GaudisCrypt.prhlStmt_seq_sample_run_map_right {A B : ProgramState → ProgramState → Prop} {s₁ s₂ : Stmt} {α β : Type} {x₁ : Setter α ProgramState} {x₂ : Setter β ProgramState} {e₁ : Getter (SubProbability α) ProgramState} {t : Stmt} (μ : ProgramState → ProgramState → SubProbability β) (f : β → α) (h : prhlStmt A s₁ s₂ fun (σ₁ σ₂ : ProgramState) => (programDenotation t σ₂ = (μ σ₁ σ₂).hbind fun (b : β) => pure ((), x₂.set b σ₂)) ∧ (e₁.get σ₁ = (μ σ₁ σ₂).hbind fun (b : β) => pure (f b)) ∧ ∀ b ∈ (μ σ₁ σ₂).support, B (x₁.set (f b) σ₁) (x₂.set b σ₂)) :

      A sampling against code that samples a preimage: x₁ <$ d on the left, on the right a statement t whose run draws b from μ and writes it to x₂, with d the image of μ by f (prhlStmt_seq_sample_run_right with a map; e.g. a block against a loop of bits).

      Pushing a distribution along a function #

      The first conjunct prhlStmt_seq_sample leaves: the coupling function pushes the left distribution to the right one.

      @[simp]
      theorem GaudisCrypt.SubProbability.bind_pure_id {α : Type} (μ : SubProbability α) :
      (do let a ← μ pure a) = μ

      The identity coupling.

      theorem GaudisCrypt.SubProbability.uniform_bind_pure_bijective {α : Type} [Fintype α] [Nonempty α] {f : α → α} (hf : Function.Bijective f) :
      (do let a ← uniform pure (f a)) = uniform

      A bijection pushes the uniform distribution to itself.

      @[simp]

      Negation pushes the uniform coin to itself (EC's rnd (fun b => !b)).

      @[simp]

      Xor with a constant pushes the uniform coin to itself.

      @[simp]

      The uniform distribution is lossless (the side condition of a one-sided sampling).

      @[simp]
      theorem GaudisCrypt.SubProbability.uniform_bind_add_left {G : Type} [AddGroup G] [Fintype G] [Nonempty G] (m : G) :
      (do let a ← uniform pure (m + a)) = uniform

      A translation pushes the uniform distribution on a group to itself.

      @[simp]
      theorem GaudisCrypt.SubProbability.uniform_bind_sub_right {G : Type} [AddGroup G] [Fintype G] [Nonempty G] (m : G) :
      (do let a ← uniform pure (a - m)) = uniform

      Subtracting a constant pushes the uniform distribution on a group to itself.

      @[simp]
      theorem GaudisCrypt.SubProbability.uniform_bind_add_right {G : Type} [AddGroup G] [Fintype G] [Nonempty G] (m : G) :
      (do let a ← uniform pure (a + m)) = uniform

      A translation on the right pushes the uniform distribution on a group to itself.

      Loops #

      theorem GaudisCrypt.prhlStmt_while {I : ProgramState → ProgramState → Prop} {c₁ c₂ : Getter Bool ProgramState} {b₁ b₂ : Stmt} (hg : ∀ (σ₁ σ₂ : ProgramState), I σ₁ σ₂ → c₁.get σ₁ = c₂.get σ₂) (hb : prhlStmt (fun (σ₁ σ₂ : ProgramState) => I σ₁ σ₂ ∧ c₁.get σ₁ = true) b₁ b₂ I) :
      prhlStmt I (StmtWithHoles.while c₁ b₁) (StmtWithHoles.while c₂ b₂) fun (σ₁ σ₂ : ProgramState) => I σ₁ σ₂ ∧ c₁.get σ₁ = false

      Synchronized loops: under the invariant the guards agree, and the bodies keep the invariant; on exit, the invariant and the (common) guard false.

      theorem GaudisCrypt.prhlStmt_seq_while {I B : ProgramState → ProgramState → Prop} {c₁ c₂ : Getter Bool ProgramState} {b₁ b₂ : Stmt} {A : ProgramState → ProgramState → Prop} {s₁ s₂ : Stmt} (hg : ∀ (σ₁ σ₂ : ProgramState), I σ₁ σ₂ → c₁.get σ₁ = c₂.get σ₂) (hb : prhlStmt (fun (σ₁ σ₂ : ProgramState) => I σ₁ σ₂ ∧ c₁.get σ₁ = true) b₁ b₂ I) (hexit : ∀ (σ₁ σ₂ : ProgramState), I σ₁ σ₂ → c₁.get σ₁ = false → B σ₁ σ₂) (hpre : prhlStmt A s₁ s₂ I) :

      The loop rule at the end of both sides, as the tactic applies it: the body keeps I, I and the guard false give B, and the code before the loops establishes I.

      The fixed-point equation of a loop, on denotations.

      A loop whose guard is false does nothing.

      theorem GaudisCrypt.prhlStmt_seq_while_false_left {A B : ProgramState → ProgramState → Prop} {c : Getter Bool ProgramState} {body s₁ s₂ : Stmt} (h : prhlStmt A s₁ s₂ fun (σ₁ σ₂ : ProgramState) => c.get σ₁ = false ∧ B σ₁ σ₂) :

      A loop on the left that does not run (EC's rcondf{1}, for a trailing loop): its guard is false where it starts.

      theorem GaudisCrypt.prhlStmt_seq_while_false_right {A B : ProgramState → ProgramState → Prop} {c : Getter Bool ProgramState} {body s₁ s₂ : Stmt} (h : prhlStmt A s₁ s₂ fun (σ₁ σ₂ : ProgramState) => c.get σ₂ = false ∧ B σ₁ σ₂) :

      A loop on the right that does not run (EC's rcondf{2}).

      Conditionals #

      theorem GaudisCrypt.prhlStmt_if {A B : ProgramState → ProgramState → Prop} {c₁ c₂ : Getter Bool ProgramState} {t₁ t₂ e₁ e₂ : Stmt} (hg : ∀ (σ₁ σ₂ : ProgramState), A σ₁ σ₂ → c₁.get σ₁ = c₂.get σ₂) (ht : prhlStmt (fun (σ₁ σ₂ : ProgramState) => A σ₁ σ₂ ∧ c₁.get σ₁ = true) t₁ t₂ B) (he : prhlStmt (fun (σ₁ σ₂ : ProgramState) => A σ₁ σ₂ ∧ c₁.get σ₁ = false) e₁ e₂ B) :
      prhlStmt A (StmtWithHoles.ifThenElse c₁ t₁ e₁) (StmtWithHoles.ifThenElse c₂ t₂ e₂) B

      Synchronized conditionals: the guards agree, and the branches are related.

      theorem GaudisCrypt.prhlStmt_if_left {A B : ProgramState → ProgramState → Prop} {c₁ : Getter Bool ProgramState} {t₁ e₁ s : Stmt} (ht : prhlStmt (fun (σ₁ σ₂ : ProgramState) => A σ₁ σ₂ ∧ c₁.get σ₁ = true) t₁ s B) (he : prhlStmt (fun (σ₁ σ₂ : ProgramState) => A σ₁ σ₂ ∧ c₁.get σ₁ = false) e₁ s B) :
      prhlStmt A (StmtWithHoles.ifThenElse c₁ t₁ e₁) s B

      A conditional on the left only (EC's if{1}): each branch against the right side.

      theorem GaudisCrypt.prhlStmt_if_right {A B : ProgramState → ProgramState → Prop} {c₂ : Getter Bool ProgramState} {t₂ e₂ s : Stmt} (ht : prhlStmt (fun (σ₁ σ₂ : ProgramState) => A σ₁ σ₂ ∧ c₂.get σ₂ = true) s t₂ B) (he : prhlStmt (fun (σ₁ σ₂ : ProgramState) => A σ₁ σ₂ ∧ c₂.get σ₂ = false) s e₂ B) :
      prhlStmt A s (StmtWithHoles.ifThenElse c₂ t₂ e₂) B

      A conditional on the right only (EC's if{2}).

      Judgments about equivalent statements #

      Along s.EquivInLens s' l, a judgment about s on one side is the judgment about s' with the conditions read through l on that side: what stmt_inline and stmt_split use, per side.

      theorem GaudisCrypt.prhlStmt_of_equivInLens_left {A A' B B' : ProgramState → ProgramState → Prop} {s s' t : Stmt} {l : Lens ProgramState ProgramState} (h : StmtWithHoles.EquivInLens s s' l) (hA : (fun (τ σ : ProgramState) => A (l.get τ) σ) = A') (hB : (fun (τ σ : ProgramState) => B (l.get τ) σ) = B') (h' : prhlStmt A' s' t B') :
      prhlStmt A s t B

      Transport on the left side, the conditions given up to an equation (as the inliner cleans them).

      theorem GaudisCrypt.prhlStmt_of_equivInLens_right {A A' B B' : ProgramState → ProgramState → Prop} {s t t' : Stmt} {l : Lens ProgramState ProgramState} (h : StmtWithHoles.EquivInLens t t' l) (hA : (fun (σ τ : ProgramState) => A σ (l.get τ)) = A') (hB : (fun (σ τ : ProgramState) => B σ (l.get τ)) = B') (h' : prhlStmt A' s t' B') :
      prhlStmt A s t B

      Transport on the right side.

      theorem GaudisCrypt.prhlStmt_of_equiv_left {A B : ProgramState → ProgramState → Prop} {s s' t : Stmt} (h : StmtWithHoles.Equiv s s') (h' : prhlStmt A s' t B) :
      prhlStmt A s t B

      Transport on the left, without renaming.

      theorem GaudisCrypt.prhlStmt_of_equiv_right {A B : ProgramState → ProgramState → Prop} {s t t' : Stmt} (h : StmtWithHoles.Equiv t t') (h' : prhlStmt A s t' B) :
      prhlStmt A s t B

      Transport on the right, without renaming.

      Procedures #

      A call statement's run: the callee's, its result written to x and its globals kept.

      theorem GaudisCrypt.Stmt.call_wp_one {sig : ProcedureSignature} {p : Procedure sig} (hp : p.IsLossless) (x : Setter sig.ret ProgramState) (args : Getter sig.ParamType ProgramState) (σ : ProgramState) :
      (programDenotation (call x p args)).wp (fun (x : Unit × ProgramState) => 1) σ = 1

      A call of a lossless procedure terminates (the losslessness half of EC's call{1} p_ll).

      Every outcome of a call is the caller's state with the callee's result and globals written back, for an outcome of the callee.

      theorem GaudisCrypt.prhlProc_of_prhlStmt {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} (resL₁ : Lens sig₁.ret VariableAssignment) (argsL₁ : Lens sig₁.ParamType VariableAssignment) (resL₂ : Lens sig₂.ret VariableAssignment) (argsL₂ : Lens sig₂.ParamType VariableAssignment) (h : prhlStmt (fun (σ₁ σ₂ : ProgramState) => A (argsL₁.get σ₁.locals) σ₁.globals (argsL₂.get σ₂.locals) σ₂.globals) (Stmt.call resL₁.intoLocal.toSetter p₁ argsL₁.intoLocal.toGetter) (Stmt.call resL₂.intoLocal.toSetter p₂ argsL₂.intoLocal.toGetter) fun (σ₁ σ₂ : ProgramState) => B (resL₁.get σ₁.locals) σ₁.globals (resL₂.get σ₂.locals) σ₂.globals) :
      prhlProc A p₁ p₂ B

      From a procedure judgment to a statement judgment: the procedures' judgment is the one about the two call statements res <- call pᵢ (args), the arguments in local slots argsLᵢ and the results in local slots resLᵢ (phoareProc_as_phoareStmt for pRHL).

      theorem GaudisCrypt.Procedure.ewp_eq_of_prhlProc {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} (h : prhlProc A p₁ p₂ B) {F : sig₁.ret → VariableAssignment → ENNReal} {G : sig₂.ret → VariableAssignment → ENNReal} (hFG : ∀ (r₁ : sig₁.ret) (g₁ : VariableAssignment) (r₂ : sig₂.ret) (g₂ : VariableAssignment), B r₁ g₁ r₂ g₂ → F r₁ g₁ = G r₂ g₂) {a₁ : sig₁.ParamType} {a₂ : sig₂.ParamType} {σ₁ σ₂ : VariableAssignment} (hA : A a₁ σ₁ a₂ σ₂) :
      p₁.ewp a₁ F σ₁ = p₂.ewp a₂ G σ₂

      EC's byequiv, for expectations: expectations that agree on related outcomes are equal.

      theorem GaudisCrypt.Procedure.Pr_eq_of_prhlProc {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} (h : prhlProc A p₁ p₂ B) {E₁ : sig₁.ret → VariableAssignment → Prop} {E₂ : sig₂.ret → VariableAssignment → Prop} (hE : ∀ (r₁ : sig₁.ret) (g₁ : VariableAssignment) (r₂ : sig₂.ret) (g₂ : VariableAssignment), B r₁ g₁ r₂ g₂ → (E₁ r₁ g₁ ↔ E₂ r₂ g₂)) {a₁ : sig₁.ParamType} {a₂ : sig₂.ParamType} {σ₁ σ₂ : VariableAssignment} (hA : A a₁ σ₁ a₂ σ₂) :
      p₁.Pr a₁ σ₁ E₁ = p₂.Pr a₂ σ₂ E₂

      EC's byequiv: events that agree on related outcomes have the same probability.

      theorem GaudisCrypt.Procedure.Pr_le_of_prhlProc {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} (h : prhlProc A p₁ p₂ B) {E₁ : sig₁.ret → VariableAssignment → Prop} {E₂ : sig₂.ret → VariableAssignment → Prop} (hE : ∀ (r₁ : sig₁.ret) (g₁ : VariableAssignment) (r₂ : sig₂.ret) (g₂ : VariableAssignment), B r₁ g₁ r₂ g₂ → E₁ r₁ g₁ → E₂ r₂ g₂) {a₁ : sig₁.ParamType} {a₂ : sig₂.ParamType} {σ₁ σ₂ : VariableAssignment} (hA : A a₁ σ₁ a₂ σ₂) :
      p₁.Pr a₁ σ₁ E₁ ≤ p₂.Pr a₂ σ₂ E₂

      EC's byequiv, one-sided: if related outcomes in E₁ are in E₂, then E₁ is at most as likely as E₂.

      theorem GaudisCrypt.prhlProc.symm {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} (h : prhlProc A p₁ p₂ B) :
      prhlProc (fun (a₂ : sig₂.ParamType) (g₂ : VariableAssignment) (a₁ : sig₁.ParamType) (g₁ : VariableAssignment) => A a₁ g₁ a₂ g₂) p₂ p₁ fun (r₂ : sig₂.ret) (g₂ : VariableAssignment) (r₁ : sig₁.ret) (g₁ : VariableAssignment) => B r₁ g₁ r₂ g₂

      Symmetry of procedure judgments: the two sides swapped.

      theorem GaudisCrypt.prhlProc_of_symm {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} (h : prhlProc (fun (a₂ : sig₂.ParamType) (g₂ : VariableAssignment) (a₁ : sig₁.ParamType) (g₁ : VariableAssignment) => A a₁ g₁ a₂ g₂) p₂ p₁ fun (r₂ : sig₂.ret) (g₂ : VariableAssignment) (r₁ : sig₁.ret) (g₁ : VariableAssignment) => B r₁ g₁ r₂ g₂) :
      prhlProc A p₁ p₂ B

      Symmetry of procedure judgments, backwards: the judgment with the sides swapped.

      theorem GaudisCrypt.Procedure.Pr_or_le {sig : ProcedureSignature} (p : Procedure sig) (args : sig.ParamType) (σ : VariableAssignment) (E F : sig.ret → VariableAssignment → Prop) :
      (p.Pr args σ fun (r : sig.ret) (g : VariableAssignment) => E r g ∨ F r g) ≤ p.Pr args σ E + p.Pr args σ F

      The union bound for a procedure's events.

      theorem GaudisCrypt.Procedure.Pr_abs_sub_le_of_prhlProc_upto {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} (h : prhlProc A p₁ p₂ B) {E₁ bad₁ : sig₁.ret → VariableAssignment → Prop} {E₂ bad₂ : sig₂.ret → VariableAssignment → Prop} (hbad : ∀ (r₁ : sig₁.ret) (g₁ : VariableAssignment) (r₂ : sig₂.ret) (g₂ : VariableAssignment), B r₁ g₁ r₂ g₂ → (bad₁ r₁ g₁ ↔ bad₂ r₂ g₂)) (hE : ∀ (r₁ : sig₁.ret) (g₁ : VariableAssignment) (r₂ : sig₂.ret) (g₂ : VariableAssignment), B r₁ g₁ r₂ g₂ → ¬bad₂ r₂ g₂ → (E₁ r₁ g₁ ↔ E₂ r₂ g₂)) {a₁ : sig₁.ParamType} {a₂ : sig₂.ParamType} {σ₁ σ₂ : VariableAssignment} (hA : A a₁ σ₁ a₂ σ₂) :
      |↑(p₁.Pr a₁ σ₁ E₁) - ↑(p₂.Pr a₂ σ₂ E₂)| ≤ ↑(p₂.Pr a₂ σ₂ bad₂)

      EC's byequiv: bad (the fundamental lemma): if related outcomes agree on the bad events, and on the events outside them, the events' probabilities differ by at most the bad event's.

      theorem GaudisCrypt.prhlStmt_seq_call {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} (h : prhlProc A p₁ p₂ B) {x₁ : Setter sig₁.ret ProgramState} {e₁ : Getter sig₁.ParamType ProgramState} {x₂ : Setter sig₂.ret ProgramState} {e₂ : Getter sig₂.ParamType ProgramState} {A' B' : ProgramState → ProgramState → Prop} {s₁ s₂ : Stmt} (hpre : prhlStmt A' s₁ s₂ fun (σ₁ σ₂ : ProgramState) => A (e₁.get σ₁) σ₁.globals (e₂.get σ₂) σ₂.globals ∧ ∀ (r₁ : sig₁.ret) (g₁ : VariableAssignment) (r₂ : sig₂.ret) (g₂ : VariableAssignment), B r₁ g₁ r₂ g₂ → B' (x₁.set r₁ (ProgramState.globalL.set g₁ σ₁)) (x₂.set r₂ (ProgramState.globalL.set g₂ σ₂))) :
      prhlStmt A' (StmtWithHoles.seq s₁ (Stmt.call x₁ p₁ e₁)) (StmtWithHoles.seq s₂ (Stmt.call x₂ p₂ e₂)) B'

      Calls on both sides, with a procedure judgment (EC's call (_ : P ==> Q)): the callees' runs coupled by h, from the arguments and globals before the calls; the postcondition for every results and globals h relates, written back.

      theorem GaudisCrypt.prhlProc.trans {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} {sig₃ : ProcedureSignature} {p₃ : Procedure sig₃} {A₂ : sig₂.ParamType → VariableAssignment → sig₃.ParamType → VariableAssignment → Prop} {B₂ : sig₂.ret → VariableAssignment → sig₃.ret → VariableAssignment → Prop} (h₁ : prhlProc A p₁ p₂ B) (h₂ : prhlProc A₂ p₂ p₃ B₂) :
      prhlProc (fun (a₁ : sig₁.ParamType) (g₁ : VariableAssignment) (a₃ : sig₃.ParamType) (g₃ : VariableAssignment) => ∃ (a₂ : sig₂.ParamType) (g₂ : VariableAssignment), A a₁ g₁ a₂ g₂ ∧ A₂ a₂ g₂ a₃ g₃) p₁ p₃ fun (r₁ : sig₁.ret) (g₁ : VariableAssignment) (r₃ : sig₃.ret) (g₃ : VariableAssignment) => ∃ (r₂ : sig₂.ret) (g₂ : VariableAssignment), B r₁ g₁ r₂ g₂ ∧ B₂ r₂ g₂ r₃ g₃

      Transitivity of procedure judgments (game hopping): couplings of p₁ with p₂ and of p₂ with p₃ glue along p₂ (ProgramDenotation.prhl2.trans).

      theorem GaudisCrypt.prhlProc_conseq {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} {A' : sig₁.ParamType → VariableAssignment → sig₂.ParamType → VariableAssignment → Prop} {B' : sig₁.ret → VariableAssignment → sig₂.ret → VariableAssignment → Prop} (h : prhlProc A' p₁ p₂ B') (hA : ∀ (a₁ : sig₁.ParamType) (g₁ : VariableAssignment) (a₂ : sig₂.ParamType) (g₂ : VariableAssignment), A a₁ g₁ a₂ g₂ → A' a₁ g₁ a₂ g₂) (hB : ∀ (r₁ : sig₁.ret) (g₁ : VariableAssignment) (r₂ : sig₂.ret) (g₂ : VariableAssignment), B' r₁ g₁ r₂ g₂ → B r₁ g₁ r₂ g₂) :
      prhlProc A p₁ p₂ B

      Consequence for procedure judgments.

      Abstract procedures (EC's call (_ : ={glob A})) #

      theorem GaudisCrypt.prhlProc_refl {sig : ProcedureSignature} (p : Procedure sig) :
      prhlProc (fun (a₁ : sig.ParamType) (g₁ : VariableAssignment) (a₂ : sig.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ g₁ = g₂) p p fun (r₁ : sig.ret) (g₁ : VariableAssignment) (r₂ : sig.ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ g₁ = g₂

      Reflexivity: any procedure, on equal arguments from equal globals, can be coupled with itself to equal results and equal globals (EC's call (_ : true) on the same code).

      theorem GaudisCrypt.prhlStmt_seq_call_refl {sig : ProcedureSignature} {p : Procedure sig} {x₁ x₂ : Setter sig.ret ProgramState} {e₁ e₂ : Getter sig.ParamType ProgramState} {A B : ProgramState → ProgramState → Prop} {s₁ s₂ : Stmt} (hpre : prhlStmt A s₁ s₂ fun (σ₁ σ₂ : ProgramState) => e₁.get σ₁ = e₂.get σ₂ ∧ σ₁.globals = σ₂.globals ∧ ∀ (r : sig.ret) (g : VariableAssignment), B (x₁.set r (ProgramState.globalL.set g σ₁)) (x₂.set r (ProgramState.globalL.set g σ₂))) :
      prhlStmt A (StmtWithHoles.seq s₁ (Stmt.call x₁ p e₁)) (StmtWithHoles.seq s₂ (Stmt.call x₂ p e₂)) B

      Calls of the same procedure on both sides (EC's call (_ : true) on the same code): from equal arguments and equal globals, the two calls return the same result and the same globals (prhlProc_refl), so the postcondition must hold for every result r and globals g written back on both sides.

      theorem GaudisCrypt.prhlStmt_seq_call_eq {sig : ProcedureSignature} {p₁ p₂ : Procedure sig} (hp : p₁ = p₂) {x₁ x₂ : Setter sig.ret ProgramState} {e₁ e₂ : Getter sig.ParamType ProgramState} {A B : ProgramState → ProgramState → Prop} {s₁ s₂ : Stmt} (hpre : prhlStmt A s₁ s₂ fun (σ₁ σ₂ : ProgramState) => e₁.get σ₁ = e₂.get σ₂ ∧ σ₁.globals = σ₂.globals ∧ ∀ (r : sig.ret) (g : VariableAssignment), B (x₁.set r (ProgramState.globalL.set g σ₁)) (x₂.set r (ProgramState.globalL.set g σ₂))) :
      prhlStmt A (StmtWithHoles.seq s₁ (Stmt.call x₁ p₁ e₁)) (StmtWithHoles.seq s₂ (Stmt.call x₂ p₂ e₂)) B

      prhlStmt_seq_call_refl for callees that are equal but not spelled the same (modules built differently that reduce to the same procedure): their equality is a premise.

      theorem GaudisCrypt.prhlProc_glob {sig : ProcedureSignature} {p : Procedure sig} {R : Footprint VariableAssignment} (hp : ∀ (a : sig.ParamType), (procedureDenotation p a).inFootprint R) :
      prhlProc (fun (a₁ : sig.ParamType) (g₁ : VariableAssignment) (a₂ : sig.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ R.touched_getter.get g₁ = R.touched_getter.get g₂) p p fun (r₁ : sig.ret) (g₁ : VariableAssignment) (r₂ : sig.ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ R.touched_getter.get g₁ = R.touched_getter.get g₂

      The adversary rule: a procedure confined to the footprint R (on every argument), run on equal arguments from globals that agree on what it can touch (R.touched_getter, EC's glob A), returns equal results and globals that again agree on it (prhl2_glob).