Skip to content

Commit 28f4e37

Browse files
committed
Separate key-share and cggmp21-keygen libs
1 parent 100c0b5 commit 28f4e37

27 files changed

+359
-1103
lines changed

.github/workflows/rust.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ jobs:
5858
with:
5959
cache-on-failure: "true"
6060
- name: Run clippy
61-
run: cargo clippy --all --lib --exclude cggmp21-tests -- --no-deps -D clippy::all -D clippy::unwrap_used -D clippy::expect_used
61+
run: cargo clippy --all --all-features --lib --exclude cggmp21-tests -- --no-deps -D clippy::all -D clippy::unwrap_used -D clippy::expect_used
6262
- name: Run clippy tests
63-
run: cargo clippy --tests --lib -- -D clippy::all
63+
run: cargo clippy --tests --all-features --lib -- -D clippy::all
6464
bench:
6565
runs-on: ubuntu-latest
6666
permissions:

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ let aux_info = cggmp21::aux_info_gen(eid, i, n, pregenerated_primes)
110110

111111
After keygen and aux info gen are done, you can make a “complete” key share that can be used for signing:
112112
```rust
113-
let key_share = cggmp21::KeyShare::make(incomplete_key_share, aux_info)?;
113+
let key_share = cggmp21::KeyShare::from_parts((incomplete_key_share, aux_info))?;
114114
```
115115

116116
### Signing

cggmp21-keygen/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ keywords = ["mpc", "dkg", "threshold-signatures", "tss", "ecdsa", "t-ecdsa"]
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

1313
[dependencies]
14-
key-share = { path = "../key-share" }
14+
key-share = { path = "../key-share", features = ["serde"] }
1515
slip-10 = { git = "https://github.com/dfns/slip-10", branch = "m", optional = true }
1616

1717
generic-ec = { version = "0.1", features = ["serde", "udigest"] }

cggmp21-keygen/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Threshold and non-threshold CGGMP21 DKG
2-
#![allow(non_snake_case)]
2+
#![allow(non_snake_case, clippy::too_many_arguments)]
33

44
pub mod progress;
55
pub mod security_level;
@@ -26,7 +26,7 @@ pub use key_share;
2626
use crate::progress::Tracer;
2727
use crate::{
2828
errors::IoError,
29-
key_share::{CoreKeyShare, InvalidKeyShare},
29+
key_share::{CoreKeyShare, InvalidCoreShare},
3030
security_level::SecurityLevel,
3131
};
3232

