Browse Source

Ethasher update.

cl-refactor
Gav Wood 10 years ago
parent
commit
63df1f7730
  1. 26
      libethcore/Ethasher.cpp
  2. 16
      libethcore/Ethasher.h

26
libethcore/Ethasher.cpp

@ -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)

16
libethcore/Ethasher.h

@ -29,19 +29,8 @@
#include <libdevcore/Guards.h> #include <libdevcore/Guards.h>
#include <libdevcrypto/SHA3.h> #include <libdevcrypto/SHA3.h>
#include <libethash/ethash.h> // TODO: REMOVE once everything merged into this class and an opaque API can be provided. #include <libethash/ethash.h> // TODO: REMOVE once everything merged into this class and an opaque API can be provided.
#define ETHASH_REVISION REVISION static const unsigned c_ethashRevision = REVISION;
#define ETHASH_DATASET_BYTES_INIT DATASET_BYTES_INIT static const unsigned c_ethashEpochLength = EPOCH_LENGTH;
#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
#undef REVISION #undef REVISION
#undef DATASET_BYTES_INIT #undef DATASET_BYTES_INIT
#undef DATASET_BYTES_GROWTH #undef DATASET_BYTES_GROWTH
@ -55,7 +44,6 @@
#undef DATASET_PARENTS #undef DATASET_PARENTS
#undef CACHE_ROUNDS #undef CACHE_ROUNDS
#undef ACCESSES #undef ACCESSES
#include "Common.h" #include "Common.h"
#include "BlockInfo.h" #include "BlockInfo.h"

Loading…
Cancel
Save