Browse Source

Merge #14249: [0.16] Fix crash bug with duplicate inputs within a transaction

9bd08fd465 [qa] backport: Test for duplicate inputs within a transaction (Suhas Daftuar)
d1dee20547 Fix crash bug with duplicate inputs within a transaction (Suhas Daftuar)

Pull request description:

  This is a backport of #14247 to 0.16.

Tree-SHA512: f11b2b0f2d8089bbac7542f78a0f14fc15c693604cb1168ef5ea71852a206da7eb53b6e420376ed1380583961176ba2d283e409e19d783c7a68c3407933a89b0
0.16^2
Wladimir J. van der Laan 6 years ago
parent
commit
696b936aa3
No known key found for this signature in database
GPG Key ID: 1E4AED62986CD25D
  1. 2
      src/validation.cpp
  2. 13
      test/functional/p2p_invalid_block.py

2
src/validation.cpp

@ -3032,7 +3032,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P
// Check transactions // Check transactions
for (const auto& tx : block.vtx) for (const auto& tx : block.vtx)
if (!CheckTransaction(*tx, state, false)) if (!CheckTransaction(*tx, state, true))
return state.Invalid(false, state.GetRejectCode(), state.GetRejectReason(), return state.Invalid(false, state.GetRejectCode(), state.GetRejectReason(),
strprintf("Transaction check failed (tx hash %s) %s", tx->GetHash().ToString(), state.GetDebugMessage())); strprintf("Transaction check failed (tx hash %s) %s", tx->GetHash().ToString(), state.GetDebugMessage()));

13
test/functional/p2p_invalid_block.py

@ -95,7 +95,18 @@ class InvalidBlockRequestTest(ComparisonTestFramework):
assert(block2_orig.vtx != block2.vtx) assert(block2_orig.vtx != block2.vtx)
self.tip = block2.sha256 self.tip = block2.sha256
yield TestInstance([[block2, RejectResult(16, b'bad-txns-duplicate')], [block2_orig, True]]) yield TestInstance([[block2, RejectResult(16, b'bad-txns-duplicate')]])
# Check transactions for duplicate inputs
self.log.info("Test duplicate input block.")
block2_dup = copy.deepcopy(block2_orig)
block2_dup.vtx[2].vin.append(block2_dup.vtx[2].vin[0])
block2_dup.vtx[2].rehash()
block2_dup.hashMerkleRoot = block2_dup.calc_merkle_root()
block2_dup.rehash()
block2_dup.solve()
yield TestInstance([[block2_dup, RejectResult(16, b'bad-txns-inputs-duplicate')], [block2_orig, True]])
height += 1 height += 1
''' '''

Loading…
Cancel
Save