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 <memusage.h>6#include <test/fuzz/FuzzedDataProvider.h>7#include <test/fuzz/fuzz.h>8#include <test/fuzz/util.h>9#include <util/serfloat.h>11#include <cassert>12#include <cmath>13#include <limits>14#include <optional>16FUZZ_TARGET(float)17{18FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());20{21const double d{[&] {22std::optional<double> tmp;23CallOneOf(24fuzzed_data_provider,25// an actual number26[&] { tmp = fuzzed_data_provider.ConsumeFloatingPoint<double>(); },27// special numbers and NANs28[&] { tmp = fuzzed_data_provider.PickValueInArray({29std::numeric_limits<double>::infinity(),30-std::numeric_limits<double>::infinity(),31std::numeric_limits<double>::min(),32-std::numeric_limits<double>::min(),33std::numeric_limits<double>::max(),34-std::numeric_limits<double>::max(),35std::numeric_limits<double>::lowest(),36-std::numeric_limits<double>::lowest(),37std::numeric_limits<double>::quiet_NaN(),38-std::numeric_limits<double>::quiet_NaN(),39std::numeric_limits<double>::signaling_NaN(),40-std::numeric_limits<double>::signaling_NaN(),41std::numeric_limits<double>::denorm_min(),42-std::numeric_limits<double>::denorm_min(),43}); },44// Anything from raw memory (also checks that DecodeDouble doesn't crash on any input)45[&] { tmp = DecodeDouble(fuzzed_data_provider.ConsumeIntegral<uint64_t>()); });46return *tmp;47}()};48(void)memusage::DynamicUsage(d);50uint64_t encoded = EncodeDouble(d);51if constexpr (std::numeric_limits<double>::is_iec559) {52if (!std::isnan(d)) {53uint64_t encoded_in_memory;54std::copy((const unsigned char*)&d, (const unsigned char*)(&d + 1), (unsigned char*)&encoded_in_memory);55assert(encoded_in_memory == encoded);56}57}58double d_deserialized = DecodeDouble(encoded);59assert(std::isnan(d) == std::isnan(d_deserialized));60assert(std::isnan(d) || d == d_deserialized);61}62}
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.