Documentation

GaudisCrypt.Logic.EagerBridge

From relational statements to the eager judgment #

ProgramDenotation.eagerR S S (=) p q (=) (Logic/EagerRhl.lean) is a judgment about two composite programs on the globals, S; p and q; S. EasyCrypt proves its eager lemmas by the relational tactics on those composites. This file lets the equiv_* tactics do the same.

A run confined to X keeps the content outside X.

theorem GaudisCrypt.Lens.eq_of_get_compl_get {Ω : Type} (X : Lens Ω VariableAssignment) {x y : VariableAssignment} (h₁ : X.get x = X.get y) (h₂ : X.compl.get x = X.compl.get y) :
x = y

Two states that agree on X and outside it are equal.

theorem GaudisCrypt.ProgramDenotation.eagerR_of_prhl2_lens {Ω : Type} (X : Lens Ω VariableAssignment) {α : Type} {S : ProgramDenotation VariableAssignment Unit} {p q : ProgramDenotation VariableAssignment α} (hS : S.inFootprint X.footprint) (hp : p.inFootprint X.footprint) (hq : q.inFootprint X.footprint) (h : prhl2 (fun (σ₁ σ₂ : VariableAssignment) => σ₁ = σ₂) (do S p) (do let a ← q S pure a) fun (u v : α × VariableAssignment) => u.1 = v.1 ∧ X.get u.2 = X.get v.2) :
S.eagerR S (fun (σ₁ σ₂ : VariableAssignment) => σ₁ = σ₂) p q fun (u v : α × VariableAssignment) => u = v

The frame for the eager judgment: with S, p and q confined to X, a coupling of S; p and q; S with equal results and equal X gives the equality-invariant judgment.

theorem GaudisCrypt.ProgramDenotation.prhl2_refl_of_inFootprint {Ω : Type} (X : Lens Ω VariableAssignment) {α : Type} {p : ProgramDenotation VariableAssignment α} (hp : p.inFootprint X.footprint) :
prhl2 (fun (g₁ g₂ : VariableAssignment) => X.get g₁ = X.get g₂) p p fun (u v : α × VariableAssignment) => u.1 = v.1 ∧ X.get u.2 = X.get v.2

