Documentation

CslibFrontier.Crypto.Computational.SchnorrProtocol

Schnorr's Sigma protocol with an efficient prover, verifier, extractor and simulator #

Schnorr's Sigma protocol ([BS23], Example 19.1) over a PrimeOrderGroupFamily, as a family indexed by a unary security parameter n and a group description d, with challenges in ZMod q for the group order q. Group elements are encoded by the family's encoding and scalars in binary (schnorrEncoding).

Two protocol families share the same response function, verifier (encodeSchnorrVerify, efficientVerifier_schnorr, efficientVerifier_schnorrProb) and extractor (schnorrExtract):

Main results for the protocol:

Main definitions #

Main results #

Ideal-sampling steps toward Example 19.3 #

References #

Group elements as words, through the family's injective encoding.

Scalars modulo the group order as binary numbers, through their least nonnegative representatives.

Schnorr's Sigma protocol ([BS23], Example 19.1) in the group described by i.2, with challenges in ZMod q. The security parameter i.1 does not change the protocol. The honest prover draws its commitment nonce exactly uniformly on ZMod q at the PMF level, an ideal sampler that no fair-coin machine with a strict polynomial time bound realizes exactly when q is not a power of two; see schnorrProbFamily for the fair-coin sampleExp prover.

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.schnorrProbCommit (F : PrimeOrderGroupFamily) (i : ℕ × F.Desc) :
ZMod (F.order i.2) → F.Carrier i.2 → ProbComp (F.Carrier i.2 × ZMod (F.order i.2))

Fair-coin commitment sampler for Schnorr's Sigma protocol ([BS23], Figure 19.1, p. 756, and Example 19.1, p. 773): at index i = (n, d), draw s ← F.sampleExp n d, read r = s mod q, and return (r • g, r).

Schnorr's Sigma protocol ([BS23], Figure 19.1, p. 756, and Example 19.1, p. 773) with a fair-coin commitment sampler: at index i = (n, d), the honest prover commits with schnorrProbCommit i (sampleExp n d), responds with r + c * α, and the verifier checks z • g = t + c • u.

Schnorr's Sigma protocol in F.Carrier d with m-bit challenges BitString m, embedded as scalars by challengeEmbedding when 2 ^ m ≤ F.order d.

def Cslib.Crypto.PrimeOrderGroupFamily.schnorrEncoding (F : PrimeOrderGroupFamily) :
Protocols.SigmaProtocol.Encoding (ℕ × F.Desc) (fun (i : ℕ × F.Desc) => F.Carrier i.2) (fun (i : ℕ × F.Desc) => F.Carrier i.2) (fun (i : ℕ × F.Desc) => ZMod (F.order i.2)) fun (i : ℕ × F.Desc) => ZMod (F.order i.2)

The word encodings of schnorrFamily: the unary security parameter with the description, group elements by the family's encoding, and challenges and responses in binary.

def Cslib.Crypto.PrimeOrderGroupFamily.schnorrExtract (F : PrimeOrderGroupFamily) (i : ℕ × F.Desc) :
F.Carrier i.2 → F.Carrier i.2 → (c z c' z' : ZMod (F.order i.2)) → ZMod (F.order i.2)