@@ -301,7 +301,7 @@ enum KeygenAborted {
301301
#[derive(Debug, Error)]
302302
enum Bug {
303303
#[error("resulting key share is not valid")]
304-
InvalidKeyShare(#[source] InvalidKeyShare),
304+
InvalidKeyShare(#[source] InvalidCoreShare),
305305
#[error("unexpected zero value")]
306306
NonZeroScalar,
307307
#[cfg(feature = "hd-wallets")]

cggmp21-keygen/src/progress.rs

-26
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,6 @@
44
//! For instance, it can be implemented to report progress to the end user.
55
//!
66
//! Out of box, there's [`PerfProfiler`] which can be used to bechmark a protocol.
7-
//!
8-
//! ## Usage example
9-
//! Provide tracer to the protocol builder and obtain results after protocol is completed:
10-
//!
11-
//! ```rust,no_run
12-
//! # use cggmp21::key_share::KeyShare;
13-
//! # type E = cggmp21::supported_curves::Secp256r1;
14-
//! # fn load_key_share() -> Result<KeyShare<E>, std::convert::Infallible> { unimplemented!() }
15-
//! # async fn connect_to_network<M>() -> Result<(cggmp21::ExecutionId<'static>, u16, round_based::MpcParty<M, round_based::simulation::MockedDelivery<M>>), std::convert::Infallible> { unimplemented!() }
16-
//! # async fn doc() -> Result<(), Box<dyn std::error::Error>> {
17-
//! # let participants = &[1, 2, 3];
18-
//! use cggmp21::progress::PerfProfiler;
19-
//!
20-
//! let mut tracer = PerfProfiler::new();
21-
//!
22-
//! let (eid, i, party) = connect_to_network().await?;
23-
//! let key_share = load_key_share()?;
24-
//! cggmp21::signing(eid, i, participants, &key_share)
25-
//! .set_progress_tracer(&mut tracer)
26-
//! .generate_presignature(&mut rand::rngs::OsRng, party)
27-
//! .await?;
28-
//!
29-
//! let perf_report = tracer.get_report()?;
30-
//! println!("{perf_report}");
31-
//! # Ok(()) }
32-
//!```
337
348
use std::fmt;
359
use std::time::{Duration, Instant};

cggmp21/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ readme = "../README.md"
1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[dependencies]
15+
cggmp21-keygen = { path = "../cggmp21-keygen" }
16+
1517
generic-ec = { version = "0.1", features = ["serde", "udigest"] }
1618
generic-ec-zkp = { version = "0.1", features = ["serde", "udigest"] }
1719
round-based = { version = "0.2", features = ["derive"] }
@@ -48,7 +50,7 @@ all-curves = ["curve-secp256k1", "curve-secp256r1", "curve-stark"]
4850
curve-secp256k1 = ["generic-ec/curve-secp256k1"]
4951
curve-secp256r1 = ["generic-ec/curve-secp256r1"]
5052
curve-stark = ["generic-ec/curve-stark"]
51-
hd-wallets = ["dep:slip-10"]
53+
hd-wallets = ["dep:slip-10", "cggmp21-keygen/hd-wallets"]
5254
spof = []
5355

5456
[package.metadata.docs.rs]

cggmp21/src/key_refresh.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub struct PregeneratedPrimes<L = crate::default_choice::SecurityLevel> {
5252
impl<L: SecurityLevel> PregeneratedPrimes<L> {
5353
/// Constructs pregenerated primes from two big numbers
5454
///
55-
/// Returns `None` if big numbers are smaller than 4 * [L::SECURITY_BITS](SecurityLevel::SECURITY_BITS)
55+
/// Returns `None` if big numbers are smaller than 4 * [L::SECURITY_BITS](crate::security_level::KeygenSecurityLevel::SECURITY_BITS)
5656
///
5757
/// Function doesn't validate that provided numbers are primes. If they're not,
5858
/// key refresh protocol should fail with some ZK proof error.

cggmp21/src/key_refresh/aux_only.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
1515

1616
use crate::{
1717
errors::IoError,
18-
key_share::{AuxInfo, DirtyAuxInfo, PartyAux},
18+
key_share::{AuxInfo, DirtyAuxInfo, PartyAux, Validate},
1919
progress::Tracer,
2020
security_level::SecurityLevel,
2121
utils,
@@ -470,14 +470,12 @@ where
470470
})
471471
.collect::<Vec<_>>();
472472
party_auxes[usize::from(i)].crt = crt;
473-
let mut aux: AuxInfo<L> = DirtyAuxInfo {
473+
let mut aux = DirtyAuxInfo {
474474
p,
475475
q,
476476
parties: party_auxes,
477477
security_level: std::marker::PhantomData,
478-
}
479-
.try_into()
480-
.map_err(Bug::InvalidShareGenerated)?;
478+
};
481479

482480
if compute_multiexp_table {
483481
tracer.stage("Precompute multiexp tables");
@@ -486,6 +484,10 @@ where
486484
.map_err(Bug::BuildMultiexpTables)?;
487485
}
488486

487+
let aux = aux
488+
.validate()
489+
.map_err(|err| Bug::InvalidShareGenerated(err.into_error()))?;
490+
489491
tracer.protocol_ends();
490492
Ok(aux)
491493
}

cggmp21/src/key_refresh/non_threshold.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use serde::{Deserialize, Serialize};
2020
use super::{Bug, KeyRefreshError, PregeneratedPrimes, ProtocolAborted};
2121
use crate::{
2222
errors::IoError,
23-
key_share::{AuxInfo, DirtyAuxInfo, DirtyIncompleteKeyShare, KeyShare, PartyAux},
23+
key_share::{DirtyAuxInfo, DirtyIncompleteKeyShare, KeyShare, PartyAux, Validate},
2424
progress::Tracer,
2525
security_level::SecurityLevel,
2626
utils,
@@ -661,8 +661,8 @@ where
661661
x: SecretScalar::new(&mut x_star),
662662
..old_core_share
663663
}
664-
.try_into()
665-
.map_err(Bug::InvalidShareGenerated)?;
664+
.validate()
665+
.map_err(|err| Bug::InvalidShareGenerated(err.into_error().into()))?;
666666
tracer.stage("Assemble auxiliary info");
667667
let mut party_auxes = decommitments
668668
.iter_including_me(&decommitment)
@@ -675,14 +675,12 @@ where
675675
})
676676
.collect::<Vec<_>>();
677677
party_auxes[usize::from(i)].crt = crt;
678-
let mut aux: AuxInfo<L> = DirtyAuxInfo {
678+
let mut aux = DirtyAuxInfo {
679679
p,
680680
q,
681681
parties: party_auxes,
682682
security_level: std::marker::PhantomData,
683-
}
684-
.try_into()
685-
.map_err(Bug::InvalidShareGenerated)?;
683+
};
686684

687685
if build_multiexp_tables {
688686
tracer.stage("Build multiexp tables");
@@ -691,8 +689,13 @@ where
691689
.map_err(Bug::BuildMultiexpTables)?;
692690
}
693691

692+
let aux = aux
693+
.validate()
694+
.map_err(|err| Bug::InvalidShareGenerated(err.into_error()))?;
695+
694696
tracer.stage("Assemble key share");
695-
let key_share = KeyShare::make(new_core_share, aux).map_err(Bug::InvalidShareGenerated)?;
697+
let key_share = KeyShare::from_parts((new_core_share, aux))
698+
.map_err(|err| Bug::InvalidShareGenerated(err.into_error()))?;
696699

697700
tracer.protocol_ends();
698701
Ok(key_share)

0 commit comments

Comments
 (0)