From 0a573682f24d20cb178b8b6f97c35ec46901c4db Mon Sep 17 00:00:00 2001 From: practicalswift Date: Tue, 8 Oct 2019 09:33:53 +0000 Subject: tests: Add fuzzing harness for CheckTransaction(...), IsStandardTx(...) and other CTransaction related functions --- src/test/fuzz/transaction.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/test/fuzz/transaction.cpp (limited to 'src/test/fuzz') diff --git a/src/test/fuzz/transaction.cpp b/src/test/fuzz/transaction.cpp new file mode 100644 index 0000000000..96d7947b07 --- /dev/null +++ b/src/test/fuzz/transaction.cpp @@ -0,0 +1,81 @@ +// Copyright (c) 2019 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +void test_one_input(const std::vector& buffer) +{ + CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION); + try { + int nVersion; + ds >> nVersion; + ds.SetVersion(nVersion); + } catch (const std::ios_base::failure& e) { + return; + } + bool valid = true; + const CTransaction tx = [&] { + try { + return CTransaction(deserialize, ds); + } catch (const std::ios_base::failure& e) { + valid = false; + return CTransaction(); + } + }(); + if (!valid) { + return; + } + + CValidationState state_with_dupe_check; + const bool valid_with_dupe_check = CheckTransaction(tx, state_with_dupe_check, /* fCheckDuplicateInputs= */ true); + CValidationState state_without_dupe_check; + const bool valid_without_dupe_check = CheckTransaction(tx, state_without_dupe_check, /* fCheckDuplicateInputs= */ false); + if (valid_with_dupe_check) { + assert(valid_without_dupe_check); + } + + const CFeeRate dust_relay_fee{DUST_RELAY_TX_FEE}; + std::string reason; + const bool is_standard_with_permit_bare_multisig = IsStandardTx(tx, /* permit_bare_multisig= */ true, dust_relay_fee, reason); + const bool is_standard_without_permit_bare_multisig = IsStandardTx(tx, /* permit_bare_multisig= */ false, dust_relay_fee, reason); + if (is_standard_without_permit_bare_multisig) { + assert(is_standard_with_permit_bare_multisig); + } + + (void)tx.GetHash(); + (void)tx.GetTotalSize(); + try { + (void)tx.GetValueOut(); + } catch (const std::runtime_error&) { + } + (void)tx.GetWitnessHash(); + (void)tx.HasWitness(); + (void)tx.IsCoinBase(); + (void)tx.IsNull(); + (void)tx.ToString(); + + (void)EncodeHexTx(tx); + (void)GetLegacySigOpCount(tx); + (void)GetTransactionWeight(tx); + (void)GetVirtualTransactionSize(tx); + (void)IsFinalTx(tx, /* nBlockHeight= */ 1024, /* nBlockTime= */ 1024); + (void)IsStandardTx(tx, reason); + (void)RecursiveDynamicUsage(tx); + (void)SignalsOptInRBF(tx); +} -- cgit v1.2.3