mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-02 21:37:05 +01:00
fa13e1b0c5build: Add option --enable-danger-fuzz-link-all (MarcoFalke)44444ba759fuzz: Link all targets once (MarcoFalke) Pull request description: Currently the linker is invoked more than 150 times when compiling with `--enable-fuzz`. This is problematic for several reasons: * It wastes disk space north of 20 GB, as all libraries and sanitizers are linked more than 150 times * It wastes CPU time, as the link step can practically not be cached (similar to ccache for object files) * It makes it a blocker to compile the fuzz tests by default for non-fuzz builds #19388, for the aforementioned reasons * The build file is several thousand lines of code, without doing anything meaningful except listing each fuzz target in a highly verbose manner * It makes writing new fuzz tests unnecessarily hard, as build system knowledge is required; Compare that to boost unit tests, which can be added by simply editing an existing cpp file * It encourages fuzz tests that re-use the `buffer` or assume the `buffer` to be concatenations of seeds, which increases complexity of seeds and complexity for the fuzz engine to explore; Thus reducing the effectiveness of the affected fuzz targets Fixes #20088 ACKs for top commit: practicalswift: Tested ACKfa13e1b0c5sipa: ACKfa13e1b0c5. Reviewed the code changes, and tested the 3 different test_runner.py modes (run once, merge, generate). I also tested building with the new --enable-danger-fuzz-link-all Tree-SHA512: 962ab33269ebd51810924c51266ecc62edd6ddf2fcd9a8c359ed906766f58c3f73c223f8d3cc49f2c60f0053f65e8bdd86ce9c19e673f8c2b3cd676e913f2642
116 lines
3.6 KiB
C++
116 lines
3.6 KiB
C++
// Copyright (c) 2019-2020 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 <chainparams.h>
|
|
#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>
|
|
#include <univalue.h>
|
|
#include <util/rbf.h>
|
|
#include <validation.h>
|
|
#include <version.h>
|
|
|
|
#include <cassert>
|
|
|
|
void initialize_transaction()
|
|
{
|
|
SelectParams(CBaseChainParams::REGTEST);
|
|
}
|
|
|
|
FUZZ_TARGET_INIT(transaction, initialize_transaction)
|
|
{
|
|
CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION);
|
|
try {
|
|
int nVersion;
|
|
ds >> nVersion;
|
|
ds.SetVersion(nVersion);
|
|
} catch (const std::ios_base::failure&) {
|
|
return;
|
|
}
|
|
bool valid_tx = true;
|
|
const CTransaction tx = [&] {
|
|
try {
|
|
return CTransaction(deserialize, ds);
|
|
} catch (const std::ios_base::failure&) {
|
|
valid_tx = false;
|
|
return CTransaction{CMutableTransaction{}};
|
|
}
|
|
}();
|
|
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) {
|
|
return;
|
|
}
|
|
|
|
TxValidationState state_with_dupe_check;
|
|
(void)CheckTransaction(tx, state_with_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);
|
|
|
|
CCoinsView coins_view;
|
|
const CCoinsViewCache coins_view_cache(&coins_view);
|
|
(void)AreInputsStandard(tx, coins_view_cache, false);
|
|
(void)AreInputsStandard(tx, coins_view_cache, true);
|
|
(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);
|
|
static const uint256 u256_max(uint256S("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
|
|
TxToUniv(tx, u256_max, u);
|
|
}
|
|
}
|