From 3cc4ac137669c3ee4a6d602c533d16baedd83aa5 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 19 Sep 2018 15:04:35 +0300 Subject: [PATCH] Fix crash bug with duplicate inputs within a transaction (#2302) * Fix crash bug with duplicate inputs within a transaction Introduced by #9049 * Remove redundant parameter fCheckDuplicateInputs from CheckTransaction --- src/validation.cpp | 18 ++++++++---------- src/validation.h | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index 47bb76760..3b067eea9 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -513,7 +513,7 @@ int GetUTXOConfirmations(const COutPoint& outpoint) } -bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fCheckDuplicateInputs) +bool CheckTransaction(const CTransaction& tx, CValidationState &state) { // Basic checks that don't depend on any context if (tx.vin.empty()) @@ -539,14 +539,12 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe return state.DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge"); } - // Check for duplicate inputs - note that this check is slow so we skip it in CheckBlock - if (fCheckDuplicateInputs) { - std::set vInOutPoints; - for (const auto& txin : tx.vin) - { - if (!vInOutPoints.insert(txin.prevout).second) - return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-duplicate"); - } + // Check for duplicate inputs + std::set vInOutPoints; + for (const auto& txin : tx.vin) + { + if (!vInOutPoints.insert(txin.prevout).second) + return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-duplicate"); } if (tx.IsCoinBase()) @@ -3437,7 +3435,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P // Check transactions for (const auto& tx : block.vtx) - if (!CheckTransaction(*tx, state, false)) + if (!CheckTransaction(*tx, state)) return state.Invalid(false, state.GetRejectCode(), state.GetRejectReason(), strprintf("Transaction check failed (tx hash %s) %s", tx->GetHash().ToString(), state.GetDebugMessage())); diff --git a/src/validation.h b/src/validation.h index 91967b4e9..95bcaf595 100644 --- a/src/validation.h +++ b/src/validation.h @@ -389,7 +389,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight); /** Transaction validation functions */ /** Context-independent validity checks */ -bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCheckDuplicateInputs=true); +bool CheckTransaction(const CTransaction& tx, CValidationState& state); namespace Consensus {