Merge branch 'bug-128tx-exploit'

This commit is contained in:
XMRig 2017-04-22 18:08:15 +03:00
commit d855ae2e36
13 changed files with 145 additions and 124 deletions

View file

@ -40,7 +40,6 @@ struct cryptonight_ctx {
extern void (* const extra_hashes[4])(const void *, size_t, char *);
bool cryptonight_init(int variant);
void cryptonight_hash(void* output, const void* input, size_t input_len);
int scanhash_cryptonight(int thr_id, uint32_t *hash, uint32_t *restrict pdata, const uint32_t *restrict ptarget, uint32_t max_nonce, unsigned long *restrict hashes_done, struct cryptonight_ctx *restrict ctx);
int scanhash_cryptonight(int thr_id, uint32_t *hash, uint32_t *restrict blob, size_t blob_size, uint32_t target, uint32_t max_nonce, unsigned long *restrict hashes_done, struct cryptonight_ctx *restrict ctx);
#endif /* __CRYPTONIGHT_H__ */

View file

@ -222,9 +222,9 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output)
}
void cryptonight_av1_aesni(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx)
void cryptonight_av1_aesni(const void *restrict input, size_t size, void *restrict output, struct cryptonight_ctx *restrict ctx)
{
keccak((const uint8_t *) input, 76, ctx->state, 200);
keccak((const uint8_t *) input, size, ctx->state, 200);
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory);

View file

@ -222,9 +222,9 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output)
}
void cryptonight_av2_aesni_stak(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx)
void cryptonight_av2_aesni_stak(const void *restrict input, size_t size, void *restrict output, struct cryptonight_ctx *restrict ctx)
{
keccak((const uint8_t *) input, 76, ctx->state, 200);
keccak((const uint8_t *) input, size, ctx->state, 200);
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory);

View file

@ -213,9 +213,9 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output)
}
void cryptonight_av3_aesni_bmi2(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx)
void cryptonight_av3_aesni_bmi2(const void *restrict input, size_t size, void *restrict output, struct cryptonight_ctx *restrict ctx)
{
keccak((const uint8_t *) input, 76, ctx->state, 200);
keccak((const uint8_t *) input, size, ctx->state, 200);
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory);

View file

@ -203,9 +203,9 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output)
}
void cryptonight_av4_softaes(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx)
void cryptonight_av4_softaes(const void *restrict input, size_t size, void *restrict output, struct cryptonight_ctx *restrict ctx)
{
keccak((const uint8_t *) input, 76, ctx->state, 200);
keccak((const uint8_t *) input, size, ctx->state, 200);
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory);

View file

@ -213,11 +213,11 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output)
}
void cryptonight_av5_aesni_experimental(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx)
void cryptonight_av5_aesni_experimental(const void *restrict input, size_t size, void *restrict output, struct cryptonight_ctx *restrict ctx)
{
const uint8_t* memory = ctx->memory;
keccak((const uint8_t *) input, 76, ctx->state, 200);
keccak((const uint8_t *) input, size, ctx->state, 200);
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) memory);
uint64_t* state = (uint64_t*) ctx->state;

View file

