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
1 change: 1 addition & 0 deletions synedrion/src/cggmp21/aux_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ impl<P: SchemeParams, I: PartyId + Serialize> Round<I> for Round3<P, I> {
}
}

#[allow(clippy::indexing_slicing)]
dvdplm marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(test)]
mod tests {
use alloc::collections::BTreeSet;
Expand Down
29 changes: 23 additions & 6 deletions synedrion/src/cggmp21/entities.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use alloc::{
boxed::Box,
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 @@ -126,25 +128,40 @@

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 144 in synedrion/src/cggmp21/entities.rs

View check run for this annotation

Codecov / codecov/patch

synedrion/src/cggmp21/entities.rs#L131-L144

Added lines #L131 - L144 were not covered by tests

let secret_share = SecretBox::new(Box::new(
self.secret_share.expose_secret() + change.secret_share_change.expose_secret(),
));
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 156 in synedrion/src/cggmp21/entities.rs

View check run for this annotation

Codecov / codecov/patch

synedrion/src/cggmp21/entities.rs#L152-L156

Added lines #L152 - L156 were not covered by tests
.collect();

Self {
Ok(Self {

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#L159

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

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

View check run for this annotation

Codecov / codecov/patch

synedrion/src/cggmp21/entities.rs#L164

Added line #L164 was not covered by tests
}

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