Documentation

GaudisCrypt.Logic.ECCallUpto

EasyCrypt's up-to-bad abstract call call (_: bad, I, J) — the rule #

equiv_call (_ : §G1.bcol ∨ §G1.bext, ={C.c, C.queries} ∧ INV …, FMap.dom §C.queries{2} [])

EC's call (_: bad, I, J) on D(O₁).f ~ D(O₂).f (D declared, O₁, O₂ concrete): before the bad event (on the right) the two runs agree on glob D, the results and I; after it, only J is kept. prhlProc_abstract_call_upto_ec is prhlProc_abstract_call_upto_module (Logic/AbstractCallUpto.lean) with EC's premises:

Deviation (exception E11 of the SHA-3 port, notes/SHA3/Exceptions.md): EC asks the left oracles lossless only after the bad event (forall &2, bad{2} => phoare[ O₁.o : J ==> J ] = 1), and D_ll with them; the rule here asks D(O₁), D(O₂) lossless outright (the tactic derives that from D_ll and each oracle's islossless), since its coupling after the bad event needs the adversary's remaining runs lossless. Every use in the SHA-3 proofs proves the oracles lossless outright.

The tactic equiv_call (_ : bad, I[, J]) (bad unsided, about the right state; I, J relational): the global variables the three read become the view L (EC's invariants on memories, here on L's contents), and the goals come in EC's order —

  1. D_ll's statement (∀ (F <: … {-D}) (P <: … {-D}), islossless P.f → … → islossless D(F, P), the oracles' procedures in EC's order: the last component's first), closed by exact D_ll (for D declared with glob R, Logic/DeclareModule.lean, the statement is against R: ∀ (F <: … {-R}) …);
  2. per oracle procedure, in that order: the equivalence, the left oracle's islossless, the right one's phoare[ … : bad ∧ J ==> bad ∧ J ] = 1, and (the deviation) the right one's islossless;
  3. the code before the calls. The frame (={glob D} kept by the oracles), L's disjointness from D, the oracles' countable arguments and, when J does not read the left side, J's preservation on the left are closed.
theorem GaudisCrypt.hoareProc_of_phoareProc_eq_one {sig : ProcedureSignature} {A : sig.ParamType → VariableAssignment → Prop} {p : Procedure sig} {B : sig.ret → VariableAssignment → Prop} (h : phoareProc A p (fun (v : sig.ret) (g : VariableAssignment) => indicatorE (B v g)) Eq fun (x : sig.ParamType) (x_1 : VariableAssignment) => 1) :
hoareProc A p B

phoare[ p : A ==> B ] = 1: B holds after every run from A (a Hoare triple).

