Path: blob/main/frontier/09-commitments-sigma-protocols/sage/09e-fiat-shamir-transform.ipynb
483 views
The Fiat-Shamir Transform
Module 09e | Commitments and Sigma Protocols
Can a prover create a convincing proof entirely alone, with no verifier in sight?
Motivating Question: Schnorr's protocol (09d) lets Alice prove she knows a secret to Bob. But it requires real-time interaction: Bob must be online to send a random challenge, and Alice must respond immediately. Can Alice create a proof offline that anyone can verify later, without any back-and-forth?
The answer is yes, and the technique that makes it possible, the Fiat-Shamir transform, is one of the most important ideas in modern cryptography.
Objectives
By the end of this notebook you will be able to:
Explain why interactive proofs are impractical for many real-world applications
Apply the Fiat-Shamir transform to convert an interactive sigma protocol into a non-interactive proof
Construct and verify Schnorr signatures as a direct application of Fiat-Shamir
Articulate the Random Oracle Model and its role in the security argument
Recognize Fiat-Shamir as the bridge from sigma protocols to SNARKs, signatures, and beyond
Prerequisites
Completion of The Schnorr Protocol, especially the 3-move structure (commit , challenge , response )
Familiarity with cryptographic hash functions (the idea that maps arbitrary data to a fixed-size, unpredictable output)
The Problem: Interaction Is Expensive
Recall the interactive Schnorr protocol from notebook 09d:
Prover picks random , sends commitment
Verifier sends random challenge
Prover sends response
Verifier checks
This works beautifully, but it requires the verifier to be online and engaged at the exact moment of proof. Consider these scenarios:
Digital signatures: Alice wants to sign a document that anyone can verify, anytime, without Alice being present.
Blockchain transactions: A proof must be verified by thousands of nodes, not just one interactive partner.
SNARKs: A prover generates a proof once; it's verified many times by many parties.
In all these cases, interaction is a deal-breaker. We need non-interactive proofs.
The Key Insight: Let a Hash Be the Verifier
The verifier's only job in the Schnorr protocol is to produce a random challenge after seeing the commitment . The ordering matters: the prover must commit to before seeing , otherwise they could cheat.
Fiat and Shamir's brilliant idea (1986): replace the verifier with a hash function.
The prover computes themselves by hashing the public parameters and their own commitment. If is a "good" hash function (modeled as a random oracle), then:
The challenge is deterministic given , the prover can compute it alone
But is unpredictable before choosing , the prover cannot "work backwards" from a desired to find
This simulates an honest verifier who picks at random after seeing
The full non-interactive protocol becomes:
Pick random , compute
Compute
Compute
Output proof
Anyone can verify by recomputing and checking .
Common mistake: "Fiat-Shamir just removes the verifier." It's more subtle than that: the hash replaces the verifier, and it enforces the crucial ordering constraint. A cheating prover who tries to pick first and then find a matching would need to invert the hash function, which is computationally infeasible. The hash commits the prover to before they "see" , even though they compute both.
Setup: Working in a Prime-Order Group
Let's set up a cyclic group of prime order inside , just as we did in 09d. We'll also define a hash function that maps to .
Step 1: Interactive Schnorr (Recap)
Before applying Fiat-Shamir, let's run the interactive Schnorr protocol one more time so the transformation is crystal clear.
Notice the bottleneck: Step 2 requires a live verifier sending a random . The Fiat-Shamir transform eliminates exactly this step.
Step 2: The Fiat-Shamir Transform
We replace the verifier's random challenge with:
Now the prover computes everything alone. The proof is the pair .
Checkpoint: Look carefully at the
fiat_shamir_provefunction. It has the exact same three computations as the interactive protocol (, , ). The only difference is where comes from. In the interactive version, is received from the verifier. Here, is computed by the prover.The verifier in
fiat_shamir_verifynever needs to talk to the prover. They just recompute from the proof and check the equation. The proof is self-contained.
Why Can't a Cheating Prover Forge a Proof?
Let's think about what a cheating prover (who does NOT know ) would need to do.
Cheat attempt 1: Choose first, then find matching .
In the interactive protocol, the simulator (from 09d) works backwards: pick and first, then compute . This produces a valid-looking transcript. But with Fiat-Shamir, the challenge is . So the cheater would need to find such that , inverting the hash function! This is infeasible.
Cheat attempt 2: Choose first, get , then find .
After choosing and computing , the cheater needs with . Without knowing , this means solving a discrete log. Also infeasible.
The hash function traps the cheater: no matter which order they try, one step requires solving a hard problem.
From Proofs to Signatures: Adding a Message
Here's where Fiat-Shamir gets even more powerful. If we include a message in the hash:
then the proof becomes bound to that message. The result is a digital signature scheme:
Key generation: secret , public
Sign: pick random , compute , , . Signature:
Verify: recompute , check
This is exactly the Schnorr signature scheme, the basis of EdDSA/Ed25519, used in SSH keys, TLS, and cryptocurrency.
The signature proves: "The holder of the secret key corresponding to endorses message ." No interaction needed.
Checkpoint: Sign and verify by hand. Before running the next cell, work through this small example on paper or in your head.
Let , , (which has order 11 mod 23). Secret key , so .
Compute .
Choose nonce . Compute .
Suppose (just pretend the hash gave us 5).
Compute .
Verify: check that .
The Random Oracle Model
Why does Fiat-Shamir work? The security proof relies on a powerful assumption called the Random Oracle Model (ROM).
A random oracle is an idealized hash function with these properties:
Deterministic: The same input always gives the same output.
Uniformly random: For any new input, the output is uniformly random in the output space.
Independent: Knowing gives no information about for any new .
Under the ROM, the hash output is indistinguishable from a truly random challenge, exactly what the honest verifier would have sent. This means:
The prover cannot predict before committing to (since is "random" on new inputs)
The prover cannot find two different values giving the same (collision resistance)
The security of the interactive protocol transfers to the non-interactive version
In practice, we use SHA-256 or SHA-3 as the hash function. These are not true random oracles (no real function can be), but they are close enough that Fiat-Shamir-based schemes have been secure for decades.
Common mistake: "The Random Oracle Model means we assume SHA-256 is perfect." Not quite. The ROM is a proof technique: we prove security assuming an ideal hash, then instantiate with a real hash like SHA-256. This is a heuristic, there exist (artificial) schemes that are secure in the ROM but broken with any real hash function. In practice, Fiat-Shamir with SHA-256 has an excellent track record, but the distinction between the model and reality is important for theory.
Side-by-Side: Interactive vs. Non-Interactive
Let's run both protocols on the same secret and compare.
Caveats and Practical Considerations
Fiat-Shamir is powerful but comes with important caveats:
1. Nonce reuse is catastrophic. If the prover ever uses the same for two different signatures on messages and , the secret key can be extracted:
Same means same was used
Two equations: and
Subtract: , so
This is how Sony's PS3 ECDSA key was broken in 2010, they used a fixed for every signature!
2. Hash function must include all public parameters. Omitting or from the hash can create subtle vulnerabilities.
3. The Random Oracle Model is a heuristic. While Fiat-Shamir works well in practice, there are theoretical separations between the ROM and the real world.
Exercises
Exercise 1 (Worked)
Implement the Fiat-Shamir transform for a modified Schnorr protocol that proves knowledge of such that , but uses a different group. Work with , , (which has order 233 mod 467). Sign the message "Exercise 1" with secret key .
Steps:
Compute the public key
Choose nonce , compute
Compute challenge
Compute response
Verify the signature
Exercise 2 (Guided)
Demonstrate the nonce reuse attack on the small group from Exercise 1. Use the same , , , .
Sign two different messages
"Transfer 5 coins"and"Transfer 50 coins"using the same nonce .Recover the secret key from the two signatures.
Verify your recovered matches the original.
Hint: From and , subtract to eliminate .
Exercise 3 (Independent)
Implement a batch verification system. Given a list of 5 signed messages (all from the same signer), verify all signatures and report which are valid. Then:
Generate a key pair and sign 5 different messages.
Tamper with one of the messages (change its text but keep the original signature).
Run your batch verifier and confirm it catches the tampered signature.
Time the verification: how long does it take to verify 5 signatures vs. 50 vs. 500?
Use the full-size group (, , ) from the main setup, not the small Exercise 1 group.
Summary
| Concept | Key idea |
|---|---|
| The core idea | Replace the verifier's random challenge with a hash: . The prover computes everything alone, and anyone can verify later |
| Schnorr signatures | The direct result of applying Fiat-Shamir to the interactive Schnorr protocol, with the message included in the hash |
| Random Oracle Model | The security argument treats the hash as an ideal random function that prevents the prover from cheating the challenge |
| Nonce reuse is fatal | Using the same random twice leaks the secret key via simple algebra |
Crypto foreshadowing: The Fiat-Shamir transform is not limited to Schnorr. It applies to any sigma protocol (and more general interactive proofs). This is the engine behind:
Ed25519 / EdDSA, the dominant signature scheme in modern systems (SSH, TLS, crypto wallets)
SNARKs (Module 10), Fiat-Shamir converts interactive SNARK verification into a single non-interactive proof
STARKs (Module 10), built entirely on Fiat-Shamir applied to the FRI protocol
Every non-interactive zero-knowledge proof you'll encounter in practice
What you've learned in this notebook is the single most important bridge between the theory of sigma protocols and the practice of modern cryptographic systems.