Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use slice indexing #164

Merged
merged 11 commits into from
Dec 14, 2024
Merged
29 changes: 23 additions & 6 deletions synedrion/src/cggmp21/entities.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use alloc::{
collections::{BTreeMap, BTreeSet},
format,
vec::Vec,
};
use core::{fmt::Debug, marker::PhantomData};
use manul::session::LocalError;
dvdplm marked this conversation as resolved.
Show resolved Hide resolved

use k256::ecdsa::VerifyingKey;
use rand_core::CryptoRngCore;
Expand Down Expand Up @@ -125,23 +127,38 @@

impl<P: SchemeParams, I: Clone + Ord + PartialEq + Debug> KeyShare<P, I> {
/// Updates a key share with a change obtained from KeyRefresh protocol.
pub fn update(self, change: KeyShareChange<P, I>) -> Self {
// TODO (#68): check that party_idx is the same for both, and the number of parties is the same
assert_eq!(self.owner, change.owner);
pub fn update(self, change: KeyShareChange<P, I>) -> Result<Self, LocalError> {
if self.owner != change.owner {
return Err(LocalError::new(format!(
"Owning party mismatch. self.owner={:?}, change.owner={:?}",
self.owner, change.owner
)));
}
if self.public_shares.len() != change.public_share_changes.len() {
return Err(LocalError::new(format!(
"Inconsistent number of public key shares in updated share set (expected {}, was {})",
self.public_shares.len(),
change.public_share_changes.len()
)));
}

Check warning on line 143 in synedrion/src/cggmp21/entities.rs

View check run for this annotation

Codecov / codecov/patch

synedrion/src/cggmp21/entities.rs#L130-L143

Added lines #L130 - L143 were not covered by tests

let secret_share = self.secret_share + change.secret_share_change;
let public_shares = self
.public_shares
.iter()
.map(|(id, public_share)| (id.clone(), *public_share + change.public_share_changes[id]))
.zip(change.public_share_changes)
dvdplm marked this conversation as resolved.
Show resolved Hide resolved
// TODO(dp): this should fail, I'm pretty sure, but doesn't (no test)
// let obviously_wrong_value = change.public_share_changes.first_key_value().unwrap().0.clone();
// .map(|(pub_share, changed_pub_share)| (obviously_wrong_value.clone(), pub_share.1 + &changed_pub_share.1))
.map(|(pub_share, changed_pub_share)| (changed_pub_share.0, *pub_share.1 + changed_pub_share.1))

Check warning on line 153 in synedrion/src/cggmp21/entities.rs

View check run for this annotation

Codecov / codecov/patch

synedrion/src/cggmp21/entities.rs#L149-L153

Added lines #L149 - L153 were not covered by tests
.collect();

Self {
Ok(Self {

Check warning on line 156 in synedrion/src/cggmp21/entities.rs

View check run for this annotation

Codecov / codecov/patch

synedrion/src/cggmp21/entities.rs#L156

Added line #L156 was not covered by tests
owner: self.owner,
secret_share,
public_shares,
phantom: PhantomData,
}
})

Check warning on line 161 in synedrion/src/cggmp21/entities.rs

View check run for this annotation

Codecov / codecov/patch

synedrion/src/cggmp21/entities.rs#L161

Added line #L161 was not covered by tests
}

/// Creates a set of random self-consistent key shares
Expand Down
Loading
Loading