From 44aba8e2a5c8944fbaf21caa2a88445010f635ce Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Thu, 11 Feb 2021 22:47:57 -0800 Subject: [PATCH] simplify and call out the code of the keccak hash function Signed-off-by: Antoine Toulme --- .../besu/ethereum/mainnet/KeccakHasher.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasher.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasher.java index e8f3f3b45dc..091d58f527d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasher.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasher.java @@ -38,14 +38,13 @@ public PoWSolution hash( final long number, final EpochCalculator epochCalc, final byte[] prePowHash) { - Bytes input = Bytes.wrap(Bytes.wrap(prePowHash), Bytes.ofUnsignedLong(nonce)); MessageDigest digest = KECCAK_256.get(); - digest.update(input.toArrayUnsafe()); - byte[] result = digest.digest(); - Bytes32 resultBytes = Bytes32.wrap(result); + digest.update(prePowHash); + digest.update(Bytes.ofUnsignedLong(nonce).toArrayUnsafe()); + Bytes32 solution = Bytes32.wrap(digest.digest()); + Hash mixHash = Hash.wrap(solution); - PoWSolution solution = new PoWSolution(nonce, Hash.wrap(resultBytes), resultBytes, prePowHash); - return solution; + return new PoWSolution(nonce, mixHash, solution, prePowHash); } }