Path: blob/main/frontier/09-commitments-sigma-protocols/sage/09c-sigma-protocols-intuition.ipynb
483 views
Sigma Protocols: The 3-Move Proof
Module 09 | 09-commitments-sigma-protocols
Commit-challenge-response, completeness, special soundness, honest-verifier zero-knowledge
The Impossible Question
Can you PROVE you know a password without ever typing it? Without revealing ANY information about it?
This sounds impossible. If you prove something, surely the proof itself leaks information? But sigma protocols do exactly this, they let a prover convince a verifier of knowledge while revealing nothing beyond the truth of the statement.
This notebook builds the intuition for how such a proof works. By the end, you will understand the elegant 3-move dance that makes zero-knowledge proofs possible, and you will run one yourself in SageMath.
Objectives
By the end of this notebook you will be able to:
Describe the 3-move structure (commit, challenge, response) of a sigma protocol.
State and demonstrate the three defining properties: completeness, special soundness, and honest-verifier zero-knowledge (HVZK).
Execute a concrete sigma protocol (prove knowledge of a discrete log) in SageMath.
Construct a simulator that creates fake transcripts indistinguishable from real ones.
Extract a witness from two accepting transcripts with the same commitment but different challenges.
Prerequisites
Completion of Pedersen Commitments.
Familiarity with cyclic groups and discrete logarithms (Modules 05-06).
Bridge from 09b: In the Pedersen commitment notebook, you saw how to commit to a value using , hiding perfectly while binding you to it. Sigma protocols use a very similar idea in their first move: the prover sends a commitment to some randomness. The key insight is that this commitment structure, combined with a challenge-response mechanism, can prove knowledge of a secret without ever revealing it. The Pedersen commitment you already understand is, in fact, the algebraic engine inside many sigma protocols.
The Ali Baba Cave: An Analogy
Before we touch any math, let us build intuition with a famous analogy.
Imagine a cave shaped like a ring, with a single entrance. Deep inside, the ring splits into two paths (left and right) that reconnect at a locked door. Only someone who knows the magic word can open the door and pass through.
The protocol:
Commit: The prover (Peggy) walks into the cave and randomly chooses the left or right path. The verifier (Victor) waits outside and does not see which path she took.
Challenge: Victor shouts a random demand: "Come out from the LEFT" or "Come out from the RIGHT."
Response: If Peggy knows the magic word, she can always comply, if she is on the wrong side, she opens the door and walks through.
Why this works:
Completeness: If Peggy knows the word, she succeeds every time.
Soundness: If Peggy does NOT know the word, she can only comply if she happened to choose the right path, a 50% chance. After rounds, a fake prover succeeds with probability , which is negligible.
Zero-knowledge: Victor learns nothing! A skeptical friend watching a VIDEO of the protocol cannot distinguish it from a staged video where Peggy and Victor colluded (Victor told Peggy the challenge in advance). This is the simulation argument, if you can fake it, it reveals nothing.
Key idea: Zero-knowledge does not mean the proof is somehow "weak." It means the verifier gains NO information beyond the single bit: "Peggy knows the secret." Not a partial clue. Not a single bit of the secret itself. Nothing.
Common Misconception: "Zero-knowledge means the verifier cannot compute the secret."
It is much stronger than that. Zero-knowledge means the verifier cannot learn anything at all, not even a single bit of information about the secret. The verifier's view of the interaction is identical to something it could have generated entirely on its own, without ever talking to the prover. This is a profound guarantee: the interaction is literally worthless to the verifier as a source of information.
The 3-Move Structure
A sigma protocol for a relation is an interactive proof with exactly three messages:
| Step | Direction | Name | Content |
|---|---|---|---|
| 1 | Prover Verifier | Commitment () | Prover commits to fresh randomness |
| 2 | Verifier Prover | Challenge () | Verifier sends a random challenge |
| 3 | Prover Verifier | Response () | Prover responds using witness + challenge |
The verifier then runs a verification equation on and accepts or rejects.
Why "sigma"? The communication pattern, down, back up diagonally, then down again, looks like the Greek letter (sigma) when drawn as a message sequence diagram:
A Concrete Sigma Protocol: Proof of Knowledge of Discrete Log
Let us make this concrete. Consider the most fundamental sigma protocol:
Statement: "I know a secret such that in a cyclic group."
The prover wants to convince the verifier that they know (the witness) without revealing .
Protocol:
Commit: Prover picks random , sends
Challenge: Verifier sends random
Response: Prover computes and sends
Verification: Verifier checks that
Why does this equation hold? Expand the right side:
Let us implement this step by step.
Checkpoint: Verify by Hand
Before reading further, convince yourself why the verification works:
Question: What happens if the prover uses instead? Would the proof still verify? Why or why not?
Click for answer
No! Then , which is NOT equal to (since ). The verification equation would fail. The response must be computed exactly as .
Property 1: Completeness
Completeness: An honest prover (who knows ) can ALWAYS convince an honest verifier.
This is the most basic requirement, if the protocol is correct, it should actually work. We already verified this for one run above. Let us confirm it works for many runs.
Property 2: Special Soundness
Special soundness: Given TWO accepting transcripts and with the same commitment but different challenges , anyone can extract the witness .
This is the proof of knowledge property. It means the prover must actually "know" , they cannot bluff, because if they could answer two different challenges for the same commitment, the secret can be extracted.
The extraction: From the two transcripts:
Subtract:
Therefore:
Since is prime, has an inverse, so we can always extract .
Why Special Soundness Implies Security
Think about what this means for a cheating prover (who does NOT know ):
A cheater commits to .
The verifier sends a random .
If the cheater could produce valid responses for TWO different challenges (same ), we could extract . But the cheater does not know !
Therefore, the cheater can respond correctly to at most one challenge value.
Since the challenge is random, the cheater succeeds with probability at most , negligible.
The critical point: the challenge must come AFTER the commitment. If the cheater sees before committing, they can cheat (as we will see in the simulator).
Property 3: Honest-Verifier Zero-Knowledge (HVZK)
HVZK: There exists a simulator that, WITHOUT knowing the witness , can produce transcripts that are statistically indistinguishable from real protocol transcripts.
This is the most subtle and profound property. Let us understand it through the simulation argument.
The Simulation Argument
Zero-knowledge means: "The verifier learns NOTHING because they could have generated the transcript themselves."
How? The simulator works backwards:
Pick a random challenge and random response .
Compute the commitment as .
Output the transcript .
Check: Does this transcript verify?
Yes! The simulated transcript passes verification, and the simulator never knew !
Are Simulated Transcripts Really Indistinguishable?
Let us generate many real and simulated transcripts and compare their distributions. In a real transcript:
is uniform random in
where is uniform random, so is also uniform random in
is a uniform random group element
In a simulated transcript:
is uniform random in (chosen directly)
is uniform random in (chosen directly)
is determined by and
Both distributions are identical: in both cases, is a uniformly random accepting transcript. No algorithm can tell them apart, not even with unlimited computational power.
The Profound Implication
Think about what we just showed:
The verifier interacts with the prover and gets a transcript .
But the verifier could have generated an identically distributed transcript by itself, using the simulator.
Therefore, the transcript contains zero information that the verifier did not already have.
The verifier learns exactly one thing: the statement is true (the prover knows ).
This is why it is called zero-knowledge: the knowledge transferred is zero. The verifier is convinced, but gains nothing it could use to (for example) convince someone else, or learn even one bit of .
Note: We proved honest-verifier zero-knowledge (HVZK), meaning the verifier follows the protocol (picks randomly). Full zero-knowledge, which handles malicious verifiers, requires additional techniques (see notebook 09e on the Fiat-Shamir transform).
What Happens When a Cheater Tries?
Let us see what happens when someone who does NOT know tries to run the protocol.
Checkpoint: The Cheater's Dilemma
Question: Could a cheater succeed by choosing BEFORE the challenge arrives?
Think about it: the cheater knows , , (which they chose), and (which they chose). They need . But they do not know yet!
If they fix first, then and are fixed, so is fixed. This pins down exactly one value of . With probability , the verifier happens to pick that exact .
Alternatively, the cheater could pick first and compute a valid pair. But then they would need the verifier to send exactly that , again probability .
Conclusion: No matter what strategy the cheater uses, they succeed with probability at most .
The Three Properties Together
Let us summarize the three properties of our sigma protocol:
| Property | What it says | What we showed |
|---|---|---|
| Completeness | Honest prover always convinces honest verifier | 1000/1000 trials passed |
| Special Soundness | Two transcripts (same , different ) reveal | Extracted from two transcripts |
| HVZK | Simulator produces indistinguishable transcripts without | Simulated transcripts pass verification |
These three properties together give us something remarkable: a proof system where:
Honest provers always succeed (completeness)
Cheating provers always fail (soundness)
The verifier learns nothing beyond the truth of the statement (zero-knowledge)
Putting It All Together: Reusable Functions
Let us package the protocol into clean, reusable functions.
Crypto Foreshadowing: The protocol we just built is essentially Schnorr's protocol, the most important sigma protocol in cryptography. In the next notebook (09d), we will see Schnorr's protocol in full detail, including its use as a digital signature scheme. Schnorr signatures are used in:
Bitcoin's Taproot upgrade (BIP 340), the biggest protocol change in Bitcoin's history
Ed25519, the most widely deployed signature scheme on the internet
Every modern zero-knowledge proof system builds on sigma protocols as a foundation
The Fiat-Shamir transform (notebook 09e) will show how to make sigma protocols non-interactive, turning our 3-message conversation into a single message that anyone can verify.
Exercises
Exercise 1: Verify a Given Transcript (Fully Worked)
Problem: You are given the following transcript from a sigma protocol. Verify whether the proof is valid.
Public parameters: group with generator and order (as set up above)
Public statement: (as set up above)
Transcript: generated by a real prover
Exercise 2: Build a Simulator (Guided)
Problem: Write a simulator that produces valid-looking transcripts WITHOUT access to the secret . You only have access to the public values , , .
Hints:
Choose and randomly first.
Compute so that the verification equation holds.
Verify your transcript passes the check.
Exercise 3: Soundness Extraction Attack (Independent)
Problem: Suppose a careless prover reuses the same random nonce in two different protocol runs (same , different challenges). You intercept both transcripts. Extract the prover's secret key .
Here are two real transcripts generated with the same nonce :
Real-world connection: This is not a theoretical exercise. In 2010, hackers extracted Sony's PlayStation 3 ECDSA private key because Sony reused the same nonce across multiple signatures. The same extraction formula you just used (or will use) is exactly what broke PS3 security. Never reuse nonces.
Summary
| Concept | Key idea |
|---|---|
| 3-move structure | Prover commits (), verifier challenges (), prover responds (). The flow resembles the letter |
| Completeness | An honest prover who knows the witness always produces a valid proof |
| Special soundness | Two accepting transcripts with the same commitment but different challenges allow extraction of the witness |
| HVZK | A simulator can produce valid-looking transcripts without knowing , so the verifier learns nothing from the interaction |
| Simulation argument | Zero-knowledge means "the verifier could have generated the transcript themselves." If a transcript can be faked, it cannot contain information |
| Nonce reuse is catastrophic | Reusing the random nonce allows anyone to extract the secret key |
Next: The Schnorr Protocol, the sigma protocol we built here, formalized as a full identification scheme and digital signature.