From dfdffcacd6bb02af7ab93007c3e67a6d70960706 Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Wed, 18 Dec 2024 17:28:03 -0700 Subject: [PATCH] chore: fmt --- frost/frost-ed448/src/lib.rs | 8 +++---- frost/frost-p384/src/lib.rs | 8 +++---- frost/frost-secp256k1-tr/src/lib.rs | 24 +++++++++---------- frost/src/error.rs | 3 ++- frost/src/keys.rs | 20 +++++++--------- frost/src/lib.rs | 15 ++++++------ frost/src/round2.rs | 8 +++---- frost/src/scalar_mul.rs | 4 ++-- frost/src/signature.rs | 3 ++- frost/src/traits.rs | 6 +++-- .../src/functions/delegate.rs | 6 +++-- pallets/services/src/mock.rs | 4 +--- .../multi-asset-delegation/src/mock.rs | 7 +++--- 13 files changed, 57 insertions(+), 59 deletions(-) diff --git a/frost/frost-ed448/src/lib.rs b/frost/frost-ed448/src/lib.rs index 671bd15c..3481fa20 100644 --- a/frost/frost-ed448/src/lib.rs +++ b/frost/frost-ed448/src/lib.rs @@ -284,8 +284,8 @@ pub mod keys { /// Contains the commitments to the coefficients for our secret polynomial _f_, /// used to generate participants' key shares. /// - /// [`VerifiableSecretSharingCommitment`] contains a set of commitments to the coefficients (which - /// themselves are scalars) for a secret polynomial f, where f is used to + /// [`VerifiableSecretSharingCommitment`] contains a set of commitments to the coefficients + /// (which themselves are scalars) for a secret polynomial f, where f is used to /// generate each ith participant's key share f(i). Participants use this set of /// commitments to perform verifiable secret sharing. /// @@ -338,8 +338,8 @@ pub type SigningPackage = frost::SigningPackage; pub mod round2 { use super::*; - /// A FROST(Ed448, SHAKE256) participant's signature share, which the Coordinator will aggregate with all other signer's - /// shares into the joint signature. + /// A FROST(Ed448, SHAKE256) participant's signature share, which the Coordinator will aggregate + /// with all other signer's shares into the joint signature. pub type SignatureShare = frost::round2::SignatureShare; /// Performed once by each participant selected for the signing operation. diff --git a/frost/frost-p384/src/lib.rs b/frost/frost-p384/src/lib.rs index 9a894fc7..0b072b67 100644 --- a/frost/frost-p384/src/lib.rs +++ b/frost/frost-p384/src/lib.rs @@ -314,8 +314,8 @@ pub mod keys { /// Contains the commitments to the coefficients for our secret polynomial _f_, /// used to generate participants' key shares. /// - /// [`VerifiableSecretSharingCommitment`] contains a set of commitments to the coefficients (which - /// themselves are scalars) for a secret polynomial f, where f is used to + /// [`VerifiableSecretSharingCommitment`] contains a set of commitments to the coefficients + /// (which themselves are scalars) for a secret polynomial f, where f is used to /// generate each ith participant's key share f(i). Participants use this set of /// commitments to perform verifiable secret sharing. /// @@ -368,8 +368,8 @@ pub type SigningPackage = frost::SigningPackage

; pub mod round2 { use super::*; - /// A FROST(P-384, SHA-384) participant's signature share, which the Coordinator will aggregate with all other signer's - /// shares into the joint signature. + /// A FROST(P-384, SHA-384) participant's signature share, which the Coordinator will aggregate + /// with all other signer's shares into the joint signature. pub type SignatureShare = frost::round2::SignatureShare

; /// Performed once by each participant selected for the signing operation. diff --git a/frost/frost-secp256k1-tr/src/lib.rs b/frost/frost-secp256k1-tr/src/lib.rs index 987aec8e..0a82729b 100644 --- a/frost/frost-secp256k1-tr/src/lib.rs +++ b/frost/frost-secp256k1-tr/src/lib.rs @@ -1,15 +1,14 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(non_snake_case)] -use sp_std::vec; -use sp_std::{borrow::Cow, collections::btree_map::BTreeMap, vec::Vec}; +use sp_std::{borrow::Cow, collections::btree_map::BTreeMap, vec, vec::Vec}; -use k256::elliptic_curve::ops::Reduce; use k256::{ elliptic_curve::{ bigint::U256, group::prime::PrimeCurveAffine, hash2curve::{hash_to_field, ExpandMsgXmd}, + ops::Reduce, point::AffineCoordinates, sec1::{FromEncodedPoint, ToEncodedPoint}, Field as FFField, PrimeField, @@ -23,8 +22,7 @@ use tg_frost_core as frost_core; use frost_core::{self as frost, random_nonzero}; -use keys::EvenY; -use keys::Tweak; +use keys::{EvenY, Tweak}; // Re-exports in our public API pub use frost_core::{ @@ -523,8 +521,8 @@ pub mod keys { /// /// # Security /// - /// To derive a FROST(secp256k1, SHA-256) keypair, the receiver of the [`SecretShare`] *must* call - /// .into(), which under the hood also performs validation. + /// To derive a FROST(secp256k1, SHA-256) keypair, the receiver of the [`SecretShare`] *must* + /// call .into(), which under the hood also performs validation. pub type SecretShare = frost::keys::SecretShare; /// A secret scalar value representing a signer's share of the group secret. @@ -533,8 +531,8 @@ pub mod keys { /// A public group element that represents a single signer's public verification share. pub type VerifyingShare = frost::keys::VerifyingShare; - /// A FROST(secp256k1, SHA-256) keypair, which can be generated either by a trusted dealer or using - /// a DKG. + /// A FROST(secp256k1, SHA-256) keypair, which can be generated either by a trusted dealer or + /// using a DKG. /// /// When using a central dealer, [`SecretShare`]s are distributed to /// participants, who then perform verification, before deriving @@ -550,8 +548,8 @@ pub mod keys { /// Contains the commitments to the coefficients for our secret polynomial _f_, /// used to generate participants' key shares. /// - /// [`VerifiableSecretSharingCommitment`] contains a set of commitments to the coefficients (which - /// themselves are scalars) for a secret polynomial f, where f is used to + /// [`VerifiableSecretSharingCommitment`] contains a set of commitments to the coefficients + /// (which themselves are scalars) for a secret polynomial f, where f is used to /// generate each ith participant's key share f(i). Participants use this set of /// commitments to perform verifiable secret sharing. /// @@ -793,8 +791,8 @@ pub mod round2 { use super::*; - /// A FROST(secp256k1, SHA-256) participant's signature share, which the Coordinator will aggregate with all other signer's - /// shares into the joint signature. + /// A FROST(secp256k1, SHA-256) participant's signature share, which the Coordinator will + /// aggregate with all other signer's shares into the joint signature. pub type SignatureShare = frost::round2::SignatureShare; /// Performed once by each participant selected for the signing operation. diff --git a/frost/src/error.rs b/frost/src/error.rs index 1d7ff4c9..113986ef 100644 --- a/frost/src/error.rs +++ b/frost/src/error.rs @@ -172,7 +172,8 @@ pub enum FieldError { InvalidZeroScalar, } -/// An error related to a Group (usually an elliptic curve or constructed from one) or one of its Elements. +/// An error related to a Group (usually an elliptic curve or constructed from one) or one of its +/// Elements. #[non_exhaustive] #[derive(Error, Debug, Copy, Clone, Eq, PartialEq)] pub enum GroupError { diff --git a/frost/src/keys.rs b/frost/src/keys.rs index 4ec8c235..15457a65 100644 --- a/frost/src/keys.rs +++ b/frost/src/keys.rs @@ -336,8 +336,8 @@ where /// `n` is the total number of shares and `t` is the threshold required to reconstruct the secret; /// in this case we use Shamir's secret sharing. /// -/// As a solution to the secret polynomial _f_ (a 'point'), the `identifier` is the x-coordinate, and the -/// `value` is the y-coordinate. +/// As a solution to the secret polynomial _f_ (a 'point'), the `identifier` is the x-coordinate, +/// and the `value` is the y-coordinate. /// /// To derive a FROST keypair, the receiver of the [`SecretShare`] *must* call /// .into(), which under the hood also performs validation. @@ -393,15 +393,13 @@ where if !(f_result == result) { // The culprit needs to be identified by the caller if needed, // because this function is called in two different contexts: - // - after trusted dealer key generation, by the participant who - // receives the SecretShare. In that case it does not make sense - // to identify themselves as the culprit, since the issue was with - // the Coordinator or in the communication. - // - during DKG, where a "fake" SecretShare is built just to reuse - // the verification logic and it does make sense to identify the - // culprit. Note that in this case, self.identifier is the caller's - // identifier and not the culprit's, so we couldn't identify - // the culprit inside this function anyway. + // - after trusted dealer key generation, by the participant who receives the + // SecretShare. In that case it does not make sense to identify themselves as the + // culprit, since the issue was with the Coordinator or in the communication. + // - during DKG, where a "fake" SecretShare is built just to reuse the verification + // logic and it does make sense to identify the culprit. Note that in this case, + // self.identifier is the caller's identifier and not the culprit's, so we couldn't + // identify the culprit inside this function anyway. return Err(Error::InvalidSecretShare { culprit: None }); } diff --git a/frost/src/lib.rs b/frost/src/lib.rs index 7a3a7f4b..048442d6 100644 --- a/frost/src/lib.rs +++ b/frost/src/lib.rs @@ -34,8 +34,7 @@ mod scalar_mul; pub mod serialization; mod signature; mod signing_key; -#[cfg(any(test, feature = "test-impl"))] -pub mod tests; + mod traits; mod verifying_key; @@ -560,8 +559,8 @@ where let (signing_package, signature_shares, pubkeys) = ::pre_aggregate(signing_package, signature_shares, pubkeys)?; - // Encodes the signing commitment list produced in round one as part of generating [`BindingFactor`], the - // binding factor. + // Encodes the signing commitment list produced in round one as part of generating + // [`BindingFactor`], the binding factor. let binding_factor_list: BindingFactorList = compute_binding_factor_list(&signing_package, &pubkeys.verifying_key, &[])?; // Compute the group commitment from signing commitments produced in round one. @@ -584,8 +583,8 @@ where // Verify the aggregate signature let verification_result = pubkeys.verifying_key.verify(signing_package.message(), &signature); - // Only if the verification of the aggregate signature failed; verify each share to find the cheater. - // This approach is more efficient since we don't need to verify all shares + // Only if the verification of the aggregate signature failed; verify each share to find the + // cheater. This approach is more efficient since we don't need to verify all shares // if the aggregate signature is valid (which should be the common case). #[cfg(feature = "cheater-detection")] if verification_result.is_err() { @@ -673,8 +672,8 @@ pub fn verify_signature_share( .get(&identifier) .expect("pre_aggregate() must keep the identifiers"); - // Encodes the signing commitment list produced in round one as part of generating [`BindingFactor`], the - // binding factor. + // Encodes the signing commitment list produced in round one as part of generating + // [`BindingFactor`], the binding factor. let binding_factor_list: BindingFactorList = compute_binding_factor_list(&signing_package, verifying_key, &[])?; diff --git a/frost/src/round2.rs b/frost/src/round2.rs index ea600baa..cc72edb4 100644 --- a/frost/src/round2.rs +++ b/frost/src/round2.rs @@ -3,9 +3,7 @@ use core::fmt::{self, Debug}; use crate as frost; -use crate::{ - Challenge, Ciphersuite, Error, Field, Group, {round1, *}, -}; +use crate::{round1, Challenge, Ciphersuite, Error, Field, Group, *}; /// A participant's signature share, which the coordinator will aggregate with all other signer's /// shares into the joint signature. @@ -138,8 +136,8 @@ pub fn sign( let (signing_package, signer_nonces, key_package) = ::pre_sign(signing_package, signer_nonces, key_package)?; - // Encodes the signing commitment list produced in round one as part of generating [`BindingFactor`], the - // binding factor. + // Encodes the signing commitment list produced in round one as part of generating + // [`BindingFactor`], the binding factor. let binding_factor_list: BindingFactorList = compute_binding_factor_list(&signing_package, &key_package.verifying_key, &[])?; let binding_factor: frost::BindingFactor = binding_factor_list diff --git a/frost/src/scalar_mul.rs b/frost/src/scalar_mul.rs index 45230f0f..130578dc 100644 --- a/frost/src/scalar_mul.rs +++ b/frost/src/scalar_mul.rs @@ -22,7 +22,6 @@ use crate::{Ciphersuite, Element, Field, Group, Scalar}; /// /// This function is similar to `div_ceil` that is [available on /// Nightly](https://github.com/rust-lang/rust/issues/88581). -/// // TODO: remove this function and use `div_ceil()` instead when `int_roundings` // is stabilized. const fn div_ceil(lhs: usize, rhs: usize) -> usize { @@ -117,7 +116,8 @@ where // If the window value is even, preserve the carry and continue. // Why is the carry preserved? // If carry == 0 and window & 1 == 0, then the next carry should be 0 - // If carry == 1 and window & 1 == 0, then bit_buf & 1 == 1 so the next carry should be 1 + // If carry == 1 and window & 1 == 0, then bit_buf & 1 == 1 so the next carry should + // be 1 pos += 1; continue; } diff --git a/frost/src/signature.rs b/frost/src/signature.rs index f2fca739..f48bbf3b 100644 --- a/frost/src/signature.rs +++ b/frost/src/signature.rs @@ -54,7 +54,8 @@ where let R_serialization = &R_bytes.try_into().map_err(|_| Error::MalformedSignature)?; - // We extract the exact length of bytes we expect, not just the remaining bytes with `bytes[R_bytes_len..]` + // We extract the exact length of bytes we expect, not just the remaining bytes with + // `bytes[R_bytes_len..]` z_bytes[..].copy_from_slice( bytes .get(R_bytes_len..R_bytes_len + z_bytes_len) diff --git a/frost/src/traits.rs b/frost/src/traits.rs index ae9091fa..700b96de 100644 --- a/frost/src/traits.rs +++ b/frost/src/traits.rs @@ -205,7 +205,8 @@ pub trait Ciphersuite: Copy + Clone + PartialEq + Debug + 'static { /// It can return None if DKG is not supported by the Ciphersuite. This is /// the default implementation. /// - /// Maps arbitrary inputs to non-zero `Self::Scalar` elements of the prime-order group scalar field. + /// Maps arbitrary inputs to non-zero `Self::Scalar` elements of the prime-order group scalar + /// field. fn HDKG(_m: &[u8]) -> Option<<::Field as Field>::Scalar> { None } @@ -216,7 +217,8 @@ pub trait Ciphersuite: Copy + Clone + PartialEq + Debug + 'static { /// way of creating identifiers. Therefore it can return None if this is not supported by the /// Ciphersuite. This is the default implementation. /// - /// Maps arbitrary inputs to non-zero `Self::Scalar` elements of the prime-order group scalar field. + /// Maps arbitrary inputs to non-zero `Self::Scalar` elements of the prime-order group scalar + /// field. fn HID(_m: &[u8]) -> Option<<::Field as Field>::Scalar> { None } diff --git a/pallets/multi-asset-delegation/src/functions/delegate.rs b/pallets/multi-asset-delegation/src/functions/delegate.rs index eac6ad6d..779c6fe0 100644 --- a/pallets/multi-asset-delegation/src/functions/delegate.rs +++ b/pallets/multi-asset-delegation/src/functions/delegate.rs @@ -25,8 +25,10 @@ use sp_runtime::{ DispatchError, Percent, }; use sp_std::vec::Vec; -use tangle_primitives::services::EvmAddressMapping; -use tangle_primitives::{services::Asset, BlueprintId}; +use tangle_primitives::{ + services::{Asset, EvmAddressMapping}, + BlueprintId, +}; impl Pallet { /// Processes the delegation of an amount of an asset to an operator. diff --git a/pallets/services/src/mock.rs b/pallets/services/src/mock.rs index a8066592..8e99f7b2 100644 --- a/pallets/services/src/mock.rs +++ b/pallets/services/src/mock.rs @@ -37,9 +37,7 @@ use sp_runtime::{ traits::{ConvertInto, IdentityLookup}, AccountId32, BuildStorage, Perbill, }; -use tangle_primitives::services::Asset; -use tangle_primitives::services::EvmRunner; -use tangle_primitives::services::{EvmAddressMapping, EvmGasWeightMapping}; +use tangle_primitives::services::{Asset, EvmAddressMapping, EvmGasWeightMapping, EvmRunner}; use core::ops::Mul; use std::{collections::BTreeMap, sync::Arc}; diff --git a/precompiles/multi-asset-delegation/src/mock.rs b/precompiles/multi-asset-delegation/src/mock.rs index 1363148b..aff71710 100644 --- a/precompiles/multi-asset-delegation/src/mock.rs +++ b/precompiles/multi-asset-delegation/src/mock.rs @@ -36,9 +36,10 @@ use sp_runtime::{ traits::{IdentifyAccount, Verify}, AccountId32, BuildStorage, }; -use tangle_primitives::services::EvmAddressMapping; -use tangle_primitives::services::EvmGasWeightMapping; -use tangle_primitives::ServiceManager; +use tangle_primitives::{ + services::{EvmAddressMapping, EvmGasWeightMapping}, + ServiceManager, +}; pub type AccountId = <::Signer as IdentifyAccount>::AccountId; pub type Balance = u64;