|
| 1 | +// Copyright (c) 2019 The Bitcoin Core developers |
| 2 | +// Distributed under the MIT software license, see the accompanying |
| 3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | + |
| 5 | +#include <coins.h> |
| 6 | +#include <consensus/tx_check.h> |
| 7 | +#include <consensus/tx_verify.h> |
| 8 | +#include <consensus/validation.h> |
| 9 | +#include <core_io.h> |
| 10 | +#include <core_memusage.h> |
| 11 | +#include <policy/policy.h> |
| 12 | +#include <policy/settings.h> |
| 13 | +#include <primitives/transaction.h> |
| 14 | +#include <streams.h> |
| 15 | +#include <test/fuzz/fuzz.h> |
| 16 | +#include <util/rbf.h> |
| 17 | +#include <validation.h> |
| 18 | +#include <version.h> |
| 19 | + |
| 20 | +#include <cassert> |
| 21 | + |
| 22 | +void test_one_input(const std::vector<uint8_t>& buffer) |
| 23 | +{ |
| 24 | + CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION); |
| 25 | + try { |
| 26 | + int nVersion; |
| 27 | + ds >> nVersion; |
| 28 | + ds.SetVersion(nVersion); |
| 29 | + } catch (const std::ios_base::failure& e) { |
| 30 | + return; |
| 31 | + } |
| 32 | + bool valid = true; |
| 33 | + const CTransaction tx = [&] { |
| 34 | + try { |
| 35 | + return CTransaction(deserialize, ds); |
| 36 | + } catch (const std::ios_base::failure& e) { |
| 37 | + valid = false; |
| 38 | + return CTransaction(); |
| 39 | + } |
| 40 | + }(); |
| 41 | + if (!valid) { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + CValidationState state_with_dupe_check; |
| 46 | + const bool valid_with_dupe_check = CheckTransaction(tx, state_with_dupe_check, /* fCheckDuplicateInputs= */ true); |
| 47 | + CValidationState state_without_dupe_check; |
| 48 | + const bool valid_without_dupe_check = CheckTransaction(tx, state_without_dupe_check, /* fCheckDuplicateInputs= */ false); |
| 49 | + if (valid_with_dupe_check) { |
| 50 | + assert(valid_without_dupe_check); |
| 51 | + } |
| 52 | + |
| 53 | + const CFeeRate dust_relay_fee{DUST_RELAY_TX_FEE}; |
| 54 | + std::string reason; |
| 55 | + const bool is_standard_with_permit_bare_multisig = IsStandardTx(tx, /* permit_bare_multisig= */ true, dust_relay_fee, reason); |
| 56 | + const bool is_standard_without_permit_bare_multisig = IsStandardTx(tx, /* permit_bare_multisig= */ false, dust_relay_fee, reason); |
| 57 | + if (is_standard_without_permit_bare_multisig) { |
| 58 | + assert(is_standard_with_permit_bare_multisig); |
| 59 | + } |
| 60 | + |
| 61 | + (void)tx.GetHash(); |
| 62 | + (void)tx.GetTotalSize(); |
| 63 | + try { |
| 64 | + (void)tx.GetValueOut(); |
| 65 | + } catch (const std::runtime_error&) { |
| 66 | + } |
| 67 | + (void)tx.GetWitnessHash(); |
| 68 | + (void)tx.HasWitness(); |
| 69 | + (void)tx.IsCoinBase(); |
| 70 | + (void)tx.IsNull(); |
| 71 | + (void)tx.ToString(); |
| 72 | + |
| 73 | + (void)EncodeHexTx(tx); |
| 74 | + (void)GetLegacySigOpCount(tx); |
| 75 | + (void)GetTransactionWeight(tx); |
| 76 | + (void)GetVirtualTransactionSize(tx); |
| 77 | + (void)IsFinalTx(tx, /* nBlockHeight= */ 1024, /* nBlockTime= */ 1024); |
| 78 | + (void)IsStandardTx(tx, reason); |
| 79 | + (void)RecursiveDynamicUsage(tx); |
| 80 | + (void)SignalsOptInRBF(tx); |
| 81 | +} |
0 commit comments