check for negatives and zero in testTarget.
This commit is contained in:
parent
aa355feb25
commit
f120d4d68a
@ -526,7 +526,7 @@ MinerBlock.prototype.findNonce = function findNonce() {
|
|||||||
// The heart and soul of the miner: match the target.
|
// The heart and soul of the miner: match the target.
|
||||||
while (block.nonce <= 0xffffffff) {
|
while (block.nonce <= 0xffffffff) {
|
||||||
// Hash and test against the next target
|
// Hash and test against the next target
|
||||||
if (rcmp(utils.dsha256(data), target) < 0)
|
if (rcmp(utils.dsha256(data), target) <= 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Increment the nonce to get a different hash
|
// Increment the nonce to get a different hash
|
||||||
|
|||||||
@ -1062,7 +1062,15 @@ utils.testTarget = function testTarget(hash, target) {
|
|||||||
if (typeof target === 'number')
|
if (typeof target === 'number')
|
||||||
target = utils.fromCompact(target);
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user