Documentation

CslibFrontier.Crypto.Protocols.SigmaProtocol.Interactive

Sigma protocols as public-coin interactive reductions #

Every Sigma protocol P : SigmaProtocol X Y T C Z with a nonempty finite challenge space C embeds as a three-round public-coin interactive reduction in the plain model (CslibFrontier.Computability.Interactive), reducing the swapped relation Function.swap R : Y → X → Prop to Interactive.Accept:

  1. The prover sends a commitment t : T with full oracle access (OracleInterface.full T).
  2. The verifier samples a uniform challenge c : C via ProbComp.uniform C.
  3. The prover sends a response z : Z with full oracle access (OracleInterface.full Z).
  4. The verifier reads t and z and accepts (some ()) iff P.verify y t c z = true.

Because SigmaProtocol.commit is a semantic PMF while Interactive.Reduction requires an explicit ProbOracleComp strategy tree, the honest prover takes a ProbComp commitment sampler sampleCommit : X → Y → ProbComp (T × P.State) certified by P.CommitRealizedBy sampleCommit. The verifier (P.toInteractiveVerifier) needs no sampler beyond ProbComp.uniform C.

This module proves that the Sigma-protocol security notions transfer across the bridge:

No knowledge-soundness statement is made here: Interactive.Verifier.KnowledgeSound asks for a straight-line extractor, while the proof-of-knowledge property of Sigma protocols comes from a rewinding extractor, built for indexed families in CslibFrontier.Crypto.Protocols.SigmaProtocol.ProofOfKnowledge.

Main definitions #

Main results #

Specification and transcripts #

@[reducible, inline]

The interactive specification of P.

Package a commitment t, challenge c and response z as a transcript of P.interactiveSpec.

Package a conversation triple (t, c, z) as a transcript of P.interactiveSpec.

The commitment t of an interactive transcript.

The challenge c of an interactive transcript.

The response z of an interactive transcript.

View an interactive transcript as a Sigma-protocol conversation (t, c, z).

Interactive verifier, prover and reduction #

def Cslib.Crypto.Protocols.SigmaProtocol.CommitRealizedBy {X Y T C Z : Type} (P : SigmaProtocol X Y T C Z) (sampleCommit : X → Y → ProbComp (T × P.State)) :

sampleCommit realizes P.commit as a ProbComp program.

The honest prover strategy of P in the plain model, using sampleCommit to sample the commitment and private prover state, then answering the verifier's challenge with P.respond.

The public-coin interactive verifier of P in the plain model: sample a uniform challenge c : C, read the commitment t : T and response z : Z, and output some () iff P.verify y t c z = true.

Embed P as a three-round public-coin interactive reduction in the plain model, reducing Function.swap R : Y → X → Prop to Interactive.Accept.

theorem Cslib.Crypto.Protocols.SigmaProtocol.plainLaw_toInteractiveProver_runStrategy {X Y T C Z : Type} (P : SigmaProtocol X Y T C Z) [Fintype C] [Nonempty C] {sampleCommit : X → Y → ProbComp (T × P.State)} (hcommit : P.CommitRealizedBy sampleCommit) (y : Y) (x : X) :

In the plain model, running P.toInteractiveProver sampleCommit against the verifier's uniform challenge sampler produces the conversation law P.conversation x y.

theorem Cslib.Crypto.Protocols.SigmaProtocol.eval_toInteractiveReduction_run {X Y T C Z : Type} (P : SigmaProtocol X Y T C Z) [Fintype C] [Nonempty C] {sampleCommit : X → Y → ProbComp (T × P.State)} (hcommit : P.CommitRealizedBy sampleCommit) (y : Y) (x : X) :
Interactive.World.plain.eval ((P.toInteractiveReduction sampleCommit).run y x) = PMF.map (fun (x : T × C × Z) => match x with | (t, c, z) => (P.transcriptOfConversation (t, c, z), if P.verify y t c z = true then some () else none, (), ())) (P.conversation x y)

The full plain-model execution law of P.toInteractiveReduction sampleCommit.

theorem Cslib.Crypto.Protocols.SigmaProtocol.map_fst_eval_toInteractiveReduction_run {X Y T C Z : Type} (P : SigmaProtocol X Y T C Z) [Fintype C] [Nonempty C] {sampleCommit : X → Y → ProbComp (T × P.State)} (hcommit : P.CommitRealizedBy sampleCommit) (y : Y) (x : X) :

