Channel: CodeSection,代码区,网络安全 - CodeSec
Viewing all articles
Browse latest Browse all 12749

The Beauty of Consensus


Would you rather have a decision validated for you by one person in charge or a wide array of individuals who have reached a general agreement? Most would prefer the latter. It is common sense that corruption would be reduced if a leader, head or decision-maker had to win over the support of, say, a 100 more decision-makers. That is one of the ways blockchain prevents fraudulent behaviors.

Blockchain technology would not be lauded around the globe if it were not for its consensus. The basic concept of blockchain is not difficult to grasp. Blockchain is a database validated by a decentralized community that has to reach a consensus before the contract is enacted.

Before Bitcoin, many systems failed because they could not find a solution to the Byzantine Generals’ Problem. This is a classic problem faced by any distributed computer system network.

What is the Byzantine Generals’ Problem?

Imagine the Byzantine empire wants to capture a city, but they are met with resistance from the opposite end. The Byzantine army has many divisions and each of it has a general. The generals and lieutenants communicate between each other through messengers only and the generals have to agree to either attack or retreat. If the attack or retreat is done half-heartedly, it will lead to defeat.

There is no guarantee that all messengers, generals or lieutenants are loyal to the empire and will pass the right instructions. The corrupt person could try to deceive the other generals to retreat instead of attack, dooming the Byzantine Empire. Without receiving correct instructions, how can we ensure victory in this battle?

In the case of blockchain, the above dilemma is even more difficult to crack as all participants involved are of equal hierarchy. Instead of needing to reach verification and agreement between two parties, now a blockchain system needs all participants to approve, while also neutralizing corrupt players. The agreement between all of these participants is known as consensus.

The Solution

The solution to the Byzantine Generals’ Problem is not simple by any means. It involves some hashing, heavy computing work, and communication between all of the participants (or generals, as in the above example) to verify the message. This solution is a consensus mechanism and there are a variety of consensus mechanisms which can solve the Byzantine Generals’ Problem.

Proof of Work

Most of today’s blockchains, including Bitcoin, use the Proof of Work (PoW) algorithm, a requirement that expensive computation or mining needs to be performed to verify a transaction and add it to a block. However, this comes with fundamental flaws. PoW has well-documented challenges that threaten to be fatal such as reports claiming that miners who work to validate transactions on blockchains employing PoW consume approximately 0.32% of all electricity produced globally per year. These global energy and environmental concerns have encouraged users to turn to other consensus mechanisms like Proof of Stake (PoS) as a result.

In addition, people and organizations that afford faster and more powerful ASICs usually stand a better chance at mining than others. It is because of this that blockchain companies running on PoW are not as decentralized as it should be. Let’s say, 65% of the hashrate is divided amongst 5 mining pools as in the graph below. Theoretically, bigger mining pools can team up with one another and launch a 51% on the Bitcoin network.

The Beauty of Consensus
Source: blockchain.com Proof of Stake

Proof of Stake (PoS) is a low-cost, low-consuming alternative to PoW algorithm. Blockchain networks employ PoS mechanism to achieve a unified agreement on blocks efficiently while retaining a large validator pool for network security. Proof of Stake is based on validators staking and locking a number of tokens in escrow, thereby giving them the right to become a validator. Ethereum is planning to move on from Proof of Work to Proof of Stake soon.

In PoW, where it is expensive and time-consuming, it is less likely for a malicious miner to stray from the main chain and force a hardfork, especially since it could be rejected by the network anyway. However, with PoS, if you are a validator, you can put your money in both chains without fear of repercussions. Either way, you will win. This is called the “Nothing at Stake” Problem. Ethereum has found a way to deal with this issue by adapting the Casper protocol. Casper is different from other PoS protocols because they can punish all malicious elements. For instance, if a validator tries to pull a “nothing at stake” and is caught acting in a violating manner, their staked tokens are forfeit and will be destroyed; this process is called ‘token slashing’. The staking/slashing model gives validators a very large economic incentive to cooperate rather than cheat when acting in the validator role.

In conclusion

There are more consensus mechanisms than PoW and PoS, including mechanisms used by EOS (Delegated Proof of Stake or DPoS) and NEO (Delegated Byzantine Fault Tolerance or dBFT). There are newer consensus mechanisms coming up every now and then, all of which are hoping to achieve the objectives of collaboration, egalitarianism, inclusion etc. Consensus is used to create a more equal and fair society for users from all around the world.

Viewing all articles
Browse latest Browse all 12749