Documentation

GaudisCrypt.Examples.ElGamal

ElGamal is IND-CPA under DDH (EasyCrypt examples/elgamal.ec) #

EC's file, declaration by declaration and script line by line (the pilot of the examples' re-port, 2026-11-15). All four lemmas are proven.

Translation:

Gap list (what keeps the file from reading as EC's; each is an item of the examples' infrastructure batch):

noncomputable def GaudisCrypt.Examples.ElGamal.ElGamal.enc {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :
procmod (group, group) → (group × group)

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

Equations
Instances For
    theorem GaudisCrypt.Examples.ElGamal.ElGamal.dec.procedure.apply_simp {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] (holeArgs✝ : HoleSigs.empty.Instantiation) :
    procedure.instantiate holeArgs✝ = proc (sk : exp, c : group × group) : (Option group) { var gy : group, gm : group; gy, gm <- §c; return some (§gm * §gy ^ (-§sk)) }

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

    theorem GaudisCrypt.Examples.ElGamal.ElGamal.kg.procedure.apply_simp {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] (holeArgs✝ : HoleSigs.empty.Instantiation) :
    procedure.instantiate holeArgs✝ = proc () : (group × exp) { var sk : exp; sk <$ EC.CyclicGroup.dt; return (EC.CyclicGroup.g ^ §sk, §sk) }

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

    @[simp]
    theorem GaudisCrypt.Examples.ElGamal.ElGamal.enc.apply_simp {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :

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

    noncomputable def GaudisCrypt.Examples.ElGamal.ElGamal.dec.procedure {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :
    proctype (exp, group × group) -> Option group

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

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      noncomputable def GaudisCrypt.Examples.ElGamal.ElGamal.kg {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :
      procmod () → (group × exp)

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

      Equations
      Instances For
        noncomputable def GaudisCrypt.Examples.ElGamal.ElGamal {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :
        PKE.Scheme

        The module declared by module ElGamal: the record of its procedures ElGamal.kg, ElGamal.enc.

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

        Equations
        Instances For
          @[simp]
          theorem GaudisCrypt.Examples.ElGamal.ElGamal.kg.apply_simp {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :

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

          theorem GaudisCrypt.Examples.ElGamal.ElGamal.enc.procedure.apply_simp {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] (holeArgs✝ : HoleSigs.empty.Instantiation) :
          procedure.instantiate holeArgs✝ = proc (pk : group, m : group) : (group × group) { var y : exp; y <$ EC.CyclicGroup.dt; return (EC.CyclicGroup.g ^ §y, §pk ^ §y * §m) }

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

          noncomputable def GaudisCrypt.Examples.ElGamal.ElGamal.enc.procedure {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :
          proctype (group, group) -> group × group

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

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            @[simp]
            theorem GaudisCrypt.Examples.ElGamal.ElGamal.dec.apply_simp {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :

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

            noncomputable def GaudisCrypt.Examples.ElGamal.ElGamal.dec {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :
            procmod (exp, group × group) → Option group

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

            Equations
            Instances For
              noncomputable def GaudisCrypt.Examples.ElGamal.ElGamal.kg.procedure {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :
              proctype () -> group × exp

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

              Equations
              Instances For
                @[simp]
                theorem GaudisCrypt.Examples.ElGamal.DDHAdv.guess.apply_simp {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] (A : PKE.Adversary) :

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

                noncomputable def GaudisCrypt.Examples.ElGamal.DDHAdv {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :

                The module declared by module DDHAdv, 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 DDHAdv.guess, each applied to the parameters that procedure itself uses — which is what the @[simp] lemma DDHAdv.apply_simp says.

                Equations
                Instances For
                  noncomputable def GaudisCrypt.Examples.ElGamal.DDHAdv.guess.procedure {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :
                  proctype (group, group, group) → Bool uses ((group) → group × group, (group × group) → Bool)

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

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For
                    theorem GaudisCrypt.Examples.ElGamal.DDHAdv.guess.procedure.apply_simp {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] (holeArgs✝ : (HoleSigs.cons (procsig (group) → group × group) (HoleSigs.cons (procsig (group × group) → Bool) HoleSigs.empty)).Instantiation) :
                    procedure.instantiate holeArgs✝ = proc (gx : group, gy : group, gz : group) : Bool { var m0 : group, m1 : group, b : Bool, b' : Bool; m0, m1 <- call (holeArgs✝.lookup HoleIndex.zero) (§gx); b <$ EC.dbool; b' <- call (holeArgs✝.lookup HoleIndex.zero.succ) (§gy, §gz * if §b = true then §m1 else §m0); return decide (§b' = §b) }

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

                    @[simp]
                    theorem GaudisCrypt.Examples.ElGamal.DDHAdv.apply_simp {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] (A : PKE.Adversary) :

                    @[simp]: applying DDHAdv to a tuple of its single parameter A — the record of its procedures DDHAdv.guess, 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 DDHAdv.guess.apply_simp to fill that procedure's holes.

                    noncomputable def GaudisCrypt.Examples.ElGamal.DDHAdv.guess {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :

                    proc guess of module DDHAdv 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 DDHAdv.guess.apply_simp, which fills the holes of DDHAdv.guess.procedure with the callees the body called.

                    Equations
                    • One or more equations did not get rendered due to their size.
                    Instances For
                      noncomputable def GaudisCrypt.Examples.ElGamal.Gb {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :
                      Module.Arr PKE.Adversary (procmod () → Bool)

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

                      Equations
                      Instances For
                        noncomputable def GaudisCrypt.Examples.ElGamal.Gb.main.procedure {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :
                        proctype () → Bool uses ((group) → group × group, (group × group) → Bool)

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

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          @[simp]
                          theorem GaudisCrypt.Examples.ElGamal.Gb.main.apply_simp {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] (A : PKE.Adversary) :

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

                          noncomputable def GaudisCrypt.Examples.ElGamal.Gb.main {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] :
                          Module.Arr PKE.Adversary (procmod () → Bool)

                          proc main of module Gb 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 Gb.main.apply_simp, which fills the holes of Gb.main.procedure with the callees the body called.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For
                            @[simp]
                            theorem GaudisCrypt.Examples.ElGamal.Gb.apply_simp {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] (A : PKE.Adversary) :
                            Gb(A).main = Module.app main A

                            @[simp]: applying Gb to a tuple of its single parameter A — the record of its procedures Gb.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 Gb.main.apply_simp to fill that procedure's holes.

                            theorem GaudisCrypt.Examples.ElGamal.Gb.main.procedure.apply_simp {group exp : Type} [_gaudiParam0 : CommGroup group] [_gaudiParam1 : Field exp] [_gaudiParam2 : Fintype exp] [_gaudiParam3 : EC.CyclicGroup.Params group exp] (holeArgs✝ : (HoleSigs.cons (procsig (group) → group × group) (HoleSigs.cons (procsig (group × group) → Bool) HoleSigs.empty)).Instantiation) :
                            procedure.instantiate holeArgs✝ = proc () : Bool { var x : exp, y : exp, m0 : group, m1 : group, z : exp, b' : Bool, b : Bool; x <$ EC.CyclicGroup.dt; y <$ EC.CyclicGroup.dt; m0, m1 <- call (holeArgs✝.lookup HoleIndex.zero) (EC.CyclicGroup.g ^ §x); z <$ EC.CyclicGroup.dt; b' <- call (holeArgs✝.lookup HoleIndex.zero.succ) (EC.CyclicGroup.g ^ §y, EC.CyclicGroup.g ^ §z); b <$ EC.dbool; return decide (§b' = §b) }

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

                            theorem GaudisCrypt.Examples.ElGamal.cpa_ddh0 {group exp : Type} [CommGroup group] [Field exp] [Fintype exp] [EC.CyclicGroup.Params group exp] (A : PKE.Adversary) [Module.Declared A ⊥] (m : VariableAssignment) :
                            Pr[ PKE.CPA(ElGamal, A).main () @ &m : §res = true ] = Pr[ EC.DiffieHellman.DDH.DDH0(DDHAdv(A)).main () @ &m : §res = true ]

                            EC's local lemma cpa_ddh0 &m: Pr[CPA(ElGamal,A).main() @ &m : res] = Pr[DDH0(DDHAdv(A)).main() @ &m : res].

                            theorem GaudisCrypt.Examples.ElGamal.ddh1_gb {group exp : Type} [CommGroup group] [Field exp] [Fintype exp] [EC.CyclicGroup.Params group exp] (A : PKE.Adversary) [Module.Declared A ⊥] (m : VariableAssignment) :
                            Pr[ EC.DiffieHellman.DDH.DDH1(DDHAdv(A)).main () @ &m : §res = true ] = Pr[ Gb(A).main () @ &m : §res = true ]

                            EC's local lemma ddh1_gb &m: Pr[DDH1(DDHAdv(A)).main() @ &m : res] = Pr[Gb.main() @ &m : res].

                            theorem GaudisCrypt.Examples.ElGamal.Gb_half {group exp : Type} [CommGroup group] [Field exp] [Fintype exp] [EC.CyclicGroup.Params group exp] (A : PKE.Adversary) [Module.Declared A ⊥] (Ac_ll : A.choose.procedure.IsLossless) (Ag_ll : A.guess.procedure.IsLossless) (m : VariableAssignment) :
                            Pr[ Gb(A).main () @ &m : §res = true ] = 1 / 2

                            EC's local lemma Gb_half &m: Pr[Gb.main()@ &m : res] = 1%r/2%r.

                            theorem GaudisCrypt.Examples.ElGamal.conclusion {group exp : Type} [CommGroup group] [Field exp] [Fintype exp] [EC.CyclicGroup.Params group exp] (A : PKE.Adversary) [Module.Declared A ⊥] (Ac_ll : A.choose.procedure.IsLossless) (Ag_ll : A.guess.procedure.IsLossless) (m : VariableAssignment) :
                            |Pr[ PKE.CPA(ElGamal, A).main () @ &m : §res = true ] - 1 / 2| = |Pr[ EC.DiffieHellman.DDH.DDH0(DDHAdv(A)).main () @ &m : §res = true ] - Pr[ EC.DiffieHellman.DDH.DDH1(DDHAdv(A)).main () @ &m : §res = true ]|

                            EC's lemma conclusion &m : | Pr[CPA(ElGamal,A).main() @ &m : res] - 1%r/2%r | = | Pr[DDH0(DDHAdv(A)).main() @ &m : res] - Pr[DDH1(DDHAdv(A)).main() @ &m : res] |.