mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 12:49:23 +00:00
Refine from pedantic, remove erratic consts
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use core::{ops::Deref, fmt};
|
||||
use std::{io, collections::HashMap};
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
use zeroize::{Zeroize, Zeroizing};
|
||||
use rand_core::{RngCore, CryptoRng};
|
||||
|
||||
@@ -68,7 +70,7 @@ impl<C: Ciphersuite, M: Message> EncryptionKeyMessage<C, M> {
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "tests"))]
|
||||
pub(crate) const fn enc_key(&self) -> C::G {
|
||||
pub(crate) fn enc_key(&self) -> C::G {
|
||||
self.enc_key
|
||||
}
|
||||
}
|
||||
@@ -328,19 +330,13 @@ fn encryption_key_transcript(context: &str) -> RecommendedTranscript {
|
||||
transcript
|
||||
}
|
||||
|
||||
#[allow(clippy::std_instead_of_core)]
|
||||
mod decryption_error {
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Error)]
|
||||
pub(crate) enum DecryptionError {
|
||||
#[error("accused provided an invalid signature")]
|
||||
InvalidSignature,
|
||||
#[error("accuser provided an invalid decryption key")]
|
||||
InvalidProof,
|
||||
}
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Error)]
|
||||
pub(crate) enum DecryptionError {
|
||||
#[error("accused provided an invalid signature")]
|
||||
InvalidSignature,
|
||||
#[error("accuser provided an invalid decryption key")]
|
||||
InvalidProof,
|
||||
}
|
||||
pub(crate) use decryption_error::DecryptionError;
|
||||
|
||||
// A simple box for managing encryption.
|
||||
#[derive(Clone)]
|
||||
@@ -386,7 +382,7 @@ impl<C: Ciphersuite> Encryption<C> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const fn registration<M: Message>(&self, msg: M) -> EncryptionKeyMessage<C, M> {
|
||||
pub(crate) fn registration<M: Message>(&self, msg: M) -> EncryptionKeyMessage<C, M> {
|
||||
EncryptionKeyMessage { msg, enc_key: self.enc_pub_key }
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ impl<C: Ciphersuite> KeyGenMachine<C> {
|
||||
/// Create a new machine to generate a key.
|
||||
///
|
||||
/// The context string should be unique among multisigs.
|
||||
pub const fn new(params: ThresholdParams, context: String) -> Self {
|
||||
pub fn new(params: ThresholdParams, context: String) -> Self {
|
||||
Self { params, context, curve: PhantomData }
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use core::fmt::{self, Debug};
|
||||
extern crate alloc;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
use zeroize::Zeroize;
|
||||
|
||||
@@ -61,58 +62,49 @@ impl fmt::Display for Participant {
|
||||
}
|
||||
|
||||
/// Various errors possible during key generation.
|
||||
#[allow(clippy::std_instead_of_core)]
|
||||
mod dkg_error {
|
||||
use core::fmt::Debug;
|
||||
use thiserror::Error;
|
||||
use super::Participant;
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
#[cfg_attr(feature = "std", derive(Error))]
|
||||
pub enum DkgError<B: Clone + PartialEq + Eq + Debug> {
|
||||
/// A parameter was zero.
|
||||
#[cfg_attr(feature = "std", error("a parameter was 0 (threshold {0}, participants {1})"))]
|
||||
ZeroParameter(u16, u16),
|
||||
/// The threshold exceeded the amount of participants.
|
||||
#[cfg_attr(feature = "std", error("invalid threshold (max {1}, got {0})"))]
|
||||
InvalidThreshold(u16, u16),
|
||||
/// Invalid participant identifier.
|
||||
#[cfg_attr(
|
||||
feature = "std",
|
||||
error("invalid participant (0 < participant <= {0}, yet participant is {1})")
|
||||
)]
|
||||
InvalidParticipant(u16, Participant),
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
#[cfg_attr(feature = "std", derive(Error))]
|
||||
pub enum DkgError<B: Clone + PartialEq + Eq + Debug> {
|
||||
/// A parameter was zero.
|
||||
#[cfg_attr(feature = "std", error("a parameter was 0 (threshold {0}, participants {1})"))]
|
||||
ZeroParameter(u16, u16),
|
||||
/// The threshold exceeded the amount of participants.
|
||||
#[cfg_attr(feature = "std", error("invalid threshold (max {1}, got {0})"))]
|
||||
InvalidThreshold(u16, u16),
|
||||
/// Invalid participant identifier.
|
||||
#[cfg_attr(
|
||||
feature = "std",
|
||||
error("invalid participant (0 < participant <= {0}, yet participant is {1})")
|
||||
)]
|
||||
InvalidParticipant(u16, Participant),
|
||||
/// Invalid signing set.
|
||||
#[cfg_attr(feature = "std", error("invalid signing set"))]
|
||||
InvalidSigningSet,
|
||||
/// Invalid amount of participants.
|
||||
#[cfg_attr(feature = "std", error("invalid participant quantity (expected {0}, got {1})"))]
|
||||
InvalidParticipantQuantity(usize, usize),
|
||||
/// A participant was duplicated.
|
||||
#[cfg_attr(feature = "std", error("duplicated participant ({0})"))]
|
||||
DuplicatedParticipant(Participant),
|
||||
/// A participant was missing.
|
||||
#[cfg_attr(feature = "std", error("missing participant {0}"))]
|
||||
MissingParticipant(Participant),
|
||||
|
||||
/// Invalid signing set.
|
||||
#[cfg_attr(feature = "std", error("invalid signing set"))]
|
||||
InvalidSigningSet,
|
||||
/// Invalid amount of participants.
|
||||
#[cfg_attr(feature = "std", error("invalid participant quantity (expected {0}, got {1})"))]
|
||||
InvalidParticipantQuantity(usize, usize),
|
||||
/// A participant was duplicated.
|
||||
#[cfg_attr(feature = "std", error("duplicated participant ({0})"))]
|
||||
DuplicatedParticipant(Participant),
|
||||
/// A participant was missing.
|
||||
#[cfg_attr(feature = "std", error("missing participant {0}"))]
|
||||
MissingParticipant(Participant),
|
||||
|
||||
/// An invalid proof of knowledge was provided.
|
||||
#[cfg_attr(feature = "std", error("invalid proof of knowledge (participant {0})"))]
|
||||
InvalidProofOfKnowledge(Participant),
|
||||
/// An invalid DKG share was provided.
|
||||
#[cfg_attr(feature = "std", error("invalid share (participant {participant}, blame {blame})"))]
|
||||
InvalidShare { participant: Participant, blame: Option<B> },
|
||||
}
|
||||
/// An invalid proof of knowledge was provided.
|
||||
#[cfg_attr(feature = "std", error("invalid proof of knowledge (participant {0})"))]
|
||||
InvalidProofOfKnowledge(Participant),
|
||||
/// An invalid DKG share was provided.
|
||||
#[cfg_attr(feature = "std", error("invalid share (participant {participant}, blame {blame})"))]
|
||||
InvalidShare { participant: Participant, blame: Option<B> },
|
||||
}
|
||||
pub use dkg_error::DkgError;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
mod lib {
|
||||
pub use super::*;
|
||||
|
||||
use core::ops::Deref;
|
||||
use alloc::sync::Arc;
|
||||
use std::{io, collections::HashMap};
|
||||
use std::{sync::Arc, io, collections::HashMap};
|
||||
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
@@ -268,17 +260,17 @@ mod lib {
|
||||
}
|
||||
|
||||
/// Parameters for these keys.
|
||||
pub const fn params(&self) -> ThresholdParams {
|
||||
pub fn params(&self) -> ThresholdParams {
|
||||
self.params
|
||||
}
|
||||
|
||||
/// Secret share for these keys.
|
||||
pub const fn secret_share(&self) -> &Zeroizing<C::F> {
|
||||
pub fn secret_share(&self) -> &Zeroizing<C::F> {
|
||||
&self.secret_share
|
||||
}
|
||||
|
||||
/// Group key for these keys.
|
||||
pub const fn group_key(&self) -> C::G {
|
||||
pub fn group_key(&self) -> C::G {
|
||||
self.group_key
|
||||
}
|
||||
|
||||
@@ -432,7 +424,7 @@ mod lib {
|
||||
}
|
||||
|
||||
/// Return the current offset in-use for these keys.
|
||||
pub const fn current_offset(&self) -> Option<C::F> {
|
||||
pub fn current_offset(&self) -> Option<C::F> {
|
||||
self.offset
|
||||
}
|
||||
|
||||
@@ -506,12 +498,12 @@ mod lib {
|
||||
|
||||
impl<C: Ciphersuite> ThresholdView<C> {
|
||||
/// Return the offset for this view.
|
||||
pub const fn offset(&self) -> C::F {
|
||||
pub fn offset(&self) -> C::F {
|
||||
self.offset
|
||||
}
|
||||
|
||||
/// Return the group key.
|
||||
pub const fn group_key(&self) -> C::G {
|
||||
pub fn group_key(&self) -> C::G {
|
||||
self.group_key
|
||||
}
|
||||
|
||||
@@ -521,7 +513,7 @@ mod lib {
|
||||
}
|
||||
|
||||
/// Return the interpolated, offset secret share.
|
||||
pub const fn secret_share(&self) -> &Zeroizing<C::F> {
|
||||
pub fn secret_share(&self) -> &Zeroizing<C::F> {
|
||||
&self.secret_share
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use core::{marker::PhantomData, ops::Deref};
|
||||
use alloc::sync::Arc;
|
||||
use std::{
|
||||
sync::Arc,
|
||||
io::{self, Read, Write},
|
||||
collections::HashMap,
|
||||
};
|
||||
|
||||
@@ -41,7 +41,7 @@ impl<G0: PrimeGroup, G1: PrimeGroup> Re<G0, G1> {
|
||||
Self::R(G0::identity(), G1::identity())
|
||||
}
|
||||
|
||||
pub(crate) const fn e_default() -> Self {
|
||||
pub(crate) fn e_default() -> Self {
|
||||
Self::e(G0::Scalar::ZERO)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ pub(crate) enum BitSignature {
|
||||
}
|
||||
|
||||
impl BitSignature {
|
||||
pub(crate) const fn to_u8(&self) -> u8 {
|
||||
pub(crate) fn to_u8(&self) -> u8 {
|
||||
match self {
|
||||
Self::ClassicLinear => 0,
|
||||
Self::ConciseLinear => 1,
|
||||
@@ -35,7 +35,7 @@ impl BitSignature {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const fn from(algorithm: u8) -> Self {
|
||||
pub(crate) fn from(algorithm: u8) -> Self {
|
||||
match algorithm {
|
||||
0 => Self::ClassicLinear,
|
||||
1 => Self::ConciseLinear,
|
||||
@@ -45,14 +45,14 @@ impl BitSignature {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const fn bits(&self) -> usize {
|
||||
pub(crate) fn bits(&self) -> usize {
|
||||
match self {
|
||||
Self::ClassicLinear | Self::EfficientLinear => 1,
|
||||
Self::ConciseLinear | Self::CompromiseLinear => 2,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const fn ring_len(&self) -> usize {
|
||||
pub(crate) fn ring_len(&self) -> usize {
|
||||
#[allow(clippy::as_conversions, clippy::cast_possible_truncation)] // Needed for const
|
||||
2_usize.pow(self.bits() as u32)
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@ use core::ops::{Deref, DerefMut};
|
||||
#[cfg(feature = "serialize")]
|
||||
use std::io::{self, Read, Write};
|
||||
|
||||
use rand_core::{RngCore, CryptoRng};
|
||||
use thiserror::Error;
|
||||
|
||||
use zeroize::{Zeroize, Zeroizing};
|
||||
use rand_core::{RngCore, CryptoRng};
|
||||
|
||||
use digest::{Digest, HashMarker};
|
||||
|
||||
@@ -92,27 +93,21 @@ impl<G: PrimeGroup> Generators<G> {
|
||||
}
|
||||
|
||||
/// Error for cross-group DLEq proofs.
|
||||
#[allow(clippy::std_instead_of_core)]
|
||||
mod dleq_error {
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, PartialEq, Eq, Debug)]
|
||||
pub enum DLEqError {
|
||||
/// Invalid proof of knowledge.
|
||||
#[error("invalid proof of knowledge")]
|
||||
InvalidProofOfKnowledge,
|
||||
/// Invalid proof length.
|
||||
#[error("invalid proof length")]
|
||||
InvalidProofLength,
|
||||
/// Invalid challenge.
|
||||
#[error("invalid challenge")]
|
||||
InvalidChallenge,
|
||||
/// Invalid proof.
|
||||
#[error("invalid proof")]
|
||||
InvalidProof,
|
||||
}
|
||||
#[derive(Error, PartialEq, Eq, Debug)]
|
||||
pub enum DLEqError {
|
||||
/// Invalid proof of knowledge.
|
||||
#[error("invalid proof of knowledge")]
|
||||
InvalidProofOfKnowledge,
|
||||
/// Invalid proof length.
|
||||
#[error("invalid proof length")]
|
||||
InvalidProofLength,
|
||||
/// Invalid challenge.
|
||||
#[error("invalid challenge")]
|
||||
InvalidChallenge,
|
||||
/// Invalid proof.
|
||||
#[error("invalid proof")]
|
||||
InvalidProof,
|
||||
}
|
||||
pub use dleq_error::DLEqError;
|
||||
|
||||
// This should never be directly instantiated and uses a u8 to represent internal values
|
||||
// Any external usage is likely invalid
|
||||
|
||||
@@ -147,7 +147,7 @@ pub type IetfSchnorr<C, H> = Schnorr<C, IetfTranscript, H>;
|
||||
|
||||
impl<C: Curve, T: Sync + Clone + Debug + Transcript, H: Hram<C>> Schnorr<C, T, H> {
|
||||
/// Construct a Schnorr algorithm continuing the specified transcript.
|
||||
pub const fn new(transcript: T) -> Self {
|
||||
pub fn new(transcript: T) -> Self {
|
||||
Self { transcript, c: None, _hram: PhantomData }
|
||||
}
|
||||
}
|
||||
@@ -156,7 +156,7 @@ impl<C: Curve, H: Hram<C>> IetfSchnorr<C, H> {
|
||||
/// Construct a IETF-compatible Schnorr algorithm.
|
||||
///
|
||||
/// Please see the `IetfSchnorr` documentation for the full details of this.
|
||||
pub const fn ietf() -> Self {
|
||||
pub fn ietf() -> Self {
|
||||
Self::new(IetfTranscript(vec![]))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
#![doc = include_str!("../README.md")]
|
||||
|
||||
use core::fmt::Debug;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
/// Distributed key generation protocol.
|
||||
pub use dkg::{self, Participant, ThresholdParams, ThresholdCore, ThresholdKeys, ThresholdView};
|
||||
|
||||
@@ -20,32 +23,25 @@ pub mod sign;
|
||||
#[cfg(any(test, feature = "tests"))]
|
||||
pub mod tests;
|
||||
|
||||
#[allow(clippy::std_instead_of_core)]
|
||||
mod frost_error {
|
||||
use core::fmt::Debug;
|
||||
use thiserror::Error;
|
||||
use dkg::Participant;
|
||||
/// Various errors possible during signing.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Error)]
|
||||
pub enum FrostError {
|
||||
#[error("invalid participant (0 < participant <= {0}, yet participant is {1})")]
|
||||
InvalidParticipant(u16, Participant),
|
||||
#[error("invalid signing set ({0})")]
|
||||
InvalidSigningSet(&'static str),
|
||||
#[error("invalid participant quantity (expected {0}, got {1})")]
|
||||
InvalidParticipantQuantity(usize, usize),
|
||||
#[error("duplicated participant ({0})")]
|
||||
DuplicatedParticipant(Participant),
|
||||
#[error("missing participant {0}")]
|
||||
MissingParticipant(Participant),
|
||||
/// Various errors possible during signing.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Error)]
|
||||
pub enum FrostError {
|
||||
#[error("invalid participant (0 < participant <= {0}, yet participant is {1})")]
|
||||
InvalidParticipant(u16, Participant),
|
||||
#[error("invalid signing set ({0})")]
|
||||
InvalidSigningSet(&'static str),
|
||||
#[error("invalid participant quantity (expected {0}, got {1})")]
|
||||
InvalidParticipantQuantity(usize, usize),
|
||||
#[error("duplicated participant ({0})")]
|
||||
DuplicatedParticipant(Participant),
|
||||
#[error("missing participant {0}")]
|
||||
MissingParticipant(Participant),
|
||||
|
||||
#[error("invalid preprocess (participant {0})")]
|
||||
InvalidPreprocess(Participant),
|
||||
#[error("invalid share (participant {0})")]
|
||||
InvalidShare(Participant),
|
||||
}
|
||||
#[error("invalid preprocess (participant {0})")]
|
||||
InvalidPreprocess(Participant),
|
||||
#[error("invalid share (participant {0})")]
|
||||
InvalidShare(Participant),
|
||||
}
|
||||
pub use frost_error::FrostError;
|
||||
|
||||
/// Validate a map of values to have the expected participants.
|
||||
pub fn validate_map<T>(
|
||||
|
||||
@@ -53,7 +53,7 @@ struct Params<C: Curve, A: Algorithm<C>> {
|
||||
}
|
||||
|
||||
impl<C: Curve, A: Algorithm<C>> Params<C, A> {
|
||||
const fn new(algorithm: A, keys: ThresholdKeys<C>) -> Self {
|
||||
fn new(algorithm: A, keys: ThresholdKeys<C>) -> Self {
|
||||
Self { algorithm, keys }
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ pub struct AlgorithmMachine<C: Curve, A: Algorithm<C>> {
|
||||
|
||||
impl<C: Curve, A: Algorithm<C>> AlgorithmMachine<C, A> {
|
||||
/// Creates a new machine to generate a signature with the specified keys.
|
||||
pub const fn new(algorithm: A, keys: ThresholdKeys<C>) -> Self {
|
||||
pub fn new(algorithm: A, keys: ThresholdKeys<C>) -> Self {
|
||||
Self { params: Params::new(algorithm, keys) }
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ Pippenger 6 is more efficient at 250 with 655µs per
|
||||
Pippenger 7 is more efficient at 475 with 500µs per
|
||||
Pippenger 8 is more efficient at 875 with 499µs per
|
||||
*/
|
||||
const fn algorithm(len: usize) -> Algorithm {
|
||||
fn algorithm(len: usize) -> Algorithm {
|
||||
#[cfg(not(debug_assertions))]
|
||||
if len == 0 {
|
||||
Algorithm::Null
|
||||
|
||||
@@ -61,7 +61,7 @@ enum DigestTranscriptMember {
|
||||
}
|
||||
|
||||
impl DigestTranscriptMember {
|
||||
const fn as_u8(&self) -> u8 {
|
||||
fn as_u8(&self) -> u8 {
|
||||
match self {
|
||||
Self::Name => 0,
|
||||
Self::Domain => 1,
|
||||
|
||||
Reference in New Issue
Block a user