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
36 changes: 29 additions & 7 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,43 @@

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]))
.collect();
.map(|(id, public_share)| {
Ok((
id.clone(),
*public_share
+ *change
.public_share_changes
.get(id)
.ok_or_else(|| LocalError::new("id={id:?} is missing in public_share_changes"))?,

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#L149-L156

Added lines #L149 - L156 were not covered by tests
))
})
.collect::<Result<_, LocalError>>()?;

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

View check run for this annotation

Codecov / codecov/patch

synedrion/src/cggmp21/entities.rs#L158-L159

Added lines #L158 - L159 were not covered by tests

Self {
Ok(Self {

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
owner: self.owner,
secret_share,
public_shares,
phantom: PhantomData,
}
})

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

View check run for this annotation

Codecov / codecov/patch

synedrion/src/cggmp21/entities.rs#L166

Added line #L166 was not covered by tests
}

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