I'm learning about mining and the first thing that surprised me is that the nounce part of the algorithm which is supposed to be randomly looped until you get a number smaller than the target hash .. is just 32 bits long. Can you explain why then is it so difficult to loop an unsigned int and how come is it increasingly difficult over time? Thank you.

Edit: It's been suggested this is a duplicate, this is not. The other question asked if you could run out of nounces, that's nothing to do with my question. My question is about the difficulty of Hashing the exact same 4 billion unsigned int entry loops.

marked as duplicate by Nate Eldredge, Pieter Wuille, Greg Hewgill, Community Aug 31 '17 at 20:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Short answer: With high probability, none of those 2^32 nonces will result in a hash smaller than the target. So then you change something else in the block header and try again. For instance, you can increment a number in the coinbase transaction, which results in a new value for the "Merkle root" hash in the block header. The smaller the target, the more times you are likely to have to do this before success. – Nate Eldredge Aug 31 '17 at 13:47
  • @NateEldredge It looks like you are saying that you do not really need to change the nounce since there is the possibility that none of the 4 billion different values may lead to a winning hash. What makes then a valid 'source material' to hash while attemting to discover a right answer? if you can point me to updated literature about it I will accept that as a right answer. Thanks – Pol Aug 31 '17 at 17:48
  • No, I'm not saying that. What you need is a valid 80-byte block header whose hash is below the target value. So you have to keep changing things in the header until you find something that leads to a winning hash. The easiest thing to change is the nonce, so you fix everything else and then try all possible nonces. If you are lucky then one of them works and you win. If not, which happens most of the time, then you change something else in the header and try all nonces for the updated header. Repeat indefinitely until you win. – Nate Eldredge Aug 31 '17 at 18:08
  • There isn't any need for "updated" literature; the block format and hashing algorithm hasn't changed in any relevant way since the initial introduction of Bitcoin. It was always possible that, with everything else in the header fixed, none of the 2^32 possible nonces wins, and this case always had to be handled; it already happens about 36% of the time even at minimum difficulty. – Nate Eldredge Aug 31 '17 at 18:09

It is not the looping that is difficult, it is generating a hash for each iteration of that loop. Furthermore, as @Nate pointed it, a miner will likely have to change more than just the nonce. As more transactions are coming in from the network, a miner will add/swap them into the block they are hashing, presumably based on maximizing transaction fees. Each time the transaction set is modified, all tried nonces can be tried again.

As for why it gets more difficult over time, that is a core part of the protocol. Every 2,016 blocks, the target hash re-adjusts so that blocks will take about 10 minutes. As more hashing power enters the network, the faster blocks are found, which in turn will trigger the re-adjustment after 2,016 blocks.

  • You say the target Hash readjusts every 2016 blocks, is that 2016 transactions on the network? And: readjusted how? as in: recalculated so all the previously calculated nounces need to be retried? – Pol Aug 31 '17 at 17:41
  • @Pol, if you are confused about a block vs a transaction, it's going to be hard for anyone to give you a satisfactory answer to your question. I recommend reading up a bit more. Here's a great place to start, and should give you the context you need to understand these answers: bitcoin.stackexchange.com/questions/148/what-exactly-is-mining – Jestin Aug 31 '17 at 18:39
  • Agreed, plus there is a question that matches my concerns already. Thanks for your help. – Pol Aug 31 '17 at 20:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.