Documentation

CatCryptCore.Examples.Sigma

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:

  1. Prover sends commitment (message)
  2. Verifier sends random challenge
  3. Prover sends response
  4. Verifier accepts/rejects

Properties #

Main definitions #

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 #

Type Definitions #

@[reducible, inline]

Use Bool as simple finite type for demonstration

Equations
Instances For

    Sigma Protocol Structure #

    A Sigma protocol consists of types and algorithms for the three-move interaction between prover and verifier.

    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.

      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 #

                        Two accepting transcripts with same message but different challenges

                        Instances For

                          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 #

                                @[implicit_reducible]

                                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:

                                  When x = w:

                                  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
                                    @[simp]

                                    The forward map of xorTransformBij w e sends a to a ⊕ w ⊕ e.

                                    @[simp]

                                    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
                                      @[simp]
                                      theorem CatCrypt.Examples.Sigma.sigmaBij_fst (w a e : Bool) :
                                      ((sigmaBij w) (a, e)).1 = e

                                      The first component of sigmaBij w (a, e) is the challenge e.

                                      @[simp]
                                      theorem CatCrypt.Examples.Sigma.sigmaBij_snd (w a e : Bool) :
                                      ((sigmaBij w) (a, e)).2 = (a ^^ w ^^ e)

                                      The second component of sigmaBij w (a, e) is the response a ⊕ w ⊕ e.

                                      Completeness Proof for simpleSigma #

                                      theorem CatCrypt.Examples.Sigma.simpleSigma_complete' (x w : Bool) (hrel : simpleSigma.relation x w) (a e : Bool) :
                                      have z := a ^^ w ^^ e; simpleSigma.verify x a e z = true

                                      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
                                      Instances For

                                        simpleSigma satisfies special soundness: simpleSigmaExtractor recovers a valid witness from any two accepting transcripts sharing a commitment.