Skip to content

Commit b553ff8

Browse files
feat: switch to frost fork with no_std support and additional trait bounds
1 parent 70dcfee commit b553ff8

File tree

26 files changed

+74
-112
lines changed

26 files changed

+74
-112
lines changed

Cargo.toml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,20 @@ aes = { version = "0.8", features = ["zeroize"], default-features = false }
2626
ctr = { version = "0.9", features = ["zeroize"], default-features = false }
2727
digest = { version = "0.10", default-features = false }
2828
document-features = "0.2"
29-
frost-core = { version = "2.1", features = ["internals"], default-features = false }
30-
frost-ed25519 = { version = "2.1", default-features = false }
31-
frost-ed448 = { version = "2.1", default-features = false }
32-
frost-p256 = { version = "2.1", default-features = false }
33-
frost-ristretto255 = { version = "2.1", default-features = false }
34-
frost-secp256k1 = { version = "2.1", default-features = false }
35-
frost-secp256k1-evm = { version = "2.1", default-features = false }
36-
frost-secp256k1-tr = { version = "2.1", default-features = false }
29+
frost-core = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", features = ["internals"], default-features = false }
30+
frost-ed25519 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
31+
frost-ed448 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
32+
frost-p256 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
33+
frost-ristretto255 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
34+
frost-secp256k1 = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
35+
frost-secp256k1-evm = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
36+
frost-secp256k1-tr = { version = "2.1", git = "https://github.com/StackOverflowExcept1on/frost", branch = "frost-secp256k1-evm-crates-io-no-std", default-features = false }
3737
hkdf = { version = "0.12", default-features = false }
3838
rand = { version = "0.8", default-features = false }
3939
rand_core = { version = "0.6", default-features = false }
4040
sha2 = { version = "0.10", default-features = false }
4141
sha3 = { version = "0.10", default-features = false }
42-
thiserror-nostd-notrait = { version = "1.0", default-features = false }
43-
thiserror = { version = "2.0", default-features = false } # TODO: https://github.com/ZcashFoundation/frost/issues/768
42+
thiserror = { version = "2.0", default-features = false }
4443

4544
roast-core = { path = "roast-core", default-features = false }
4645
roast-ed25519 = { path = "roast-ed25519", default-features = false }

roast-core/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@ frost-core.workspace = true
2020
hkdf.workspace = true
2121
rand = { workspace = true, optional = true }
2222
rand_core.workspace = true
23-
thiserror-nostd-notrait.workspace = true
24-
thiserror = { workspace = true, optional = true }
23+
thiserror.workspace = true
2524

2625
[features]
27-
default = ["serialization", "cheater-detection", "std"]
26+
default = ["serialization", "cheater-detection"]
2827
#! ## Features
29-
## Enable standard library support.
30-
std = ["dep:thiserror"]
3128
## Enable `serde` support for types that need to be communicated. You
3229
## can use `serde` to serialize structs with any encoder that supports
3330
## `serde` (e.g. JSON with `serde_json`).

roast-core/src/dkg.rs

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,37 +54,38 @@ fn try_apply_keystream(key: [u8; 16], iv: [u8; 16], buffer: &mut [u8]) -> Option
5454
.ok()
5555
}
5656

57+
type Round2PackageSerialization<C> =
58+
<<<C as Ciphersuite>::Group as Group>::Field as Field>::Serialization;
59+
5760
fn encrypt_round2_package<C: Ciphersuite, H: Clone + BlockSizeUser + Digest>(
5861
round2_package: round2::Package<C>,
5962
receiver_temp_public_key: &VerifyingKey<C>,
6063
sender_temp_secret_key: &SigningKey<C>,
61-
) -> Option<Vec<u8>> {
64+
) -> Option<Round2PackageSerialization<C>> {
6265
let shared_secret_bytes = diffie_hellman(sender_temp_secret_key, receiver_temp_public_key)?;
6366
let (key, iv) = hkdf::<C, H>(shared_secret_bytes)?;
6467

6568
let signing_share = round2_package.signing_share().to_scalar();
66-
let singing_share_bytes = <<C::Group as Group>::Field as Field>::serialize(&signing_share);
69+
let mut singing_share_bytes = <<C::Group as Group>::Field as Field>::serialize(&signing_share);
6770

68-
let mut buffer = singing_share_bytes.as_ref().to_vec();
69-
try_apply_keystream(key, iv, &mut buffer)?;
71+
try_apply_keystream(key, iv, singing_share_bytes.as_mut())?;
7072

71-
Some(buffer)
73+
Some(singing_share_bytes)
7274
}
7375

