Cryptocurrency Mining


Cryptocurrency mining

Cryptocurrencies are praised as a way to perform financial transactions (and other operations) in a secure, decentralized, and trustless network. But what makes the system secure? And in a decentralized system who decides which transactions go on the blockchain and which ones don’t? Cryptocurrency mining is the method by which the blockchain is created in secured. The blockchain is made up a series of blocks containing the data to be stored on the blockchain. The goal of cryptocurrencies is to create these blocks in a way that it would be extremely difficult for a person or group to create a blockchain that is more believable than the one created by the network as a whole. Since cryptocurrency miners create each block in the chain, an attacker could control the blockchain if they manage to be the one selected to create each block in the chain.

Cryptocurrency mining is designed to make this impossible or at least extremely hard. How? Cryptocurrencies are designed to base their security off of scarcity. What is scarce depends on the algorithm used by the cryptocurrency, but in all cases controlling the system requires having a large quantity of whatever is being used. By the laws of supply and demand, this is expensive. The security of cryptocurrencies is mainly based on making cheating too expensive to be possible.

While several protocols for cryptocurrency mining (or forging, farming, etc.) have been created, two are currently dominant: Proof of Work and Proof of Stake. In this article, we’ll give a brief walkthrough on how these protocols work, what they use as their “scarce” resource, and how they secure the blockchain.


Proof of Work

Proof of Work is the oldest way of securing a blockchain. It was created by Satoshi Nakamoto as part of Bitcoin and many cryptocurrencies have adopted it as their method of securing the blockchain.

The security of Proof of Work is based on solving a “hard” cryptography problem. This problem is intentionally designed to have multiple solutions but these solutions can only be found by random guessing. In a Proof of Work cryptocurrency, all of the miners race to find a possible solution to the “hard” problem. The winner of the race gets to create a new block and earn the associated block reward (which pays for their hard work).

The scarcity used in Proof of Work systems to secure the blockchain is the scarcity of computational resources. Since the problem can only be solved by random guessing, the best way to guarantee that you will win the race is to make more guesses than everyone else in the network. To do this, you need to have more computing power that the rest of the network put together.

The rest of this section is devoted to describing different details of Proof of Work. To start, we need to discuss hash functions, which are at the heart of the “hard problem” that cryptocurrency miners race to solve. Then, we can discuss the overall mechanics of Proof of Work: how hash functions are used in the “problem” and how miners can guess possible solutions. Next, we’ll talk more about the security of Proof of Work systems and how they can be broken (they’re not perfectly secure). Finally, we’ll talk about some of the cons of Proof of Work for securing cryptocurrency.


Hash Functions

Hash functions

The problem to be solved in Proof of Work cryptocurrencies uses a cryptographic hash function. While this may sound complicated, all you need to know is that a cryptographic hash function is a mathematical function with these properties:

  1. A hash function can take an input of any length and create an output of a set length
  2. It is impossible to determine the input to a hash function given its output
  3. Applying a hash function to two binary strings that differ in a single bit results in outputs that match in about half of their bits

Each of these three properties is important to the functionality of a Proof of Work cryptocurrency. The first is significant because a hash function can reduce inputs of varying sizes into outputs of the same size for easy comparison. This is important because the problem in Proof of Work cryptocurrencies is finding a hash output that meets a certain difficulty target. These difficulty targets are usually described as requiring the first N digits of the binary representation of a hash function output to be zero. By producing outputs of a standard length from inputs of varying lengths, hash functions make comparisons possible.

The second property of hash functions is vital to the security of Proof of Work blockchains. As described above, the solution to a Proof of Work problem is a hash function output starting with a certain number of leading zeros. If someone could choose an output that met the difficulty target and determine an input that would produce that output, then solving the Proof of Work problem would be too easy.

Finally, similar inputs to hash functions cannot produce similar outputs if a hash function is going to be used in Proof of Work. The goal of Proof of Work is that miners guess randomly until they pick an input that meets the target. If similar inputs created similar outputs, miners could use a hill climbing approach. In this approach, a user starts tries a small change to an input and keeps it if it’s closer to the target or discards it if it’s further away. This would let a miner find a valid Proof of Work solution much more quickly than guessing randomly, which would be bad for blockchain security.


