Merge bitcoin/bitcoin#21970: fuzz: Add missing CheckTransaction before CheckTxInputs

fae4ee545a fuzz: Add missing CheckTransaction before CheckTxInputs (MarcoFalke)
faacb7eadb fuzz: Sanity check result of CheckTransaction (MarcoFalke)

Pull request description:

  This bug was introduced by myself in commit eeee8f5be1 (https://github.com/bitcoin/bitcoin/pull/21553)

  Reproducer: https://github.com/bitcoin/bitcoin/files/6492249/clusterfuzz-testcase-minimized-coins_view-6109460079706112.log

  Hopefully fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34301

ACKs for top commit:
  practicalswift:
    cr ACK fae4ee545a: patch looks correct :)

Tree-SHA512: 9ece7a5c4bfa60f5e5ffeba3f0ee52a07944c9bd6102588dd7ff7405695e6b32449945b7c41bd25baf38814df5a2436521e655ceff87223ad03c69ed39053023
This commit is contained in:
MarcoFalke 2021-05-19 21:24:26 +02:00
commit 7d19c85f4a
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
2 changed files with 11 additions and 2 deletions

View file

@ -6,6 +6,7 @@
#include <chainparams.h>
#include <chainparamsbase.h>
#include <coins.h>
#include <consensus/tx_check.h>
#include <consensus/tx_verify.h>
#include <consensus/validation.h>
#include <key.h>
@ -230,6 +231,11 @@ FUZZ_TARGET_INIT(coins_view, initialize_coins_view)
// consensus/tx_verify.cpp:171: bool Consensus::CheckTxInputs(const CTransaction &, TxValidationState &, const CCoinsViewCache &, int, CAmount &): Assertion `!coin.IsSpent()' failed.
return;
}
TxValidationState dummy;
if (!CheckTransaction(transaction, dummy)) {
// It is not allowed to call CheckTxInputs if CheckTransaction failed
return;
}
(void)Consensus::CheckTxInputs(transaction, state, coins_view_cache, fuzzed_data_provider.ConsumeIntegralInRange<int>(0, std::numeric_limits<int>::max()), tx_fee_out);
assert(MoneyRange(tx_fee_out));
},

View file

@ -61,8 +61,11 @@ FUZZ_TARGET_INIT(transaction, initialize_transaction)
return;
}
TxValidationState state_with_dupe_check;
(void)CheckTransaction(tx, state_with_dupe_check);
{
TxValidationState state_with_dupe_check;
const bool res{CheckTransaction(tx, state_with_dupe_check)};
Assert(res == state_with_dupe_check.IsValid());
}
const CFeeRate dust_relay_fee{DUST_RELAY_TX_FEE};
std::string reason;