diff --git a/Cargo.lock b/Cargo.lock index 331f80a7454..f9df08d9396 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4016,7 +4016,7 @@ dependencies = [ [[package]] name = "mithril-common" -version = "0.6.35" +version = "0.6.37" dependencies = [ "anyhow", "async-trait", @@ -4294,7 +4294,7 @@ dependencies = [ [[package]] name = "mithril-stm" -version = "0.6.3" +version = "0.6.4" dependencies = [ "anyhow", "blake2 0.10.6", diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 7c088aedd1a..1c0cfcf0e5c 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-common" -version = "0.6.35" +version = "0.6.37" description = "Common types, interfaces, and utilities for Mithril nodes." authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-common/src/protocol/multi_signer.rs b/mithril-common/src/protocol/multi_signer.rs index b3476640263..4973cc847b1 100644 --- a/mithril-common/src/protocol/multi_signer.rs +++ b/mithril-common/src/protocol/multi_signer.rs @@ -91,7 +91,7 @@ impl MultiSigner { #[cfg(test)] mod test { - use mithril_stm::MultiSignatureError; + use mithril_stm::BlsSignatureError; use crate::{ crypto_helper::ProtocolAggregationError, @@ -195,8 +195,8 @@ mod test { "Verify single signature should fail if the signer isn't in the registered parties", ); - match error.downcast_ref::() { - Some(MultiSignatureError::SignatureInvalid(_)) => (), + match error.downcast_ref::() { + Some(BlsSignatureError::SignatureInvalid(_)) => (), _ => panic!("Expected an SignatureInvalid error, got: {error:?}"), } } @@ -221,8 +221,8 @@ mod test { .verify_single_signature(&ProtocolMessage::default(), &single_signature) .expect_err("Verify single signature should fail"); - match error.downcast_ref::() { - Some(MultiSignatureError::SignatureInvalid(_)) => (), + match error.downcast_ref::() { + Some(BlsSignatureError::SignatureInvalid(_)) => (), _ => panic!("Expected an SignatureInvalid error, got: {error:?}"), } } diff --git a/mithril-stm/CHANGELOG.md b/mithril-stm/CHANGELOG.md index f3aa3bcf4eb..642fc4e5893 100644 --- a/mithril-stm/CHANGELOG.md +++ b/mithril-stm/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.6.4 (12-12-2025) + +### Changed + +- Error types in the Stm library moved to corresponding sub-modules. + ## 0.6.2 (11-27-2025) ### Changed diff --git a/mithril-stm/Cargo.toml b/mithril-stm/Cargo.toml index 09a33778454..a7d22bcb28a 100644 --- a/mithril-stm/Cargo.toml +++ b/mithril-stm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-stm" -version = "0.6.3" +version = "0.6.4" edition = { workspace = true } authors = { workspace = true } homepage = { workspace = true } @@ -17,8 +17,7 @@ crate-type = ["lib", "cdylib", "staticlib"] default = ["rug-backend"] rug-backend = ["rug/default"] num-integer-backend = ["dep:num-bigint", "dep:num-rational", "dep:num-traits"] -benchmark-internals = [] # For benchmarking multi_sig -future_proof_system = [] # For activating future proof systems +benchmark-internals = [] # For benchmarking future_snark = [ "dep:ff", "dep:group", @@ -73,7 +72,7 @@ required-features = ["benchmark-internals"] [[bench]] name = "schnorr_sig" harness = false -required-features = ["future_snark"] +required-features = ["future_snark", "benchmark-internals"] [[bench]] name = "stm" diff --git a/mithril-stm/src/lib.rs b/mithril-stm/src/lib.rs index a6b06f0f9ca..bf4864635e9 100644 --- a/mithril-stm/src/lib.rs +++ b/mithril-stm/src/lib.rs @@ -117,6 +117,7 @@ mod protocol; mod signature_scheme; pub use protocol::*; +pub use signature_scheme::BlsSignatureError; #[cfg(feature = "benchmark-internals")] pub use signature_scheme::{ diff --git a/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs b/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs index 561c9038380..845f8c2289e 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/commitment.rs @@ -1,10 +1,12 @@ +use std::marker::PhantomData; + use anyhow::{Context, anyhow}; use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; -use std::marker::PhantomData; -use super::{MerkleBatchPath, MerklePath, MerkleTreeLeaf, parent, sibling}; -use crate::{MerkleTreeError, StmResult}; +use crate::StmResult; + +use super::{MerkleBatchPath, MerklePath, MerkleTreeError, MerkleTreeLeaf, parent, sibling}; /// `MerkleTree` commitment. /// This structure differs from `MerkleTree` in that it does not contain all elements, which are not always necessary. diff --git a/mithril-stm/src/membership_commitment/merkle_tree/error.rs b/mithril-stm/src/membership_commitment/merkle_tree/error.rs new file mode 100644 index 00000000000..f1af9f82471 --- /dev/null +++ b/mithril-stm/src/membership_commitment/merkle_tree/error.rs @@ -0,0 +1,15 @@ +/// Error types related to merkle trees. +#[derive(Debug, Clone, thiserror::Error)] +pub enum MerkleTreeError { + /// Serialization error + #[error("Serialization of a merkle tree failed")] + SerializationError, + + /// Invalid merkle path + #[error("Path does not verify against root")] + PathInvalid(Vec), + + /// Invalid merkle batch path + #[error("Batch path does not verify against root")] + BatchPathInvalid(Vec), +} diff --git a/mithril-stm/src/membership_commitment/merkle_tree/leaf.rs b/mithril-stm/src/membership_commitment/merkle_tree/leaf.rs index 0a77e907405..8ebdf658ab8 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/leaf.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/leaf.rs @@ -2,9 +2,9 @@ use std::cmp::Ordering; use serde::{Deserialize, Serialize}; -use crate::{ - MerkleTreeError, Stake, StmResult, VerificationKey, signature_scheme::BlsVerificationKey, -}; +use crate::{Stake, StmResult, VerificationKey, signature_scheme::BlsVerificationKey}; + +use super::MerkleTreeError; /// The values that are committed in the Merkle Tree. /// Namely, a verified `VerificationKey` and its corresponding stake. diff --git a/mithril-stm/src/membership_commitment/merkle_tree/mod.rs b/mithril-stm/src/membership_commitment/merkle_tree/mod.rs index 1b14c4a3c80..89f5e07f1e3 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/mod.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/mod.rs @@ -1,11 +1,13 @@ //! Merkle tree implementation for STM mod commitment; +mod error; mod leaf; mod path; mod tree; pub use commitment::*; +pub use error::*; pub use leaf::*; pub use path::*; pub use tree::*; diff --git a/mithril-stm/src/membership_commitment/merkle_tree/path.rs b/mithril-stm/src/membership_commitment/merkle_tree/path.rs index 80aaa9c0c89..5d38ef97837 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/path.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/path.rs @@ -1,8 +1,11 @@ +use std::marker::PhantomData; + use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; -use std::marker::PhantomData; -use crate::{MerkleTreeError, StmResult}; +use crate::StmResult; + +use super::MerkleTreeError; /// Path of hashes from root to leaf in a Merkle Tree. /// Contains all hashes on the path, and the index of the leaf. diff --git a/mithril-stm/src/membership_commitment/merkle_tree/tree.rs b/mithril-stm/src/membership_commitment/merkle_tree/tree.rs index acd4de54247..01c3b3b07f7 100644 --- a/mithril-stm/src/membership_commitment/merkle_tree/tree.rs +++ b/mithril-stm/src/membership_commitment/merkle_tree/tree.rs @@ -1,12 +1,14 @@ +use std::marker::PhantomData; + use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; -use std::marker::PhantomData; + +use crate::StmResult; use super::{ - MerkleBatchPath, MerklePath, MerkleTreeBatchCommitment, MerkleTreeCommitment, MerkleTreeLeaf, - left_child, parent, right_child, sibling, + MerkleBatchPath, MerklePath, MerkleTreeBatchCommitment, MerkleTreeCommitment, MerkleTreeError, + MerkleTreeLeaf, left_child, parent, right_child, sibling, }; -use crate::{MerkleTreeError, StmResult}; /// Tree of hashes, providing a commitment of data and its ordering. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs b/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs index b398b773fc0..0b14021123d 100644 --- a/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs +++ b/mithril-stm/src/protocol/aggregate_signature/basic_verifier.rs @@ -1,13 +1,16 @@ -use anyhow::{Context, anyhow}; use std::collections::{BTreeMap, HashMap, HashSet}; +use anyhow::{Context, anyhow}; + use crate::{ - AggregationError, Index, Parameters, RegisteredParty, SingleSignature, - SingleSignatureWithRegisteredParty, Stake, StmResult, + Index, Parameters, RegisteredParty, SingleSignature, SingleSignatureWithRegisteredParty, Stake, + StmResult, membership_commitment::MerkleTreeLeaf, signature_scheme::{BlsSignature, BlsVerificationKey}, }; +use super::AggregationError; + /// Full node verifier including the list of eligible signers and the total stake of the system. pub struct BasicVerifier { /// List of registered parties. diff --git a/mithril-stm/src/protocol/aggregate_signature/clerk.rs b/mithril-stm/src/protocol/aggregate_signature/clerk.rs index d4d6ea05fd0..8a76709c2b6 100644 --- a/mithril-stm/src/protocol/aggregate_signature/clerk.rs +++ b/mithril-stm/src/protocol/aggregate_signature/clerk.rs @@ -1,18 +1,19 @@ use anyhow::Context; use blake2::digest::{Digest, FixedOutput}; -#[cfg(feature = "future_proof_system")] +#[cfg(feature = "future_snark")] use anyhow::anyhow; -#[cfg(feature = "future_proof_system")] -use crate::AggregationError; +#[cfg(feature = "future_snark")] +use super::AggregationError; -use super::{AggregateSignature, AggregateSignatureType, AggregateVerificationKey}; use crate::{ ClosedKeyRegistration, Index, Parameters, Signer, SingleSignature, Stake, StmResult, VerificationKey, proof_system::ConcatenationProof, }; +use super::{AggregateSignature, AggregateSignatureType, AggregateVerificationKey}; + /// `Clerk` can verify and aggregate `SingleSignature`s and verify `AggregateSignature`s. /// Clerks can only be generated with the registration closed. /// This avoids that a Merkle Tree is computed before all parties have registered. @@ -89,7 +90,7 @@ impl Clerk { ) })?, )), - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignatureType::Future => Err(anyhow!( AggregationError::UnsupportedProofSystem(aggregate_signature_type) )), diff --git a/mithril-stm/src/protocol/aggregate_signature/error.rs b/mithril-stm/src/protocol/aggregate_signature/error.rs new file mode 100644 index 00000000000..dc7d561f759 --- /dev/null +++ b/mithril-stm/src/protocol/aggregate_signature/error.rs @@ -0,0 +1,32 @@ +use super::AggregateSignatureType; + +/// Error types for aggregation. +#[derive(Debug, Clone, thiserror::Error)] +pub enum AggregationError { + /// Not enough signatures were collected, got this many instead. + #[error("Not enough signatures. Got only {0} out of {1}.")] + NotEnoughSignatures(u64, u64), + + #[error("Unsupported proof system: {0}")] + UnsupportedProofSystem(AggregateSignatureType), + + /// There is a duplicate index + #[error("Indices are not unique.")] + IndexNotUnique, +} + +/// Errors which can be output by Mithril aggregate verification. +#[derive(Debug, Clone, thiserror::Error)] +pub enum AggregateSignatureError { + /// This error occurs when the serialization of the raw bytes failed + #[error("Invalid bytes")] + SerializationError, + + /// Batch verification of STM aggregate signatures failed + #[error("Batch verification of STM aggregate signatures failed")] + BatchInvalid, + + /// The proof system used in the aggregate signature is not supported + #[error("Unsupported proof system: {0}")] + UnsupportedProofSystem(AggregateSignatureType), +} diff --git a/mithril-stm/src/protocol/aggregate_signature/mod.rs b/mithril-stm/src/protocol/aggregate_signature/mod.rs index 317afb68ba4..3a59f190d0e 100644 --- a/mithril-stm/src/protocol/aggregate_signature/mod.rs +++ b/mithril-stm/src/protocol/aggregate_signature/mod.rs @@ -1,11 +1,13 @@ mod aggregate_key; mod basic_verifier; mod clerk; +mod error; mod signature; pub use aggregate_key::*; pub use basic_verifier::*; pub use clerk::*; +pub use error::*; pub use signature::*; #[cfg(test)] @@ -20,13 +22,16 @@ mod tests { use rand_core::{RngCore, SeedableRng}; use std::collections::{HashMap, HashSet}; - use super::{AggregateSignature, AggregateSignatureType, BasicVerifier, Clerk}; use crate::{ - AggregationError, Initializer, KeyRegistration, Parameters, Signer, SingleSignature, + Initializer, KeyRegistration, Parameters, Signer, SingleSignature, SingleSignatureWithRegisteredParty, Stake, StmResult, membership_commitment::MerkleBatchPath, signature_scheme::BlsVerificationKey, }; + use super::{ + AggregateSignature, AggregateSignatureType, AggregationError, BasicVerifier, Clerk, + }; + type Sig = AggregateSignature; type D = Blake2b; diff --git a/mithril-stm/src/protocol/aggregate_signature/signature.rs b/mithril-stm/src/protocol/aggregate_signature/signature.rs index f0b4aa53f1c..6f5ced1b63e 100644 --- a/mithril-stm/src/protocol/aggregate_signature/signature.rs +++ b/mithril-stm/src/protocol/aggregate_signature/signature.rs @@ -4,12 +4,13 @@ use anyhow::anyhow; use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; -use super::AggregateVerificationKey; use crate::{ - AggregateSignatureError, Parameters, StmError, StmResult, - membership_commitment::MerkleBatchPath, proof_system::ConcatenationProof, + Parameters, StmError, StmResult, membership_commitment::MerkleBatchPath, + proof_system::ConcatenationProof, }; +use super::{AggregateSignatureError, AggregateVerificationKey}; + /// The type of STM aggregate signature. #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum AggregateSignatureType { @@ -17,7 +18,7 @@ pub enum AggregateSignatureType { #[default] Concatenation, /// Future proof system. Not suitable for production. - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] Future, } @@ -28,7 +29,7 @@ impl AggregateSignatureType { pub fn get_byte_encoding_prefix(&self) -> u8 { match self { AggregateSignatureType::Concatenation => 0, - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignatureType::Future => 255, } } @@ -39,7 +40,7 @@ impl AggregateSignatureType { pub fn from_byte_encoding_prefix(byte: u8) -> Option { match byte { 0 => Some(AggregateSignatureType::Concatenation), - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] 255 => Some(AggregateSignatureType::Future), _ => None, } @@ -52,7 +53,7 @@ impl From<&AggregateSignature> fn from(aggr_sig: &AggregateSignature) -> Self { match aggr_sig { AggregateSignature::Concatenation(_) => AggregateSignatureType::Concatenation, - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignature::Future => AggregateSignatureType::Future, } } @@ -64,7 +65,7 @@ impl FromStr for AggregateSignatureType { fn from_str(s: &str) -> Result { match s { "Concatenation" => Ok(AggregateSignatureType::Concatenation), - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] "Future" => Ok(AggregateSignatureType::Future), _ => Err(anyhow!("Unknown aggregate signature type: {}", s)), } @@ -75,7 +76,7 @@ impl Display for AggregateSignatureType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { AggregateSignatureType::Concatenation => write!(f, "Concatenation"), - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignatureType::Future => write!(f, "Future"), } } @@ -89,7 +90,7 @@ impl Display for AggregateSignatureType { ))] pub enum AggregateSignature { /// A future proof system. - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] Future, /// Concatenation proof system. @@ -112,7 +113,7 @@ impl AggregateSignature { AggregateSignature::Concatenation(concatenation_proof) => { concatenation_proof.verify(msg, avk, parameters) } - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignature::Future => Err(anyhow!( AggregateSignatureError::UnsupportedProofSystem(self.into()) )), @@ -145,7 +146,7 @@ impl AggregateSignature { ConcatenationProof::batch_verify(&concatenation_proofs, msgs, avks, parameters) } - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignatureType::Future => Err(anyhow!( AggregateSignatureError::UnsupportedProofSystem(aggregate_signature_type) )), @@ -164,7 +165,7 @@ impl AggregateSignature { AggregateSignature::Concatenation(concatenation_proof) => { concatenation_proof.to_bytes() } - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignature::Future => vec![], }; aggregate_signature_bytes.append(&mut proof_bytes); @@ -182,7 +183,7 @@ impl AggregateSignature { AggregateSignatureType::Concatenation => Ok(AggregateSignature::Concatenation( ConcatenationProof::from_bytes(proof_bytes)?, )), - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignatureType::Future => Ok(AggregateSignature::Future), } } @@ -191,7 +192,7 @@ impl AggregateSignature { pub fn to_concatenation_proof(&self) -> Option<&ConcatenationProof> { match self { AggregateSignature::Concatenation(proof) => Some(proof), - #[cfg(feature = "future_proof_system")] + #[cfg(feature = "future_snark")] AggregateSignature::Future => None, } } diff --git a/mithril-stm/src/protocol/error.rs b/mithril-stm/src/protocol/error.rs index 8bb8e12309c..410498b3bfd 100644 --- a/mithril-stm/src/protocol/error.rs +++ b/mithril-stm/src/protocol/error.rs @@ -1,106 +1,4 @@ -//! Crate specific errors -use anyhow::anyhow; -use blst::BLST_ERROR; - -use crate::{ - AggregateSignatureType, StmResult, - signature_scheme::{BlsSignature, BlsVerificationKey, BlsVerificationKeyProofOfPossession}, -}; - -/// Error types for multi signatures. -#[derive(Debug, thiserror::Error, Eq, PartialEq)] -pub enum MultiSignatureError { - /// Invalid Single signature - #[error("Invalid single signature")] - SignatureInvalid(BlsSignature), - - /// Invalid aggregate signature - #[error("Invalid aggregated signature")] - AggregateSignatureInvalid, - - /// This error occurs when the the serialization of the raw bytes failed - #[error("Invalid bytes")] - SerializationError, - - /// Incorrect proof of possession - #[error("Key with invalid PoP")] - KeyInvalid(Box), - - /// At least one signature in the batch is invalid - #[error("One signature in the batch is invalid")] - BatchInvalid, - - /// Single signature is the infinity - #[error("Single signature is the infinity")] - SignatureInfinity(BlsSignature), - - /// Verification key is the infinity - #[error("Verification key is the infinity")] - VerificationKeyInfinity(Box), -} - -/// Error types related to merkle trees. -#[derive(Debug, Clone, thiserror::Error)] -pub enum MerkleTreeError { - /// Serialization error - #[error("Serialization of a merkle tree failed")] - SerializationError, - - /// Invalid merkle path - #[error("Path does not verify against root")] - PathInvalid(Vec), - - /// Invalid merkle batch path - #[error("Batch path does not verify against root")] - BatchPathInvalid(Vec), -} - -/// Errors which can be output by Mithril single signature verification. -#[derive(Debug, Clone, thiserror::Error)] -pub enum SignatureError { - /// There is an index out of bounds - #[error("Received index, {0}, is higher than what the security parameter allows, {1}.")] - IndexBoundFailed(u64, u64), - - /// The lottery was actually lost for the signature - #[error("Lottery for this epoch was lost.")] - LotteryLost, - - /// This error occurs when the the serialization of the raw bytes failed - #[error("Invalid bytes")] - SerializationError, -} - -/// Error types for aggregation. -#[derive(Debug, Clone, thiserror::Error)] -pub enum AggregationError { - /// Not enough signatures were collected, got this many instead. - #[error("Not enough signatures. Got only {0} out of {1}.")] - NotEnoughSignatures(u64, u64), - - #[error("Unsupported proof system: {0}")] - UnsupportedProofSystem(AggregateSignatureType), - - /// There is a duplicate index - #[error("Indices are not unique.")] - IndexNotUnique, -} - -/// Errors which can be output by Mithril aggregate verification. -#[derive(Debug, Clone, thiserror::Error)] -pub enum AggregateSignatureError { - /// This error occurs when the the serialization of the raw bytes failed - #[error("Invalid bytes")] - SerializationError, - - /// Batch verification of STM aggregate signatures failed - #[error("Batch verification of STM aggregate signatures failed")] - BatchInvalid, - - /// The proof system used in the aggregate signature is not supported - #[error("Unsupported proof system: {0}")] - UnsupportedProofSystem(AggregateSignatureType), -} +use crate::signature_scheme::{BlsVerificationKey, BlsVerificationKeyProofOfPossession}; /// Errors which can be outputted by key registration. #[derive(Debug, Clone, thiserror::Error, PartialEq, Eq)] @@ -121,32 +19,3 @@ pub enum RegisterError { #[error("Initializer not registered. Cannot participate as a signer.")] UnregisteredInitializer, } - -pub fn blst_error_to_stm_error( - e: BLST_ERROR, - sig: Option, - key: Option, -) -> StmResult<()> { - match e { - BLST_ERROR::BLST_SUCCESS => Ok(()), - BLST_ERROR::BLST_PK_IS_INFINITY => { - if let Some(s) = sig { - return Err(anyhow!(MultiSignatureError::SignatureInfinity(s))); - } - if let Some(vk) = key { - return Err(anyhow!(MultiSignatureError::VerificationKeyInfinity( - Box::new(vk) - ))); - } - Err(anyhow!(MultiSignatureError::SerializationError)) - } - BLST_ERROR::BLST_VERIFY_FAIL => { - if let Some(s) = sig { - Err(anyhow!(MultiSignatureError::SignatureInvalid(s))) - } else { - Err(anyhow!(MultiSignatureError::AggregateSignatureInvalid)) - } - } - _ => Err(anyhow!(MultiSignatureError::SerializationError)), - } -} diff --git a/mithril-stm/src/protocol/mod.rs b/mithril-stm/src/protocol/mod.rs index d7a58b7caaf..7975dda24a2 100644 --- a/mithril-stm/src/protocol/mod.rs +++ b/mithril-stm/src/protocol/mod.rs @@ -7,18 +7,15 @@ mod participant; mod single_signature; pub use aggregate_signature::{ - AggregateSignature, AggregateSignatureType, AggregateVerificationKey, BasicVerifier, Clerk, + AggregateSignature, AggregateSignatureError, AggregateSignatureType, AggregateVerificationKey, + AggregationError, BasicVerifier, Clerk, }; pub(crate) use eligibility_check::is_lottery_won; -pub(crate) use error::blst_error_to_stm_error; -pub use error::{ - AggregateSignatureError, AggregationError, MerkleTreeError, MultiSignatureError, RegisterError, - SignatureError, -}; +pub use error::RegisterError; pub use key_registration::{ClosedKeyRegistration, KeyRegistration, RegisteredParty}; pub use parameters::Parameters; pub use participant::{Initializer, Signer, VerificationKey, VerificationKeyProofOfPossession}; -pub use single_signature::{SingleSignature, SingleSignatureWithRegisteredParty}; +pub use single_signature::{SignatureError, SingleSignature, SingleSignatureWithRegisteredParty}; // Aliases #[deprecated(since = "0.5.0", note = "Use `AggregateSignature` instead")] diff --git a/mithril-stm/src/protocol/participant/initializer.rs b/mithril-stm/src/protocol/participant/initializer.rs index daff6272ae0..f2c16ef7e55 100644 --- a/mithril-stm/src/protocol/participant/initializer.rs +++ b/mithril-stm/src/protocol/participant/initializer.rs @@ -4,12 +4,13 @@ use digest::FixedOutput; use rand_core::{CryptoRng, RngCore}; use serde::{Deserialize, Serialize}; -use super::Signer; use crate::{ ClosedKeyRegistration, Parameters, RegisterError, RegisteredParty, Stake, StmResult, signature_scheme::{BlsSigningKey, BlsVerificationKeyProofOfPossession}, }; +use super::Signer; + /// Wrapper of the MultiSignature Verification key with proof of possession pub type VerificationKeyProofOfPossession = BlsVerificationKeyProofOfPossession; diff --git a/mithril-stm/src/protocol/single_signature/error.rs b/mithril-stm/src/protocol/single_signature/error.rs new file mode 100644 index 00000000000..8cdbad1b1c7 --- /dev/null +++ b/mithril-stm/src/protocol/single_signature/error.rs @@ -0,0 +1,15 @@ +/// Errors which can be output by Mithril single signature verification. +#[derive(Debug, Clone, thiserror::Error)] +pub enum SignatureError { + /// There is an index out of bounds + #[error("Received index, {0}, is higher than what the security parameter allows, {1}.")] + IndexBoundFailed(u64, u64), + + /// The lottery was actually lost for the signature + #[error("Lottery for this epoch was lost.")] + LotteryLost, + + /// This error occurs when the serialization of the raw bytes failed + #[error("Invalid bytes")] + SerializationError, +} diff --git a/mithril-stm/src/protocol/single_signature/mod.rs b/mithril-stm/src/protocol/single_signature/mod.rs index 43b3969c8ee..945d4b5672c 100644 --- a/mithril-stm/src/protocol/single_signature/mod.rs +++ b/mithril-stm/src/protocol/single_signature/mod.rs @@ -1,5 +1,7 @@ +mod error; mod signature; mod signature_registered_party; +pub use error::*; pub use signature::*; pub use signature_registered_party::*; diff --git a/mithril-stm/src/protocol/single_signature/signature.rs b/mithril-stm/src/protocol/single_signature/signature.rs index 57a9620ebc6..f477497ff43 100644 --- a/mithril-stm/src/protocol/single_signature/signature.rs +++ b/mithril-stm/src/protocol/single_signature/signature.rs @@ -8,10 +8,12 @@ use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize}; use crate::{ - AggregateVerificationKey, Index, Parameters, SignatureError, Stake, StmResult, VerificationKey, - is_lottery_won, signature_scheme::BlsSignature, + AggregateVerificationKey, Index, Parameters, Stake, StmResult, VerificationKey, is_lottery_won, + signature_scheme::BlsSignature, }; +use super::SignatureError; + /// Signature created by a single party who has won the lottery. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SingleSignature { diff --git a/mithril-stm/src/protocol/single_signature/signature_registered_party.rs b/mithril-stm/src/protocol/single_signature/signature_registered_party.rs index a72ee0d97cf..2fbc6846cfe 100644 --- a/mithril-stm/src/protocol/single_signature/signature_registered_party.rs +++ b/mithril-stm/src/protocol/single_signature/signature_registered_party.rs @@ -1,8 +1,9 @@ use blake2::digest::{Digest, FixedOutput}; use serde::{Deserialize, Serialize, Serializer, ser::SerializeTuple}; -use super::SingleSignature; -use crate::{RegisteredParty, SignatureError, StmResult}; +use crate::{RegisteredParty, StmResult}; + +use super::{SignatureError, SingleSignature}; /// Signature with its registered party. #[derive(Debug, Clone, Hash, Deserialize, Eq, PartialEq, Ord, PartialOrd)] diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/error.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/error.rs new file mode 100644 index 00000000000..7589d4b141d --- /dev/null +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/error.rs @@ -0,0 +1,68 @@ +//! Crate specific errors +use anyhow::anyhow; +use blst::BLST_ERROR; + +use crate::StmResult; + +use super::{BlsSignature, BlsVerificationKey, BlsVerificationKeyProofOfPossession}; + +/// Error types for multi signatures. +#[derive(Debug, thiserror::Error, Eq, PartialEq)] +pub enum BlsSignatureError { + /// Invalid Single signature + #[error("Invalid single signature")] + SignatureInvalid(BlsSignature), + + /// Invalid aggregate signature + #[error("Invalid aggregated signature")] + AggregateSignatureInvalid, + + /// This error occurs when the serialization of the raw bytes failed + #[error("Invalid bytes")] + SerializationError, + + /// Incorrect proof of possession + #[error("Key with invalid PoP")] + KeyInvalid(Box), + + /// At least one signature in the batch is invalid + #[error("One signature in the batch is invalid")] + BatchInvalid, + + /// Single signature is the infinity + #[error("Single signature is the infinity")] + SignatureInfinity(BlsSignature), + + /// Verification key is the infinity + #[error("Verification key is the infinity")] + VerificationKeyInfinity(Box), +} + +pub fn blst_error_to_stm_error( + e: BLST_ERROR, + sig: Option, + key: Option, +) -> StmResult<()> { + match e { + BLST_ERROR::BLST_SUCCESS => Ok(()), + BLST_ERROR::BLST_PK_IS_INFINITY => { + if let Some(s) = sig { + return Err(anyhow!(BlsSignatureError::SignatureInfinity(s))); + } + if let Some(vk) = key { + return Err(anyhow!(BlsSignatureError::VerificationKeyInfinity( + Box::new(vk) + ))); + } + Err(anyhow!(BlsSignatureError::SerializationError)) + } + BLST_ERROR::BLST_VERIFY_FAIL => { + if let Some(s) = sig { + Err(anyhow!(BlsSignatureError::SignatureInvalid(s))) + } else { + Err(anyhow!(BlsSignatureError::AggregateSignatureInvalid)) + } + } + _ => Err(anyhow!(BlsSignatureError::SerializationError)), + } +} diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/helper.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/helper.rs index 8eeae988526..3e7e52ff280 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/helper.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/helper.rs @@ -9,8 +9,8 @@ pub(crate) mod unsafe_helpers { }; use crate::{ - MultiSignatureError::SerializationError, StmResult, + signature_scheme::bls_multi_signature::error::BlsSignatureError::SerializationError, signature_scheme::{BlsProofOfPossession, BlsVerificationKey}, }; diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/mod.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/mod.rs index fc3c3bc1646..dba959071c1 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/mod.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/mod.rs @@ -1,11 +1,13 @@ //! BLST Multi-signature module +mod error; pub(super) mod helper; mod proof_of_possession; mod signature; mod signing_key; mod verification_key; +pub use error::*; pub use proof_of_possession::*; pub use signature::*; pub use signing_key::*; @@ -94,8 +96,9 @@ mod tests { use rand_chacha::ChaCha20Rng; use rand_core::{RngCore, SeedableRng}; + use super::error::BlsSignatureError; use super::helper::unsafe_helpers::{p1_affine_to_sig, p2_affine_to_vk}; - use crate::{KeyRegistration, MultiSignatureError, RegisterError}; + use crate::{KeyRegistration, RegisterError}; use super::*; @@ -134,8 +137,8 @@ mod tests { assert!( matches!( - error.downcast_ref::(), - Some(MultiSignatureError::SignatureInvalid(_)) + error.downcast_ref::(), + Some(BlsSignatureError::SignatureInvalid(_)) ), "Unexpected error: {error:?}"); } @@ -152,8 +155,8 @@ mod tests { let error = sig_infinity.verify(&msg, &vk).expect_err("Verification should fail"); assert!( matches!( - error.downcast_ref::(), - Some(MultiSignatureError::SignatureInfinity(_)) + error.downcast_ref::(), + Some(BlsSignatureError::SignatureInfinity(_)) ), "Unexpected error: {error:?}"); } @@ -171,8 +174,8 @@ mod tests { let error = vkpop_infinity.verify_proof_of_possession().expect_err("VK pop infinity should fail"); assert!( matches!( - error.downcast_ref::(), - Some(MultiSignatureError::VerificationKeyInfinity(_)) + error.downcast_ref::(), + Some(BlsSignatureError::VerificationKeyInfinity(_)) ), "Unexpected error: {error:?}"); } @@ -296,8 +299,8 @@ mod tests { let error = BlsSignature::batch_verify_aggregates(&batch_msgs, &batch_vk, &batch_sig).expect_err("Batch verify should fail"); assert!( matches!( - error.downcast_ref::(), - Some(MultiSignatureError::BatchInvalid) + error.downcast_ref::(), + Some(BlsSignatureError::BatchInvalid) ), "Unexpected error: {error:?}"); } diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/proof_of_possession.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/proof_of_possession.rs index 41035e41af1..c934bf1ee7e 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/proof_of_possession.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/proof_of_possession.rs @@ -1,10 +1,11 @@ use blst::{blst_p1, min_sig::Signature as BlstSig}; +use crate::StmResult; + use super::{ - BlsSigningKey, POP, + BlsSignatureError, BlsSigningKey, POP, blst_error_to_stm_error, helper::unsafe_helpers::{compress_p1, scalar_to_pk_in_g1, uncompress_p1}, }; -use crate::{MultiSignatureError, StmResult, blst_error_to_stm_error}; /// MultiSig proof of possession, which contains two elements from G1. However, /// the two elements have different types: `k1` is represented as a BlstSig @@ -35,7 +36,7 @@ impl BlsProofOfPossession { /// Deserialize a byte string to a `PublicKeyPoP`. pub fn from_bytes(bytes: &[u8]) -> StmResult { let k1 = match BlstSig::from_bytes( - bytes.get(..48).ok_or(MultiSignatureError::SerializationError)?, + bytes.get(..48).ok_or(BlsSignatureError::SerializationError)?, ) { Ok(key) => key, Err(e) => { @@ -44,7 +45,7 @@ impl BlsProofOfPossession { } }; - let k2 = uncompress_p1(bytes.get(48..96).ok_or(MultiSignatureError::SerializationError)?)?; + let k2 = uncompress_p1(bytes.get(48..96).ok_or(BlsSignatureError::SerializationError)?)?; Ok(Self { k1, k2 }) } diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs index 3ad44712dd0..2177af094e0 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs @@ -1,3 +1,5 @@ +use std::{cmp::Ordering, iter::Sum}; + use anyhow::{Context, anyhow}; use blake2::{Blake2b, Blake2b512, Digest}; use blst::{ @@ -6,13 +8,13 @@ use blst::{ p1_affines, p2_affines, }; use digest::consts::U16; -use std::{cmp::Ordering, iter::Sum}; + +use crate::{Index, StmResult}; use super::{ - BlsVerificationKey, + BlsSignatureError, BlsVerificationKey, blst_error_to_stm_error, helper::unsafe_helpers::{p1_affine_to_sig, p2_affine_to_vk, sig_to_p1, vk_from_p2_affine}, }; -use crate::{Index, MultiSignatureError, StmResult, blst_error_to_stm_error}; /// MultiSig signature, which is a wrapper over the `BlstSig` type. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -62,7 +64,7 @@ impl BlsSignature { /// # Error /// Returns an error if the byte string does not represent a point in the curve. pub fn from_bytes(bytes: &[u8]) -> StmResult { - let bytes = bytes.get(..48).ok_or(MultiSignatureError::SerializationError)?; + let bytes = bytes.get(..48).ok_or(BlsSignatureError::SerializationError)?; match BlstSig::sig_validate(bytes, true) { Ok(sig) => Ok(Self(sig)), Err(e) => Err(blst_error_to_stm_error(e, None, None) @@ -95,7 +97,7 @@ impl BlsSignature { sigs: &[BlsSignature], ) -> StmResult<(BlsVerificationKey, BlsSignature)> { if vks.len() != sigs.len() || vks.is_empty() { - return Err(anyhow!(MultiSignatureError::AggregateSignatureInvalid)); + return Err(anyhow!(BlsSignatureError::AggregateSignatureInvalid)); } if vks.len() < 2 { @@ -175,7 +177,7 @@ impl BlsSignature { None, None, ) - .map_err(|_| anyhow!(MultiSignatureError::BatchInvalid)) + .map_err(|_| anyhow!(BlsSignatureError::BatchInvalid)) } } diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/signing_key.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/signing_key.rs index 6108d9f6374..607c11c182c 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/signing_key.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/signing_key.rs @@ -1,8 +1,9 @@ use blst::min_sig::SecretKey as BlstSk; use rand_core::{CryptoRng, RngCore}; -use super::BlsSignature; -use crate::{MultiSignatureError, StmResult, blst_error_to_stm_error}; +use crate::StmResult; + +use super::{BlsSignature, BlsSignatureError, blst_error_to_stm_error}; /// MultiSig secret key, which is a wrapper over the BlstSk type from the blst /// library. @@ -35,7 +36,7 @@ impl BlsSigningKey { /// # Error /// Fails if the byte string represents a scalar larger than the group order. pub fn from_bytes(bytes: &[u8]) -> StmResult { - let bytes = bytes.get(..32).ok_or(MultiSignatureError::SerializationError)?; + let bytes = bytes.get(..32).ok_or(BlsSignatureError::SerializationError)?; match BlstSk::from_bytes(bytes) { Ok(sk) => Ok(Self(sk)), Err(e) => Err(blst_error_to_stm_error(e, None, None) diff --git a/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs b/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs index 1247115d28f..73ec370f8a5 100644 --- a/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs +++ b/mithril-stm/src/signature_scheme/bls_multi_signature/verification_key.rs @@ -1,4 +1,3 @@ -use anyhow::anyhow; use std::{ cmp::Ordering, fmt::{Display, Formatter}, @@ -6,14 +5,19 @@ use std::{ iter::Sum, }; +use anyhow::anyhow; use blst::{ BLST_ERROR, min_sig::{AggregatePublicKey, PublicKey as BlstVk}, }; use serde::{Deserialize, Serialize}; -use super::{BlsProofOfPossession, BlsSigningKey, POP, helper::unsafe_helpers::verify_pairing}; -use crate::{MultiSignatureError, StmResult, blst_error_to_stm_error}; +use crate::StmResult; + +use super::{ + BlsProofOfPossession, BlsSignatureError, BlsSigningKey, POP, blst_error_to_stm_error, + helper::unsafe_helpers::verify_pairing, +}; /// MultiSig verification key, which is a wrapper over the BlstVk (element in G2) /// from the blst library. @@ -32,7 +36,7 @@ impl BlsVerificationKey { /// This function fails if the bytes do not represent a compressed point of the prime /// order subgroup of the curve Bls12-381. pub fn from_bytes(bytes: &[u8]) -> StmResult { - let bytes = bytes.get(..96).ok_or(MultiSignatureError::SerializationError)?; + let bytes = bytes.get(..96).ok_or(BlsSignatureError::SerializationError)?; match BlstVk::key_validate(bytes) { Ok(vk) => Ok(Self(vk)), Err(e) => Err(blst_error_to_stm_error(e, None, None) @@ -149,7 +153,7 @@ impl BlsVerificationKeyProofOfPossession { ) == BLST_ERROR::BLST_SUCCESS && result) { - return Err(anyhow!(MultiSignatureError::KeyInvalid(Box::new(*self)))); + return Err(anyhow!(BlsSignatureError::KeyInvalid(Box::new(*self)))); } Ok(()) } @@ -187,11 +191,11 @@ impl BlsVerificationKeyProofOfPossession { /// Deserialize a byte string to a `BlsVerificationKeyProofOfPossession`. pub fn from_bytes(bytes: &[u8]) -> StmResult { let mvk = BlsVerificationKey::from_bytes( - bytes.get(..96).ok_or(MultiSignatureError::SerializationError)?, + bytes.get(..96).ok_or(BlsSignatureError::SerializationError)?, )?; let pop = BlsProofOfPossession::from_bytes( - bytes.get(96..).ok_or(MultiSignatureError::SerializationError)?, + bytes.get(96..).ok_or(BlsSignatureError::SerializationError)?, )?; Ok(Self { vk: mvk, pop }) diff --git a/mithril-stm/src/signature_scheme/schnorr_signature/signature.rs b/mithril-stm/src/signature_scheme/schnorr_signature/signature.rs index 6ddf3bcfba2..4a16ebe156c 100644 --- a/mithril-stm/src/signature_scheme/schnorr_signature/signature.rs +++ b/mithril-stm/src/signature_scheme/schnorr_signature/signature.rs @@ -6,11 +6,12 @@ use dusk_jubjub::{ use dusk_poseidon::{Domain, Hash}; use group::{Group, GroupEncoding}; +use crate::StmResult; + use super::{ DST_SIGNATURE, SchnorrSignatureError, SchnorrVerificationKey, get_coordinates_several_points, is_on_curve, }; -use crate::StmResult; /// Structure of the Schnorr signature to use with the SNARK /// @@ -153,11 +154,11 @@ impl SchnorrSignature { #[cfg(test)] mod tests { - - use crate::{SchnorrSignature, SchnorrSigningKey, SchnorrVerificationKey}; use rand_chacha::ChaCha20Rng; use rand_core::SeedableRng; + use crate::signature_scheme::{SchnorrSignature, SchnorrSigningKey, SchnorrVerificationKey}; + #[test] fn invalid_sig() { let msg = vec![0, 0, 0, 1]; @@ -209,7 +210,7 @@ mod tests { use rand_chacha::ChaCha20Rng; use rand_core::SeedableRng; - use crate::{SchnorrSignature, SchnorrSigningKey}; + use crate::signature_scheme::{SchnorrSignature, SchnorrSigningKey}; const GOLDEN_BYTES: &[u8; 96] = &[ 143, 53, 198, 62, 178, 1, 88, 253, 21, 92, 100, 13, 72, 180, 198, 127, 39, 175, 102, diff --git a/mithril-stm/src/signature_scheme/schnorr_signature/signing_key.rs b/mithril-stm/src/signature_scheme/schnorr_signature/signing_key.rs index ef2148f39d1..2bffc1dea70 100644 --- a/mithril-stm/src/signature_scheme/schnorr_signature/signing_key.rs +++ b/mithril-stm/src/signature_scheme/schnorr_signature/signing_key.rs @@ -7,11 +7,12 @@ use dusk_poseidon::{Domain, Hash}; use group::Group; use rand_core::{CryptoRng, RngCore}; +use crate::StmResult; + use super::{ DST_SIGNATURE, SchnorrSignature, SchnorrSignatureError, SchnorrVerificationKey, generate_non_zero_scalar, get_coordinates_several_points, }; -use crate::StmResult; /// Schnorr Signing key, it is essentially a random scalar of the Jubjub scalar field #[derive(Debug, Clone)] @@ -128,10 +129,11 @@ impl SchnorrSigningKey { #[cfg(test)] mod tests { - pub(crate) use super::*; use rand_chacha::ChaCha20Rng; use rand_core::SeedableRng; + use super::*; + #[test] fn generate_signing_key() { let mut rng = ChaCha20Rng::from_seed([0u8; 32]); @@ -191,7 +193,7 @@ mod tests { use rand_chacha::ChaCha20Rng; use rand_core::SeedableRng; - use crate::SchnorrSigningKey; + use crate::signature_scheme::SchnorrSigningKey; const GOLDEN_BYTES: &[u8; 32] = &[ 126, 191, 239, 197, 88, 151, 248, 254, 187, 143, 86, 35, 29, 62, 90, 13, 196, 71, 234, diff --git a/mithril-stm/src/signature_scheme/schnorr_signature/utils.rs b/mithril-stm/src/signature_scheme/schnorr_signature/utils.rs index 44b53f83181..606b60f1671 100644 --- a/mithril-stm/src/signature_scheme/schnorr_signature/utils.rs +++ b/mithril-stm/src/signature_scheme/schnorr_signature/utils.rs @@ -7,9 +7,10 @@ use ff::Field; use group::Curve; use rand_core::{CryptoRng, RngCore}; -use super::SchnorrSignatureError; use crate::StmResult; +use super::SchnorrSignatureError; + /// Check if the given point is on the curve using its coordinates pub fn is_on_curve(point: JubjubExtended) -> bool { let point_affine_representation = JubjubAffine::from(point); @@ -57,13 +58,13 @@ pub fn generate_non_zero_scalar(rng: &mut R) -> StmResul #[cfg(test)] mod tests { - - use super::*; use dusk_jubjub::{AffinePoint as JubjubAffine, ExtendedPoint as JubjubExtended}; use group::Group; use rand_chacha::ChaCha20Rng; use rand_core::SeedableRng; + use super::*; + #[test] fn get_coordinates_from_several_points() { let seed = [0u8; 32]; diff --git a/mithril-stm/src/signature_scheme/schnorr_signature/verification_key.rs b/mithril-stm/src/signature_scheme/schnorr_signature/verification_key.rs index a2b671fd7fc..0e1787f3f96 100644 --- a/mithril-stm/src/signature_scheme/schnorr_signature/verification_key.rs +++ b/mithril-stm/src/signature_scheme/schnorr_signature/verification_key.rs @@ -2,9 +2,10 @@ use anyhow::{Context, anyhow}; use dusk_jubjub::SubgroupPoint as JubjubSubgroup; use group::{Group, GroupEncoding}; -use super::SchnorrSignatureError; use crate::StmResult; +use super::{SchnorrSignatureError, SchnorrSigningKey}; + /// Schnorr verification key, it consists of a point on the Jubjub curve /// vk = g * sk, where g is a generator #[derive(Debug, Clone, Copy, Default, PartialEq, Eq)] @@ -38,12 +39,12 @@ impl SchnorrVerificationKey { } } -impl From<&crate::SchnorrSigningKey> for SchnorrVerificationKey { +impl From<&SchnorrSigningKey> for SchnorrVerificationKey { /// Convert a Schnorr secret key into a verification key /// /// This is done by computing `vk = g * sk` where g is the generator /// of the subgroup and sk is the schnorr secret key - fn from(signing_key: &crate::SchnorrSigningKey) -> Self { + fn from(signing_key: &SchnorrSigningKey) -> Self { let generator = JubjubSubgroup::generator(); SchnorrVerificationKey(generator * signing_key.0) @@ -52,7 +53,6 @@ impl From<&crate::SchnorrSigningKey> for SchnorrVerificationKey { #[cfg(test)] mod tests { - use dusk_jubjub::Fq as JubjubBase; use dusk_jubjub::SubgroupPoint as JubjubSubgroup; use ff::Field;