Skip to content

Commit 4715c52

Browse files
committed
improve combine() api to accept sized iter
1 parent 9dff1ee commit 4715c52

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

timeboost-crypto/src/feldman.rs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -246,19 +246,17 @@ impl<C: CurveGroup> KeyResharing<Self> for FeldmanVss<C> {
246246
fn combine(
247247
old_pp: &FeldmanVssPublicParam,
248248
new_pp: &FeldmanVssPublicParam,
249-
send_node_indices: &[usize],
250-
row_commitments: &[FeldmanCommitment<C>],
251249
recv_node_idx: usize,
252-
recv_reshares: &[C::ScalarField],
250+
reshares: impl ExactSizeIterator<Item = (usize, C::ScalarField, FeldmanCommitment<C>)> + Clone,
253251
) -> Result<(C::ScalarField, FeldmanCommitment<C>), VssError> {
254252
// input validation
255253
let n = old_pp.n.get();
256-
if send_node_indices.is_empty() || row_commitments.is_empty() || recv_reshares.is_empty() {
254+
if reshares.len() == 0 {
257255
return Err(VssError::EmptyReshare);
258256
}
259-
for idx in send_node_indices.iter() {
260-
if *idx >= n {
261-
return Err(VssError::IndexOutOfBound(n - 1, *idx));
257+
for (idx, _, _) in reshares.clone() {
258+
if idx >= n {
259+
return Err(VssError::IndexOutOfBound(n - 1, idx));
262260
}
263261
}
264262

@@ -267,24 +265,23 @@ impl<C: CurveGroup> KeyResharing<Self> for FeldmanVss<C> {
267265
if recv_node_idx >= new_n {
268266
return Err(VssError::IndexOutOfBound(new_n - 1, recv_node_idx));
269267
}
270-
if row_commitments.iter().any(|cm| cm.len() != new_t) {
271-
return Err(VssError::InvalidCommitment);
272-
}
273-
274-
let subset_size = recv_reshares.len();
275-
if send_node_indices.len() != subset_size || row_commitments.len() != subset_size {
276-
return Err(VssError::MismatchedInputLength);
268+
for (_, _, row_commitment) in reshares.clone() {
269+
if row_commitment.len() != new_t {
270+
return Err(VssError::InvalidCommitment);
271+
}
277272
}
278273

279274
// interpolate reshares to get new secret share
280-
let eval_points: Vec<_> = send_node_indices
281-
.iter()
282-
.map(|&idx| C::ScalarField::from(idx as u64 + 1))
275+
let eval_points: Vec<_> = reshares
276+
.clone()
277+
.map(|(idx, _, _)| C::ScalarField::from(idx as u64 + 1))
283278
.collect();
284-
let new_secret = interpolate::<C>(&eval_points, recv_reshares)
279+
let recv_reshares: Vec<_> = reshares.clone().map(|(_, share, _)| share).collect();
280+
let new_secret = interpolate::<C>(&eval_points, &recv_reshares)
285281
.map_err(|e| VssError::FailedCombine(e.to_string()))?;
286282

287283
// interpolate in the exponent to get new Feldman commitment
284+
let row_commitments: Vec<_> = reshares.map(|(_, _, commitment)| commitment).collect();
288285
let new_commitment = (0..new_t)
289286
.into_par_iter()
290287
.map(|j| {
@@ -455,15 +452,10 @@ mod tests {
455452
let selected_row_commitments: Vec<FeldmanCommitment<_>> =
456453
(0..old_t).map(|i| row_commitments[i].clone()).collect();
457454

458-
let (new_secret_share, new_commitment) = FeldmanVss::<G1Projective>::combine(
459-
&old_pp,
460-
&new_pp,
461-
&(0..old_t).collect::<Vec<_>>(),
462-
&selected_row_commitments,
463-
j,
464-
&recv_reshares,
465-
)
466-
.unwrap();
455+
let reshares_iter =
456+
(0..old_t).map(|i| (i, recv_reshares[i], selected_row_commitments[i].clone()));
457+
let (new_secret_share, new_commitment) =
458+
FeldmanVss::<G1Projective>::combine(&old_pp, &new_pp, j, reshares_iter).unwrap();
467459

468460
new_shares.push(new_secret_share);
469461
new_commitments.push(new_commitment);

timeboost-crypto/src/traits/dkg.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@ pub trait KeyResharing<VSS: VerifiableSecretSharing> {
9494
fn combine(
9595
old_pp: &VSS::PublicParam,
9696
new_pp: &VSS::PublicParam,
97-
send_node_indices: &[usize],
98-
row_commitments: &[VSS::Commitment],
9997
recv_node_idx: usize,
100-
recv_reshares: &[VSS::SecretShare],
98+
reshares: impl ExactSizeIterator<Item = (usize, VSS::SecretShare, VSS::Commitment)> + Clone,
10199
) -> Result<(VSS::Secret, VSS::Commitment), VssError>;
102100
}
103101

0 commit comments

Comments
 (0)