Documentation

GaudisCrypt.Logic.Representation

Representing functor modules by procedures with holes #

The abstract call rule needs an adversary D as code: a procedure with holes p that D, applied to oracles O, behaves like when filled with ext O (Module.RepresentedBy, Logic/AbstractCall.lean). Exception E2 of the SHA-3 port takes this as a hypothesis. Every module is code, though: a closed normal module expression. This file works towards extracting the representation from that normal form, for functors over first-order oracle types (products of procedures), with the full list of the oracle's procedures as ext.

noncomputable def GaudisCrypt.Flatten.paramWriter (names : List String) (tys : List Type) (hlen : names.length = tys.length) :

Write the arguments into the parameter slots names of a fresh callee frame emb (all its other locals init).

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

    The call of a procedure with holes q, flattened into the caller: reset the callee frame, write the arguments, run q's body in the frame emb, store the return value.

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

      Flattening the call of a procedure with holes: calling q filled with inst is equivalent, along trafo, to q's flattened call filled with inst. This is StmtWithHoles.equivInLens_flattenCall at the instantiated body, with applyLens commuted past the instantiation.

      noncomputable def GaudisCrypt.StmtWithHoles.substHoles {h h' : HoleSigs} (q : {sig : ProcedureSignature} → HoleIndex h sig → ProcedureWithHoles h' sig) :

      Substituting procedures with holes for the holes of a statement: each hole n becomes the flattened call of q n; everything else is re-targeted along trafo, which makes room for the callee frames.

      Equations
      Instances For
        theorem GaudisCrypt.StmtWithHoles.equivInLens_substHoles {h h' : HoleSigs} (q : {sig : ProcedureSignature} → HoleIndex h sig → ProcedureWithHoles h' sig) (inst : h.Instantiation) (inst' : h'.Instantiation) (hinst : ∀ {sig : ProcedureSignature} (n : HoleIndex h sig), inst.lookup n = (q n).instantiate inst') (s : StmtWithHoles h) :

        The substitution is sound: filling the holes of s with the q n filled with inst' is equivalent, along trafo, to filling the substituted statement with inst'.

        theorem GaudisCrypt.VariableAssignment.update_withName_rel (ι : String → String) (hι : Function.Injective ι) {m m' : VariableAssignment} (hm : ∀ (v : VariableName), m (v.withName (ι v.name)) = m' v) (n : String) (T : Type) [Nonempty T] (a : T) (v : VariableName) :
        (varLens { name := ι n, type := T, nonempty := inst✝, key := VariableName.encode (ι n), keyCorrect := ⋯ }).set a m (v.withName (ι v.name)) = (varLens { name := n, type := T, nonempty := inst✝, key := VariableName.encode n, keyCorrect := ⋯ }).set a m' v

        A slot update on both sides of the renaming ι: slot n on the right, slot ι n on the left.

        theorem GaudisCrypt.VariableAssignment.setParams_map_withName (ι : String → String) (hι : Function.Injective ι) (names : List String) (tys : List Type) (h : names.length = tys.length) (h' : (List.map ι names).length = tys.length) (args : typeListToTuple tys) {m m' : VariableAssignment} :
        (∀ (v : VariableName), m (v.withName (ι v.name)) = m' v) → ∀ (v : VariableName), setParams (List.map ι names) tys h' args m (v.withName (ι v.name)) = setParams names tys h args m' v

        setParams commutes with renaming the slots by ι.

        theorem GaudisCrypt.Flatten.trafo_get_entry_escape (names : List String) (tys : List Type) (h : names.length = tys.length) (h' : (List.map escape names).length = tys.length) (args : typeListToTuple tys) (st : VariableAssignment) :
        trafo.get { globals := st, locals := VariableAssignment.setParams (List.map escape names) tys h' args VariableAssignment.init } = { globals := st, locals := VariableAssignment.setParams names tys h args VariableAssignment.init }

        trafo sees the parameters written into the escaped slots in the original ones.

        theorem GaudisCrypt.Flatten.procedureDenotation_congr_rename {sig : ProcedureSignature} (names names' : List String) (hlen : names.length = sig.params.length) (hlen' : names'.length = sig.params.length) (hnodup : names.Nodup) (hnodup' : names'.Nodup) (l : Lens ProgramState ProgramState) (b b' : Stmt) (r : Getter sig.ret ProgramState) (hb : StmtWithHoles.EquivInLens b b' l) (hinit : ∀ (st : VariableAssignment) (args : typeListToTuple sig.params), l.get { globals := st, locals := VariableAssignment.setParams names' sig.params hlen' args VariableAssignment.init } = { globals := st, locals := VariableAssignment.setParams names sig.params hlen args VariableAssignment.init }) (hglobL : l.chain ProgramState.globalL = ProgramState.globalL) :
        procedureDenotation { parameterNames := names', parameterNames_length := hlen', parameterNames_nodup := hnodup', body := b', return_val := l.chainGetter r } = procedureDenotation { parameterNames := names, parameterNames_length := hlen, parameterNames_nodup := hnodup, body := b, return_val := r }

        procedureDenotation_congr with the parameters renamed: the renaming l sees the entry state of names' as that of names.

        A procedure with its holes substituted (StmtWithHoles.substHoles).

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem GaudisCrypt.ProcedureWithHoles.procedureDenotation_substHoles {h h' : HoleSigs} {sig : ProcedureSignature} (p : ProcedureWithHoles h sig) (q : {sig : ProcedureSignature} → HoleIndex h sig → ProcedureWithHoles h' sig) (inst : h.Instantiation) (inst' : h'.Instantiation) (hinst : ∀ {sig : ProcedureSignature} (n : HoleIndex h sig), inst.lookup n = (q n).instantiate inst') :

          The substitution is sound for procedures: p with its holes substituted by the q n, filled with inst', computes what p filled with the q n filled with inst' computes.

          First-order module types: products of procedures (and unit), no functors.

          Equations
          Instances For

            A chain of projections of a variable: a component of a module parameter.

            Instances For

              The normal forms of first-order type over first-order parameters: procedures, tuples, components of parameters, and procedures with holes applied to such (not literal) tuples.

              Instances For

                Inversion of first-order normal forms: over first-order parameters, a normal term of first-order type is an FONormal; a neutral term has first-order type, and is a component of a parameter unless it has procedure type.

                The shape of a first-order functor module: a closed normal module of type T →ₘ procmod …, T first-order, is a procedure with holes, or an abstraction whose body is a first-order normal form over the parameter.

                The footprint of a substitution #

                A kernel f on the globals, lifted to program states, commutes with every update of R: the condition Lens.reduceFootprint_alt_def characterizes R's share of the globals by.

                Equations
                Instances For
                  theorem GaudisCrypt.Footprint.GlobalsCommute.iSup {ι : Sort u_1} {A : ι → Footprint ProgramState} {f : VariableAssignment → SubProbability VariableAssignment} (h : ∀ (i : ι), (A i).GlobalsCommute f) :
                  (⨆ (i : ι), A i).GlobalsCommute f

                  Commuting with a join: with each joinand (the updates of a join are the bicommutant of the union).

                  A zoomed program commutes with what the original commutes with, along a lens of program states that keeps the globals: a kernel on the globals commutes with every generator of zoom l p once it commutes with those of p, at the zoomed state.

                  @[simp]

                  fvP's statement-level footprint, spelled out.

                  A program on the locals alone, zoomed into the program state, is outside the globals.

                  A write that changes only the locals, as a function of the locals, is outside the globals.

                  A read of a constant is nothing.

                  An assignment reads its expression as a point mass: no more than reading the expression.

                  The globals' share of a substituted statement: the statement's own, plus a bound Q on the substituted procedures'.

                  theorem GaudisCrypt.FVP.fvP_proc_substHoles_le {h h' : HoleSigs} {sig : ProcedureSignature} (p : ProcedureWithHoles h sig) (q : {sig : ProcedureSignature} → HoleIndex h sig → ProcedureWithHoles h' sig) (Q : Footprint VariableAssignment) (hQ : ∀ {sig : ProcedureSignature} (n : HoleIndex h sig), fvP_proc (q n) ≤ Q) :
                  fvP_proc (p.substHoles fun {sig : ProcedureSignature} => q) ≤ fvP_proc p ⊔ Q

                  The footprint of a substituted procedure: the procedure's own, plus a bound on the substituted procedures'.

                  The pieces of the extraction #

                  An instantiation from a family of procedures, one per hole.

                  Equations
                  Instances For
                    @[simp]
                    theorem GaudisCrypt.HoleSigs.Instantiation.lookup_ofFun {h : HoleSigs} (f : {sig : ProcedureSignature} → HoleIndex h sig → Procedure sig) {sig : ProcedureSignature} (n : HoleIndex h sig) :
                    (ofFun fun {sig : ProcedureSignature} => f).lookup n = f n

                    Filling the holes with procedures of the same denotations gives the same denotation.

                    Components of the oracle, on a literal oracle: a projection chain of the parameter of type H's tuple, the parameter replaced by a tuple of procedures, reduces to one of them (at procedure type) or to the tuple of a selection of them (at tuple type).

                    The name of the wrapper's parameter i: x…x (i+1 times).

                    Equations
                    Instances For

                      The wrapper's parameter names, for the parameter types tys, from index i on.

                      Equations
                      Instances For
                        theorem GaudisCrypt.Wrapper.mem_wNames {tys : List Type} {i : ℕ} {n : String} :
                        n ∈ wNames tys i → ∃ (j : ℕ), i ≤ j ∧ n = wName j
                        noncomputable def GaudisCrypt.Wrapper.wGet (tys : List Type) :
                        (∀ T ∈ tys, Nonempty T) → ℕ → VariableAssignment → typeListToTuple tys

                        Read the parameters back from their slots.

                        Equations
                        Instances For
                          theorem GaudisCrypt.Wrapper.wGet_setParams (tys : List Type) (h : ∀ T ∈ tys, Nonempty T) (i : ℕ) (hlen : (wNames tys i).length = tys.length) (a : typeListToTuple tys) (m : VariableAssignment) :
                          wGet tys h i (VariableAssignment.setParams (wNames tys i) tys hlen a m) = a
                          noncomputable def GaudisCrypt.ProcedureWithHoles.ofHole {H : HoleSigs} {sig : ProcedureSignature} (n : HoleIndex H sig) (hp : ∀ T ∈ sig.params, Nonempty T) [Nonempty sig.ret] :

                          The wrapper of a hole: the procedure that calls hole n with its arguments and returns what it returns. Its parameters and result live in local slots, so their types must be nonempty.

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

                            The wrapper of hole n, filled, computes what the procedure in hole n computes.

                            A read of the locals alone is outside the globals.

                            The wrapper of a hole touches no globals.

                            A procedure without holes, in a context of holes it does not use.

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

                              The extraction #

                              def GaudisCrypt.HoleIndex.consFun {F : ProcedureSignature → Sort u_1} {s : ProcedureSignature} {h : HoleSigs} (a : F s) (f : {sig : ProcedureSignature} → HoleIndex h sig → F sig) {sig : ProcedureSignature} :
                              HoleIndex (HoleSigs.cons s h) sig → F sig

                              A family over the holes of cons s h: a at the first, f at the others.

                              Equations
                              Instances For
                                theorem GaudisCrypt.ModuleExpression.reduce_app_procHoles {holes : HoleSigs} {sig : ProcedureSignature} (ne : holes.NonEmpty) (r : ProcedureWithHoles holes sig) {a : ModuleExpression} {inst : holes.Instantiation} (h : a.reduce = inst.toModuleExpr) :

                                The δ-step on an argument that reduces to a literal tuple.

                                The extraction: over the oracle parameter of type H's tuple, a first-order normal form of procedure type is represented by a procedure with holes, and one of tuple type by a family of them: the substituted term, for a literal oracle, reduces to procedures computing the same, and the representation's footprint is at most the term's.

                                The procedure of a proc-typed module whose expression is a given .proc.

                                Every first-order functor module is represented by a procedure with holes, over the full list of the oracle's procedures, with the footprint of its own normal form.

                                Module types #

                                The procedures of a first-order module type, in order, in front of R.

                                Equations
                                Instances For

                                  One procedure in front of an instantiation.

                                  Equations
                                  Instances For

                                    The procedures of a literal module O of first-order type T, in front of rest.

                                    Equations
                                    Instances For

                                      Rebuild a value of type T from the front of a tuple x; the rest of the tuple second.

                                      Equations
                                      Instances For

                                        Reducing a rebuilt value only depends on the tuple's reduct.

                                        A literal module of a product type is the pair of its projections.

                                        Rebuilding a literal module from the tuple of its procedures gives it back.

                                        The procedures of a literal module O of first-order type T, in order.

                                        Equations
                                        Instances For

                                          Every functor module over a first-order module type is represented by a procedure with holes over the list of the type's procedures (T.holesApp .empty), filled with those of the oracle (T.extOfApp), with at most the footprint of its own normal form. The module type may be any tree of products (as moduletype builds them, without a trailing unit).

                                          theorem GaudisCrypt.Module.representable_of_firstOrder {M : Type 1} [IsModule M] {sig : ProcedureSignature} (hT : (moduleTypeRep M).FirstOrder) (hne : ∀ {sig' : ProcedureSignature} (a : HoleIndex ((moduleTypeRep M).holesApp HoleSigs.empty) sig'), (∀ U ∈ sig'.params, Nonempty U) ∧ Nonempty sig'.ret) (ext : M → ((moduleTypeRep M).holesApp HoleSigs.empty).Instantiation) (hext : ∀ (O : M), ext O = (moduleTypeRep M).extOf (cast M O)) (D : Arr M (Proc sig)) :

                                          Removing exception E2 for full oracle lists: a functor module over a first-order module type M is representable (Module.Representable) with the list of all of M's procedures as ext, provided their parameter and result types are nonempty.