Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
drewstone committed Dec 19, 2024
1 parent 13621de commit dfdffca
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 59 deletions.
8 changes: 4 additions & 4 deletions frost/frost-ed448/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -338,8 +338,8 @@ pub type SigningPackage = frost::SigningPackage<E>;
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<E>;

/// Performed once by each participant selected for the signing operation.
Expand Down
8 changes: 4 additions & 4 deletions frost/frost-p384/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -368,8 +368,8 @@ pub type SigningPackage = frost::SigningPackage<P>;
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<P>;

/// Performed once by each participant selected for the signing operation.
Expand Down
24 changes: 11 additions & 13 deletions frost/frost-secp256k1-tr/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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::{
Expand Down Expand Up @@ -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<S>;

/// A secret scalar value representing a signer's share of the group secret.
Expand All @@ -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<S>;

/// 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
Expand All @@ -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.
///
Expand Down Expand Up @@ -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<S>;

/// Performed once by each participant selected for the signing operation.
Expand Down
3 changes: 2 additions & 1 deletion frost/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 9 additions & 11 deletions frost/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 });
}

Expand Down
15 changes: 7 additions & 8 deletions frost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -560,8 +559,8 @@ where
let (signing_package, signature_shares, pubkeys) =
<C>::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<C> =
compute_binding_factor_list(&signing_package, &pubkeys.verifying_key, &[])?;
// Compute the group commitment from signing commitments produced in round one.
Expand All @@ -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() {
Expand Down Expand Up @@ -673,8 +672,8 @@ pub fn verify_signature_share<C: Ciphersuite>(
.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<C> =
compute_binding_factor_list(&signing_package, verifying_key, &[])?;

Expand Down
8 changes: 3 additions & 5 deletions frost/src/round2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -138,8 +136,8 @@ pub fn sign<C: Ciphersuite>(
let (signing_package, signer_nonces, key_package) =
<C>::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<C> =
compute_binding_factor_list(&signing_package, &key_package.verifying_key, &[])?;
let binding_factor: frost::BindingFactor<C> = binding_factor_list
Expand Down
4 changes: 2 additions & 2 deletions frost/src/scalar_mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion frost/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions frost/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<<<Self::Group as Group>::Field as Field>::Scalar> {
None
}
Expand All @@ -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<<<Self::Group as Group>::Field as Field>::Scalar> {
None
}
Expand Down
6 changes: 4 additions & 2 deletions pallets/multi-asset-delegation/src/functions/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config> Pallet<T> {
/// Processes the delegation of an amount of an asset to an operator.
Expand Down
4 changes: 1 addition & 3 deletions pallets/services/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
7 changes: 4 additions & 3 deletions precompiles/multi-asset-delegation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
pub type Balance = u64;
Expand Down

0 comments on commit dfdffca

Please sign in to comment.