diff --git a/libethcore/Ethasher.cpp b/libethcore/Ethasher.cpp index f80277cb2..e24bfdb6c 100644 --- a/libethcore/Ethasher.cpp +++ b/libethcore/Ethasher.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include "BlockInfo.h" #include "Ethasher.h" using namespace std; @@ -44,9 +43,9 @@ Ethasher* dev::eth::Ethasher::s_this = nullptr; bytes const& Ethasher::cache(BlockInfo const& _header) { RecursiveGuard l(x_this); - if (_header.number > EPOCH_LENGTH*2048) { + if (_header.number > c_ethashEpochLength * 2048) { std::ostringstream error; - error << "block number is too high; max is " << EPOCH_LENGTH*2048 << "(was " << _header.number << ")"; + error << "block number is too high; max is " << c_ethashEpochLength * 2048 << "(was " << _header.number << ")"; throw std::invalid_argument( error.str() ); } @@ -101,21 +100,20 @@ ethash_params Ethasher::params(unsigned _n) bool Ethasher::verify(BlockInfo const& _header) { - if (_header.number >= ETHASH_EPOCH_LENGTH * 2048) + if (_header.number >= c_ethashEpochLength * 2048) return false; + h256 boundary = u256((bigint(1) << 256) / _header.difficulty); - uint8_t quickHashOut[32]; - ethash_quick_hash( - quickHashOut, + + // should be equivalent to: + auto r = eval(_header); + return r.mixHash == _header.mixHash && r.value <= boundary; + + return ethash_quick_check_difficulty( _header.headerHash(WithoutNonce).data(), (uint64_t)(u64)_header.nonce, - _header.mixHash.data() - ); - h256 quickHashOut256 = h256(quickHashOut, h256::ConstructFromPointer); - if (quickHashOut256 > boundary) - return false; - auto e = eval(_header, _header.nonce); - return (u256)e.value <= boundary && e.mixHash == _header.mixHash; + _header.mixHash.data(), + boundary.data()); } Ethasher::Result Ethasher::eval(BlockInfo const& _header, Nonce const& _nonce) diff --git a/libethcore/Ethasher.h b/libethcore/Ethasher.h index 469bbd723..ec8d61225 100644 --- a/libethcore/Ethasher.h +++ b/libethcore/Ethasher.h @@ -29,19 +29,8 @@ #include #include #include // TODO: REMOVE once everything merged into this class and an opaque API can be provided. -#define ETHASH_REVISION REVISION -#define ETHASH_DATASET_BYTES_INIT DATASET_BYTES_INIT -#define ETHASH_DATASET_BYTES_GROWTH DATASET_BYTES_GROWTH -#define ETHASH_CACHE_BYTES_INIT CACHE_BYTES_INIT -#define ETHASH_CACHE_BYTES_GROWTH CACHE_BYTES_GROWTH -#define ETHASH_DAGSIZE_BYTES_INIT DAGSIZE_BYTES_INIT -#define ETHASH_DAG_GROWTH DAG_GROWTH -#define ETHASH_EPOCH_LENGTH EPOCH_LENGTH -#define ETHASH_MIX_BYTES MIX_BYTES -#define ETHASH_HASH_BYTES HASH_BYTES -#define ETHASH_DATASET_PARENTS DATASET_PARENTS -#define ETHASH_CACHE_ROUNDS CACHE_ROUNDS -#define ETHASH_ACCESSES ACCESSES +static const unsigned c_ethashRevision = REVISION; +static const unsigned c_ethashEpochLength = EPOCH_LENGTH; #undef REVISION #undef DATASET_BYTES_INIT #undef DATASET_BYTES_GROWTH @@ -55,7 +44,6 @@ #undef DATASET_PARENTS #undef CACHE_ROUNDS #undef ACCESSES - #include "Common.h" #include "BlockInfo.h"