The transcript marginal of an honest plain-model run of P.toInteractiveReduction is (P.conversation x y).map P.transcriptOfConversation.

Completeness transfer #

theorem Cslib.Crypto.Protocols.SigmaProtocol.Complete.toInteractiveReduction {X Y T C Z : Type} {P : SigmaProtocol X Y T C Z} [Fintype C] [Nonempty C] {R : X → Y → Prop} {sampleCommit : X → Y → ProbComp (T × P.State)} (h : P.Complete R) (hcommit : P.CommitRealizedBy sampleCommit) :

Completeness transfer: a complete Sigma protocol with a realized commitment sampler gives a perfectly complete interactive reduction to Interactive.Accept in the plain model.

Round-by-round soundness and soundness transfer #

The round-by-round state predicate for P on transcript prefixes of P.interactiveSpec:

  • at the empty prefix none, some commitment has accepting responses for two distinct challenges;
  • after commitment t (some (t, none)), t has accepting responses for two distinct challenges;
  • after challenge c (some (t, some (c, none))), (t, c) has an accepting response z;
  • on a complete transcript some (t, some (c, some (z, ()))), P.Accepts y t c z holds.
theorem Cslib.Crypto.Protocols.SigmaProtocol.not_rbrState_empty_of_specialSoundness {X Y T C Z : Type} {P : SigmaProtocol X Y T C Z} {W : Type} {R : W → Y → Prop} {extract : Y → T → C → Z → C → Z → W} (h : P.SpecialSoundness R extract) {y : Y} (hy : y ∉ Interactive.language (Function.swap R)) :

P.rbrState y satisfies RbrFrom with challenge error 1 / Fintype.card C.

theorem Cslib.Crypto.Protocols.SigmaProtocol.SpecialSoundness.rbrSound {X Y T C Z : Type} {P : SigmaProtocol X Y T C Z} [Fintype C] [Nonempty C] {W : Type} {R : W → Y → Prop} {extract : Y → T → C → Z → C → Z → W} (h : P.SpecialSoundness R extract) (langOut : Set Unit := Set.univ) :

Round-by-round soundness transfer: 2-special soundness of P implies round-by-round soundness of P.toInteractiveVerifier with challenge error 1 / |C|.

theorem Cslib.Crypto.Protocols.SigmaProtocol.SpecialSoundness.sound {X Y T C Z : Type} {P : SigmaProtocol X Y T C Z} [Fintype C] [Nonempty C] {W : Type} {R : W → Y → Prop} {extract : Y → T → C → Z → C → Z → W} (h : P.SpecialSoundness R extract) (langOut : Set Unit := Set.univ) :

Soundness transfer: 2-special soundness of P implies plain-model soundness of P.toInteractiveVerifier against arbitrary unbounded provers with error 1 / |C|.

Honest-verifier zero knowledge transfer #

noncomputable def Cslib.Crypto.Protocols.SigmaProtocol.interactiveSim {X Y T C Z : Type} [Fintype C] [Nonempty C] (P : SigmaProtocol X Y T C Z) (simComp : Y → C → ProbComp (T × Z)) (y : Y) :

The interactive transcript simulator induced by a challenge-conditioned ProbComp simulator simComp: sample a uniform challenge c : C, sample (t, z) ← simComp y c, and return (t, c, z, ()).

theorem Cslib.Crypto.Protocols.SigmaProtocol.eval_interactiveSim {X Y T C Z : Type} [Fintype C] [Nonempty C] (P : SigmaProtocol X Y T C Z) (simComp : Y → C → ProbComp (T × Z)) (y : Y) :
(P.interactiveSim simComp y).eval = (Probability.PMF.uniformOfFintype C).bind fun (c : C) => PMF.map (fun (tz : T × Z) => P.interactiveTranscript tz.1 c tz.2) (simComp y c).eval
theorem Cslib.Crypto.Protocols.SigmaProtocol.SpecialHVZK.hvzk {X Y T C Z : Type} {P : SigmaProtocol X Y T C Z} [Fintype C] [Nonempty C] {R : X → Y → Prop} {simulate : Y → C → PMF (T × Z)} {sampleCommit : X → Y → ProbComp (T × P.State)} {simComp : Y → C → ProbComp (T × Z)} {ε : ENNReal} (h : P.SpecialHVZK R simulate) (hcommit : P.CommitRealizedBy sampleCommit) (hsim : ∀ (y : Y) (c : C), Probability.CloseTo (simulate y c) (simComp y c).eval ε) :
(P.toInteractiveReduction sampleCommit).HVZK (Function.swap R) (P.interactiveSim simComp) ε

