Skip to content

Commit 3e1fc40

Browse files
committed
refactor(wallet)!: remove TxOrdering::Bip69Lexicographic
BIP 69 proposed a deterministic way to sort transaction inputs and outputs with the idea of enhancing privacy. It was later discovered there was no such enhancement but rather a decrement in privacy due to this sorting. To avoid the promotion of bad practices, the TxOrdering::Bip69Lexicographic variant which implemented this BIP for BDK is removed with this change. Notice that you can still produce a BIP 69 compliant transaction defining order functions for TxOrdering::Custom.
1 parent 1354adc commit 3e1fc40

File tree

2 files changed

+22
-50
lines changed

2 files changed

+22
-50
lines changed

crates/wallet/src/wallet/tx_builder.rs

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,6 @@ pub enum TxOrdering {
776776
Shuffle,
777777
/// Unchanged
778778
Untouched,
779-
/// BIP69 / Lexicographic
780-
Bip69Lexicographic,
781779
/// Provide custom comparison functions for sorting
782780
Custom {
783781
/// Transaction inputs sort function
@@ -792,7 +790,6 @@ impl core::fmt::Debug for TxOrdering {
792790
match self {
793791
TxOrdering::Shuffle => write!(f, "Shuffle"),
794792
TxOrdering::Untouched => write!(f, "Untouched"),
795-
TxOrdering::Bip69Lexicographic => write!(f, "Bip69Lexicographic"),
796793
TxOrdering::Custom { .. } => write!(f, "Custom"),
797794
}
798795
}
@@ -817,13 +814,6 @@ impl TxOrdering {
817814
shuffle_slice(&mut tx.input, rng);
818815
shuffle_slice(&mut tx.output, rng);
819816
}
820-
TxOrdering::Bip69Lexicographic => {
821-
tx.input.sort_unstable_by_key(|txin| {
822-
(txin.previous_output.txid, txin.previous_output.vout)
823-
});
824-
tx.output
825-
.sort_unstable_by_key(|txout| (txout.value, txout.script_pubkey.clone()));
826-
}
827817
TxOrdering::Custom {
828818
input_sort,
829819
output_sort,
@@ -939,45 +929,6 @@ mod test {
939929
.expect("it should have moved the outputs at least once");
940930
}
941931

942-
#[test]
943-
fn test_output_ordering_bip69() {
944-
use core::str::FromStr;
945-
946-
let original_tx = ordering_test_tx!();
947-
let mut tx = original_tx;
948-
949-
TxOrdering::Bip69Lexicographic.sort_tx(&mut tx);
950-
951-
assert_eq!(
952-
tx.input[0].previous_output,
953-
bitcoin::OutPoint::from_str(
954-
"0e53ec5dfb2cb8a71fec32dc9a634a35b7e24799295ddd5278217822e0b31f57:5"
955-
)
956-
.unwrap()
957-
);
958-
assert_eq!(
959-
tx.input[1].previous_output,
960-
bitcoin::OutPoint::from_str(
961-
"0f60fdd185542f2c6ea19030b0796051e7772b6026dd5ddccd7a2f93b73e6fc2:0"
962-
)
963-
.unwrap()
964-
);
965-
assert_eq!(
966-
tx.input[2].previous_output,
967-
bitcoin::OutPoint::from_str(
968-
"0f60fdd185542f2c6ea19030b0796051e7772b6026dd5ddccd7a2f93b73e6fc2:1"
969-
)
970-
.unwrap()
971-
);
972-
973-
assert_eq!(tx.output[0].value.to_sat(), 800);
974-
assert_eq!(tx.output[1].script_pubkey, ScriptBuf::from(vec![0xAA]));
975-
assert_eq!(
976-
tx.output[2].script_pubkey,
977-
ScriptBuf::from(vec![0xAA, 0xEE])
978-
);
979-
}
980-
981932
#[test]
982933
fn test_output_ordering_custom_but_bip69() {
983934
use core::str::FromStr;

crates/wallet/tests/wallet.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
extern crate alloc;
2+
13
use std::path::Path;
24
use std::str::FromStr;
35

@@ -966,13 +968,32 @@ fn test_create_tx_drain_to_dust_amount() {
966968

967969
#[test]
968970
fn test_create_tx_ordering_respected() {
971+
use alloc::sync::Arc;
972+
969973
let (mut wallet, _) = get_funded_wallet_wpkh();
970974
let addr = wallet.next_unused_address(KeychainKind::External);
975+
976+
let bip69_txin_cmp = |tx_a: &TxIn, tx_b: &TxIn| {
977+
let project_outpoint = |t: &TxIn| (t.previous_output.txid, t.previous_output.vout);
978+
project_outpoint(tx_a).cmp(&project_outpoint(tx_b))
979+
};
980+
981+
let bip69_txout_cmp = |tx_a: &TxOut, tx_b: &TxOut| {
982+
let project_utxo = |t: &TxOut| (t.value, t.script_pubkey.clone());
983+
project_utxo(tx_a).cmp(&project_utxo(tx_b))
984+
};
985+
986+
let custom_bip69_ordering = bdk_wallet::wallet::tx_builder::TxOrdering::Custom {
987+
input_sort: Arc::new(bip69_txin_cmp),
988+
output_sort: Arc::new(bip69_txout_cmp),
989+
};
990+
971991
let mut builder = wallet.build_tx();
972992
builder
973993
.add_recipient(addr.script_pubkey(), Amount::from_sat(30_000))
974994
.add_recipient(addr.script_pubkey(), Amount::from_sat(10_000))
975-
.ordering(bdk_wallet::wallet::tx_builder::TxOrdering::Bip69Lexicographic);
995+
.ordering(custom_bip69_ordering);
996+
976997
let psbt = builder.finish().unwrap();
977998
let fee = check_fee!(wallet, psbt);
978999

0 commit comments

Comments
 (0)