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?