Documentation

GaudisCrypt.Logic.ECCallMultiProcTest

Golden tests: a declared module with several procedures and an oracle #

EC's module type Adv (O : POr) = { proc a1 … proc a2 … }, declare module A <: Adv {-…}: the call rules on A(O).a1, A(O).a2 (an accessor of the functor's result): the invariant call with EC's frame of the untouched globals, the up-to-bad call with EC's full precondition, swap of a sampling into a global past the call, and pHL's call with the adversary's losslessness; and inline of the oracle of a cloned theory (clone import ROM as H, H.Lazy.LRO.o) (see Logic/ECAutoTest.lean for the format; scripts/update_golden.py refreshes the expected text).

instance GaudisCrypt.ECCallMultiProcTest.instIsGlobalVarNatVMk :
O.v.IsGlobalVar (VariableName.mk "GaudisCrypt.ECCallMultiProcTest.O.v" ℕ)
Equations
Instances For
    instance GaudisCrypt.ECCallMultiProcTest.instIsGlobalVarNatZMk :
    G.z.IsGlobalVar (VariableName.mk "GaudisCrypt.ECCallMultiProcTest.G.z" ℕ)
    Equations
    Instances For
      instance GaudisCrypt.ECCallMultiProcTest.instIsGlobalVarNatWMk :
      G.w.IsGlobalVar (VariableName.mk "GaudisCrypt.ECCallMultiProcTest.G.w" ℕ)
      Equations
      Instances For

        The module type declared by moduletype POr, with fields o: the type Module POr.typeRep of modules that are a right-nested tuple of the field types.

        Build one from a record of its fields with POr.mk, read a single field off one with the accessors POr.o, and get the whole record back with POr.structure.

        Equations
        Instances For
          @[simp]
          theorem GaudisCrypt.ECCallMultiProcTest.POr.mk_destruct (theRecord✝ : Structure) :
          (mk theRecord✝).structure = theRecord✝

          @[simp]: POr.structure (POr.mk r) = r — destructing a module built from a record gives that record back.

          The record of a module's fields: POr.structure m is POr.Structure.mk applied to POr.o of m.

          Inverse of POr.mk (POr.mk_destruct, POr.destruct_mk).

          Equations
          Instances For
            @[simp]
            theorem GaudisCrypt.ECCallMultiProcTest.POr.destruct_mk (theModule✝ : POr) :
            mk theModule✝.structure = theModule✝

            @[simp]: POr.mk (POr.structure m) = m — rebuilding a module from its own fields gives that module back.

            The ModuleTypeRep underlying POr, the module type declared by moduletype POr: the right-nested product of its 1 field types, in declaration order.

            POr is by definition Module POr.typeRep.

            Equations
            Instances For

              What is derivable about the accessor POr.o, bundled into one ModuleTypeUtilities (one name per field in the namespace, rather than one per fact):

              • POr.o.utilities.accessorModule : POr →ₘ … — the accessor as a module, a projection being a module morphism;
              • POr.o.utilities.apply_simp — Module.app POr.o.utilities.accessorModule m = POr.o m: applying that module is the accessor;
              • POr.o.utilities.expression_eq — the same at the level of expressions: (POr.o m).expression = (POr.o.utilities.proj m.expression).reduce.
              Equations
              • One or more equations did not get rendered due to their size.
              Instances For
                @[reducible]

                Builds a module of type POr from the record POr.Structure of its fields, as a right-nested Module.pair'. @[reducible].

                Inverse of POr.structure (POr.mk_destruct, POr.destruct_mk); a single field of a module built this way is read back by the @[simp] lemmas POr.o.mk_simp.

                Equations
                Instances For

                  The record of the fields of a module of type POr: the fields o, one per moduletype field, each of that field's own module type.

                  POr.mk turns such a record into a POr, POr.structure turns a POr back into one.

                  Instances For

                    The field o of a module of type POr: the projection onto component 0 of the right-nested tuple POr.typeRep, as a chain of Module.fst'/Module.snd'. Tagged @[module_accessor].

                    POr.o.mk_simp reads this field back off a module built by POr.mk; POr.o.utilities has the accessor as a module, and the lemmas about it.

                    Its parameters are named x, in that order (recorded in @[gaudiProcParamNames], a ProcedureSignature holding only their types).

                    Equations
                    • theModule✝.o = theModule✝
                    Instances For
                      @[implicit_reducible]

                      The IsModule POr instance: POr is a module type, with representation POr.typeRep.

                      It is what lets the name POr stand where a module type is expected — in Module.Arr/Module.Prod (→ₘ/×ₘ), say — which the underlying Module POr.typeRep would do on its own but POr, a plain (non-reducible) def, would not.

                      Equations
                      @[simp]
                      theorem GaudisCrypt.ECCallMultiProcTest.POr.o.mk_simp (theRecord✝ : Structure) :
                      (mk theRecord✝).o = theRecord✝.o

                      @[simp]: reading the field o back off a module built from a record — POr.o (POr.mk r) = r.o.

                      It is what carries the right-hand side of an X.apply_simp (which is an POr.mk) on to the field the caller actually asked for, so that simp chains X.apply_simp into X.o.apply_simp.

                      Instantiating the holes of O.o.procedure with a tuple holeArgs of procedures: the body of proc o as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.

                      Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [O.o.procedure.apply_simp]).

                      proc o of module O as a module: Module.proc O.o.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — O.o.apply_simp says exactly that.

                      Equations
                      Instances For
                        @[simp]

                        @[simp]: O.o = Module.proc O.o.procedure — true by definition, proc o using no module parameter and so having no holes to fill.

                        The body of proc o of module O, as a procedure of its own: it calls no module parameter, so it has no holes.

                        A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see O.o.procedure.apply_simp) rather than run. Use O.o for this procedure as a module.

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

                          The module declared by module O: the record of its procedures O.o.

                          The declaration has no parameter list, so no procedure of it can call one either and the module is not a function — it is the plain record itself, and there is no O.apply_simp to apply it with.

                          Equations
                          Instances For

                            The module type declared by moduletype AdvProcs, with fields a1, a2: the type Module AdvProcs.typeRep of modules that are a right-nested tuple of the field types.

                            Build one from a record of its fields with AdvProcs.mk, read a single field off one with the accessors AdvProcs.a1, AdvProcs.a2, and get the whole record back with AdvProcs.structure.

                            Equations
                            Instances For

                              What is derivable about the accessor AdvProcs.a1, bundled into one ModuleTypeUtilities (one name per field in the namespace, rather than one per fact):

                              • AdvProcs.a1.utilities.accessorModule : AdvProcs →ₘ … — the accessor as a module, a projection being a module morphism;
                              • AdvProcs.a1.utilities.apply_simp — Module.app AdvProcs.a1.utilities.accessorModule m = AdvProcs.a1 m: applying that module is the accessor;
                              • AdvProcs.a1.utilities.expression_eq — the same at the level of expressions: (AdvProcs.a1 m).expression = (AdvProcs.a1.utilities.proj m.expression).reduce.
                              Equations
                              • One or more equations did not get rendered due to their size.
                              Instances For
                                @[simp]
                                theorem GaudisCrypt.ECCallMultiProcTest.AdvProcs.destruct_mk (theModule✝ : AdvProcs) :
                                mk theModule✝.structure = theModule✝

                                @[simp]: AdvProcs.mk (AdvProcs.structure m) = m — rebuilding a module from its own fields gives that module back.

                                @[simp]
                                theorem GaudisCrypt.ECCallMultiProcTest.AdvProcs.a1.mk_simp (theRecord✝ : Structure) :
                                (mk theRecord✝).a1 = theRecord✝.a1

                                @[simp]: reading the field a1 back off a module built from a record — AdvProcs.a1 (AdvProcs.mk r) = r.a1.

                                It is what carries the right-hand side of an X.apply_simp (which is an AdvProcs.mk) on to the field the caller actually asked for, so that simp chains X.apply_simp into X.a1.apply_simp.

                                The field a2 of a module of type AdvProcs: the projection onto component 1 of the right-nested tuple AdvProcs.typeRep, as a chain of Module.fst'/Module.snd'. Tagged @[module_accessor].

                                AdvProcs.a2.mk_simp reads this field back off a module built by AdvProcs.mk; AdvProcs.a2.utilities has the accessor as a module, and the lemmas about it.

                                Its parameters are named c, in that order (recorded in @[gaudiProcParamNames], a ProcedureSignature holding only their types).

                                Equations
                                Instances For

                                  The record of the fields of a module of type AdvProcs: the fields a1, a2, one per moduletype field, each of that field's own module type.

                                  AdvProcs.mk turns such a record into a AdvProcs, AdvProcs.structure turns a AdvProcs back into one.

                                  Instances For
                                    @[implicit_reducible]

                                    The IsModule AdvProcs instance: AdvProcs is a module type, with representation AdvProcs.typeRep.

                                    It is what lets the name AdvProcs stand where a module type is expected — in Module.Arr/Module.Prod (→ₘ/×ₘ), say — which the underlying Module AdvProcs.typeRep would do on its own but AdvProcs, a plain (non-reducible) def, would not.

                                    Equations
                                    @[simp]
                                    theorem GaudisCrypt.ECCallMultiProcTest.AdvProcs.mk_destruct (theRecord✝ : Structure) :
                                    (mk theRecord✝).structure = theRecord✝

                                    @[simp]: AdvProcs.structure (AdvProcs.mk r) = r — destructing a module built from a record gives that record back.

                                    The ModuleTypeRep underlying AdvProcs, the module type declared by moduletype AdvProcs: the right-nested product of its 2 field types, in declaration order.

                                    AdvProcs is by definition Module AdvProcs.typeRep.

                                    Equations
                                    Instances For
                                      @[reducible]

                                      Builds a module of type AdvProcs from the record AdvProcs.Structure of its fields, as a right-nested Module.pair'. @[reducible].

                                      Inverse of AdvProcs.structure (AdvProcs.mk_destruct, AdvProcs.destruct_mk); a single field of a module built this way is read back by the @[simp] lemmas AdvProcs.a1.mk_simp, AdvProcs.a2.mk_simp.

                                      Equations
                                      Instances For

                                        The field a1 of a module of type AdvProcs: the projection onto component 0 of the right-nested tuple AdvProcs.typeRep, as a chain of Module.fst'/Module.snd'. Tagged @[module_accessor].

                                        AdvProcs.a1.mk_simp reads this field back off a module built by AdvProcs.mk; AdvProcs.a1.utilities has the accessor as a module, and the lemmas about it.

                                        Its parameters are named p, in that order (recorded in @[gaudiProcParamNames], a ProcedureSignature holding only their types).

                                        Equations
                                        Instances For
                                          @[simp]
                                          theorem GaudisCrypt.ECCallMultiProcTest.AdvProcs.a2.mk_simp (theRecord✝ : Structure) :
                                          (mk theRecord✝).a2 = theRecord✝.a2

                                          @[simp]: reading the field a2 back off a module built from a record — AdvProcs.a2 (AdvProcs.mk r) = r.a2.

                                          It is what carries the right-hand side of an X.apply_simp (which is an AdvProcs.mk) on to the field the caller actually asked for, so that simp chains X.apply_simp into X.a2.apply_simp.

                                          What is derivable about the accessor AdvProcs.a2, bundled into one ModuleTypeUtilities (one name per field in the namespace, rather than one per fact):

                                          • AdvProcs.a2.utilities.accessorModule : AdvProcs →ₘ … — the accessor as a module, a projection being a module morphism;
                                          • AdvProcs.a2.utilities.apply_simp — Module.app AdvProcs.a2.utilities.accessorModule m = AdvProcs.a2 m: applying that module is the accessor;
                                          • AdvProcs.a2.utilities.expression_eq — the same at the level of expressions: (AdvProcs.a2 m).expression = (AdvProcs.a2.utilities.proj m.expression).reduce.
                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For

                                            The record of a module's fields: AdvProcs.structure m is AdvProcs.Structure.mk applied to AdvProcs.a1, AdvProcs.a2 of m.

                                            Inverse of AdvProcs.mk (AdvProcs.mk_destruct, AdvProcs.destruct_mk).

                                            Equations
                                            Instances For

                                              The module declared by module G, abstracted over its single parameter A, which it takes as one right-nested tuple: Module.Arr (T₁ ×ₘ (… ×ₘ Tₙ)) M, with M the anonymous product of the procedures' own types, the declaration naming no module type.

                                              Applied to such a tuple it is the record of its procedures G.main, each applied to the parameters that procedure itself uses — which is what the @[simp] lemma G.apply_simp says.

                                              Equations
                                              Instances For
                                                @[simp]

                                                @[simp]: applying G.main to the parameters proc main uses (A) is Module.proc (G.main.procedure.instantiate …) — the procedure with its holes filled by the callees they were made from, each written as it was in the body (with the arguments in place of the module parameters) and turned into a Procedure by Module.Proc.procedure.

                                                @[simp]

                                                @[simp]: applying G to a tuple of its single parameter A — the record of its procedures G.main, each applied to the parameters it uses.

                                                This is the lemma that unfolds a module use: simp rewrites with it, then with the field lemmas of the module type (N.f.mk_simp) to get at the one procedure the goal is about, and then with G.main.apply_simp to fill that procedure's holes.

                                                The body of proc main of module G, as a procedure of its own: the 2 calls it makes to module parameters (A) are its holes, in the order the body makes them.

                                                A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see G.main.procedure.apply_simp) rather than run. Use G.main for this procedure as a module.

                                                Equations
                                                • One or more equations did not get rendered due to their size.
                                                Instances For
                                                  theorem GaudisCrypt.ECCallMultiProcTest.G.main.procedure.apply_simp (holeArgs✝ : (HoleSigs.cons (procsig (ℕ) → ℕ) (HoleSigs.cons (procsig (ℕ) → Bool) HoleSigs.empty)).Instantiation) :
                                                  procedure.instantiate holeArgs✝ = proc () : Bool { var x : ℕ, b : Bool; z <$ do let i ← SubProbability.uniform pure ↑i; w <$ do let i ← SubProbability.uniform pure ↑i; x <- call (holeArgs✝.lookup HoleIndex.zero) (§z); b <- call (holeArgs✝.lookup HoleIndex.zero.succ) (§x + §z); return §b }

                                                  Instantiating the holes of G.main.procedure with a tuple holeArgs of procedures: the body of proc main as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.

                                                  Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [G.main.procedure.apply_simp]).

                                                  proc main of module G as a module, abstracted over the module parameters it uses (A, in declaration order): Module.Arr … (Module.Proc (procsig …)).

                                                  Apply it with the @[simp] lemma G.main.apply_simp, which fills the holes of G.main.procedure with the callees the body called.

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

                                                    @[simp]: Q.main = Module.proc Q.main.procedure — true by definition, proc main using no module parameter and so having no holes to fill.

                                                    The body of proc main of module Q, as a procedure of its own: it calls no module parameter, so it has no holes.

                                                    A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see Q.main.procedure.apply_simp) rather than run. Use Q.main for this procedure as a module.

                                                    Equations
                                                    Instances For

                                                      proc main of module Q as a module: Module.proc Q.main.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — Q.main.apply_simp says exactly that.

                                                      Equations
                                                      Instances For

                                                        The module declared by module Q: the record of its procedures Q.main.

                                                        The declaration has no parameter list, so no procedure of it can call one either and the module is not a function — it is the plain record itself, and there is no Q.apply_simp to apply it with.

                                                        Equations
                                                        Instances For
                                                          theorem GaudisCrypt.ECCallMultiProcTest.Q.main.procedure.apply_simp (holeArgs✝ : HoleSigs.empty.Instantiation) :
                                                          procedure.instantiate holeArgs✝ = proc (x : ℕ) : Bool { var r : Bool; r <- call H.Lazy.LRO.o.procedure (§x); return §r }

                                                          Instantiating the holes of Q.main.procedure with a tuple holeArgs of procedures: the body of proc main as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.

                                                          Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [Q.main.procedure.apply_simp]).