Skip to content

Commit

Permalink
Blob length adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasjones committed May 17, 2014
1 parent c1f737f commit 9137c82
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
14 changes: 6 additions & 8 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ static struct option const options[] = {
};

struct work {
uint32_t data[1024];
size_t data_len;
uint32_t data[32];
uint32_t target[8];

char *job_id;
Expand Down Expand Up @@ -394,7 +393,7 @@ static bool rpc2_job_decode(const json_t *job, struct work *work) {
}
const char *hexblob = json_string_value(tmp);
int blobLen = strlen(hexblob);
if (blobLen % 2 != 0 || ((blobLen / 2) < 40 && blobLen != 0)) {
if (blobLen % 2 != 0 || ((blobLen / 2) < 40 && blobLen != 0) || (blobLen / 2) > 128) {
applog(LOG_ERR, "JSON invalid blob length");
goto err_out;
}
Expand Down Expand Up @@ -430,7 +429,6 @@ static bool rpc2_job_decode(const json_t *job, struct work *work) {
goto err_out;
}
memcpy(work->data, rpc2_blob, rpc2_bloblen);
work->data_len = rpc2_bloblen;
memset(work->target, 0xff, sizeof(work->target));
work->target[7] = rpc2_target;
if (work->job_id)
Expand Down Expand Up @@ -596,7 +594,7 @@ static bool submit_upstream_work(CURL *curl, struct work *work) {
switch(opt_algo) {
case ALGO_CRYPTONIGHT:
default:
cryptonight_hash(hash, work->data, work->data_len);
cryptonight_hash(hash, work->data, 76);
}
char *hashhex = bin2hex(hash, 32);
snprintf(s, JSON_BUF_LEN,
Expand All @@ -618,9 +616,9 @@ static bool submit_upstream_work(CURL *curl, struct work *work) {
reason ? json_string_value(reason) : NULL );
} else {
/* build hex string */
for (i = 0; i < work->data_len; i++)
for (i = 0; i < 76; i++)
le32enc(((char*)work->data) + i, *((uint32_t*) (((char*)work->data) + i)));
str = bin2hex((unsigned char *) work->data, work->data_len);
str = bin2hex((unsigned char *) work->data, 76);
if (unlikely(!str)) {
applog(LOG_ERR, "submit_upstream_work OOM");
goto out;
Expand Down Expand Up @@ -1117,7 +1115,7 @@ static void *miner_thread(void *userdata) {
break;
case ALGO_CRYPTONIGHT:
rc = scanhash_cryptonight(thr_id, work.data, work.target,
work.data_len, max_nonce, &hashes_done);
max_nonce, &hashes_done);
break;

default:
Expand Down
4 changes: 2 additions & 2 deletions cryptonight.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void cryptonight_hash(void* output, const void* input, size_t len) {
}

int scanhash_cryptonight(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
size_t data_len, uint32_t max_nonce, unsigned long *hashes_done) {
uint32_t max_nonce, unsigned long *hashes_done) {
uint32_t *nonceptr = (uint32_t*) (((char*)pdata) + 39);
uint32_t n = *nonceptr - 1;
const uint32_t first_nonce = n + 1;
Expand All @@ -189,7 +189,7 @@ int scanhash_cryptonight(int thr_id, uint32_t *pdata, const uint32_t *ptarget,

do {
*nonceptr = ++n;
cryptonight_hash_ctx(hash, pdata, data_len, ctx);
cryptonight_hash_ctx(hash, pdata, 76, ctx);
if (unlikely(hash[7] < ptarget[7])) {
*hashes_done = n - first_nonce + 1;
return true;
Expand Down
2 changes: 1 addition & 1 deletion miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ extern int scanhash_x11(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
extern void cryptonight_hash(void* output, const void* input, size_t input_len);

extern int scanhash_cryptonight(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
size_t data_len, uint32_t max_nonce, unsigned long *hashes_done);
uint32_t max_nonce, unsigned long *hashes_done);

struct thr_info {
int id;
Expand Down

0 comments on commit 9137c82

Please sign in to comment.