| 72 | } |
| 73 | |
| 74 | bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params) |
| 75 | { |
| 76 | bool fNegative; |
| 77 | bool fOverflow; |
| 78 | arith_uint256 bnTarget; |
| 79 | |
| 80 | bnTarget.SetCompact(nBits, &fNegative, &fOverflow); |
| 81 | |
| 82 | // Check range |
| 83 | if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) |
| 84 | return false; |
| 85 | |
| 86 | // Check proof of work matches claimed amount |
| 87 | if (UintToArith256(hash) > bnTarget) |
| 88 | return false; |
| 89 | |
| 90 | return true; |
| 91 | } |