A Tweetstorm Series featuring Yan Pritzker, Author of "Inventing Bitcoin".
As part of an on-going Tweetstorm Series, we showcase excellent Twitter threads on the most interesting topics in the industry and publish them here on Decentralize.Today.
Today's topic is Bitcoin Mining.
Bitcoin mining is easily the most important component of the Bitcoin protocol, as its job is to secure the integrity of the network and all the transactions within, yet it remains one of the hardest things to explain to the average Joe or Jane. Nevertheless, it has become a multi-billion dollar annual industry in just the last three years, with large chip manufacturers like Samsung developing state-of-the-art hardware for more efficient mining of the digital currency.
"Bitcoin Mining Explained. There is lots not covered here, but shooting for an intro rather than deep dive." — Yan
Bitcoin is a ledger of accounts where thousands of people have a copy. In order to ensure consistency of the ledger, only one person can write to the ledger at a time.
To ensure only one write, we implement a lottery system. The lottery will allow the winner to write to the ledger. It will also reward the winner with newly created Bitcoin. This is how we make Bitcoin distribution "fair".
A lottery system needs tickets, but we can't trust anyone to sell tickets. Instead, players must burn energy to buy the tickets. Each ticket costs a certain amount of electricity. Electricity costs money because of 1st law of thermodynamics.
Each ticket consists of a run of a "hashing algorithm." This is a piece of code that takes data and creates a fingerprint of that data. The number of possible fingerprints is roughly 2²⁵⁶, or about the number of atoms in the universe. We can visualize it as a number line.
To generate a ticket, you take the payments that everyone wants to make (the transactions), you add a random number, and you produce this "hash". The hash is a number between 0 and the number of atoms in the universe and lands somewhere on this number line.
Ahead of time, everyone has agreed that in order to win, you have to find a hash that's under a specific Target Number. Let's say that number is 100,000,000,000. That means every time you roll your random generator, you have to land in a tiny space on this number line to win.
Most of the time, you miss. Roughly once every 10 minutes somewhere in the world, someone hits a number that's lower than the Target Number and wins the Block Reward of newly minted Bitcoin. In order to win, they present to the network all the data they used to get the hash.
Since the chances of hitting that tiny space are very very small, by proving that they generated such a number, they are proving that they've done the work of burning a certain amount of energy.
But if more people start mining, doesn't that increase the chances that we'd find a winning number more frequently? Yes! So, every 2016 blocks, every node checks for how often blocks have been coming and adjust the Target Number proportionally.
If blocks came too fast, the Target is decreased, making it less likely to hit the Target, meaning you have to spend more energy to find a winning combination.
And if blocks are coming too slowly, because too few miners are active, then we can increase the Target, making it more likely that you'd hit the Target with fewer rolls of the die, and thus more profitable. This will attract more miners.
The data that produces the hash consists basically of the transactions we want to write to the ledger, the hash of the prior block, and a random number. This connects every found block to the prior block, ensuring a consistent chain of history.
A large amount of energy goes into mining each block, and the block's hash acts as a fingerprint on the data that's in the block. If someone wants to modify an old record in the Bitcoin ledger, they have to re-mine that block by producing a new hash. This is very expensive!
If they try to tamper with an old block, that block's hash will change. But because every subsequent block used that block's hash as part of its hash, then every subsequent block will change too. That means you have to re-mine the entire chain from the point of tampering.
This makes it extremely expensive to change the Bitcoin ledger. You would have to spend as much energy as the entire honest mining network.
Fin. If you found this insightful, I would appreciate a retweet of the first tweet in this thread. - Yan