A "not" overflow was missing

This commit is contained in:
mratsim 2018-02-27 19:08:51 +01:00
parent c949d9729c
commit 2f95b74b36
2 changed files with 14 additions and 2 deletions

View File

@ -13,6 +13,9 @@ proc readUint256BE*(ba: ByteArrayBE[32]): UInt256 {.noSideEffect.}=
result = result shl 8 or ba[i].u256
proc willMulOverflow(a, b: uint64): bool {.noSideEffect.}=
# Returns true if a * b overflows
# false otherwise
# We assume a <= b
if a > b:
return willMulOverflow(b, a)
@ -93,7 +96,7 @@ proc isValid(nonce: uint64,
else:
let hi_hash = candidate.table[0]
result = willMulOverflow(hi_hash, difficulty)
result = not willMulOverflow(hi_hash, difficulty)
proc mine*(full_size: Natural, dataset: seq[Hash[512]], header: Hash[256], difficulty: uint64): uint64 =

View File

@ -1,7 +1,7 @@
# Copyright (c) 2018 Status Research & Development GmbH
# Distributed under the Apache v2 License (license terms are at http://www.apache.org/licenses/LICENSE-2.0).
import ../src/ethash, unittest, keccak_tiny, times
import ../src/ethash, unittest, keccak_tiny, times, strutils
suite "Test mining":
@ -29,3 +29,12 @@ suite "Test mining":
echo " Done, time taken: ", $(cpuTime() - start), " seconds"
check: mined_nonce == 0x495732e0ed7a801c'u64
# test "1st test from official ethereum/tests repo":
# # https://github.com/ethereum/tests/blob/b6aa0947a8e20f4140dd2647882791be6ceb2ac5/PoWTests/ethash_tests.json
# let
# seed = Hash[256]()
# cache = mkcache(16776896, seed)
# check: $keccak_256(cache) == toUpperAscii "35ded12eecf2ce2e8da2e15c06d463aae9b84cb2530a00b932e4bbc484cde353"