Bitcoin Forum

Other => Beginners & Help => Topic started by: r0nin on August 26, 2012, 06:51:29 PM



Title: nonce values count & hashrate
Post by: r0nin on August 26, 2012, 06:51:29 PM
Hi!
maximum value for unsigned 32 bit integer is 4 294 967 295. So in order to try all the values i need to calculate ~4.3 G of hashes. Then if I have 4.3 GH/s rig I would found it in a second. What I missed?


Title: Re: nonce values count & hashrate
Post by: Jutarul on August 26, 2012, 07:02:40 PM
There are other fields which can be altered too. Timestamp, Coinbase....


Title: Re: nonce values count & hashrate
Post by: r0nin on August 26, 2012, 07:21:13 PM
I don't see anything except nonce is incremented in this code. (CPU miner)

bool scanhash_c(int thr_id, const unsigned char *midstate, unsigned char *data,
           unsigned char *hash, const unsigned char *target,
           uint32_t max_nonce, unsigned long *hashes_done)
{
   uint32_t *hash32 = (uint32_t *) hash;
   uint32_t *nonce = (uint32_t *)(data + 12);
   uint32_t n = 0;
   unsigned long stat_ctr = 0;

   work_restart[thr_id].restart = 0;

   while (1) {
      unsigned char hash1[32];

      n++;
      *nonce = n;

      runhash(hash1, data, midstate);
      runhash(hash, hash1, sha256_init_state);

      stat_ctr++;

      if (unlikely((hash32[7] == 0) && fulltest(hash, target))) {
         *hashes_done = stat_ctr;
         return true;
      }

      if ((n >= max_nonce) || work_restart[thr_id].restart) {
         *hashes_done = stat_ctr;
         return false;
      }
   }
}


Title: Re: nonce values count & hashrate
Post by: DeathAndTaxes on August 26, 2012, 07:24:18 PM
It isn't in that code.  The rest of the blockheader (midstate) is only incremented outside of that code.

Simple version.
1) Calculate all elements of blockheader (merkle root hash, timestamp, difficulty, version, prior block hash) except the nonce.
2) Pass those values to the miner
3) Increment through all 4 billion possible nonces.  Add the current nonce to the rest of blockhash and hash it.
4a) if share is found return it.
5) wait for new blockheader.


Title: Re: nonce values count & hashrate
Post by: r0nin on August 26, 2012, 07:32:40 PM
Got it, thanks!