Remove uses of default XOnlyPublicKey serde
What changed, and why it matters
This commit removes and replaces default serialization/deserialization handling for a special Bitcoin public key type (XOnlyPublicKey) in the rust-bitcoin library. It is a cleanup/refactoring change to prepare for a future removal of the old default serde implementation. It also removes derived serde support from two related types (ControlBlock and TweakedPublicKey). There is no direct security fix here; it is an internal API and test-data cleanup.
No immediate security action required. Downstream users relying on serde for ControlBlock or TweakedPublicKey should review the upcoming API changes and migration guidance when the default XOnlyPublicKey serde implementation is removed. Monitor the project for the follow-up commit that actually removes the default serde implementation.
Security signals we found
No security-relevant bug is fixed in the diff
Change is framed by the author as a prerequisite for removing default serde impls, not as a security fix
No input validation, cryptographic, or memory-safety changes are visible
Removal of serde derives could affect downstream consumers but is an intentional API change
Evidence from the diff
The commit removes the default serde derive on ControlBlock and TweakedPublicKey, deletes a serde regression test and its hex fixture for ControlBlock, and switches one test field (internal_pubkey) to use the new x_only_serde module. The stated goal is to eliminate existing uses of the default XOnlyPublicKey serde implementation before that default implementation is removed. This is a preparatory refactoring commit, not a patch for a reported vulnerability.
Changed components
bitcoin/src/taproot/mod.rs (ControlBlock serde derive removed)crypto/src/key.rs (TweakedPublicKey serde derive removed)bitcoin/tests/serde.rs (ControlBlock serde regression test removed)bitcoin/tests/data/serde/control_block_hex (test fixture removed)bitcoin/tests/sighash.rs (XOnlyPublicKey test field switched to x_only_serde module)Inspect captured patch +2 / −18
### bitcoin/src/taproot/mod.rs
@@ -985,7 +985,6 @@ impl<'leaf> ScriptLeaf<'leaf> {
/// Control block data structure used in Tapscript satisfaction.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
-#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ControlBlock<Branch = TaprootMerkleBranchBuf, Key = UntweakedPublicKey>
where
Branch: ?Sized,
### bitcoin/tests/data/serde/control_block_hex
@@ -1 +0,0 @@
-c1a9d6f66cd4b25004f526bfa873e56942f98e8e492bd79ed6532b966104817c2bda584e7d32612381cf88edc1c02e28a296e807c16ad22f591ee113946e48a71e0641e660d1e5392fb79d64838c2b84faf04b7f5f283c9d8bf83e39e177b64372a0cd22eeab7e093873e851e247714eff762d8a30be699ba4456cfe6491b282e193a071350ae099005a5950d74f73ba13077a57bc478007fb0e4d1099ce9cf3d4
### bitcoin/tests/serde.rs
@@ -23,7 +23,7 @@ use bincode::serialize;
use bitcoin::bip32::{ChildNumber, Xpriv, Xpub};
use bitcoin::locktime::{absolute, relative};
use bitcoin::sighash::{EcdsaSighashType, TapSighashType};
-use bitcoin::taproot::{self, ControlBlock, LeafVersion, TapTree, TaprootBuilder};
+use bitcoin::taproot::{self, LeafVersion, TapTree, TaprootBuilder};
use bitcoin::witness::Witness;
use bitcoin::{
ecdsa, hex, Address, AddressParams, LegacyPublicKey, OutPoint, ScriptSigBuf, TapScriptBuf,
@@ -150,16 +150,6 @@ fn serde_regression_ecdsa_sig() {
assert_eq!(got, want)
}
-#[test]
-fn serde_regression_control_block() {
- let s = include_str!("data/serde/control_block_hex");
- let block = ControlBlock::decode(&hex::decode_to_vec(s.trim()).unwrap()).unwrap();
-
- let got = serialize(&block).unwrap();
- let want = include_bytes!("data/serde/control_block_bincode") as &[_];
- assert_eq!(got, want)
-}
-
#[test]
fn serde_regression_child_number() {
let num = ChildNumber::from_raw(0xDEADBEEF);
### bitcoin/tests/sighash.rs
@@ -127,6 +127,7 @@ fn bip_341_sighash_tests() {
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct KpsInputSpendingIntermediary {
+ #[serde(with = "bitcoin::key::x_only_serde::without_parity")]
internal_pubkey: XOnlyPublicKey,
tweaked_privkey: SecretKey,
sig_msg: String,
### crypto/src/key.rs
@@ -216,15 +216,10 @@ mod private_key {
}
mod tweaked_public_key {
- #[cfg(feature = "serde")]
- use serde::{Deserialize, Serialize};
-
use super::{TweakedKeypair, XOnlyPublicKey};
/// Tweaked BIP-0340 X-coord-only public key.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
- #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
- #[cfg_attr(feature = "serde", serde(transparent))]
pub struct TweakedPublicKey(XOnlyPublicKey);
impl TweakedPublicKey {Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.