Skip to content

Commit 682a5b6

Browse files
committed
feat(simulator): implement SigmaProtocolSimulator trait for SchnorrProtocol
- feat: add SigmaProtocolSimulator trait implementation for SchnorrProtocol - chore: move bls12_381 dependency to dev-dependencies - fix: correct naming inconsistencies and miscellaneous issues
1 parent 77ac92f commit 682a5b6

File tree

9 files changed

+45
-51
lines changed

9 files changed

+45
-51
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ subtle = "2.6.1"
3737
num-bigint = "0.4.6"
3838
num-traits = "0.2.19"
3939
tiny-keccak = { version = "2.0.2", features = ["fips202"] }
40-
bls12_381 = "0.8.0"
4140

4241
[dev-dependencies]
4342
bincode = "1"

src/codec/keccak_codec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! # Keccak-based Fiat-Shamir Codec for vector tests
22
//!
3-
//! This module implements a **Fiat-Shamir transcript codec** using the Keccak-f[1600] permutation
3+
//! This module implements a **Fiat-Shamir codec** using the Keccak-f[1600] permutation
44
//! in a duplex sponge construction
55
//!
66
//! It includes:
77
//! - A custom `KeccakPermutationState` and `KeccakDuplexSponge`
8-
//! - A [`ByteSchnorrCodec`] transcript codec based on this sponge
8+
//! - A [`ByteSchnorrCodec`] codec based on this sponge
99
//!
1010
//! ## Purpose
1111
//! This module exists to **match test vectors** generated in the original Sage implementation
@@ -19,7 +19,7 @@
1919
//! ## Components
2020
//! - `KeccakPermutationState`: Low-level Keccak-f[1600] state representation
2121
//! - `KeccakDuplexSponge`: Duplex sponge over 200-byte state buffer
22-
//! - `ByteSchnorrCodec`: Fiat-Shamir transcript codec compatible with Sage Schnorr proofs
22+
//! - `ByteSchnorrCodec`: Fiat-Shamir codec compatible with Sage Schnorr proofs
2323
use crate::codec::r#trait::{Codec, DuplexSpongeInterface};
2424
use ff::PrimeField;
2525
use group::{Group, GroupEncoding};

src/proof_composition.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub enum OrEnum<L, R> {
173173
Right(R),
174174
}
175175

176-
/// Internal state for a simulated transcript in an OR proof.
176+
/// Internal state for a simulated transcription in an OR proof.
177177
pub struct OrState<P: SigmaProtocol>(P::Challenge, P::Response);
178178

