Bitcoin Mining
Explore the fundamentals of Bitcoin mining, including the role of nonce in block creation and how mining difficulty is adjusted to secure the blockchain. This lesson helps you grasp why mining is challenging yet crucial for maintaining Bitcoin's value and incentivizing miners.
We'll cover the following...
Mining
In Bitcoin implementation there is an extra field added in each block, called nonce.
Mining peers continuously receive new transactions submitted on the chain. In order for a transaction to be confirmed, it should be put in a block, that needs to be created.
Simply adding transactions to a block is simple - you get the hash or prev block, increment the block number, add the list of transactions, and take its hash. Pretty fast! But in order to incentivize to run a node, Bitcoin awards miners for creating new blocks by giving them newly generated Bitcoins.
Since it would be very simple to mine a block and devalue the generated coin, Bitcoin has made the block creation process challenging. This difficulty self-adjusts to ensure the global pool of miners are able to mine around one block every 10 minutes. This ensures that the supply of new coins is not too fast, making bitcoin a valuable asset.
Nonce Mining
So Bitcoin adds this extra requirement for a block to have a nonce value, such that the block hash of the new block with the nonce has X number of leading zeros. This X is adjusted by the protocol to control the speed of coin generation. The higher the value of X, the harder it is to calculate a nonce.
Now since hash functions are one-way functions the nonce cannot really be ‘calculated’. Miners do a hit and trial kind of algorithm to see if they can find a nonce that satisfies the requirement(X leading zeros) for the next block.
If we go back to our block # 40000 that we looked at earlier, you will find that its hash is
000000000000000004ec466ce4732fe6f1ed1cddc2ed4b328fff5224276e3f6f which has 17 leading zeros.This means that when this block was mined in 2016, the value for X was 17.
Exercise - Mining
The purpose of this exercise is to understand how block mining is ‘hard’.
Let’s say you have a list of transactions that you are mining a block for. And you are required to find a value for nonce that creates blockhash with 3 leading zeros. Input a value of nonce and the hash will adjust. See if you can find a good nonce in a minute.
Test Yourself
Mining a bitcoin essentially is:
Finding the right value of nonce that satisfies the block hash to have set number of leading zeros
Predicting the hash value of new block
Predict a nonce with set number of leading zeros
In the next lesson, we will discuss the value of bitcoin…