A run confined to X from two states equal on X (EC's sim on code touching only X): the two runs couple with equal results and equal X. The second state is the first with its outside replaced, a deterministic update outside X, which the run commutes with.

theorem GaudisCrypt.prhlProc_refl_of_inFootprint {Ω : Type} (X : Lens Ω VariableAssignment) {sig : ProcedureSignature} (p : Procedure sig) (hp : ∀ (a : sig.ParamType), (procedureDenotation p a).inFootprint X.footprint) :
prhlProc (fun (a₁ : sig.ParamType) (g₁ : VariableAssignment) (a₂ : sig.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ X.get g₁ = X.get g₂) p p fun (r₁ : sig.ret) (g₁ : VariableAssignment) (r₂ : sig.ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ X.get g₁ = X.get g₂

ProgramDenotation.prhl2_refl_of_inFootprint for a procedure: EC's sim on an oracle procedure whose code touches only X, from ={arg, X} to ={res, X}.

theorem GaudisCrypt.prhlProc_refl_of_within {Ω : Type} (X : Lens Ω VariableAssignment) {sig : ProcedureSignature} (p : Procedure sig) (hb : StmtWithHoles.Within X p.body) (hr : Getter.Within X p.return_val) :
prhlProc (fun (a₁ : sig.ParamType) (g₁ : VariableAssignment) (a₂ : sig.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ X.get g₁ = X.get g₂) p p fun (r₁ : sig.ret) (g₁ : VariableAssignment) (r₂ : sig.ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ X.get g₁ = X.get g₂

prhlProc_refl_of_inFootprint for a procedure within X (within_lens).

theorem GaudisCrypt.ProgramDenotation.prhl2_lossless_left {α β : Type} {A : VariableAssignment → VariableAssignment → Prop} {p : ProgramDenotation VariableAssignment α} (b : β) {B : α × VariableAssignment → β × VariableAssignment → Prop} (hloss : ∀ (σ : VariableAssignment), ((p σ).expected fun (x : α × VariableAssignment) => 1) = 1) (h : ∀ (σ₁ σ₂ : VariableAssignment), A σ₁ σ₂ → (p σ₁).satisfies fun (u : α × VariableAssignment) => B u (b, σ₂)) :
prhl2 A p (pure b) B

A run on the left only, against a value on the right: lossless, and the postcondition on all its outcomes (ProgramDenotation.prhl2.kill_left for any result types).

The composites as statements #

theorem GaudisCrypt.programDenotation_hcall_apply {sig : ProcedureSignature} (x : Setter sig.ret ProgramState) (p : Procedure sig) (args : Getter sig.ParamType ProgramState) (σ : ProgramState) :
programDenotation (GaudiProg[ x <- call p (§args); ]) σ = (procedureDenotation p (args.get σ) σ.globals).hbind fun (r : sig.ret × VariableAssignment) => pure ((), x.set r.1 (ProgramState.globalL.set r.2 σ))

programDenotation_call_apply, for StmtWithHoles.call (the form the program syntax and the inliner use).

_ <- R(); y <- p(a): the eager side's composite, as a statement.

Equations
Instances For

    y <- q(a); _ <- R(): the lazy side's composite, as a statement.

    Equations
    Instances For
      theorem GaudisCrypt.eagerLeftStmt_denotation {sig : ProcedureSignature} (R : proctype () → Unit) (p : Procedure sig) (a : sig.ParamType) {y : Lens sig.ret ProgramState} (hy : ∀ (v : sig.ret) (σ : ProgramState), (y.set v σ).globals = σ.globals) (g loc : VariableAssignment) :
      (procedureDenotation R () >>= fun (x : (procsig () → Unit).ret) => procedureDenotation p a) g = (programDenotation (eagerLeftStmt R p a y) { globals := g, locals := loc }).hbind fun (u : Unit × ProgramState) => pure (y.get u.2, u.2.globals)
      theorem GaudisCrypt.eagerRightStmt_denotation {sig : ProcedureSignature} (R : proctype () → Unit) (q : Procedure sig) (a : sig.ParamType) {y : Lens sig.ret ProgramState} (hy : ∀ (v : sig.ret) (σ : ProgramState), (y.set v σ).globals = σ.globals) (hyg : ∀ (g : VariableAssignment) (σ : ProgramState), y.get (ProgramState.globalL.set g σ) = y.get σ) (g loc : VariableAssignment) :
      (procedureDenotation q a >>= fun (r : sig.ret) => do let _ ← procedureDenotation R () pure r) g = (programDenotation (eagerRightStmt R q a y) { globals := g, locals := loc }).hbind fun (u : Unit × ProgramState) => pure (y.get u.2, u.2.globals)
      theorem GaudisCrypt.eagerR_of_prhlStmt {Ω : Type} (X : Lens Ω VariableAssignment) {sig : ProcedureSignature} (R : proctype () → Unit) (p q : Procedure sig) (a : sig.ParamType) {y : Lens sig.ret ProgramState} (hy : ∀ (v : sig.ret) (σ : ProgramState), (y.set v σ).globals = σ.globals) (hR : (procedureDenotation R ()).inFootprint X.footprint) (hp : (procedureDenotation p a).inFootprint X.footprint) (hq : (procedureDenotation q a).inFootprint X.footprint) (hyg : ∀ (g : VariableAssignment) (σ : ProgramState), y.get (ProgramState.globalL.set g σ) = y.get σ) (h : prhlStmt (fun (σ₁ σ₂ : ProgramState) => X.get σ₁.globals = X.get σ₂.globals) (eagerLeftStmt R p a y) (eagerRightStmt R q a y) fun (σ₁ σ₂ : ProgramState) => y.get σ₁ = y.get σ₂ ∧ X.get σ₁.globals = X.get σ₂.globals) :
      (procedureDenotation R ()).eagerR (procedureDenotation R ()) (fun (σ₁ σ₂ : VariableAssignment) => σ₁ = σ₂) (procedureDenotation p a) (procedureDenotation q a) fun (u v : sig.ret × VariableAssignment) => u = v

      From statements to the eager judgment: a prhlStmt between _ <- R(); y <- p(a) and y <- q(a); _ <- R(), from equal X to equal y and equal X, is the equality-invariant eager judgment, when R, p and q are confined to X. EasyCrypt's eager proc on a concrete pair of procedures, followed by its relational proof.