By Kelvin Ting, Head of Blockchain Strategy
This is the third article of our Digital Assets Decoded series which aims to give you a fundamental understanding of the cryptocurrency space. In our previous article, “What are Consensus Algorithms”, we discussed what a consensus algorithm is — a method for a group of people to arrive at a decision without the need for a centralized party.
This article describes the topic of Proof-of-Work, a type of consensus algorithm that is used in Bitcoin, Litecoin, and Ethereum (at the time of writing). Here, we attempt to break down how Proof-of-Work consensus algorithms work.
As we have discussed in our previous articles, a consensus algorithm means that multiple parties have to follow a set of rules to come to an agreement. The word proof in this context refers to having demonstrable evidence that a block of transactions at a certain time can be considered valid by the network.
A Proof-of-Work system is one where transactions are validated by miners who spend computing power in order to validate transactions, and in turn, receive block rewards in the form of cryptocurrency.
Let’s discuss Proof-of-Work in the vein of Bitcoin. In order for a Proof-of-Work system to work, the system needs machines on the network called miners, to audit and verify any pending transactions on the blockchain. Once a person sends their assets such as Bitcoin to the network and signs the transaction using their private key, they will be picked up by miners, who ensure that the transaction is legitimate.
The miner’s job is what the name implies — someone who goes out into the field and does something in order to get a reward. However, the difference between a miner in the classical sense and a cryptocurrency miner is the work that is done to obtain a reward. A normal miner’s work would be to go out into the field, prospect, and start digging. If they are lucky, they will be rewarded with gold. In other words, they have to do some work, and as a result of their work, may receive a reward for that work. Similarly, the cryptocurrency miner also has to perform some work in order to get rewarded.
The cryptocurrency miner’s job is to calculate a number that represents all the information within a block (i.e. a block header) in such a way that it is less than or equal to a set target number. In order to do this, the miner looks at the pending transactions in the network, and selects and collects the block size’s (1 megabyte) worth of transactions. The miner then passes them into a cryptographic hash function called SHA-256, along with various metadata such as the miner’s Bitcoin client version (i.e. the current software version that the miner is using), a cryptographic hash describing the previous block and the timestamp of the block.1
The miner then attempts to repeatedly compute an output hash and submitting these hashes to the network. This is a very computationally intensive operation, as the miner will have to use brute force. The miner is required to calculate a nonce, an arbitrary number that is used to be added to the block header, and then hashing it. This hash is then compared with the target, a large number that the miner’s guessed output has to fall below. If the miner’s solution falls below the target value, then it is considered a valid solution. However, this is very intensive as the miner will have to guess the nonce, which could be any number between 0 and roughly 4.29 billion.
This means that the miner will have to keep guessing and recomputing what this output hash is over and over again until a valid solution is found. The difficulty of guessing such a transaction depends on the number of miners in the network — the more miners trying to guess a solution, the higher the difficulty of guessing such a solution.
If the network accepts the suggested solution from the miner, then the miner is considered to have mined the block. The transactions that the miner has proposed will then be added to the Bitcoin blockchain, and the miner will receive a block reward for their work. At the time of writing, for Bitcoin, miners are given 6.25 BTC per block. An example workflow for miners is shown in Figure 1.
Mining Pools and 51% attacks
With each block, only one miner is given a block reward, and this reward happens at an interval in accordance to the block time (around 10 minutes). As mining is computationally expensive, and relies on miners spending large amounts of computational power and electricity costs, miners pool together their resources or hashing power to mine Bitcoin using mining pools. Once a miner in the pool finds a solution, they are given the reward, which is split among the various other members in the pool.
The power which the miner or a mining pool consumes to compute a solution is called hashing power. A 51% attack is one in which a pool or a mining pool who owns at least 50% of the entire network’s hashing power may act maliciously by double-spending their tokens. However, this is less likely in matured networks such as Bitcoin and Ethereum.
In this article, we explored the mechanics of a Proof-of-Work algorithm. We discussed how transactions are validated by miners, who receive a payment for their work. However, as rewards are only given to one individual miner, miners can work together in a mining pool and receive rewards proportional to their contributions within the pool. Stay tuned for our next article where we discuss how the Proof-of-Stake consensus algorithm works.