|
@ -31,7 +31,6 @@ |
|
|
#include <libdevcrypto/CryptoPP.h> |
|
|
#include <libdevcrypto/CryptoPP.h> |
|
|
#include <libdevcrypto/FileSystem.h> |
|
|
#include <libdevcrypto/FileSystem.h> |
|
|
#include <libethcore/Params.h> |
|
|
#include <libethcore/Params.h> |
|
|
#include <libethash/ethash.h> |
|
|
|
|
|
#include "BlockInfo.h" |
|
|
#include "BlockInfo.h" |
|
|
#include "Ethasher.h" |
|
|
#include "Ethasher.h" |
|
|
using namespace std; |
|
|
using namespace std; |
|
@ -44,9 +43,9 @@ Ethasher* dev::eth::Ethasher::s_this = nullptr; |
|
|
bytes const& Ethasher::cache(BlockInfo const& _header) |
|
|
bytes const& Ethasher::cache(BlockInfo const& _header) |
|
|
{ |
|
|
{ |
|
|
RecursiveGuard l(x_this); |
|
|
RecursiveGuard l(x_this); |
|
|
if (_header.number > EPOCH_LENGTH*2048) { |
|
|
if (_header.number > c_ethashEpochLength * 2048) { |
|
|
std::ostringstream error; |
|
|
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() ); |
|
|
throw std::invalid_argument( error.str() ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -101,21 +100,20 @@ ethash_params Ethasher::params(unsigned _n) |
|
|
|
|
|
|
|
|
bool Ethasher::verify(BlockInfo const& _header) |
|
|
bool Ethasher::verify(BlockInfo const& _header) |
|
|
{ |
|
|
{ |
|
|
if (_header.number >= ETHASH_EPOCH_LENGTH * 2048) |
|
|
if (_header.number >= c_ethashEpochLength * 2048) |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
h256 boundary = u256((bigint(1) << 256) / _header.difficulty); |
|
|
h256 boundary = u256((bigint(1) << 256) / _header.difficulty); |
|
|
uint8_t quickHashOut[32]; |
|
|
|
|
|
ethash_quick_hash( |
|
|
// should be equivalent to:
|
|
|
quickHashOut, |
|
|
auto r = eval(_header); |
|
|
|
|
|
return r.mixHash == _header.mixHash && r.value <= boundary; |
|
|
|
|
|
|
|
|
|
|
|
return ethash_quick_check_difficulty( |
|
|
_header.headerHash(WithoutNonce).data(), |
|
|
_header.headerHash(WithoutNonce).data(), |
|
|
(uint64_t)(u64)_header.nonce, |
|
|
(uint64_t)(u64)_header.nonce, |
|
|
_header.mixHash.data() |
|
|
_header.mixHash.data(), |
|
|
); |
|
|
boundary.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; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Ethasher::Result Ethasher::eval(BlockInfo const& _header, Nonce const& _nonce) |
|
|
Ethasher::Result Ethasher::eval(BlockInfo const& _header, Nonce const& _nonce) |
|
|