check for negatives and zero in testTarget.

This commit is contained in:
Christopher Jeffrey 2016-06-10 18:26:18 -07:00
parent aa355feb25
commit f120d4d68a
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 10 additions and 2 deletions

View File

@ -526,7 +526,7 @@ MinerBlock.prototype.findNonce = function findNonce() {
// The heart and soul of the miner: match the target.
while (block.nonce <= 0xffffffff) {
// Hash and test against the next target
if (rcmp(utils.dsha256(data), target) < 0)
if (rcmp(utils.dsha256(data), target) <= 0)
return true;
// Increment the nonce to get a different hash

View File

@ -1062,7 +1062,15 @@ utils.testTarget = function testTarget(hash, target) {
if (typeof target === 'number')
target = utils.fromCompact(target);
return new bn(hash, 'le').cmp(target) < 0;
if (target.isNeg() || target.cmpn(0) === 0)
return false;
hash = new bn(hash, 'le');
if (hash.cmp(target) > 0)
return false;
return true;
};
/**