Skip to content

Commit 9dff1ee

Browse files
committed
avoid collect in reconstruction
1 parent da6ae58 commit 9dff1ee

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

timeboost-crypto/src/feldman.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,27 +153,26 @@ impl<C: CurveGroup> VerifiableSecretSharing for FeldmanVss<C> {
153153

154154
fn reconstruct(
155155
pp: &Self::PublicParam,
156-
shares: impl Iterator<Item = (usize, Self::SecretShare)>,
156+
shares: impl ExactSizeIterator<Item = (usize, Self::SecretShare)> + Clone,
157157
) -> Result<Self::Secret, VssError> {
158-
let shares = shares.collect::<Vec<_>>();
159158
let n = pp.n.get();
160159
let t = pp.t.get();
161160
// input validation
162161
if shares.len() != t {
163162
return Err(VssError::MismatchedSharesCount(t, shares.len()));
164163
}
165-
for (idx, _) in shares.iter() {
166-
if *idx >= n {
167-
return Err(VssError::IndexOutOfBound(n - 1, *idx));
164+
for (idx, _) in shares.clone() {
165+
if idx >= n {
166+
return Err(VssError::IndexOutOfBound(n - 1, idx));
168167
}
169168
}
170169

171170
// Lagrange interpolate to get back the secret
172171
let eval_points: Vec<_> = shares
173-
.iter()
174-
.map(|&(idx, _)| C::ScalarField::from(idx as u64 + 1))
172+
.clone()
173+
.map(|(idx, _)| C::ScalarField::from(idx as u64 + 1))
175174
.collect();
176-
let evals: Vec<_> = shares.iter().map(|&(_, share)| share).collect();
175+
let evals: Vec<_> = shares.map(|(_, share)| share).collect();
177176
interpolate::<C>(&eval_points, &evals)
178177
.map_err(|e| VssError::FailedReconstruction(e.to_string()))
179178
}

timeboost-crypto/src/traits/dkg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub trait VerifiableSecretSharing {
5151
/// Returns `Ok(secret)` if reconstruction succeeds, or an appropriate `VssError` otherwise.
5252
fn reconstruct(
5353
pp: &Self::PublicParam,
54-
shares: impl Iterator<Item = (usize, Self::SecretShare)>,
54+
shares: impl ExactSizeIterator<Item = (usize, Self::SecretShare)> + Clone,
5555
) -> Result<Self::Secret, VssError>;
5656
}
5757

0 commit comments

Comments
 (0)