diff --git a/src/test/fuzz/block.cpp b/src/test/fuzz/block.cpp index d232df1e4..648b1f8e3 100644 --- a/src/test/fuzz/block.cpp +++ b/src/test/fuzz/block.cpp @@ -1,71 +1,83 @@ // 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 void initialize() { static const ECCVerifyHandle verify_handle; SelectParams(CBaseChainParams::REGTEST); } void test_one_input(const std::vector &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 Config &config = GetConfig(); const Consensus::Params &consensus_params = config.GetChainParams().GetConsensus(); BlockValidationOptions options(config); BlockValidationState validation_state_pow_and_merkle; const bool valid_incl_pow_and_merkle = CheckBlock( block, validation_state_pow_and_merkle, consensus_params, options); + assert(validation_state_pow_and_merkle.IsValid() || + validation_state_pow_and_merkle.IsInvalid() || + validation_state_pow_and_merkle.IsError()); + (void)validation_state_pow_and_merkle.Error(""); BlockValidationState validation_state_pow; const bool valid_incl_pow = CheckBlock(block, validation_state_pow, consensus_params, options.withCheckMerkleRoot(false)); + assert(validation_state_pow.IsValid() || validation_state_pow.IsInvalid() || + validation_state_pow.IsError()); BlockValidationState validation_state_merkle; const bool valid_incl_merkle = CheckBlock(block, validation_state_merkle, consensus_params, options.withCheckPoW(false)); + assert(validation_state_merkle.IsValid() || + validation_state_merkle.IsInvalid() || + validation_state_merkle.IsError()); BlockValidationState validation_state_none; const bool valid_incl_none = CheckBlock(block, validation_state_none, consensus_params, options.withCheckPoW(false).withCheckMerkleRoot(false)); + assert(validation_state_none.IsValid() || + validation_state_none.IsInvalid() || + validation_state_none.IsError()); 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); CBlock block_copy = block; block_copy.SetNull(); const bool is_null = block_copy.IsNull(); assert(is_null); } diff --git a/src/test/fuzz/block_header.cpp b/src/test/fuzz/block_header.cpp index e150e0237..91caf0360 100644 --- a/src/test/fuzz/block_header.cpp +++ b/src/test/fuzz/block_header.cpp @@ -1,43 +1,52 @@ // Copyright (c) 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 #include #include #include #include #include #include #include #include #include void test_one_input(const std::vector &buffer) { FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); const std::optional block_header = ConsumeDeserializable(fuzzed_data_provider); if (!block_header) { return; } { const BlockHash hash = block_header->GetHash(); static const BlockHash blockhash_max( uint256S("fffffffffffffffffffffffffffffffffffffffffffffffffffffffff" "fffffff")); assert(hash != blockhash_max); assert(block_header->GetBlockTime() == block_header->nTime); assert(block_header->IsNull() == (block_header->nBits == 0)); } { CBlockHeader mut_block_header = *block_header; mut_block_header.SetNull(); assert(mut_block_header.IsNull()); CBlock block{*block_header}; assert(block.GetBlockHeader().GetHash() == block_header->GetHash()); (void)block.ToString(); block.SetNull(); assert(block.GetBlockHeader().GetHash() == mut_block_header.GetHash()); } + { + std::optional block_locator = + ConsumeDeserializable(fuzzed_data_provider); + if (block_locator) { + (void)block_locator->IsNull(); + block_locator->SetNull(); + assert(block_locator->IsNull()); + } + } } diff --git a/src/test/fuzz/script.cpp b/src/test/fuzz/script.cpp index 184eedaca..e8d146e5a 100644 --- a/src/test/fuzz/script.cpp +++ b/src/test/fuzz/script.cpp @@ -1,113 +1,117 @@ // 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