Safer calcscore implementation

This commit is contained in:
Evan Duffield 2015-07-24 08:50:10 -07:00
parent c137a204fb
commit 9e65749ff6

View File

@ -159,8 +159,14 @@ uint256 CMasternode::CalculateScore(int mod, int64_t nBlockHeight)
if(!GetBlockHash(hash, nBlockHeight)) return 0;
uint256 hash2 = Hash(BEGIN(hash), END(hash));
uint256 hash3 = Hash(BEGIN(hash), END(hash), BEGIN(aux), END(aux));
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
ss << hash;
uint256 hash2 = ss.GetHash();
CHashWriter ss2(SER_GETHASH, PROTOCOL_VERSION);
ss2 << hash;
ss2 << aux;
uint256 hash3 = ss2.GetHash();
uint256 r = (hash3 > hash2 ? hash3 - hash2 : hash2 - hash3);