Mining is more than just performing Proof of Work - it comes with highly interesting economic implications, from choosing which blockchain to mine, to what hardware to use and what strategies to apply. In this article, we want to take a holistic view of the mining industry. Mining has become a large business, and it would be misleading not to account for this in one way or another.

We will often use the term decentralizing and centralizing to express in which direction a given development shifts the overall level of coordination. There is no absolute decentralization or centralization and a system is moving on a scale between the two. When we talk about a decentralizing factor this does not mean it makes the system entirely decentralized, but it moves it on the centralization scale towards a more decentralized system.

## What a Miner Does

On a purely technical level it is straightforward to explain mining. It describes the activity of performing a computationally expensive task - the Proof of Work (PoW). In the simplest case, this task is finding a nonce that when hashed together with the rest of the block header produces a block hash below a certain threshold which is called the target. The total number of hash operations performed per second is called the hashrate of the network.

### Hashcash Proof of Work

This type of PoW is called Hashcash Proof of Work and was introduced by Adam Back in 1997 as a measure against spam emails. The idea is simple: adding a small PoW to an email does not impact an honest user sending only a few mails per day. Automated spam on the other hand would become computationally expensive because every single email would need to have a valid PoW attached.

The graphic above shows the mining process in a Hashcash style PoW scheme. The block header is repeatedly hashed using a different nonce each time. The header is hashed twice using SHA256 and the resulting candidate block hash is compared with the current target. If it is greater than the target the nonce is discarded and the process starts again.

Once a miner finds a nonce producing a block hash less than or equal to the target it is broadcast to the network, verified by all other nodes (including other miners) and appended to the blockchain.

The difficulty is a different way to express the current target. The difficulty is a relative measure of the current target compared to the initial maximum target that is defined with the genesis block of a blockchain.

On the Bitcoin network, which has seen the biggest growth in hash power since its inception the current difficulty (at the time of writing) is about $$1.3 \cdot 10^{13}$$, meaning it is 13 trillion times harder to find a block today, than it was when the protocol was launched.

## The Purpose of Miners

Now you might ask why it is necessary to make block production computationally hard if we want to continuously add blocks to the blockchain. The reason is that PoW is an efficient way to provide Sybil resistance.

### Sybil-Resistance

In a Sybil Attack an attacker creates a large number of malicious node in an effort to achieve some goal. In the blockchain context, this goal can be including malicious transactions in a block, censoring transactions from a given network participant or performing a double spend after a block reorganization.

Spinning up a node comes at a very low cost, so there is not much to prevent an attacker from creating a large number of them. The consensus mechanism represents an abstract form of voting on different versions of the transaction history. If voting was tied to an IP address an attacker could manipulate the vote easily by creating Sybil nodes. By tying the voting power to external costs, electricity and hardware, interfering with the voting process on blocks becomes much harder.

### Providing Immutability

Not only does PoW prevent Byzantine actors from obstructing the block production process, but it also protects the history recorded on the blockchain from being tampered with. All nodes following the protocol of a blockchain will reject versions of the blockchain that do not have a chain of references form the current block all the way back to the genesis block, each protected with a Proof of Work.

Without a Proof of Work, this chain of references could be reconstructed at almost zero cost. Only by securing each link between two blocks with a large amount of spent electricity, the blockchain becomes immutable. Without Proof of Work, it would simply be tamper-evident.

A node with access to the most recent protocol can verify the entire blockchain with all its transactions without having to rely on any external input. It will start with the first block, reconstruct the Merkle tree of transactions to verify the Merkle root included in the block header is valid, validate if the block hash meets the target given the nonce used to produce it and finally moves on to the next block. It can also compute the difficulty at any point in time as the rules for when and how the difficulty changes are part of the protocol.

For their contribution to the network, miners are allowed to include the coinbase transaction. In this transaction miners are sending the current block subsidy and the aggregate transaction fees included in the block to a self-controlled address. After the block reward maturation period ends this output becomes spendable. The block maturity interval for Horizen as well as Bitcoin is 100 blocks.