theorem GaudisCrypt.prhlProc_abstract_call_upto_ec {Ω : Type} (L : Lens Ω VariableAssignment) {T : Type 1} [IsModule T] {sig : ProcedureSignature} {holes : HoleSigs} (D : Module.Arr T (Module.Proc sig)) (ext : T → holes.Instantiation) (hD : Module.Representable D ext) (hDL : FVP.fvP D ≤ L.footprintᶜ) (hc : ∀ {sig' : ProcedureSignature} (a : HoleIndex holes sig'), Countable sig'.ParamType) (bad : Ω → Prop) (I Q : Ω → Ω → Prop) (O₁ O₂ : T) (hll₁ : (Module.app D O₁).procedure.IsLossless) (hll₂ : (Module.app D O₂).procedure.IsLossless) (hwk₁ : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), StmtWithHoles.WritesKeep (FVP.fvP D).touched_getter.get ((ext O₁).lookup n).body) (hwk₂ : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), StmtWithHoles.WritesKeep (FVP.fvP D).touched_getter.get ((ext O₂).lookup n).body) (horacle : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), prhlProc (fun (a₁ : sig'.ParamType) (g₁ : VariableAssignment) (a₂ : sig'.ParamType) (g₂ : VariableAssignment) => ¬bad (L.get g₂) ∧ a₁ = a₂ ∧ I (L.get g₁) (L.get g₂)) ((ext O₁).lookup n) ((ext O₂).lookup n) fun (r₁ : sig'.ret) (g₁ : VariableAssignment) (r₂ : sig'.ret) (g₂ : VariableAssignment) => if bad (L.get g₂) then Q (L.get g₁) (L.get g₂) else r₁ = r₂ ∧ I (L.get g₁) (L.get g₂)) (hQ₁ : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig') (ω₂ : Ω), bad ω₂ → hoareProc (fun (x : sig'.ParamType) (g : VariableAssignment) => Q (L.get g) ω₂) ((ext O₁).lookup n) fun (x : sig'.ret) (g : VariableAssignment) => Q (L.get g) ω₂) (hQ₂ : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig') (ω₁ : Ω), phoareProc (fun (x : sig'.ParamType) (g : VariableAssignment) => bad (L.get g) ∧ Q ω₁ (L.get g)) ((ext O₂).lookup n) (fun (x : sig'.ret) (g : VariableAssignment) => indicatorE (bad (L.get g) ∧ Q ω₁ (L.get g))) Eq fun (x : sig'.ParamType) (x_1 : VariableAssignment) => 1) :
prhlProc (fun (a₁ : sig.ParamType) (g₁ : VariableAssignment) (a₂ : sig.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ syncInv L (FVP.fvP D) I bad g₁ g₂) (Module.app D O₁).procedure (Module.app D O₂).procedure fun (r₁ : sig.ret) (g₁ : VariableAssignment) (r₂ : sig.ret) (g₂ : VariableAssignment) => badInv L bad Q g₁ g₂ ∨ r₁ = r₂ ∧ syncInv L (FVP.fvP D) I bad g₁ g₂

EC's call (_: bad, I, J) on an abstract procedure: see the module docstring.

theorem GaudisCrypt.prhlProc_abstract_call_upto_ecF {Ω : Type} (L : Lens Ω VariableAssignment) {T : Type 1} [IsModule T] {sig : ProcedureSignature} {holes : HoleSigs} (D : Module.Arr T (Module.Proc sig)) (ext : T → holes.Instantiation) (hD : Module.Representable D ext) (F : Footprint VariableAssignment) (hDF : FVP.fvP D ≤ F) (hFL : F ≤ L.footprintᶜ) (hc : ∀ {sig' : ProcedureSignature} (a : HoleIndex holes sig'), Countable sig'.ParamType) (bad : Ω → Prop) (I Q : Ω → Ω → Prop) (O₁ O₂ : T) (hll₁ : (Module.app D O₁).procedure.IsLossless) (hll₂ : (Module.app D O₂).procedure.IsLossless) (horacle : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), prhlProc (fun (a₁ : sig'.ParamType) (g₁ : VariableAssignment) (a₂ : sig'.ParamType) (g₂ : VariableAssignment) => ¬bad (L.get g₂) ∧ a₁ = a₂ ∧ F.touched_getter.get g₁ = F.touched_getter.get g₂ ∧ I (L.get g₁) (L.get g₂)) ((ext O₁).lookup n) ((ext O₂).lookup n) fun (r₁ : sig'.ret) (g₁ : VariableAssignment) (r₂ : sig'.ret) (g₂ : VariableAssignment) => if bad (L.get g₂) then Q (L.get g₁) (L.get g₂) else r₁ = r₂ ∧ F.touched_getter.get g₁ = F.touched_getter.get g₂ ∧ I (L.get g₁) (L.get g₂)) (hQ₁ : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig') (ω₂ : Ω), bad ω₂ → hoareProc (fun (x : sig'.ParamType) (g : VariableAssignment) => Q (L.get g) ω₂) ((ext O₁).lookup n) fun (x : sig'.ret) (g : VariableAssignment) => Q (L.get g) ω₂) (hQ₂ : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig') (ω₁ : Ω), phoareProc (fun (x : sig'.ParamType) (g : VariableAssignment) => bad (L.get g) ∧ Q ω₁ (L.get g)) ((ext O₂).lookup n) (fun (x : sig'.ret) (g : VariableAssignment) => indicatorE (bad (L.get g) ∧ Q ω₁ (L.get g))) Eq fun (x : sig'.ParamType) (x_1 : VariableAssignment) => 1) :
prhlProc (fun (a₁ : sig.ParamType) (g₁ : VariableAssignment) (a₂ : sig.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ syncInv L F I bad g₁ g₂) (Module.app D O₁).procedure (Module.app D O₂).procedure 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₂

EC's call (_: bad, I, J) with ={glob P, …} in I: prhlProc_abstract_call_upto_ec with the region F of those globs (and glob D) kept equal, which the oracles' judgments keep themselves (they may change it: glob P of an oracle's own module).

theorem GaudisCrypt.prhlProc_abstract_call_upto_ecF_bad {Ω : Type} (L : Lens Ω VariableAssignment) {T : Type 1} [IsModule T] {sig : ProcedureSignature} {holes : HoleSigs} (D : Module.Arr T (Module.Proc sig)) (ext : T → holes.Instantiation) (hD : Module.Representable D ext) (F : Footprint VariableAssignment) (hDF : FVP.fvP D ≤ F) (hFL : F ≤ L.footprintᶜ) (hc : ∀ {sig' : ProcedureSignature} (a : HoleIndex holes sig'), Countable sig'.ParamType) (bad : Ω → Prop) (I Q : Ω → Ω → Prop) (O₁ O₂ : T) (hll₁ : (Module.app D O₁).procedure.IsLossless) (hll₂ : (Module.app D O₂).procedure.IsLossless) (horacle : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), prhlProc (fun (a₁ : sig'.ParamType) (g₁ : VariableAssignment) (a₂ : sig'.ParamType) (g₂ : VariableAssignment) => ¬bad (L.get g₂) ∧ a₁ = a₂ ∧ F.touched_getter.get g₁ = F.touched_getter.get g₂ ∧ I (L.get g₁) (L.get g₂)) ((ext O₁).lookup n) ((ext O₂).lookup n) fun (r₁ : sig'.ret) (g₁ : VariableAssignment) (r₂ : sig'.ret) (g₂ : VariableAssignment) => if bad (L.get g₂) then Q (L.get g₁) (L.get g₂) else r₁ = r₂ ∧ F.touched_getter.get g₁ = F.touched_getter.get g₂ ∧ I (L.get g₁) (L.get g₂)) (hQ₁ : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig') (ω₂ : Ω), bad ω₂ → hoareProc (fun (x : sig'.ParamType) (g : VariableAssignment) => Q (L.get g) ω₂) ((ext O₁).lookup n) fun (x : sig'.ret) (g : VariableAssignment) => Q (L.get g) ω₂) (hQ₂ : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig') (ω₁ : Ω), phoareProc (fun (x : sig'.ParamType) (g : VariableAssignment) => bad (L.get g) ∧ Q ω₁ (L.get g)) ((ext O₂).lookup n) (fun (x : sig'.ret) (g : VariableAssignment) => indicatorE (bad (L.get g) ∧ Q ω₁ (L.get g))) Eq fun (x : sig'.ParamType) (x_1 : VariableAssignment) => 1) :
prhlProc (fun (a₁ : sig.ParamType) (g₁ : VariableAssignment) (a₂ : sig.ParamType) (g₂ : VariableAssignment) => badInv L bad Q g₁ g₂ ∨ a₁ = a₂ ∧ syncInv L F I bad g₁ g₂) (Module.app D O₁).procedure (Module.app D O₂).procedure 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₂

prhlProc_abstract_call_upto_ecF with EC's precondition in full: the bad event may have happened before the call (then only bad and J are asked: EC's if bad{2} then J else ={args, glob} /\ I).

