Replace use of con_serde in sighash test
What changed, and why it matters
This commit is a routine internal test refactor. It swaps one test-only helper for another so that a unit test can still decode hex transaction data after an older helper is removed. There is no change to production code or to how real transactions are handled.
No security action needed. Treat as normal maintenance/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The bip_341_sighash_tests unit test previously used crate::consensus::serde (con_serde) with a Hex wrapper to deserialize a raw_unsigned_tx field from JSON test vectors. Because the project plans to remove the old consensus logic, the test now uses a locally defined tx_deser_hex helper that calls crate::encoding::decode_from_hex. The bitcoin-consensus-encoding dependency also gains the hex feature. Only test code and test dependency features are affected.
Changed components
bitcoin/src/crypto/sighash.rs (test module only)bitcoin/Cargo.toml (test dependency feature flag)Inspect captured patch +12 / −3
diff --git a/bitcoin/Cargo.toml b/bitcoin/Cargo.toml
index 436dd136..4d4e93b6 100644
--- a/bitcoin/Cargo.toml
+++ b/bitcoin/Cargo.toml
@@ -31,7 +31,7 @@ bech32 = { version = "0.11.0", default-features = false, features = ["alloc"] }
crypto = { package = "bitcoin-crypto", path = "../crypto", version = "0.2.0", default-features = false, features = ["alloc", "hex"] }
hashes = { package = "bitcoin_hashes", path = "../hashes", version = "1.0.0", default-features = false, features = ["alloc", "hex"] }
key-expression = { package = "bitcoin-key-expression", path = "../key_expression", version = "0.1.0", default-features = false, features = ["alloc"] }
-encoding = { package = "bitcoin-consensus-encoding", path = "../consensus_encoding", version = "1.0.0", default-features = false, features = ["alloc"] }
+encoding = { package = "bitcoin-consensus-encoding", path = "../consensus_encoding", version = "1.0.0", default-features = false, features = ["alloc", "hex"] }
hex = { package = "hex-conservative", version = "1.1.0", default-features = false, features = ["alloc"] }
internals = { package = "bitcoin-internals", path = "../internals", version = "0.5.0", features = ["alloc", "hex"] }
io = { package = "bitcoin-io", path = "../io", version = "0.5.0", default-features = false, features = ["alloc", "hashes"] }
diff --git a/bitcoin/src/crypto/sighash.rs b/bitcoin/src/crypto/sighash.rs
index 1afc2261..c2db1a38 100644
--- a/bitcoin/src/crypto/sighash.rs
+++ b/bitcoin/src/crypto/sighash.rs
@@ -1700,9 +1700,18 @@ mod tests {
})
}
+ fn tx_deser_hex<'de, D>(deserializer: D) -> Result<Transaction, D::Error>
+ where
+ D: serde::Deserializer<'de>,
+ {
+ use serde::de::{Deserialize, Error};
+
+ let hex_str = String::deserialize(deserializer)?;
+ crate::encoding::decode_from_hex(&hex_str).map_err(D::Error::custom)
+ }
+
use secp256k1::SecretKey;
- use crate::consensus::serde as con_serde;
use crate::crypto::key::XOnlyPublicKey;
use crate::key::{Keypair, PrivateKey, TapTweak};
use crate::taproot::TapNodeHash;
@@ -1719,7 +1728,7 @@ mod tests {
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct KpsGiven {
- #[serde(with = "con_serde::With::<con_serde::Hex>")]
+ #[serde(deserialize_with = "tx_deser_hex")]
raw_unsigned_tx: Transaction,
utxos_spent: Vec<UtxoSpent>,
}
Why this scored 15/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.