## Mining Algorithms

In the article on PoW we went over the criteria defining a “good” PoW and at this point we would like to recap those properties:

• Asymmetry: The Proof of Work needs to be hard to produce, but easy to verify.
• Optimization Free: An optimization free algorithm means that you cannot improve the efficiency of performing that task through software or algorithmic improvements.
• Amortization free: This means economies of scale that would render all mining pools besides the largest one irrelevant should not be possible based on the algorithm. (Other aspects of mining will always enable economies of scale to play out.)
• Independently Tunable Parameters: Certain parameters of the problem to solve by the miners should be easy to adapt to changing circumstances, e.g. an increase in hashrate.

Furthermore, the PoW needs to be pseudorandom so there is no shortcut to taking a brute-force approach of solving the task at hand. This also ensures that the block production time follows a statistical distribution with a constant average, ceteris paribus.

The PoW algorithm also needs to have independently adjustable parameters to account for changes in the overall hash power. To keep the block production rate constant as more hash power is added to the network the difficulty can increase. On the Horizen network this difficulty adjustment is performed after every block.

The algorithm needs to be deterministic so the verification of the proof is guaranteed.

## Mining Hardware

In our article on PoW we introduced two metrics to assess computational hardness. Space complexity refers to the memory intensiveness of the computation, while time complexity describes the reliance on the processor.

When a PoW algorithm involves creating large data sets in an intermediary step this will increase the space complexity. Other PoW algorithms barely require any memory as they involve repeated hashing of small amounts of data in the kilo byte range. By concatenating many computations on this small data set the time complexity of the algorithm will increase, with the space complexity remaining constant.

When it comes to hardware there is a tradeoff between versatility and performance. A highly specialized chip architecture will allow a very good performance on one task, at the cost of being less versatile and vice versa.

The central processing unit (CPU) of a computer offers the greatest flexibility with regards to the types of computations it can perform, at the cost of being not very performant. The graphical processing unit (GPU) is focused on tasks around image processing as the name suggests. It also includes more memory because computations on graphics tend to have a higher space complexity. Field-programmable gate arrays (FPGAs) are meant to be configured for a specific task after manufacturing which allows a specialization of the integrated circuits depending on their application. After configuration they represent another step towards specialization at the expense of versatility. As the name suggests, the Application Specific Integrated Circuit (ASIC) sits on the end of the spectrum on specialization and allows for the efficient execution of the tasks it was designed for.

### From CPUs to ASICs

In the early days of cryptocurrency mining, people used the hardware they had at hand - desktop computers and their CPUs. In October of 2010 GPU mining became feasible when the first software utilizing the graphical processing unit for mining was released to the public. People with a gaming setup were now at a serious advantage compared to CPU miners. Mining started to become more lucrative and hence more competitive. People started configuring FPGAs to suit the requirements of efficient mining. The last major evolutionary step in mining happened in 2013 when the first ASIC designed for cryptocurrency mining was released.

### ASIC Resistance

A number of different “ASIC resistant” mining algos were proposed but ASIC resistant algorithms are a myth - at least to some degree. When a chip manufacturer designs an integrated circuit with a specific mining algorithm in mind, it will always perform better than a more versatile GPU.

More realistically, the assumption was that the cost to design and produce ASICs for certain algorithms was just not worth the marginal improvement in efficiency. While this assumption was certainly justified at the time many of the mining algorithms emerged, it didn’t account for the rising valuations of cryptocurrencies that we saw in 2017. This caused a range of ASICs being developed for different mining algorithms, including some that were thought of as “ASIC resistant”.

ASIC resistance was mostly achieved by increasing the space complexity of the algorithm and thereby increasing the memory demand. High-bandwidth memory is a very expensive component in chip manufacturing. A general increase in demand for high-speed memory technology such as GDDR6 and HBM2 made producing relatively cheap ASICs for memory intensive mining algorithms feasible.

