Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input validation #4381

Merged
merged 1 commit into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions core/src/main/java/bisq/core/trade/DelayedPayoutTxValidation.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionInput;
import org.bitcoinj.core.TransactionOutPoint;
import org.bitcoinj.core.TransactionOutput;

import java.util.List;
Expand Down Expand Up @@ -70,6 +71,12 @@ public static class InvalidLockTimeException extends Exception {
}
}

public static class InvalidInputException extends Exception {
InvalidInputException(String msg) {
super(msg);
}
}

public static void validatePayoutTx(Trade trade,
Transaction delayedPayoutTx,
DaoFacade daoFacade,
Expand Down Expand Up @@ -184,4 +191,19 @@ public static void validatePayoutTx(Trade trade,
throw new DonationAddressException(errorMsg);
}
}

public static void validatePayoutTxInput(Transaction depositTx,
Transaction delayedPayoutTx)
throws InvalidInputException {
TransactionInput input = delayedPayoutTx.getInput(0);
checkNotNull(input, "delayedPayoutTx.getInput(0) must not be null");
// input.getConnectedOutput() is null as the tx is not committed at that point

TransactionOutPoint outpoint = input.getOutpoint();
if (!outpoint.getHash().toString().equals(depositTx.getHashAsString()) || outpoint.getIndex() != 0) {
throw new InvalidInputException("Input of delayed payout transaction does not point to output of deposit tx.\n" +
"Delayed payout tx=" + delayedPayoutTx + "\n" +
"Deposit tx=" + depositTx);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkNotNull;

@Slf4j
public class BuyerVerifiesFinalDelayedPayoutTx extends TradeTask {
@SuppressWarnings({"unused"})
Expand All @@ -40,18 +42,25 @@ protected void run() {
runInterceptHook();

Transaction delayedPayoutTx = trade.getDelayedPayoutTx();
checkNotNull(delayedPayoutTx, "trade.getDelayedPayoutTx() must not be null");
// Check again tx
DelayedPayoutTxValidation.validatePayoutTx(trade,
delayedPayoutTx,
processModel.getDaoFacade(),
processModel.getBtcWalletService());

// Now as we know the deposit tx we can also verify the input
Transaction depositTx = trade.getDepositTx();
checkNotNull(depositTx, "trade.getDepositTx() must not be null");
DelayedPayoutTxValidation.validatePayoutTxInput(depositTx, delayedPayoutTx);

complete();
} catch (DelayedPayoutTxValidation.DonationAddressException |
DelayedPayoutTxValidation.MissingDelayedPayoutTxException |
DelayedPayoutTxValidation.InvalidTxException |
DelayedPayoutTxValidation.InvalidLockTimeException |
DelayedPayoutTxValidation.AmountMismatchException e) {
DelayedPayoutTxValidation.AmountMismatchException |
DelayedPayoutTxValidation.InvalidInputException e) {
failed(e.getMessage());
} catch (Throwable t) {
failed(t);
Expand Down