Inside Bitcoin
Opening the selected file…
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) 2009-2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6#ifndef BITCOIN_POW_H7#define BITCOIN_POW_H9#include <consensus/params.h>11#include <cstdint>13class CBlockHeader;14class CBlockIndex;15class uint256;16class arith_uint256;18/**19* Convert nBits value to target.20*21* @param[in] nBits compact representation of the target22* @param[in] pow_limit PoW limit (consensus parameter)23*24* @return the proof-of-work target or nullopt if the nBits value25* is invalid (due to overflow or exceeding pow_limit)26*/27std::optional<arith_uint256> DeriveTarget(unsigned int nBits, uint256 pow_limit);29unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params&);30unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params&);32/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */33bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&);34bool CheckProofOfWorkImpl(uint256 hash, unsigned int nBits, const Consensus::Params&);36/**37* Return false if the proof-of-work requirement specified by new_nbits at a38* given height is not possible, given the proof-of-work on the prior block as39* specified by old_nbits.40*41* This function only checks that the new value is within a factor of 4 of the42* old value for blocks at the difficulty adjustment interval, and otherwise43* requires the values to be the same.44*45* Always returns true on networks where min difficulty blocks are allowed,46* such as regtest/testnet.47*/48bool PermittedDifficultyTransition(const Consensus::Params& params, int64_t height, uint32_t old_nbits, uint32_t new_nbits);50#endif // BITCOIN_POW_H
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.