The demand for ASIC resistant algorithms came largely from an interest in a decentralized mining economy resulting in a more decentralized distribution of newly minted coins. GPUs are more widely spread and accessible than the highly specialized ASICs. Hence, a GPU-mineable algorithm would in theory lead to a wider distribution of new coins.

The demand for GPU mining was met with some projects changing their mining algorithm, rendering the highly specialized ASICs useless. But changing algorithms mostly benefits large hardware manufacturers as they have the resources to develop ASICs for the new algorithm first. By sticking to an algorithm, smaller companies have the chance to design and produce mining hardware accordingly, which decentralizes the business again. Grin took an interesting approach to launching their network with two different mining algorithms used simultaneously, one ASIC-mineable, the other GPU-mineable.

Today, we are past the peak of mining centralization. For a period of time around 2017 and 2018 Bitmain used to be the dominant manufacturer for mining specific hardware. Since then, their market share has constantly decreased and new players have entered the scene.

## How Mining has Professionalized

Besides using sophisticated and specialized hardware mining has professionalized in other ways. Economic principles known for decades and centuries increasingly started to apply to the field.

### The Need for Cheap Electricity

First, location factors are very important today, as the industry is highly competitive and electricity prices are an important factor determining if a mining operation is profitable or not. Miners settle in regions with very low electricity costs in order to gain a competitive advantage. While the mining industry is not very transparent, it is assumed that almost three quarters of the energy used for Bitcoin mining comes from renewable energy sources. This is due to the fact that large renewable energy sources are often built without the needed capacity to transport all the energy to the next consumers. By setting up a mining operation close to such an energy source, for instance a damn with hydroelectric power generation, costs can be cut.

### Mining Pools

Next, miners started to organize into mining pools. They prefer stable cash flows and have come up with mining pools to share the work and socialize the winnings. Mining pools have a centralizing effect and grant a lot of power to the pool operators. Mining pool software could be configured to exclude transactions involving certain addresses - something that cryptocurrencies try to avoid at great cost. BetterHash addresses this issue by allowing individual miners to create their own block templates.

Economies of scale are also starting to play out, which is not a bad thing per se. A mining operation will always be more profitable when it gets bulk discounts on hardware or electricity and the price per square meter tends to go down when you rent or buy larger warehouses. But large-scale mining operations operate in a highly competitive environment that leaves minimal margins when selling the mined coins. To cover operational costs there is constant selling pressure for these actors, which effectively makes it seem like coins are issued to the secondary market directly.

## Mining Economics

When you look at the economics from a miners perspective you first need to think of the cost of the operation, then consider the potential revenues and lastly, derive an estimate of your profits.

### CAPEX vs. OPEX

The costs can be divided into two categories, capital expenditures (CAPEX) and operational expenditures (OPEX):

• CAPEX are the cost of acquiring non-monetary capital like mining gear, racks, and property (if bought).
• OPEX are ongoing expenditures like wages, electricity cost for the rigs as well as cooling and property (if rented).

Setting up a mining operation will usually come with both capital and operational expenditures but depending on the circumstances it can be set up to tend towards being CAPEX or OPEX-heavy. This article goes through the economics of setting up an operation that aims to mine one block a day on the Bitcoin network. Although the numbers are outdated, the considerations behind calculating costs and profits are explained very well.

### Hashrate vs. Price

The mining industry and the price of a given coin are arguably related to some extend. Firstly, the hashrate will follow the price, because an increase in price will increase the profit margin of existing miners and lead to them taking more hardware online. Additionally, new entrants will join the network and try to get a share of the cake. This increase in competition and the accommponied decrease in margins leads to the mining cost tending towards the price of a coin, minus a small margin for the miners.

The trailing effect of the hashrate following the price comes with a delay and the delay when prices rise is greater than in a situation where prices decline. Ordering new mining gear and getting equipment live takes longer than taking hardware offline when prices decline.

