From 6502f7dcd7218de0171795aa1e853471177640aa Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Sat, 29 Jan 2022 13:19:34 -0600 Subject: [PATCH] fix: do not panic when validating events with malformed pubkeys --- src/event.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/event.rs b/src/event.rs index a9a8261..700ea8c 100644 --- a/src/event.rs +++ b/src/event.rs @@ -148,9 +148,13 @@ impl Event { let sig = schnorr::Signature::from_str(&self.sig).unwrap(); if let Ok(msg) = secp256k1::Message::from_slice(digest.as_ref()) { - let pubkey = XOnlyPublicKey::from_str(&self.pubkey).unwrap(); - let verify = SECP.verify_schnorr(&sig, &msg, &pubkey); - matches!(verify, Ok(())) + if let Ok(pubkey) = XOnlyPublicKey::from_str(&self.pubkey) { + let verify = SECP.verify_schnorr(&sig, &msg, &pubkey); + matches!(verify, Ok(())) + } else { + info!("Client sent malformed pubkey"); + false + } } else { warn!("Error converting digest to secp256k1 message"); false