Skip to content

Commit d8d7968

Browse files
committed
Simplify struct for SchnorrProof
1 parent 46c4eba commit d8d7968

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

src/toolbox/sigma/group_morphism.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct Morphism<G: Group> {
3333
/// Perform a simple multi-scalar multiplication (MSM) over scalars and points.
3434
fn msm_pr<G: Group>(scalars: &[G::Scalar], bases: &[G]) -> G {
3535
let mut acc = G::identity();
36-
for (s, p) in scalars.iter().zip(bases.iter()) {
36+
for (s, p) in scalars.iter().zip(bases.into_iter()) {
3737
acc += *p * s;
3838
}
3939
acc

src/toolbox/sigma/schnorr_proof.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ use rand::{CryptoRng, Rng};
1515
/// A Schnorr protocol proving knowledge some discrete logarithm relation.
1616
///
1717
/// The specific proof instance is defined by a [`GroupMorphismPreimage`] over a group `G`.
18-
pub struct SchnorrProof<G>
19-
where
20-
G: Group + GroupEncoding + GroupSerialisation,
21-
{
22-
/// The public instance and its associated group morphism.
23-
pub morphismp: GroupMorphismPreimage<G>,
24-
}
18+
pub struct SchnorrProof<G: Group + GroupEncoding + GroupSerialisation>(pub GroupMorphismPreimage<G>);
2519

2620
/// Internal prover state during the protocol execution: (random nonce, witness)
2721
pub struct SchnorrState<S> {
@@ -47,9 +41,9 @@ where
4741
witness: &Self::Witness,
4842
mut rng: &mut (impl Rng + CryptoRng),
4943
) -> (Self::Commitment, Self::ProverState) {
50-
let nonces: Vec<G::Scalar> = (0..self.morphismp.morphism.num_scalars).map(|_| G::Scalar::random(&mut rng)).collect();
44+
let nonces: Vec<G::Scalar> = (0..self.0.morphism.num_scalars).map(|_| G::Scalar::random(&mut rng)).collect();
5145
let prover_state = (nonces.clone(), witness.clone());
52-
let commitment = self.morphismp.morphism.evaluate(&nonces);
46+
let commitment = self.0.morphism.evaluate(&nonces);
5347
(commitment, prover_state)
5448
}
5549

@@ -60,8 +54,8 @@ where
6054
challenge: &Self::Challenge,
6155
) -> Self::Response {
6256
let mut responses = Vec::new();
63-
for i in 0..self.morphismp.morphism.num_scalars {
64-
responses.push(state.0[i] + *challenge * state.1[i]);
57+
for i in 0..self.0.morphism.num_scalars {
58+
responses.push(state.0[i] + state.1[i] * challenge);
6559
}
6660
responses
6761
}
@@ -73,16 +67,16 @@ where
7367
challenge: &Self::Challenge,
7468
response: &Self::Response,
7569
) -> Result<(), ProofError> {
76-
let lhs = self.morphismp.morphism.evaluate(response);
70+
let lhs = self.0.morphism.evaluate(response);
7771

7872
let mut rhs = Vec::new();
7973
for (i, g) in commitment
8074
.iter()
8175
.enumerate()
82-
.take(self.morphismp.morphism.num_statements())
76+
.take(self.0.morphism.num_statements())
8377
{
8478
rhs.push(
85-
self.morphismp.morphism.group_elements[self.morphismp.image[i]] * challenge + g,
79+
self.0.morphism.group_elements[self.0.image[i]] * challenge + g,
8680
);
8781
}
8882

@@ -100,8 +94,8 @@ where
10094
response: &Self::Response,
10195
) -> Vec<u8> {
10296
let mut bytes = Vec::new();
103-
let scalar_nb = self.morphismp.morphism.num_scalars;
104-
let point_nb = self.morphismp.morphism.num_statements();
97+
let scalar_nb = self.0.morphism.num_scalars;
98+
let point_nb = self.0.morphism.num_statements();
10599

106100
// Serialize commitments
107101
for commit in commitment.iter().take(point_nb) {
@@ -117,8 +111,8 @@ where
117111

118112
/// Deserializes a batchable proof format back into (`commitment`, `response`).
119113
fn deserialize_batchable(&self, data: &[u8]) -> Option<(Self::Commitment, Self::Response)> {
120-
let scalar_nb = self.morphismp.morphism.num_scalars;
121-
let point_nb = self.morphismp.morphism.num_statements();
114+
let scalar_nb = self.0.morphism.num_scalars;
115+
let point_nb = self.0.morphism.num_statements();
122116

123117
let point_size = G::generator().to_bytes().as_ref().len();
124118
let scalar_size = <<G as Group>::Scalar as PrimeField>::Repr::default()

tests/non_interactive_protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn fiat_shamir_schnorr_proof_ristretto() {
3636
morphismp.append_equation(1, &[(0, 0)]);
3737

3838
// The SigmaProtocol induced by morphismp
39-
let protocol = SchnorrProof { morphismp };
39+
let protocol = SchnorrProof(morphismp);
4040

4141
// Fiat-Shamir wrapper
4242
let mut nizk =

tests/various_tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ fn NI_discrete_logarithm() {
231231
let (morphismp, witness) = discrete_logarithm::<G>(&mut rng);
232232

233233
// The SigmaProtocol induced by morphismp
234-
let protocol = SchnorrProof { morphismp };
234+
let protocol = SchnorrProof(morphismp);
235235
// Fiat-Shamir wrapper
236236
let domain_sep = b"test-fiat-shamir-schnorr";
237237
let mut nizk =
@@ -251,7 +251,7 @@ fn NI_dleq() {
251251
let (morphismp, witness) = dleq::<G>(&mut rng);
252252

253253
// The SigmaProtocol induced by morphismp
254-
let protocol = SchnorrProof { morphismp };
254+
let protocol = SchnorrProof(morphismp);
255255
// Fiat-Shamir wrapper
256256
let domain_sep = b"test-fiat-shamir-DLEQ";
257257
let mut nizk =
@@ -271,7 +271,7 @@ fn NI_pedersen_commitment() {
271271
let (morphismp, witness) = pedersen_commitment::<G>(&mut rng);
272272

273273
// The SigmaProtocol induced by morphismp
274-
let protocol = SchnorrProof { morphismp };
274+
let protocol = SchnorrProof(morphismp);
275275
// Fiat-Shamir wrapper
276276
let domain_sep = b"test-fiat-shamir-pedersen-commitment";
277277
let mut nizk =
@@ -291,7 +291,7 @@ fn NI_pedersen_commitment_dleq() {
291291
let (morphismp, witness) = pedersen_commitment_dleq::<G>(&mut rng);
292292

293293
// The SigmaProtocol induced by morphismp
294-
let protocol = SchnorrProof { morphismp };
294+
let protocol = SchnorrProof(morphismp);
295295
// Fiat-Shamir wrapper
296296
let domain_sep = b"test-fiat-shamir-pedersen-commitment-DLEQ";
297297
let mut nizk =
@@ -311,7 +311,7 @@ fn NI_bbs_blind_commitment_computation() {
311311
let (morphismp, witness) = bbs_blind_commitment_computation::<G>(&mut rng);
312312

313313
// The SigmaProtocol induced by morphismp
314-
let protocol = SchnorrProof { morphismp };
314+
let protocol = SchnorrProof(morphismp);
315315
// Fiat-Shamir wrapper
316316
let domain_sep = b"test-fiat-shamir-bbs-blind-commitment-computation";
317317
let mut nizk =

0 commit comments

Comments
 (0)