Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2020-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <common/bloom.h>6#include <primitives/transaction.h>7#include <test/fuzz/FuzzedDataProvider.h>8#include <test/fuzz/fuzz.h>9#include <test/fuzz/util.h>10#include <uint256.h>12#include <cassert>13#include <limits>14#include <optional>15#include <vector>17FUZZ_TARGET(bloom_filter)18{19FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());20bool good_data{true};22CBloomFilter bloom_filter{23fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(1, 10000000),241.0 / fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(1, std::numeric_limits<unsigned int>::max()),25fuzzed_data_provider.ConsumeIntegral<unsigned int>(),26static_cast<unsigned char>(fuzzed_data_provider.PickValueInArray({BLOOM_UPDATE_NONE, BLOOM_UPDATE_ALL, BLOOM_UPDATE_P2PUBKEY_ONLY, BLOOM_UPDATE_MASK}))};27LIMITED_WHILE (good_data && fuzzed_data_provider.remaining_bytes() > 0, 10'000) {28CallOneOf(29fuzzed_data_provider,30[&] {31const std::vector<unsigned char> b = ConsumeRandomLengthByteVector(fuzzed_data_provider);32(void)bloom_filter.contains(b);33bloom_filter.insert(b);34const bool present = bloom_filter.contains(b);35assert(present);36},37[&] {38const std::optional<COutPoint> out_point = ConsumeDeserializable<COutPoint>(fuzzed_data_provider);39if (!out_point) {40good_data = false;41return;42}43(void)bloom_filter.contains(*out_point);44bloom_filter.insert(*out_point);45const bool present = bloom_filter.contains(*out_point);46assert(present);47},48[&] {49const std::optional<uint256> u256 = ConsumeDeserializable<uint256>(fuzzed_data_provider);50if (!u256) {51good_data = false;52return;53}54(void)bloom_filter.contains(*u256);55bloom_filter.insert(*u256);56const bool present = bloom_filter.contains(*u256);57assert(present);58},59[&] {60const std::optional<CMutableTransaction> mut_tx = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);61if (!mut_tx) {62good_data = false;63return;64}65const CTransaction tx{*mut_tx};66(void)bloom_filter.IsRelevantAndUpdate(tx);67});68(void)bloom_filter.IsWithinSizeConstraints();69}70}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.