Lesson 15 of 15

Zero-Knowledge Proofs (Schnorr)

Zero-Knowledge Proofs

A zero-knowledge proof (ZKP) lets a prover convince a verifier that they know a secret, without revealing the secret itself. Introduced by Goldwasser, Micali, and Rackoff (1985), ZKPs are a cornerstone of modern cryptography.

Three Properties of a ZKP

  • Completeness — if the prover knows the secret, they can always convince the verifier
  • Soundness — a cheating prover (who doesn't know the secret) cannot convince the verifier except with negligible probability
  • Zero-knowledge — the verifier learns nothing about the secret beyond its existence

Schnorr Identification Protocol

The Schnorr protocol (Claus Schnorr, 1989) proves knowledge of a discrete logarithm in zero-knowledge.

Setup: prime pp, subgroup of order qq (where qp1q | p-1), generator gg of order qq.

Public key: y=gxmodpy = g^x \bmod p (prover knows private key xx).

Protocol (3 moves):

  1. Commit: Prover picks random rr, sends t=grmodpt = g^r \bmod p
  2. Challenge: Verifier sends random cc
  3. Respond: Prover sends s=(r+cx)modqs = (r + c \cdot x) \bmod q

Verification:

gs=?tyc(modp)g^s \stackrel{?}{=} t \cdot y^c \pmod{p}

This works because: gs=gr+cx=gr(gx)c=tycg^s = g^{r + cx} = g^r \cdot (g^x)^c = t \cdot y^c

Example

p=23p=23, q=11q=11, g=2g=2, private key x=3x=3, public key y=23mod23=8y = 2^3 \bmod 23 = 8.

  • Commit: r=5r=5, t=25mod23=9t = 2^5 \bmod 23 = 9
  • Challenge: c=4c = 4
  • Response: s=(5+4×3)mod11=6s = (5 + 4 \times 3) \bmod 11 = 6
  • Verify: 26mod23=64mod23=18=984mod232^6 \bmod 23 = 64 \bmod 23 = 18 = 9 \cdot 8^4 \bmod 23

Your Task

Implement:

  • schnorr_commitment(g, r, p)grmodpg^r \bmod p
  • schnorr_response(r, challenge, priv_key, q)(r+challenge×priv_key)modq(r + \text{challenge} \times \text{priv\_key}) \bmod q
  • schnorr_verify(g, pub_key, commitment, challenge, response, p, q)bool
Python runtime loading...
Loading...
Click "Run" to execute your code.