Bitcoin's Hashing Race and the Extra Nonce Solution

In this article, we learn about Bitcoin's hashing race and the extra nonce solution used to solve Bitcoin's cryptographic puzzle.

Table of contents.

  1. Introduction.
  2. Extra Nonce.
  3. Summary.
  4. References.

Introduction

Mining cryptocurrencies such as Bitcoin or Etherium is very competitive and as such requires participants to have a greater share of the global hash rate in order to compete effectively.
Over the years, the hashing power has increased exponentially. Some of this growth is as a result of technological change. For example, mining switched from hardware to CPU mining to GPU mining and Field Programmable Gate(FPGA) mining between 2010 and 2011.

This also changed in 2013 to the use of ASIC(Application-Specific Integrated Circuit) where the SHA-256 algorithm was directly encoded into the silicon chips for the specialized purpose of mining Bitcoin. These chips delivered more mining power than the entire network before 2010.

ASIC mining is very expensive and even if a single party can afford a single ASIC mining chip, he/she would not be even close to being able to compete with organizations of individuals with a huge amount of resources with warehouses filled with racks of ASIC miners located near a hydroelectric power plant. This led to the creation of mining pools where miners could contribute their hashing power to solve Bitcoin's cryptographic puzzle after which they share in the profits.

Below is a graph of the hashing power of Bitcoin over the past year until the writing of this;

bit92

As we can see the increase in hashing power is exponential, this comes as a result of competing miners.

In a similar way, as the amount of hashing power used for mining increases, so as the difficulty. The following is the difficulty chart over the past year until the time of writing this;

bit93

ASIC miners have become denser thereby cutting the edge of silicon fabrication with a feature size of 16 nanometers. There are no more gigantic leaps as we have seen from CPU - GPU - ASIC since Bitcoin's mining industry has reached the edge of Moore's law which stipulates that the computing density doubles after every 18 months. Now it is not about how much mining a chip can handle but how many of these chips can fit in a building while dissipating heat and providing the needed electricity to power them.

Extra Nonce.

In previous articles, we learned about the nonce(Number only used once). This is the number added to a hashed block in a blockchain is then when the hash is rehashed it meets the level of difficulty. This is the number miners usually look for, it takes a significant amount of computational power to find it and about 10 minutes. Once found miners are rewarded with bitcoins.
Nonces weed out untalented crypto miners meaning a rig with a significant amount of computational power is needed to compete.

During the initial year of Bitcoins release, miners had to loop through the nonce until the resulting hash was below the target. Over time as the difficulty increased and miners had to loop over billions of values(nonces) to no avail. In 2012 mining evolved to resolve this limitation that came about as a result of the block header structure.

Updating the block timestamp to account for passed elapsed time resolved this issue. This was because the timestamp which is part of the block header allowed miners to loop through values of the nonce again with different results. Overtime mining hardware exceeded 4 GH/s meaning that this approach soon became increasingly difficult because the nonce values were depleted in milliseconds.

The introduction of ASIC miners in 2013 pushed and exceeded the TH/s hash rate. This meant that mining equipment needed storage for nonce values for them to find valid blocks. Although the timestamp could be extended, moving it too far forward would result in a block becoming invalid.

A change to the block header structures was required. A solution proposed the use of the coinbase transaction as the source of the extra nonce values. This is because the coinbase script could hold 2 - 100 bytes of data. Miners now used the extra space to store nonce values. This allowed them to explore a large range of block header values in order to find valid blocks.

Since the coinbase transaction is included in the Merkle tree, it meant that any change in the coinbase script caused a change in the Merkle root. 8 bytes of extra nonce add 4 bytes of standard nonce allowed the miner to be able to explore 2^96 possibilities per second without the need to modify the timestamp.

Up to now, the coin base script has space that could be used for future expansion of the extra nonce space.

In conclusion, the block header is double hashed using the SHA-256 hashing algorithm.
If the hash is less than the target, the solution is found, otherwise, nonce - a value in the block header is incremented. This process is repeated until the nonce is found or until the hash is less than the target. Four billion nonces are tested. We can reference the 'Mining a Block' article in the reference section for the PoW algorithm implemented in Python.

In the case where all 4 billion nonces have been tried without a successful solution, miners can adjust the timestamp, order of transactions, or use an extra nonce. This extra nonce is part of the input that is used in generating the coinbase transaction - the first transaction in the block.

Once the adjustments are made, in this case, the extra nonce, all 4 billion nonces are tried again with this new block header. If this is unsuccessful, the miner adjusts the header again and tries all 4 billion values to find a hash less than the target.

This process is repeated until a combination of a block header and a nonce is less than the target hash.
For more on this refer to the first link in the references section.

Summary

A nonce(number only used once) is a number that is added to a hashed block that when rehashed meets the criteria for solving the puzzle. When miners find this nonce, they are rewarded with 6.25 Bitcoins.
A golden nonce is a number that is added to a hashed block in a blockchain to make it less than the target difficulty meaning that it solves the puzzle.
Mining is a way Bitcoin uses to introduce new coins into circulation.
The extra nonce comes from the coinbase transaction. The coinbase is the first transaction in a block without any inputs. This transaction is what is used to pay miners. The payment is the sum of the reward by Bitcoin protocol and the total sum of all transaction fees in the block.

References

Mining a Block