From 4ac0321acb76ac3dbd692cb1033adfdd9ef4e4d2 Mon Sep 17 00:00:00 2001 From: gerlofvanek Date: Mon, 8 Jun 2026 22:47:23 +0200 Subject: [PATCH] Verify initiate lock-tx amount. --- basicswap/basicswap.py | 12 ++++++++++++ basicswap/interface/bch.py | 1 + basicswap/interface/btc.py | 4 ++++ basicswap/interface/dcr/dcr.py | 1 + basicswap/interface/firo.py | 2 ++ basicswap/interface/nav.py | 2 ++ 6 files changed, 22 insertions(+) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 1bc38e7..88c7c7b 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -8454,6 +8454,18 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp): ) index = None if found: + if ( + "value" in found + and found["value"] is not None + and found["value"] != int(bid.amount) + ): + self.setBidError( + bid, + "Incorrect output amount in initiate txn {}: {} != {}.".format( + initiate_txnid_hex, found["value"], int(bid.amount) + ), + ) + return True bid.initiate_tx.conf = found["depth"] if "index" in found: index = found["index"] diff --git a/basicswap/interface/bch.py b/basicswap/interface/bch.py index b81e1b1..2c71f4a 100644 --- a/basicswap/interface/bch.py +++ b/basicswap/interface/bch.py @@ -322,6 +322,7 @@ class BCHInterface(BTCInterface): "depth": confirmations, "index": found_vout, "height": block_height, + "value": self.make_int(txout["value"]), } return rv diff --git a/basicswap/interface/btc.py b/basicswap/interface/btc.py index da62769..0488deb 100644 --- a/basicswap/interface/btc.py +++ b/basicswap/interface/btc.py @@ -3006,6 +3006,8 @@ class BTCInterface(FeeValidator, Secp256k1Interface): if find_index: tx_obj = self.rpc("decoderawtransaction", [tx["hex"]]) rv["index"] = find_vout_for_address_from_txobj(tx_obj, dest_address) + if rv["index"] is not None and rv["index"] >= 0: + rv["value"] = self.make_int(tx_obj["vout"][rv["index"]]["value"]) if return_txid: rv["txid"] = txid.hex() @@ -3063,6 +3065,7 @@ class BTCInterface(FeeValidator, Secp256k1Interface): for idx, txout in enumerate(tx.vout): if txout.scriptPubKey == dest_script: rv["index"] = idx + rv["value"] = txout.nValue break except Exception: pass @@ -3124,6 +3127,7 @@ class BTCInterface(FeeValidator, Secp256k1Interface): for idx, txout in enumerate(tx.vout): if txout.scriptPubKey == dest_script: rv["index"] = idx + rv["value"] = txout.nValue break except Exception as e: self._log.debug( diff --git a/basicswap/interface/dcr/dcr.py b/basicswap/interface/dcr/dcr.py index ac677a4..5765e97 100644 --- a/basicswap/interface/dcr/dcr.py +++ b/basicswap/interface/dcr/dcr.py @@ -940,6 +940,7 @@ class DCRInterface(FeeValidator, Secp256k1Interface): "depth": confirmations, "index": found_vout, "height": block_height, + "value": self.make_int(txout["value"]), } return rv diff --git a/basicswap/interface/firo.py b/basicswap/interface/firo.py index d799ab0..24b1d20 100644 --- a/basicswap/interface/firo.py +++ b/basicswap/interface/firo.py @@ -276,6 +276,8 @@ class FIROInterface(BTCInterface): if find_index: tx_obj = self.rpc("decoderawtransaction", [tx["hex"]]) rv["index"] = find_vout_for_address_from_txobj(tx_obj, dest_address) + if rv["index"] is not None and rv["index"] >= 0: + rv["value"] = self.make_int(tx_obj["vout"][rv["index"]]["value"]) if return_txid: rv["txid"] = txid.hex() diff --git a/basicswap/interface/nav.py b/basicswap/interface/nav.py index 920d426..5d3a2f1 100644 --- a/basicswap/interface/nav.py +++ b/basicswap/interface/nav.py @@ -614,6 +614,8 @@ class NAVInterface(BTCInterface): if find_index: tx_obj = self.rpc("decoderawtransaction", [tx["hex"]]) rv["index"] = find_vout_for_address_from_txobj(tx_obj, dest_address) + if rv["index"] is not None and rv["index"] >= 0: + rv["value"] = self.make_int(tx_obj["vout"][rv["index"]]["value"]) if return_txid: rv["txid"] = txid.hex()