2020-04-16 13:14:08 -04:00
|
|
|
// Copyright (c) 2019-2020 The Bitcoin Core developers
|
2019-10-08 06:33:53 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2020-01-15 18:53:25 -03:00
|
|
|
#include <chainparams.h>
|
2019-10-08 06:33:53 -03:00
|
|
|
#include <coins.h>
|
|
|
|
#include <consensus/tx_check.h>
|
|
|
|
#include <consensus/tx_verify.h>
|
|
|
|
#include <consensus/validation.h>
|
|
|
|
#include <core_io.h>
|
|
|
|
#include <core_memusage.h>
|
|
|
|
#include <policy/policy.h>
|
|
|
|
#include <policy/settings.h>
|
|
|
|
#include <primitives/transaction.h>
|
|
|
|
#include <streams.h>
|
|
|
|
#include <test/fuzz/fuzz.h>
|
2020-01-15 18:53:25 -03:00
|
|
|
#include <univalue.h>
|
2019-10-08 06:33:53 -03:00
|
|
|
#include <util/rbf.h>
|
|
|
|
#include <validation.h>
|
|
|
|
#include <version.h>
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
2020-01-15 18:53:25 -03:00
|
|
|
void initialize()
|
|
|
|
{
|
|
|
|
SelectParams(CBaseChainParams::REGTEST);
|
|
|
|
}
|
|
|
|
|
2019-10-08 06:33:53 -03:00
|
|
|
void test_one_input(const std::vector<uint8_t>& buffer)
|
|
|
|
{
|
|
|
|
CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION);
|
|
|
|
try {
|
|
|
|
int nVersion;
|
|
|
|
ds >> nVersion;
|
|
|
|
ds.SetVersion(nVersion);
|
2019-10-03 11:18:31 -03:00
|
|
|
} catch (const std::ios_base::failure&) {
|
2019-10-08 06:33:53 -03:00
|
|
|
return;
|
|
|
|
}
|
2019-10-03 11:18:31 -03:00
|
|
|
bool valid_tx = true;
|
2019-10-08 06:33:53 -03:00
|
|
|
const CTransaction tx = [&] {
|
|
|
|
try {
|
|
|
|
return CTransaction(deserialize, ds);
|
2019-10-03 11:18:31 -03:00
|
|
|
} catch (const std::ios_base::failure&) {
|
|
|
|
valid_tx = false;
|
2019-10-08 06:33:53 -03:00
|
|
|
return CTransaction();
|
|
|
|
}
|
|
|
|
}();
|
2019-10-03 11:18:31 -03:00
|
|
|
bool valid_mutable_tx = true;
|
|
|
|
CDataStream ds_mtx(buffer, SER_NETWORK, INIT_PROTO_VERSION);
|
|
|
|
CMutableTransaction mutable_tx;
|
|
|
|
try {
|
|
|
|
int nVersion;
|
|
|
|
ds_mtx >> nVersion;
|
|
|
|
ds_mtx.SetVersion(nVersion);
|
|
|
|
ds_mtx >> mutable_tx;
|
|
|
|
} catch (const std::ios_base::failure&) {
|
|
|
|
valid_mutable_tx = false;
|
|
|
|
}
|
|
|
|
assert(valid_tx == valid_mutable_tx);
|
|
|
|
if (!valid_tx) {
|
2019-10-08 06:33:53 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-24 12:35:42 -03:00
|
|
|
TxValidationState state_with_dupe_check;
|
2019-10-08 15:42:17 -03:00
|
|
|
(void)CheckTransaction(tx, state_with_dupe_check);
|
2019-10-08 06:33:53 -03:00
|
|
|
|
|
|
|
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);
|
2020-01-15 18:53:25 -03:00
|
|
|
|
|
|
|
CCoinsView coins_view;
|
|
|
|
const CCoinsViewCache coins_view_cache(&coins_view);
|
|
|
|
(void)AreInputsStandard(tx, coins_view_cache);
|
|
|
|
(void)IsWitnessStandard(tx, coins_view_cache);
|
|
|
|
|
|
|
|
UniValue u(UniValue::VOBJ);
|
|
|
|
// ValueFromAmount(i) not defined when i == std::numeric_limits<int64_t>::min()
|
|
|
|
bool skip_tx_to_univ = false;
|
|
|
|
for (const CTxOut& txout : tx.vout) {
|
|
|
|
if (txout.nValue == std::numeric_limits<int64_t>::min()) {
|
|
|
|
skip_tx_to_univ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!skip_tx_to_univ) {
|
|
|
|
TxToUniv(tx, /* hashBlock */ {}, u);
|
2020-03-10 08:28:10 -03:00
|
|
|
static const uint256 u256_max(uint256S("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
|
|
|
|
TxToUniv(tx, u256_max, u);
|
2020-01-15 18:53:25 -03:00
|
|
|
}
|
2019-10-08 06:33:53 -03:00
|
|
|
}
|