### The Fixed Issuance Schedule

Without the difficulty adjustment in place, a given amount of hashrate would always produce a fixed amount of coins. This would still allow for a fixed supply, but not a fixed issuance schedule. This is an important differentiating factor when comparing cryptocurrencies with gold.

With gold, production will increase as prices rise. Less profitable, inactive mining sites are reactivated as the expected return on investment (ROI) becomes positive and active mining facilities increase their production. This effect also plays out the other way around. When prices decline mining facilities are lowering their production or closing all together. This dampens the volatility because the supply can increase or decrease in tandem with price. With cryptocurrencies production is constant and can not display this effect.

An economic term often used in the context of commodities like gold and other metals is the Stock-to-Flow ratio. It describes the amount of a commodity in circulation relative to the production rate. Bitcoin was the first asset to ever allow not just for a predictable supply and issuance schedule, but also a predictable stock to flow ratio.

## Mining Strategies

As we mentioned earlier, mining is a rather intransparent business and cryptocurrency mining is no exception. Miners can be one of three things: honest, rational or malicious.

• An honest miner will adhere to the rules of the protocol at all times.
• A rational miner will act to maximise profit, either by adhering to the protocol or deriving from it, depending on the incentives provided.
• A malicious miner will derive from the protocol to acheive their objective.

It is assumed that most miners are rational, meaning they don’t mind following the protocol as long as it is the most profitable strategy. Some strategies evolved that are used to gain a competitive advantage - most notably selfish mining also referred to as the block withholding strategy.

### Selfish Mining

The general idea of selfish mining is to selectively publish blocks to increase revenue in the long term. Let’s assume the selfish miner has a share x of the relative hashrate on the network. All other miners combined therefore control the hashrate (1-x). When the selfish miner joins the network the system is in state 0.

Starting at state 0 the selfish miner is in competition with the network to find the next block and will succeed with a probability p that equals his share of overall hashrate x. When he finds a valid block 1’ he does NOT publish it and the system transitions to state 1. If another miner finds a block first it is broadcast as usual and there is no state transition.

When the selfish miner has found block 1’ he continues building block 2’ on top of it. If he succeeds the system transitions to state 2. But the other miners don’t sit on their hands in the meantime. They are still trying to find block 1 and will succeed with a probability (1-x). If the network finds block 1 before the selfish miner finds block 2’, the system transitions to state 0’.

State 0’ is a little more interesting.

The selfish miner still has the chance of winning the competition between block 1 and 1’. As soon as he becomes aware of block 1 he will broadcast his version (1’) to the network. At this point there is a tie but block 1 has an advantage. Miners build on the block they see first.

• Just like in state 1, the selfish miner will find block 2’ with a probability p = x.
• A fraction of the remaining miners with a combined relative hashrate of z will receive the selfish block 1’ first, mine on top of it and find block 2’ with a probability of p = (1 - x) z.
• Most miners will receive block 1 first and build on top of it. With a probability p = (1 - x)(1 - z)

At this point the chance of the network extending the honest chain by finding block 2 is the highest. This depends on their share of the hashrate but most likely it is greater than 50%, otherwise the selfish miner could have gone ahead and mounted a block reorganization attack in the first place. The share of miners on the network that will see the selfish block 1’ first (z) will be small because of the broadcasting delay.

Either way, the system will restart at state 0 no matter what happens in state 0’.

When we return to state 1, there was a good chance of the selfish miner extending his private chain with block 2’ and the system transitioning to state 2.

At this point the selfish miner is at a serious advantage over the rest of the network. With probability p = x he will extend the private chain with block 3’ and transition the system to state n.

In case the honest miners find block 1 before block 3’ is found, the selfish miner already has two valid blocks to broadcast. All nodes will receive block 1 when it’s broadcast, but discard it shortly after when they receive blocks 1’ and 2’ from the selfish miner. This will lead to the system returning to state 0.