HVZK transfer: if P is special HVZK with simulate, sampleCommit realizes P.commit, and simComp y c is within statistical distance ε of simulate y c at every challenge, then P.toInteractiveReduction sampleCommit is ε-HVZK with P.interactiveSim simComp.

theorem Cslib.Crypto.Protocols.SigmaProtocol.SpecialHVZK.hvzk_zero {X Y T C Z : Type} {P : SigmaProtocol X Y T C Z} [Fintype C] [Nonempty C] {R : X → Y → Prop} {simulate : Y → C → PMF (T × Z)} {sampleCommit : X → Y → ProbComp (T × P.State)} {simComp : Y → C → ProbComp (T × Z)} (h : P.SpecialHVZK R simulate) (hcommit : P.CommitRealizedBy sampleCommit) (hsim : ∀ (y : Y) (c : C), (simComp y c).eval = simulate y c) :
(P.toInteractiveReduction sampleCommit).HVZK (Function.swap R) (P.interactiveSim simComp) 0

Perfect HVZK transfer: if P is special HVZK with simulate, sampleCommit realizes P.commit, and simComp evaluates to simulate at every challenge, then P.toInteractiveReduction sampleCommit is perfectly HVZK (ε = 0).

Indexed families: encodings and efficient HVZK #

def Cslib.Crypto.Protocols.SigmaProtocol.Encoding.toInteractiveEncoding {I : Type} {XF YF TF CF ZF : I → Type} (PF : (i : I) → SigmaProtocol (XF i) (YF i) (TF i) (CF i) (ZF i)) (enc : Encoding I YF TF CF ZF) :
Interactive.Encoding I (fun (i : I) => (PF i).interactiveSpec) YF

Convert a SigmaProtocol.Encoding for an indexed family PF into an Interactive.Encoding, encoding each transcript (t, c, z, ()) as the nested pair (t, (c, z)).

def Cslib.Crypto.Protocols.SigmaProtocol.interactiveSimWord {I : Type} {YF TF CF ZF : I → Type} (enc : Encoding I YF TF CF ZF) (program : I × List Bool × List Bool → ProbComp (List Bool × List Bool)) (sampleChallenge : (i : I) → ProbComp (CF i)) :

Combine a challenge sampler sampleChallenge with a word-level Sigma-protocol simulator program to sample encoded interactive transcripts (t, (c, z)): the sampled challenge is passed to program encoded by enc.

If program is uniform strict PPT and one machine samples the encoded challenges of sampleChallenge from the encoded index, then interactiveSimWord is uniform strict PPT.

theorem Cslib.Crypto.Protocols.SigmaProtocol.simulatorRealizedBy_interactiveSimWord {I : Type} {XF YF TF CF ZF : I → Type} (PF : (i : I) → SigmaProtocol (XF i) (YF i) (TF i) (CF i) (ZF i)) [(i : I) → Fintype (CF i)] [∀ (i : I), Nonempty (CF i)] {enc : Encoding I YF TF CF ZF} {simulate : (i : I) → YF i → CF i → PMF (TF i × ZF i)} {simComp : (i : I) → YF i → CF i → ProbComp (TF i × ZF i)} {program : I × List Bool × List Bool → ProbComp (List Bool × List Bool)} {sampleChallenge : (i : I) → ProbComp (CF i)} {δ δC : I → ENNReal} (hsim : ∀ (i : I) (y : YF i) (c : CF i), (simComp i y c).eval = simulate i y c) (hreal : WordSimulatorRealizedBy enc simulate program δ) (hchal : ∀ (i : I), Probability.CloseTo (Probability.PMF.uniformOfFintype (CF i)) (sampleChallenge i).eval (δC i)) :
Interactive.SimulatorRealizedBy (Encoding.toInteractiveEncoding PF enc) (fun (i : I) => (PF i).interactiveSim (simComp i)) (interactiveSimWord enc program sampleChallenge) fun (i : I) => δC i + δ i

