Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Cryptology City: Pedersen commitment, CvHP91 hash and KR00 chameleon hash

Definition
CryptologyCity_DLogCommitments

by axhoover · Nov 28, 2026 · Mathlib 0df444a (Lean v4.33.1)

cryptographycryptology-citydiscrete-logarithm

Schemes built from (m,r)↦gmhr(m, r) \mapsto g^m h^r(m,r)↦gmhr over a fixed cyclic group of order ppp. Conventions follow CryptologyCity_DLogGames.

  • uniformNonOne G: the uniform law on G∖{1}G \setminus \{1\}G∖{1}. uniformNonZero p: the uniform law on Zp∖{0}\mathbb Z_p \setminus \{0\}Zp​∖{0}. Each falls back to a point mass when the set is empty, which cannot happen when p≥2p \ge 2p≥2.
  • pedersen g h m r =gmhr= g^m h^r=gmhr: the Pedersen commitment, which is also the CvHP91 hash Hg,h(m,r)H_{g,h}(m, r)Hg,h​(m,r) and the KR00 chameleon hash CH(h,m;r)\mathrm{CH}(h, m; r)CH(h,m;r).
  • Pedersen binding game. h←G∖{1}h \leftarrow G \setminus \{1\}h←G∖{1}, then (c,(m0,r0),(m1,r1))←A(h)(c, (m_0, r_0), (m_1, r_1)) \leftarrow \mathcal A(h)(c,(m0​,r0​),(m1​,r1​))←A(h). Win iff c=gm0hr0c = g^{m_0} h^{r_0}c=gm0​hr0​, c=gm1hr1c = g^{m_1} h^{r_1}c=gm1​hr1​ and m0≠m1m_0 \neq m_1m0​=m1​.
  • CvHP91 collision game. h←G∖{1}h \leftarrow G \setminus \{1\}h←G∖{1}, then (x,x′)←A(h)(x, x') \leftarrow \mathcal A(h)(x,x′)←A(h) with x,x′∈Zp2x, x' \in \mathbb Z_p^2x,x′∈Zp2​. Win iff x≠x′x \neq x'x=x′ and Hg,h(x)=Hg,h(x′)H_{g,h}(x) = H_{g,h}(x')Hg,h​(x)=Hg,h​(x′).
  • kr00TCol x m r m' =r+(m−m′)x−1= r + (m - m') x^{-1}=r+(m−m′)x−1.
  • KR00 collision game. x←Zp∗x \leftarrow \mathbb Z_p^*x←Zp∗​, then ((m,r),(m′,r′))←A(gx)((m, r), (m', r')) \leftarrow \mathcal A(g^x)((m,r),(m′,r′))←A(gx). Win iff m≠m′m \ne m'm=m′ and gmhr=gm′hr′g^m h^r = g^{m'} h^{r'}gmhr=gm′hr′ for h=gxh = g^xh=gx.

Each advantage is the probability that its game outputs true.

Definition code
import Definitions.Def_CryptologyCity_DLogGames
import Mathlib.Algebra.Field.ZMod

/-!
# Cryptology City: Pedersen commitments, the CvHP91 hash and the KR00 chameleon hash

Schemes over one fixed finite cyclic group `G = ⟨g⟩` of order `p`, following
<https://cryptology.city/Reductions/dlog-to-com-ped91>,
<https://cryptology.city/Reductions/dlog-to-crhf-cvhp91> and
<https://cryptology.city/Reductions/prime-order-dlog-to-chameleon-hash-function-kr00>.
Conventions are those of `Definitions.Def_CryptologyCity_DLogGames`: exponents are in `ZMod p`,
`g^x` is `g ^ x.val`, adversaries are arbitrary `PMF`-valued functions, and games output `true`
when the adversary wins.
-/

open scoped ENNReal

namespace CryptologyCity

variable {G : Type*} [Group G]

/-! ## Key distributions -/

/-- The uniform distribution on `G ∖ {1}`. (If `G` is trivial, the point mass at `1`; this case
does not arise for a group of order `p ≥ 2`.) -/
noncomputable def uniformNonOne (G : Type*) [Group G] [Fintype G] [DecidableEq G] : PMF G :=
  if h : (Finset.univ.erase (1 : G)).Nonempty then PMF.uniformOfFinset _ h else PMF.pure 1

/-- The uniform distribution on `ℤ_p^* = ZMod p ∖ {0}`. (If `p = 1`, the point mass at `0`;
this case does not arise for `p ≥ 2`.) -/
noncomputable def uniformNonZero (p : ℕ) [NeZero p] : PMF (ZMod p) :=
  if h : (Finset.univ.erase (0 : ZMod p)).Nonempty then PMF.uniformOfFinset _ h else PMF.pure 0

/-! ## The Pedersen commitment and the CvHP91 hash -/

/-- The Pedersen commitment to `m ∈ ℤ_p` with randomness `r ∈ ℤ_p` under public parameters
`(g, h)`: `g^m h^r`. As a function of `(m, r)` this is also the CvHP91 hash
`H_{g,h}(x₁, x₂) = g^{x₁} h^{x₂}` and the KR00 chameleon hash `CH((g, h), m; r)`. -/
def pedersen (g h : G) {p : ℕ} (m r : ZMod p) : G := g ^ m.val * h ^ r.val

/-- A binding adversary for the Pedersen commitment receives `h` and outputs a commitment `c`
and two decommitments `(m₀, r₀)`, `(m₁, r₁)`. -/
abbrev PedersenBindingAdversary (G : Type*) (p : ℕ) :=
  G → PMF (G × (ZMod p × ZMod p) × (ZMod p × ZMod p))

/-- $\mathrm{Game}^{\mathrm{bind}}$ for the Pedersen commitment: sample `h ← G ∖ {1}`, run the
adversary on `h`, and output whether both decommitments open `c` (`c = g^{m_i} h^{r_i}`) to
distinct messages `m₀ ≠ m₁`. -/
noncomputable def pedersenBindingGame [Fintype G] [DecidableEq G] (g : G) (p : ℕ)
    (A : PedersenBindingAdversary G p) : PMF Bool :=
  (uniformNonOne G).bind fun h =>
    (A h).bind fun out =>
      PMF.pure (decide (out.1 = pedersen g h out.2.1.1 out.2.1.2 ∧
        out.1 = pedersen g h out.2.2.1 out.2.2.2 ∧ out.2.1.1 ≠ out.2.2.1))

/-- $\mathrm{Adv}^{\mathrm{bind}}_{\mathcal A} := \Pr[\mathrm{Game}^{\mathrm{bind}}_{\mathcal A} = 1]$. -/
noncomputable def pedersenBindingAdv [Fintype G] [DecidableEq G] (g : G) (p : ℕ)
    (A : PedersenBindingAdversary G p) : ℝ≥0∞ :=
  pedersenBindingGame g p A true

/-- A collision finder for the CvHP91 hash receives `h` and outputs two inputs in `ℤ_p²`. -/
abbrev CvHPAdversary (G : Type*) (p : ℕ) := G → PMF ((ZMod p × ZMod p) × (ZMod p × ZMod p))

/-- $\mathrm{Game}^{\mathrm{cr}}$ for `H_{g,h}(x₁, x₂) = g^{x₁} h^{x₂}`: sample `h` uniformly
from `G ∖ {1}` (the set of generators of `G` when `|G|` is prime), run the adversary on `h`, and output
whether it returned two distinct inputs with the same hash. -/
noncomputable def cvhpCollisionGame [Fintype G] [DecidableEq G] (g : G) (p : ℕ)
    (A : CvHPAdversary G p) : PMF Bool :=
  (uniformNonOne G).bind fun h =>
    (A h).bind fun out =>
      PMF.pure (decide (out.1 ≠ out.2 ∧
        pedersen g h out.1.1 out.1.2 = pedersen g h out.2.1 out.2.2))

/-- $\mathrm{Adv}^{\mathrm{cr}}_{\mathcal A} := \Pr[\mathrm{Game}^{\mathrm{cr}}_{\mathcal A} = 1]$. -/
noncomputable def cvhpCollisionAdv [Fintype G] [DecidableEq G] (g : G) (p : ℕ)
    (A : CvHPAdversary G p) : ℝ≥0∞ :=
  cvhpCollisionGame g p A true

/-! ## The KR00 chameleon hash -/

/-- `TCol(x, m, r, m') = r + (m - m')/x` in `ℤ_p`. -/
def kr00TCol {p : ℕ} (x m r m' : ZMod p) : ZMod p := r + (m - m') * x⁻¹

/-- A collision finder for the KR00 chameleon hash receives the hash key `h = g^x` and outputs
`(m, r, m', r')`. -/
abbrev KR00Adversary (G : Type*) (p : ℕ) := G → PMF ((ZMod p × ZMod p) × (ZMod p × ZMod p))

/-- $\mathrm{Game}^{\mathrm{cr}}$ for the KR00 chameleon hash: `KeyGen` samples `x ← ℤ_p^*` and
sets `hk = h = g^x`; the adversary receives `h` and wins if it outputs `(m, r), (m', r')` with
`m ≠ m'` and `CH(h, m; r) = CH(h, m'; r')`. -/
noncomputable def kr00CollisionGame [DecidableEq G] (g : G) (p : ℕ) [NeZero p]
    (A : KR00Adversary G p) : PMF Bool :=
  (uniformNonZero p).bind fun x =>
    (A (g ^ x.val)).bind fun out =>
      PMF.pure (decide (out.1.1 ≠ out.2.1 ∧
        pedersen g (g ^ x.val) out.1.1 out.1.2 = pedersen g (g ^ x.val) out.2.1 out.2.2))

/-- $\mathrm{Adv}^{\mathrm{cr}}_{\mathcal A} := \Pr[\mathrm{Game}^{\mathrm{cr}}_{\mathcal A} = 1]$. -/
noncomputable def kr00CollisionAdv [DecidableEq G] (g : G) (p : ℕ) [NeZero p]
    (A : KR00Adversary G p) : ℝ≥0∞ :=
  kr00CollisionGame g p A true

end CryptologyCity
Source
Cryptology City, https://cryptology.city/Reductions/dlog-to-com-ped91, https://cryptology.city/Reductions/dlog-to-crhf-cvhp91, https://cryptology.city/Reductions/prime-order-dlog-to-chameleon-hash-function-kr00; games from https://cryptology.city/Primitives/commitment-scheme#binding and https://cryptology.city/Primitives/chameleon-hash-function.
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Throughout, GGG is an arbitrary group (written multiplicatively, identity 111), g∈Gg \in Gg∈G is an arbitrary element and ppp is an arbitrary natural number. Exponents live in Zp\mathbb{Z}_pZp​ (Mathlib's ZMod p; note that for p=0p = 0p=0 this is Z\mathbb{Z}Z). For a∈Zpa \in \mathbb{Z}_pa∈Zp​, aˉ\bar aaˉ denotes its canonical natural-number representative (in {0,…,p−1}\{0,\dots,p-1\}{0,…,p−1} when p≥1p \ge 1p≥1; ∣a∣|a|∣a∣ when p=0p = 0p=0), and "gag^aga" always means gaˉg^{\bar a}gaˉ, a natural-number power. Nothing in this file assumes that ggg generates GGG, that GGG has order ppp, or that ppp is prime. "Probability" means the mass a probability distribution assigns, valued in [0,∞][0, \infty][0,∞]. Adversaries are arbitrary functions from their input to a probability distribution over outputs; no efficiency, uniformity or computational model is imposed.

Uniform non-identity element. For a finite group GGG with decidable equality, UG∖{1}U_{G\setminus\{1\}}UG∖{1}​ is the uniform distribution on G∖{1}G \setminus \{1\}G∖{1}; if this set is empty (i.e. GGG is trivial), it is instead the point mass at 111.

Uniform non-zero exponent. For p≥1p \ge 1p≥1, UZp∗U_{\mathbb{Z}_p^*}UZp∗​​ is the uniform distribution on Zp∖{0}\mathbb{Z}_p \setminus \{0\}Zp​∖{0}; if this set is empty (i.e. p=1p = 1p=1), it is the point mass at 000. For composite ppp this set includes non-units of Zp\mathbb{Z}_pZp​; it is the set of non-zero residues, not the unit group.

Pedersen function. For g,h∈Gg, h \in Gg,h∈G and m,r∈Zpm, r \in \mathbb{Z}_pm,r∈Zp​,

Pedg,h(m,r):=gmˉ⋅hrˉ∈G.\mathrm{Ped}_{g,h}(m, r) := g^{\bar m} \cdot h^{\bar r} \in G.Pedg,h​(m,r):=gmˉ⋅hrˉ∈G.

The docstring states that this single function serves as the Pedersen commitment, the CvHP91 hash Hg,h(x1,x2)H_{g,h}(x_1,x_2)Hg,h​(x1​,x2​) and the KR00 chameleon hash CH((g,h),m;r)\mathrm{CH}((g,h), m; r)CH((g,h),m;r).

Pedersen binding adversary. A function A\mathcal AA that, given h∈Gh \in Gh∈G, outputs a distribution over tuples (c,(m0,r0),(m1,r1))∈G×Zp2×Zp2(c, (m_0, r_0), (m_1, r_1)) \in G \times \mathbb{Z}_p^2 \times \mathbb{Z}_p^2(c,(m0​,r0​),(m1​,r1​))∈G×Zp2​×Zp2​.

Pedersen binding game and advantage. For finite GGG with decidable equality, g∈Gg \in Gg∈G, p∈Np \in \mathbb{N}p∈N and a binding adversary A\mathcal AA: sample h←UG∖{1}h \leftarrow U_{G\setminus\{1\}}h←UG∖{1}​, then (c,(m0,r0),(m1,r1))←A(h)(c, (m_0,r_0), (m_1,r_1)) \leftarrow \mathcal A(h)(c,(m0​,r0​),(m1​,r1​))←A(h), and output 111 iff

c=Pedg,h(m0,r0)  ∧  c=Pedg,h(m1,r1)  ∧  m0≠m1.c = \mathrm{Ped}_{g,h}(m_0, r_0) \;\wedge\; c = \mathrm{Ped}_{g,h}(m_1, r_1) \;\wedge\; m_0 \ne m_1 .c=Pedg,h​(m0​,r0​)∧c=Pedg,h​(m1​,r1​)∧m0​=m1​.

Only the messages must differ; r0=r1r_0 = r_1r0​=r1​ is allowed. Advg,pbind(A)\mathrm{Adv}^{\mathrm{bind}}_{g,p}(\mathcal A)Advg,pbind​(A) is the probability that this game outputs 111. The value ggg is used only inside Ped\mathrm{Ped}Ped; A\mathcal AA is not given ggg explicitly (it is a fixed parameter).

CvHP91 collision adversary. A function A\mathcal AA that, given h∈Gh \in Gh∈G, outputs a distribution over pairs ((x1,x2),(x1′,x2′))∈Zp2×Zp2((x_1,x_2),(x_1',x_2')) \in \mathbb{Z}_p^2 \times \mathbb{Z}_p^2((x1​,x2​),(x1′​,x2′​))∈Zp2​×Zp2​.

CvHP91 collision game and advantage. For finite GGG with decidable equality: sample h←UG∖{1}h \leftarrow U_{G\setminus\{1\}}h←UG∖{1}​, then ((x1,x2),(x1′,x2′))←A(h)((x_1,x_2),(x_1',x_2')) \leftarrow \mathcal A(h)((x1​,x2​),(x1′​,x2′​))←A(h), and output 111 iff

(x1,x2)≠(x1′,x2′)  ∧  Pedg,h(x1,x2)=Pedg,h(x1′,x2′).(x_1,x_2) \ne (x_1',x_2') \;\wedge\; \mathrm{Ped}_{g,h}(x_1,x_2) = \mathrm{Ped}_{g,h}(x_1',x_2').(x1​,x2​)=(x1′​,x2′​)∧Pedg,h​(x1​,x2​)=Pedg,h​(x1′​,x2′​).

AdvCvHP,g,pcr(A)\mathrm{Adv}^{\mathrm{cr}}_{\mathrm{CvHP},g,p}(\mathcal A)AdvCvHP,g,pcr​(A) is the probability of output 111. The code samples hhh uniformly from G∖{1}G \setminus \{1\}G∖{1} for every finite GGG, whatever its order; the docstring says the same and adds that this set is the set of generators of GGG when ∣G∣|G|∣G∣ is prime. Nothing in the definition requires ∣G∣|G|∣G∣ to be prime, so for other orders hhh may be a non-generator.

KR00 trapdoor-collision function. For x,m,r,m′∈Zpx, m, r, m' \in \mathbb{Z}_px,m,r,m′∈Zp​,

TCol(x,m,r,m′):=r+(m−m′)⋅x−1∈Zp,\mathrm{TCol}(x, m, r, m') := r + (m - m')\cdot x^{-1} \in \mathbb{Z}_p,TCol(x,m,r,m′):=r+(m−m′)⋅x−1∈Zp​,

where x−1x^{-1}x−1 is Mathlib's total inverse on Zp\mathbb{Z}_pZp​: for prime ppp it is the field inverse with 0−1=00^{-1} = 00−1=0; for non-prime ppp and non-unit xxx it is a junk value (and 0−1=00^{-1} = 00−1=0).

KR00 collision adversary. A function A\mathcal AA that, given h∈Gh \in Gh∈G, outputs a distribution over ((m,r),(m′,r′))∈Zp2×Zp2((m, r), (m', r')) \in \mathbb{Z}_p^2 \times \mathbb{Z}_p^2((m,r),(m′,r′))∈Zp2​×Zp2​.

KR00 collision game and advantage. For GGG with decidable equality (not necessarily finite) and p≥1p \ge 1p≥1: sample x←UZp∗x \leftarrow U_{\mathbb{Z}_p^*}x←UZp∗​​, set h:=gxˉh := g^{\bar x}h:=gxˉ, run ((m,r),(m′,r′))←A(h)((m,r),(m',r')) \leftarrow \mathcal A(h)((m,r),(m′,r′))←A(h), and output 111 iff

m≠m′  ∧  Pedg,h(m,r)=Pedg,h(m′,r′).m \ne m' \;\wedge\; \mathrm{Ped}_{g,h}(m, r) = \mathrm{Ped}_{g,h}(m', r').m=m′∧Pedg,h​(m,r)=Pedg,h​(m′,r′).

AdvKR00,g,pcr(A)\mathrm{Adv}^{\mathrm{cr}}_{\mathrm{KR00},g,p}(\mathcal A)AdvKR00,g,pcr​(A) is the probability of output 111. Here, unlike the CvHP91 game, the messages must differ (differing only in rrr does not count), and hhh is distributed as gxˉg^{\bar x}gxˉ for uniform non-zero xxx rather than uniform on G∖{1}G \setminus \{1\}G∖{1}.

Imported notions used below. IsCyclic(g,p)\mathrm{IsCyclic}(g, p)IsCyclic(g,p) means every element of GGG is an integer power of ggg and the order of ggg is exactly ppp (Mathlib's orderOf, which is 000 for an element of infinite order); with ppp prime this makes GGG cyclic of order ppp generated by ggg. For p≥1p \ge 1p≥1 and a DLOG adversary B:G→Dist(Zp)\mathcal B : G \to \mathrm{Dist}(\mathbb{Z}_p)B:G→Dist(Zp​), the DLOG game samples xxx uniformly from all of Zp\mathbb{Z}_pZp​ (including 000), runs x′←B(gxˉ)x' \leftarrow \mathcal B(g^{\bar x})x′←B(gxˉ), and outputs 111 iff x′=xx' = xx′=x; Advg,pdl(B)∈[0,∞]\mathrm{Adv}^{\mathrm{dl}}_{g,p}(\mathcal B) \in [0,\infty]Advg,pdl​(B)∈[0,∞] is the probability of output 111.

Human review
  • Endorsed by Shuze Chen · Nov 30, 2026

    Confirmed by the moderator at approval.

  • Endorsed by axhoover · Nov 30, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me