Business
Difficulty – Proof of Work: Compare Computed Hash with Target Hash
![Difficulty – Proof of Work: Compare Computed Hash with Target Hash Difficulty – Proof of Work: Compare Computed Hash with Target Hash](http://cdn.sstatic.net/Sites/bitcoin/Img/apple-touch-icon@2.png?v=b4864ba760f1)
According to the source code, here’s where the hash calculated by the miner is compared to 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 please comment the code above to help me understand the role of all the variables used in this function?
I read this about comparing hashes, but anyway, can I make another example that prints the hash string to show the output of every line of code?
Difficulty – Proof of Work: Compare Computed Hash with Target Hash
Source link Difficulty – Proof of Work: Compare Computed Hash with Target Hash