interactiveSimWord realizes (PF i).interactiveSim (simComp i) on encodings up to δC i + δ i, when program is within δ i of the encoded simulate i on every encoded input (as SimulatorRealizedBy.exists_word provides).

theorem Cslib.Crypto.Protocols.SigmaProtocol.EfficientSpecialHVZK.efficientHVZK {I : Type} {XF YF TF CF ZF : I → Type} (PF : (i : I) → SigmaProtocol (XF i) (YF i) (TF i) (CF i) (ZF i)) [(i : I) → Fintype (CF i)] [∀ (i : I), Nonempty (CF i)] {RF : (i : I) → XF i → YF i → Prop} {enc : Encoding I YF TF CF ZF} {simulate : (i : I) → YF i → CF i → PMF (TF i × ZF i)} {sampleCommit : (i : I) → XF i → YF i → ProbComp (TF i × (PF i).State)} {simComp : (i : I) → YF i → CF i → ProbComp (TF i × ZF i)} {sampleChallenge : (i : I) → ProbComp (CF i)} {δ δC : I → ENNReal} (h : EfficientSpecialHVZK PF RF enc simulate δ) (hcommit : ∀ (i : I), (PF i).CommitRealizedBy (sampleCommit i)) (hsim : ∀ (i : I) (y : YF i) (c : CF i), (simComp i y c).eval = simulate i y c) (hchalPPT : Probability.IsPPTOn enc.index Turing.MultiTapeTM.encBits fun (i : I) => ⇑(enc.challenge i) <$> sampleChallenge i) (hchal : ∀ (i : I), Probability.CloseTo (Probability.PMF.uniformOfFintype (CF i)) (sampleChallenge i).eval (δC i)) :
Interactive.Reduction.EfficientHVZK (fun (i : I) => (PF i).toInteractiveReduction (sampleCommit i)) (fun (i : I) => Function.swap (RF i)) (Encoding.toInteractiveEncoding PF enc) (fun (i : I) => (PF i).interactiveSim (simComp i)) (fun (x : I) => 0) fun (i : I) => δC i + δ i

Efficient HVZK transfer: an EfficientSpecialHVZK family of Sigma protocols, paired with a strict PPT challenge sampler for CF i within δC i of uniform, yields Interactive.Reduction.EfficientHVZK with simulation error 0 and realization error δC i + δ i.

Realizations for linear, Schnorr, AND and OR protocols #

noncomputable def Cslib.Crypto.Protocols.SigmaProtocol.linearCommit {q : ℕ} {M N Y : Type} [AddCommGroup M] [Module (ZMod q) M] [Fintype M] [Nonempty M] [AddCommGroup N] [Module (ZMod q) N] (ψ : Y → M →ₗ[ZMod q] N) :
M → (y : Y) → ProbComp (N × M)

ProbComp commitment sampler for SigmaProtocol.linear: draw r ← ProbComp.uniform M and return (ψ y r, r).

noncomputable def Cslib.Crypto.Protocols.SigmaProtocol.linearSimComp {q : ℕ} {M N Y C : Type} [AddCommGroup M] [Module (ZMod q) M] [Fintype M] [Nonempty M] [AddCommGroup N] [Module (ZMod q) N] (ψ : Y → M →ₗ[ZMod q] N) (u : Y → N) (ι : C ↪ ZMod q) (y : Y) (c : C) :
ProbComp (N × M)

ProbComp simulator for SigmaProtocol.linear: draw z ← ProbComp.uniform M and return (ψ y z - ι c • u y, z).

