@@ -29,17 +29,18 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
2929 int64_t PastBlocksMin = 24 ;
3030 int64_t PastBlocksMax = 24 ;
3131 int64_t CountBlocks = 0 ;
32- uint256 PastDifficultyAverage;
33- uint256 PastDifficultyAveragePrev;
32+ arith_uint256 PastDifficultyAverage;
33+ arith_uint256 PastDifficultyAveragePrev;
3434 const Consensus::Params& consensus = Params ().GetConsensus ();
35+ const arith_uint256& powLimit = UintToArith256 (consensus.powLimit );
3536
3637 if (BlockLastSolved == NULL || BlockLastSolved->nHeight == 0 || BlockLastSolved->nHeight < PastBlocksMin) {
37- return consensus. powLimit .GetCompact ();
38+ return powLimit.GetCompact ();
3839 }
3940
4041 if (consensus.NetworkUpgradeActive (pindexLast->nHeight + 1 , Consensus::UPGRADE_POS)) {
4142 const bool fTimeV2 = !Params ().IsRegTestNet () && consensus.IsTimeProtocolV2 (pindexLast->nHeight +1 );
42- const uint256 & bnTargetLimit = consensus.ProofOfStakeLimit (fTimeV2 );
43+ const arith_uint256 & bnTargetLimit = UintToArith256 ( consensus.ProofOfStakeLimit (fTimeV2 ) );
4344 const int64_t & nTargetTimespan = consensus.TargetTimespan (fTimeV2 );
4445
4546 int64_t nActualSpacing = 0 ;
@@ -52,7 +53,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
5253
5354 // ppcoin: target change every block
5455 // ppcoin: retarget with exponential moving toward target spacing
55- uint256 bnNew;
56+ arith_uint256 bnNew;
5657 bnNew.SetCompact (pindexLast->nBits );
5758
5859 // on first block with V2 time protocol, reduce the difficulty by a factor 16
@@ -79,7 +80,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
7980 if (CountBlocks == 1 ) {
8081 PastDifficultyAverage.SetCompact (BlockReading->nBits );
8182 } else {
82- PastDifficultyAverage = ((PastDifficultyAveragePrev * CountBlocks) + (uint256 ().SetCompact (BlockReading->nBits ))) / (CountBlocks + 1 );
83+ PastDifficultyAverage = ((PastDifficultyAveragePrev * CountBlocks) + (arith_uint256 ().SetCompact (BlockReading->nBits ))) / (CountBlocks + 1 );
8384 }
8485 PastDifficultyAveragePrev = PastDifficultyAverage;
8586 }
@@ -97,7 +98,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
9798 BlockReading = BlockReading->pprev ;
9899 }
99100
100- uint256 bnNew (PastDifficultyAverage);
101+ arith_uint256 bnNew (PastDifficultyAverage);
101102
102103 int64_t _nTargetTimespan = CountBlocks * consensus.nTargetSpacing ;
103104
@@ -110,8 +111,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
110111 bnNew *= nActualTimespan;
111112 bnNew /= _nTargetTimespan;
112113
113- if (bnNew > consensus. powLimit ) {
114- bnNew = consensus. powLimit ;
114+ if (bnNew > powLimit) {
115+ bnNew = powLimit;
115116 }
116117
117118 return bnNew.GetCompact ();
@@ -121,31 +122,31 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits)
121122{
122123 bool fNegative ;
123124 bool fOverflow ;
124- uint256 bnTarget;
125+ arith_uint256 bnTarget;
125126
126127 if (Params ().IsRegTestNet ()) return true ;
127128
128129 bnTarget.SetCompact (nBits, &fNegative , &fOverflow );
129130
130131 // Check range
131- if (fNegative || bnTarget.IsNull () || fOverflow || bnTarget > Params ().GetConsensus ().powLimit )
132+ if (fNegative || bnTarget.IsNull () || fOverflow || bnTarget > UintToArith256 ( Params ().GetConsensus ().powLimit ) )
132133 return error (" CheckProofOfWork() : nBits below minimum work" );
133134
134135 // Check proof of work matches claimed amount
135- if (hash > bnTarget)
136+ if (UintToArith256 ( hash) > bnTarget)
136137 return error (" CheckProofOfWork() : hash doesn't match nBits" );
137138
138139 return true ;
139140}
140141
141- uint256 GetBlockProof (const CBlockIndex& block)
142+ arith_uint256 GetBlockProof (const CBlockIndex& block)
142143{
143- uint256 bnTarget;
144+ arith_uint256 bnTarget;
144145 bool fNegative ;
145146 bool fOverflow ;
146147 bnTarget.SetCompact (block.nBits , &fNegative , &fOverflow );
147148 if (fNegative || fOverflow || bnTarget.IsNull ())
148- return UINT256_ZERO ;
149+ return ARITH_UINT256_ZERO ;
149150 // We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256
150151 // as it's too large for a uint256. However, as 2**256 is at least as large
151152 // as bnTarget+1, it is equal to ((2**256 - bnTarget - 1) / (bnTarget+1)) + 1,
0 commit comments