Skip to content

Commit

Permalink
KeyResharing converted
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Nov 9, 2024
1 parent 0355294 commit 5444f65
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 231 deletions.
2 changes: 1 addition & 1 deletion synedrion/src/cggmp21/protocols/interactive_signing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::marker::PhantomData;

use manul::{
combinators::{Chained, ChainedEntryPoint, ChainedProtocol},
combinators::chain::{Chained, ChainedEntryPoint, ChainedProtocol},
protocol::PartyId,
};

Expand Down
2 changes: 1 addition & 1 deletion synedrion/src/cggmp21/protocols/signing_malicious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::marker::PhantomData;

use k256::ecdsa::{signature::hazmat::PrehashVerifier, VerifyingKey};
use manul::{
combinators::{Misbehaving, MisbehavingEntryPoint, MisbehavingInputs},
combinators::misbehave::{Misbehaving, MisbehavingEntryPoint, MisbehavingInputs},
protocol::{
Artifact, BoxedRound, Deserializer, DirectMessage, EntryPoint, LocalError, NormalBroadcast,
PartyId, ProtocolMessagePart, RoundId, Serializer,
Expand Down
16 changes: 9 additions & 7 deletions synedrion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,22 @@ mod paillier;
//pub mod sessions;
mod tools;
mod uint;
//mod www02;
mod www02;

// Some re-exports to avoid the need for version-matching
pub use bip32;
pub use k256;
pub use k256::ecdsa;
pub use signature;

/*pub use cggmp21::{
AuxGenError, AuxGenResult, AuxInfo, InteractiveSigningError, InteractiveSigningProof,
InteractiveSigningResult, KeyGenError, KeyGenProof, KeyGenResult, KeyInitError, KeyInitResult,
KeyRefreshResult, KeyShare, KeyShareChange, PresigningError, PresigningProof, PresigningResult,
ProductionParams, SchemeParams, SigningProof, SigningResult, TestParams,
};*/
pub use cggmp21::{
SchemeParams,
TestParams,
//AuxGenError, AuxGenResult, AuxInfo, InteractiveSigningError, InteractiveSigningProof,
//InteractiveSigningResult, KeyGenError, KeyGenProof, KeyGenResult, KeyInitError, KeyInitResult,
//KeyRefreshResult, KeyShare, KeyShareChange, PresigningError, PresigningProof, PresigningResult,
//ProductionParams, SigningProof, SigningResult,
};
//pub use constructors::{
// make_aux_gen_session, make_interactive_signing_session, make_key_gen_session,
// make_key_init_session, make_key_refresh_session, make_key_resharing_session, PrehashedMessage,
Expand Down
11 changes: 8 additions & 3 deletions synedrion/src/tools/sss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ use core::ops::{Add, Mul};

use rand_core::CryptoRngCore;
use serde::{Deserialize, Serialize};
use zeroize::ZeroizeOnDrop;

use crate::curve::{Point, Scalar};
use crate::{
curve::{Point, Scalar},
tools::HideDebug,
};

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct ShareId(Scalar);
Expand Down Expand Up @@ -37,7 +41,8 @@ where
res
}

pub(crate) struct Polynomial(Vec<Scalar>);
#[derive(Debug, ZeroizeOnDrop)]
pub(crate) struct Polynomial(HideDebug<Vec<Scalar>>);

impl Polynomial {
pub fn random(rng: &mut impl CryptoRngCore, coeff0: &Scalar, degree: usize) -> Self {
Expand All @@ -46,7 +51,7 @@ impl Polynomial {
for _ in 1..degree {
coeffs.push(Scalar::random_nonzero(rng));
}
Self(coeffs)
Self(coeffs.into())
}

pub fn evaluate(&self, x: &ShareId) -> Scalar {
Expand Down
2 changes: 1 addition & 1 deletion synedrion/src/www02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ mod entities;
pub(crate) mod key_resharing;

pub use entities::{DeriveChildKey, ThresholdKeyShare};
pub use key_resharing::{KeyResharingInputs, KeyResharingResult, NewHolder, OldHolder};
pub use key_resharing::{KeyResharingInputs, KeyResharingProtocol, NewHolder, OldHolder};
36 changes: 24 additions & 12 deletions synedrion/src/www02/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,32 +291,44 @@ mod tests {
use alloc::collections::BTreeSet;

use k256::ecdsa::SigningKey;
use manul::{
session::signature::Keypair,
testing::{TestSigner, TestVerifier},
};
use rand_core::OsRng;
use secrecy::ExposeSecret;

use super::ThresholdKeyShare;
use crate::cggmp21::TestParams;
use crate::curve::Scalar;
use crate::rounds::test_utils::Id;

#[test]
fn threshold_key_share_centralized() {
let sk = SigningKey::random(&mut OsRng);

let ids = BTreeSet::from([Id(0), Id(1), Id(2)]);

let shares =
ThresholdKeyShare::<TestParams, Id>::new_centralized(&mut OsRng, &ids, 2, Some(&sk));
let signers = (0..3).map(TestSigner::new).collect::<Vec<_>>();
let ids = signers
.iter()
.map(|signer| signer.verifying_key())
.collect::<Vec<_>>();
let ids_set = ids.iter().cloned().collect::<BTreeSet<_>>();

let shares = ThresholdKeyShare::<TestParams, TestVerifier>::new_centralized(
&mut OsRng,
&ids_set,
2,
Some(&sk),
);

assert_eq!(&shares[&Id(0)].verifying_key(), sk.verifying_key());
assert_eq!(&shares[&Id(1)].verifying_key(), sk.verifying_key());
assert_eq!(&shares[&Id(2)].verifying_key(), sk.verifying_key());
assert_eq!(&shares[&ids[0]].verifying_key(), sk.verifying_key());
assert_eq!(&shares[&ids[1]].verifying_key(), sk.verifying_key());
assert_eq!(&shares[&ids[2]].verifying_key(), sk.verifying_key());

assert_eq!(&shares[&Id(0)].verifying_key(), sk.verifying_key());
assert_eq!(&shares[&ids[0]].verifying_key(), sk.verifying_key());

let ids_subset = BTreeSet::from([Id(2), Id(0)]);
let nt_share0 = shares[&Id(0)].to_key_share(&ids_subset);
let nt_share1 = shares[&Id(2)].to_key_share(&ids_subset);
let ids_subset = BTreeSet::from([ids[2], ids[0]]);
let nt_share0 = shares[&ids[0]].to_key_share(&ids_subset);
let nt_share1 = shares[&ids[2]].to_key_share(&ids_subset);

assert_eq!(
nt_share0.secret_share.expose_secret() + nt_share1.secret_share.expose_secret(),
Expand Down
Loading

0 comments on commit 5444f65

Please sign in to comment.