Skip to content

Commit 745bd29

Browse files
committed
nit: re-use rng in tests and use core when possible.
1 parent f6c1956 commit 745bd29

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

src/linear_relation/canonical.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use core::iter;
2+
use core::marker::PhantomData;
13
use std::collections::HashMap;
2-
use std::iter;
3-
use std::marker::PhantomData;
44

55
use ff::Field;
66
use group::prime::PrimeGroup;

src/linear_relation/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
//! - [`LinearMap`]: a collection of linear combinations acting on group elements.
99
//! - [`LinearRelation`]: a higher-level structure managing linear maps and their associated images.
1010
11-
use std::iter;
12-
use std::marker::PhantomData;
11+
use core::iter;
12+
use core::marker::PhantomData;
1313

1414
use ff::Field;
1515
use group::prime::PrimeGroup;
@@ -40,8 +40,8 @@ impl<G> ScalarVar<G> {
4040
}
4141
}
4242

43-
impl<G> std::hash::Hash for ScalarVar<G> {
44-
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
43+
impl<G> core::hash::Hash for ScalarVar<G> {
44+
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
4545
self.0.hash(state)
4646
}
4747
}
@@ -58,8 +58,8 @@ impl<G> GroupVar<G> {
5858
}
5959
}
6060

61-
impl<G> std::hash::Hash for GroupVar<G> {
62-
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
61+
impl<G> core::hash::Hash for GroupVar<G> {
62+
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
6363
self.0.hash(state)
6464
}
6565
}
@@ -104,7 +104,7 @@ impl<T> Sum<T> {
104104
}
105105
}
106106

107-
impl<T> std::iter::Sum<T> for Sum<T> {
107+
impl<T> core::iter::Sum<T> for Sum<T> {
108108
/// Add a bunch of `T` to yield a `Sum<T>`
109109
fn sum<I>(iter: I) -> Self
110110
where

src/linear_relation/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ mod tests {
573573
use crate::linear_relation::{GroupVar, ScalarTerm, ScalarVar, Term};
574574
use curve25519_dalek::RistrettoPoint as G;
575575
use curve25519_dalek::Scalar;
576-
use std::marker::PhantomData;
576+
use core::marker::PhantomData;
577577

578578
fn scalar_var(i: usize) -> ScalarVar<G> {
579579
ScalarVar(i, PhantomData)

src/tests/test_composition.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use curve25519_dalek::ristretto::RistrettoPoint;
22
use group::Group;
3-
use rand::rngs::OsRng;
3+
use rand::{rngs::OsRng, thread_rng};
44

55
use super::test_relations::*;
66
use crate::composition::{ComposedRelation, ComposedWitness};
@@ -20,7 +20,7 @@ fn test_composition_example() {
2020
let domain_sep = b"hello world";
2121

2222
// definitions of the underlying protocols
23-
let mut rng = OsRng;
23+
let mut rng = thread_rng();
2424
let (relation1, witness1) = dleq(&mut rng);
2525
let (relation2, witness2) = pedersen_commitment(&mut rng);
2626
let (relation3, witness3) = discrete_logarithm(&mut rng);
@@ -44,8 +44,8 @@ fn test_composition_example() {
4444
let nizk = instance.into_nizk(domain_sep);
4545

4646
// Batchable and compact proofs
47-
let proof_batchable_bytes = nizk.prove_batchable(&witness, &mut OsRng).unwrap();
48-
let proof_compact_bytes = nizk.prove_compact(&witness, &mut OsRng).unwrap();
47+
let proof_batchable_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();
48+
let proof_compact_bytes = nizk.prove_compact(&witness, &mut rng).unwrap();
4949
// Verify proofs
5050
assert!(nizk.verify_batchable(&proof_batchable_bytes).is_ok());
5151
assert!(nizk.verify_compact(&proof_compact_bytes).is_ok());
@@ -57,7 +57,7 @@ fn test_or_one_true() {
5757
// Test composition of a basic OR protocol, with one of the two witnesses being valid.
5858

5959
// definitions of the underlying protocols
60-
let mut rng = OsRng;
60+
let mut rng = rand::thread_rng();
6161
let (relation1, witness1) = dleq::<G, _>(&mut rng);
6262
let (relation2, witness2) = dleq::<G, _>(&mut rng);
6363

@@ -78,8 +78,8 @@ fn test_or_one_true() {
7878

7979
for witness in [witness_or_1, witness_or_2] {
8080
// Batchable and compact proofs
81-
let proof_batchable_bytes = nizk.prove_batchable(&witness, &mut OsRng).unwrap();
82-
let proof_compact_bytes = nizk.prove_compact(&witness, &mut OsRng).unwrap();
81+
let proof_batchable_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();
82+
let proof_compact_bytes = nizk.prove_compact(&witness, &mut rng).unwrap();
8383
// Verify proofs
8484
assert!(nizk.verify_batchable(&proof_batchable_bytes).is_ok());
8585
assert!(nizk.verify_compact(&proof_compact_bytes).is_ok());
@@ -92,18 +92,18 @@ fn test_or_both_true() {
9292
// Test composition of a basic OR protocol, with both of the two witnesses being valid.
9393

9494
// definitions of the underlying protocols
95-
let mut rng = OsRng;
95+
let mut rng = rand::thread_rng();
9696
let (relation1, witness1) = dleq::<G, _>(&mut rng);
9797
let (relation2, witness2) = dleq::<G, _>(&mut rng);
9898

9999
let or_protocol = ComposedRelation::or([relation1, relation2]);
100100

101101
let witness = ComposedWitness::or([witness1, witness2]);
102-
let nizk = or_protocol.into_nizk(b"test_or_one_true");
102+
let nizk = or_protocol.into_nizk(b"test_or_both_true");
103103

104104
// Batchable and compact proofs
105-
let proof_batchable_bytes = nizk.prove_batchable(&witness, &mut OsRng).unwrap();
106-
let proof_compact_bytes = nizk.prove_compact(&witness, &mut OsRng).unwrap();
105+
let proof_batchable_bytes = nizk.prove_batchable(&witness, &mut rng).unwrap();
106+
let proof_compact_bytes = nizk.prove_compact(&witness, &mut rng).unwrap();
107107
// Verify proofs
108108
assert!(nizk.verify_batchable(&proof_batchable_bytes).is_ok());
109109
assert!(nizk.verify_compact(&proof_compact_bytes).is_ok());

0 commit comments

Comments
 (0)