179179
/// Enum to describe which side (left or right) is simulated in an OR proof.
@@ -213,7 +213,7 @@ where
213213
let (r_index, r_witness_w) = witness;
214214
match r_witness_w {
215215
OrEnum::Left(ref r_witness) => {
216-
let f_trnsc = self.protocol1.simulate_transcript(rng);
216+
let f_trnsc = self.protocol1.simulate_transcription(rng);
217217
let ST = OrState(f_trnsc.1, f_trnsc.2);
218218
let (commit, r_pr_st) = self.protocol0.prover_commit(r_witness, rng);
219219
(
@@ -222,7 +222,7 @@ where
222222
)
223223
}
224224
OrEnum::Right(ref r_witness) => {
225-
let f_trnsc = self.protocol0.simulate_transcript(rng);
225+
let f_trnsc = self.protocol0.simulate_transcription(rng);
226226
let ST = OrState(f_trnsc.1, f_trnsc.2);
227227
let (commit, r_pr_st) = self.protocol1.prover_commit(r_witness, rng);
228228
(

src/schnorr_protocol.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
77
use crate::{
88
group_serialization::*,
9-
CompactProtocol, GroupMorphismPreimage, ProofError,
9+
GroupMorphismPreimage,
10+
ProofError,
1011
SigmaProtocol,
12+
CompactProtocol,
13+
SigmaProtocolSimulator,
1114
};
1215

1316
use ff::{Field, PrimeField};
1417
use group::{Group, GroupEncoding};
1518
use rand::{CryptoRng, Rng};
19+
use std::iter;
1620

1721
/// A Schnorr protocol proving knowledge some discrete logarithm relation.
1822
///
@@ -220,3 +224,28 @@ where
220224
Ok((challenge, responses))
221225
}
222226
}
227+
228+
impl<G> SigmaProtocolSimulator for SchnorrProtocol<G>
229+
where
230+
G: Group + GroupEncoding,
231+
{
232+
fn simulate_proof(
233+
&self,
234+
challenge: &Self::Challenge,
235+
rng: &mut (impl Rng + CryptoRng),
236+
) -> (Self::Commitment, Self::Response) {
237+
let mut response = Vec::new();
238+
response.extend(iter::repeat(G::Scalar::random(rng)).take(self.0.morphism.num_scalars));
239+
let commitment = self.get_commitment(challenge, &response);
240+
(commitment, response)
241+
}
242+
243+
fn simulate_transcription(
244+
&self,
245+
rng: &mut (impl Rng + CryptoRng),
246+
) -> (Self::Commitment, Self::Challenge, Self::Response) {
247+
let challenge = G::Scalar::random(&mut *rng);
248+
let (commitment, response) = self.simulate_proof(&challenge, &mut *rng);
249+
(commitment, challenge, response)
250+
}
251+
}

src/trait.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub trait SigmaProtocol {
4848
challenge: &Self::Challenge,
4949
) -> Self::Response;
5050

51-
/// Verifies a Sigma protocol transcript.
51+
/// Verifies a Sigma protocol transcription.
5252
///
5353
/// Returns:
5454
/// - `Ok(())` if the verification succeeds.
@@ -60,7 +60,7 @@ pub trait SigmaProtocol {
6060
response: &Self::Response,
6161
) -> Result<(), ProofError>;
6262

63-
/// Serializes a proof transcript (commitment, challenge, response) to bytes batchable proof.
63+
/// Serializes a proof transcription (commitment, challenge, response) to bytes batchable proof.
6464
fn serialize_batchable(
6565
&self,
6666
_commitment: &Self::Commitment,
@@ -99,7 +99,7 @@ pub trait CompactProtocol: SigmaProtocol {
9999
response: &Self::Response,
100100
) -> Self::Commitment;
101101

102-
/// Serializes a proof transcript (commitment, challenge, response) to bytes compact proof.
102+
/// Serializes a proof transcription (commitment, challenge, response) to bytes compact proof.
103103
fn serialize_compact(
104104
&self,
105105
_commitment: &Self::Commitment,
@@ -120,17 +120,17 @@ pub trait CompactProtocol: SigmaProtocol {
120120
}
121121
}
122122

123-
/// A trait defining the behavior of a Sigma protocol for which simulation of transcripts is necessary.
123+
/// A trait defining the behavior of a Sigma protocol for which simulation of transcriptions is necessary.
124124
///
125-
/// All Sigma protocols can technically simulate a valid transcript, but this mostly serve to prove the security of the protocol and is not used in the real protocol execution.
125+
/// All Sigma protocols can technically simulate a valid transcription, but this mostly serve to prove the security of the protocol and is not used in the real protocol execution.
126126
/// However, some protocols (like OR protocols that prove the truth of one-out-of-two statements) require them during for the real execution.
127127
///
128128
/// ## Minimal Implementation
129129
/// Types implementing `SigmaProtocolSimulator` must define:
130130
/// - `simulate_proof`
131131
/// - `simulate_transcription`
132132
pub trait SigmaProtocolSimulator: SigmaProtocol {
133-
/// Simulates a protocol transcript given a challenge.
133+
/// Simulates a protocol transcription given a challenge.
134134
///
135135
/// This serves to create zero-knowledge simulations without access to a witness.
136136
fn simulate_proof(
@@ -139,8 +139,8 @@ pub trait SigmaProtocolSimulator: SigmaProtocol {
139139
rng: &mut (impl Rng + CryptoRng),
140140
) -> (Self::Commitment, Self::Response);
141141

142-
/// Simulates an entire protocol transcript.
143-
fn simulate_transcript(
142+
/// Simulates an entire protocol transcription.
143+
fn simulate_transcription(
144144
&self,
145145
rng: &mut (impl Rng + CryptoRng),
146146
) -> (Self::Commitment, Self::Challenge, Self::Response);

tests/interactive_codec.rs

Lines changed: 0 additions & 34 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

tests/proof_composition_test.rs renamed to tests/proof_composition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl SigmaProtocolSimulator for SchnorrZkp {
7575
(R, z)
7676
}
7777

78-
fn simulate_transcript(
78+
fn simulate_transcription(
7979
&self,
8080
rng: &mut (impl Rng + CryptoRng),
8181
) -> (Self::Commitment, Self::Challenge, Self::Response) {

0 commit comments

Comments
 (0)