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

Update deps, improve tests #120

Merged
merged 20 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ exclude = [
]

[workspace.dependencies]
cggmp21 = { version = "0.5", path = "cggmp21" }
cggmp21-keygen = { version = "0.4", path = "cggmp21-keygen" }
key-share = { version = "0.5", path = "key-share", default-features = false }
cggmp21 = { version = "0.6", path = "cggmp21" }
cggmp21-keygen = { version = "0.5", path = "cggmp21-keygen" }
key-share = { version = "0.6", path = "key-share", default-features = false }

generic-ec = { version = "0.4.1", default-features = false }
generic-ec-zkp = { version = "0.4.1", default-features = false }
Expand Down Expand Up @@ -41,6 +41,10 @@ serde_with = { version = "2", default-features = false }
serde_json = "1"
hex = { version = "0.4", default-features = false }

hd-wallet = { version = "0.5", default-features = false }
hd-wallet = { version = "0.6", default-features = false }

generic-tests = "0.1"

[patch.crates-io.hd-wallet]
git = "https://github.com/LFDT-Lockness/hd-wallet"
branch = "dt"
5 changes: 5 additions & 0 deletions cggmp21-keygen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.5.0
* Update `hd-wallet` dep to v0.6 [#120]

[#120]: https://github.com/LFDT-Lockness/cggmp21/pull/120

## v0.4.0
* BREAKING: use `hd-wallet` crate for HD support instead of `slip-10` [#115]
* BREAKING: rename `hd-wallets` feature into `hd-wallet` [#115]
Expand Down
2 changes: 1 addition & 1 deletion cggmp21-keygen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cggmp21-keygen"
version = "0.4.0"
version = "0.5.0"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "UC-secure DKG implementation based on CGGMP21 paper"
Expand Down
5 changes: 5 additions & 0 deletions cggmp21/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.6.0
* Update `hd-wallet` dep to v0.6 [#120]

[#120]: https://github.com/LFDT-Lockness/cggmp21/pull/120

## v0.5.0
* BREAKING: use `hd-wallet` crate for HD support instead of `slip-10` [#115]
* BREAKING: rename `hd-wallets` feature into `hd-wallet` [#115]
Expand Down
10 changes: 6 additions & 4 deletions cggmp21/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cggmp21"
version = "0.5.0"
version = "0.6.0"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "TSS ECDSA implementation based on CGGMP21 paper"
Expand Down Expand Up @@ -47,10 +47,12 @@ generic-tests = { workspace = true }

[features]
all-curves = ["curve-secp256k1", "curve-secp256r1", "curve-stark"]
curve-secp256k1 = ["generic-ec/curve-secp256k1"]
curve-secp256r1 = ["generic-ec/curve-secp256r1"]
curve-stark = ["generic-ec/curve-stark"]
curve-secp256k1 = ["generic-ec/curve-secp256k1", "hd-wallet?/curve-secp256k1"]
curve-secp256r1 = ["generic-ec/curve-secp256r1", "hd-wallet?/curve-secp256r1"]
curve-stark = ["generic-ec/curve-stark", "hd-wallet?/curve-stark"]
hd-wallet = ["dep:hd-wallet", "cggmp21-keygen/hd-wallet"]
hd-slip10 = ["hd-wallet/slip10"]
hd-stark = ["hd-wallet/stark"]
spof = ["key-share/spof"]

state-machine = ["cggmp21-keygen/state-machine"]
Expand Down
13 changes: 8 additions & 5 deletions cggmp21/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,10 @@ where
/// ```
///
/// ## Derivation algorithm
/// This method uses [`hd_wallet::Slip10Like`] derivation algorithm. If you need to use another one, see
/// This method uses [`hd_wallet::Slip10`] derivation algorithm, which can only be used with secp256k1
/// and secp256r1 curves. If you need to use another one, see
/// [`set_derivation_path_with_algo`](Self::set_derivation_path_with_algo)
#[cfg(feature = "hd-wallet")]
#[cfg(all(feature = "hd-wallet", feature = "hd-slip10"))]
pub fn set_derivation_path<Index>(
self,
path: impl IntoIterator<Item = Index>,
Expand All @@ -361,9 +362,10 @@ where
crate::key_share::HdError<<Index as TryInto<hd_wallet::NonHardenedIndex>>::Error>,
>
where
hd_wallet::Slip10: hd_wallet::HdWallet<E>,
hd_wallet::NonHardenedIndex: TryFrom<Index>,
{
self.set_derivation_path_with_algo::<hd_wallet::Slip10Like, _>(path)
self.set_derivation_path_with_algo::<hd_wallet::Slip10, _>(path)
}

/// Specifies HD derivation path, using HD derivation algorithm [`hd_wallet::HdWallet`]
Expand Down Expand Up @@ -1292,16 +1294,17 @@ impl<E: Curve> Presignature<E> {
///
/// For HD derivation, uses [`hd_wallet::Slip10Like`] algorithm. If you need to
/// use another derivation algorithm, see [`set_derivation_path_with_algo`](Self::set_derivation_path_with_algo)
#[cfg(feature = "hd-wallet")]
#[cfg(all(feature = "hd-wallet", feature = "hd-slip10"))]
pub fn set_derivation_path<Index>(
self,
epub: hd_wallet::ExtendedPublicKey<E>,
derivation_path: impl IntoIterator<Item = Index>,
) -> Result<Self, <Index as TryInto<hd_wallet::NonHardenedIndex>>::Error>
where
hd_wallet::Slip10: hd_wallet::HdWallet<E>,
hd_wallet::NonHardenedIndex: TryFrom<Index>,
{
self.set_derivation_path_with_algo::<hd_wallet::Slip10Like, _>(epub, derivation_path)
self.set_derivation_path_with_algo::<hd_wallet::Slip10, _>(epub, derivation_path)
}

/// Specifies HD derivation path
Expand Down
5 changes: 5 additions & 0 deletions key-share/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.6.0
* Update `hd-wallet` dep to v0.6 [#120]

[#120]: https://github.com/LFDT-Lockness/cggmp21/pull/120

## v0.5.0
* BREAKING: use `hd-wallet` crate for HD support instead of `slip-10` [#115]
* BREAKING: rename `hd-wallets` feature into `hd-wallet` [#115]
Expand Down
2 changes: 1 addition & 1 deletion key-share/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "key-share"
version = "0.5.0"
version = "0.6.0"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Key share of any Threshold Signature Scheme (TSS)"
Expand Down
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ generic-tests = "0.1"
test-case = "3"

[features]
hd-wallet = ["cggmp21/hd-wallet"]
hd-wallet = ["cggmp21/hd-wallet", "cggmp21/hd-slip10", "cggmp21/hd-stark"]

[[bin]]
name = "precompute_shares"
Expand Down
22 changes: 22 additions & 0 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,25 @@ pub fn random_derivation_path(rng: &mut impl rand::RngCore) -> Vec<u32> {
.take(len)
.collect::<Vec<_>>()
}

/// Parameters per each curve that are needed in tests
pub trait CurveParams: Curve {
/// Which HD derivation algorithm to use with that curve
#[cfg(feature = "hd-wallet")]
type HdAlgo: cggmp21::hd_wallet::HdWallet<Self>;
}

impl CurveParams for cggmp21::supported_curves::Secp256k1 {
#[cfg(feature = "hd-wallet")]
type HdAlgo = cggmp21::hd_wallet::Slip10;
}

impl CurveParams for cggmp21::supported_curves::Secp256r1 {
#[cfg(feature = "hd-wallet")]
type HdAlgo = cggmp21::hd_wallet::Slip10;
}

impl CurveParams for cggmp21::supported_curves::Stark {
#[cfg(feature = "hd-wallet")]
type HdAlgo = cggmp21::hd_wallet::Stark;
}
13 changes: 7 additions & 6 deletions tests/tests/it/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ mod generic {
#[test_case::case(3, 5, false; "t3n5")]
#[cfg_attr(feature = "hd-wallet", test_case::case(3, 5, true; "t3n5-hd"))]
#[tokio::test]
async fn full_pipeline_works<E: Curve>(t: u16, n: u16, hd_enabled: bool)
async fn full_pipeline_works<E>(t: u16, n: u16, hd_enabled: bool)
where
E: Curve + cggmp21_tests::CurveParams,
Point<E>: generic_ec::coords::HasAffineX<E>,
{
let mut rng = DevRng::new();
Expand Down Expand Up @@ -106,7 +107,7 @@ mod generic {

async fn run_signing<E>(shares: &[KeyShare<E>], random_derivation_path: bool, rng: &mut DevRng)
where
E: Curve,
E: Curve + cggmp21_tests::CurveParams,
Point<E>: generic_ec::coords::HasAffineX<E>,
{
#[cfg(not(feature = "hd-wallet"))]
Expand Down Expand Up @@ -152,7 +153,9 @@ mod generic {

#[cfg(feature = "hd-wallet")]
let signing = if let Some(derivation_path) = derivation_path {
signing.set_derivation_path(derivation_path).unwrap()
signing
.set_derivation_path_with_algo::<E::HdAlgo, _>(derivation_path)
.unwrap()
} else {
signing
};
Expand All @@ -169,9 +172,7 @@ mod generic {
let public_key = if let Some(path) = &derivation_path {
generic_ec::NonZero::from_point(
shares[0]
.derive_child_public_key::<cggmp21::hd_wallet::Slip10Like, _>(
path.iter().cloned(),
)
.derive_child_public_key::<E::HdAlgo, _>(path.iter().cloned())
.unwrap()
.public_key,
)
Expand Down
53 changes: 31 additions & 22 deletions tests/tests/it/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ mod generic {
#[cfg_attr(feature = "hd-wallet", test_case::case(Some(2), 3, false, true; "t2n3-hd"))]
#[cfg_attr(feature = "hd-wallet", test_case::case(Some(3), 3, false, true; "t3n3-hd"))]
#[tokio::test]
async fn signing_works<E: Curve, V>(
t: Option<u16>,
n: u16,
reliable_broadcast: bool,
hd_wallet: bool,
) where
async fn signing_works<E, V>(t: Option<u16>, n: u16, reliable_broadcast: bool, hd_wallet: bool)
where
E: Curve + cggmp21_tests::CurveParams,
Point<E>: HasAffineX<E>,
V: ExternalVerifier<E>,
{
Expand Down Expand Up @@ -80,7 +77,9 @@ mod generic {

#[cfg(feature = "hd-wallet")]
let signing = if let Some(derivation_path) = derivation_path {
signing.set_derivation_path(derivation_path).unwrap()
signing
.set_derivation_path_with_algo::<E::HdAlgo, _>(derivation_path)
.unwrap()
} else {
signing
};
Expand All @@ -97,9 +96,7 @@ mod generic {
let public_key = if let Some(path) = &derivation_path {
generic_ec::NonZero::from_point(
shares[0]
.derive_child_public_key::<cggmp21::hd_wallet::Slip10Like, _>(
path.iter().cloned(),
)
.derive_child_public_key::<E::HdAlgo, _>(path.iter().cloned())
.unwrap()
.public_key,
)
Expand All @@ -123,8 +120,9 @@ mod generic {
#[test_case::case(Some(3), 5, false; "t3n5")]
#[cfg_attr(feature = "hd-wallet", test_case::case(Some(3), 5, true; "t3n5-hd"))]
#[tokio::test]
async fn signing_with_presigs<E: Curve, V>(t: Option<u16>, n: u16, hd_wallet: bool)
async fn signing_with_presigs<E, V>(t: Option<u16>, n: u16, hd_wallet: bool)
where
E: Curve + cggmp21_tests::CurveParams,
Point<E>: HasAffineX<E>,
V: ExternalVerifier<E>,
{
Expand Down Expand Up @@ -187,7 +185,10 @@ mod generic {
let presig = if let Some(derivation_path) = &derivation_path {
let epub = shares[0].extended_public_key().expect("not hd wallet");
presig
.set_derivation_path(epub, derivation_path.iter().copied())
.set_derivation_path_with_algo::<E::HdAlgo, _>(
epub,
derivation_path.iter().copied(),
)
.unwrap()
} else {
presig
Expand All @@ -203,9 +204,7 @@ mod generic {
let public_key = if let Some(path) = &derivation_path {
generic_ec::NonZero::from_point(
shares[0]
.derive_child_public_key::<cggmp21::hd_wallet::Slip10Like, _>(
path.iter().cloned(),
)
.derive_child_public_key::<E::HdAlgo, _>(path.iter().cloned())
.unwrap()
.public_key,
)
Expand All @@ -230,6 +229,7 @@ mod generic {
#[cfg_attr(feature = "hd-wallet", test_case::case(Some(3), 5, true; "t3n5-hd"))]
fn signing_sync<E: Curve, V>(t: Option<u16>, n: u16, hd_wallet: bool)
where
E: Curve + cggmp21_tests::CurveParams,
Point<E>: HasAffineX<E>,
V: ExternalVerifier<E>,
{
Expand Down Expand Up @@ -276,7 +276,9 @@ mod generic {

#[cfg(feature = "hd-wallet")]
let signing = if let Some(derivation_path) = derivation_path.clone() {
signing.set_derivation_path(derivation_path).unwrap()
signing
.set_derivation_path_with_algo::<E::HdAlgo, _>(derivation_path)
.unwrap()
} else {
signing
};
Expand All @@ -296,9 +298,7 @@ mod generic {
let public_key = if let Some(path) = &derivation_path {
generic_ec::NonZero::from_point(
shares[0]
.derive_child_public_key::<cggmp21::hd_wallet::Slip10Like, _>(
path.iter().cloned(),
)
.derive_child_public_key::<E::HdAlgo, _>(path.iter().cloned())
.unwrap()
.public_key,
)
Expand All @@ -319,10 +319,19 @@ mod generic {
.expect("external verification failed")
}

#[instantiate_tests(<cggmp21::supported_curves::Secp256k1, cggmp21_tests::external_verifier::blockchains::Bitcoin>)]
#[instantiate_tests(<
cggmp21::supported_curves::Secp256k1,
cggmp21_tests::external_verifier::blockchains::Bitcoin
>)]
mod secp256k1 {}
#[instantiate_tests(<cggmp21::supported_curves::Secp256r1, cggmp21_tests::external_verifier::Noop>)]
#[instantiate_tests(<
cggmp21::supported_curves::Secp256r1,
cggmp21_tests::external_verifier::Noop
>)]
mod secp256r1 {}
#[instantiate_tests(<cggmp21::supported_curves::Stark, cggmp21_tests::external_verifier::blockchains::StarkNet>)]
#[instantiate_tests(<
cggmp21::supported_curves::Stark,
cggmp21_tests::external_verifier::blockchains::StarkNet
>)]
mod stark {}
}
Loading
Loading