According to the source code here is where the hash computed by a miner is compared with the target hash:
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
{
bool fNegative;
bool fOverflow;
arith_uint256 bnTarget;
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
// Check range
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
return false;
// Check proof of work matches claimed amount
if (UintToArith256(hash) > bnTarget)
return false;
return true;
}
Can you fill the code above with comments to make me to understand what is the role of every variable used in this function?
About the hashes comparing I have read this, anyway, can you make another example printing hash strings to show to me the output of every line of the code?
uint256 hash
and what does it do? I assumed it is the hash generated by a miner but then why the comparation is>
against thebnTarget
instead of<
? – smartmouse Oct 09 '22 at 09:22hash
is the value calculated by the miner. Note thatif (hash > bnTarget) FAIL
is the same asif (hash <= bnTarget) SUCCEED
. – RedGrittyBrick Oct 09 '22 at 09:50