Skip to content

Commit

Permalink
use fold to sum private shares since we don't impl Sum for Scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
xoloki committed Nov 25, 2024
1 parent 42e7014 commit a535269
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ impl Party {
return Err(DkgError::BadPrivateShares(bad_shares));
}

for (_i, s) in private_shares.iter() {
self.private_key += s;
}
self.private_key = private_shares.values().fold(Scalar::zero(), |a, s| a + s);
self.public_key = self.private_key * G;

Ok(())
Expand Down
6 changes: 2 additions & 4 deletions src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,8 @@ impl Party {
for key_id in &self.key_ids {
self.private_keys.insert(*key_id, Scalar::zero());
if let Some(shares) = private_shares.get(key_id) {
for (_sender, s) in shares {
self.private_keys
.insert(*key_id, self.private_keys[key_id] + s);
}
let secret = shares.values().fold(Scalar::zero(), |acc, s| acc + s);
self.private_keys.insert(*key_id, secret);
} else {
warn!(
"no private shares for key_id {}, even though we checked for it above",
Expand Down

0 comments on commit a535269

Please sign in to comment.