From 202f6d1fa0c9ef082c59b02f73ab4027b0f0cd7f Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Tue, 25 May 2021 11:36:24 +1000 Subject: [PATCH] Bitcoin network check when building PSBT This ensures that funds are not sent to an address on the wrong network. --- CHANGELOG.md | 2 ++ swap/src/bitcoin/wallet.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d0d8e4d..589ac877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - An issue where long-running connections are dead without a connection closure being reported back to the swarm. Adding a periodic ping ensures that the connection is kept alive, and a broken connection is reported back resulting in a close event on the swarm. This fixes the error of the ASB being unable to send a transfer proof to the CLI. +- An issue where ASB Bitcoin withdrawal can be done to an address on the wrong network. + A network check was added that compares the wallet's network against the network of the given address when building the transaction. ## [0.6.0] - 2021-05-24 diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index 6268d64e..c39305f1 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -303,6 +303,10 @@ where address: Address, amount: Amount, ) -> Result { + if self.network != address.network { + bail!("Cannot build PSBT because network of given address is {} but wallet is on network {}", address.network, self.network); + } + let wallet = self.wallet.lock().await; let client = self.client.lock().await; let fee_rate = client.estimate_feerate(self.target_block)?;