Mining in Proof of Work Blockchains

Now that we’ve discussed hash functions, we can see how mining the blockchain works. Above, we talked about how miners try to find an input to a hash function that produces an output that meets the difficulty target (number of leading zeros). The input used in blockchain’s Proof of Work calculations is designed to cover the entirety of the block. This could involve hashing the entire block or, as is done in Bitcoin, hashing the header of the block where the header contains a hash output of hashing the transaction list.

This block contains a several required pieces of information (list of transactions, hash of previous block, miner identifier, etc.) but also contains one piece of information that can be set by the miner. This nonce allows the miner to manipulate the output of the hash of the block. Remember that flipping a single bit of the input to a hash function changes on average half of the output’s bits. By trying different values for this nonce, a miner can produce any possible hash output. This includes solutions that meet the difficulty target.

Miners in Proof of Work blockchains take a block as input and try different nonce values until they identify one that produces an output that meets the difficulty target. A successful miner then sends out the block (including the nonce) to other members in the network. Anyone in the network can easily test the validity of the block by computing the hash themselves and comparing it to the difficulty target. If the target is met (and the miner has followed all of the rules for block structure and contents), the block is accepted on the blockchain and the miner is paid a block reward to compensate them for their efforts in securing the blockchain.


Security of Proof of Work

Security of Proof of work


While cryptocurrency mining may be interesting and a good way to make money, it must have some purpose on the blockchain or no-one would be paid to do it, right? The purpose of mining in blockchain is to secure the blockchain. Blockchain technology is designed to operate in a decentralized and trustless manner, meaning that anyone with a copy of the blockchain should be able to verify that it is correct and be convinced that no-one could generate a fake blockchain that could appear more authentic than the real one.

Proof of Work blockchains base the security of the blockchain on the fact that Proof of Work is HARD. Most cryptocurrencies are designed to generate a new block at a fixed rate (every ten minutes for Bitcoin). However, there is no rule that forces a block to be generated at that rate. Instead, the rate is enforced using the difficulty of the cryptographic puzzle used for Proof of Work. This difficulty is set so that the probability of finding a valid solution to the problem is so low that it takes the entire time between blocks for the entire network to try enough guesses to find a solution.

For example, Bitcoin has a target block rate of ten minutes. The Bitcoin network as a whole can try over twenty-five million terahashes (billions of hashes) per second. A ten minute block rate means that the difficulty is set so that the network needs to try over 15 quintillion (that’s a fifteen with fifteen zeros after it) guesses in order to have a good chance at finding one that meets the difficulty target.

This difficulty is the basis of the security of a Proof of Work cryptocurrency. To create a fake blockchain, an attacker would have to create a valid blockchain that was at least as hard to create as the real blockchain. This means that the attacker would have to have more computational resources than the rest of the network combined since they would need to create valid blocks at the same rate as the real blockchain in order to stay ahead.

This is called the 51% Attack and is the main security weakness of Proof of Work blockchains. Any individual or group controlling over half of the computational resources of the network has the ability to perform double-spending attacks. In these attacks, the attacker creates one version of a blockchain where they make a transaction and another version where they do not. Once they have received the goods purchased using the transaction, they make the other blockchain version the official one (by making it public when it has more work invested in it than the blockchain containing the transaction) and get to keep their cryptocurrency as well as whatever they bought. Since transactions on the blockchain cannot be reversed, the cheated party cannot do anything to get the cryptocurrency that they were promised.


Cons of Proof of Work

While Proof of Work provides an effective defense against double-spending attacks and fake blockchains, it isn’t perfect. The two main complaints about Proof of Work cryptocurrencies are the energy consumption and the bias toward wealthy miners and mining groups. Proof of Work mining involves expending large amounts of energy to solve problems that have no purpose other than protecting the security of the blockchain. As Proof of Work cryptocurrencies grow in value and popularity, the amount of energy used in mining also grows, which makes their sustainability questionable. The other main complaint about Proof of Work is the centralization of mining power in the hands of wealthy miners and mining groups. The number of possible hashes that a miner can try at once (and therefore his probability of mining a block) is limited only by the amount of money that he is willing to invest in mining equipment and electricity. Smaller miners must either join a mining pool or accept that block rewards will be few and far between. This centralizes control of the blockchain within the hands of a small number of groups. At one point a Bitcoin mining pool nearly controlled 51% of the network’s resources, making a possible before they voluntarily split to protect the security of the network.


