Introduction
A consensus algorithm is a mechanism by which users and programs can coordinate their actions in a distributed network. It ensures that all network participants reach agreement on the current state of the data, even if some nodes fail. In other words, consensus helps maintain system resiliency (to learn more, check out Byzantine Generals' Missions Explained).
In a centralized structure, one entity has power over the entire system. In most cases, these bodies have the power to make changes as they see fit: there is no complex governance system to reach consensus among multiple administrators.
In a decentralized environment, the mechanism of operation is completely different. For example, if we are talking about a distributed database, how can we get consent from all participants in the network regarding what data can be added to the network?
Achieving consensus in an environment where parties cannot trust each other was one of the most important developments in the industry, which paved the way for the emergence of blockchains. In this article, we will look at the importance of consensus algorithms for the proper functioning of cryptocurrencies and distributed ledgers.
Consensus algorithms and cryptocurrency
In cryptocurrency networks, user balances are recorded in a database - the blockchain. Each user (node) must own an identical copy of the database. Otherwise, information will vary, which will violate the principles of reliability and openness of the entire cryptocurrency network.
Public key cryptography ensures that unauthorized parties cannot access your coins. However, users also need a reliable way to check whether funds have been spent or not.
Satoshi Nakamoto, the creator of Bitcoin, proposed the Proof of Work system to coordinate network users. Next, we'll look at how PoW works, but first we'll identify the common features of most existing consensus algorithms.
The first is the requirement for users who want to add blocks (we'll call them validators) to provide some kind of stake in return. A share or stake is a certain value that a validator must put forward as a guarantee of honest work: if validators try to deceive the system, they will lose their share. The share can be computing power, cryptocurrency or reputation.
You may ask a logical question: why would they risk their own resources? The fact is that there is a special system of rewards for work here. Typically, rewards are issued in the form of native protocol tokens, and funds for them are taken from user fees and newly created cryptocurrency, or sometimes both.
Another important feature is transparency to identify fraudulent activities. Producing blocks should be expensive, and checking the work done should be cheap and accessible to ordinary users. Thus, anyone can check and monitor the work of validators.
Types of Consensus Algorithms
Proof of Work (PoW)
Proof of Work (PoW) became the progenitor of all other consensus algorithms on the blockchain. It was first implemented in Bitcoin, but the concept itself appeared long before that. In Proof of Work, validators (called miners) hash the data they want to add until they get a suitable solution to a cryptographic puzzle.
A hash is a random set of letters and numbers that is created when data is processed through a hash function. If you hash the same data again, you will get the same result, but if you change even one value, the hash will become completely different.
By looking at the output, you won't be able to tell what information was passed through the function. For this reason, hashes are great for proving something you knew before a certain time. You can give someone such a hash, and then provide the initial information so that the person can run it through the function and see if the output matches.
In Proof of Work, the protocol sets the conditions for confirmation (validation) of a block. For example, you can set that only the block whose hash starts with 00 will be valid. The only way for a miner to create a valid block is to simply iterate over the input data. Validators configure the program to produce different results each time it is hashed until the correct hash is generated.
In large blockchains, it is extremely difficult to find a suitable hash: you will need a whole warehouse of special equipment to hash a large amount of data (with ASIC type units) in order to be competitive and be able to create a valid block.
In mining, the stake is the cost of such equipment and the electricity spent on the work. ASIC (Specific Purpose Integrated Circuit) type hardware is designed for one task, so it cannot be used for anything other than cryptocurrency mining. The only way to recoup the initial investment is through mining and rewards for successfully adding a block.
For the network, it is enough to make sure that you actually created the correct block. Even if your ASICs performed trillions of combinations to get the correct hash, to check its correctness it is enough to pass the data through the function once. If your data produces a valid hash, the block will be accepted as valid by the network and you will receive a reward. Otherwise, the network rejects your request to add a block and you can say that you wasted time and electricity.
Proof of Stake (PoS)
Proof of Stake (PoS) appeared in the early days of Bitcoin as an alternative to Proof of Work. The PoS system does not require the participation of miners, the use of special equipment or massive consumption of electricity - an ordinary personal computer will suffice.
In addition, you will have to make your own contribution. PoS does not use an external resource (electricity or equipment), but an internal one - cryptocurrency. Requirements may vary between protocols, but generally there is a minimum amount of funds that grants the owner the right to stake.
During the staking period, funds are blocked in the wallet (they cannot be moved during staking). In most cases, you agree with other validators regarding which transactions will go into the next block. In a sense, validators bid on the block they want to add to the blockchain, but the right to choose the block remains with the protocol.
Validators whose block is selected will receive a portion of transaction fees depending on the size of their stake. The more funds in the wallet have been blocked, the greater the reward will be. However, for attempts to deceive the system and add invalid transactions, attackers risk losing part (or all) of their share. Thus, PoS works similarly to PoW: acting honestly is more profitable than trying to cheat the system.
This mechanism does not provide rewards for validators in the form of newly created coins. With this algorithm, the native currency of the blockchain must be issued in another way, such as through an initial offering (ICO or IEO), or by launching the protocol on PoW and then switching to PoS.
To date, Proof of Stake in its pure form has only been deployed in a few cryptocurrencies with a relatively small network, for this reason it is still difficult to say for sure whether it can become a viable alternative to PoW. Although this algorithm seems theoretically sound, in practice everything happens a little differently.
Once PoS is deployed within a network with a large amount of funds, game theories and various financial incentives come into play in the system. If someone wants to “hack” a PoS system, it will only be with a guarantee of profit, so we can only find out how likely this is on the network.
Large-scale testing of PoS will take place very soon: as part of the Ethereum network update (also known as Ethereum 2.0), the Casper protocol will be implemented.
Other Consensus Algorithms
Proof of Work and Proof of Stake are the most talked about consensus algorithms, but there are many others that have their own advantages and disadvantages. We recommend that you familiarize yourself with them in more detail in the following articles:
Deferred proof of work explained
How Leased Proof of Stake works
Explanation of proof of authority
Explanation of combustion evidence
Clarification of delegated proof of stake
Hybrid Consensus Algorithm
Summary
Consensus mechanisms are vital to the functioning of distributed systems. Many believe that Bitcoin's greatest innovation was its use of Proof of Work, which allows users to agree on a common set of facts.
Consensus algorithms today support not only digital money systems, but also blockchains, allowing developers to run code on a distributed network. They are now the cornerstone of blockchain technology and are critical to the long-term viability of various existing networks.
Of all the consensus algorithms, Proof of Work still remains dominant, for the simple reason that an alternative that is more reliable and more secure has not yet been proposed. However, there is a huge amount of research and development to replace PoW, and we will likely only see more of it.