Schnorr's extractor ([BS23], Example 19.2), computed with extractNat: it is (c - c')⁻¹ (z - z') whenever c ≠ c'.

Schnorr's extractor on words: on the index (n, d) and the binary challenges and responses of two conversations, return extractNat of their values in binary. It computes schnorrExtract on encodings (extractorRealizedBy_schnorrExtractWord).

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.schnorrSimulator (F : PrimeOrderGroupFamily) :
Protocols.SigmaProtocol.Simulator (ℕ × F.Desc) (fun (i : ℕ × F.Desc) => F.Carrier i.2) (fun (i : ℕ × F.Desc) => F.Carrier i.2) (fun (i : ℕ × F.Desc) => ZMod (F.order i.2)) fun (i : ℕ × F.Desc) => ZMod (F.order i.2)

Schnorr's simulator ([BS23], Example 19.3) with fair coins: at index (n, d), on a statement u and a challenge c, sample s with sampleExp n d, read it as the response z = s mod q, and return the commitment z • g - c • u with z.

Schnorr's simulator on words ([BS23], Example 19.3): on the index (n, d), an encoded statement u and a binary challenge c, sample s with sampleExp n d and return the encodings of s • g - c • u and of s mod q. It is the strict PPT certificate of schnorrSimulator (eval_schnorrSimulateWord); SchnorrEavesdrop also runs it on arbitrary challenge words.

Special soundness #

Schnorr's protocol has efficient special soundness ([BS23], Example 19.2).

Special HVZK #

A challenge sampler for schnorrFamily with fair coins: at index (n, d), sample s with sampleExp n d and read it modulo the group order. It is within statistical distance 1 / 2 ^ n of uniform (closeTo_schnorrSampleChallenge).

Reducing a computed binary natural modulo the group order F.order (d a) and encoding the remainder in binary is computable in polynomial time.

One machine samples the encoded challenges of schnorrSampleChallenge from the encoded index: it samples s with sampleExp n d and writes the binary encoding of s mod q.

A word-level commitment step k • b + (q - c % q) • x computed with the family's word operations is computable in polynomial time from polynomial-time components.

schnorrSimulator realizes Schnorr's perfect simulator linearSimulate ([BS23], Example 19.3) up to statistical distance 1 / 2 ^ n at security parameter n.

Ideal-sampling step toward [BS23], Example 19.3 (special HVZK, Definition 19.5), not the cited result: against the honest prover of schnorrFamily, which draws its commitment nonce exactly uniformly on ZMod q at the PMF level, linearSimulate is a perfect simulator, and the strict PPT simulator schnorrSimulator realizes it with statistical error 1 / 2 ^ n at security parameter n. Consumed by closeTo_transcript_schnorrProbFamily_simulator and advantage_chvzkGame_schnorrProbFamily_le for the fair-coin prover schnorrProbFamily.

theorem Cslib.Crypto.PrimeOrderGroupFamily.accepts_schnorrSimulator (F : PrimeOrderGroupFamily) (i : ℕ × F.Desc) (u : F.Carrier i.2) (c : ZMod (F.order i.2)) :
(F.schnorrSimulator i u c).eval.toOuterMeasure {tz : (fun (i : ℕ × F.Desc) => F.Carrier i.2) i × (fun (i : ℕ × F.Desc) => ZMod (F.order i.2)) i | (F.schnorrFamily i).Accepts u tz.1 c tz.2} = 1

Every output of schnorrSimulator is an accepting conversation (acceptance error 0): for every sampled z, (z • g - c • u) + c • u = z • g.

theorem Cslib.Crypto.PrimeOrderGroupFamily.computationalSpecialHVZK_schnorr_ideal (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) :
Protocols.SigmaProtocol.ComputationalSpecialHVZK F.schnorrFamily (fun (i : ℕ × F.Desc) (α : ZMod (F.order i.2)) (u : F.Carrier i.2) => α • F.generator i.2 = u) F.schnorrEncoding (fun (i : ℕ × F.Desc) => F.encScalar i.2) (fun (n : ℕ) => PMF.map (fun (x : F.Desc) => (n, x)) (setup n)) F.schnorrSimulator fun (x : ℕ × F.Desc) => 0

Ideal-sampling step toward [BS23], Example 19.3 with Definition 20.6 (special computational HVZK), not the cited result: Experiment 0 of Attack Game 20.4 runs the honest prover of schnorrFamily, which draws its commitment nonce exactly uniformly on ZMod q at the PMF level, and against it the strict PPT simulator schnorrSimulator satisfies Definition 20.6 with zero acceptance error (δ = fun _ => 0) over any group-description setup setup : ℕ → PMF F.Desc paired with the security parameter. Consumed by computationalSpecialHVZK_schnorr for the fair-coin prover schnorrProbFamily.

Fair-coin schnorrProbFamily completeness, special soundness, and special HVZK #

Completeness of the fair-coin Schnorr Sigma protocol ([BS23], Figure 19.1, p. 756, and Example 19.1 with Definition 19.3, pp. 772–773): for every valid discrete-logarithm pair α • g = u and every challenge c, every honest transcript of schnorrProbFamily i is accepting.

Efficient special soundness of the fair-coin Schnorr Sigma protocol ([BS23], Example 19.2 with Definition 19.4, p. 773): schnorrProbFamily shares the verifier of schnorrFamily, so schnorrExtract (schnorrExtractWord) extracts α in polynomial time.

On every valid discrete-logarithm pair (α, u) and challenge c, the honest transcript of the fair-coin schnorrProbFamily and the output of the strict PPT simulator schnorrSimulator are within statistical distance 2 / 2 ^ n (1 / 2 ^ n from the prover's sampleExp commitment nonce and 1 / 2 ^ n from the simulator's sampleExp response; [BS23], Example 19.3 with Definition 19.5, p. 774, relaxing Definition 19.5(ii)'s identical transcript distribution to 2 / 2 ^ n statistical closeness in the strict-PPT fair-coin model, cf. Definition 2.8, p. 30). Derived from efficientSpecialHVZK_schnorr_ideal via closeTo_transcript_linearProbFamily_simulator.

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_chvzkGame_schnorrProbFamily_le (F : PrimeOrderGroupFamily) {σ : Type} (setup : ℕ → PMF F.Desc) (A : Protocols.SigmaProtocol.CHVZKAdversary (ℕ × F.Desc) (fun (i : ℕ × F.Desc) => ZMod (F.order i.2)) (fun (i : ℕ × F.Desc) => F.Carrier i.2) (fun (i : ℕ × F.Desc) => F.Carrier i.2) (fun (i : ℕ × F.Desc) => ZMod (F.order i.2)) (fun (i : ℕ × F.Desc) => ZMod (F.order i.2)) σ) (n : ℕ) :
(Protocols.SigmaProtocol.chvzkRealGame F.schnorrProbFamily (fun (i : ℕ × F.Desc) (α : ZMod (F.order i.2)) (u : F.Carrier i.2) => α • F.generator i.2 = u) (fun (m : ℕ) => PMF.map (fun (x : F.Desc) => (m, x)) (setup m)) A n).advantage (Protocols.SigmaProtocol.chvzkSimGame (fun (i : ℕ × F.Desc) (α : ZMod (F.order i.2)) (u : F.Carrier i.2) => α • F.generator i.2 = u) (fun (m : ℕ) => PMF.map (fun (x : F.Desc) => (m, x)) (setup m)) F.schnorrSimulator A n) ≤ 2 / 2 ^ n

In Attack Game 20.4 (chvzkRealGame vs chvzkSimGame), the fair-coin Schnorr prover schnorrProbFamily and the strict PPT simulator schnorrSimulator differ in distinguishing advantage by at most 2 / 2 ^ n against every adversary (including computationally unbounded ones). Derived from efficientSpecialHVZK_schnorr_ideal via advantage_chvzkGame_linearProbFamily_le.

theorem Cslib.Crypto.PrimeOrderGroupFamily.computationalSpecialHVZK_schnorr (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) :
Protocols.SigmaProtocol.ComputationalSpecialHVZK F.schnorrProbFamily (fun (i : ℕ × F.Desc) (α : ZMod (F.order i.2)) (u : F.Carrier i.2) => α • F.generator i.2 = u) F.schnorrEncoding (fun (i : ℕ × F.Desc) => F.encScalar i.2) (fun (n : ℕ) => PMF.map (fun (x : F.Desc) => (n, x)) (setup n)) F.schnorrSimulator fun (x : ℕ × F.Desc) => 0

Schnorr's fair-coin Sigma protocol satisfies computational special HVZK ([BS23], Example 19.3, Section 19.4.2, p. 774, with Definition 20.6, Section 20.4.2, p. 840): Example 19.3 states exact special HVZK (Definition 19.5(ii), under Definition 2.8's negligible-overflow runtime convention, p. 30); in the strict-PPT fair-coin model exact simulation on ZMod q is impossible when q is not a power of two, so Definition 19.5(ii) is relaxed here to the 2 / 2 ^ n statistical form (closeTo_transcript_schnorrProbFamily_simulator) and Definition 20.6. Against the fair-coin honest prover of schnorrProbFamily, the strict PPT simulator schnorrSimulator satisfies Definition 20.6 with exact zero acceptance error (δ = fun _ => 0) over any group-description setup setup : ℕ → PMF F.Desc paired with the security parameter. Derived from computationalSpecialHVZK_schnorr_ideal via computationalSpecialHVZK_linearProbFamily.

Shared bit-encoded Schnorr key generation, commitment, response, and verification #

Ideal encoded Schnorr key generation for group description d: sample a uniform secret scalar α : ZMod (F.order d) and output the encoded public key F.encode d (α • F.generator d) paired with the binary-encoded secret key F.encScalar d α.

Bit-encoded Schnorr key generation at security parameter n and group description d ([BS23], Sections 19.1–19.2): sample an approximate uniform exponent sk ← F.sampleExp n d and output the encoded public key F.smul (d, sk, F.encode d (F.generator d)) together with the binary secret key (sk % F.order d).bits.

Output distribution of schnorrSigKeyGen: the sampled exponent modulo F.order d determines the encoded public key α • g and secret scalar α.

schnorrSigKeyGen n d is within statistical distance 1 / 2 ^ n of the ideal encoded Schnorr key generator schnorrIdealKeyGen d.

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_bind_schnorrSigKeyGen_le (F : PrimeOrderGroupFamily) (n : ℕ) (d : F.Desc) (continuation : List Bool → ZMod (F.order d) → Game) :
Game.advantage ((F.schnorrSigKeyGen n d).eval.bind fun (pksk : List Bool × List Bool) => continuation pksk.1 ↑(Turing.MultiTapeTM.ofBits pksk.2)) ((Probability.PMF.uniformOfFintype (ZMod (F.order d))).bind fun (α : ZMod (F.order d)) => continuation (F.encode d (α • F.generator d)) α) ≤ 1 / 2 ^ n

Replacing schnorrSigKeyGen n d with an exact uniform secret key α ← PMF.uniformOfFintype (ZMod (F.order d)) changes any Boolean continuation on the encoded public key and secret scalar (ofBits sk : ZMod (F.order d)) by at most 1 / 2 ^ n.

Bit-level Schnorr commitment: given (d, r) where r is the binary-encoded commitment exponent, compute the encoded group element r • g.

@[simp]

On an encoded scalar r : ZMod (F.order d), schnorrCommitBits produces F.encode d (r • g).

@[reducible, inline]

Input (d, a, b, c) of the bit-level Schnorr response and commitment-recovery maps: a group description d, then three bit words. The description and the first two words are framed.

Bit-level Schnorr response: given (d, sk, r, roOut) where sk is the encoded secret key, r is the encoded commitment randomness, and roOut is the challenge bit string, compute ((ofBits r + ofBits roOut * ofBits sk) % F.order d).bits.

@[simp]

On encoded scalars α, r : ZMod (F.order d), schnorrRespondBits computes the encoded scalar r + (ofBits roOut : ZMod (F.order d)) * α.

Bit-level Schnorr commitment recovery ([BS23], Sections 19.1 and 19.2.1): given (d, pk, c, z), compute the encoded group element z • g - c • pk.

@[simp]

On an encoded public key pk = F.encode d u, schnorrRecoverCommitBits computes the encoding of z • g - roOut • u.

Polynomial-time Schnorr verification on an encoded public key pk, commitment word t, challenge word c, and response word z: compares t with the canonical commitment recovery schnorrRecoverCommitBits (d, pk, c, z).

@[simp]

On a canonical encoded public key F.encode d u, encodeSchnorrVerify agrees with the algebraic Schnorr verification check t = encode (z • g - c • u).

Under a canonical public key F.encode d u, encodeSchnorrVerify accepts if and only if t equals the canonical encoding of z • g - c • u.

The uniform strict PPT program schnorrSigKeyGen (isPPTOn_schnorrSigKeyGen) computes the encoded commitment and scalar private state of schnorrProbCommit on encodings (the commitment r • g uses neither the witness α nor the statement u; see [BS23], Figure 19.1, p. 756, and the remark after Example 19.1, p. 773, that the prover does not use the statement).