What’s the deal with bitcoin mining?

Please read before continuing: Technical Explanation of Bitcoin, Blockchain

If the blockchain is the ultimate authority on bitcoin ownership, we better make sure that it’s accurate.

axe.png

Bitcoin “mining” is a somewhat misleading term, just like the term bitcoin “wallet”. Our preconceived ideas about what these words mean can create a lot of confusion when trying to understand how certain concepts work in the context of bitcoin.

So let’s start from scratch.

Bitcoin “mining” is just the process of determining what block goes next in the chain.

The blockchain has a lot of power. If the blockchain is what everyone in the network looks to as the correct version of the list, it better be valid and it needs to be trustworthy.

exchangenet.png

In a traditional banking system, we look to the bank to tell us the correct version of balances.

We put our trust in the bank to keep an accurate record of all transactions. So how could this possibly work in a system like bitcoin, which doesn’t have a middleman we can trust?

Well, we just need everyone to agree on the list. We need consensus.

Since millions of people are sending around transactions and proposed edits to the list, we need a way to unify the network. We need a single version of the list we can look to and deem it as the one valid list. As we’ve already discussed, this version of the list is called the blockchain.

How does bitcoin decide which version of the list gets to be the blockchain? The network decides on this by following a single rule: the chain with the most number of blocks is the valid chain.

longest.png

So there can be multiple blockchains?

Remember, a block is just a group of transactions and a blockchain is just a group of blocks. Anyone is free to collect certain transactions and group them together in a block, but if their blockchain is not the one with the most blocks… the rest of the network isn’t going to care what their list of transactions looks like. They only care about the chain with the most number of blocks.


As you can tell, adding blocks to the chain must be an important process.

We mentioned that mining is the process of adding blocks to a chain, but how exactly does it work?

Think of mining like a network-wide guessing game.

minenonceguessnode.png

The winner of the game gets to add the next block and choose which transactions are included in it. They “mined” a block! Dave won the game, so he gathers transactions that he sees people want added to the chain.. then puts them in his block.

minenonceguessnoderight2new.png

There are a several things to note that will help us understand why this guessing game is so special, and why it’s an excellent way to get the network to agree on which chain is the blockchain.

  1. The winner of the game is rewarded with bitcoin! This creates an incentive for people in the network to play the game.

  2. Guesses are not cheap. Each guess is created by a special computer, which means you need to spend a lot money to buy one of these computers.. and then also pay for the electricity it takes to run it.

  3. Each possible version of the blockchain has its own guessing game, which is playing to choose that specific version’s next block.

  4. The more people playing a specific version of the game, the faster blocks will be created. It is easier for 100 people to guess the random number than it is for 1 person to do it alone. Also because blocks are being created faster in the most popular game, this game will make a longer chain than the others.

So this game is expensive to play, but the winner earns a valuable prize. It also incentivizes everyone in the network to play the game on the longest blockchain. If they start playing the game on a different chain, they are wasting money trying to earn a prize that will not be valid. Again… because it won’t be longest chain.

Since everyone is incentivized to play the same game, we are creating agreement between all participants of the network! Maybe without even realizing it, everyone is working together towards building a single version of the list.

This process is what makes bitcoin so resilient and resistant to bad actors. It solves the “double-spend” problem.

The “double-spend” problem is what bitcoin is praised for having found a solution to. But what is the double-spend problem you might ask?

dpa.png

Here you can see Bob has just paid Dave 7 bitcoin. Somebody won the guessing game and added this transaction into the next block in the chain. Since the blockchain is the definitive version of the transaction list, Dave sees the payment and accepts it as final. Unfortunately, Bob is up to no good.

dpa3.png.png

Here we can see that Bob will try to reverse his payment to Dave, by instead paying his 7 BTC to Alice. He is attempting a double-spend attack, he wants to spend the same bitcoin twice. Bob has to go back in time to change the block that was already added to the chain… which included his payment to Dave. Then all he has to do is win enough guessing games to make a new “longest blockchain”. At that point, everyone will switch over to Bob’s new version and consider that one valid. Dave will have lost his 7 bitcoin!

But notice that Bob is at a severe disadvantage. He is only one person and has two guessing games to play to catch up with the rest of the network. Alice, Charlie, Dave and Erin are playing the same game together, and they already have a lead.

dpa4.png

Bob quickly falls behind. It’s just too difficult to compete with the rest of the network when they are all working together. The blockchain remains secure and Bob finally gives up his attack.

There is certainly much more behind bitcoin mining and how it exactly works.. but we’ll save that for another lesson.

Bitcoin mining is the process of adding new blocks to the blockchain. When a block is “mined”, the winner of the game receives bitcoin as a reward. All participants in the network are working together to keep the longest chain safe and unchanged.

Visit more lessons!