An Overview of Bitcoin Mining

2021-04-22

Bitcoin can seem strange at first: after all, how can money come from nothing? How can it be ethereal, living only online without physical form, or without a central authority, company, or government managing its production and use? The answer is the process known as bitcoin mining. In this blog post, I will take you on a short tour of bitcoin mining, how it works, a brief history of development in the space, and some thoughts on the current news surrounding bitcoin mining, as well as some possible future directions the industry might take in the future.

What is Bitcoin Mining?

To understand the process of mining, one must first understand the cryptographic primitive that underlies it. The mining process was adapted from a 2002 paper written by Adam Back called Hashcash. Hashcash, which sounds like it might be a currency in and of itself, was actually proposed as a solution to the problem of email spam. The idea was simple: what if there was some function that was difficult to calculate, but easy to verify? An email server could then send a challenge to anyone who wanted to send an message to their users. An honest user could calculate this function, and return the answer. But a spammer, who would be sending thousands of near worthless messages, would have to calculate this difficult function thousands of times, while the server would easily be able to check to make sure the spammer was putting in the work.

This challenge was created using a concept called a hash function. A hash function accepts an arbitrary input (say, the string "Hello World!", or an email address, or an MP3 file) and returns a fixed length string called a digest. It is important to note that every bit of the hash appears random, even though it is deterministically derived from the input. It is also impossible to take a digest and "reverse" the function to retrieve its input. There is only one way through a hash function.

Hashcash introduced the idea that one can treat this digest as a number: specifically, if you are given some data whose hash digest is below a given threshold, how rare is that hash? Well, because we know that each bit of a hash appears independently random, we can consider each bit as a coin toss. If the hash starts with, say, 30 zeros, we know that this only has a one in a billion (2^30) chance of occuring. If someone were to attempt to find a hash that started with 30 zeros, they would have to try 1 billion times, hashing over and over again before they got lucky. To verify that the hash does indeed start with 30 zeros requires us to only hash the data once. Voila, we can now verify that someone has (on average) put in a billion times more work than we did.

So what does this have to do with bitcoin? Although Hashcash never found widespread use on email servers, Satoshi Nakamoto saw the Hashcash process as a more general "Proof of Work". Specifically, one could trustlessly prove to someone else that work has been done on a specific data set by appending a nonce (a cryptographic term for number used once) to your data set and hashing, repeating the process with a new random nonce until you have a resulting hash below a given target. In bitcoin today, a hash has to start with over 70 zeros, so you can be sure that a lot of work is put into every single bitcoin block!

Why all this Hashing? What Problem are We Solving?

A problem that beguiled cryptographers for decades was called the "double spending problem". If I have some digital cash, and I give it to you, how do you know that I didn't also give that same cash to someone else? In traditional finance, this problem is solved by a bank: whoever the bank says has the money, has the money. But a trusted third party like a bank is something that Satoshi was trying to eliminate with bitcoin. So what can you do? You could tell the world that you have the money, but what if there are conflicting messages? Who gets the money first? It is sort of like cashing bad checks. If a con artist has $100 in his bank account, but writes three $100 checks, who gets the money? Whoever cashes out first. But in a system with no trusted authority, how do you know who was first?

Satoshi solved this problem with Proof of Work. Bitcoin miners listen on the internet for new, valid bitcoin transactions. When they hear one, the append the transaction to a group of new transactions they have heard called a block. They then hash this entire block of transactions repeatedly, using the Hashcash procedure described above until they find a hash with a difficulty below their target. Once they do so, they release this block into the world and start listening for more transactions. In addition, each of these blocks conatins the hash of the most recent block, forming a chain of blocks containing all transactions that have ever occured on the bitcoin network. This is where the term "blockchain" comes from. Finally, users of the bitcoin network only listen for the chain of blocks that contain the most work put into them.

