Skip to content

Commit 0f127fe

Browse files
committed
Fix clippy warnings
1 parent cc694ce commit 0f127fe

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

src/toolbox/sigma/fiat_shamir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ where
8080
}
8181

8282
/// Verify a non-interactive serialized proof and returns a Result: `Ok(())` if the proof verifies successfully, `Err(())` otherwise.
83-
pub fn verify(&mut self, proof: &Vec<u8>) -> Result<(), ()> {
83+
pub fn verify(&mut self, proof: &[u8]) -> Result<(), ()> {
8484
self.hash_state = C::new(&self.domain_sep);
8585

8686
let (commitment, response) = self.sigmap.deserialize_batchable(proof).unwrap();

src/toolbox/sigma/group_morphism.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ pub struct Morphism<G: Group> {
3434
fn msm_pr<G: Group>(scalars: &[G::Scalar], bases: &[G]) -> G {
3535
let mut acc = G::identity();
3636
for (s, p) in scalars.iter().zip(bases.iter()) {
37-
acc = acc + (*p * s.clone());
37+
acc += *p * s;
3838
}
3939
acc
4040
}
4141

42+
impl<G: Group> Default for Morphism<G> {
43+
fn default() -> Self {
44+
Self::new()
45+
}
46+
}
47+
4248
impl<G: Group> Morphism<G> {
4349
/// Creates a new empty Morphism.
4450
pub fn new() -> Self {
@@ -65,8 +71,8 @@ impl<G: Group> Morphism<G> {
6571
/// Computes all linear combinations using the provided scalars and returns their group outputs.
6672
pub fn evaluate(&self, scalars: &[<G as Group>::Scalar]) -> Vec<G> {
6773
self.linear_combination.iter().map(|lc| {
68-
let coefficients: Vec<_> = lc.scalar_indices.iter().map(|&i| scalars[i].clone()).collect();
69-
let elements: Vec<_> = lc.element_indices.iter().map(|&i| self.group_elements[i].clone()).collect();
74+
let coefficients: Vec<_> = lc.scalar_indices.iter().map(|&i| scalars[i]).collect();
75+
let elements: Vec<_> = lc.element_indices.iter().map(|&i| self.group_elements[i]).collect();
7076
msm_pr(&coefficients, &elements)
7177
}).collect()
7278
}
@@ -87,6 +93,15 @@ where
8793
pub image: Vec<usize>,
8894
}
8995

96+
impl<G> Default for GroupMorphismPreimage<G>
97+
where
98+
G: Group + GroupEncoding,
99+
{
100+
fn default() -> Self {
101+
Self::new()
102+
}
103+
}
104+
90105
impl<G> GroupMorphismPreimage<G>
91106
where
92107
G: Group + GroupEncoding,
@@ -143,15 +158,15 @@ where
143158
/// Set the value of group elements at a given index, inside the list of allocated group elements.
144159
pub fn set_elements(&mut self, elements: &[(usize, G)]) {
145160
for &(i, ref elt) in elements {
146-
self.morphism.group_elements[i] = elt.clone();
161+
self.morphism.group_elements[i] = *elt;
147162
}
148163
}
149164

150165
/// Return the group elements corresponding to the image indices.
151166
pub fn image(&self) -> Vec<G> {
152167
let mut result = Vec::new();
153168
for i in &self.image {
154-
result.push(self.morphism.group_elements[*i].clone());
169+
result.push(self.morphism.group_elements[*i]);
155170
}
156171
result
157172
}

src/toolbox/sigma/schnorr_proof.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ where
7171
challenge: &Self::Challenge,
7272
response: &Self::Response,
7373
) -> Result<(), ()> {
74-
let lhs = self.morphismp.morphism.evaluate(&response);
74+
let lhs = self.morphismp.morphism.evaluate(response);
75+
7576
let mut rhs = Vec::new();
76-
for i in 0..self.morphismp.morphism.num_scalars {
77-
rhs.push(commitment[i] + self.morphismp.morphism.group_elements[self.morphismp.image[i]] * *challenge);
77+
for (i, g) in commitment.iter().enumerate().take(self.morphismp.morphism.num_scalars) {
78+
rhs.push(*g + self.morphismp.morphism.group_elements[self.morphismp.image[i]] * *challenge);
7879
}
80+
7981
match lhs == rhs {
8082
true => Ok(()),
8183
false => Err(()),
@@ -90,14 +92,16 @@ where
9092
response: &Self::Response
9193
) -> Vec<u8> {
9294
let mut bytes = Vec::new();
93-
let scalar_nb = self.morphismp.morphism.num_scalars.clone();
95+
let scalar_nb = self.morphismp.morphism.num_scalars;
96+
9497
// Serialize commitments
95-
for i in 0..scalar_nb {
96-
bytes.extend_from_slice(commitment[i].to_bytes().as_ref());
98+
for commit in commitment.iter().take(scalar_nb) {
99+
bytes.extend_from_slice(commit.to_bytes().as_ref());
97100
}
101+
98102
// Serialize responses
99-
for i in 0..scalar_nb {
100-
bytes.extend_from_slice(response[i].to_repr().as_ref());
103+
for response in response.iter().take(scalar_nb) {
104+
bytes.extend_from_slice(response.to_repr().as_ref());
101105
}
102106
bytes
103107
}

src/toolbox/sigma/trait.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ pub trait SigmaProtocol {
9494
/// Types implementing `SigmaProtocolSimulator` must define:
9595
/// - `simulate_proof`
9696
/// - `simulate_transcription`
97-
pub trait SigmaProtocolSimulator
98-
where Self: SigmaProtocol {
97+
pub trait SigmaProtocolSimulator: SigmaProtocol {
9998

10099
/// Simulates a protocol transcript given a challenge.
101100
///

0 commit comments

Comments
 (0)