Cryptology City: Feldman and Pedersen verifiable secret sharing
DefinitionCityVSScryptographysecret-sharing
Verifiable secret sharing over a cyclic group of prime order , in the conventions of CryptologyCity_DLogGames (exponents in , adversaries are arbitrary PMF-valued functions).
- ; parties sit at points .
- Lagrange reconstruction on a set : , .
evalCommitat : (in index order).- Feldman: commitments ; a share at passes iff . The simulator
feldmanSimcomputes, from and shares for a coalition , the commitments , where is the -th coefficient of the Lagrange basis polynomial of node on the nodes . The secret-recovery game samples uniformly, gives the adversary the commitments and 's shares, and checks whether it outputs ;feldmanToDLogturns an adversary into a DLOG adversary that runs it onfeldmanSimof its challenge and uniform shares. - Pedersen: coins are ; commitments with ; the party at gets and accepts iff .
pedersenVSSViewis the law of (commitments, 's shares) under uniform coins. - A cheating dealer receives and outputs commitments, one share per party and two sets ; it wins if , all shares in pass, and (on the components).
vssBindingGamesamples uniformly from .dealerToBindingoutputs with the two openings and .
Definition code
import Definitions.Def_CryptologyCity_DLogCommitments
import Mathlib.LinearAlgebra.Lagrange
/-!
# Cryptology City: Feldman and Pedersen verifiable secret sharing
Conventions of `Def_CryptologyCity_DLogGames`: a group `G` with generator `g` of order `p`,
exponents in `ZMod p`, `g^x` is `g ^ x.val`, adversaries are arbitrary `PMF`-valued functions.
A dealer shares `s ∈ ℤ_p` among parties `0, …, n-1`, held at evaluation points
`α : Fin n → ℤ_p`, using a polynomial of degree `≤ t`; any `t+1` shares reconstruct, and
coalitions of `≤ t` parties should learn nothing (beyond `g^s` for Feldman).
-/
open scoped ENNReal
namespace CryptologyCity.VSS
open Finset
variable {p : ℕ}
/-- `s + c₀ x + ⋯ + c_{t-1} xᵗ`. -/
def poly {t : ℕ} (s : ZMod p) (c : Fin t → ZMod p) (x : ZMod p) : ZMod p :=
s + ∑ j : Fin t, c j * x ^ (j.val + 1)
/-- Lagrange coefficient at `0` for party `i` within the set `S`:
`∏_{k ∈ S, k ≠ i} α k / (α k - α i)`. -/
def lamOn [Fact p.Prime] {n : ℕ} (α : Fin n → ZMod p) (S : Finset (Fin n)) (i : Fin n) : ZMod p :=
∏ k ∈ S.erase i, α k / (α k - α i)
/-- Reconstruction from the shares of the parties in `S`: `∑_{i ∈ S} λᵢ^S vᵢ`. -/
def reconOn [Fact p.Prime] {n : ℕ} (α : Fin n → ZMod p) (S : Finset (Fin n)) (v : Fin n → ZMod p) :
ZMod p :=
∑ i ∈ S, lamOn α S i * v i
variable {G : Type*} [Group G]
/-- The group element `C₀^{x⁰} C₁^{x¹} ⋯ Cₜ^{xᵗ}` that a share at point `x` is checked
against (product in index order, so `G` need not be commutative). -/
def evalCommit {t : ℕ} (C : Fin (t + 1) → G) (x : ZMod p) : G :=
((List.finRange (t + 1)).map fun j => C j ^ (x ^ j.val).val).prod
/-! ## Feldman VSS -/
/-- Feldman commitments to `f(X) = s + ∑ cⱼ X^{j+1}`: `(g^s, g^{c₀}, …, g^{c_{t-1}})`. -/
def feldmanCommit (g : G) {t : ℕ} (s : ZMod p) (c : Fin t → ZMod p) : Fin (t + 1) → G :=
Fin.cons (g ^ s.val) fun j => g ^ (c j).val
/-- Feldman's check of the share `σ` at point `x` against commitments `C`:
`g^σ = ∏ⱼ Cⱼ^{xʲ}`. -/
def feldmanCheck (g : G) {t : ℕ} (C : Fin (t + 1) → G) (x σ : ZMod p) : Prop :=
g ^ σ.val = evalCommit C x
/-- Feldman simulator: from `X = g^s` and uniformly chosen shares `u` for the parties in `T`,
compute in the exponent the commitments of the unique polynomial of degree `≤ |T|` through
`(0, s)` and `(α i, u i)`, using the Lagrange basis on the nodes `{0} ∪ α(T)`. -/
noncomputable def feldmanSim [Fact p.Prime] (g : G) {n t : ℕ} (α : Fin n → ZMod p)
(T : Finset (Fin n)) (X : G) (u : T → ZMod p) : Fin (t + 1) → G :=
fun j =>
let N : Finset (ZMod p) := insert 0 (T.image α)
X ^ ((Lagrange.basis N id 0).coeff j.val).val *
g ^ (∑ i : T, u i * (Lagrange.basis N id (α i)).coeff j.val).val
/-- A secret-recovery adversary against Feldman VSS for the coalition `T`: given the
commitments and `T`'s shares, it guesses the secret. -/
abbrev FeldmanAdversary (G : Type*) (p t : ℕ) {n : ℕ} (T : Finset (Fin n)) :=
(Fin (t + 1) → G) → (T → ZMod p) → PMF (ZMod p)
/-- Secret-recovery game: sample `s` and `c` uniformly, give the adversary the commitments and
`T`'s shares, and output whether it returns `s`. -/
noncomputable def feldmanRecoveryGame (g : G) [NeZero p] {n t : ℕ} (α : Fin n → ZMod p)
(T : Finset (Fin n)) (A : FeldmanAdversary G p t T) : PMF Bool :=
(PMF.uniformOfFintype (ZMod p × (Fin t → ZMod p))).bind fun sc =>
(A (feldmanCommit g sc.1 sc.2) fun i => poly sc.1 sc.2 (α i)).bind fun s' =>
PMF.pure (decide (s' = sc.1))
/-- The DLOG adversary built from a Feldman adversary: run it on simulated commitments and
uniformly random shares. -/
noncomputable def feldmanToDLog [Fact p.Prime] (g : G) {n t : ℕ} (α : Fin n → ZMod p)
(T : Finset (Fin n)) (A : FeldmanAdversary G p t T) : DLogAdversary G p :=
fun X => (PMF.uniformOfFintype (T → ZMod p)).bind fun u => A (feldmanSim g α T X u) u
/-! ## Pedersen VSS -/
/-- Dealer coins of Pedersen VSS: the higher coefficients `a` of `f` and all coefficients `b`
of the blinding polynomial `f'`. -/
abbrev PedersenCoins (p t : ℕ) := (Fin t → ZMod p) × (Fin (t + 1) → ZMod p)
/-- Pedersen VSS commitments `Cⱼ = g^{fⱼ} h^{f'ⱼ}`, where `f = s + ∑ aⱼ X^{j+1}` and
`f' = ∑ bⱼ Xʲ`. -/
def pedersenVSSCommit (g h : G) {t : ℕ} (s : ZMod p) (r : PedersenCoins p t) :
Fin (t + 1) → G :=
fun j => pedersen g h ((Fin.cons s r.1 : Fin (t + 1) → ZMod p) j) (r.2 j)
/-- Party at point `x` receives `(f(x), f'(x))`. -/
def pedersenVSSShare {t : ℕ} (s : ZMod p) (r : PedersenCoins p t) (x : ZMod p) :
ZMod p × ZMod p :=
(poly s r.1 x, poly (r.2 0) (fun j => r.2 j.succ) x)
/-- Pedersen's check of the share `(σ, ρ)` at `x`: `g^σ h^ρ = ∏ⱼ Cⱼ^{xʲ}`. -/
def pedersenCheck (g h : G) {t : ℕ} (C : Fin (t + 1) → G) (x : ZMod p)
(sh : ZMod p × ZMod p) : Prop :=
pedersen g h sh.1 sh.2 = evalCommit C x
/-- The view of the coalition `T`: all commitments and `T`'s shares, under uniform coins. -/
noncomputable def pedersenVSSView (g h : G) [NeZero p] {n t : ℕ} (α : Fin n → ZMod p)
(T : Finset (Fin n)) (s : ZMod p) : PMF ((Fin (t + 1) → G) × (T → ZMod p × ZMod p)) :=
(PMF.uniformOfFintype (PedersenCoins p t)).map fun r =>
(pedersenVSSCommit g h s r, fun i => pedersenVSSShare s r (α i))
/-- A cheating dealer receives `h` and outputs commitments, one share per party, and two
sets of parties. -/
abbrev CheatingDealer (G : Type*) (p t n : ℕ) :=
G → PMF ((Fin (t + 1) → G) × (Fin n → ZMod p × ZMod p) × Finset (Fin n) × Finset (Fin n))
/-- The dealer wins if both sets have `t+1` parties, every share in them passes the check,
and the two sets reconstruct different secrets. -/
def dealerWins [Fact p.Prime] (g h : G) {n t : ℕ} (α : Fin n → ZMod p)
(out : (Fin (t + 1) → G) × (Fin n → ZMod p × ZMod p) × Finset (Fin n) × Finset (Fin n)) :
Prop :=
out.2.2.1.card = t + 1 ∧ out.2.2.2.card = t + 1 ∧
(∀ i ∈ out.2.2.1 ∪ out.2.2.2, pedersenCheck g h out.1 (α i) (out.2.1 i)) ∧
reconOn α out.2.2.1 (fun i => (out.2.1 i).1) ≠ reconOn α out.2.2.2 (fun i => (out.2.1 i).1)
/-- VSS binding game: sample `h ← G ∖ {1}`, run the dealer on `h`, and output whether it wins. -/
noncomputable def vssBindingGame [Fact p.Prime] [Fintype G] [DecidableEq G] (g : G) {n t : ℕ}
(α : Fin n → ZMod p) (A : CheatingDealer G p t n) : PMF Bool := by
classical
exact (uniformNonOne G).bind fun h => (A h).bind fun out =>
PMF.pure (decide (dealerWins g h α out))
/-- The Pedersen binding adversary built from a cheating dealer: open `C₀` twice by
recombining each set's shares. -/
noncomputable def dealerToBinding [Fact p.Prime] {n t : ℕ} (α : Fin n → ZMod p) (A : CheatingDealer G p t n) :
PedersenBindingAdversary G p :=
fun h => (A h).map fun out =>
(out.1 0,
(reconOn α out.2.2.1 (fun i => (out.2.1 i).1), reconOn α out.2.2.1 (fun i => (out.2.1 i).2)),
(reconOn α out.2.2.2 (fun i => (out.2.1 i).1), reconOn α out.2.2.2 (fun i => (out.2.1 i).2)))
end CryptologyCity.VSS