Proof of Stake

Proof of stake

Proof of Stake cryptocurrencies take a different approach to blockchain security than Proof of Work systems. In Proof of Work, the block creator (and winner of the block reward) is “selected” based upon the amount of work miners are willing to do to win the honor since the probability of winning is proportional to the number of potential nonces that a miner tries for a given block. In Proof of Stake systems, the probability that a user will be chosen to create or forge a new block and win the reward is proportional to the amount of cryptocurrency that the user is willing to invest or stake to have a chance at creating a block.

Proof of Stake systems take advantage of the scarcity of the cryptocurrency to secure the system. Since the probability of being selected to mine a block is proportional to the amount of cryptocurrency that a user has staked, a user needs to own over 50% of the staked coins in order to have a high probability of being selected to forge a block. This situation is unlikely since the act of buying up cryptocurrency will increase its value, incentivizing others to also invest in the cryptocurrency and make more of it unavailable.


How Proof of Stake Works

In Proof of Stake cryptocurrencies, members of the network stake some of their coins, promising that they will not spend them in return for the chance to be the signer of the next block. Two main versions of Proof of Stake exist: randomized block selection and coin age selection.


  • Randomized Block Selection

In randomized block selection schemes, the choice for the forger of a block is based upon a pseudo-random value (typically a hash function output) and the size of the forger’s stake. The larger a user’s stake, the more probable that they will be selected as the forger of any block. Using a pseudo-random value protects against the user with the largest stake being chosen every time while allowing anyone to calculate who the next forger should be. This is because pseudo-random values can be calculated by anyone as long as the algorithm and starting point are known.

  • Coin Age Selection

largest stack being indicated as the “winner”?> In Proof of Stake protocols based on coin age selection, the concept of the “age” of a coin is introduced as well. The age of a stake is set to zero when the coins are first staked and reset to zero any time that the owner is selected as the forger of a block. Typically, users are ineligible to forge a block with a stake whose age is less than thirty days.

The forger of a block in a coin age selection scheme is based on the product of the size and age of the stake. This favors users who have a large stake and/or have not been selected as the forger in a while. Typically, the algorithms are designed with a maximum age value of 90 days. This prevents a network from being dominated by users with large, old stakes.


Security of Proof of Stake

As mentioned above, the security of Proof of Stake is based on the scarcity of the cryptocurrency. If a user wants to increase the probability that they are chosen to forge a new coin, they need to stake more coins, which probably means that they need to buy more. A limited supply of coins means that increased demand will increase the price of the cryptocurrency, making it difficult to purchase enough coins to gain a controlling share in the network.

To control a Proof of Stake blockchain, an attacker must collect and stake enough of the cryptocurrency to have a high probability of being selected as the forger of a block that they wish to change. One advantage that an attacker has in a Proof of Stake blockchain is that in Proof of Stake “the right get richer”.

If the attacker stakes all of their cryptocurrency as they receive it, the effect is similar to compound interest. The more cryptocurrency that they control, the higher the probability that they will be chosen to earn block rewards, which in turn increase the amount that they can stake. Theoretically, in a blockchain with a fixed number of coins, the person with the largest stake will eventually have control of the blockchain given enough time. The security of Proof of Stake is based on this not happening during the life of the cryptocurrency.

Pros and Cons of Proof of Stake

The main benefit of Proof of Stake over Proof of Work is their relative energy consumptions. Since Proof of Work uses computational resources as its source of scarcity, it burns a lot of energy. Proof of Stake burns significantly less energy since all it needs to do is determine the next forger, have the forger perform the necessary calculations to create the block, and distribute transactions and blocks throughout the network. This represents a significant decrease in energy usage compared to Proof of Work.

The main con of Proof of Stake is the fact that it makes the rich richer. This is a disadvantage to Proof of Stake from a fairness perspective (logically if the rich are getting richer, the poor are getting poorer) and from a security perspective (since over time a “hoarding” user could eventually control all of the cryptocurrency in a system).