Documentation

GaudisCrypt.Logic.AbstractCallTest

Smoke test for the abstract call rule: an abstract adversary with one oracle, run against a counter that adds 1 and one that adds 2, keeps count₂ = 2 · count₁.

Equations
Instances For
    instance GaudisCrypt.AbstractCallTest.instIsGlobalVarNatCountMk :
    count.IsGlobalVar (VariableName.mk "GaudisCrypt.AbstractCallTest.count" ℕ)

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

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

    Equations
    Instances For

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

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

      Equations
      Instances For

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

        Oracle is by definition Module Oracle.typeRep.

        Equations
        Instances For

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

          Oracle.query.mk_simp reads this field back off a module built by Oracle.mk; Oracle.query.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✝.query = theModule✝
          Instances For
            @[simp]
            theorem GaudisCrypt.AbstractCallTest.Oracle.query.mk_simp (theRecord✝ : Structure) :
            (mk theRecord✝).query = theRecord✝.query

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

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

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

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

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

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

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

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

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

              Instances For
                @[reducible]

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

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

                Equations
                Instances For
                  @[implicit_reducible]

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

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

                  Equations

                  The module declared by module Count1: the record of its procedures Count1.query.

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

                  Equations
                  Instances For

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

                    Equations
                    Instances For
                      @[simp]

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

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

                      Equations
                      Instances For

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

                        @[simp]

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

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

                        The module declared by module Count2: the record of its procedures Count2.query.

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

                        Equations
                        Instances For

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

                          Equations
                          Instances For

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

                            Equations
                            Instances For
                              theorem GaudisCrypt.AbstractCallTest.count_query (F : Footprint VariableAssignment) (hF : F ≤ count.footprintᶜ) :
                              prhlProc (fun (a₁ : (procsig (ℕ) → ℕ).ParamType) (g₁ : VariableAssignment) (a₂ : (procsig (ℕ) → ℕ).ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ globInvF count F (fun (c₁ c₂ : ℕ) => c₂ = 2 * c₁) g₁ g₂) Count1.query.procedure Count2.query.procedure fun (r₁ : (procsig (ℕ) → ℕ).ret) (g₁ : VariableAssignment) (r₂ : (procsig (ℕ) → ℕ).ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ globInvF count F (fun (c₁ c₂ : ℕ) => c₂ = 2 * c₁) g₁ g₂

                              The oracle premise, for any region F disjoint from the counter.

                              theorem GaudisCrypt.AbstractCallTest.adversary_count (A : proctype () -> Bool) (hdisj : FVP.fvP_proc A ≤ count.footprintᶜ) :
                              prhlProc (fun (a₁ : (procsig () → Bool).ParamType) (g₁ : VariableAssignment) (a₂ : (procsig () → Bool).ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ globInv count A (fun (c₁ c₂ : ℕ) => c₂ = 2 * c₁) g₁ g₂) (A.instantiate Count1.query.procedure) (A.instantiate Count2.query.procedure) fun (r₁ : (procsig () → Bool).ret) (g₁ : VariableAssignment) (r₂ : (procsig () → Bool).ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ globInv count A (fun (c₁ c₂ : ℕ) => c₂ = 2 * c₁) g₁ g₂

                              EC: equiv[ A(Count1).main ~ A(Count2).main : ={glob A} ∧ count{2} = 2 * count{1} ==> ={res, glob A} ∧ count{2} = 2 * count{1} ] by proc (count{2} = 2 * count{1}).

                              theorem GaudisCrypt.AbstractCallTest.module_adversary_count (D : Module.Arr Oracle (procmod () → Bool)) (hD : Module.Representable D fun (O : Oracle) => O.query.procedure) (hdisj : FVP.fvP D ≤ count.footprintᶜ) :
                              prhlProc (fun (a₁ : (procsig () → Bool).ParamType) (g₁ : VariableAssignment) (a₂ : (procsig () → Bool).ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ globInvF count (FVP.fvP D) (fun (c₁ c₂ : ℕ) => c₂ = 2 * c₁) g₁ g₂) (Module.app D Count1).procedure (Module.app D Count2).procedure fun (r₁ : (procsig () → Bool).ret) (g₁ : VariableAssignment) (r₂ : (procsig () → Bool).ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ globInvF count (FVP.fvP D) (fun (c₁ c₂ : ℕ) => c₂ = 2 * c₁) g₁ g₂

                              The same at module level: the adversary is a module of the functor type, as EasyCrypt declares it (declare module D <: Adv {-count}), with the representation hypothesis (exception E2).

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

                              Apply it with the @[simp] lemma Guess.main.apply_simp, which fills the holes of Guess.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]: applying Guess to a tuple of its single parameter O — the record of its procedures Guess.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 Guess.main.apply_simp to fill that procedure's holes.

                                The module declared by module Guess, abstracted over its single parameter O, 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 Guess.main, each applied to the parameters that procedure itself uses — which is what the @[simp] lemma Guess.apply_simp says.

                                Equations
                                Instances For
                                  theorem GaudisCrypt.AbstractCallTest.Guess.main.procedure.apply_simp (holeArgs✝ : (HoleSigs.cons (procsig (ℕ) → ℕ) HoleSigs.empty).Instantiation) :
                                  procedure.instantiate holeArgs✝ = proc () : Bool { var y : ℕ; y <- call (holeArgs✝.lookup HoleIndex.zero) (3); return §y == 3 }

                                  Instantiating the holes of Guess.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 [Guess.main.procedure.apply_simp]).

                                  The body of proc main of module Guess, as a procedure of its own: the one call it makes to a module parameter (O) is its single hole.

                                  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 Guess.main.procedure.apply_simp) rather than run. Use Guess.main for this procedure as a module.

                                  Equations
                                  Instances For
                                    @[simp]

                                    @[simp]: applying Guess.main to the parameters proc main uses (O) is Module.proc (Guess.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.

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

                                    Equations
                                    Instances For

                                      The module declared by module Zero: the record of its procedures Zero.query.

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

                                      Equations
                                      Instances For
                                        @[simp]

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

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

                                        Equations
                                        Instances For
                                          theorem GaudisCrypt.AbstractCallTest.Zero.query.procedure.apply_simp (holeArgs✝ : HoleSigs.empty.Instantiation) :
                                          procedure.instantiate holeArgs✝ = proc (x : ℕ) : ℕ { skip; return 0 }

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