Skip to content

Commit

Permalink
Fix --no-default-features (ZcashFoundation#630)
Browse files Browse the repository at this point in the history
* fix --no-default-features; also make sure everything compilers with every feature combination

* backport some fixes from no-std PR

* update CHANGELOG
  • Loading branch information
conradoplg authored Apr 10, 2024
1 parent a47177d commit c205ef7
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 24 deletions.
6 changes: 6 additions & 0 deletions frost-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Entries are listed in reverse chronological order.

## Unreleased

## 1.0.1

* Fixed `no-default-features`, previously it wouldn't compile.
* Fixed some feature handling that would include unneeded dependencies in some
cases.

## Released

## 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion frost-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internals = []
serde = ["dep:serde", "dep:serdect"]
serialization = ["serde", "dep:postcard"]
# Exposes ciphersuite-generic tests for other crates to use
test-impl = ["proptest", "serde_json", "criterion"]
test-impl = ["dep:proptest", "dep:serde_json", "dep:criterion"]
# Enable cheater detection
cheater-detection = []

Expand Down
7 changes: 4 additions & 3 deletions frost-core/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ use rand_core::{CryptoRng, RngCore};
use zeroize::{DefaultIsZeroes, Zeroize};

use crate::{
serialization::{Deserialize, Serialize},
Ciphersuite, Element, Error, Field, Group, Header, Identifier, Scalar, SigningKey,
VerifyingKey,
Ciphersuite, Element, Error, Field, Group, Header, Identifier, Scalar, SigningKey, VerifyingKey,
};

#[cfg(feature = "serde")]
use crate::serialization::{ElementSerialization, ScalarSerialization};

#[cfg(feature = "serialization")]
use crate::serialization::{Deserialize, Serialize};

use super::compute_lagrange_coefficient;

pub mod dkg;
Expand Down
2 changes: 2 additions & 0 deletions frost-core/src/keys/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub mod round1 {
use derive_getters::Getters;
use zeroize::Zeroize;

#[cfg(feature = "serialization")]
use crate::serialization::{Deserialize, Serialize};

use super::*;
Expand Down Expand Up @@ -167,6 +168,7 @@ pub mod round2 {
use derive_getters::Getters;
use zeroize::Zeroize;

#[cfg(feature = "serialization")]
use crate::serialization::{Deserialize, Serialize};

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion frost-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct Header<C: Ciphersuite> {
serde(deserialize_with = "crate::serialization::ciphersuite_deserialize::<_, C>")
)]
ciphersuite: (),
#[serde(skip)]
#[cfg_attr(feature = "serde", serde(skip))]
phantom: PhantomData<C>,
}

Expand Down
12 changes: 6 additions & 6 deletions frost-core/src/round1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ use hex::FromHex;
use rand_core::{CryptoRng, RngCore};
use zeroize::Zeroize;

use crate as frost;
use crate::{
serialization::{Deserialize, Serialize},
Ciphersuite, Element, Error, Field, Group, Header, Scalar,
};
use crate::{Ciphersuite, Element, Error, Field, Group, Header, Scalar};

#[cfg(feature = "serde")]
use crate::serialization::{ElementSerialization, ScalarSerialization};

#[cfg(feature = "serialization")]
use crate::serialization::{Deserialize, Serialize};

use super::{keys::SigningShare, Identifier};

/// A scalar that is a signing nonce.
Expand Down Expand Up @@ -353,11 +352,12 @@ where
/// Computes the [signature commitment share] from these round one signing commitments.
///
/// [signature commitment share]: https://www.ietf.org/archive/id/draft-irtf-cfrg-frost-14.html#name-signature-share-verificatio
#[cfg(any(feature = "cheater-detection", feature = "internals"))]
#[cfg_attr(feature = "internals", visibility::make(pub))]
#[cfg_attr(docsrs, doc(cfg(feature = "internals")))]
pub(super) fn to_group_commitment_share(
self,
binding_factor: &frost::BindingFactor<C>,
binding_factor: &crate::BindingFactor<C>,
) -> GroupCommitmentShare<C> {
GroupCommitmentShare::<C>(self.hiding.0 + (self.binding.0 * binding_factor.0))
}
Expand Down
1 change: 1 addition & 0 deletions frost-core/src/round2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ where
/// This is the final step of [`verify_signature_share`] from the spec.
///
/// [`verify_signature_share`]: https://www.ietf.org/archive/id/draft-irtf-cfrg-frost-14.html#name-signature-share-verificatio
#[cfg(any(feature = "cheater-detection", feature = "internals"))]
#[cfg_attr(feature = "internals", visibility::make(pub))]
#[cfg_attr(docsrs, doc(cfg(feature = "internals")))]
pub(crate) fn verify(
Expand Down
7 changes: 6 additions & 1 deletion frost-core/src/serialization.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! Serialization support.
use crate::{Ciphersuite, Error, Field, Group};
#[cfg(feature = "serde")]
use crate::{Ciphersuite, Field, Group};

#[cfg(feature = "serialization")]
use crate::Error;

#[cfg(feature = "serde")]
#[cfg_attr(feature = "internals", visibility::make(pub))]
Expand Down Expand Up @@ -89,6 +93,7 @@ where

// The short 4-byte ID. Derived as the CRC-32 of the UTF-8
// encoded ID in big endian format.
#[cfg(feature = "serde")]
const fn short_id<C>() -> [u8; 4]
where
C: Ciphersuite,
Expand Down
1 change: 1 addition & 0 deletions frost-core/src/tests/ciphersuite_generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ fn check_aggregate_errors<C: Ciphersuite + PartialEq>(
);
}

#[cfg(feature = "cheater-detection")]
fn check_aggregate_corrupted_share<C: Ciphersuite + PartialEq>(
signing_package: frost::SigningPackage<C>,
mut signature_shares: BTreeMap<frost::Identifier<C>, frost::round2::SignatureShare<C>>,
Expand Down
5 changes: 3 additions & 2 deletions frost-ed25519/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ serde_json = "1.0"
[features]
nightly = []
default = ["serialization", "cheater-detection"]
serialization = ["serde", "frost-core/serialization"]
#! ## Features
## Enable `serde` support for types that need to be communicated. You
## can use `serde` to serialize structs with any encoder that supports
## `serde` (e.g. JSON with `serde_json`).
serde = ["frost-core/serde"]
## Enable cheater detection
cheater-detection = ["frost-core/cheater-detection"]
cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"]
## Enable a default serialization format. Enables `serde`.
serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"]

[lib]
# Disables non-criterion benchmark which is not used; prevents errors
Expand Down
5 changes: 3 additions & 2 deletions frost-ed448/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ serde_json = "1.0"
[features]
nightly = []
default = ["serialization", "cheater-detection"]
serialization = ["serde", "frost-core/serialization"]
#! ## Features
## Enable `serde` support for types that need to be communicated. You
## can use `serde` to serialize structs with any encoder that supports
## `serde` (e.g. JSON with `serde_json`).
serde = ["frost-core/serde"]
## Enable cheater detection
cheater-detection = ["frost-core/cheater-detection"]
cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"]
## Enable a default serialization format. Enables `serde`.
serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"]

[lib]
# Disables non-criterion benchmark which is not used; prevents errors
Expand Down
5 changes: 3 additions & 2 deletions frost-p256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ serde_json = "1.0"
[features]
nightly = []
default = ["serialization", "cheater-detection"]
serialization = ["serde", "frost-core/serialization"]
#! ## Features
## Enable `serde` support for types that need to be communicated. You
## can use `serde` to serialize structs with any encoder that supports
## `serde` (e.g. JSON with `serde_json`).
serde = ["frost-core/serde"]
## Enable cheater detection
cheater-detection = ["frost-core/cheater-detection"]
cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"]
## Enable a default serialization format. Enables `serde`.
serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"]

[lib]
# Disables non-criterion benchmark which is not used; prevents errors
Expand Down
5 changes: 3 additions & 2 deletions frost-rerandomized/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ rand_core = "0.6"
[features]
nightly = []
default = ["serialization", "cheater-detection"]
serialization = ["serde", "frost-core/serialization"]
#! ## Features
## Enable `serde` support for types that need to be communicated. You
## can use `serde` to serialize structs with any encoder that supports
## `serde` (e.g. JSON with `serde_json`).
serde = ["frost-core/serde"]
# Exposes ciphersuite-generic tests for other crates to use
test-impl = ["frost-core/test-impl"]
test-impl = ["frost-core/test-impl", "serialization"]
## Enable cheater detection
cheater-detection = ["frost-core/cheater-detection"]
## Enable a default serialization format. Enables `serde`.
serialization = ["serde", "frost-core/serialization"]
5 changes: 3 additions & 2 deletions frost-ristretto255/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ serde_json = "1.0"
[features]
nightly = []
default = ["serialization", "cheater-detection"]
serialization = ["serde", "frost-core/serialization"]
#! ## Features
## Enable `serde` support for types that need to be communicated. You
## can use `serde` to serialize structs with any encoder that supports
## `serde` (e.g. JSON with `serde_json`).
serde = ["frost-core/serde"]
## Enable cheater detection
cheater-detection = ["frost-core/cheater-detection"]
cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"]
## Enable a default serialization format. Enables `serde`.
serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"]

[lib]
# Disables non-criterion benchmark which is not used; prevents errors
Expand Down
5 changes: 3 additions & 2 deletions frost-secp256k1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ serde_json = "1.0"
[features]
nightly = []
default = ["serialization", "cheater-detection"]
serialization = ["serde", "frost-core/serialization"]
#! ## Features
## Enable `serde` support for types that need to be communicated. You
## can use `serde` to serialize structs with any encoder that supports
## `serde` (e.g. JSON with `serde_json`).
serde = ["frost-core/serde"]
## Enable cheater detection
cheater-detection = ["frost-core/cheater-detection"]
cheater-detection = ["frost-core/cheater-detection", "frost-rerandomized/cheater-detection"]
## Enable a default serialization format. Enables `serde`.
serialization = ["serde", "frost-core/serialization", "frost-rerandomized/serialization"]

[lib]
# Disables non-criterion benchmark which is not used; prevents errors
Expand Down

0 comments on commit c205ef7

Please sign in to comment.