@@ -302,41 +302,42 @@ impl<C: CurveGroup> KeyResharing<Self> for FeldmanVss<C> {
302
302
old_pp : & FeldmanVssPublicParam < C > ,
303
303
new_pp : & FeldmanVssPublicParam < C > ,
304
304
recv_node_idx : usize ,
305
- reshares : impl ExactSizeIterator < Item = ( usize , C :: ScalarField , FeldmanCommitment < C > ) > + Clone ,
305
+ reshares : impl Iterator < Item = ( usize , C :: ScalarField , FeldmanCommitment < C > ) > ,
306
306
) -> Result < ( C :: ScalarField , FeldmanCommitment < C > ) , VssError > {
307
- // input validation
308
307
let n = old_pp. n . get ( ) ;
309
- if reshares. len ( ) == 0 {
310
- return Err ( VssError :: EmptyReshare ) ;
311
- }
312
- for ( idx, _, _) in reshares. clone ( ) {
308
+
309
+ let mut eval_points = Vec :: new ( ) ;
310
+ let mut recv_shares = Vec :: new ( ) ;
311
+ let mut row_commitments = Vec :: new ( ) ;
312
+
313
+ for ( idx, share, commitment) in reshares {
313
314
if idx >= n {
314
315
return Err ( VssError :: IndexOutOfBound ( n - 1 , idx) ) ;
315
316
}
317
+ eval_points. push ( C :: ScalarField :: from ( idx as u64 + 1 ) ) ;
318
+ recv_shares. push ( share) ;
319
+ row_commitments. push ( commitment) ;
320
+ }
321
+
322
+ if eval_points. is_empty ( ) {
323
+ return Err ( VssError :: EmptyReshare ) ;
316
324
}
317
325
318
326
let new_n = new_pp. n . get ( ) ;
319
327
let new_t = new_pp. t . get ( ) ;
320
328
if recv_node_idx >= new_n {
321
329
return Err ( VssError :: IndexOutOfBound ( new_n - 1 , recv_node_idx) ) ;
322
330
}
323
- for ( _, _, row_commitment) in reshares. clone ( ) {
324
- if row_commitment. len ( ) != new_t {
325
- return Err ( VssError :: InvalidCommitment ) ;
326
- }
331
+
332
+ if row_commitments. iter ( ) . any ( |c| c. len ( ) != new_t) {
333
+ return Err ( VssError :: InvalidCommitment ) ;
327
334
}
328
335
329
336
// interpolate reshares to get new secret share
330
- let eval_points: Vec < _ > = reshares
331
- . clone ( )
332
- . map ( |( idx, _, _) | C :: ScalarField :: from ( idx as u64 + 1 ) )
333
- . collect ( ) ;
334
- let recv_reshares: Vec < _ > = reshares. clone ( ) . map ( |( _, share, _) | share) . collect ( ) ;
335
- let new_secret = interpolate :: < C > ( & eval_points, & recv_reshares)
337
+ let new_secret = interpolate :: < C > ( & eval_points, & recv_shares)
336
338
. map_err ( |e| VssError :: FailedCombine ( e. to_string ( ) ) ) ?;
337
339
338
340
// interpolate in the exponent to get new Feldman commitment
339
- let row_commitments: Vec < _ > = reshares. map ( |( _, _, commitment) | commitment) . collect ( ) ;
340
341
let new_commitment = ( 0 ..new_t)
341
342
. into_par_iter ( )
342
343
. map ( |j| {
@@ -346,6 +347,7 @@ impl<C: CurveGroup> KeyResharing<Self> for FeldmanVss<C> {
346
347
. map_err ( |e| VssError :: FailedCombine ( e. to_string ( ) ) )
347
348
} )
348
349
. collect :: < Result < Vec < _ > , VssError > > ( ) ?;
350
+
349
351
let new_commitment = C :: normalize_batch ( & new_commitment) ;
350
352
351
353
Ok ( ( new_secret, new_commitment. into ( ) ) )
0 commit comments