diff options
Diffstat (limited to 'src/test/fuzz')
-rw-r--r-- | src/test/fuzz/crypto.cpp | 18 | ||||
-rw-r--r-- | src/test/fuzz/net.cpp | 25 | ||||
-rw-r--r-- | src/test/fuzz/process_message.cpp | 2 | ||||
-rw-r--r-- | src/test/fuzz/process_messages.cpp | 2 | ||||
-rw-r--r-- | src/test/fuzz/signet.cpp | 34 |
5 files changed, 63 insertions, 18 deletions
diff --git a/src/test/fuzz/crypto.cpp b/src/test/fuzz/crypto.cpp index 3edcf96495..664e65accc 100644 --- a/src/test/fuzz/crypto.cpp +++ b/src/test/fuzz/crypto.cpp @@ -7,6 +7,7 @@ #include <crypto/ripemd160.h> #include <crypto/sha1.h> #include <crypto/sha256.h> +#include <crypto/sha3.h> #include <crypto/sha512.h> #include <hash.h> #include <test/fuzz/FuzzedDataProvider.h> @@ -32,6 +33,7 @@ void test_one_input(const std::vector<uint8_t>& buffer) CSHA1 sha1; CSHA256 sha256; CSHA512 sha512; + SHA3_256 sha3; CSipHasher sip_hasher{fuzzed_data_provider.ConsumeIntegral<uint64_t>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>()}; while (fuzzed_data_provider.ConsumeBool()) { @@ -51,6 +53,7 @@ void test_one_input(const std::vector<uint8_t>& buffer) (void)ripemd160.Write(data.data(), data.size()); (void)sha1.Write(data.data(), data.size()); (void)sha256.Write(data.data(), data.size()); + (void)sha3.Write(data); (void)sha512.Write(data.data(), data.size()); (void)sip_hasher.Write(data.data(), data.size()); @@ -65,11 +68,12 @@ void test_one_input(const std::vector<uint8_t>& buffer) (void)ripemd160.Reset(); (void)sha1.Reset(); (void)sha256.Reset(); + (void)sha3.Reset(); (void)sha512.Reset(); break; } case 2: { - switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 8)) { + switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 9)) { case 0: { data.resize(CHash160::OUTPUT_SIZE); hash160.Finalize(data); @@ -115,9 +119,21 @@ void test_one_input(const std::vector<uint8_t>& buffer) data[0] = sip_hasher.Finalize() % 256; break; } + case 9: { + data.resize(SHA3_256::OUTPUT_SIZE); + sha3.Finalize(data); + break; + } } break; } } } + if (fuzzed_data_provider.ConsumeBool()) { + uint64_t state[25]; + for (size_t i = 0; i < 25; ++i) { + state[i] = fuzzed_data_provider.ConsumeIntegral<uint64_t>(); + } + KeccakF(state); + } } diff --git a/src/test/fuzz/net.cpp b/src/test/fuzz/net.cpp index cd0c93b8d0..a85c353243 100644 --- a/src/test/fuzz/net.cpp +++ b/src/test/fuzz/net.cpp @@ -48,7 +48,7 @@ void test_one_input(const std::vector<uint8_t>& buffer) fuzzed_data_provider.ConsumeRandomLengthString(32), fuzzed_data_provider.PickValueInArray({ConnectionType::INBOUND, ConnectionType::OUTBOUND_FULL_RELAY, ConnectionType::MANUAL, ConnectionType::FEELER, ConnectionType::BLOCK_RELAY, ConnectionType::ADDR_FETCH})}; while (fuzzed_data_provider.ConsumeBool()) { - switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 12)) { + switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 11)) { case 0: { node.CloseSocketDisconnect(); break; @@ -58,7 +58,7 @@ void test_one_input(const std::vector<uint8_t>& buffer) break; } case 2: { - node.SetSendVersion(fuzzed_data_provider.ConsumeIntegral<int>()); + node.SetCommonVersion(fuzzed_data_provider.ConsumeIntegral<int>()); break; } case 3: { @@ -71,21 +71,17 @@ void test_one_input(const std::vector<uint8_t>& buffer) break; } case 4: { - node.SetRecvVersion(fuzzed_data_provider.ConsumeIntegral<int>()); - break; - } - case 5: { const CNode* add_ref_node = node.AddRef(); assert(add_ref_node == &node); break; } - case 6: { + case 5: { if (node.GetRefCount() > 0) { node.Release(); } break; } - case 7: { + case 6: { if (node.m_addr_known == nullptr) { break; } @@ -96,7 +92,7 @@ void test_one_input(const std::vector<uint8_t>& buffer) node.AddAddressKnown(*addr_opt); break; } - case 8: { + case 7: { if (node.m_addr_known == nullptr) { break; } @@ -108,7 +104,7 @@ void test_one_input(const std::vector<uint8_t>& buffer) node.PushAddress(*addr_opt, fast_random_context); break; } - case 9: { + case 8: { const std::optional<CInv> inv_opt = ConsumeDeserializable<CInv>(fuzzed_data_provider); if (!inv_opt) { break; @@ -116,11 +112,11 @@ void test_one_input(const std::vector<uint8_t>& buffer) node.AddKnownTx(inv_opt->hash); break; } - case 10: { + case 9: { node.PushTxInventory(ConsumeUInt256(fuzzed_data_provider)); break; } - case 11: { + case 10: { const std::optional<CService> service_opt = ConsumeDeserializable<CService>(fuzzed_data_provider); if (!service_opt) { break; @@ -128,7 +124,7 @@ void test_one_input(const std::vector<uint8_t>& buffer) node.SetAddrLocal(*service_opt); break; } - case 12: { + case 11: { const std::vector<uint8_t> b = ConsumeRandomLengthByteVector(fuzzed_data_provider); bool complete; node.ReceiveMsgBytes((const char*)b.data(), b.size(), complete); @@ -143,10 +139,9 @@ void test_one_input(const std::vector<uint8_t>& buffer) (void)node.GetLocalNonce(); (void)node.GetLocalServices(); (void)node.GetMyStartingHeight(); - (void)node.GetRecvVersion(); const int ref_count = node.GetRefCount(); assert(ref_count >= 0); - (void)node.GetSendVersion(); + (void)node.GetCommonVersion(); (void)node.RelayAddrsWithConn(); const NetPermissionFlags net_permission_flags = fuzzed_data_provider.ConsumeBool() ? diff --git a/src/test/fuzz/process_message.cpp b/src/test/fuzz/process_message.cpp index 3d6947ca92..3ef03137ec 100644 --- a/src/test/fuzz/process_message.cpp +++ b/src/test/fuzz/process_message.cpp @@ -71,7 +71,7 @@ void test_one_input(const std::vector<uint8_t>& buffer) CNode& p2p_node = *MakeUnique<CNode>(0, ServiceFlags(NODE_NETWORK | NODE_WITNESS | NODE_BLOOM), 0, INVALID_SOCKET, CAddress{CService{in_addr{0x0100007f}, 7777}, NODE_NETWORK}, 0, 0, CAddress{}, std::string{}, ConnectionType::OUTBOUND_FULL_RELAY).release(); p2p_node.fSuccessfullyConnected = true; p2p_node.nVersion = PROTOCOL_VERSION; - p2p_node.SetSendVersion(PROTOCOL_VERSION); + p2p_node.SetCommonVersion(PROTOCOL_VERSION); connman.AddTestNode(p2p_node); g_setup->m_node.peerman->InitializeNode(&p2p_node); try { diff --git a/src/test/fuzz/process_messages.cpp b/src/test/fuzz/process_messages.cpp index c9433d325a..f722eeac3a 100644 --- a/src/test/fuzz/process_messages.cpp +++ b/src/test/fuzz/process_messages.cpp @@ -51,7 +51,7 @@ void test_one_input(const std::vector<uint8_t>& buffer) p2p_node.fSuccessfullyConnected = true; p2p_node.fPauseSend = false; p2p_node.nVersion = PROTOCOL_VERSION; - p2p_node.SetSendVersion(PROTOCOL_VERSION); + p2p_node.SetCommonVersion(PROTOCOL_VERSION); g_setup->m_node.peerman->InitializeNode(&p2p_node); connman.AddTestNode(p2p_node); diff --git a/src/test/fuzz/signet.cpp b/src/test/fuzz/signet.cpp new file mode 100644 index 0000000000..4736ae27f5 --- /dev/null +++ b/src/test/fuzz/signet.cpp @@ -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)); + } +} |