Sigma Protocol Example #
This file demonstrates Sigma protocols formalized in CatCrypt-Lean4.
Overview #
A Sigma protocol is a three-move public-coin interactive proof system:
- Prover sends commitment (message)
- Verifier sends random challenge
- Prover sends response
- Verifier accepts/rejects
Properties #
- Completeness: Honest prover with valid witness is always accepted
- Special Soundness: From two accepting transcripts with same commitment but different challenges, one can extract a valid witness
- Special Honest-Verifier Zero-Knowledge (SHVZK): A simulator can produce transcripts indistinguishable from real ones given only the statement and challenge
Main definitions #
SigmaProtocol— the three-move structure with a stateless prover.SigmaProtocolS— the three-move structure whose prover carries state from the first move to the third, withSigmaProtocol.toSigmaProtocolSfor the trivial-state case andSigmaProtocolS.toSigmaProtocolfor the stateless protocol whose first message carries the state.Completeness,SpecialSoundness,SHVZK,SHVZK_given— the property predicates.
Implementation #
We use a simplified model over Bool types (like PRF.lean) to demonstrate the proof techniques. The key insight for SHVZK is that if the simulator samples the challenge first and then computes (message, response) via a bijection, it produces the same distribution as the real protocol.
References #
- [Damgard, On Sigma Protocols]
- [Cramer & Damgard, Sigma Protocols and Efficient Zero-Knowledge]
Type Definitions #
Use Bool as simple finite type for demonstration
Equations
Instances For
Instances For
Instances For
Sigma Protocol Structure #
A Sigma protocol consists of types and algorithms for the three-move interaction between prover and verifier.
- Statement : Type
Type of statements (what we're proving)
- Witness : Type
Type of witnesses (secret known to prover)
- Message : Type
Type of first message (commitment)
- Challenge : Type
Type of challenge (from verifier)
- Response : Type
Type of response
Challenge type is finite (for uniform sampling)
Challenge type is nonempty
The NP relation: R(x, w) means w is a valid witness for x
- commit : self.Statement → self.Witness → Core.SPComp self.Message
Prover's first message (commitment)
Prover's response to a challenge
Verifier's check
Simulator for SHVZK
Instances For
Sigma Protocols with Prover State #
A Sigma protocol whose prover carries state from the first move to the
third. The commitment step returns a message together with a private state
PState, and the response step reads that state.
SigmaProtocol is the special case PState = Unit, recorded by
SigmaProtocol.toSigmaProtocolS. A protocol whose response depends on
randomness that the commitment does not determine — because the map from
that randomness to the message loses information — is expressible here and
not over SigmaProtocol.
- Statement : Type
Type of statements (what we're proving)
- Witness : Type
Type of witnesses (secret known to prover)
- Message : Type
Type of first message (commitment)
- Challenge : Type
Type of challenge (from verifier)
- Response : Type
Type of response
- PState : Type
Type of the prover's private state between the first and third move
Challenge type is finite (for uniform sampling)
Challenge type is nonempty
The prover-state type is nonempty
The NP relation: R(x, w) means w is a valid witness for x
Prover's first message together with the state it retains
- respond : self.Statement → self.Witness → self.PState → self.Message → self.Challenge → Core.SPComp self.Response
Prover's response, reading the retained state
Verifier's check, on the public transcript only
Simulator for SHVZK, producing a public transcript
Instances For
A SigmaProtocol viewed as a SigmaProtocolS with trivial prover state.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The stateless Sigma protocol obtained by appending the prover state to the
first message. The verifier ignores the appended component, so the
predicates that read only the types and verify — the soundness error,
TwoTranscripts, SpecialSoundness — are statements about the same
verification equation as sps.
The simulator has no state to produce and emits an arbitrary one, so the zero-knowledge predicates, which compare real and simulated first messages, do not transfer.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Transcript Type #
A transcript of a Sigma protocol execution
Instances For
Protocol Computations #
Real protocol execution: prover with witness generates transcript
Equations
- One or more equations did not get rendered due to their size.
Instances For
Simulated transcript: simulator generates transcript given challenge
Equations
- One or more equations did not get rendered due to their size.
Instances For
Protocol Computations with Given Challenge (Rocq style) #
In the standard cryptographic definition of SHVZK, the challenge is provided as input
rather than sampled internally. This matches Rocq's CatCrypt formalization where
chInput = (h, w, e) includes the challenge. This allows a simpler 1D bijection
coupling proof.
Real protocol with given challenge: prover generates transcript for fixed challenge
Equations
Instances For
Simulated transcript with given challenge
Equations
Instances For
Completeness Property #
Completeness: honest execution with valid witness always verifies
Equations
Instances For
Special Soundness Property #
Special soundness: from two accepting transcripts with same commitment but different challenges, extract a valid witness
Equations
- One or more equations did not get rendered due to their size.
Instances For
SHVZK Property #
Special Honest-Verifier Zero-Knowledge (given challenge version): For any given challenge, real and simulated transcripts have the same distribution.
This is the standard cryptographic definition where the challenge is provided as input (matching Rocq's CatCrypt formalization). This formulation allows a simple 1D bijection coupling proof.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Special Honest-Verifier Zero-Knowledge: real and simulated transcripts have the same distribution for any statement with a valid witness.
This is formalized using rHoare: for any precondition, the real and simulated computations produce outputs that are equal (same transcript).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Simple Example: XOR-based Protocol over Bool #
A simple Sigma protocol where the statement is the XOR of message and response, and the witness is either true or false.
Statement: x Witness: w such that x = (witness property) Protocol:
- Commit: sample random message a
- Challenge: e (random Bool)
- Response: z = xor a (xor w e)
- Verify: check that xor a z = xor w e... (simplified)
For simplicity, we use a trivial protocol where everything is in Bool.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Bijection for SHVZK Proof #
The key bijection for SHVZK relates sampled values directly:
- Real: sample a, compute z = xor (xor a w) e
- Simulated: sample z, compute a = xor z (xor x e)
When x = w:
- From real (a, z): z = xor (xor a w) e
- The bijection f : a ↦ z = xor (xor a w) e is an equiv on Bool
If we show uniform(a).bind(a ↦ pure(a, f(a))) = uniform(z).bind(z ↦ pure(f⁻¹(z), z)), then the transcripts have the same distribution.
XOR-based bijection: for fixed w and e, mapping a to z
Equations
Instances For
The forward map of xorTransformBij w e sends a to a ⊕ w ⊕ e.
The inverse map of xorTransformBij w e sends z to z ⊕ e ⊕ w.
2D bijection for Sigma protocol SHVZK: Maps (a, e) from Real protocol to (e', z) from Simulation where e' = e (challenges match) and z = xor (xor a w) e (responses match). Then Sim's computed message = xor z (xor w e') = a = Real's message.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Completeness Proof for simpleSigma #
Completeness for simpleSigma: honest executions always verify.
Note: The generic Completeness definition above is too strong as it
requires verify to succeed for ALL z values. The correct formulation
is that verify succeeds for z produced by the honest respond function.
This theorem captures the correct completeness property.
SHVZK Proof for simpleSigma #
SHVZK for simpleSigma with given challenge: the core bijection coupling proof.
This follows Rocq's CatCrypt approach where the challenge e is provided as input.
The bijection xorTransformBij w e : a ↦ z = a ⊕ w ⊕ e couples:
- Real's sampled commitment
a - Sim's sampled response
z
Since a' = z ⊕ w ⊕ e = (a ⊕ w ⊕ e) ⊕ w ⊕ e = a, both produce the same
transcript.
SHVZK for simpleSigma with the challenge sampled internally rather than
supplied as input.
This extends the standard SHVZK definition used in Rocq's CatCrypt
(SigmaProtocol.v:163-170), where the challenge is part of the input
(h, w, e). The SHVZK_given theorem above matches that input-challenge
formulation; this variant samples the challenge inside the protocol.
Special Soundness for simpleSigma #
The extractor for simpleSigma: given two transcripts with same a, different e, extract the witness.
From two accepting transcripts:
- (a, e₁, z₁) with xor a z₁ = xor x e₁
- (a, e₂, z₂) with xor a z₂ = xor x e₂
We can compute: xor (xor a z₁) (xor a z₂) = xor (xor x e₁) (xor x e₂) xor z₁ z₂ = xor e₁ e₂ (by XOR properties)
And from xor a z₁ = xor x e₁: x = xor (xor a z₁) e₁
So the extractor returns: xor (xor a z₁) e₁
Equations
- CatCrypt.Examples.Sigma.simpleSigmaExtractor x tt = (tt.message ^^ tt.response1 ^^ tt.challenge1)
Instances For
simpleSigma satisfies special soundness: simpleSigmaExtractor recovers a
valid witness from any two accepting transcripts sharing a commitment.