2

This is a C/C++ programming question related to CPU mining. In the source code for CPU miners wolf-xmr-miner, cpuminer-multi et al there is a function called scanhash_cryptonight that has this the following prototype:

int scanhash_cryptonight(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
                         uint32_t max_nonce, uint64_t *hashes_done);

The parameters pdata and ptarget are pointers to members of a struct that looks like this:

struct work {
    uint32_t data[32];
    uint32_t target[8];

    /* ... */
};

Now when scanhash_cryptonight is called there is this nonceptr variable that is initialized like this (link to scanhash function):

uint32_t *nonceptr = (uint32_t*) (((char*)pdata) + 39); 

My question is: what is the value of nonceptr used for and what is the casting in the expresssion doing?

moo
  • 125
  • 6

1 Answers1

3

nonceptr is a pointer to the place where the nonce is in the block header (pointed to by pdata). It is defined as a pointer to an unsigned 32-bit integer because the nonce is 32 bits long, and it is used when mining to easily change the nonce (e.g. *nonceptr = new_nonce;).

glv
  • 3,364
  • 11
  • 15