Strategically, the miner will broadcast the pair of blocks with a slight delay. This will give him an advantage as he has some extra time to find block 3’ before the other nodes even learn about 2’ and enter the competition. The delay can’t be to big though, as it gives the other miners a chance to find block 2 which leads to a situation similar to state 0’, only that there is a fork with two blocks on each branch instead of one.

The attacker will be in a comfortable postion if they manage to transition the system to state n (n > 2).

If the attacker extends the private chain, the system will transition to state (n + 1). When the other miners find block 1 the selfish miner can broadcast two blocks at once leading to block 1 being disregarded and the system transitioning to state (n-1).

Eyal and Sirer demonstrated in their paper Majority is not Enough: Bitcoin Mining is Vulnerable that at z = 0.5 the selfish miner becomes more efficient than the network given he controls more than 25% of the hashrate. In case he controls more than a third of the network, (x > 0.33) he is more efficient, no matter what z is. He could now coerce other miners to enter a coalition and participate in the unfair advantage of the block withholding strategy. Eventually, this coalition could reach a majority of the hasrate, enough to successfully mount a 51% attack and perform double spends. Vitalik Buterin summarized this paper for the Bitcoin Magazine.

The paper mentioned above was published in 2013 and selfish mining has been theorized about as early as 2010, so you might ask why this scenario has not played out as described. Besides the block reward there are higher level economic considerations.

### The Risks of Selfish Mining

Miners with a significant share of the hashrate have a lot of tied up capital in their business, even when they operate OPEX heavy. Mining equipment is usually bought, representing the largest share of capital expenditures. By mounting such an attack, the entity would undermine the credibility of their source of income (the blockchain in question) and likely influence the price of the coin they are attacking significantly. To make this attack feasible, one would also have to involve other miners or pools at some point which comes at a significant risk.

“There is at least one data point in favor of this theory. In 2014, the GHash.io mining pool repeatedly flirted with >50% hashpower (by attracting miners with its zero-fee policy), and allegedly even engaged in double-spending the popular betting site BetCoin Dice12. As the news about mining pool centralization propagated through the Bitcoin community, trust in the system was shaken. Several important figures publicly sold parts of their Bitcoin13. In the aftermath, individual miners fled the pool in large numbers to protect their investment. After that, no mining pool has dared to come anywhere near this level of hashpower again. It seems miners became aware that any form of market panic can have a highly detrimental effect on their bottom lines.” - Curtis, Hasu & Prestwich, “A model for Bitcoin’s security and the declining block subsidy”

Nonetheless, short block withholding periods are likely used by some pools, especially when blocks are found very quickly relative to the targeted block production rate. It gives the miner a slight advantage by increasing the chances of finding two consecutive blocks in a row.

This section should give you an idea of how intricate the mining process can be. Finding a nonce that produces a block hash less than or equal to the target seems pretty straight forward compared to the economic and strategic considerations going into the mining process. There are even more complex and intricate mining strategies, such as Stubborn Mining which combines the selfish mining strategy with an Eclipse Attack.

## Energy Consumption

One of the biggest criticisms with regards to Proof-of-Work and the mining process is the large energy consumption. Bitcoin is the blockchain that consumes the greatest amount of energy due to the immense hashrate on the network. The University of Cambridge has created a dedicated page for the Cambridge Bitcoin Electricity Consumption Index. While most other blockchains have only a fraction of Bitcoin’s energy demand, they do consume a lot of energy.

This energy consumption is a necessity for securing the ledger. Only by spending real world resources on securing the links between blocks, these references become costly to forge. So costly in fact, that after a reasonable confirmation time you can be certain an entry in the blockchain will not be reversed.

### “Saving” Energy

