Skip to content

Commit c001794

Browse files
committed
refactor(mutability): remove unnecessary mutable references in NISigmaProtocol
- refactor: eliminate unnecessary mutable character from NISigmaProtocol method parameters
1 parent d5533c7 commit c001794

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

src/fiat_shamir.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ where
9090
/// # Panics
9191
/// Panics if local verification fails.
9292
pub fn prove(
93-
&mut self,
93+
&self,
9494
witness: &P::Witness,
9595
rng: &mut (impl RngCore + CryptoRng),
9696
) -> Result<Transcript<P>, ProofError> {
@@ -127,7 +127,7 @@ where
127127
/// - The challenge doesn't match the recomputed one from the commitment.
128128
/// - The response fails verification under the Sigma protocol.
129129
pub fn verify(
130-
&mut self,
130+
&self,
131131
commitment: &P::Commitment,
132132
challenge: &P::Challenge,
133133
response: &P::Response,
@@ -159,7 +159,7 @@ where
159159
/// # Panics
160160
/// Panics if serialization fails (should not happen under correct implementation).
161161
pub fn prove_batchable(
162-
&mut self,
162+
&self,
163163
witness: &P::Witness,
164164
rng: &mut (impl RngCore + CryptoRng),
165165
) -> Result<Vec<u8>, ProofError> {
@@ -183,7 +183,7 @@ where
183183
/// - Returns `ProofError::VerificationFailure` if:
184184
/// - The challenge doesn't match the recomputed one from the commitment.
185185
/// - The response fails verification under the Sigma protocol.
186-
pub fn verify_batchable(&mut self, proof: &[u8]) -> Result<(), ProofError> {
186+
pub fn verify_batchable(&self, proof: &[u8]) -> Result<(), ProofError> {
187187
let (commitment, response) = self.sigmap.deserialize_batchable(proof).unwrap();
188188

189189
let mut codec = self.hash_state.clone();
@@ -220,7 +220,7 @@ where
220220
/// # Panics
221221
/// Panics if serialization fails.
222222
pub fn prove_compact(
223-
&mut self,
223+
&self,
224224
witness: &P::Witness,
225225
rng: &mut (impl RngCore + CryptoRng),
226226
) -> Result<Vec<u8>, ProofError> {
@@ -246,7 +246,7 @@ where
246246
/// - Returns `ProofError::VerificationFailure` if:
247247
/// - Deserialization fails.
248248
/// - The recomputed commitment or response is invalid under the Sigma protocol.
249-
pub fn verify_compact(&mut self, proof: &[u8]) -> Result<(), ProofError> {
249+
pub fn verify_compact(&self, proof: &[u8]) -> Result<(), ProofError> {
250250
let (challenge, response) = self.sigmap.deserialize_compact(proof).unwrap();
251251
// Compute the commitments
252252
let commitment = self.sigmap.get_commitment(&challenge, &response)?;

tests/morphism_preimage.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ fn NI_discrete_logarithm() {
232232
let protocol = SchnorrProtocol::from_preimage(morphismp);
233233
// Fiat-Shamir wrapper
234234
let domain_sep = b"test-fiat-shamir-schnorr";
235-
let mut nizk =
235+
let nizk =
236236
NISigmaProtocol::<SchnorrProtocol<G>, ShakeCodec<G>, G>::new(domain_sep, protocol);
237237

238238
// Batchable and compact proofs
@@ -261,7 +261,7 @@ fn NI_dleq() {
261261
let protocol = SchnorrProtocol::from_preimage(morphismp);
262262
// Fiat-Shamir wrapper
263263
let domain_sep = b"test-fiat-shamir-DLEQ";
264-
let mut nizk =
264+
let nizk =
265265
NISigmaProtocol::<SchnorrProtocol<G>, ShakeCodec<G>, G>::new(domain_sep, protocol);
266266

267267
// Batchable and compact proofs
@@ -290,7 +290,7 @@ fn NI_pedersen_commitment() {
290290
let protocol = SchnorrProtocol::from_preimage(morphismp);
291291
// Fiat-Shamir wrapper
292292
let domain_sep = b"test-fiat-shamir-pedersen-commitment";
293-
let mut nizk =
293+
let nizk =
294294
NISigmaProtocol::<SchnorrProtocol<G>, ShakeCodec<G>, G>::new(domain_sep, protocol);
295295

296296
// Batchable and compact proofs
@@ -319,7 +319,7 @@ fn NI_pedersen_commitment_dleq() {
319319
let protocol = SchnorrProtocol::from_preimage(morphismp);
320320
// Fiat-Shamir wrapper
321321
let domain_sep = b"test-fiat-shamir-pedersen-commitment-DLEQ";
322-
let mut nizk =
322+
let nizk =
323323
NISigmaProtocol::<SchnorrProtocol<G>, ShakeCodec<G>, G>::new(domain_sep, protocol);
324324

325325
// Batchable and compact proofs
@@ -348,7 +348,7 @@ fn NI_bbs_blind_commitment_computation() {
348348
let protocol = SchnorrProtocol::from_preimage(morphismp);
349349
// Fiat-Shamir wrapper
350350
let domain_sep = b"test-fiat-shamir-bbs-blind-commitment-computation";
351-
let mut nizk =
351+
let nizk =
352352
NISigmaProtocol::<SchnorrProtocol<G>, ShakeCodec<G>, G>::new(domain_sep, protocol);
353353

354354
// Batchable and compact proofs

tests/proof_composition.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn and_proof_correct() {
7676
witness.extend(&x1);
7777
witness.extend(&x2);
7878

79-
let mut nizk = NISigmaProtocol::<AndProtocol<RistrettoPoint>, ShakeCodec<G>, G>::new(
79+
let nizk = NISigmaProtocol::<AndProtocol<RistrettoPoint>, ShakeCodec<G>, G>::new(
8080
domain_sep,
8181
and_protocol,
8282
);
@@ -111,7 +111,7 @@ fn and_proof_incorrect() {
111111
witness.push(fake_x);
112112
witness.extend(x2);
113113

114-
let mut nizk = NISigmaProtocol::<AndProtocol<RistrettoPoint>, ShakeCodec<G>, G>::new(
114+
let nizk = NISigmaProtocol::<AndProtocol<RistrettoPoint>, ShakeCodec<G>, G>::new(
115115
domain_sep,
116116
and_protocol,
117117
);
@@ -143,7 +143,7 @@ fn or_proof_correct() {
143143

144144
let witness = (1, x1);
145145

146-
let mut nizk = NISigmaProtocol::<OrProtocol<RistrettoPoint>, ShakeCodec<G>, G>::new(
146+
let nizk = NISigmaProtocol::<OrProtocol<RistrettoPoint>, ShakeCodec<G>, G>::new(
147147
domain_sep,
148148
or_protocol,
149149
);
@@ -177,7 +177,7 @@ fn or_proof_incorrect() {
177177

178178
let witness = (0, vec![<G as Group>::Scalar::random(&mut rng)]);
179179

180-
let mut nizk = NISigmaProtocol::<OrProtocol<RistrettoPoint>, ShakeCodec<G>, G>::new(
180+
let nizk = NISigmaProtocol::<OrProtocol<RistrettoPoint>, ShakeCodec<G>, G>::new(
181181
domain_sep,
182182
or_protocol,
183183
);

tests/spec/sage_test_vectors.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ fn NI_discrete_logarithm(seed: &[u8], context: &[u8]) -> (Vec<Scalar>, Vec<u8>)
250250

251251
let protocol = SchnorrProtocolCustom(morphismp);
252252
let domain_sep: Vec<u8> = context.to_vec();
253-
let mut nizk = NISigmaP::new(&domain_sep, protocol);
253+
let nizk = NISigmaP::new(&domain_sep, protocol);
254254

255255
let proof_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();
256256
let verified = nizk.verify_batchable(&proof_bytes).is_ok();
@@ -265,7 +265,7 @@ fn NI_dleq(seed: &[u8], context: &[u8]) -> (Vec<Scalar>, Vec<u8>) {
265265

266266
let protocol = SchnorrProtocolCustom(morphismp);
267267
let domain_sep: Vec<u8> = context.to_vec();
268-
let mut nizk = NISigmaP::new(&domain_sep, protocol);
268+
let nizk = NISigmaP::new(&domain_sep, protocol);
269269

270270
let proof_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();
271271
let verified = nizk.verify_batchable(&proof_bytes).is_ok();
@@ -280,7 +280,7 @@ fn NI_pedersen_commitment(seed: &[u8], context: &[u8]) -> (Vec<Scalar>, Vec<u8>)
280280

281281
let protocol = SchnorrProtocolCustom(morphismp);
282282
let domain_sep: Vec<u8> = context.to_vec();
283-
let mut nizk = NISigmaP::new(&domain_sep, protocol);
283+
let nizk = NISigmaP::new(&domain_sep, protocol);
284284

285285
let proof_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();
286286
let verified = nizk.verify_batchable(&proof_bytes).is_ok();
@@ -295,7 +295,7 @@ fn NI_pedersen_commitment_dleq(seed: &[u8], context: &[u8]) -> (Vec<Scalar>, Vec
295295

296296
let protocol = SchnorrProtocolCustom(morphismp);
297297
let domain_sep: Vec<u8> = context.to_vec();
298-
let mut nizk = NISigmaP::new(&domain_sep, protocol);
298+
let nizk = NISigmaP::new(&domain_sep, protocol);
299299

300300
let proof_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();
301301
let verified = nizk.verify_batchable(&proof_bytes).is_ok();
@@ -310,7 +310,7 @@ fn NI_bbs_blind_commitment_computation(seed: &[u8], context: &[u8]) -> (Vec<Scal
310310

311311
let protocol = SchnorrProtocolCustom(morphismp);
312312
let domain_sep: Vec<u8> = context.to_vec();
313-
let mut nizk = NISigmaP::new(&domain_sep, protocol);
313+
let nizk = NISigmaP::new(&domain_sep, protocol);
314314

315315
let proof_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();
316316
let verified = nizk.verify_batchable(&proof_bytes).is_ok();

0 commit comments

Comments
 (0)