|
|
@ -24,19 +24,20 @@ |
|
|
|
#include <stdbool.h> |
|
|
|
#include <string.h> |
|
|
|
#include <stddef.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include "compiler.h" |
|
|
|
|
|
|
|
#define REVISION 23 |
|
|
|
#define DATASET_BYTES_INIT 1073741824U // 2**30
|
|
|
|
#define DATASET_BYTES_GROWTH 8388608U // 2**23
|
|
|
|
#define CACHE_BYTES_INIT 1073741824U // 2**24
|
|
|
|
#define CACHE_BYTES_GROWTH 131072U // 2**17
|
|
|
|
#define EPOCH_LENGTH 30000U |
|
|
|
#define MIX_BYTES 128 |
|
|
|
#define HASH_BYTES 64 |
|
|
|
#define DATASET_PARENTS 256 |
|
|
|
#define CACHE_ROUNDS 3 |
|
|
|
#define ACCESSES 64 |
|
|
|
#define ETHASH_REVISION 23 |
|
|
|
#define ETHASH_DATASET_BYTES_INIT 1073741824U // 2**30
|
|
|
|
#define ETHASH_DATASET_BYTES_GROWTH 8388608U // 2**23
|
|
|
|
#define ETHASH_CACHE_BYTES_INIT 1073741824U // 2**24
|
|
|
|
#define ETHASH_CACHE_BYTES_GROWTH 131072U // 2**17
|
|
|
|
#define ETHASH_EPOCH_LENGTH 30000U |
|
|
|
#define ETHASH_MIX_BYTES 128 |
|
|
|
#define ETHASH_HASH_BYTES 64 |
|
|
|
#define ETHASH_DATASET_PARENTS 256 |
|
|
|
#define ETHASH_CACHE_ROUNDS 3 |
|
|
|
#define ETHASH_ACCESSES 64 |
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
extern "C" { |
|
|
@ -61,34 +62,49 @@ static inline void ethash_params_init(ethash_params *params, const uint32_t bloc |
|
|
|
params->cache_size = ethash_get_cachesize(block_number); |
|
|
|
} |
|
|
|
|
|
|
|
typedef struct ethash_cache { |
|
|
|
void *mem; |
|
|
|
} ethash_cache; |
|
|
|
/***********************************
|
|
|
|
* OLD API ************************* |
|
|
|
*********************************** |
|
|
|
******************** (deprecated) * |
|
|
|
***********************************/ |
|
|
|
|
|
|
|
void ethash_mkcache(ethash_cache *cache, ethash_params const *params, const uint8_t seed[32]); |
|
|
|
void ethash_compute_full_data(void *mem, ethash_params const *params, ethash_cache const *cache); |
|
|
|
void ethash_full(ethash_return_value *ret, void const *full_mem, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce); |
|
|
|
void ethash_light(ethash_return_value *ret, ethash_cache const *cache, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce); |
|
|
|
void ethash_get_seedhash(uint8_t seedhash[32], const uint32_t block_number); |
|
|
|
void ethash_mkcache(void *cache, ethash_params const *params, const uint8_t seed[32]); |
|
|
|
void ethash_light(ethash_return_value *ret, void const *cache, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce); |
|
|
|
void ethash_compute_full_data(void *mem, ethash_params const *params, void const *cache); |
|
|
|
void ethash_full(ethash_return_value *ret, void const *full_mem, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce); |
|
|
|
|
|
|
|
static inline void ethash_prep_light(void *cache, ethash_params const *params, const uint8_t seed[32]) { |
|
|
|
ethash_cache c; |
|
|
|
c.mem = cache; |
|
|
|
ethash_mkcache(&c, params, seed); |
|
|
|
} |
|
|
|
/***********************************
|
|
|
|
* NEW API ************************* |
|
|
|
***********************************/ |
|
|
|
|
|
|
|
// TODO: compute params and seed in ethash_new_light; it should take only block_number
|
|
|
|
// TODO: store params in ethash_light_t/ethash_full_t to avoid having to repass into compute/new_full
|
|
|
|
|
|
|
|
typedef uint8_t const ethash_seedhash_t[32]; |
|
|
|
|
|
|
|
static inline void ethash_compute_light(ethash_return_value *ret, void const *cache, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce) { |
|
|
|
ethash_cache c; |
|
|
|
c.mem = (void *) cache; |
|
|
|
ethash_light(ret, &c, params, header_hash, nonce); |
|
|
|
typedef void const* ethash_light_t; |
|
|
|
static inline ethash_light_t ethash_new_light(ethash_params const* params, ethash_seedhash_t seed) { |
|
|
|
void* ret = malloc(params->cache_size); |
|
|
|
ethash_mkcache(ret, params, seed); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
static inline void ethash_compute_light(ethash_return_value *ret, ethash_light_t light, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce) { |
|
|
|
ethash_light(ret, light, params, header_hash, nonce); |
|
|
|
} |
|
|
|
static inline void ethash_delete_light(ethash_light_t light) { |
|
|
|
free((void*)light); |
|
|
|
} |
|
|
|
|
|
|
|
typedef void const* ethash_full_t; |
|
|
|
static inline ethash_full_t ethash_new_full(ethash_params const* params, ethash_light_t light) { |
|
|
|
void* ret = malloc(params->full_size); |
|
|
|
ethash_compute_full_data(ret, params, light); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
static inline void ethash_prep_full(void *full, ethash_params const *params, void const *cache) { |
|
|
|
ethash_cache c; |
|
|
|
c.mem = (void *) cache; |
|
|
|
ethash_compute_full_data(full, params, &c); |
|
|
|
ethash_compute_full_data(full, params, cache); |
|
|
|
} |
|
|
|
|
|
|
|
static inline void ethash_compute_full(ethash_return_value *ret, void const *full, ethash_params const *params, const uint8_t header_hash[32], const uint64_t nonce) { |
|
|
|
ethash_full(ret, full, params, header_hash, nonce); |
|
|
|
} |
|
|
|