The argument that blockchain consumes too much energy can be answered from different angles. The criticism is often based on the premise that the energy is being “wasted”. When you pay for a commodity and use it to achieve a subjectively (and also objectively) valuable goal, mining cryptocurrencies, the energy is not wasted but used. In fact, a lot of the energy used for Bitcoin mining might go to waste if miners weren’t using it.

“In China, excess energy is used for bitcoin mining with wind and solar plants using up to 30% of the oversupply which would otherwise be refused by the grid, grounded, and wasted.” - CoinShares Research, The Bitcoin Mining Network June 2019

This is also true for certain regions in Canada which have built massive hydropower plants and have to figure out how to use excess energy.

Another way to “save” energy, or better use under-utilized energy, is using natural gas. Instead of flaring it, it can be used to power gas generators and those can power mining gear in return.

### Utilizing Renewable Energy

Miners use an overproportional share of renewables compared to the global energy consumption. As of December 2019 it is assumed that 73% of Bitcoin’s energy consumption comes from renewable sources.

“Finally, using a combination of estimates of global mining locations and regional renewables penetrations we again calculate the Bitcoin mining industry to be heavily renewables-driven. Our current approximate percentage of renewable power generation in the Bitcoin mining energy mix stands at 73%, around four times the global average” - CoinShares Research, The Bitcoin Mining Network Dezember 2019

It is reasonable to assume a high share of renewable energy being used to mine other currencies as well. Often times renewable energy is a lot cheaper than energy from burning fossil fuels. Many regions that have focused on expanding their renewables production have regional oversupplies of energy, which leads to very low prices.

Overall cryptocurrency mining is a way for renewable energy producers to temporarily utilize energy that the grid cannot transport to locations where it is needed. By mining with their excess energy, they can lower the financial risk of setting up a windpark, hydro dam or solar park. PoW might therefore pose a net positive for the global energy footprint.

“[…] bitcoin is providing a powerful market incentive to energy producers worldwide to increase their energy production. […] By giving a large financial incentive to anyone able to mine at an electricity cost below that of the market, Bitcoin makes the development of cheap sources of electricity, anywhere in the world, very rewarding.” - Saifedean, Bitcoin Mining: Energy and Security, 2018, Volume 1, Issue 3

### Efficient Electricity Export

Lastly, using energy to mine is a great way to export cheap electricity. Transmitting electricity over long distances is highly inefficient. A mechanism used in the past to utilize stranded energy was performing energy-intensive but location independent services in these regions.

One example is Island, which has access to large amounts of clean energy due to being located in a geothermally active region. Island generates about 70% of its electricity from hydroelectric sources and 30% from geothermal sources. Island has pivoted into a highly energy intensive industry due to this fact, namely the aluminium production.

““We are based in the middle of the North Atlantic Ocean. We are not connected to the mainland Europe grid,” said Bjarni Mar Gylfason, chief economist for the Federation of Icelandic Industries. “So we export energy in the form of aluminum.”” - Henry Chu, Los Angeles Times, Iceland Divided Over Aluminum’s Role in its Future

Cryptocurrency mining has the potential to even the global energy-price hyperplane through miners settling in regions where electricity is abundant.

## Summary

To summarize, we looked at the task a miner performs first, before we explained what the purpose of miners is: providing the network with a Sybil-resistance mechanism and making the blockchain immutable.

We continued with looking at how mining has professionalized through dedicated hardware, the need for cheap electricity and the formation of mining pools to allow small mining operations to have a steady revenue.

We gave a quick overview of mining economics and explained that a mining operation can be set up CAPEX or OPEX heavy, that the hashrate follows the price of a given crypto asset and that the fixed issuance schedule doesn’t allow miners to dampen the volatility of a coin through changing the “production rate”.

After we looked at selfish mining, a strategy miners can apply go gain an advantage over their competition without breaking the rules of the protocol we talked about the energy consumption of the mining process. It is a necessity to secure the ledger on one hand, and is mostly done with stranded renewable energy, as it is the cheapest source of electricity available.

In our last article within this chapter we look at blockchain governance.