Skip to content

Commit 8760d87

Browse files
committed
Merge #2188: fix(electrum): verify txid of server-returned transactions
d101a09 fix(electrum): verify txid of server-returned transactions (Elias Rohrer) Pull request description: ### Description An Electrum server could return an arbitrary transaction when `fetch_tx()` requests a specific txid. The returned transaction was cached and used without verifying that its computed txid matches the requested one. Add a verification check that `tx.compute_txid() == txid` after fetching from the server, returning an error on mismatch. Include a unit test with a mock Electrum client that exercises both the mismatch rejection and the matching-txid happy path. ACKs for top commit: evanlinjin: ACK d101a09 Tree-SHA512: aecb729fd7d92bf75ec2877b1717eaeed824178d81a5c769a738314326d4a1acddeded3b37837f3af84ca6c69b7c73bff46d901697a8f2125ea1d4c34bef6096
2 parents 10d9333 + d101a09 commit 8760d87

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

crates/electrum/src/bdk_electrum_client.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ impl<E: ElectrumApi> BdkElectrumClient<E> {
7878
drop(tx_cache);
7979

8080
let tx = Arc::new(self.inner.transaction_get(&txid)?);
81+
let returned_txid = tx.compute_txid();
82+
if returned_txid != txid {
83+
return Err(Error::Message(format!(
84+
"electrum server returned transaction with unexpected txid: expected {txid}, got {returned_txid}"
85+
)));
86+
}
8187

8288
self.tx_cache.lock().unwrap().insert(txid, Arc::clone(&tx));
8389

0 commit comments

Comments
 (0)