forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin#17071: tests: Add fuzzing harness for CheckBlock(...) a…
…nd other CBlock related functions 893aa20 tests: Add fuzzing harness for CheckBlock(...) and other CBlock related functions (practicalswift) ec8dcb0 tests: Add corpora suppression (FUZZERS_MISSING_CORPORA) for fuzzers missing in https://github.com/bitcoin-core/qa-assets/tree/master/fuzz_seed_corpus (practicalswift) Pull request description: Add fuzzing harness for `CheckBlock(...)` and other `CBlock` related functions. **Testing this PR** Run: ``` $ CC=clang CXX=clang++ ./configure --enable-fuzz --with-sanitizers=address,fuzzer,undefined $ make $ src/test/fuzz/block … # And to to quickly verify that the relevant code regions are triggered, that the # fuzzing throughput seems reasonable, etc. $ contrib/devtools/test_fuzzing_harnesses.sh '^block$' ``` `test_fuzzing_harnesses.sh` can be found in PR bitcoin#17000. Top commit has no ACKs. Tree-SHA512: 275abd46d8ac970b28d8176f59124988b1e07c070173e001acd55995b830333417f301c309199fc589da08a6ac4c03aa74650d5e1638f6e3023dfbd3c9f6921d
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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 <chainparams.h> | ||
#include <consensus/merkle.h> | ||
#include <consensus/validation.h> | ||
#include <core_io.h> | ||
#include <core_memusage.h> | ||
#include <pubkey.h> | ||
#include <primitives/block.h> | ||
#include <streams.h> | ||
#include <test/fuzz/fuzz.h> | ||
#include <validation.h> | ||
#include <version.h> | ||
|
||
#include <cassert> | ||
#include <string> | ||
|
||
void initialize() | ||
{ | ||
const static auto verify_handle = MakeUnique<ECCVerifyHandle>(); | ||
SelectParams(CBaseChainParams::REGTEST); | ||
} | ||
|
||
void test_one_input(const std::vector<uint8_t>& buffer) | ||
{ | ||
CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION); | ||
CBlock block; | ||
try { | ||
int nVersion; | ||
ds >> nVersion; | ||
ds.SetVersion(nVersion); | ||
ds >> block; | ||
} catch (const std::ios_base::failure&) { | ||
return; | ||
} | ||
const Consensus::Params& consensus_params = Params().GetConsensus(); | ||
BlockValidationState validation_state_pow_and_merkle; | ||
const bool valid_incl_pow_and_merkle = CheckBlock(block, validation_state_pow_and_merkle, consensus_params, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ true); | ||
BlockValidationState validation_state_pow; | ||
const bool valid_incl_pow = CheckBlock(block, validation_state_pow, consensus_params, /* fCheckPOW= */ true, /* fCheckMerkleRoot= */ false); | ||
BlockValidationState validation_state_merkle; | ||
const bool valid_incl_merkle = CheckBlock(block, validation_state_merkle, consensus_params, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ true); | ||
BlockValidationState validation_state_none; | ||
const bool valid_incl_none = CheckBlock(block, validation_state_none, consensus_params, /* fCheckPOW= */ false, /* fCheckMerkleRoot= */ false); | ||
if (valid_incl_pow_and_merkle) { | ||
assert(valid_incl_pow && valid_incl_merkle && valid_incl_none); | ||
} else if (valid_incl_merkle || valid_incl_pow) { | ||
assert(valid_incl_none); | ||
} | ||
(void)block.GetHash(); | ||
(void)block.ToString(); | ||
(void)BlockMerkleRoot(block); | ||
if (!block.vtx.empty()) { | ||
// TODO: Avoid array index out of bounds error in BlockWitnessMerkleRoot | ||
// when block.vtx.empty(). | ||
(void)BlockWitnessMerkleRoot(block); | ||
} | ||
(void)GetBlockWeight(block); | ||
(void)GetWitnessCommitmentIndex(block); | ||
(void)RecursiveDynamicUsage(block); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters