The consensus algorithm is a mechanism that allows users or machines to coordinate relationships in a distributed environment. It requires ensuring that all agents in the system can ultimately agree on a single source of truth (even if some agents disagree). In other words, the system must have good fault tolerance (see also "Byzantine Fault Tolerance Detailed").
In a centralized environment, a single entity has control over the entire system. In most cases, these entities are often able to change the system at will because they fail to create a well-defined governance system that allows many administrators to reach a consensus.
But if it is in a decentralized environment, it is a completely different story. Assuming we are using a distributed database, how do we agree on which entries to add?
This environment is full of strangers who do not trust each other. How to overcome this challenge may be the key to solving development problems and pave the way for blockchain. In this article, we will look at the importance of consensus algorithms for running cryptocurrencies and distributed ledgers.
In a cryptocurrency environment, user balances are recorded in blocks chain in this database. It is critical that every user (more precisely, every node) maintains the same copy of the database. Failure to do so will ultimately lead to information conflict issues that undermine the entire purpose of the cryptocurrency network.
Public key cryptography ensures that users cannot use 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 a proof-of-work system as a way to coordinate participants. We’ll go into more detail about how Proof of Work works later. Now, let’s first understand the common characteristics of various existing consensus algorithms.
First, we need users who want to add blocks (also known as validators) to stake stake. Validators must stake equity of some value to prevent them from committing fraud. Once they cheat, they will lose their staked rights. For example, losing computing power and cryptocurrency, or even losing your reputation.
Then why do they risk their own resources? Because there is also a reward mechanism in this process. Rewards are typically the protocol’s native cryptocurrency. Rewards may also be fees paid by other users, newly generated cryptocurrency units, or both.
Finally, we need to ensure transparency. We need to have the ability to detect cheating in a timely manner. In theory, producing blocks costs a lot, but verifying their authenticity is quite cheap. Through this mechanism, ordinary users can easily constrain validators.
Proof of Work (PoW) is considered the godfather of blockchain consensus algorithms. This mechanism has been used for the first time 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 repeatedly will always give the same output. However, if you change even a small detail, the resulting hash value will be completely different.
It is impossible to infer what information is input into the function from the output alone. Therefore, this method is effective in proving that you knew a certain piece of data before a specific point in time. You can tell someone the hash beforehand, and when you reveal the data later, that person can just run the function and see that the output is the same.
In proof-of-work, the protocol specifies the conditions that make a block valid. For example, it may stipulate that only hash values starting with 00 are valid blocks. The only way for a miner to create a block that matches this combination is to brute force the input. They adjust the data parameters and test every guess with different results until they get the correct hash value.
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 the conditions for producing valid blocks.
During the mining process, your stake includes the cost of purchasing the machine and the electricity required to run the machine. Application Specific Integrated Circuits (ASICs) are built specifically for cryptocurrency mining and are useless for other applications. The only way you can recoup your initial investment is through mining, and if you successfully add new blocks to the blockchain, you can reap considerable rewards.
The network can easily verify the authenticity of the blocks you create. You might need to try trillions of combinations to get the hash value right, but validating data only requires a single hash function calculation. If your data produces a valid hash, the network will accept it and you will be rewarded for it. Otherwise, the network will reject the value and all your time and power will be wasted.
In the early days of Bitcoin, Proof of Stake (PoS) ) is considered an alternative to proof of work. In a proof-of-stake system, there is no concept of miners, specialized hardware, or massive energy consumption. All you need is an ordinary computer.
However, this is not always the case. You also need some capital. In a proof-of-stake mechanism, while no external resources (such as electricity or hardware) need to be consumed, internal resources, namely cryptocurrency, must be provided. The rules of each protocol are different, but generally there is a minimum investment amount that you must meet to be eligible to stake.
Once you complete this operation, the funds in your wallet will be locked (funds cannot be moved while staking). Generally speaking, you need to agree with other validators on which transactions will go into the next block. In a sense, this is equivalent to betting on which block will be selected, and the protocol will only choose one of the blocks.
If your block is selected by the protocol, you will receive transaction fees proportional to the amount of staked stake. The more funds you lock up, the greater your returns. If you attempt to cheat and propose an invalid transaction, you will lose some (or all) of your stake. Therefore, we operate a mechanism similar to proof of stake, wherehonesty and trustworthiness can gain more than cheating.
Generally speaking, validator rewards will not be issued in the form of newly minted tokens. Therefore, the blockchain’s native currency must be issued in some other way. This could be through an initial offering (i.e. ICO or IEO), or by launching the protocol with Proof-of-Work and then transitioning to Proof-of-Stake.
To date, pure proof-of-stake has only been deployed in smaller cryptocurrencies. Therefore, it is unclear whether it can serve as a viable alternative to proof-of-work. While it works in theory, in practice it's nothing like that.
Once the proof-of-stake mechanism is implemented on a network with a large amount of value, the entire system becomes an arena filled with 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 determine whether it is feasible is to apply it to an online network.
Proof-of-Stake will soon 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.
Proof-of-work and proof-of-stake are currently the most discussed consensus algorithms. But there are many other algorithms besides this, and each has its own pros and cons. For details, please read the following articles:
The mechanism for reaching consensus is crucial to the operation of distributed systems. Many people believe that Bitcoin's biggest innovation is the use of proof of work, a mechanism through which users can often 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 occupy a cornerstone position in blockchain technology and play a vital role in the long-term viability of various existing networks.
Among all consensus algorithms, proof of work occupies a dominant position. No one has yet proposed a more reliable and safer alternative solution. Having said that, professionals are still developing a number of products to replace proof of work, and we can expect to see more alternative solutions emerge in the coming years.