test: add small signet fuzzer

This commit is contained in:
practicalswift 2020-08-17 18:41:37 +09:00 committed by Karl-Johan Alm
parent ec9b25d046
commit 4c189abdc4
No known key found for this signature in database
GPG Key ID: 57AF762DB3353322
2 changed files with 41 additions and 0 deletions

View File

@ -134,6 +134,7 @@ FUZZ_TARGETS = \
test/fuzz/scriptnum_ops \
test/fuzz/service_deserialize \
test/fuzz/signature_checker \
test/fuzz/signet \
test/fuzz/snapshotmetadata_deserialize \
test/fuzz/span \
test/fuzz/spanparsing \
@ -1106,6 +1107,12 @@ test_fuzz_signature_checker_LDADD = $(FUZZ_SUITE_LD_COMMON)
test_fuzz_signature_checker_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
test_fuzz_signature_checker_SOURCES = test/fuzz/signature_checker.cpp
test_fuzz_signet_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
test_fuzz_signet_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
test_fuzz_signet_LDADD = $(FUZZ_SUITE_LD_COMMON)
test_fuzz_signet_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
test_fuzz_signet_SOURCES = test/fuzz/signet.cpp
test_fuzz_snapshotmetadata_deserialize_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) -DSNAPSHOTMETADATA_DESERIALIZE=1
test_fuzz_snapshotmetadata_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
test_fuzz_snapshotmetadata_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)

34
src/test/fuzz/signet.cpp Normal file
View File

@ -0,0 +1,34 @@
// 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 <chainparams.h>
#include <consensus/validation.h>
#include <primitives/block.h>
#include <signet.h>
#include <streams.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/util.h>
#include <cstdint>
#include <optional>
#include <vector>
void initialize()
{
InitializeFuzzingContext(CBaseChainParams::SIGNET);
}
void test_one_input(const std::vector<uint8_t>& buffer)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
const std::optional<CBlock> block = ConsumeDeserializable<CBlock>(fuzzed_data_provider);
if (!block) {
return;
}
(void)CheckSignetBlockSolution(*block, Params().GetConsensus());
if (GetWitnessCommitmentIndex(*block) != NO_WITNESS_COMMITMENT) {
(void)SignetTxs(*block, ConsumeScript(fuzzed_data_provider));
}
}