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 <cuckoocache.h>6#include <script/sigcache.h>7#include <test/fuzz/FuzzedDataProvider.h>8#include <test/fuzz/fuzz.h>9#include <test/fuzz/util.h>10#include <test/util/setup_common.h>11#include <util/byte_units.h>13#include <cstdint>14#include <string>15#include <vector>17namespace {18FuzzedDataProvider* fuzzed_data_provider_ptr = nullptr;20struct RandomHasher {21template <uint8_t>22uint32_t operator()(const bool& /* unused */) const23{24assert(fuzzed_data_provider_ptr != nullptr);25return fuzzed_data_provider_ptr->ConsumeIntegral<uint32_t>();26}27};28} // namespace30FUZZ_TARGET(cuckoocache)31{32FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());33fuzzed_data_provider_ptr = &fuzzed_data_provider;34CuckooCache::cache<int, RandomHasher> cuckoo_cache{};35if (fuzzed_data_provider.ConsumeBool()) {36const size_t megabytes = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 16);37cuckoo_cache.setup_bytes(megabytes * 1_MiB);38} else {39cuckoo_cache.setup(fuzzed_data_provider.ConsumeIntegralInRange<uint32_t>(0, 4096));40}41LIMITED_WHILE (fuzzed_data_provider.ConsumeBool(), 10000) {42if (fuzzed_data_provider.ConsumeBool()) {43cuckoo_cache.insert(fuzzed_data_provider.ConsumeBool());44} else {45auto e = fuzzed_data_provider.ConsumeBool();46auto erase = fuzzed_data_provider.ConsumeBool();47cuckoo_cache.contains(e, erase);48}49}50fuzzed_data_provider_ptr = nullptr;51}
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.