EVG101 Part 4: Bitcoin Mining

Everest Ventures Group
EVG101
Published in
10 min readApr 4, 2019

Welcome to Part 4 of Everest’s crypto and blockchain guide! With the rise in value of Bitcoin, Bitcoin mining has evolved into a multi-billion dollar industry. But what exactly is mining, and why is it so important to Bitcoin? In this article, we will go into the details of how mining works and talk about the role which it plays in Bitcoin.

To go back to our home page: link

To go back to the previous article on Bitcoin transactions: link

To go to the next article on miscellaneous details in Bitcoin: link

Table of Contents

  1. What is mining?
  2. How are the rewards for mining determined?
  3. What is the proof of work consensus algorithm?
  4. What is the computational problem used in proof of work?
  5. How exactly does mining work?
  6. What is a double spend?
  7. How does mining help Bitcoin to prevent double spending?

TLDR;

A summary of Part 4 of our guide

Let’s get mining!

1. What is mining?

We mentioned mining briefly when talking about miners in part 2 of our guide. In general, mining refers to the act of selecting transactions from the transaction pool, grouping them into a block, and attempting to add this new block to the blockchain. It is the final piece of the Bitcoin incentive puzzle which aligns various stakeholders’ interests so that Bitcoin can function reliably as a decentralized record of transactions.

Miners who successful mine a block and extend the blockchain receive some bitcoin as reward for their efforts. This reward is offered by the Bitcoin network and received through a coinbase transaction. These coinbase transactions are the only way in which new bitcoin are created. Bitcoins received in coinbase transaction can only be spent after 100 confirmations, or after 100 other blocks have been added to the blockchain containing the mined block. This prevents miners from profiting off blocks containing fraudulent transactions since these blocks will have been invalidated and rejected by other nodes. Successful miners also receive transaction fees from every transaction in the block which they mined. Therefore, as long as bitcoins hold sufficient value, there are strong incentives to be a miner in the Bitcoin network.

Miners hard at work. Source: Crypto Capers

In fact, the incentives are so strong that there are companies creating computer chips and hardware dedicated to Bitcoin mining! The most prominent manufacturer of these hardware, Bitmain, has raised more than US$700 million from famous venture capital firms such as IDG Capital and Sequoia. Although the crypto bear market has cooled the mining industry significantly, bitcoin mining remains a lucrative business.

2. How are the rewards for mining determined?

The coinbase transaction reward, or the Bitcoin block reward, is determined by the block reward schedule which was created together with the Bitcoin network. The block reward schedule is one of Bitcoin’s central pillars and cannot be changed.

The block reward schedule works as follows: The value of the block reward started at 50 BTC for each mined block beginning from block #1. The block reward then halves every 210,000 blocks. This means that miners who solve block #1 to block #210,000 receive 50 BTC per solved block, miners who solve block #210,001 to block #420,000 receive 25 BTC per solved block and so on. The average time needed to mine a block is 10 minutes, which means that the block reward is halved approximately every 4 years. This continues until the supply of bitcoin is exhausted.

Number of bitcoins in existence

The total supply of bitcoin is capped at 21 million. Once the circulating supply of bitcoin reaches 21 million, this means that all bitcoin have been released to the network as block rewards, and there will no longer be any block rewards for future mined blocks. Miners, however, will continue to receive transaction fees for their efforts.

3. What is the proof of work consensus algorithm?

We spoke briefly on consensus algorithms in part 1 of our guide. Consensus algorithms provide a means for participants in a blockchain to agree on which blockchain everyone should follow. Bitcoin uses the proof of work consensus algorithm. The proof of work algorithm achieves consensus by defining the longest blockchain to be the canonical (true) blockchain, and uses a competition-and-reward mechanism to determine which miner gets to add a block to the Bitcoin blockchain, with the reward being the block reward discussed in question 2.

To win the competition, miners need to be the first to solve a computational problem. The computational problem is one which is most efficiently solved by brute force (by trying every possible solution to the problem). The computational nature of the proof of work consensus is what makes Bitcoin prohibitively expensive to sabotage.

4. What is the computational problem used in proof of work?

The computational problem utilizes the properties of the SHA-256 algorithm mentioned in Part 1 of our guide. The SHA-256 is used to hash the block header of the proposed block twice to generate the block hash, a 256 digit-long binary sequence. Miners are required to find a hash that begins with a certain number of zeros (the current number of zeros that the hash must begin with is 72). They can do this by choosing the value of the nonce, an integer field in the block header, before hashing.

As explained in Part 1, the hash output from the SHA-256 algorithm is unpredictable: miners will not be able to predict what the hash output will be given the content of a block. Therefore, they will have to systematically try many, many different values of the nonce to obtain a hash output that begins with 18 zeros in hexadecimal format (or 72 zeros in binary). There is a 1 in 2⁷² chance, or 1 in ~10²¹ chance of getting a binary hash that starts with 72 zeros, since each digit can take 2 possible values.

In other words, a miner has on average 10²¹ options, of which only one holds the solution to the computational problem. Each of these options looks the same, so the miner has no choice but to choose randomly from these options until he finds the option which solves the computational problem. The miner which can most quickly check all their options (try all the different possible values of the nonce) will, on average, solve the computational problem the quickest and receive the block reward. Therefore, miners with more computational power are at an advantage: the more computational power you have, the higher the odds of finding the correct nonce to generate a block hash which satisfies the requirements set by the network.

