Skip to content

Commit e48d337

Browse files
committed
modified multisig error to blssig
1 parent affa665 commit e48d337

File tree

11 files changed

+172
-83
lines changed

11 files changed

+172
-83
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// Error types related to merkle trees.
2+
#[derive(Debug, Clone, thiserror::Error)]
3+
pub enum MerkleTreeError {
4+
/// Serialization error
5+
#[error("Serialization of a merkle tree failed")]
6+
SerializationError,
7+
8+
/// Invalid merkle path
9+
#[error("Path does not verify against root")]
10+
PathInvalid(Vec<u8>),
11+
12+
/// Invalid merkle batch path
13+
#[error("Batch path does not verify against root")]
14+
BatchPathInvalid(Vec<u8>),
15+
}

mithril-stm/src/membership_commitment/merkle_tree/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
//! Merkle tree implementation for STM
22
33
mod commitment;
4+
mod error;
45
mod leaf;
56
mod path;
67
mod tree;
78

89
pub use commitment::*;
10+
pub use error::*;
911
pub use leaf::*;
1012
pub use path::*;
1113
pub use tree::*;

mithril-stm/src/protocol/error.rs

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,36 @@ use crate::{
88
};
99

1010
/// Error types for multi signatures.
11-
#[derive(Debug, thiserror::Error, Eq, PartialEq)]
12-
pub enum MultiSignatureError {
13-
/// Invalid Single signature
14-
#[error("Invalid single signature")]
15-
SignatureInvalid(BlsSignature),
11+
// #[derive(Debug, thiserror::Error, Eq, PartialEq)]
12+
// pub enum MultiSignatureError {
13+
// /// Invalid Single signature
14+
// #[error("Invalid single signature")]
15+
// SignatureInvalid(BlsSignature),
1616

17-
/// Invalid aggregate signature
18-
#[error("Invalid aggregated signature")]
19-
AggregateSignatureInvalid,
17+
// /// Invalid aggregate signature
18+
// #[error("Invalid aggregated signature")]
19+
// AggregateSignatureInvalid,
2020

21-
/// This error occurs when the the serialization of the raw bytes failed
22-
#[error("Invalid bytes")]
23-
SerializationError,
21+
// /// This error occurs when the the serialization of the raw bytes failed
22+
// #[error("Invalid bytes")]
23+
// SerializationError,
2424

25-
/// Incorrect proof of possession
26-
#[error("Key with invalid PoP")]
27-
KeyInvalid(Box<BlsVerificationKeyProofOfPossession>),
25+
// /// Incorrect proof of possession
26+
// #[error("Key with invalid PoP")]
27+
// KeyInvalid(Box<BlsVerificationKeyProofOfPossession>),
2828

29-
/// At least one signature in the batch is invalid
30-
#[error("One signature in the batch is invalid")]
31-
BatchInvalid,
29+
// /// At least one signature in the batch is invalid
30+
// #[error("One signature in the batch is invalid")]
31+
// BatchInvalid,
3232

33-
/// Single signature is the infinity
34-
#[error("Single signature is the infinity")]
35-
SignatureInfinity(BlsSignature),
33+
// /// Single signature is the infinity
34+
// #[error("Single signature is the infinity")]
35+
// SignatureInfinity(BlsSignature),
3636

37-
/// Verification key is the infinity
38-
#[error("Verification key is the infinity")]
39-
VerificationKeyInfinity(Box<BlsVerificationKey>),
40-
}
37+
// /// Verification key is the infinity
38+
// #[error("Verification key is the infinity")]
39+
// VerificationKeyInfinity(Box<BlsVerificationKey>),
40+
// }
4141

4242
/// Error types related to merkle trees.
4343
#[derive(Debug, Clone, thiserror::Error)]
@@ -122,31 +122,31 @@ pub enum RegisterError {
122122
UnregisteredInitializer,
123123
}
124124