@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#ifndef BUILD_TEST
# include "xmrig.h"
@ -52,16 +53,16 @@ const static char test_output[32] = {
};
void cryptonight_av1_aesni(void* output, const void* input, struct cryptonight_ctx* ctx);
void cryptonight_av4_softaes(void* output, const void* input, struct cryptonight_ctx* ctx);
void cryptonight_av1_aesni(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx);
void cryptonight_av4_softaes(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx);
#if defined(__x86_64__)
void cryptonight_av2_aesni_stak(void* output, const void* input, struct cryptonight_ctx* ctx);
void cryptonight_av3_aesni_bmi2(void* output, const void* input, struct cryptonight_ctx* ctx);
void cryptonight_av5_aesni_experimental(void* output, const void* input, struct cryptonight_ctx* ctx);
void cryptonight_av2_aesni_stak(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx);
void cryptonight_av3_aesni_bmi2(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx);
void cryptonight_av5_aesni_experimental(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx);
#endif
void (*cryptonight_hash_ctx)(void* output, const void* input, struct cryptonight_ctx* ctx) = NULL;
void (*cryptonight_hash_ctx)(void* input, size_t size, const void* output, struct cryptonight_ctx* ctx) = NULL;
static bool self_test() {
@ -70,7 +71,7 @@ static bool self_test() {
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) malloc(sizeof(struct cryptonight_ctx));
ctx->memory = (uint8_t *) malloc(MEMORY);
cryptonight_hash_ctx(output, test_input, ctx);
cryptonight_hash_ctx(test_input, sizeof(test_input), output, ctx);
free(ctx->memory);
free(ctx);
@ -136,16 +137,16 @@ void (* const extra_hashes[4])(const void *, size_t, char *) = {do_blake_hash, d
#ifndef BUILD_TEST
int scanhash_cryptonight(int thr_id, uint32_t *hash, uint32_t *restrict pdata, const uint32_t *restrict ptarget, uint32_t max_nonce, unsigned long *restrict hashes_done, struct cryptonight_ctx *restrict ctx) {
uint32_t *nonceptr = (uint32_t*) (((char*)pdata) + 39);
int scanhash_cryptonight(int thr_id, uint32_t *hash, uint32_t *restrict blob, size_t blob_size, uint32_t target, uint32_t max_nonce, unsigned long *restrict hashes_done, struct cryptonight_ctx *restrict ctx) {
uint32_t *nonceptr = (uint32_t*) (((char*) blob) + 39);
uint32_t n = *nonceptr - 1;
const uint32_t first_nonce = n + 1;
do {
*nonceptr = ++n;
cryptonight_hash_ctx(hash, pdata, ctx);
cryptonight_hash_ctx(blob, blob_size, hash, ctx);
if (unlikely(hash[7] < ptarget[7])) {
if (unlikely(hash[7] < target)) {
*hashes_done = n - first_nonce + 1;
return true;
}

View file

@ -250,9 +250,9 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output)
}
void cryptonight_av1_aesni(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx)
void cryptonight_av1_aesni(const void *restrict input, size_t size, void *restrict output, struct cryptonight_ctx *restrict ctx)
{
keccak((const uint8_t *) input, 76, ctx->state, 200);
keccak((const uint8_t *) input, size, ctx->state, 200);
cn_explode_scratchpad((__m128i*) ctx->state, (__m128i*) ctx->memory);

View file

@ -230,7 +230,7 @@ static inline void cn_implode_scratchpad(const __m128i* input, __m128i* output)
}
void cryptonight_av4_softaes(void *restrict output, const void *restrict input, struct cryptonight_ctx *restrict ctx)
void cryptonight_av4_softaes(const void *restrict input, size_t size, void *restrict output, struct cryptonight_ctx *restrict ctx)
{
keccak((const uint8_t *) input, 76, ctx->state, 200);

View file

@ -58,6 +58,9 @@
#define unlikely(expr) (__builtin_expect(!!(expr), 0))
static struct work work;
static bool send_line(curl_socket_t sock, char *s);
static bool socket_full(curl_socket_t sock, int timeout);
static void buffer_append(struct stratum_ctx *sctx, const char *s);
@ -66,7 +69,7 @@ static int sockopt_keepalive_cb(void *userdata, curl_socket_t fd, curlsocktype p
static curl_socket_t opensocket_grab_cb(void *clientp, curlsocktype purpose, struct curl_sockaddr *addr);
static int closesocket_cb(void *clientp, curl_socket_t item);
static bool login_decode(struct stratum_ctx *sctx, const json_t *val);
static bool job_decode(struct stratum_ctx *sctx, const json_t *job);
static bool job_decode(const json_t *job);
static bool jobj_binary(const json_t *obj, const char *key, void *buf, size_t buflen);
@ -327,13 +330,17 @@ bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *p
}
login_decode(sctx, val);
json_t *job = json_object_get(result, "job");
pthread_mutex_lock(&sctx->work_lock);
if (job) {
job_decode(sctx, job);
}
pthread_mutex_unlock(&sctx->work_lock);
job(sctx, json_object_get(result, "job"));
// json_t *job = json_object_get(result, "job");
//pthread_mutex_lock(&sctx->work_lock);
//if (job) {
// job_decode(sctx, job);
//}
//pthread_mutex_unlock(&sctx->work_lock);
json_decref(val);
return true;
@ -492,11 +499,20 @@ static void buffer_append(struct stratum_ctx *sctx, const char *s)
*/
static bool job(struct stratum_ctx *sctx, json_t *params)
{
bool ret = false;
if (!job_decode(params)) {
return false;
}
pthread_mutex_lock(&sctx->work_lock);
ret = job_decode(sctx, params);
if (sctx->work.target != work.target) {
stats_set_target(work.target);
}
memcpy(&sctx->work, &work, sizeof(struct work));
pthread_mutex_unlock(&sctx->work_lock);
return ret;
return true;
}
@ -584,33 +600,22 @@ static bool login_decode(struct stratum_ctx *sctx, const json_t *val) {
return false;
}
json_t *tmp = json_object_get(res, "id");
if (!tmp) {
const char *id = json_string_value(json_object_get(res, "id"));
if (!id || strlen(id) >= (sizeof(sctx->id))) {
applog(LOG_ERR, "JSON invalid id");
return false;
}
const char *id = json_string_value(tmp);
if (!id) {
applog(LOG_ERR, "JSON id is not a string");
return false;
}
memcpy(&sctx->id, id, 64);
memset(&sctx->id, 0, sizeof(sctx->id));
memcpy(&sctx->id, id, strlen(id));
pthread_mutex_lock(&sctx->sock_lock);
sctx->ready = true;
pthread_mutex_unlock(&sctx->sock_lock);
tmp = json_object_get(res, "status");
if (!tmp) {
applog(LOG_ERR, "JSON invalid status");
return false;
}
const char *s = json_string_value(tmp);
const char *s = json_string_value(json_object_get(res, "status"));
if (!s) {
applog(LOG_ERR, "JSON status is not a string");
applog(LOG_ERR, "JSON invalid status");
return false;
}
@ -630,46 +635,40 @@ static bool login_decode(struct stratum_ctx *sctx, const json_t *val) {
* @param work
* @return
*/
static bool job_decode(struct stratum_ctx *sctx, const json_t *job) {
json_t *tmp = json_object_get(job, "job_id");
if (!tmp) {
static bool job_decode(const json_t *job) {
const char *job_id = json_string_value(json_object_get(job, "job_id"));
if (!job_id || strlen(job_id) >= sizeof(work.job_id)) {
applog(LOG_ERR, "JSON invalid job id");
return false;
}
const char *job_id = json_string_value(tmp);
tmp = json_object_get(job, "blob");
if (!tmp) {
const char *blob = json_string_value(json_object_get(job, "blob"));
if (!blob) {
applog(LOG_ERR, "JSON invalid blob");
return false;
}
const char *hexblob = json_string_value(tmp);
if (!hexblob || strlen(hexblob) != 152) {
work.blob_size = strlen(blob);
if (work.blob_size % 2 != 0) {
applog(LOG_ERR, "JSON invalid blob length");
return false;
}
if (!hex2bin(sctx->blob, hexblob, 76)) {
applog(LOG_ERR, "JSON inval blob");
work.blob_size /= 2;
if (work.blob_size < 76 || work.blob_size > (sizeof(work.blob))) {
applog(LOG_ERR, "JSON invalid blob length");
return false;
}
uint32_t target;
jobj_binary(job, "target", &target, 4);
if (sctx->target != target) {
stats_set_target(target);
sctx->target = target;
if (!hex2bin((unsigned char *) work.blob, blob, work.blob_size)) {
applog(LOG_ERR, "JSON invalid blob");
return false;
}
memcpy(sctx->work.data, sctx->blob, 76);
memset(sctx->work.target, 0xff, sizeof(sctx->work.target));
jobj_binary(job, "target", &work.target, 4);
sctx->work.target[7] = sctx->target;
free(sctx->work.job_id);
sctx->work.job_id = strdup(job_id);
memset(work.job_id, 0, sizeof(work.job_id));
memcpy(work.job_id, job_id, strlen(job_id));
return true;
}
@ -699,6 +698,7 @@ static bool jobj_binary(const json_t *obj, const char *key, void *buf, size_t bu
return false;
}
if (!hex2bin(buf, hexstr, buflen)) {
return false;
}

View file

@ -29,14 +29,18 @@
#include <curl/curl.h>
/**
* 128tx exploit.
*
* Max blob size is 84 (75 fixed + 9 variable), aligned to 96.
* https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk.
*/
struct work {
uint32_t data[19];
uint32_t target[8];
uint32_t hash[8];
char *job_id;
size_t xnonce2_len;
unsigned char *xnonce2;
uint32_t blob[21] __attribute__((aligned(16)));
size_t blob_size __attribute__((aligned(16)));
uint32_t target __attribute__((aligned(16)));
uint32_t hash[8] __attribute__((aligned(16)));
char job_id[64] __attribute__((aligned(16)));
};
@ -53,8 +57,6 @@ struct stratum_ctx {
bool ready;
char id[64];
char blob[76];
uint32_t target;
struct work work;
struct work g_work;

View file

@ -2,24 +2,30 @@
#include <stdbool.h>
#include <stdlib.h>
#include <algo/cryptonight/cryptonight.h>
#include <string.h>
const static char input[76] = {
const static char input1[76] = {
0x03, 0x05, 0xA0, 0xDB, 0xD6, 0xBF, 0x05, 0xCF, 0x16, 0xE5, 0x03, 0xF3, 0xA6, 0x6F, 0x78, 0x00, 0x7C, 0xBF, 0x34,
0x14, 0x43, 0x32, 0xEC, 0xBF, 0xC2, 0x2E, 0xD9, 0x5C, 0x87, 0x00, 0x38, 0x3B, 0x30, 0x9A, 0xCE, 0x19, 0x23, 0xA0,
0x96, 0x4B, 0x00, 0x00, 0x00, 0x08, 0xBA, 0x93, 0x9A, 0x62, 0x72, 0x4C, 0x0D, 0x75, 0x81, 0xFC, 0xE5, 0x76, 0x1E,
0x9D, 0x8A, 0x0E, 0x6A, 0x1C, 0x3F, 0x92, 0x4F, 0xDD, 0x84, 0x93, 0xD1, 0x11, 0x56, 0x49, 0xC0, 0x5E, 0xB6, 0x01
};
const static char input2[] = "This is a test";
const static char input3[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pellentesque metus.";
void cryptonight_av1_aesni(void* output, const void* input, struct cryptonight_ctx* ctx);
void cryptonight_av2_aesni_stak(void* output, const void* input, struct cryptonight_ctx* ctx);
void cryptonight_av3_aesni_bmi2(void* output, const void* input, struct cryptonight_ctx* ctx);
void cryptonight_av4_softaes(void* output, const void* input, struct cryptonight_ctx* ctx);
void cryptonight_av5_aesni_experimental(void* output, const void* input, struct cryptonight_ctx* ctx);
void cryptonight_av1_aesni(const void* input, size_t size, void* output, struct cryptonight_ctx* ctx);
void cryptonight_av2_aesni_stak(const void* input, size_t size, void* output, struct cryptonight_ctx* ctx);
void cryptonight_av3_aesni_bmi2(const void* input, size_t size, void* output, struct cryptonight_ctx* ctx);
void cryptonight_av4_softaes(const void* input, size_t size, void* output, struct cryptonight_ctx* ctx);
void cryptonight_av5_aesni_experimental(const void* input, size_t size, void* output, struct cryptonight_ctx* ctx);
static char hash[32];
#define RESULT "1a3ffbee909b420d91f7be6e5fb56db71b3110d886011e877ee5786afd080100"
#define RESULT1 "1a3ffbee909b420d91f7be6e5fb56db71b3110d886011e877ee5786afd080100"
#define RESULT2 "a084f01d1437a09c6985401b60d43554ae105802c5f5d8a9b3253649c0be6605"
#define RESULT3 "0bbe54bd26caa92a1d436eec71cbef02560062fa689fe14d7efcf42566b411cf"
static char *bin2hex(const unsigned char *p, size_t len)
@ -54,11 +60,16 @@ static void free_ctx(struct cryptonight_ctx *ctx) {
void test_cryptonight_av1_should_CalcHash(void) {
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) create_ctx();
cryptonight_av1_aesni(&hash, input, ctx);
cryptonight_av1_aesni(input1, sizeof(input1), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT1, bin2hex(hash, 32));
cryptonight_av1_aesni(input2, strlen(input2), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT2, bin2hex(hash, 32));
cryptonight_av1_aesni(input3, strlen(input3), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT3, bin2hex(hash, 32));
free_ctx(ctx);
TEST_ASSERT_EQUAL_STRING(RESULT, bin2hex(hash, 32));
}
@ -66,11 +77,16 @@ void test_cryptonight_av2_should_CalcHash(void)
{
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) create_ctx();
cryptonight_av2_aesni_stak(&hash, input, ctx);
cryptonight_av2_aesni_stak(input1, sizeof(input1), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT1, bin2hex(hash, 32));
cryptonight_av2_aesni_stak(input2, strlen(input2), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT2, bin2hex(hash, 32));
cryptonight_av2_aesni_stak(input3, strlen(input3), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT3, bin2hex(hash, 32));
free_ctx(ctx);
TEST_ASSERT_EQUAL_STRING(RESULT, bin2hex(hash, 32));
}
@ -78,11 +94,16 @@ void test_cryptonight_av3_should_CalcHash(void)
{
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) create_ctx();
cryptonight_av3_aesni_bmi2(&hash, input, ctx);
cryptonight_av3_aesni_bmi2(input1, sizeof(input1), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT1, bin2hex(hash, 32));
cryptonight_av3_aesni_bmi2(input2, strlen(input2), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT2, bin2hex(hash, 32));
cryptonight_av3_aesni_bmi2(input3, strlen(input3), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT3, bin2hex(hash, 32));
free_ctx(ctx);
TEST_ASSERT_EQUAL_STRING(RESULT, bin2hex(hash, 32));
}
@ -90,11 +111,16 @@ void test_cryptonight_av4_should_CalcHash(void)
{
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) create_ctx();
cryptonight_av4_softaes(&hash, input, ctx);
cryptonight_av4_softaes(input1, sizeof(input1), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT1, bin2hex(hash, 32));
cryptonight_av4_softaes(input2, strlen(input2), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT2, bin2hex(hash, 32));
cryptonight_av4_softaes(input3, strlen(input3), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT3, bin2hex(hash, 32));
free_ctx(ctx);
TEST_ASSERT_EQUAL_STRING(RESULT, bin2hex(hash, 32));
}
@ -102,11 +128,16 @@ void test_cryptonight_av5_should_CalcHash(void)
{
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) create_ctx();
cryptonight_av5_aesni_experimental(&hash, input, ctx);
cryptonight_av5_aesni_experimental(input1, sizeof(input1), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT1, bin2hex(hash, 32));
cryptonight_av5_aesni_experimental(input2, strlen(input2), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT2, bin2hex(hash, 32));
cryptonight_av5_aesni_experimental(input3, strlen(input3), &hash, ctx);
TEST_ASSERT_EQUAL_STRING(RESULT3, bin2hex(hash, 32));
free_ctx(ctx);
TEST_ASSERT_EQUAL_STRING(RESULT, bin2hex(hash, 32));
}

24
xmrig.c
View file

@ -75,8 +75,6 @@ static void workio_cmd_free(struct workio_cmd *wc);
* @param w
*/
static inline void work_free(struct work *w) {
free(w->job_id);
free(w->xnonce2);
}
@ -87,14 +85,6 @@ static inline void work_free(struct work *w) {
*/
static inline void work_copy(struct work *dest, const struct work *src) {
memcpy(dest, src, sizeof(struct work));
if (src->job_id) {
dest->job_id = strdup(src->job_id);
}
if (src->xnonce2) {
dest->xnonce2 = malloc(src->xnonce2_len);
memcpy(dest->xnonce2, src->xnonce2, src->xnonce2_len);
}
}
@ -117,9 +107,7 @@ static inline void gen_workify(struct stratum_ctx *sctx) {
pthread_mutex_lock(&stratum_ctx->work_lock);
if (stratum_ctx->work.job_id && (!stratum_ctx->g_work_time || strcmp(stratum_ctx->work.job_id, stratum_ctx->g_work.job_id))) {
free(sctx->g_work.job_id);
memcpy(&sctx->g_work, &sctx->work, sizeof(struct work));
sctx->work.job_id = strdup(sctx->work.job_id);
time(&stratum_ctx->g_work_time);
pthread_mutex_unlock(&stratum_ctx->work_lock);
@ -143,11 +131,11 @@ static bool submit_upstream_work(struct work *work) {
char s[JSON_BUF_LEN];
/* pass if the previous hash is not the current previous hash */
if (memcmp(work->data + 1, stratum_ctx->g_work.data + 1, 32)) {
if (memcmp(work->blob + 1, stratum_ctx->g_work.blob + 1, 32)) {
return true;
}
char *noncestr = bin2hex(((const unsigned char*) work->data) + 39, 4);
char *noncestr = bin2hex(((const unsigned char*) work->blob) + 39, 4);
char *hashhex = bin2hex((const unsigned char *) work->hash, 32);
snprintf(s, JSON_BUF_LEN,
@ -288,7 +276,7 @@ static void *miner_thread(void *userdata) {
affine_to_cpu_mask(thr_id, (unsigned long) opt_affinity);
}
uint32_t *nonceptr = (uint32_t*) (((char*)work.data) + 39);
uint32_t *nonceptr = (uint32_t*) (((char*)work.blob) + 39);
uint32_t hash[8] __attribute__((aligned(32)));
while (1) {
@ -304,10 +292,10 @@ static void *miner_thread(void *userdata) {
pthread_mutex_lock(&stratum_ctx->work_lock);
if (memcmp(work.data, stratum_ctx->g_work.data, 39) || memcmp(((uint8_t*) work.data) + 43, ((uint8_t*) stratum_ctx->g_work.data) + 43, 33)) {
if (memcmp(work.blob, stratum_ctx->g_work.blob, 39) || memcmp(((uint8_t*) work.blob) + 43, ((uint8_t*) stratum_ctx->g_work.blob) + 43, 33)) {
work_free(&work);
work_copy(&work, &stratum_ctx->g_work);
nonceptr = (uint32_t*) (((char*)work.data) + 39);
nonceptr = (uint32_t*) (((char*) work.blob) + 39);
*nonceptr = 0xffffffffU / opt_n_threads * thr_id;
} else {
++(*nonceptr);
@ -335,7 +323,7 @@ static void *miner_thread(void *userdata) {
gettimeofday(&tv_start, NULL );
/* scan nonces for a proof-of-work hash */
rc = scanhash_cryptonight(thr_id, hash, work.data, work.target, max_nonce, &hashes_done, persistentctx);
rc = scanhash_cryptonight(thr_id, hash, work.blob, work.blob_size, work.target, max_nonce, &hashes_done, persistentctx);
stats_add_hashes(thr_id, &tv_start, hashes_done);
memcpy(work.hash, hash, 32);