From c3754d13958e1233980827e2cdc5912dd0585142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E9=B9=8F=E9=A3=9E=28Philip=20Qin=29?= Date: Tue, 3 Sep 2019 23:56:08 +0800 Subject: [PATCH 1/2] Fix the difficulty judgment logic of PoW. According to the agreement in the yellow book, it should be: n <= (2^256) / difficulty. --- .../src/main/java/org/ethereum/mine/EthashAlgo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/mine/EthashAlgo.java b/ethereumj-core/src/main/java/org/ethereum/mine/EthashAlgo.java index 879ecd7dc2..d1b47b4f0b 100644 --- a/ethereumj-core/src/main/java/org/ethereum/mine/EthashAlgo.java +++ b/ethereumj-core/src/main/java/org/ethereum/mine/EthashAlgo.java @@ -216,7 +216,7 @@ public long mine(long fullSize, int[] dataset, byte[] blockHeaderTruncHash, long nonce++; Pair pair = hashimotoFull(fullSize, dataset, blockHeaderTruncHash, longToBytes(nonce)); BigInteger h = new BigInteger(1, pair.getRight() /* ?? */); - if (h.compareTo(target) < 0) break; + if (h.compareTo(target) <= 0) break; } return nonce; } @@ -236,7 +236,7 @@ public long mineLight(long fullSize, final int[] cache, byte[] blockHeaderTruncH nonce++; Pair pair = hashimotoLight(fullSize, cache, blockHeaderTruncHash, longToBytes(nonce)); BigInteger h = new BigInteger(1, pair.getRight() /* ?? */); - if (h.compareTo(target) < 0) break; + if (h.compareTo(target) <= 0) break; } return nonce; } From 3615d4dfc6ab164af3a34e8cfc812d35420d9df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E9=B9=8F=E9=A3=9E=28Philip=20Qin=29?= Date: Wed, 4 Sep 2019 00:10:04 +0800 Subject: [PATCH 2/2] Fix the difficulty judgment logic of PoW. According to the agreement in the yellow book, it should be: n <= (2^256) / difficulty. --- .../src/main/java/org/ethereum/mine/EthashAlgoSlow.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/mine/EthashAlgoSlow.java b/ethereumj-core/src/main/java/org/ethereum/mine/EthashAlgoSlow.java index 47ccc5de2b..26ab9ae50f 100644 --- a/ethereumj-core/src/main/java/org/ethereum/mine/EthashAlgoSlow.java +++ b/ethereumj-core/src/main/java/org/ethereum/mine/EthashAlgoSlow.java @@ -181,7 +181,7 @@ public long mine(long fullSize, byte[][] dataset, byte[] blockHeaderTruncHash, l nonce++; Pair pair = hashimotoFull(fullSize, dataset, blockHeaderTruncHash, longToBytes(nonce)); BigInteger h = new BigInteger(1, pair.getRight() /* ?? */); - if (h.compareTo(target) < 0) break; + if (h.compareTo(target) <= 0) break; } return nonce; } @@ -197,7 +197,7 @@ public long mineLight(long fullSize, final byte[][] cache, byte[] blockHeaderTru nonce++; Pair pair = hashimotoLight(fullSize, cache, blockHeaderTruncHash, longToBytes(nonce)); BigInteger h = new BigInteger(1, pair.getRight() /* ?? */); - if (h.compareTo(target) < 0) break; + if (h.compareTo(target) <= 0) break; } return nonce; }