theorem Cslib.Crypto.Protocols.SigmaProtocol.commitRealizedBy_linear {q : ℕ} {M N Y C : Type} [AddCommGroup M] [Module (ZMod q) M] [Fintype M] [Nonempty M] [AddCommGroup N] [Module (ZMod q) N] [DecidableEq N] (ψ : Y → M →ₗ[ZMod q] N) (u : Y → N) (ι : C ↪ ZMod q) :
@[simp]
theorem Cslib.Crypto.Protocols.SigmaProtocol.eval_linearSimComp {q : ℕ} {M N Y C : Type} [AddCommGroup M] [Module (ZMod q) M] [Fintype M] [Nonempty M] [AddCommGroup N] [Module (ZMod q) N] (ψ : Y → M →ₗ[ZMod q] N) (u : Y → N) (ι : C ↪ ZMod q) (y : Y) (c : C) :
(linearSimComp ψ u ι y c).eval = linearSimulate ψ u ι y c
noncomputable def Cslib.Crypto.Protocols.SigmaProtocol.schnorrCommit {q : ℕ} [NeZero q] {G : Type} [AddCommGroup G] [Module (ZMod q) G] (g : G) :
ZMod q → G → ProbComp (G × ZMod q)

ProbComp commitment sampler for SigmaProtocol.schnorr.

noncomputable def Cslib.Crypto.Protocols.SigmaProtocol.schnorrSimComp {q : ℕ} [NeZero q] {G C : Type} [AddCommGroup G] [Module (ZMod q) G] (ι : C ↪ ZMod q) (g : G) :
G → C → ProbComp (G × ZMod q)

ProbComp simulator for SigmaProtocol.schnorr.

@[simp]
theorem Cslib.Crypto.Protocols.SigmaProtocol.eval_schnorrSimComp {q : ℕ} [NeZero q] {G C : Type} [AddCommGroup G] [Module (ZMod q) G] (ι : C ↪ ZMod q) (g u : G) (c : C) :
(schnorrSimComp ι g u c).eval = linearSimulate (fun (x : G) => LinearMap.toSpanSingleton (ZMod q) G g) id ι u c
def Cslib.Crypto.Protocols.SigmaProtocol.andCommit {X₀ Y₀ T₀ Z₀ X₁ Y₁ T₁ Z₁ C : Type} {P₀ : SigmaProtocol X₀ Y₀ T₀ C Z₀} {P₁ : SigmaProtocol X₁ Y₁ T₁ C Z₁} (sample₀ : X₀ → Y₀ → ProbComp (T₀ × P₀.State)) (sample₁ : X₁ → Y₁ → ProbComp (T₁ × P₁.State)) (x : X₀ × X₁) (y : Y₀ × Y₁) :
ProbComp ((T₀ × T₁) × P₀.State × P₁.State)

ProbComp commitment sampler for P₀.andProof P₁.

def Cslib.Crypto.Protocols.SigmaProtocol.andSimComp {Y₀ T₀ Z₀ Y₁ T₁ Z₁ C : Type} (sim₀ : Y₀ → C → ProbComp (T₀ × Z₀)) (sim₁ : Y₁ → C → ProbComp (T₁ × Z₁)) (y : Y₀ × Y₁) (c : C) :
ProbComp ((T₀ × T₁) × Z₀ × Z₁)

ProbComp simulator for P₀.andProof P₁.

theorem Cslib.Crypto.Protocols.SigmaProtocol.commitRealizedBy_andProof {X₀ Y₀ T₀ Z₀ X₁ Y₁ T₁ Z₁ C : Type} {P₀ : SigmaProtocol X₀ Y₀ T₀ C Z₀} {P₁ : SigmaProtocol X₁ Y₁ T₁ C Z₁} {sample₀ : X₀ → Y₀ → ProbComp (T₀ × P₀.State)} {sample₁ : X₁ → Y₁ → ProbComp (T₁ × P₁.State)} (h₀ : P₀.CommitRealizedBy sample₀) (h₁ : P₁.CommitRealizedBy sample₁) :
(P₀.andProof P₁).CommitRealizedBy (andCommit sample₀ sample₁)
theorem Cslib.Crypto.Protocols.SigmaProtocol.eval_andSimComp {Y₀ T₀ Z₀ Y₁ T₁ Z₁ C : Type} {simulate₀ : Y₀ → C → PMF (T₀ × Z₀)} {simulate₁ : Y₁ → C → PMF (T₁ × Z₁)} {sim₀ : Y₀ → C → ProbComp (T₀ × Z₀)} {sim₁ : Y₁ → C → ProbComp (T₁ × Z₁)} (h₀ : ∀ (y : Y₀) (c : C), (sim₀ y c).eval = simulate₀ y c) (h₁ : ∀ (y : Y₁) (c : C), (sim₁ y c).eval = simulate₁ y c) (y : Y₀ × Y₁) (c : C) :
(andSimComp sim₀ sim₁ y c).eval = andSimulate simulate₀ simulate₁ y c
noncomputable def Cslib.Crypto.Protocols.SigmaProtocol.orCommit {X₀ Y₀ T₀ Z₀ X₁ Y₁ T₁ Z₁ C : Type} {P₀ : SigmaProtocol X₀ Y₀ T₀ C Z₀} {P₁ : SigmaProtocol X₁ Y₁ T₁ C Z₁} [Fintype C] [Nonempty C] (sample₀ : X₀ → Y₀ → ProbComp (T₀ × P₀.State)) (sample₁ : X₁ → Y₁ → ProbComp (T₁ × P₁.State)) (sim₀ : Y₀ → C → ProbComp (T₀ × Z₀)) (sim₁ : Y₁ → C → ProbComp (T₁ × Z₁)) :
X₀ ⊕ X₁ → Y₀ × Y₁ → ProbComp ((T₀ × T₁) × (X₀ × P₀.State × C × Z₁ ⊕ X₁ × P₁.State × C × Z₀))