How does this solve the double spend problem? Well, consider what would happen if someone were to try to cheat the system. To spend money that has already been spent in a block would require the attacker to create their own alternative chain of events: a new fork in the blockchain. They might be able to create a few blocks, but it takes a tremendous amount of work. And in the meantime, the rest of the bitcoin network would have produced even more blocks that makes the honest chain longer. Eventually, unless you have close to 50% of the total computing power of the network, you will be overwhelmed, and the honest chain will win. In a distributed system like bitcoin, it is better to play by the rules and come to consensus than to cheat the system.

Why Would a Miner put in all this Work to Make a Block?

The genius of the Bitcoin system relies on its incentive structures. Specifically, in the case of mining, new blocks are rewarded with new bitcoins that have been created by the network, along with any transaction fees for all the transactions packaged in the block. Each block currently rewards the miner ₿6.25, but this halves every 210,000 blocks (about 4 years) until eventually only transaction fees will incentivize mining. This repeated halving is what ensures that there will only ever be 21 million bitcoin, with the last satoshis (the smallest unit in Bitcoin, or ₿0.00000001) being mined sometime in 2140.

So Can I Start Mining Bitcoin Right Now?

The short answer: probably not. When bitcoin began, it was trivial to fire up the software on your laptop and mine some blocks in an afternoon. As bitcoin became more valuable though, there began an arms race. The other part of mining that I have glossed over until now is how the difficulty of finding a block is decided. The bitcoin network automatically adjusts the difficulty every 2016 blocks (about 2 weeks) such that it takes about 10 minutes for a new block to appear on the network. If more miners come online, and blocks arrive quicker than 10 minutes, then the difficulty goes up and blocks quiet back down to 10 minutes (on average). If miners go offline, blocks arrive slower, and difficulty automatically decreases.

As more miners saw bitcoin as valuable in the early days, clever miners wrote software to allow mining to run on GPUs that were thousands of times faster than any CPU could hope to be. Then GPUs gave way to more specialized technologies, leading eventually to ASICs. Application Specific Integrated Chips (ASICs) are purpose built computers made for mining. They do only one thing, but they do it very well. Each of these new technologies increased the difficulty of finding a new bitcoin block as thousands of miners competed each day for the chance to mine a block.

Perhaps more noteworthy than the increases in power was the innovation of mining pools, such that small individual miners who might never mine a block on their own could pool their hashrate and share in the spoils should the pool find a block. Pooled mining is now the standard across bitcoin today.

What is Happening with Mining Today?

Today, mining is globally distributed and robust. Companies like Great American Mining or Upstream Data take on projects like reducing harmful flare gas from natural gas wells and using the energy to power their bitcoin miners. The state of Kentucky now provides tax incentives to bitcoin miners. Although hardware efficiency improvements have slowed, software improvements have made mining even more competitive, but robust to network conditions. And whatever is happening in the world, bitcoin keeps ticking.

Of note is the recent coal mining accident in the Xinjiang province of China. When large parts of their electrical grid were damaged, a large percentage of bitcoin's mining power was taken offline. Despite this temporary drop in mining power, bitcoin continues to produce blocks and order transactions. It goes to show that bitcoin's mining process is still not as distributed as it needs to be, but the trend across the industry shows mining continuing to develop in places with better infrastructure, or even in places tranditional electrical grids cannot support. Overall, bitcoin's incentives ensure that anywhere in the world can be used as a suitable location for mining, and will ensure that local events have little to no impact on the global health of the network as bitcoin continues to grow.

What Does the Future of Bitcoin Mining Look Like?

I believe that mining will continue to spread across the world and deepen its connection with existing energy infrastructure. The most promising future for mining I see is as an incentive to load balance new smart energy grids, acting as a needed capacitor to absorb excess capacity. This is especially important in a future with renewable energy resources that have unpredictable outputs. Already, there exist proposals for using bitcoin mining as a virtual battery to stabilize demand in places like Texas that have large reserves of wind power. In many places across Europe, negatively priced energy from renewable sources need an energy sink, and bitcoin can not only consume excess energy, but also stabilize demand across time, making large scale renewable projects economically viable and indeed beneficial to existing energy grids.

Conclusion

Bitcoin mining is a process akin to digital alchemy: turning energy into gold. It is perhaps unintuitive, but I hope you now understand it just a little bit better.