From 289dc1e7f5e99d5853d694596da586f831ebd292 Mon Sep 17 00:00:00 2001 From: sanket1729 Date: Fri, 24 Feb 2023 01:35:58 -0800 Subject: [PATCH] Remove serde for taprootspendinfo Implementing this for spendinfo is really complicated because it contains some cached data without retaining the components that are used to compute them. Users should serde the 1) NodeInfo and 2) internal key and reconstruct TaprootSpendInfo from it. --- bitcoin/src/taproot.rs | 2 -- .../data/serde/taproot_spend_info_bincode | Bin 724 -> 0 bytes bitcoin/tests/serde.rs | 27 +----------------- 3 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 bitcoin/tests/data/serde/taproot_spend_info_bincode diff --git a/bitcoin/src/taproot.rs b/bitcoin/src/taproot.rs index d0d3408f6..2b47e3311 100644 --- a/bitcoin/src/taproot.rs +++ b/bitcoin/src/taproot.rs @@ -186,8 +186,6 @@ type ScriptMerkleProofMap = BTreeMap<(ScriptBuf, LeafVersion), BTreeSet{)fd8`7vrqm#X~I{s zzb zPW%|YHaer^cHdvV2k&ck_<5GCc?NSw5ZpyfP?x|=SRpxgN1XhWor25k|D9vh-m(6q zqT$n7iO!C<{Vo}5*?7RzO~|t}l4sb^(d;&}?OKY6)tkR_E02UmTsgljy3FRhO##fN zV4OA`D*N}*B4a}0?1qP2UPi4&H%lh3y_9)hN_6>;`CTvGaFS|M2u_;}H?@ZSe0uTt zkCWSY(tTcR-1Wi6+^U*wg^Zy2F-40x<}jOx4ZTpfP3ZBtB3hCC`@~IIEzcuzG|nAA aov5I9`GTa&4Wj^lGxMfvr7)YQ6`ug`7W;Pq diff --git a/bitcoin/tests/serde.rs b/bitcoin/tests/serde.rs index fe67a5424..bb76b88ef 100644 --- a/bitcoin/tests/serde.rs +++ b/bitcoin/tests/serde.rs @@ -33,16 +33,14 @@ use bitcoin::blockdata::witness::Witness; use bitcoin::consensus::encode::deserialize; use bitcoin::hashes::hex::FromHex; use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash}; -use bitcoin::key::UntweakedPublicKey; use bitcoin::psbt::raw::{self, Key, Pair, ProprietaryKey}; use bitcoin::psbt::{Input, Output, Psbt, PsbtSighashType}; use bitcoin::sighash::{EcdsaSighashType, TapSighashType}; -use bitcoin::taproot::{self, ControlBlock, LeafVersion, TaprootBuilder, TaprootSpendInfo, TapTree}; +use bitcoin::taproot::{self, ControlBlock, LeafVersion, TaprootBuilder, TapTree}; use bitcoin::{ ecdsa, Address, Block, Network, OutPoint, PrivateKey, PublicKey, ScriptBuf, Sequence, Target, Transaction, TxIn, TxOut, Txid, Work, }; -use secp256k1::Secp256k1; /// Implicitly does regression test for `BlockHeader` also. #[test] @@ -365,29 +363,6 @@ fn serde_regression_taptree() { assert_eq!(got, want) } -#[test] -fn serde_regression_taproot_spend_info() { - let secp = Secp256k1::verification_only(); - let internal_key = UntweakedPublicKey::from_str( - "93c7378d96518a75448821c4f7c8f4bae7ce60f804d03d1f0628dd5dd0f5de51", - ) - .unwrap(); - - let script_weights = vec![ - (10, ScriptBuf::from_hex("51").unwrap()), // semantics of script don't matter for this test - (20, ScriptBuf::from_hex("52").unwrap()), - (20, ScriptBuf::from_hex("53").unwrap()), - (30, ScriptBuf::from_hex("54").unwrap()), - (19, ScriptBuf::from_hex("55").unwrap()), - ]; - let tree_info = - TaprootSpendInfo::with_huffman_tree(&secp, internal_key, script_weights).unwrap(); - - let got = serialize(&tree_info).unwrap(); - let want = include_bytes!("data/serde/taproot_spend_info_bincode") as &[_]; - assert_eq!(got, want) -} - // Used to get a 256 bit integer as a byte array. fn le_bytes() -> [u8; 32] { let x: u128 = 0xDEAD_BEEF_CAFE_BABE_DEAD_BEEF_CAFE_BABE;