7476
fn decrypt_round2_package<C: Ciphersuite, H: Clone + BlockSizeUser + Digest>(
75-
round2_package_encrypted: Vec<u8>,
77+
mut round2_package_encrypted: Round2PackageSerialization<C>,
7678
sender_temp_public_key: &VerifyingKey<C>,
7779
receiver_temp_secret_key: &SigningKey<C>,
7880
) -> Option<round2::Package<C>> {
7981
let shared_secret_bytes = diffie_hellman(receiver_temp_secret_key, sender_temp_public_key)?;
8082
let (key, iv) = hkdf::<C, H>(shared_secret_bytes)?;
8183

82-
let mut buffer = round2_package_encrypted;
83-
try_apply_keystream(key, iv, &mut buffer)?;
84+
try_apply_keystream(key, iv, round2_package_encrypted.as_mut())?;
8485

85-
let buffer_serialized = buffer.try_into().ok()?;
86-
let signing_share =
87-
SigningShare::new(<<C::Group as Group>::Field>::deserialize(&buffer_serialized).ok()?);
86+
let signing_share = SigningShare::new(
87+
<<C::Group as Group>::Field>::deserialize(&round2_package_encrypted).ok()?,
88+
);
8889

8990
Some(round2::Package::new(signing_share))
9091
}
@@ -112,7 +113,8 @@ pub struct Dealer<C: Ciphersuite, H: Clone + BlockSizeUser + Digest> {
112113
participants: Vec<Identifier<C>>,
113114
participants_set: BTreeSet<Identifier<C>>,
114115
round1_packages: BTreeMap<Identifier<C>, Round1Package<C>>,
115-
round2_packages_encrypted: BTreeMap<Identifier<C>, BTreeMap<Identifier<C>, Vec<u8>>>,
116+
round2_packages_encrypted:
117+
BTreeMap<Identifier<C>, BTreeMap<Identifier<C>, Round2PackageSerialization<C>>>,
116118
round2_participants_set: BTreeSet<Identifier<C>>,
117119
round2_culprits_set: BTreeSet<Identifier<C>>,
118120
phantom: PhantomData<H>,
@@ -169,7 +171,7 @@ impl<C: Ciphersuite, H: Clone + BlockSizeUser + Digest> Dealer<C, H> {
169171
pub fn round2_packages_encrypted(
170172
&self,
171173
receiver_identifier: Identifier<C>,
172-
) -> Option<&BTreeMap<Identifier<C>, Vec<u8>>> {
174+
) -> Option<&BTreeMap<Identifier<C>, Round2PackageSerialization<C>>> {
173175
self.round2_packages_encrypted.get(&receiver_identifier)
174176
}
175177

@@ -220,7 +222,7 @@ impl<C: Ciphersuite, H: Clone + BlockSizeUser + Digest> Dealer<C, H> {
220222
pub fn receive_round2_packages_encrypted(
221223
&mut self,
222224
identifier: Identifier<C>,
223-
round2_packages_encrypted: BTreeMap<Identifier<C>, Vec<u8>>,
225+
round2_packages_encrypted: BTreeMap<Identifier<C>, Round2PackageSerialization<C>>,
224226
) -> Result<DkgStatus, DkgDealerError<C>> {
225227
if !self.participants_set.contains(&identifier) {
226228
return Err(DkgDealerError::UnknownParticipant);
@@ -230,25 +232,11 @@ impl<C: Ciphersuite, H: Clone + BlockSizeUser + Digest> Dealer<C, H> {
230232
return Err(DkgDealerError::Frost(FrostError::IncorrectNumberOfPackages));
231233
}
232234

233-
let zero = <<C::Group as Group>::Field>::zero();
234-
let serialization = <<C::Group as Group>::Field>::serialize(&zero);
235-
let expected_len = serialization.as_ref().len();
236-
237-
// check that `round2_packages_encrypted` keys contain all identifiers except
238-
// sender identifier
239235
if self
240236
.participants
241237
.iter()
242238
.filter(|id| identifier.ne(id))
243-
.any(|id| {
244-
// value must be `Some(_)` and must also have length of `expected_len`
245-
round2_packages_encrypted
246-
.get(id)
247-
.filter(|round2_package_encrypted| {
248-
round2_package_encrypted.len() == expected_len
249-
})
250-
.is_none()
251-
})
239+
.any(|id| !round2_packages_encrypted.contains_key(id))
252240
{
253241
return Err(DkgDealerError::Frost(FrostError::IncorrectPackage));
254242
}
@@ -461,7 +449,8 @@ impl<C: Ciphersuite, H: Clone + BlockSizeUser + Digest> Participant<C, H> {
461449
pub fn receive_round1_packages(
462450
&mut self,
463451
mut round1_packages: BTreeMap<Identifier<C>, Round1Package<C>>,
464-
) -> Result<BTreeMap<Identifier<C>, Vec<u8>>, DkgParticipantError<C>> {
452+
) -> Result<BTreeMap<Identifier<C>, Round2PackageSerialization<C>>, DkgParticipantError<C>>
453+
{
465454
let round1_secret_package = self
466455
.round1_secret_package
467456
.take()
@@ -501,7 +490,7 @@ impl<C: Ciphersuite, H: Clone + BlockSizeUser + Digest> Participant<C, H> {
501490
/// Receives `round2_packages_encrypted` from the dealer.
502491
pub fn receive_round2_packages_encrypted(
503492
&mut self,
504-
round2_packages_encrypted: BTreeMap<Identifier<C>, Vec<u8>>,
493+
round2_packages_encrypted: BTreeMap<Identifier<C>, Round2PackageSerialization<C>>,
505494
) -> Result<(KeyPackage<C>, PublicKeyPackage<C>), DkgParticipantError<C>> {
506495
let round2_secret_package = self
507496
.round2_secret_package

roast-core/src/error.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
//! Error types.
22
33
use frost_core::{Ciphersuite, Error as FrostErrorType};
4-
#[cfg(feature = "std")]
54
use thiserror::Error;
6-
#[cfg(not(feature = "std"))]
7-
use thiserror_nostd_notrait::Error;
85

96
/// Represents all possible errors that can occur in FROST protocol.
107
pub type FrostError<C> = FrostErrorType<C>;
@@ -48,19 +45,6 @@ pub enum DkgParticipantError<C: Ciphersuite> {
4845
InvalidSecretShares,
4946
}
5047

51-
/// Represents all possible errors that can occur in Distributed Key Generation
52-
/// protocol.
53-
#[cfg(any(test, feature = "test-impl"))]
54-
#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
55-
pub enum DkgError<C: Ciphersuite> {
56-
/// Error in Distributed Key Generation protocol on dealer side.
57-
#[error("DKG dealer error: {0}")]
58-
DkgDealer(#[from] DkgDealerError<C>),
59-
/// Error in Distributed Key Generation protocol on participant side.
60-
#[error("DKG participant error: {0}")]
61-
DkgParticipant(#[from] DkgParticipantError<C>),
62-
}
63-
6448
/// Represents all possible errors for which signer can be marked as malicious.
6549
#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
6650
pub enum MaliciousSignerError {

roast-core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(not(feature = "std"), no_std)]
1+
#![no_std]
22
#![deny(missing_docs)]
33
#![doc = include_str!("../README.md")]
44
#![doc = document_features::document_features!()]

roast-core/src/tests.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
33
use crate::{
44
dkg::{Dealer, Participant},
5-
error::{DkgError, DkgParticipantError, RoastError},
5+
error::{DkgParticipantError, RoastError},
66
Coordinator, SessionStatus, Signer,
77
};
88
use aes::cipher::crypto_common::BlockSizeUser;
9-
use alloc::collections::BTreeMap;
9+
use alloc::{boxed::Box, collections::BTreeMap};
10+
use core::error::Error;
1011
use digest::Digest;
1112
use frost_core::{
1213
keys::{self, IdentifierList, KeyPackage},
@@ -25,7 +26,7 @@ pub fn test_dkg_basic<
2526
min_signers: u16,
2627
max_signers: u16,
2728
rng: &mut RNG,
28-
) -> Result<(), DkgError<C>> {
29+
) -> Result<(), Box<dyn Error>> {
2930
let mut identifiers = vec![];
3031
let mut participants = vec![];
3132

roast-ed25519/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ roast-core = { workspace = true, features = ["test-impl"] }
2222
rand_core = { workspace = true, features = ["getrandom"] }
2323

2424
[features]
25-
default = ["serialization", "cheater-detection", "std"]
25+
default = ["serialization", "cheater-detection"]
2626
#! ## Features
27-
## Enable standard library support.
28-
std = ["roast-core/std"]
2927
## Enable `serde` support for types that need to be communicated. You
3028
## can use `serde` to serialize structs with any encoder that supports
3129
## `serde` (e.g. JSON with `serde_json`).

roast-ed25519/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(not(feature = "std"), no_std)]
1+
#![no_std]
22
#![deny(missing_docs)]
33
#![doc = include_str!("../README.md")]
44
#![doc = document_features::document_features!()]

roast-ed25519/tests/integration_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use roast_core::{error::DkgError, tests};
1+
use roast_core::tests;
22
use roast_ed25519::{error::RoastError, frost::rand_core::OsRng};
33

44
#[test]
5-
fn test_dkg_basic() -> Result<(), DkgError<frost_ed25519::Ed25519Sha512>> {
5+
fn test_dkg_basic() -> Result<(), Box<dyn std::error::Error>> {
66
let mut rng = OsRng;
7-
tests::test_dkg_basic::<_, sha2::Sha512, _>(2, 3, &mut rng)?;
7+
tests::test_dkg_basic::<frost_ed25519::Ed25519Sha512, sha2::Sha512, _>(2, 3, &mut rng)?;
88
Ok(())
99
}
1010

roast-ed448/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ roast-core = { workspace = true, features = ["test-impl"] }
2222
rand_core = { workspace = true, features = ["getrandom"] }
2323

2424
[features]
25-
default = ["serialization", "cheater-detection", "std"]
25+
default = ["serialization", "cheater-detection"]
2626
#! ## Features
27-
## Enable standard library support.
28-
std = ["roast-core/std"]
2927
## Enable `serde` support for types that need to be communicated. You
3028
## can use `serde` to serialize structs with any encoder that supports
3129
## `serde` (e.g. JSON with `serde_json`).

roast-ed448/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// TODO: #![cfg_attr(not(feature = "std"), no_std)] (https://github.com/ZcashFoundation/frost/issues/769)
1+
#![no_std]
22
#![deny(missing_docs)]
33
#![doc = include_str!("../README.md")]
44
#![doc = document_features::document_features!()]

roast-p256/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ roast-core = { workspace = true, features = ["test-impl"] }
2222
rand_core = { workspace = true, features = ["getrandom"] }
2323

2424
[features]
25-
default = ["serialization", "cheater-detection", "std"]
25+
default = ["serialization", "cheater-detection"]
2626
#! ## Features
27-
## Enable standard library support.
28-
std = ["roast-core/std"]
2927
## Enable `serde` support for types that need to be communicated. You
3028
## can use `serde` to serialize structs with any encoder that supports
3129
## `serde` (e.g. JSON with `serde_json`).

roast-p256/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(not(feature = "std"), no_std)]
1+
#![no_std]
22
#![deny(missing_docs)]
33
#![doc = include_str!("../README.md")]
44
#![doc = document_features::document_features!()]

roast-p256/tests/integration_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use roast_core::{error::DkgError, tests};
1+
use roast_core::tests;
22
use roast_p256::{error::RoastError, frost::rand_core::OsRng};
33

44
#[test]
5-
fn test_dkg_basic() -> Result<(), DkgError<frost_p256::P256Sha256>> {
5+
fn test_dkg_basic() -> Result<(), Box<dyn std::error::Error>> {
66
let mut rng = OsRng;
7-
tests::test_dkg_basic::<_, sha2::Sha256, _>(2, 3, &mut rng)?;
7+
tests::test_dkg_basic::<frost_p256::P256Sha256, sha2::Sha256, _>(2, 3, &mut rng)?;
88
Ok(())
99
}
1010

roast-ristretto255/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ roast-core = { workspace = true, features = ["test-impl"] }
2222
rand_core = { workspace = true, features = ["getrandom"] }
2323

2424
[features]
25-
default = ["serialization", "cheater-detection", "std"]
25+
default = ["serialization", "cheater-detection"]
2626
#! ## Features
27-
## Enable standard library support.
28-
std = ["roast-core/std"]
2927
## Enable `serde` support for types that need to be communicated. You
3028
## can use `serde` to serialize structs with any encoder that supports
3129
## `serde` (e.g. JSON with `serde_json`).

roast-ristretto255/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(not(feature = "std"), no_std)]
1+
#![no_std]
22
#![deny(missing_docs)]
33
#![doc = include_str!("../README.md")]
44
#![doc = document_features::document_features!()]

roast-ristretto255/tests/integration_tests.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use roast_core::{error::DkgError, tests};
1+
use roast_core::tests;
22
use roast_ristretto255::{error::RoastError, frost::rand_core::OsRng};
33

44
#[test]
5-
fn test_dkg_basic() -> Result<(), DkgError<frost_ristretto255::Ristretto255Sha512>> {
5+
fn test_dkg_basic() -> Result<(), Box<dyn std::error::Error>> {
66
let mut rng = OsRng;
7-
tests::test_dkg_basic::<_, sha2::Sha512, _>(2, 3, &mut rng)?;
7+
tests::test_dkg_basic::<frost_ristretto255::Ristretto255Sha512, sha2::Sha512, _>(
8+
2, 3, &mut rng,
9+
)?;
810
Ok(())
911
}
1012

roast-secp256k1-evm/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ roast-core = { workspace = true, features = ["test-impl"] }
2222
rand_core = { workspace = true, features = ["getrandom"] }
2323

2424
[features]
25-
default = ["serialization", "cheater-detection", "std"]
25+
default = ["serialization", "cheater-detection"]
2626
#! ## Features
27-
## Enable standard library support.
28-
std = ["roast-core/std"]
2927
## Enable `serde` support for types that need to be communicated. You
3028
## can use `serde` to serialize structs with any encoder that supports
3129
## `serde` (e.g. JSON with `serde_json`).

roast-secp256k1-evm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(not(feature = "std"), no_std)]
1+
#![no_std]
22
#![deny(missing_docs)]
33
#![doc = include_str!("../README.md")]
44
#![doc = document_features::document_features!()]

roast-secp256k1-evm/tests/integration_tests.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use roast_core::{error::DkgError, tests};
1+
use roast_core::tests;
22
use roast_secp256k1_evm::{error::RoastError, frost::rand_core::OsRng};
33

44
#[test]
5-
fn test_dkg_basic() -> Result<(), DkgError<frost_secp256k1_evm::Secp256K1Keccak256>> {
5+
fn test_dkg_basic() -> Result<(), Box<dyn std::error::Error>> {
66
let mut rng = OsRng;
7-
tests::test_dkg_basic::<_, sha3::Keccak256, _>(2, 3, &mut rng)?;
7+
tests::test_dkg_basic::<frost_secp256k1_evm::Secp256K1Keccak256, sha3::Keccak256, _>(
8+
2, 3, &mut rng,
9+
)?;
810
Ok(())
911
}
1012

roast-secp256k1-tr/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ roast-core = { workspace = true, features = ["test-impl"] }
2222
rand_core = { workspace = true, features = ["getrandom"] }
2323

2424
[features]
25-
default = ["serialization", "cheater-detection", "std"]
25+
default = ["serialization", "cheater-detection"]
2626
#! ## Features
27-
## Enable standard library support.
28-
std = ["roast-core/std"]
2927
## Enable `serde` support for types that need to be communicated. You
3028
## can use `serde` to serialize structs with any encoder that supports
3129
## `serde` (e.g. JSON with `serde_json`).

0 commit comments

Comments
 (0)