How does Bitcoin mining work? A guide to discover the mechanisms behind it
- Mining: a misleading term
- The Competition: Rolling Digital Dice
- Proof-of-Work and difficulty adjustment
- Network Security
Mining: a misleading term
The term mining in Bitcoin can be misleading. It does not indicate the search for precious materials, but a process whose task is to write blocks on the blockchain and supply them to the network nodes, while simultaneously securing the network. The issuing of new currency is the designed way to economically compensate the miner’s activity.
The newly executed transactions are placed by the nodes in an area called a mempool. The miner collects these transactions and enters them into a group of information called a candidate block. In addition to these transactions, the miner also enters the coinbase transaction, a special transaction that assigns the new bitcoins issued with the new block to itself.
- The miners receive and verify the unconfirmed transactions and enter them into the mempool;
- They build the candidate block by selecting transactions from the mempool;
- They enter the coinbase transaction, self-assigning the bitcoin reward;
- Start the race to find the correct Proof-of-Work and add the block to the blockchain.
The competition: Rolling Digital Dice
Miners around the world compete with each other to earn the right to write their block on the blockchain and, as a result, collect the coinbase transaction together with the fees of all transactions on the blockchain.
This digital competition can be compared to a continuous roll of the dice. If the requirement is a number less than 12 and we have two dice with 6 dials in our hands, it will most likely only take one throw to find a winning result. If the requirement is a number less than 3, then more throws will most likely be needed.
- Miners take the hash of the previous block, a unique code that acts as an identification number;
- They add a random number, called a nonce, to the hash;
- They apply the SHA-256 algorithm to the result, resulting in a new hash;
- They check whether the new hash meets the specific requirement dictated by the nodes;
- If it does not meet the requirement, they change the nonce and repeat the process until they find a valid number;
- When a miner finds a hash compatible with the requirement it transmits the result to the network, which can cryptographically verify that the block has been mined and add it to the blockchain. From this moment, the race for the next block starts.
Proof-of-Work and Difficulty Adjustment
In Bitcoin mining, the difficulty of the process is carefully adjusted, with the aim of ensuring that a new block is found on average every 10 minutes. How does this process work?
Although each attempt produces a random result, the probability of any result can be calculated in advance. The difficulty adjustment is done by giving miners a target to reach. This difficulty is adjusted every 2,016 blocks – about two weeks – and each node updates it independently based on the time it took to mine the previous 2,016 blocks. In short: the more computing power there is in the network, the higher the difficulty and vice versa. Specialised mining servers, called ASICs, are capable of producing up to 250 TH/s (TeraHash per second), or 250 trillion attempts every second.
Proof-of-Work is the cryptographic demonstration that a miner has done the necessary work to find the hash compatible with the difficulty provided by the nodes. The winning hash becomes the hash of the mined block and will be used as the basis for finding the Proof-of-Work of the next block. This creates a chain, where the hash of each block is obtained from the hash of the previous block, plus the nonce (and the Merkle tree root).
Network Security
Bitcoin’s security is guaranteed by the same computational power used to find the Proof-of-Work of the blocks. The greater the difficulty required to mine each block, the more secure the network. More hashes, more security. To change the hash of one block, one would have to change the hash of all subsequent blocks down to the last one in the chain, which is virtually impossible. This makes Bitcoin’s blockchain extremely secure.