125-
pub fn blst_error_to_stm_error(
126-
e: BLST_ERROR,
127-
sig: Option<BlsSignature>,
128-
key: Option<BlsVerificationKey>,
129-
) -> StmResult<()> {
130-
match e {
131-
BLST_ERROR::BLST_SUCCESS => Ok(()),
132-
BLST_ERROR::BLST_PK_IS_INFINITY => {
133-
if let Some(s) = sig {
134-
return Err(anyhow!(MultiSignatureError::SignatureInfinity(s)));
135-
}
136-
if let Some(vk) = key {
137-
return Err(anyhow!(MultiSignatureError::VerificationKeyInfinity(
138-
Box::new(vk)
139-
)));
140-
}
141-
Err(anyhow!(MultiSignatureError::SerializationError))
142-
}
143-
BLST_ERROR::BLST_VERIFY_FAIL => {
144-
if let Some(s) = sig {
145-
Err(anyhow!(MultiSignatureError::SignatureInvalid(s)))
146-
} else {
147-
Err(anyhow!(MultiSignatureError::AggregateSignatureInvalid))
148-
}
149-
}
150-
_ => Err(anyhow!(MultiSignatureError::SerializationError)),
151-
}
152-
}
125+
// pub fn blst_error_to_stm_error(
126+
// e: BLST_ERROR,
127+
// sig: Option<BlsSignature>,
128+
// key: Option<BlsVerificationKey>,
129+
// ) -> StmResult<()> {
130+
// match e {
131+
// BLST_ERROR::BLST_SUCCESS => Ok(()),
132+
// BLST_ERROR::BLST_PK_IS_INFINITY => {
133+
// if let Some(s) = sig {
134+
// return Err(anyhow!(MultiSignatureError::SignatureInfinity(s)));
135+
// }
136+
// if let Some(vk) = key {
137+
// return Err(anyhow!(MultiSignatureError::VerificationKeyInfinity(
138+
// Box::new(vk)
139+
// )));
140+
// }
141+
// Err(anyhow!(MultiSignatureError::SerializationError))
142+
// }
143+
// BLST_ERROR::BLST_VERIFY_FAIL => {
144+
// if let Some(s) = sig {
145+
// Err(anyhow!(MultiSignatureError::SignatureInvalid(s)))
146+
// } else {
147+
// Err(anyhow!(MultiSignatureError::AggregateSignatureInvalid))
148+
// }
149+
// }
150+
// _ => Err(anyhow!(MultiSignatureError::SerializationError)),
151+
// }
152+
// }

mithril-stm/src/protocol/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ pub use aggregate_signature::{
1010
AggregateSignature, AggregateSignatureType, AggregateVerificationKey, BasicVerifier, Clerk,
1111
};
1212
pub(crate) use eligibility_check::is_lottery_won;
13-
pub(crate) use error::blst_error_to_stm_error;
1413
pub use error::{
15-
AggregateSignatureError, AggregationError, MerkleTreeError, MultiSignatureError, RegisterError,
16-
SignatureError,
14+
AggregateSignatureError, AggregationError, MerkleTreeError, RegisterError, SignatureError,
1715
};
1816
pub use key_registration::{ClosedKeyRegistration, KeyRegistration, RegisteredParty};
1917
pub use parameters::Parameters;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//! Crate specific errors
2+
use anyhow::anyhow;
3+
use blst::BLST_ERROR;
4+
5+
use super::{BlsSignature, BlsVerificationKey, BlsVerificationKeyProofOfPossession};
6+
7+
use crate::StmResult;
8+
9+
/// Error types for multi signatures.
10+
#[derive(Debug, thiserror::Error, Eq, PartialEq)]
11+
pub enum BlsSignatureError {
12+
/// Invalid Single signature
13+
#[error("Invalid single signature")]
14+
SignatureInvalid(BlsSignature),
15+
16+
/// Invalid aggregate signature
17+
#[error("Invalid aggregated signature")]
18+
AggregateSignatureInvalid,
19+
20+
/// This error occurs when the the serialization of the raw bytes failed
21+
#[error("Invalid bytes")]
22+
SerializationError,
23+
24+
/// Incorrect proof of possession
25+
#[error("Key with invalid PoP")]
26+
KeyInvalid(Box<BlsVerificationKeyProofOfPossession>),
27+
28+
/// At least one signature in the batch is invalid
29+
#[error("One signature in the batch is invalid")]
30+
BatchInvalid,
31+
32+
/// Single signature is the infinity
33+
#[error("Single signature is the infinity")]
34+
SignatureInfinity(BlsSignature),
35+
36+
/// Verification key is the infinity
37+
#[error("Verification key is the infinity")]
38+
VerificationKeyInfinity(Box<BlsVerificationKey>),
39+
}
40+
41+
pub fn blst_error_to_stm_error(
42+
e: BLST_ERROR,
43+
sig: Option<BlsSignature>,
44+
key: Option<BlsVerificationKey>,
45+
) -> StmResult<()> {
46+
match e {
47+
BLST_ERROR::BLST_SUCCESS => Ok(()),
48+
BLST_ERROR::BLST_PK_IS_INFINITY => {
49+
if let Some(s) = sig {
50+
return Err(anyhow!(BlsSignatureError::SignatureInfinity(s)));
51+
}
52+
if let Some(vk) = key {
53+
return Err(anyhow!(BlsSignatureError::VerificationKeyInfinity(
54+
Box::new(vk)
55+
)));
56+
}
57+
Err(anyhow!(BlsSignatureError::SerializationError))
58+
}
59+
BLST_ERROR::BLST_VERIFY_FAIL => {
60+
if let Some(s) = sig {
61+
Err(anyhow!(BlsSignatureError::SignatureInvalid(s)))
62+
} else {
63+
Err(anyhow!(BlsSignatureError::AggregateSignatureInvalid))
64+
}
65+
}
66+
_ => Err(anyhow!(BlsSignatureError::SerializationError)),
67+
}
68+
}

