Whenever I introduce new people to Bitcoin I tend to get asked quite a few questions about mining. What is it? Can anyone mine Bitcoin? What do I have to do to get started mining? Etc. In the next couple blog posts I’m going to answer these questions and hopefully give a fairly comprehensive intro to Bitcoin mining. Even if you don’t plan on mining yourself, chances are you’ll still come away with a good understand of what makes Bitcoin tick. So stay tuned!
What The Heck Is Mining Anyway?
I think part of the problem we have when introducing people to Bitcoin is that we have all these confusing words that don’t accurately describe what’s going on. “Mining” is one of them. Bitcoin mining is essentially transaction validation. When transactions are broadcast to the peer to peer network, someone (or some computer) needs to verify that the transaction is valid and record it the public transaction database (the blockchain). That is essentially what “miners” do ― process and verify transactions and record them in the blockchain. They are rewarded for their efforts with newly created bitcoins (more on this in a little bit), which explains the origins of the term “mining”.
The process of verifying transactions is actually very easy to do. It only takes a computer a fraction of a second. Adding new transactions to the blockchain, however, is intentionally designed to be much more difficult. I’ve gone into much more detail on the reasons for this in past blog posts. To recap, trying to get millions of Bitcoin uses around the world to agree on a single version of the transaction database is no easy task. In fact, it’s a bit of miracle that it happens at all. The secret here is something called “proof of work”. The Bitcoin protocol requires that those wishing to add additional blocks of transactions to the blockchain provide proof that they expended a scare resource, in this case processing power. In this sense miners sort of “vote” with their processing power. But since there is a very real opportunity cost to expending processing power, miners will only want to “vote” for the transaction history which is supported by the majority of other miners. To vote for an alternative transaction history is to waste the processing power and risk losing reward. It’s this opportunity cost that ends up driving the network towards a consensus in regards to the transaction history.
The “work” part here consists of running the block header including a random nonce through a cryptographic hash function (SHA-256 to be exact) and checking to see if the function’s output meets the requirements set forth by the protocol. In this case the output needs to be less than a certain difficulty target. To put it another way, the output needs to start with a minimum number of zeros. For example:
If the output does not meet the difficulty requirement, the nonce is incremented and header is run through the function again. This is done over and over until one miner in the network finds a nonce that produces a valid output. Consider the following example: Suppose we want to find a nonce such that when concatenated with “Hello, world!” produces a hash output that starts with at least three zeros. We would start with a nonce of zero and keep incrementing until we get the output we’re looking for.
"Hello, world!0" => 1312af178c253f84028d480a6adc1e25e81caa44c749ec81976192e2ec934c64 "Hello, world!1" => e9afc424b79e4f6ab42d99c81156d3a17228d6e1eef4139be78e948a9332a7d8 "Hello, world!2" => ae37343a357a8297591625e7134cbea22f5928be8ca2a32aa475cf05fd4266b7 ... "Hello, world!4248" => 6e110d98b388e77e9c6f042ac6b497cec46660deef75a55ebc7cfdf65cc0b965 "Hello, world!4249" => c004190b822f1669cac8dc37e761cb73652e7832fb814565702245cf26ebb9e6 "Hello, world!4250" => 0000c3af42fc31103f1fdc0151fa747ff87349a4714df7cc52ea464e12dcd4e9
In this example it took 4,251 tries to produce an output hash that starts with at least three zeros. This is basically how the proof of work in bitcoin works. Miners run the block header through the (double) SHA-256 hash function over and over, incrementing the nonce each attempt in hopes of producing a hash output that meets the difficult target. The difficulty is automatically re-calibrated by the protocol every two weeks to target to target a block interval of 10 minutes. That is, since the output of the hash function is random, it should take an average of 10 minutes for one miner in the network to solve the proof of work for any given block of transactions.
The miner who finds the valid block earns the block reward ― currently set at 25 bitcoins. The protocol halves the reward every four years according to the following schedule:
Megahashes, Gigahashes, and Terrahashes
Because the rate with which bitcoins are rewarded is regulated by the protocol, Bitcoin mining is essentially a zero-sum game. That is, more total processing power in the network does not generate more total bitcoins, it only reduces the reward per unit of processing power. This means that the faster you can perform the SHA-256 calculations, the greater percentage of the total block reward you will earn. We typically measure the speed of a mining rig in terms of the number of hash operations it can perform per second (h/s).
Back in the old days, circa 2009, Bitcoin was a Windows only software and most mining was done right on your CPU using the GUI. Fairly quickly people figured out that GPUs (graphics processing units) were more efficient at calculating hashes than CPUs. Those who switched to mining on GPUs saw their bitcoin earnings increase at the expense of those who stuck with CPUs. And thus a mining arms race was born that continues to this day.
After a brief period of FPGA mining, the first ASICs (application-specific integrated circuits) hit the market in early 2013. An ASIC is a custom built computer chip designed to do nothing but perform double SHA-256 calculations very fast. As more and more ASICs were brought online, the total hashrate in the network skyrocketed driving non-ASIC miners out of the market in the process.
Today the total hash rate in the network is around 83 petahashes/sec. That’s 83,000,000,000,000,000 hash operations per second. Way more than top 500 supercomputers in the world can do combined.
Back in the early days all miners looked for blocks individually. Given that blocks are only created on average every ten minutes miners would frequently go days if not weeks without mining a block. When a block was found, the payoff would be fairly large (50 bitcoins originally, now 25), but the variance in returns was extremely high. The solution to the variance problem came in the form of pooled mining. Basically, miners would pool their resources together to find blocks faster and split the rewards according to how much work each miner contributed.
The technicalities work like this ― in addition to looking for valid blocks, miners also look for “shares”. The difficulty for finding a share is usually set by the pool operator well below the difficulty for finding a block.
For example, a valid block may need to start with 14 zeros, say. Whereas a valid share needs only 5, say.
Since the difficulty is much lower for shares, miners will find these much more frequently. Each share is submitted to the pool operator and when a block is found the reward is paid out to miners in proportion to the number of shares they submit.
Of course, pooled mining is not without significant controversy. As I already mentioned, in the early days miners looked for blocks individually. They maintained their own copy of the blockchain, and retained control of which transactions they include in blocks. With pooled mining, miners are essentially delegating those responsibilities to the pool operator. Today most miners don’t even have a copy of the blockchain nor do they have any control over which transactions make it into their blocks. This not only creates a worrisome degree of centralization but it gives pool operators an inordinate amount of power. For example, a pool operator controlling 30% of the network mining power can double spend his own transactions with a 30% success rate. Want to tilt the odds of a gambling site in your favor? That’s how you do it. Worse, if that pool operator colluded with another pool operated with, say, just over 20% hashing power, the two could double spend transactions with 100% success, among other things. Here’s the current hashrate distribution:
The saving grace is the fact that pool operators do not actually own or control the physical hardware. So the thinking is should a pool operator(s) turn malicious, miners would quickly abandon the pool limiting the damage. It seems every few months a mining pool gets close to 50% of the hashrate and the bitcoin community panics and directs their wrath at the pool operator. Public enemy number one these days is GHash.io. The cycle looks something like this:
Developers have created several tools to address the problem of mining centralization. First is the getblocktemplate mining protocol which allows miners to retain control over the blocks they create. Unfortunately miners and mining pools have shunned it in favor of the centralized stratum mining protocol. There is work planned for a getblocktemplate 2.0 which would be even more decentralized, but it remains to be seen whether miners will actually adopt it.
There’s also P2Pool, a peer-to-peer mining pool that was developed with grant money from the Bitcoin Foundation. Yet, it only manages a meager 1% of the network hashrate, likely because it’s much more complex than stratum. If you plan on mining bitcoin, you really should do the network a favor and at minimum pick a pool with a lesser hashrate or better yet use P2Pool.
I can speak for myself, I have a couple 330 Mh/s USB miners. The total miner power is negligible and cost far more to operate than they would ever generate mining. So every now and then when I leave the house I turn them on solo mining for the off chance they will mine a 25 BTC block. It’s kind of like playing the lottery. The odds certainly aren’t in your favor, but you can’t win if you don’t play. And it supports the network, so in that sense it’s worth it.
What do I need to start mining?
You’ll need to get an ASIC for one. Unfortunately it isn’t very easy to get one, at least not within a reasonable time frame. ASIC manufacturers are notorious for long production delays. Given that the mining difficulty has been increasing at a fast pace, it’s critical to get your hardware mining as soon as possible. The longer it takes for the hardware to be fabricated and delivered to you, the more money you are losing. What’s worse is manufactures tend to prioritize orders from large mining firms that purchase hardware in bunk. This puts individuals with limited resources at a competitive disadvantage.
If you do acquire an ASIC you’ll also need to install some software. BFGMiner and CGMiner are two of the most popular. Both are command line only and will likely be difficult to use for people who are not tech savvy. Butterfly Labs has a GUI wrapper (EasyMiner) for both CG and BFGMiner. Once everything is installed, you can usually start mining with a single command. For example:
bfgminer -o stratum+tcp://stratum.mining.eligius.st:3334 -O 1CBKzGN7TkcJ9YGCxfCCMsxjhSperRcyUX
Is it a good investment?
There are quite a few variables that determine whether an investment in mining hardware will be profitable or not:
- The cost of the hardware (including shipping)
- The shipping delay (it will take a while)
- The cost of the electricity
- The difficult rate
- The current Bitcoin exchange rate
- The expected future value of bitcoins
To figure out if you will earn a profit or loss on the mining hardware you need to estimate all these variables and come to your own conclusion about profitability. There are profit/loss calculators you can use as well. I will say this, however ― your hardware will almost certainly start depreciating the moment you plug it in. As other miners bring additional hardware online, and as the difficulty increases, your share of the mining reward will go down. Eventually, it will get to a point where you are spending more money on electricity to operate the hardware than you are earning in block rewards. At that point you will likely want to shut the hardware down. You could continue mining at a loss and speculate that the bitcoin price will increase to cover your losses, but that adds additional risk.
What this all means for you is that your hardware likely has an expiration date. When you first plug it in, that will be the most you ever earn. The profits will continue to decline until they turn negative. Typically you can expect to get about six months out of your hardware and that’s about it. If you’ve calculated correctly, you will have earned enough in Bitcoin to cover the cost of the hardware and earn a small return on your investment. If you didn’t, you’ll take a loss. If you earn a profit, you have to decide whether to take your profits and run, or reinvest some or all of it in more hardware.
A word of caution ― there have been people who continually reinvested their mining profits in more and more hardware, amassing a large hashrate in the process. It sounds impressive, yet as the price of Bitcoin climbed towards $1,000 they found themselves with zero actual bitcoin while everyone around them were counting their riches. So you have to find a good rate to reinvest.
A final point I want to make is relate to shipping delays when purchasing hardware. Delays can be the difference between earning a positive return on your investment or a loss. To illustrate how crucial timing is, let me tell you a little story. Back in early 2013 prior to ASICs hitting the market, I was considering dropping $2,500 dollars on a 50 Gh/s ASIC. At that point I did the math and calculated that if I was able to receive the hardware within the next week or two, I would earn some ridiculous amount of money. Somewhere around $150,000/month. Not bad for a $2,500 investment. The problem was I knew the order wouldn’t ship in two weeks, more like 5 or 6 months. So I was left to try to estimate the hashrate six months out and calculate my would-be profits. Naturally, forecasting the hashrate that far out was practically impossible, but if it skyrocketed during that period, I would take a loss on the hardware. So despite the promise of $150,000/month, I declined and just purchased bitcoins with the money. And good thing! The hashrate did, in fact, skyrocket. And the shipping delays were even worse than expected. People who ordered at that point ended up waiting 8 months or more. I almost certainly would have taken a loss. Instead I earned a big profit just by buying Bitcoin outright.
This still likely hold true today. At this point there is so much hashing power in the network that I suspect most miners are operating at a loss while speculating that they can recover that loss through future increases in the price of bitcoin. If you do decide to get into mining, you need to take that into consideration and adjust your expectations accordingly.
So that’s it for now. In the next post I’m going to cover some mining topics that weren’t covered in this post. Stay tuned.
Original content by Chris, copyleft, tips welcome