From 345426fb50b7e80042ab6df2b8cd994ea9530658 Mon Sep 17 00:00:00 2001 From: Steven Barclay Date: Wed, 18 Nov 2020 20:45:58 +0000 Subject: [PATCH] Add further validation checks for delayed payout tx Do some extra sanity checks like tx.outputSum < tx.inputSum, to rule out any edge cases where an invalid delayed payout tx might still arise. --- .../main/java/bisq/core/btc/wallet/TradeWalletService.java | 4 ++++ .../protocol/tasks/seller/SellerCreatesDelayedPayoutTx.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java b/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java index 0373a4a5dce..2b05f47c182 100644 --- a/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java +++ b/core/src/main/java/bisq/core/btc/wallet/TradeWalletService.java @@ -76,6 +76,7 @@ public class TradeWalletService { private static final Logger log = LoggerFactory.getLogger(TradeWalletService.class); + private static final Coin MIN_DELAYED_PAYOUT_TX_FEE = Coin.valueOf(1000); private final WalletsSetup walletsSetup; private final Preferences preferences; @@ -766,6 +767,9 @@ public Transaction finalizeUnconnectedDelayedPayoutTx(Transaction delayedPayoutT WalletService.printTx("finalizeDelayedPayoutTx", delayedPayoutTx); WalletService.verifyTransaction(delayedPayoutTx); + if (checkNotNull(inputValue).isLessThan(delayedPayoutTx.getOutputSum().add(MIN_DELAYED_PAYOUT_TX_FEE))) { + throw new TransactionVerificationException("Delayed payout tx is paying less than the minimum allowed tx fee"); + } Script scriptPubKey = get2of2MultiSigOutputScript(buyerPubKey, sellerPubKey, false); input.getScriptSig().correctlySpends(delayedPayoutTx, 0, witness, inputValue, scriptPubKey, Script.ALL_VERIFY_FLAGS); return delayedPayoutTx; diff --git a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerCreatesDelayedPayoutTx.java b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerCreatesDelayedPayoutTx.java index ae9048bec7b..a466f112643 100644 --- a/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerCreatesDelayedPayoutTx.java +++ b/core/src/main/java/bisq/core/trade/protocol/tasks/seller/SellerCreatesDelayedPayoutTx.java @@ -20,6 +20,7 @@ import bisq.core.btc.wallet.TradeWalletService; import bisq.core.dao.governance.param.Param; import bisq.core.trade.Trade; +import bisq.core.trade.TradeDataValidation; import bisq.core.trade.protocol.tasks.TradeTask; import bisq.common.taskrunner.TaskRunner; @@ -53,6 +54,10 @@ protected void run() { donationAddressString, minerFee, lockTime); + TradeDataValidation.validateDelayedPayoutTx(trade, + preparedDelayedPayoutTx, + processModel.getDaoFacade(), + processModel.getBtcWalletService()); processModel.setPreparedDelayedPayoutTx(preparedDelayedPayoutTx);