Skip to content

Commit 92f2b93

Browse files
committed
review suggestions
1 parent dc2d058 commit 92f2b93

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-stm/src/error.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub enum MultiSignatureError {
3636

3737
/// Verification key is the infinity
3838
#[error("Verification key is the infinity")]
39-
VerificationKeyInfinity,
39+
VerificationKeyInfinity(VerificationKey),
4040
}
4141

4242
/// Errors which can be output by Mithril single signature verification.
@@ -168,7 +168,7 @@ impl From<MultiSignatureError> for StmSignatureError {
168168
MultiSignatureError::KeyInvalid(_) => unreachable!(),
169169
MultiSignatureError::AggregateSignatureInvalid => unreachable!(),
170170
MultiSignatureError::SignatureInfinity(_) => unreachable!(),
171-
MultiSignatureError::VerificationKeyInfinity => unreachable!(),
171+
MultiSignatureError::VerificationKeyInfinity(_) => unreachable!(),
172172
}
173173
}
174174
}
@@ -207,7 +207,7 @@ impl<D: Digest + FixedOutput> From<MultiSignatureError> for StmAggregateSignatur
207207
MultiSignatureError::SignatureInfinity(_) => {
208208
Self::CoreVerificationError(CoreVerifierError::from(e))
209209
}
210-
MultiSignatureError::VerificationKeyInfinity => {
210+
MultiSignatureError::VerificationKeyInfinity(_) => {
211211
Self::CoreVerificationError(CoreVerifierError::from(e))
212212
}
213213
}
@@ -247,7 +247,7 @@ impl From<MultiSignatureError> for CoreVerifierError {
247247
MultiSignatureError::KeyInvalid(_) => unreachable!(),
248248
MultiSignatureError::SignatureInvalid(_e) => unreachable!(),
249249
MultiSignatureError::SignatureInfinity(_) => unreachable!(),
250-
MultiSignatureError::VerificationKeyInfinity => unreachable!(),
250+
MultiSignatureError::VerificationKeyInfinity(_) => unreachable!(),
251251
}
252252
}
253253
}
@@ -273,15 +273,18 @@ impl From<MultiSignatureError> for RegisterError {
273273
pub(crate) fn blst_err_to_mithril(
274274
e: BLST_ERROR,
275275
sig: Option<Signature>,
276+
key: Option<VerificationKey>
276277
) -> Result<(), MultiSignatureError> {
277278
match e {
278279
BLST_ERROR::BLST_SUCCESS => Ok(()),
279280
BLST_ERROR::BLST_PK_IS_INFINITY => {
280281
if let Some(s) = sig {
281-
Err(MultiSignatureError::SignatureInfinity(s))
282-
} else {
283-
Err(MultiSignatureError::VerificationKeyInfinity)
282+
return Err(MultiSignatureError::SignatureInfinity(s));
283+
}
284+
if let Some(vk) = key {
285+
return Err(MultiSignatureError::VerificationKeyInfinity(vk));
284286
}
287+
Err(MultiSignatureError::SerializationError)
285288
}
286289
BLST_ERROR::BLST_VERIFY_FAIL => {
287290
if let Some(s) = sig {

mithril-stm/src/multi_sig.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl SigningKey {
8888
pub fn from_bytes(bytes: &[u8]) -> Result<Self, MultiSignatureError> {
8989
match BlstSk::from_bytes(&bytes[..32]) {
9090
Ok(sk) => Ok(Self(sk)),
91-
Err(e) => Err(blst_err_to_mithril(e, None)
91+
Err(e) => Err(blst_err_to_mithril(e, None, None)
9292
.expect_err("If deserialization is not successful, blst returns and error different to SUCCESS."))
9393
}
9494
}
@@ -108,7 +108,7 @@ impl VerificationKey {
108108
pub fn from_bytes(bytes: &[u8]) -> Result<Self, MultiSignatureError> {
109109
match BlstVk::key_validate(&bytes[..96]) {
110110
Ok(vk) => Ok(Self(vk)),
111-
Err(e) => Err(blst_err_to_mithril(e, None)
111+
Err(e) => Err(blst_err_to_mithril(e, None, None)
112112
.expect_err("If deserialization is not successful, blst returns and error different to SUCCESS."))
113113
}
114114
}
@@ -207,7 +207,7 @@ impl VerificationKeyPoP {
207207
}
208208
Ok(())
209209
}
210-
Err(e) => blst_err_to_mithril(e, None),
210+
Err(e) => blst_err_to_mithril(e, None, Some(self.vk)),
211211
}
212212
}
213213

@@ -265,7 +265,7 @@ impl ProofOfPossession {
265265
let k1 = match BlstSig::from_bytes(&bytes[..48]) {
266266
Ok(key) => key,
267267
Err(e) => {
268-
return Err(blst_err_to_mithril(e, None)
268+
return Err(blst_err_to_mithril(e, None, None)
269269
.expect_err("If it passed, blst returns and error different to SUCCESS."))
270270
}
271271
};
@@ -295,8 +295,9 @@ impl Signature {
295295
Ok(_) => blst_err_to_mithril(
296296
self.0.verify(false, msg, &[], &[], &mvk.0, false),
297297
Some(*self),
298+
None,
298299
),
299-
Err(e) => blst_err_to_mithril(e, Some(*self)),
300+
Err(e) => blst_err_to_mithril(e, Some(*self), None),
300301
}
301302
}
302303

@@ -330,7 +331,7 @@ impl Signature {
330331
pub fn from_bytes(bytes: &[u8]) -> Result<Self, MultiSignatureError> {
331332
match BlstSig::sig_validate(&bytes[..48], true) {
332333
Ok(sig) => Ok(Self(sig)),
333-
Err(e) => Err(blst_err_to_mithril(e, None)
334+
Err(e) => Err(blst_err_to_mithril(e, None, None)
334335
.expect_err("If deserialization is not successful, blst returns and error different to SUCCESS."))
335336
}
336337
}
@@ -405,7 +406,7 @@ impl Signature {
405406

406407
blst_err_to_mithril(
407408
aggr_sig.0.verify(false, msg, &[], &[], &aggr_vk.0, false),
408-
Some(aggr_sig),
409+
Some(aggr_sig), None,
409410
)
410411
}
411412

@@ -421,7 +422,7 @@ impl Signature {
421422
false,
422423
) {
423424
Ok(sig) => BlstSig::from_aggregate(&sig),
424-
Err(e) => return blst_err_to_mithril(e, None),
425+
Err(e) => return blst_err_to_mithril(e, None, None),
425426
};
426427

427428
let p2_vks: Vec<&BlstVk> = vks.iter().map(|vk| &vk.0).collect();
@@ -433,6 +434,7 @@ impl Signature {
433434
blst_err_to_mithril(
434435
batched_sig.aggregate_verify(false, &slice_msgs, &[], &p2_vks, false),
435436
None,
437+
None
436438
)
437439
.map_err(|_| MultiSignatureError::BatchInvalid)
438440
}

0 commit comments

Comments
 (0)