The process of nonce incrementation to solve the computation problem

Since the chances of getting the right hash beginning with the correct number of zeros is very small, on average, anyone who manages to find a hash that fulfills the criteria is likely to have tried many other combinations before stumbling on the correct one. Thus, a hash that fulfills the criteria is proof that the miner has done the work (of trying many different nonces) required to add a block to the blockchain, hence the name proof of work.

The network achieves consensus by recognizing the longest blockchain as the truth since that is the blockchain that has had the most work put into it. The competition of a large network of participants attempting to validate Bitcoin transactions incentivizes miners to stay honest; there is no incentive to help to validate another person’s fraudulent transactions.

Note that the requirements for the computational problem changes over time depending on network activity and the number of miners. The Bitcoin supply schedule is fixed such that one block is mined every ten minutes. Thus, for a given difficulty level (represented by the number of zeros the hash must start with), an increase in miners, representing an increase in overall network computational power, means that a solution will be found more quickly. Therefore the difficulty has to be adjusted according to the total network mining power so that the mining time per block remains at 10 minutes.

5. How exactly does mining work?

A step-by-step visual of the mining process

Honest miners follow the following steps:

  1. Verify that the existing transactions in the blockchain are valid. If a block is not valid, ignore that block and build on the block before that.
  2. Select and group transactions from the mempool, a pool of submitted transactions which are recognized by all users but not yet validated, into a block. Validate each transaction to be added into the block by ensuring that the transactions meet the protocol rules of the Bitcoin network.
  3. Once the miners verify the validity of all the transactions in this block, they go through the proof of work mechanism: 1) choose a value for the nonce in the block header, 2) hash the block header twice using SHA-256 and 3) try to add their block to the blockchain. We will elaborate on the proof of work mechanism in the next question.
  4. If the block header hash satisfies the requirements set by the network, they receive a coinbase transaction as a reward in addition to the transaction fees paid by the senders of the transactions. If they fail or someone else mines the block before them, they return to step 1.

Note that miners do not necessarily have to validate transactions before grouping them into a block and attempting to extend the blockchain. Malicious miners may intentionally create blocks which contain fraudulent transactions which benefit themselves. It is then up to the rest of the Bitcoin network to invalidate these blocks and remove them from consideration.

6. What is a double spend?

In Bitcoin, a double spend is an attack on the network where a given set of UTXOs are spent in more than one transaction. For example, a person may attempt to send the same bitcoin to two different merchants so that he or she may receive two separate products or services for the price of one.

Possible origins of double spending attacks include:

  1. Race attacks — Broadcast two conflicting transactions using the same UTXOs in rapid succession to the Bitcoin network
  2. 51% attack — If an entity possesses a majority of the total computing power of the Bitcoin network, they will have the power over the blocks which are added, and thus which transactions are added, to the blockchain. This means that they can reverse or override existing transactions to recover their bitcoin after spending it on a service or product.

7. How do miners help Bitcoin to prevent double spending?

In reality, double spending is prevented through the efforts of a trusted third party, usually a bank, which keeps track of everyone’s account balances to make sure they can’t spend money they don’t have. However, there are no account balances and no trusted third parties in Bitcoin. Double spending is prevented by the incentive structure put in place by the mining process.

At any one point in time, there are multiple possible versions of the blockchain. Recall that the general rule in proof of work is that the longest blockchain is the truth. To avoid the problem of double spending, nodes, miners, and participants of the Bitcoin network can simply wait for confirmation of the block containing the suspected double spend transaction. One confirmation means that one new block of transactions has been added to the blockchain. Waiting for subsequent blocks to be confirmed help us to ensure the validity of the transactions in a given block.

This is because miners and nodes are collectively incentivized to stay honest. Nodes are incentivized to reject blocks with invalid transactions to maintain network integrity. Miners are then dis-incentivized from building on blocks containing fraudulent transactions, since these blocks might be invalidated by the network, which renders worthless any block rewards they might obtain from mining.

This means that the bad actor who created the fraudulent block will need to extend the blockchain containing that block by themselves. Since the Bitcoin network recognizes only the longest blockchain as the truth, the bad actor will need to be able to successfully mine blocks as quickly as the rest of the network combined. This is prohibitively expensive due to the large amount of computational power in the Bitcoin network.

Thus, the length of blockchains containing invalid transactions is likely to stagnate while blockchains containing only valid transactions continue to grow. By waiting for a few confirmations, one can tell whether a transaction is valid or invalid by checking to see if the block which contains that transaction exists on the recognized (longest) blockchain.

Different people believe in different confirmation period lengths before believing that a transaction is valid. A common rule of thumb is 6 confirmations, or to wait for the blockchain to increment in length by 6 blocks after a given transaction, before accepting a transaction as valid.

Concluding Remarks

In this article, we have explained how mining works and the role it plays in Bitcoin. In the next article, we will explore miscellaneous questions related to the Bitcoin network.

We see this guide as a continuous work-in-progress! Please leave any questions or remarks in the comments section and we will try our best to include them in updated versions of our guide. And if you found our guide useful, please leave some claps!

For more information on Everest, please visit our website.

--

--