Skip to content

Commit

Permalink
add TweakCheck error
Browse files Browse the repository at this point in the history
  • Loading branch information
MCJOHN974 committed Jan 6, 2025
1 parent 960579c commit 021cec3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions signer/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ pub enum Error {
#[error("invalid tweak? seriously? {0}")]
InvalidPublicKeyTweak(#[source] secp256k1::Error),

/// This happens when a tweak produced by [`XOnlyPublicKey::add_tweak`] was computed incorrectly.
/// One if possible reasons is that you tweaked same key twice.
#[error("Tweak was computed incorrectly.")]
InvalidPublicKeyTweakCheck,

/// This occurs when converting a byte slice to our internal public key
/// type, which is a thin wrapper around the secp256k1::SecretKey.
#[error("invalid private key: {0}")]
Expand Down
4 changes: 3 additions & 1 deletion signer/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ impl SignerScriptPubKey for secp256k1::XOnlyPublicKey {
.add_tweak(SECP256K1, &tweak)
.map_err(Error::InvalidPublicKeyTweak)?;

debug_assert!(self.tweak_add_check(SECP256K1, &output_key, parity, tweak));
if !self.tweak_add_check(SECP256K1, &output_key, parity, tweak) {
return Err(Error::InvalidPublicKeyTweakCheck);
}
let pk = secp256k1::PublicKey::from_x_only_public_key(output_key, parity);
Ok(PublicKey(pk))
}
Expand Down

0 comments on commit 021cec3

Please sign in to comment.