mithril-stm/src/signature_scheme/bls_multi_signature/helper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ pub(crate) mod unsafe_helpers {
99
};
1010

1111
use crate::{
12-
MultiSignatureError::SerializationError,
1312
StmResult,
13+
signature_scheme::bls_multi_signature::error::BlsSignatureError::SerializationError,
1414
signature_scheme::{BlsProofOfPossession, BlsVerificationKey},
1515
};
1616

mithril-stm/src/signature_scheme/bls_multi_signature/mod.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
//! BLST Multi-signature module
22
3+
mod error;
34
pub(super) mod helper;
45
mod proof_of_possession;
56
mod signature;
67
mod signing_key;
78
mod verification_key;
89

10+
pub use error::*;
911
pub use proof_of_possession::*;
1012
pub use signature::*;
1113
pub use signing_key::*;
@@ -94,8 +96,9 @@ mod tests {
9496
use rand_chacha::ChaCha20Rng;
9597
use rand_core::{RngCore, SeedableRng};
9698

99+
use super::error::BlsSignatureError;
97100
use super::helper::unsafe_helpers::{p1_affine_to_sig, p2_affine_to_vk};
98-
use crate::{KeyRegistration, MultiSignatureError, RegisterError};
101+
use crate::{KeyRegistration, RegisterError};
99102

100103
use super::*;
101104

@@ -134,8 +137,8 @@ mod tests {
134137

135138
assert!(
136139
matches!(
137-
error.downcast_ref::<MultiSignatureError>(),
138-
Some(MultiSignatureError::SignatureInvalid(_))
140+
error.downcast_ref::<BlsSignatureError>(),
141+
Some(BlsSignatureError::SignatureInvalid(_))
139142
),
140143
"Unexpected error: {error:?}");
141144
}
@@ -152,8 +155,8 @@ mod tests {
152155
let error = sig_infinity.verify(&msg, &vk).expect_err("Verification should fail");
153156
assert!(
154157
matches!(
155-
error.downcast_ref::<MultiSignatureError>(),
156-
Some(MultiSignatureError::SignatureInfinity(_))
158+
error.downcast_ref::<BlsSignatureError>(),
159+
Some(BlsSignatureError::SignatureInfinity(_))
157160
),
158161
"Unexpected error: {error:?}");
159162
}
@@ -171,8 +174,8 @@ mod tests {
171174
let error = vkpop_infinity.verify_proof_of_possession().expect_err("VK pop infinity should fail");
172175
assert!(
173176
matches!(
174-
error.downcast_ref::<MultiSignatureError>(),
175-
Some(MultiSignatureError::VerificationKeyInfinity(_))
177+
error.downcast_ref::<BlsSignatureError>(),
178+
Some(BlsSignatureError::VerificationKeyInfinity(_))
176179
),
177180
"Unexpected error: {error:?}");
178181
}
@@ -296,8 +299,8 @@ mod tests {
296299
let error = BlsSignature::batch_verify_aggregates(&batch_msgs, &batch_vk, &batch_sig).expect_err("Batch verify should fail");
297300
assert!(
298301
matches!(
299-
error.downcast_ref::<MultiSignatureError>(),
300-
Some(MultiSignatureError::BatchInvalid)
302+
error.downcast_ref::<BlsSignatureError>(),
303+
Some(BlsSignatureError::BatchInvalid)
301304
),
302305
"Unexpected error: {error:?}");
303306
}

mithril-stm/src/signature_scheme/bls_multi_signature/proof_of_possession.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use blst::{blst_p1, min_sig::Signature as BlstSig};
22

33
use super::{
4-
BlsSigningKey, POP,
4+
BlsSignatureError, BlsSigningKey, POP, blst_error_to_stm_error,
55
helper::unsafe_helpers::{compress_p1, scalar_to_pk_in_g1, uncompress_p1},
66
};
7-
use crate::{MultiSignatureError, StmResult, blst_error_to_stm_error};
7+
use crate::StmResult;
88

99
/// MultiSig proof of possession, which contains two elements from G1. However,
1010
/// the two elements have different types: `k1` is represented as a BlstSig
@@ -35,7 +35,7 @@ impl BlsProofOfPossession {
3535
/// Deserialize a byte string to a `PublicKeyPoP`.
3636
pub fn from_bytes(bytes: &[u8]) -> StmResult<Self> {
3737
let k1 = match BlstSig::from_bytes(
38-
bytes.get(..48).ok_or(MultiSignatureError::SerializationError)?,
38+
bytes.get(..48).ok_or(BlsSignatureError::SerializationError)?,
3939
) {
4040
Ok(key) => key,
4141
Err(e) => {
@@ -44,7 +44,7 @@ impl BlsProofOfPossession {
4444
}
4545
};
4646

47-
let k2 = uncompress_p1(bytes.get(48..96).ok_or(MultiSignatureError::SerializationError)?)?;
47+
let k2 = uncompress_p1(bytes.get(48..96).ok_or(BlsSignatureError::SerializationError)?)?;
4848

4949
Ok(Self { k1, k2 })
5050
}

mithril-stm/src/signature_scheme/bls_multi_signature/signature.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use digest::consts::U16;
99
use std::{cmp::Ordering, iter::Sum};
1010

1111
use super::{
12-
BlsVerificationKey,
12+
BlsSignatureError, BlsVerificationKey, blst_error_to_stm_error,
1313
helper::unsafe_helpers::{p1_affine_to_sig, p2_affine_to_vk, sig_to_p1, vk_from_p2_affine},
1414
};
15-
use crate::{Index, MultiSignatureError, StmResult, blst_error_to_stm_error};
15+
use crate::{Index, StmResult};
1616

1717
/// MultiSig signature, which is a wrapper over the `BlstSig` type.
1818
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -62,7 +62,7 @@ impl BlsSignature {
6262
/// # Error
6363
/// Returns an error if the byte string does not represent a point in the curve.
6464
pub fn from_bytes(bytes: &[u8]) -> StmResult<Self> {
65-
let bytes = bytes.get(..48).ok_or(MultiSignatureError::SerializationError)?;
65+
let bytes = bytes.get(..48).ok_or(BlsSignatureError::SerializationError)?;
6666
match BlstSig::sig_validate(bytes, true) {
6767
Ok(sig) => Ok(Self(sig)),
6868
Err(e) => Err(blst_error_to_stm_error(e, None, None)
@@ -95,7 +95,7 @@ impl BlsSignature {
9595
sigs: &[BlsSignature],
9696
) -> StmResult<(BlsVerificationKey, BlsSignature)> {
9797
if vks.len() != sigs.len() || vks.is_empty() {
98-
return Err(anyhow!(MultiSignatureError::AggregateSignatureInvalid));
98+
return Err(anyhow!(BlsSignatureError::AggregateSignatureInvalid));
9999
}
100100

101101
if vks.len() < 2 {
@@ -175,7 +175,7 @@ impl BlsSignature {
175175
None,
176176
None,
177177
)
178-
.map_err(|_| anyhow!(MultiSignatureError::BatchInvalid))
178+
.map_err(|_| anyhow!(BlsSignatureError::BatchInvalid))
179179
}
180180
}
181181

0 commit comments

Comments
 (0)