Yesterday I called my friend and as we caught up the topic of cryptocurrency came up. He had bought some Dogecoin and Etherium after the recent headlines about them, and felt some FOMO (or, felt that he’d actually missed out) about Bitcoin. A few years ago, when a Bitcoin cost $100, a mutual friend of ours had told him to buy some. If he had, he’d have 100x’ed his investment by now.
I started explaining the recent controversy around the environmental impact of Bitcoin, and he asked how exactly Bitcoin worked and what mining really was. I’ve been meaning to start a blog explaining Computer Science topics for lay people - my dream is to write something as lucid and engaging as Planet Money is about economics - and I figured Bitcoin might be a good place to start.
This blog post is for you if you follow tech and have a basic understanding of how computers work - you know how binary is used, and what CPUs and RAM and hard drives are. Maybe you’ve programmed a few times or debugged some of the configuration of your operating system. But if you’ve majored in computer science, you program for a living, or you’re Satoshi Nakamoto (the creator of Bitcoin, whose real identity is still a secret) and just haven’t told anyone yet, you might find this blog post a bit too simple.
Also, although I have some pretty strong opinions about crypto’s role in the economy that might seep out through this blog post, I don’t want to talk about that. After reading this, I hope you’ll understand a bit more about why cryptocurrency is such a cool technology, and about why so many people are skeptical that you’ll ever pay for your coffee with Bitcoins.
Bitcoin is an interesting technology because it’s designed to solve a trust problem instead of a purely technical problem, and because it solves that problem by being inefficient. Instead of sending money as cheaply as possible, it’s intentionally slow and expensive so that we can make sure we don’t need to trust anyone to believe in the system as a whole.
Let’s back up. Bitcoin is designed to be a way to keep track of and transfer money. Money is about exchanging value. In order for money to work, everyone has to agree on how much of it there is and on what counts as money and what doesn’t. We all agree that monopoly money has very little value for anything other than buying Park Place, and that a dollar can buy you a can of Coke. We try to make sure nobody can make fake dollars as well, and as long as that’s rare, most of us don’t worry about giving and receiving dollar bills for all kinds of purposes. This is kind of an “if it looks like a duck and quacks like a duck, it is a duck” approach to money, and it’s worked pretty well for thousands of years.
The problem with Internet money is that it’s all just numbers written on a hard drive somewhere, so if someone says they’ll give you $5 if you send them that collectible baseball card on eBay, you can’t just believe them. You need someone that everyone trusts to keep track of how much money people have. Usually, that someone is a bank. A bank says “Tim has $100,” and when I send you $5 for the baseball card on Paypal, Paypal asks the bank if I have enough money and then takes that money away. There’s a lot of regulation around how banks operate to make sure they don’t mess this up - if I could spend $500 when I only have $100, the whole financial system would collapse. So, implicitly, when you trust the bank, you’re trusting the government to regulate that bank and make sure it’s not making up money too.
Bitcoin’s goal is to make it so you don’t have to trust the bank or the government - this is called “decentralization.” Let’s not think too hard right now about why Bitcoin’s inventor and maintainers wanted this - they probably don’t want banks, or the government, or both to have as much power as they do. A lot of new software technologies are exciting because they make things that used to require centralized power no longer need that centralized power, and Bitcoin is no exception.
Bitcoin needs to figure out a way for a lot of people to agree on how much money other people have without trusting one person or group of people to just tell everyone else the answer. Getting anyone to agree on anything on the Internet is hard, and it’s especially hard for things that have a lot of value. If we can’t agree whether a dress is blue or white and gold, we definitely can’t agree on whether I’m allowed to spend $500 or only $100.
Luckily, we should all agree on some basic rules about how money works, and if we all follow those rules and make sure everyone else is following the rules then we can keep track of money together. To give some basic examples of rules we agree on: if I have 1 Bitcoin in my wallet (a Bitcoin bank account, basically), I can spend 1 Bitcoin, and when I spend 1 Bitcoin, I should have 0 Bitcoins left. Now, in order to make sure I’m following the rules, I need to tell everyone when I spend Bitcoin so they can double check that I don’t try to spend my Bitcoin twice. And that’s what we do in the Bitcoin network - everyone tells everyone else every time they send money to anyone.
Yes, this means that everyone can see at all times how much money everyone else has, and can see who is sending who else money too.
The Bitcoin network is just a collection of computers that all know how much money everyone has and agree on it.
So far, the Bitcoin network just looks just like a bank, except all the transactions are public. A bank also has a list of how much money everyone has and every transaction they’ve ever done. This allows them to audit themselves to make sure that when you deposit $20, you don’t end up with $21 in your account.
So this introduces us to the big problem that Bitcoin presents a unique solution to: How do we make sure there aren’t disagreements about what happened? What if someone comes into the network and starts lying about the transactions they’ve seen? What if they start telling everyone they have 5 Bitcoins when no one ever gave them 5 Bitcoins? How do we decide that they’re wrong and everyone else is right?
Satoshi Nakamoti had two key insights that helped him solve this problem:
If there’s some sort of voting on what transactions are valid, you can make sure that only valid transactions go through
If one of the rules of the monetary system is that people get paid for voting according to the rules, then people will vote according to the rules
These are the key innovations of Bitcoin. Let’s break them down.
First, insight one: voting.
Most people participating in Bitcoin are just sending or receiving money, but some people are “mining” Bitcoin. Bitcoin “miners” verify all the past transactions, and they’re the ones who follow and enforce Bitcoin’s rules. There are clear rules on how to determine what is valid and what isn’t (this gets into other areas of computer science around distributed systems that aren’t worth going into right now). Every once in a while, one of these miners gets to create a new block of verified transactions, which everyone else can check to make sure it’s valid. If they agree, they can start verifying transactions on top of the last block and make their own block. These are all added to a long “chain” of blocks that represents the full history of all transactions over all time. Hence, the word “Blockchain.”
How do you make sure that the Blockchain is valid? The miners vote with their feet. If they agree with a new block on the chain, they start building on top of it. If they don’t, they ignore it. If there’s a chain of blocks that’s longest, that’s the one most people agree on.
Keep in mind: this isn’t voting for President. Voters aren’t supposed to think about whether they like Biden or Trump more when they decide who gets Bitcoins and who doesn’t. They’re just supposed to follow the rules. So, ideally, everyone should vote the same way every time. It should have an even more predictable outcome than a North Korean election.
Now comes another hard part. How do you decide who gets to be a miner and vote by creating blocks? How do you prevent one bad actor from spitting out lots of bad blocks? If people were voting, you’d pick something like what democracies do - giving everyone 1 vote per person. But Bitcoin doesn’t want to have a central record of who each person is. Instead, Bitcoin could hand out votes per computer, but again, how do you know that each computer is unique? How do you prevent one computer from getting two votes?
Bitcoin’s solution is called “proof of work” - that is, I prove that I’m a computer that can vote by crunching numbers. Since computers are machines that can crunch numbers really quickly, the more numbers you crunch, the more computers you have, and the more votes you have. Obviously, faster computers get more votes, and from Bitcoin’s point of view, that’s just fine.
It’s not super important to know much about the math itself, except that there’s a random number attached to each block and you’re basically trying to find the password that matches that random number. Everyone can see the random number, but no one knows what the inputs are that will generate that number. So, out of hundreds of quintillions of possibilities, each voter guesses a bunch of numbers until it finds the right one. The first one to publish the secret password gets to validate the block with that secret password, and everyone else will see that the password works and move on to generating the next block in the chain.
Now, insight two: paying people to vote according to the rules
Okay, cool, so everyone goes around voting by doing some math to see if they can guess the secret password. But if I own a computer, why would I want to do that? Out of the goodness of my heart? I have to suck up electricity and tie up my computing resources on this busywork just to make sure someone can spend a Bitcoin to buy a pizza. Why should I care?
This is the part that we call “mining.” Everyone who does this math has a chance to get Bitcoins. Every 10 minutes, if you guess the secret password, you get to insert a transaction in the block that says “oh by the way I get a small amount of Bitcoins right now.” That Bitcoin doesn’t come from anyone else - you get to just make it out of thin air. You get to act as a mini federal reserve for the moment. That’s one of the rules everyone agrees on - whoever wins this lottery and validates the Blockchain correctly gets a little Bitcoin. (As of today, you get 6.25 Bitcoins for mining a block - about $100,000, not counting transaction fees, which we will discuss later.)
Voila! Suddenly everyone in the world wants to spend lots of money on computers specially designed to vote on Bitcoin.
But Bitcoin was also designed to give out less and less Bitcoin to miners over time so there wouldn’t be an infinite supply of Bitcoins. What if the reward gets so small that miners stop mining? Or, what if there are too many transactions to verify? Each block only has so many slots for transactions - what do you do if your transaction doesn’t fit in the blocks as they come in.
When that happens, you’ll need to bribe the voters to accept your transaction. When you send out your transaction, you can add a little tip for whichever miner puts your transaction in their block. As of today, you have to pay about $5 to make sure your transaction gets put onto the Blockchain. You know the old saying - you have to spend money to spend money! (In practice, if you buy Bitcoin from Robinhood or Square Cash, you probably don’t pay the transaction fee because you actually don’t have your own Bitcoin wallet - Robinhood or Square just says “you stake a claim in our big pile of Bitcoins that we’re holding for you” and you just have to trust them, and the government regulation that covers them. Hmm… sounds familiar… kind of like the traditional money system!)
So that’s the basics of how Bitcoin - and all cryptocurrencies - maintain their value. They have some encoded rules, and people get paid to enforce those rules by voting with their computing power.
All of this means there’s a massive race to the bottom to basically turn electricity into Bitcoin. And they’re not even doing useful work, like calculating how much money everyone has. They’re just guessing random numbers until they find the secret password so they can get Bitcoin. Every Bitcoin transaction is trivial on its own, but everyone racing to vote on whether it’s valid uses a ton of energy.
Next time, I’ll talk more about how Ethereum, the second biggest cryptocurrency, plans to solve this problem.