theorem GaudisCrypt.prhlProc_abstract_call_module_ec {Ω : Type} (L : Lens Ω VariableAssignment) {T : Type 1} [IsModule T] {sig : ProcedureSignature} {holes : HoleSigs} (D : Module.Arr T (Module.Proc sig)) (ext : T → holes.Instantiation) (hD : Module.Representable D ext) (hFL : FVP.fvP D ≤ L.footprintᶜ) (I : Ω → Ω → Prop) (hc : ∀ {sig' : ProcedureSignature} (a : HoleIndex holes sig'), Countable sig'.ParamType) (O₁ O₂ : T) (hwk₁ : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), StmtWithHoles.WritesKeep (FVP.fvP D).touched_getter.get ((ext O₁).lookup n).body) (hwk₂ : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), StmtWithHoles.WritesKeep (FVP.fvP D).touched_getter.get ((ext O₂).lookup n).body) (horacle : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), prhlProc (fun (a₁ : sig'.ParamType) (g₁ : VariableAssignment) (a₂ : sig'.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ I (L.get g₁) (L.get g₂)) ((ext O₁).lookup n) ((ext O₂).lookup n) 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 (FVP.fvP D) I g₁ g₂) (Module.app D O₁).procedure (Module.app D O₂).procedure fun (r₁ : sig.ret) (g₁ : VariableAssignment) (r₂ : sig.ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ globInvF L (FVP.fvP D) I g₁ g₂

EC's abstract call (_: ={…} /\ I) with the region glob D alone: the oracles' judgments are EC's ={arg} /\ I ==> ={res} /\ I, ={glob D} framed syntactically (their writes keep glob D, StmtWithHoles.WritesKeep).

The frame goals StmtWithHoles.WritesKeep (FVP.fvP D).touched_getter.get o.body of the k oracle procedures (one goal gw for all holes): each split down to its writes, a write to a local or a global outside glob D (D's restriction, fp_disjoint) closed.

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

    §x without a side ↦ §x{2}: EC's bad is about the right memory.

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

      A read eval at CurrentState.mk σ of x: (σ, x).

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

        The conditions bad, I, J (functions of the two states) on the contents of the global variables they read: the lens L of those variables (in order of appearance), its content type Ω, and bad, I, J as predicates on Ω.

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

          EC's ={glob X, …} in the invariant I of call (_: bad, I, J) (I that or ={…} ∧ rest): a declared X (a local) leaves ={…}, its glob joins the region kept equal (returned, as FVP.fvP X); a concrete module's glob is its global variables (DeclareModule.globalVarsOf).

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

            Hole i's component and its position in it, for components with nprocs procedures.

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

              EC's D_ll: ∀ (X₁ : C₁) [Module.Declared X₁ G] …, islossless (in order) → islossless D(X₁, …), over the oracles' component module types Cs.

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

                  EC's call (_: bad, I, J): see the module docstring.

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

                    A region's view of a conditional state is the conditional of the views (a conditional write, RO.get's if (x ∉ m) m.[x] <- r, under glob D).

                    Succeeds when the goal shows a write under a getter, g.get (x.set v σ): the shape touched_set_of_le_compl rewrites. glob_simp's guard: the rw with the lemma's pattern left open, when nothing matches, tries to unify it with every get in the goal, and on a large invariant that is seconds (1.3G heartbeats a call in Handle.CF_G1).

                    Equations
                    Instances For

                      EC's implicit ={glob D} across code writing outside glob D: each write x.set v g under (FVP.fvP D).touched_getter.get removed (touched_set_of_le_compl, x outside glob D by fp_disjoint), as long as one is found (glob_set_present says whether there is one to look for); the view taken into conditional states first.

                      Equations
                      Instances For

                        EC's call (_: ={glob A, x, …} /\ I) on an abstract procedure D(O₁) ~ D(O₂) (D declared): the declared modules' globs (and glob D) a region kept equal, the other items and the variables I reads a view L on which the whole invariant is a relation (prhlProc_abstract_call_moduleF). Goals: per oracle procedure (EC's order: the last component's first) its judgment, then the code before the call.

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

                          equiv_call (_ : cond) for cond an invariant ={…} ∧ I, or ={…} alone (see equivCallInvAnd).

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

                            The declared module D of the left side's last statement, a call of D(O) (D a local), if it is one; the goal left as it is.

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

                              Do both sides of the relational goal end with a call of an applied declared module (D(O₁) ~ D(O₂), D a local)?

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