Documentation

GaudisCrypt.Logic.DeclareModule

EasyCrypt's declare module #

declare module A <: AdvPreimage «from» «to» {-RO, -Preimage}

declares an abstract module A of a module type for the rest of the section, with EasyCrypt's restriction: A touches none of the globals of RO and Preimage. It is

variable (A : AdvPreimage «from» «to») [Module.Declared A S]

with S the join of those globals' footprints. Module.Declared A S bundles the two facts EC takes for granted about a declared module: finitely many globals, and none of them in S. As an instance-implicit section variable it is part of exactly the lemmas that mention A — EC's generalization over A when the section is closed — and fp_disjoint reads it like the restriction hypothesis FVP.fvP A ≤ Sᶜ it states.

The restriction. Each -X names a module or a global variable:

A region for glob A (exception E14 of the SHA-3 port).

declare module D <: DISTINGUISHER {-C, -Perm} with glob R

also declares a region R above D's footprint, restricted like D (Module.ECGlob D R, Footprint.Restricted R S), and {-R} in a restriction names it:

variable (D_ll : ∀ (F <: DFUNCTIONALITY {-R}), ∀ (P <: DPRIMITIVE {-R}), … → islossless D(F, P).distinguish)

This is for a lemma that restricts other modules against glob D (EC's {-D} on a module bound in a hypothesis) and is applied to a module built from a declared one, A(D'). EC's glob A(D') is glob D' and the variables of A, by definition; here the footprint of an application is bounded from above only, so {-A(D')} does not give {-D'}. Stated against R, the lemma is applied with the region written out, glob D' ⊔ C.c.footprint (an instance Module.ECGlob (A D') _, and Footprint.Restricted _ _ by ⟨by fp_finite, by fp_disjoint⟩). Applied to a declared module it is applied with R its glob (Module.ECGlob.declared, Footprint.Restricted.glob_declared).

Representability (exception E2 of the SHA-3 port) is not a hypothesis: over a first-order module type it is a theorem (Module.representable_of_firstOrder), and Module.Declared.ecModule A ext gives Module.ECModule A ext with its side conditions discharged by default (ext the module type's canonical one, as Oracle.ext is).

A is an EasyCrypt declared module restricted against S: finitely many globals (EC's glob A is a set of variables), none of them in S.

Instances

    S is a sub-join of S₀: every joinand of S is one of S₀ (or ⊥), found by instance search on the two joins. What lets a module declared against S₀ be used where a lemma declares it against less (Module.Declared.weaken): a lemma of a theory, used in a clone whose declaration restricts more (EC's exact (RO_is_collision_resistant A &m)).

    • le : S ≤ S₀
    Instances
      instance GaudisCrypt.Footprint.JoinLe.sup {a b S : Footprint VariableAssignment} [ha : a.JoinLe S] [hb : b.JoinLe S] :
      (a ⊔ b).JoinLe S
      @[instance 100]
      @[instance 100]
      @[instance 100]
      instance GaudisCrypt.Module.Declared.weaken {M : Type 1} [IsModule M] {A : M} {S₀ S : Footprint VariableAssignment} [h : Declared A S₀] [hS : S.JoinLe S₀] :

      A module declared against S₀ is declared against any sub-join S of it. The declaration is found first, its S₀ unknown (a local hypothesis: declare module's, an introduced binder's), then S checked against it: the synthesis order the check would not accept.

      Concrete modules: their glob read off their code #

      EC checks a restriction against a concrete module from its code (glob Perm is Perm.m, Perm.mi). Here a concrete module carries Module.GlobBound A B: its footprint within a join B of global_vars (proven once, by fp_module, next to the module). Instance search then derives Module.Declared for it, and for a declared module against the glob of a concrete one, as EC does:

      A concrete module's footprint lies within B, a join of global_vars (fp_module): what EC reads off the module's code. Not an EC notion.

      Instances

        B is a join of global_vars: finitely supported, and outside a finitely supported F, outside glob F.

        Instances

          B ≤ Sᶜ, by instance search over the two joins.

          Instances

            A module without globals (its bound is ⊥) stays outside everything.

            Two global_vars: their Lens.Disjoint instance.

            @[instance 100]
            instance GaudisCrypt.Footprint.Outside.glob_declared {M : Type 1} [IsModule M] {N : M} {B S₀ : Footprint VariableAssignment} [h : Module.Declared N S₀] [hB : B.GlobalJoin] [hS : B.JoinLe S₀] :

            The glob of a declared module N: its restriction keeps it outside B.

            @[instance 100]
            instance GaudisCrypt.Footprint.Outside.glob_declared_left {M : Type 1} [IsModule M] {N : M} {S S₀ : Footprint VariableAssignment} [h : Module.Declared N S₀] [hS : S.GlobalJoin] [hJ : S.JoinLe S₀] :

            The glob of a declared module N on the left: its restriction keeps the global_vars S outside it.

            The glob of a concrete module N, its bound B' outside B.

            instance GaudisCrypt.Module.Declared.ofGlobBound {M : Type 1} [IsModule M] {A : M} {B S : Footprint VariableAssignment} [h : GlobBound A B] [hO : B.Outside S] :

            A concrete module is declared against what its bound stays outside (EC's check of a restriction from the module's code).

            instance GaudisCrypt.Module.Declared.app {A B : Type 1} [IsModule A] [IsModule B] {F : Arr A B} {X : A} {BF S : Footprint VariableAssignment} [hF : GlobBound F BF] [hX : Declared X S] [hO : BF.Outside S] :

            A concrete functor applied to a declared module is declared where both stay outside (EC's restriction of F(A) from F's code and A's declaration).

            EC's syntactic glob A: R, a region containing A's footprint, within the glob of a finitely supported footprint (a declared module's glob, joined with global_vars). Given once for a local module built from declared ones (EC's glob D' is glob D and the variables of D''s code), where glob (fvP A) would not do: fvP of an application is only bounded above.

            Instances
              @[instance 100]

              A declared module's EC glob is its glob.

              @[instance 100]
              instance GaudisCrypt.Module.Declared.ofECGlob {M : Type 1} [IsModule M] {A : M} {R S : Footprint VariableAssignment} [h : ECGlob A R] [hO : R.Outside S] :

              A module is declared against what its EC glob stays outside (EC's restriction of a local module, {-PRPi} on D').

              The glob of a finitely supported footprint is finitely supported: within the same variables.

              What stays outside S₀ (a finitely supported footprint) stays outside S.

              Instances
                @[instance 100]
                instance GaudisCrypt.Footprint.Covers.sup {S₀ a b : Footprint VariableAssignment} [ha : S₀.Covers a] [hb : S₀.Covers b] :
                S₀.Covers (a ⊔ b)
                instance GaudisCrypt.Footprint.Covers.glob_concrete {M : Type 1} [IsModule M] {N : M} {S₀ B : Footprint VariableAssignment} [h : Module.GlobBound N B] [hB : B.GlobalJoin] [hS : B.JoinLe S₀] :

                The glob of a concrete module whose bound lies within S₀ (EC: a module restricted against Perm.m, Perm.mi is restricted against glob Perm).

                @[instance 100]
                instance GaudisCrypt.Module.Declared.weakenCovers {M : Type 1} [IsModule M] {A : M} {S₀ S : Footprint VariableAssignment} [h : Declared A S₀] [hS : S₀.Covers S] :

                Module.Declared.weaken, to what a declaration's set Covers: also the glob of the concrete modules within it.

                A region for glob A (declare module … with glob R) #

                Footprint.Restricted R S (Logic/FootprintSolver.lean) is weakened like a declaration, and gives the Footprint.Outside instances of R (so a module with Module.ECGlob A R is declared, Module.Declared.ofECGlob).

                @[instance 100]

                A region restricted against S₀ is restricted against any sub-join S of it (as Module.Declared.weaken).

                @[instance 100]

                A restricted region stays outside the sub-joins of its restriction.

                A declared module's glob is a restricted region: the lemma stated against a region is applied to a declared module with R its glob.

                Every procedure signature of holes has nonempty parameter and result types.

                Equations
                Instances For
                  theorem GaudisCrypt.HoleSigs.AllNonempty.index {holes : HoleSigs} (h : holes.AllNonempty) {sig : ProcedureSignature} :
                  ∀ (a : HoleIndex holes sig), (∀ U ∈ sig.params, Nonempty U) ∧ Nonempty sig.ret

                  Discharge (Module.moduleTypeRep T).FirstOrder for a literal module type: the constructor lemmas, unification unfolding the type down to its representation.

                  Equations
                  Instances For

                    Discharge HoleSigs.AllNonempty holes for literal signatures: one goal per parameter and result type, by instance search.

                    Equations
                    Instances For
                      theorem GaudisCrypt.Module.Declared.ecModule {T : Type 1} [IsModule T] {sig : ProcedureSignature} (A : Arr T (Proc sig)) [h : Declared A ⊥] (ext : T → ((moduleTypeRep T).holesApp HoleSigs.empty).Instantiation) (hT : (moduleTypeRep T).FirstOrder := by module_first_order) (hne : ((moduleTypeRep T).holesApp HoleSigs.empty).AllNonempty := by holes_nonempty) (hext : ∀ (O : T), ext O = (moduleTypeRep T).extOf (cast T O) := by intro _; rfl) :
                      ECModule A ext

                      A declared module is EasyCrypt-like (Module.ECModule): its finite support is part of the declaration, and over a first-order module type its representability is a theorem (Module.representable_of_firstOrder). The side conditions are discharged by default for a module type declared by moduletype and its canonical ext (each procedure in order).

                      The restriction as a hypothesis.

                      A global variable's footprint is finitely supported (one variable): what Module.Declared's finite support combines with for the modules built from declared ones and the theory's variables.

                      c is a global_var or a module_var: its value is varLens … under the binders of its implicit arguments (and module_var's haves).

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

                          Whether to look into the definition c for globals: ours (this file, the examples, the libraries), not the framework's or mathlib's.

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

                            The global_vars the code of the definitions roots mentions, through the definitions it uses (EC's glob of a concrete module), in the order first met. Under an alias of a clone (Syntax/Clone.lean), a variable of the clone's theory is the clone's (SRO.RO.m for SecureRO.RO.m), nested clones innermost first: the name that elaborates where the clone is used (the theory's own would need the theory's instance, which a clone does not register).

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

                              The restriction {-X₁, …, -Xₖ} as a footprint term, resolved in the current context, as declare module resolves it: a declared module (a local) is glob X; a region (a local, of declare module … with glob R) itself; a global variable itself; a concrete module (a definition) the globals its code mentions.

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

                                  An argument of the module type in declare module: a name or a parenthesized term (so that the restriction {-…} that follows is not read as one more argument).

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

                                      declare module A <: T a₁ … aₙ {-X₁, …, -Xₖ}: see the module docstring.

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

                                        declare module A <: T a₁ … aₙ {-X₁, …, -Xₖ} with glob R: declare module, and a region R above A's footprint, restricted like A ({-R} names it in a restriction): see the module docstring.

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

                                          clear_decl_hyps: clear the hypotheses that state a declared module's restrictions (Module.Declared A S, Footprint.Restricted R S, Module.ECGlob A R: instances that declare module puts in the context), where nothing depends on them.

                                          For the closers, in front of simp_all: it simplifies every hypothesis, and a restriction is a join of dozens of footprints that it can do nothing with (measured: 4 s per call under SHA3Security.ec's adversary, in every auto; 7 s per call under SHA3OSecurity.ec's, in sim's closer before it cleared them). Only where the goal is then closed or the step undone: the footprint tactics need these hypotheses.

                                          Equations
                                          Instances For