# Why mining bitcoins is difficult?

As I understand to obtain a Golden Block is to finding a nonce that matches a hash lower than a given target, as shown in this research-gate article.

And here is a "py" kernel: Bitcoin mining python (Github)

As the nonce is only a 4 (8-bit)byte it is only to compare 65,536 hashes, that it seems ridiculous for any GPU.

So... Why is it difficult?

• 4 bytes is $2^{32}$, not $2^{16}$; but there is no restriction on the nonce length in this code. It is "difficult" (slow; but embarrassingly parallizable) to brute force the hash to be less than the target. Mar 9, 2020 at 12:00
• What is the probability that a random input will have 4-byte zero 256-bit output of SHA-256? Mar 9, 2020 at 13:51
• @kelalaka I'd re-phrase your question for the OP as "What is the probability the hash of a random input starts with 4 zero bytes?" to disambiguate from $4/32$ zero bytes in any position. Mar 9, 2020 at 14:15
• Right ... I thought the nonce was 4 hexadecimal digits. Mar 9, 2020 at 17:09

There are 4294967296 nonces, because it is 32-bit.

Most of the time, none of the nonces will produce a "Golden Block". If none of the nonces work, the miner must make a new block (with a different Merkle root (256 bits) which means the block has different transactions in it) and try to mine that block instead.

Currently, about 99.999999994% of blocks don't have any valid nonce. That means the miner must try over 15 billion blocks before it finds one that has a nonce.

This is not a problem, because one of the transactions in a block is the one which gives the bitcoins to the miner. The miner can't change other peoples' transactions, but it can add extra unused bytes to its own transaction, which means the block has different transactions in it, and a different Merkle root.

• Most of the time = ? Mar 9, 2020 at 15:22
• @kelalaka Currently, about 99.999999994% of blocks will not have any valid nonce. Mar 9, 2020 at 15:49
• That's correct! I thought the nonce was 4 hexadecimals. But even being 4,295 million it is still easy to obtain it in less than one second with a good GPU. So it is a question of milliseconds to be the winner? Mar 9, 2020 at 17:14
• "This is done by slightly changing the transaction that gives you the new bitcoins" .. can you explain this better? Mar 9, 2020 at 17:17
• Ok ... Imagine I can know when a block has not a valid nonce. I only have to wait to the one and then I only will spend 20 milliseconds of my GPU(s) Mar 9, 2020 at 17:28