Skip to content

Commit f796bb8

Browse files
committed
Fix crash bug with duplicate inputs within a transaction
1 parent 5526ad1 commit f796bb8

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/validation.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ int GetUTXOConfirmations(const COutPoint& outpoint)
534534
}
535535

536536

537-
bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCheckDuplicateInputs)
537+
bool CheckTransaction(const CTransaction& tx, CValidationState& state)
538538
{
539539
// Basic checks that don't depend on any context
540540
if (tx.vin.empty())
@@ -563,13 +563,12 @@ bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fChe
563563
}
564564
}
565565

566-
// Check for duplicate inputs - note that this check is slow so we skip it in CheckBlock
567-
if (fCheckDuplicateInputs) {
568-
std::set<COutPoint> vInOutPoints;
569-
for (const auto& txin : tx.vin) {
570-
if (!vInOutPoints.insert(txin.prevout).second)
571-
return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-duplicate");
572-
}
566+
// Check for duplicate inputs
567+
std::set<COutPoint> vInOutPoints;
568+
for (const auto& txin : tx.vin)
569+
{
570+
if (!vInOutPoints.insert(txin.prevout).second)
571+
return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-duplicate");
573572
}
574573

575574
if (tx.IsCoinBase()) {
@@ -3414,7 +3413,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
34143413

34153414
// Check transactions
34163415
for (const auto& tx : block.vtx) {
3417-
if (!CheckTransaction(*tx, state, false))
3416+
if (!CheckTransaction(*tx, state))
34183417
return state.Invalid(false, state.GetRejectCode(), state.GetRejectReason(),
34193418
strprintf("Transaction check failed (tx hash %s) %s", tx->GetHash().ToString(), state.GetDebugMessage()));
34203419

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
385385
/** Transaction validation functions */
386386

387387
/** Context-independent validity checks */
388-
bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCheckDuplicateInputs = true);
388+
bool CheckTransaction(const CTransaction& tx, CValidationState& state);
389389

390390
namespace Consensus
391391
{

0 commit comments

Comments
 (0)