Documentation

GaudisCrypt.Logic.ConcreteFootprint

The footprint of concrete code that only uses locals #

FVP.fvP of a module is a syntactic over-approximation of what it touches. For a concrete procedure whose reads and writes are all on local variables (StmtWithHoles.LocalsOnly), it is ⊥ (FVP.fvP_proc_le_of_localsOnly): such reads and writes are zooms along localL, which is disjoint from the globals. locals_only proves LocalsOnly for a module's procedure, unfolding it as the inliner does and closing the reads and writes of local variables by rfl. What it cannot close is a read or write of a global.

This is what makes a concrete wrapper of abstract modules (RODist(D), …) finitely supported when the abstract modules are.

More generally, a procedure whose reads and writes touch the globals only through a lens X (StmtWithHoles.Within X) touches only X (FVP.fvP_proc_le_of_within): such reads and writes are zooms along the pair of the locals and X (ProgramState.withinL X). within_lens proves Within X as locals_only proves LocalsOnly. This is how a concrete oracle (PROM's RRO.resample) is confined to its module variable.

A read that does not depend on the globals.

Equations
Instances For

    A write that keeps the globals and commutes with writing them.

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

      Every read and write of the statement, its callees' included, is on the locals alone.

      Equations
      Instances For

        A procedure on the locals alone touches no globals.

        fvP of module expressions, by the expression #

        locals_only: on a goal StmtWithHoles.LocalsOnly s (or Getter.LocalsOnly, Setter.LocalsOnly), the conditions on the single reads and writes of s, callees included; those on local variables are closed by rfl.

        Equations
        Instances For
          @[reducible, inline]

          The locals and X's part of the globals, as one lens.

          Equations
          Instances For

            A read that depends on the globals only through X.

            Equations
            Instances For

              A write that changes the globals only through X, as a function of the locals and X.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                theorem GaudisCrypt.Setter.within_of_locals {Ω : Type} {X : Lens Ω VariableAssignment} {α : Type} {x : Setter α ProgramState} (hl : ∀ (v : α) (g : VariableAssignment) (σ : ProgramState), x.set v { globals := g, locals := σ.locals } = { globals := g, locals := (x.set v σ).locals }) (hg : ∀ (v : α) (σ : ProgramState), (x.set v σ).globals = σ.globals) :
                Within X x

                A write of the locals alone is within any X.

                theorem GaudisCrypt.Setter.within_self {Ω : Type} {X : Lens Ω VariableAssignment} {x : Setter Ω ProgramState} (hx : ∀ (v : Ω) (σ : ProgramState), x.set v σ = { globals := X.set v σ.globals, locals := σ.locals }) :
                Within X x

                A write of X itself is within X.

                theorem GaudisCrypt.Lens.get_of_disjoint_set' {a : Type u_1} {b : Type u_2} {m : Type u_3} (L : Lens a m) (M : Lens b m) [hd : L.Disjoint M] (v : b) (s : m) :
                L.get (M.set v s) = L.get s

                Writing through a disjoint lens keeps a lens's get (Lens.get_of_disjoint_set, with the disjointness the other way round).

                theorem GaudisCrypt.Lens.set_get_of_disjoint_set {a : Type u_1} {b : Type u_2} {m : Type u_3} (L : Lens a m) (M : Lens b m) [M.Disjoint L] (v : b) (s : m) :
                L.set (L.get s) (M.set v s) = M.set v s

                Writing back a disjoint lens's own content after a write is no write.

                theorem GaudisCrypt.Lens.set_get_of_disjoint_set' {a : Type u_1} {b : Type u_2} {m : Type u_3} (L : Lens a m) (M : Lens b m) [hd : L.Disjoint M] (v : b) (s : m) :
                L.set (L.get s) (M.set v s) = M.set v s
                theorem GaudisCrypt.Setter.within_of_global {Ω : Type} {X : Lens Ω VariableAssignment} {β : Type} {Y : Lens β VariableAssignment} {x : Setter β ProgramState} (hx : ∀ (v : β) (σ : ProgramState), x.set v σ = { globals := Y.set v σ.globals, locals := σ.locals }) (hY : ∀ (v : β) (g : VariableAssignment), X.set (X.get (Y.set v g)) g = Y.set v g) (hYX : ∀ (v : β) (g g' : VariableAssignment), X.get g = X.get g' → X.get (Y.set v g) = X.get (Y.set v g')) :
                Within X x

                A write of a global Y that changes the globals only in X, as a function of X (Y a component of a pair X, …), is within X.

                Every read and write of the statement, its callees' included, touches the globals only through X.

                Equations
                Instances For

                  A procedure within X touches only X.

                  Unfold every module procedure (Module.Proc.procedure M) in the goal, as the inliner does.

                  Unfold a procedure definition a return value is read off ((P …).return_val, P a definition of a procedure, as the module command generates them), down to the return value's getter.

                  within_lens: on a goal StmtWithHoles.Within X s (or Getter.Within, Setter.Within), the conditions on the single reads and writes of s, callees included. Reads and writes of local variables, writes of X (or of a component of it, X a pair of variables) and reads of expressions in X (or its components) and the locals are closed.

                  Equations
                  Instances For

                    fp_module: the footprint of a concrete module #

                    At a closed module c inside the module being bounded (a module applied to its Lean arguments, a clone's module): c's own bound FVP.fvP c ≤ B_c from the bound hook (read off c's code once per file and cached, Logic/ModuleFootprint.lean), then B_c ≤ B (each of B_c's variables among B's, fp_sub). false, and the goal untouched, if there is no such bound or it does not fit: the caller then unfolds c. A sub-module met several times (DSqueeze2 in Gconcl_list.D5, FC, PC in D2 … D6) is so read once, not at each occurrence.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      partial def GaudisCrypt.FpModule.go (close : Lean.TSyntax `tactic) (g : Lean.MVarId) (fuel : ℕ := 64) (atRoot : Bool := true) :

                      Bound L ≤ B, L a join of FVP.fvP M, evalMexpr of module expressions and procedure footprints, through the module's expression down to its procedures, each closed by close. atRoot: still at the module being bounded itself, before its expression is taken apart; below it, a closed sub-module is bounded by its own bound where it has one (subBound).

                      fp_module X: prove FVP.fvP M ≤ B for a concrete module M (a module, or a functor of modules: the parameters contribute nothing) whose procedures read and write the globals only through the lens X (within_lens), with X.footprint ≤ B (by le_rfl, after splitting X's pairs, or B = F ⊔ X.footprint). An abstract module A inside M (a Lean parameter) needs B = FVP.fvP A ⊔ …. fp_module alone: M's procedures use locals only (locals_only), and B is anything, ⊥ in particular. EasyCrypt reads a concrete module's globals off its code.

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