What Is Bitcoin Mining?
I have many fond memories of my college days, but as far as computer memories go, I used to love watching my computer process data from space hoping to be the one who discovered an alien transmission. I watched the colorful charts flash across my screen hoping to see a pattern in all that noise. SETI@home was an amazing idea to me. The concept of getting computers from all over the world to combine their power into one large data processing unit working together towards a common goal simply astounded me. Since then there have been several advances in distributed computing, all looking for answers to something. Then, along comes Bitcoin.
One of the very first things that fascinated me about Bitcoin was the idea that I could set my computer to the task of minting money. Who doesn’t want free money, even if it is “Magic Internet Money”. Well, that’s what I heard, anyway. Nobody just goes on the Internet and lies, so that had to be true, right? As with many rumors, there is a nugget of truth to it but it misses the mark by quite a span. I’d like to take a deeper look at what exactly Bitcoin mining is, why it’s done, and the idea of minting digital money.
On a very basic level, Bitcoin mining is the process of verifying recent transactions and receiving new Bitcoin as a reward. So the rumor above is true, to a certain degree. The difference is that you, or your computer, rather, needs to do work. And not only does it need to do work, it needs to provide proof of that work. What kind of work is required? Here’s the part where I hit you with the difficult description, but you should know by now that I’ll explain it later.
Bitcoin mining is the process of verifying recent transactions, bundling them into a block, inserting the hash of the previous block, adding a nonce, comparing the resulting hash to a target value, repeatedly hashing with a new nonce until creating a hash that is below the set target value, providing proof of work, having it verified, and then writing the new block to the Blockchain. Once the new block is written Bitcoin nodes broadcast the block to other Bitcoin nodes confirming the new block. The Bitcoin miner that solves the problem and writes the new block is then rewarded with new Bitcoin called the Block Reward.
Have I lost you yet? No worries. We’re going to look at each piece and sort it out.
If you’ve gone through my Tutorials you’ve already learned the process of sending and receiving Bitcoin. All those transactions must be verified and written down or the coin doesn’t actually change ownership. Send and receive transactions are put into a queue to be processed. But that queue is not first come first served. Think of the queue as more of a pile of items in a bin, all nicely tagged, ready to be processed. Miners select from the bin recent transactions that need to be verified and recorded. Once a group of transactions are selected they are bundled into a block. But the block has to be verified before it can be written. This is where hashing comes in. To explain this I’m going to have to kind of go a bit backwards, so bear with me for a minute.
I’ve mentioned how mining is basically solving a really hard math problem. That problem is considered solved when a block is processed according to the rules. The answer is a really long string of seemingly random letters and numbers. But that string of letters and numbers isn’t random at all. It is actually all the transaction data from the block currently being verified, plus two variables I’ll get to in a moment, encoded into one long string called a hash. Changing even a single character of the included data would alter the resulting encoded string, thus changing the hash. The hash, being encoded, is much shorter than all the data contained within, making it much easier to store. But it has another use, which I will get to next.
One of the two additional variables I just mentioned is the completed hash of the previous block. It is added it to the transaction data of the current block, along with one other variable I’ll get to next, and then itself hashed. Since the completed hash of the previous block is added to the data of the current block which is then hashed, the current block is dependant on the previous block. Changing even a single character of the data in a block creates a completely different hash. So changing even a single character in a previous block would invalidate every block after it. This creates a chain of blocks that can’t be broken or all the subsequent blocks would be incorrect, thus the name Blockchain. The Blockchain is an encoded list of every Bitcoin transaction ever made since the Bitcoin protocol was turned on in 01/2009.
The second of the two additional variables I mentioned is called a nonce. It’s a 32-bit string of characters added to the data that will, if correct, create a hash with a specific number of zeroes in a run at the start of the hash. The number of zeroes required is set by the network and changes on a regular basis. It is what is known as the Network Difficulty and it is based on the hashing power of all the miners currently working on the problem. The more hashing power, the more zeroes required. The more zeroes required, the harder the problem. Because there is no way to know which nonce will produce a hash below the set difficulty, miners hash the transaction data in the proposed block, plus the hash of the previous block, plus a randomly chosen nonce over and over trying to find a hash below the target value set by the Network Difficulty. Any hashes produced that do not have a value below the target value will be declined. When a nonce is found that creates a hash below the target value the block is considered hashed correctly.
When the correct nonce is found the block is verified by Bitcoin nodes and then written to the Blockchain. Bitcoin nodes are a network of computers that record and store copies of the Blockchain. The hash of the block that was just verified is then added to the next block of transactions and miners start hashing again. In the meantime, however, the miner who discovered the block is given a reward called the Block Reward. This is how new Bitcoin are created and introduced to the network.
So, now that you have a better understanding of the terms used, read the difficult description I wrote above in a more succinct description of mining and see if it makes more sense:
The header of the most recent verified block is combined with the transaction data of the current proposed block. A random nonce is then added to the data and it is all hashed. The resulting hash is then compared to a target value which is set by the network difficulty. If the hash does not compute lower than the target value it is ignored by the network and the miner tries again with a new nonce. If the hash does compute lower than the target value the block is then verified by Bitcoin nodes, written to the Blockchain, and the miner is issued the block reward.
There are some really neat things to note about this process.
It is extremely difficult to find the nonce that correctly creates a hash, but it is not difficult at all to verify the nonce once it is discovered. It was done this way on purpose. The problem itself is supposed to be the difficult part, that way miners have to provide a proof of work in order to get the reward. But it is very easy for Bitcoin nodes to verify the answer so as not to have to reproduce the work done to find the nonce. That way the network can propagate the verified blocks quickly to all the Bitcoin nodes all across the network.
The difficulty of finding the correct nonce adjusts automatically on a set schedule. Every 2,016 blocks the difficulty is reevaluated. By design, blocks are supposed to be discovered, on average, every 10 minutes. This means that the difficulty is reevaluated every 20,160 minutes, or 336 hours, or roughly every 2 weeks. If the blocks are being found too quickly that means more hashing power has been added and the network raises the difficulty. If blocks aren’t being found quickly enough that means hashing power has been removed and the network lowers the difficulty.
Because blocks are found on average every 10 minutes this means the reward is released into the network on a more or less set schedule. Again, this was by design so that not all the Bitcoin were created at the start. Had all the Bitcoin been created right away they’d all be owned right now and the experiment would have failed. Bitcoin needed to be created very quickly early on so that people could get involved cheaply and quickly, but as time goes on the inflation of the supply will slow and Bitcoin will become a deflationary currency.
On a related note, the Block Reward will reduce at set times on a known schedule until it eventually goes to zero. Every 210,000 blocks the Block Reward is cut in half. In 01/2009, when Bitcoin started, the Block Reward was 50 Bitcoin. In 11/2013 the Block Reward was cut in half to 25 Bitcoin. It is estimated that in 07/2016 the Block Reward will again cut in half to 12.5 Bitcoin. I say estimated because we know the set number of the block that will next be halved, block number 420,000, but because of the average and the shifting difficulty involved it may take more or less time to get to that block.
And, the thing I love most, all these rules are set in the code. These rules can be changed by anyone because the project is open source. You are free to download the source code and change whatever you like. You could make the mining difficulty easier, set the supply of Bitcoin to 2,621,984,228,675,650,147,435,579,309,984,228, or even assign them all to a wallet you control. But here’s the key: if you change any of the rules for your version or change any of the data in your copy of the Blockchain and nobody else changes the rules or data in their version, any blocks you produce will not be recognized by the rest of the network. This is called consensus. Only if you play by the agreed upon rules of the majority will you be able to participate. But, if you get enough people to change the rules to agree with you, your version could become the new defacto Bitcoin chain.
So, if you’re like me, now you want to know how you can get in on the action. You want to know where you can get the software to run on your computer to start mining and cash in on the Bitcoin phenomenon. Bitcoin mining was an itch I simply had to scratch. We will discuss that in my next Article titled “Should I Start Mining Bitcoin?”