@@ -39,6 +39,22 @@ pub enum MultiSignatureError {
39
39
VerificationKeyInfinity ( Box < VerificationKey > ) ,
40
40
}
41
41
42
+ /// Error types related to merkle trees.
43
+ #[ derive( Debug , Clone , thiserror:: Error ) ]
44
+ pub enum MerkleTreeError < D : Digest + FixedOutput > {
45
+ /// Serialization error
46
+ #[ error( "Serialization of a merkle tree failed" ) ]
47
+ SerializationError ,
48
+
49
+ /// Invalid merkle path
50
+ #[ error( "Path does not verify against root" ) ]
51
+ PathInvalid ( Path < D > ) ,
52
+
53
+ /// Invalid merkle batch path
54
+ #[ error( "Batch path does not verify against root" ) ]
55
+ BatchPathInvalid ( BatchPath < D > ) ,
56
+ }
57
+
42
58
/// Errors which can be output by Mithril single signature verification.
43
59
#[ derive( Debug , Clone , thiserror:: Error ) ]
44
60
pub enum StmSignatureError {
@@ -67,28 +83,39 @@ pub enum StmSignatureError {
67
83
SerializationError ,
68
84
}
69
85
70
- /// Errors which can be output by Mithril aggregate verification.
71
- #[ derive( Debug , Clone , thiserror:: Error ) ]
72
- pub enum StmAggregateSignatureError < D : Digest + FixedOutput > {
73
- /// The IVK is invalid after aggregating the keys
74
- #[ error( "Aggregated key does not correspond to the expected key." ) ]
75
- IvkInvalid ( Box < VerificationKey > ) ,
76
-
77
- /// This error occurs when the the serialization of the raw bytes failed
78
- #[ error( "Invalid bytes" ) ]
79
- SerializationError ,
86
+ impl From < MultiSignatureError > for StmSignatureError {
87
+ fn from ( e : MultiSignatureError ) -> Self {
88
+ match e {
89
+ MultiSignatureError :: SerializationError => Self :: SerializationError ,
90
+ MultiSignatureError :: SignatureInvalid ( e) => Self :: SignatureInvalid ( e) ,
91
+ MultiSignatureError :: BatchInvalid => unreachable ! ( ) ,
92
+ MultiSignatureError :: KeyInvalid ( _) => unreachable ! ( ) ,
93
+ MultiSignatureError :: AggregateSignatureInvalid => unreachable ! ( ) ,
94
+ MultiSignatureError :: SignatureInfinity ( _) => unreachable ! ( ) ,
95
+ MultiSignatureError :: VerificationKeyInfinity ( _) => unreachable ! ( ) ,
96
+ }
97
+ }
98
+ }
80
99
81
- /// Invalid merkle batch path
82
- #[ error( "Batch path does not verify against root" ) ]
83
- PathInvalid ( BatchPath < D > ) ,
100
+ impl < D : Digest + FixedOutput > From < MerkleTreeError < D > > for StmSignatureError {
101
+ fn from ( e : MerkleTreeError < D > ) -> Self {
102
+ match e {
103
+ MerkleTreeError :: SerializationError => Self :: SerializationError ,
104
+ _ => unreachable ! ( ) ,
105
+ }
106
+ }
107
+ }
84
108
85
- /// Batch verification of STM aggregate signatures failed
86
- #[ error( "Batch verification of STM aggregate signatures failed" ) ]
87
- BatchInvalid ,
109
+ /// Error types for aggregation.
110
+ #[ derive( Debug , Clone , thiserror:: Error ) ]
111
+ pub enum AggregationError {
112
+ /// Not enough signatures were collected, got this many instead.
113
+ #[ error( "Not enough signatures. Got only {0} out of {1}." ) ]
114
+ NotEnoughSignatures ( u64 , u64 ) ,
88
115
89
- /// `CoreVerifier` check failed
90
- #[ error( "Core verification error: {0} " ) ]
91
- CoreVerificationError ( # [ source ] CoreVerifierError ) ,
116
+ /// This error happens when we try to convert a u64 to a usize and it does not fit
117
+ #[ error( "Invalid usize conversion " ) ]
118
+ UsizeConversionInvalid ,
92
119
}
93
120
94
121
/// Errors which can be output by `CoreVerifier`.
@@ -111,81 +138,59 @@ pub enum CoreVerifierError {
111
138
IndividualSignatureInvalid ( #[ source] StmSignatureError ) ,
112
139
}
113
140
114
- /// Error types for aggregation.
115
- #[ derive( Debug , Clone , thiserror:: Error ) ]
116
- pub enum AggregationError {
117
- /// Not enough signatures were collected, got this many instead.
118
- #[ error( "Not enough signatures. Got only {0} out of {1}." ) ]
119
- NotEnoughSignatures ( u64 , u64 ) ,
120
-
121
- /// This error happens when we try to convert a u64 to a usize and it does not fit
122
- #[ error( "Invalid usize conversion" ) ]
123
- UsizeConversionInvalid ,
124
- }
125
-
126
- /// Error types related to merkle trees.
127
- #[ derive( Debug , Clone , thiserror:: Error ) ]
128
- pub enum MerkleTreeError < D : Digest + FixedOutput > {
129
- /// Serialization error
130
- #[ error( "Serialization of a merkle tree failed" ) ]
131
- SerializationError ,
132
-
133
- /// Invalid merkle path
134
- #[ error( "Path does not verify against root" ) ]
135
- PathInvalid ( Path < D > ) ,
136
-
137
- /// Invalid merkle batch path
138
- #[ error( "Batch path does not verify against root" ) ]
139
- BatchPathInvalid ( BatchPath < D > ) ,
140
- }
141
-
142
- /// Errors which can be outputted by key registration.
143
- #[ derive( Debug , Clone , thiserror:: Error , PartialEq , Eq ) ]
144
- pub enum RegisterError {
145
- /// This key has already been registered by a participant
146
- #[ error( "This key has already been registered." ) ]
147
- KeyRegistered ( Box < VerificationKey > ) ,
148
-
149
- /// Verification key is the infinity
150
- #[ error( "Verification key is the infinity" ) ]
151
- VerificationKeyInfinity ( Box < VerificationKey > ) ,
152
-
153
- /// The supplied key is not valid
154
- #[ error( "The verification of correctness of the supplied key is invalid." ) ]
155
- KeyInvalid ( Box < VerificationKeyPoP > ) ,
156
-
157
- /// Serialization error
158
- #[ error( "Serialization error" ) ]
159
- SerializationError ,
160
-
161
- /// UnregisteredInitializer error
162
- #[ error( "Initializer not registered. Cannot participate as a signer." ) ]
163
- UnregisteredInitializer ,
141
+ impl From < AggregationError > for CoreVerifierError {
142
+ fn from ( e : AggregationError ) -> Self {
143
+ match e {
144
+ AggregationError :: NotEnoughSignatures ( e, _e) => Self :: NoQuorum ( e, e) ,
145
+ AggregationError :: UsizeConversionInvalid => unreachable ! ( ) ,
146
+ }
147
+ }
164
148
}
165
149
166
- impl From < MultiSignatureError > for StmSignatureError {
150
+ impl From < MultiSignatureError > for CoreVerifierError {
167
151
fn from ( e : MultiSignatureError ) -> Self {
168
152
match e {
169
- MultiSignatureError :: SerializationError => Self :: SerializationError ,
170
- MultiSignatureError :: SignatureInvalid ( e) => Self :: SignatureInvalid ( e) ,
153
+ MultiSignatureError :: AggregateSignatureInvalid => Self :: AggregateSignatureInvalid ,
171
154
MultiSignatureError :: BatchInvalid => unreachable ! ( ) ,
155
+ MultiSignatureError :: SerializationError => unreachable ! ( ) ,
172
156
MultiSignatureError :: KeyInvalid ( _) => unreachable ! ( ) ,
173
- MultiSignatureError :: AggregateSignatureInvalid => unreachable ! ( ) ,
157
+ MultiSignatureError :: SignatureInvalid ( _e ) => unreachable ! ( ) ,
174
158
MultiSignatureError :: SignatureInfinity ( _) => unreachable ! ( ) ,
175
159
MultiSignatureError :: VerificationKeyInfinity ( _) => unreachable ! ( ) ,
176
160
}
177
161
}
178
162
}
179
163
180
- impl < D : Digest + FixedOutput > From < MerkleTreeError < D > > for StmSignatureError {
181
- fn from ( e : MerkleTreeError < D > ) -> Self {
182
- match e {
183
- MerkleTreeError :: SerializationError => Self :: SerializationError ,
184
- _ => unreachable ! ( ) ,
185
- }
164
+ impl From < StmSignatureError > for CoreVerifierError {
165
+ fn from ( e : StmSignatureError ) -> Self {
166
+ CoreVerifierError :: IndividualSignatureInvalid ( e)
186
167
}
187
168
}
188
169
170
+ /// Errors which can be output by Mithril aggregate verification.
171
+ #[ derive( Debug , Clone , thiserror:: Error ) ]
172
+ pub enum StmAggregateSignatureError < D : Digest + FixedOutput > {
173
+ /// The IVK is invalid after aggregating the keys
174
+ #[ error( "Aggregated key does not correspond to the expected key." ) ]
175
+ IvkInvalid ( Box < VerificationKey > ) ,
176
+
177
+ /// This error occurs when the the serialization of the raw bytes failed
178
+ #[ error( "Invalid bytes" ) ]
179
+ SerializationError ,
180
+
181
+ /// Invalid merkle batch path
182
+ #[ error( "Batch path does not verify against root" ) ]
183
+ PathInvalid ( BatchPath < D > ) ,
184
+
185
+ /// Batch verification of STM aggregate signatures failed
186
+ #[ error( "Batch verification of STM aggregate signatures failed" ) ]
187
+ BatchInvalid ,
188
+
189
+ /// `CoreVerifier` check failed
190
+ #[ error( "Core verification error: {0}" ) ]
191
+ CoreVerificationError ( #[ source] CoreVerifierError ) ,
192
+ }
193
+
189
194
impl < D : Digest + FixedOutput > From < MerkleTreeError < D > > for StmAggregateSignatureError < D > {
190
195
fn from ( e : MerkleTreeError < D > ) -> Self {
191
196
match e {
@@ -233,33 +238,28 @@ impl<D: Digest + FixedOutput> From<StmSignatureError> for StmAggregateSignatureE
233
238
}
234
239
}
235
240
236
- impl From < AggregationError > for CoreVerifierError {
237
- fn from ( e : AggregationError ) -> Self {
238
- match e {
239
- AggregationError :: NotEnoughSignatures ( e, _e) => Self :: NoQuorum ( e, e) ,
240
- AggregationError :: UsizeConversionInvalid => unreachable ! ( ) ,
241
- }
242
- }
243
- }
241
+ /// Errors which can be outputted by key registration.
242
+ #[ derive( Debug , Clone , thiserror:: Error , PartialEq , Eq ) ]
243
+ pub enum RegisterError {
244
+ /// This key has already been registered by a participant
245
+ #[ error( "This key has already been registered." ) ]
246
+ KeyRegistered ( Box < VerificationKey > ) ,
244
247
245
- impl From < MultiSignatureError > for CoreVerifierError {
246
- fn from ( e : MultiSignatureError ) -> Self {
247
- match e {
248
- MultiSignatureError :: AggregateSignatureInvalid => Self :: AggregateSignatureInvalid ,
249
- MultiSignatureError :: BatchInvalid => unreachable ! ( ) ,
250
- MultiSignatureError :: SerializationError => unreachable ! ( ) ,
251
- MultiSignatureError :: KeyInvalid ( _) => unreachable ! ( ) ,
252
- MultiSignatureError :: SignatureInvalid ( _e) => unreachable ! ( ) ,
253
- MultiSignatureError :: SignatureInfinity ( _) => unreachable ! ( ) ,
254
- MultiSignatureError :: VerificationKeyInfinity ( _) => unreachable ! ( ) ,
255
- }
256
- }
257
- }
248
+ /// Verification key is the infinity
249
+ #[ error( "Verification key is the infinity" ) ]
250
+ VerificationKeyInfinity ( Box < VerificationKey > ) ,
258
251
259
- impl From < StmSignatureError > for CoreVerifierError {
260
- fn from ( e : StmSignatureError ) -> Self {
261
- CoreVerifierError :: IndividualSignatureInvalid ( e)
262
- }
252
+ /// The supplied key is not valid
253
+ #[ error( "The verification of correctness of the supplied key is invalid." ) ]
254
+ KeyInvalid ( Box < VerificationKeyPoP > ) ,
255
+
256
+ /// Serialization error
257
+ #[ error( "Serialization error" ) ]
258
+ SerializationError ,
259
+
260
+ /// UnregisteredInitializer error
261
+ #[ error( "Initializer not registered. Cannot participate as a signer." ) ]
262
+ UnregisteredInitializer ,
263
263
}
264
264
265
265
impl From < MultiSignatureError > for RegisterError {
0 commit comments