Cybersecurity

The Color-Blind Verifier: A Simple Analogy

LLMs Encryption Cryptography Web Security Authentication OAuth Rust Credentials Passwords Hashing Certificates TLS HTTPS
992 words Includes Code

Prove you know a password without sending it. Verify identity without revealing personal data. Validate transactions without exposing details. Welcome to zero-knowledge proofs.

Key Takeaway: Zero-knowledge proofs (ZKPs) let you prove you know something without revealing what you know. They're used in password authentication, blockchain privacy, identity verification, and secure voting — and every developer should understand the concept.

The Color-Blind Verifier: A Simple Analogy

Alice has two balls: one RED, one GREEN. Bob is color-blind. Alice wants to prove the balls are different colors without revealing which is which.

The Protocol:

  1. Bob shows Alice both balls
  2. Bob takes them behind his back and shows Alice one ball
  3. Bob puts it back, may or may not swap them, then shows Alice again
  4. Alice says "same" or "different"

After 20 rounds:

  • If Alice is honest, she always gets it right
  • If she's lying, she gets it wrong 50% of the time
  • After 20 rounds, a cheater is caught 99.9999% of the time

Key insight: Bob never learns which ball is red. Alice proved knowledge without revealing it.

This is the essence of a zero-knowledge proof.

What Makes Something a ZKP?

A zero-knowledge proof must satisfy three properties:

PropertyWhat It MeansSimple Explanation
CompletenessIf the statement is true, an honest prover convinces an honest verifierHonest proof always works
SoundnessIf the statement is false, no cheater can convince the verifier (except with tiny probability)Cheating is detected
Zero-KnowledgeThe verifier learns nothing beyond the fact that the statement is trueNo secret leaked

If your proof doesn't have all three, it's not a ZKP — it might be just a regular proof, or it might leak information.

Hash-Based Commitment: A Developer's First ZKP

The simplest ZKP is a commitment scheme. It works like sealing a secret in an envelope:

import hashlib, secrets

def create_commitment(secret: bytes) -> tuple:
    """Step 1: Prover creates commitment (sealed envelope)"""
    nonce = secrets.token_bytes(16)
    commitment = hashlib.sha256(secret + nonce).digest()
    return commitment, nonce

def verify_commitment(commitment: bytes, secret: bytes, nonce: bytes) -> bool:
    """Step 5: Verifier checks (opens envelope, verifies contents)"""
    recomputed = hashlib.sha256(secret + nonce).digest()
    return recomputed == commitment

# Prover creates commitment
secret = b"my-secret-password"
commitment, nonce = create_commitment(secret)

# Verifier challenges: "reveal your secret and nonce"
# Prover reveals both
valid = verify_commitment(commitment, secret, nonce)
print(f"Proof valid: {valid}")  # True

The verifier learns nothing from the commitment alone — only the hash. But once the secret is revealed, the verifier can verify it matches the original commitment.

Schnorr Protocol: Prove You Know a Secret Number

The Schnorr protocol is a more sophisticated ZKP that proves you know a secret number without revealing it. It's the basis for many cryptographic systems.

Setup:

  • Public: Prime P, Generator G
  • Prover's secret: x (never revealed)
  • Public key: G^x mod P

Protocol:

# Simplified Schnorr-like protocol
P = 2027  # Prime
G = 3     # Generator

# Prover knows secret x, verifier knows public key G^x mod P
secret = 1592  # NEVER revealed
public_key = pow(G, secret, P)  # 550

# Step 1: Prover commits
r = 1246  # Random nonce
commitment = pow(G, r, P)  # 1923

# Step 2: Verifier challenges
c = 107  # Random challenge

# Step 3: Prover responds
response = (r + c * secret) % (P - 1)  # 1406

# Step 4: Verifier checks
lhs = pow(G, response, P)
rhs = (commitment * pow(public_key, c, P)) % P
print(f"Proof valid: {lhs == rhs}")  # True — without learning secret!

The verifier checks G^response ≡ commitment × public_key^c (mod P). If it holds, the prover knows the secret. The secret x is never transmitted.

Password Authentication Without Sending Passwords

You've already used ZKP-like protocols. When you log in with a challenge-response system, your password never crosses the network:

Traditional LoginZKP-Style Login
Client sends passwordClient sends proof
Server verifies passwordServer verifies proof
Password traverses networkPassword NEVER leaves client
Intercepted = compromisedIntercepted = useless for replay

Protocols like SRP (Secure Remote Password) and OPAQUE implement this pattern. Your password never leaves your device.

Where ZKPs Are Used Today

ApplicationWhat It ProvesTechnology
Password Authentication"I know the password" without sending itSRP, OPAQUE
Identity Verification"I'm over 18" without revealing birthdateVerifiable Credentials
Blockchain Privacy"Transaction is valid" without revealing detailszk-SNARKs, zk-STARKs
Key Exchange"We share a secret" over public channelDiffie-Hellman, Signal
Private Voting"My vote is valid" without revealing choicezk-Voting
Selective Disclosure"I have a valid credential" for specific attributesAnoncreds, W3C VC

zk-SNARKs and zk-STARKs: The Blockchain Connection

You've probably heard of these in the context of privacy-focused cryptocurrencies:

Featurezk-SNARKszk-STARKs
Proof sizeSmall (~200 bytes)Larger (~50 KB)
Verification speedVery fastFast
Quantum resistanceNo (relies on elliptic curves)Yes (hash-based)
Trusted setupRequiredNot required
Used inZcash, Ethereum (via Polygon)StarkNet, Ethereum
💡 Developer Note: zk-STARKs are quantum-resistant and don't require a trusted setup, making them increasingly attractive for new systems.

The Three Properties in Practice

When evaluating any ZKP system, ask these questions:

  1. Completeness: Does an honest prover always convince an honest verifier?
  2. Soundness: Can a cheater fool the verifier? What's the probability?
  3. Zero-Knowledge: Does the verifier learn anything about the secret?

If the answer to #2 is "yes, with probability > 0.001%" or #3 is "maybe, depending on implementation" — you don't have a proper ZKP.

Try It Yourself

Start with the hash-based commitment scheme. It's the simplest ZKP and demonstrates the core concept. Then explore Schnorr protocols for asymmetric cryptography.

Related BestWordz Tools:

Further Reading

All cryptographic examples in this article use synthetic data and simplified protocols for educational purposes. Production ZKP systems use peer-reviewed protocols with rigorous security proofs.

Try the Password Strength Checker

Put what you've learned into practice with this free BestWordz tool.

Open Tool →

💬 Discuss on BestWordz Community

Join the conversation about LLMs, Encryption, Cryptography on the BestWordz Community forum.

Visit Forum →