An Introduction to Bitcoin Mining

By: David Marc
Updated: May 18, 2018

 

Distributed Consensus through Bitcoin Mining

Bitcoin mining is based on a methodology developed by Adam Back called Hashcash, utilizing a concept known as “proof of work” to add new blocks to the blockchain. Proof of work is meant to show that a certain amount of computational power has been exerted behind the task at hand. As it pertains to bitcoin, proof of work is demonstrated by successfully running a block through a hash function known as “SHA-256”, SHA standing for secure hash function and the 256 a reference to the number of bits contained within.

To rehash (haha), a hash function is a cryptographic process that converts variable amounts of information – sometimes an extremely large amount – into smaller, standardized lengths of numbers and/or letters arranged in seemingly random order. Identical inputs will always result in the exact same output; however, the alteration of a single digit within a single input results in a waterfall effect by which the output bears absolutely no resemblance to its previous iteration. This is important for three reasons. First, it ensures that no hash input can be retroactively changed without instantly being noticed. Second, the output can be replicated in a fraction of a second by any computer, provided that all inputs are known. And third, because the composition of a hash output is impossible to predict before actually running the hash, proof of work can be engineered to introduce a scalable level of difficulty. Confusing, but read on.

The bitcoin protocol requires that a hash output must start with a predetermined number of zeros before the block will be considered as successfully mined and added to the blockchain. Miners attempt to produce an output starting with the specified number of zeros by hashing all inputs within the block against a variable digit known as a nonce. The nonce is continually changed and hashed against the block inputs at galactic speeds – the network hashrate is currently at 400,000 trillion hashes…per second! – until the output starts with the predetermined number of zeros. The miner then happily releases the nonce and the inputs to the network, who can confirm the solution by hashing the lucky nonce against the inputs. If a majority of nodes both agree with the proof of work and find that all transactions contained within are valid and not already spent, the block is added to the blockchain and the miners move on to the next block to repeat the process.

block graphic

Here is a nice before and after visualization of inputs and outputs.  A brief description of some of the inputs. First we see the previous block hash to which the new hash will be added, insuring chronological integrity. Rather than include each individual transaction – 63 of them according to the illustration – a cryptographic construction called a Merkle tree is utilized to hash all transactions into a single, 32-bit hash. Each transaction is hashed against another, and so on, until the last two parent transactions are hashed together producing a single hash value, called a Merkle root. We are also able to see the successful nonce listed, which, when combined with the other inputs, produces the block hash output displayed on the right. The coinbase transaction is a special transaction created by the successful miner, which allocates the mining reward to the miner’s address.

Let’s imagine an extremely unlikely hypothetical in which two different miners simultaneously find a solution which is broadcast to the network, causing a split or “fork” in the blockchain. According to Nakamoto, “The majority decision is represented by the longest chain, which has the greatest proof of work effort invested in it. If a majority of CPU power is controlled by honest nodes [i.e. not working together to undermine the network], the honest chain will grow fastest and outpace competing chains”. The shorter block will become an orphan block as miners switch to work on the longest chain, as only successful proof of work on the longest chain will be accepted by the network.

This whole convoluted mess is necessary for a few reasons.

Reason One: The Money Supply

First, the process is meant to control the introduction of new units of bitcoin into the network. You’ll remember that bitcoin was designed as a deflationary currency with a predetermined ceiling of 21 million coins. These coins are meant to be introduced at a diminishing rate until the last bitcoin is produced some time in 2140.

Initially, miners were rewarded with 50 bitcoins for each successful proof of work, with the reward halved after every 210,000 blocks successfully mined. On average, it should take 4 ½ years for the collective miner community to mine 210,000 blocks; 2016 every two weeks or one every 10 minutes. The miners, however, continue to increase their processing power. While at launch the bitcoin miner network was composed primarily of crypto-enthusiasts with personal computers running the software, now it is the realm of massive mining pools with unfathomable computational horsepower. These pools would have no trouble providing proof of work back in 2008 within a fraction of a second.

To avoid flooding the market with newly mined coins, once every two weeks the bitcoin protocol reviews the average time it took to mine a successful block and adjusts the zeros required accordingly so that on average, one successful hash will be produced at around the 10 minute target. This ensures that the money supply will release at a rate more or less in line with the original intention.

Reason Two: Decentralization

The proof of work mechanism is intentionally designed to be random. That is to say, each particular hash has the exact same chance of finding the correct answer. The only way to increase the chance of successfully mining a block is to increase the computational power devoted to the task. And this is exactly what has happened. Numerous technology companies compete to develop faster and more efficient mining rigs, different groups of individuals combine their mining power into pools and split the rewards based on hashing contribution, and specialized mining data centers lease mining power to mining speculators. The rules are clearly stated, the rewards lucrative and the whole thing has been pushed out to the free market. Mining has been democratized, and the diversity of participants from every corner of the globe has ensured that no single entity can gain a majority of mining power.  Provided that the majority of miners are “honest” – or in other words are not colluding to hijack the network – attacking the network is impossible.

And what would happen if an individual or aligned group did gain a majority of mining power? Actually, why could this whole process not be replicated on a secured central server? Even the most benevolent central miner would represent a single point of failure, a point at which external pressure, or incompetence, or death, or force majeure, or misplaced good intentions, could undermine the network. The decentralization of mining means the bitcoin network is uncensorable and immutable. Unimpeded, it continues the autonomous execution of the task for which it was established.

But what really is there to prevent an evil collusion or monopoly, to prevent a so-called 51% attack? First, there is powerful economic incentive to play by the rules. In the event that a miner were to gain a majority share of mining power, the profit gained by simply collecting the bitcoin rewards would surely outweigh any short-term gain earned by creating forks in the blockchain in order to double spend transactions. With bitcoin currently valued at $250, and 25 coins granted every 10 minutes as reward, a 50% miner would generate approximately $20,000 per hour if we include transaction fees, or close to half a million dollars daily. What single transaction is worth sacrificing such a pay day? Moreover, much of the mining power is organized into a large number of collective pools. Individual miners themselves have proved a powerful force for self-policing (as have the pool operators), moving to different pools to maintain a fragmented network hashing rate.

Of course, a large government – China or Russia perhaps – might be able to disrupt the network were they to see bitcoin as a strategic threat. However, the continued growth of the network hashrate, made possible by a democratized and global process of mining optimization, makes even a large scale governmental attack less and less likely to suceed as time passes.