Litecoin: avoid overflow in GetNextWorkRequired()

This commit is contained in:
pooler 2015-01-23 13:25:02 +01:00 committed by Warren Togami
parent 60b0651d85
commit 27300530be

View File

@ -66,8 +66,14 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
uint256 bnOld;
bnNew.SetCompact(pindexLast->nBits);
bnOld = bnNew;
// Litecoin: intermediate uint256 can overflow by 1 bit
bool fShift = bnNew.bits() > 235;
if (fShift)
bnNew >>= 1;
bnNew *= nActualTimespan;
bnNew /= Params().TargetTimespan();
if (fShift)
bnNew <<= 1;
if (bnNew > Params().ProofOfWorkLimit())
bnNew = Params().ProofOfWorkLimit();