Skip to content

Commit

Permalink
simplify and call out the code of the keccak hash function
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine Toulme <[email protected]>
  • Loading branch information
atoulme committed Feb 12, 2021
1 parent d617364 commit 44aba8e
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 44aba8e

Please sign in to comment.