ProbComp commitment sampler for orProof P₀ P₁ simulate₀ simulate₁.

noncomputable def Cslib.Crypto.Protocols.SigmaProtocol.orSimComp {Y₀ T₀ Z₀ Y₁ T₁ Z₁ C : Type} [AddCommGroup C] [Fintype C] [Nonempty C] (sim₀ : Y₀ → C → ProbComp (T₀ × Z₀)) (sim₁ : Y₁ → C → ProbComp (T₁ × Z₁)) (y : Y₀ × Y₁) (c : C) :
ProbComp ((T₀ × T₁) × C × Z₀ × Z₁)

ProbComp simulator for orProof P₀ P₁ simulate₀ simulate₁.

theorem Cslib.Crypto.Protocols.SigmaProtocol.commitRealizedBy_orProof {X₀ Y₀ T₀ Z₀ X₁ Y₁ T₁ Z₁ C : Type} {P₀ : SigmaProtocol X₀ Y₀ T₀ C Z₀} {P₁ : SigmaProtocol X₁ Y₁ T₁ C Z₁} [AddCommGroup C] [Fintype C] [Nonempty C] {simulate₀ : Y₀ → C → PMF (T₀ × Z₀)} {simulate₁ : Y₁ → C → PMF (T₁ × Z₁)} {sample₀ : X₀ → Y₀ → ProbComp (T₀ × P₀.State)} {sample₁ : X₁ → Y₁ → ProbComp (T₁ × P₁.State)} {sim₀ : Y₀ → C → ProbComp (T₀ × Z₀)} {sim₁ : Y₁ → C → ProbComp (T₁ × Z₁)} (h₀ : P₀.CommitRealizedBy sample₀) (h₁ : P₁.CommitRealizedBy sample₁) (hs₀ : ∀ (y : Y₀) (c : C), (sim₀ y c).eval = simulate₀ y c) (hs₁ : ∀ (y : Y₁) (c : C), (sim₁ y c).eval = simulate₁ y c) :
(P₀.orProof P₁ simulate₀ simulate₁).CommitRealizedBy (orCommit sample₀ sample₁ sim₀ sim₁)
theorem Cslib.Crypto.Protocols.SigmaProtocol.eval_orSimComp {Y₀ T₀ Z₀ Y₁ T₁ Z₁ C : Type} [AddCommGroup C] [Fintype C] [Nonempty C] {simulate₀ : Y₀ → C → PMF (T₀ × Z₀)} {simulate₁ : Y₁ → C → PMF (T₁ × Z₁)} {sim₀ : Y₀ → C → ProbComp (T₀ × Z₀)} {sim₁ : Y₁ → C → ProbComp (T₁ × Z₁)} (hs₀ : ∀ (y : Y₀) (c : C), (sim₀ y c).eval = simulate₀ y c) (hs₁ : ∀ (y : Y₁) (c : C), (sim₁ y c).eval = simulate₁ y c) (y : Y₀ × Y₁) (c : C) :
(orSimComp sim₀ sim₁ y c).eval = orSimulate simulate₀ simulate₁ y c