Introduction
A consensus algorithm is a mechanism that allows users or machines to coordinate relationships in a distributed environment. It needs to ensure that all agents in the system can eventually agree on a single source of truth (even if some agents disagree). In other words, the system must be fault-tolerant (see also Byzantine Fault Tolerance Explained).
In a centralized environment, a single entity has control over the entire system. In many cases, these entities can make changes to the system at will because there is no well-defined governance system in place to enable consensus among many administrators.
But in a decentralized environment, it’s a completely different story. Assuming we are using a distributed database, how do we agree on which entries to add?
Overcoming this challenge in an environment filled with strangers who do not trust each other may be the key to solving development problems and paving the way for blockchain. In this article, we will understand the importance of consensus algorithms for running cryptocurrencies and distributed ledgers.
Consensus Algorithms and Cryptocurrencies
In the context of cryptocurrencies, users’ balances are recorded in a database called the blockchain. It is critical that every user (or more precisely, every node) maintains the same copy of the database. Failure to do so will eventually lead to information conflicts, undermining the entire purpose of the cryptocurrency network.
Public key cryptography ensures that users cannot spend other users’ tokens, but there must be a single source of truth that network participants can trust to know whether funds have been spent.
Bitcoin creator Satoshi Nakamoto proposed the proof-of-work system as a way to coordinate participants. We will explain in detail how proof-of-work works later. For now, let’s take a look at the common features of various existing consensus algorithms.
First, we need users who want to add blocks (also known as validators) to stake their interests. Validators must stake an interest of some value to prevent them from cheating. If they cheat, they will lose their staked interests. For example, they will lose computing power and cryptocurrency, and they may even lose their reputation.
So why would they risk their own resources? Because there is a reward mechanism in the process. The reward is usually the native cryptocurrency of the protocol. The reward may also be a transaction fee paid by other users, a newly generated unit of cryptocurrency, or both.
Finally, we also need to ensure transparency. We need to be able to detect cheating in a timely manner. In theory, producing blocks consumes a lot of costs, but the cost of verifying their authenticity is quite low. Through this mechanism, ordinary users can easily constrain validators.
Consensus algorithm type
Proof of Work (PoW)
Proof of Work (PoW) is considered the godfather of blockchain consensus algorithms. The mechanism was first used in the Bitcoin space, but the actual concept has been around for a long time. In Proof of Work, validators (called miners) hash the data they want to add until a specific solution is produced.
A hash is a seemingly random string of letters and numbers created by running data through a hash function. Running the same data over and over will always give the same output. However, changing even one small detail can produce a completely different hash value.
The output alone does not tell you what was input into the function. Therefore, this method is a good way to prove that you knew a piece of data before a certain point in time. You can tell someone the hash value in advance, and later when you reveal the data, they can just run the function and check that the output is the same.
In proof of work, the protocol specifies the conditions that make a block valid. For example, it might specify that a block must have a hash that starts with 00. The only way for miners to create a block that matches that combination is to brute-force the input. They tweak the data parameters, testing each guess and getting different results until they get the right hash.
For the main blockchain, the threshold is often quite high. In order to compete with other miners, you need to prepare a large amount of special hashing hardware (Application Specific Integrated Circuits) to create conditions for producing valid blocks.
In the mining process, the stake you stake covers the cost of purchasing the machine and the electricity required to run it. Application-specific integrated circuits (ASICs) are designed specifically for cryptocurrency mining and are useless for other applications. The only way you can recoup your initial investment is by mining, and if you successfully add new blocks to the blockchain, you can get a considerable reward.
The network can easily verify the authenticity of the blocks you create. You may need to try trillions of combinations to get the right hash value, but verifying your data only requires one hash function calculation. If your data produces a valid hash value, the network accepts it and you get rewarded. Otherwise, the network rejects it and your time and electricity are wasted.
Proof of Stake (PoS)
In the early days of Bitcoin, Proof of Stake (PoS) was seen as an alternative to Proof of Work. In a Proof of Stake system, there are no miners, specialized hardware, or large amounts of energy consumption. All you need is an ordinary computer.
But that’s not always the case. You still need to put some capital in place. In proof-of-stake, while you don’t need to consume external resources (like electricity or hardware), you do need to provide internal resources, namely cryptocurrency. The rules of each protocol are different, but generally there is a minimum contribution that you must meet to be eligible for staking.
Once you have done this, the funds in your wallet will be locked (you cannot move your funds while staking). Typically, you will need to agree with other validators on which transactions will go into the next block. In a sense, this is like placing a bet on which blocks will be selected, and the protocol will only choose one of them.
If the protocol selects your block, you will receive transaction fees proportional to the amount of stake you have. The more funds you lock up, the more benefits you will get. If you attempt to cheat and propose invalid transactions, you will lose some (or all) of your stake. Therefore, we run a mechanism similar to proof of stake, in which honesty is more profitable than cheating.
Generally, validator rewards are not issued in the form of newly minted tokens. Therefore, the blockchain’s native currency must be issued in some other way. This can be done through an initial coin offering (i.e., an ICO or IEO), or by launching the protocol with proof of work and then transitioning to proof of stake.
So far, pure proof-of-stake has only been deployed in smaller cryptocurrencies. As such, it’s unclear whether it can be a viable alternative to proof-of-work. While it may work in theory, it’s anything but in practice.
Once proof of stake is implemented on a network with a lot of value, the entire system becomes an arena full of game theory and economic incentives. As long as there is a profit, those skilled hackers will "hack" the proof of stake system. Therefore, the only way to know for sure whether it is feasible is to apply it to the online network.
Soon, proof of stake will be tested at scale, and the Ethereum network is about to implement a series of upgrades (collectively known as Ethereum 2.0), including the implementation of Casper.
Other consensus algorithms
Proof of Work and Proof of Stake are the most discussed consensus algorithms. But there are many other algorithms, each with its own pros and cons. For more information, please read the following articles:
Delayed Proof of Work Explained
《Leased Proof of Stake Consensus Explained》
《Detailed Explanation of Proof of Authority》
《Detailed Explanation of Proof of Destruction》
《Detailed Explanation of Delegated Proof of Stake》
Hybrid Proof of Work/Proof of Stake Consensus Explained
Summarize
Mechanisms for reaching consensus are critical to the functioning of distributed systems. Many consider Bitcoin’s greatest innovation to be its use of proof-of-work, a mechanism by which users tend to agree on a set of shared facts.
Today, consensus algorithms have become the foundation of digital currency systems and blockchains, allowing developers to run code on distributed networks. Consensus algorithms are the cornerstone of blockchain technology and are crucial to the long-term viability of existing networks.
Among all consensus algorithms, proof of work is the dominant one. No one has yet proposed a more reliable and secure alternative solution. That being said, professionals are still developing a lot of products to replace proof of work, and we can expect to see more alternative solutions emerge in the next few years.

