Documentation

GaudisCrypt.Logic.ECProcInvTest

Golden tests of equiv_proc (I) and equiv_conseq_frame H #

(Logic/ECProcInv.lean; see Logic/ECAutoTest.lean for the format, scripts/update_golden.py refreshes the expected text.) Two oracles that count in steps of one and of two, a declared adversary with one procedure, and a declared functor with two procedures, whose oracle lists are a hypothesis and whose procedures have a rule tagged @[proc_inv].

instance GaudisCrypt.ECProcInvTest.instIsGlobalVarIntPCountMk :
pCount.IsGlobalVar (VariableName.mk "GaudisCrypt.ECProcInvTest.pCount" ℤ)
Equations
Instances For
    instance GaudisCrypt.ECProcInvTest.instIsGlobalVarIntPOtherMk :
    pOther.IsGlobalVar (VariableName.mk "GaudisCrypt.ECProcInvTest.pOther" ℤ)
    Equations
    Instances For
      @[reducible]

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

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

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

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

        @[simp]
        theorem GaudisCrypt.ECProcInvTest.Orc.get.mk_simp (theRecord✝ : Structure) :
        (mk theRecord✝).get = theRecord✝.get

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

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

        @[simp]
        theorem GaudisCrypt.ECProcInvTest.Orc.mk_destruct (theRecord✝ : Structure) :
        (mk theRecord✝).structure = theRecord✝

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

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

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

        Equations
        Instances For

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

          Orc.get.mk_simp reads this field back off a module built by Orc.mk; Orc.get.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✝.get = theModule✝
          Instances For

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

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

            Equations
            Instances For
              @[implicit_reducible]

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

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

              Equations

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

              Orc is by definition Module Orc.typeRep.

              Equations
              Instances For

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

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

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

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

                  Instances For

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

                    Two.p.mk_simp reads this field back off a module built by Two.mk; Two.p.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
                    Instances For

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

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

                      Instances For
                        @[implicit_reducible]

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

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

                        Equations

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

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

                        Equations
                        Instances For

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

                          • Two.p.utilities.accessorModule : Two →ₘ … — the accessor as a module, a projection being a module morphism;
                          • Two.p.utilities.apply_simp — Module.app Two.p.utilities.accessorModule m = Two.p m: applying that module is the accessor;
                          • Two.p.utilities.expression_eq — the same at the level of expressions: (Two.p m).expression = (Two.p.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: Two.structure m is Two.Structure.mk applied to Two.p, Two.q of m.

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

                            Equations
                            Instances For
                              @[reducible]

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

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

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

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

                                @[simp]
                                theorem GaudisCrypt.ECProcInvTest.Two.mk_destruct (theRecord✝ : Structure) :
                                (mk theRecord✝).structure = theRecord✝

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

                                @[simp]
                                theorem GaudisCrypt.ECProcInvTest.Two.p.mk_simp (theRecord✝ : Structure) :
                                (mk theRecord✝).p = theRecord✝.p

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

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

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

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

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

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

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

                                  Two.q.mk_simp reads this field back off a module built by Two.mk; Two.q.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
                                  Instances For

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

                                    Two is by definition Module Two.typeRep.

                                    Equations
                                    Instances For
                                      @[reducible, inline]

                                      An adversary with oracle access.

                                      Equations
                                      Instances For
                                        @[reducible, inline]

                                        A functor with two procedures (a simulator).

                                        Equations
                                        Instances For

                                          The body of proc get of module Inc, 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 Inc.get.procedure.apply_simp) rather than run. Use Inc.get for this procedure as a module.

                                          Equations
                                          Instances For
                                            @[simp]

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

                                            Instantiating the holes of Inc.get.procedure with a tuple holeArgs of procedures: the body of proc get 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 [Inc.get.procedure.apply_simp]).

                                            The module declared by module Inc: the record of its procedures Inc.get.

                                            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 Inc.apply_simp to apply it with.

                                            Equations
                                            Instances For

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

                                              Equations
                                              Instances For

                                                Instantiating the holes of Inc2.get.procedure with a tuple holeArgs of procedures: the body of proc get 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 [Inc2.get.procedure.apply_simp]).

                                                @[simp]

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

                                                The body of proc get of module Inc2, 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 Inc2.get.procedure.apply_simp) rather than run. Use Inc2.get for this procedure as a module.

                                                Equations
                                                Instances For

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

                                                  Equations
                                                  Instances For

                                                    The module declared by module Inc2: the record of its procedures Inc2.get.

                                                    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 Inc2.apply_simp to apply it with.

                                                    Equations
                                                    Instances For

                                                      Inc.get touches pCount (EC reads a concrete module's globals off its code).

                                                      theorem GaudisCrypt.ECProcInvTest.Inc_Inc2 :
                                                      equiv[ Inc.get (x) ~ Inc2.get (x) : ={x} ∧ §pCount{2} = 2 * §pCount{1} ==> ={res} ∧ §pCount{2} = 2 * §pCount{1} ]

                                                      The two oracles keep pCount{2} = 2 * pCount{1}.

                                                      hoare_call (: P ==> Q) / x #

                                                      clear_decl_hyps (what the closers do in front of simp_all) #

                                                      equiv_call (H), the callees spelled differently #

                                                      equiv_conseq_frame H #

                                                      equiv_proc (I) on a declared adversary #

                                                      equiv_proc (I) by a rule (@[proc_inv]) #

                                                      EC's module type of S lists the oracles of its procedures (proc p(x : int) : int {O.get}): each procedure of S(O) is code with a hole for O.get.

                                                      Equations
                                                      • One or more equations did not get rendered due to their size.
                                                      Instances For
                                                        theorem GaudisCrypt.ECProcInvTest.SIM.call_p {Ω : Type} (L : Lens Ω VariableAssignment) (S : SIM) (hS : S.Rep) (F : Footprint VariableAssignment) (hSF : FVP.fvP S ≤ F) (hFL : F ≤ L.footprintᶜ) (I : Ω → Ω → Prop) (O₁ O₂ : Orc) (horacle : prhlProc (fun (a₁ : (procsig (ℤ) → ℤ).ParamType) (g₁ : VariableAssignment) (a₂ : (procsig (ℤ) → ℤ).ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ globInvF L F I g₁ g₂) O₁.get.procedure O₂.get.procedure fun (r₁ : (procsig (ℤ) → ℤ).ret) (g₁ : VariableAssignment) (r₂ : (procsig (ℤ) → ℤ).ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ globInvF L F I g₁ g₂) :
                                                        prhlProc (fun (a₁ : (procsig (ℤ) → ℤ).ParamType) (g₁ : VariableAssignment) (a₂ : (procsig (ℤ) → ℤ).ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ globInvF L F I g₁ g₂) S(O₁).p.procedure S(O₂).p.procedure fun (r₁ : (procsig (ℤ) → ℤ).ret) (g₁ : VariableAssignment) (r₂ : (procsig (ℤ) → ℤ).ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ globInvF L F I g₁ g₂

                                                        The abstract call rule for S(O).p (none is given for S(O).q).