Let’s talk consensus!
In centralized systems, agreement among individuals is guaranteed because a single authority imposes the rules and finalizes the decisions.
But what happens in a system where everyone has authority and power is distributed rather than centralized? How does everyone agree on the rules and state of the system? Who gets to propose a new idea, and who approves of it?
This article will explore consensus mechanisms in blockchain and how they facilitate agreement among nodes in the network.
What Is a Consensus Mechanism?
A consensus mechanism is a protocol that facilitates agreement among nodes in a distributed system. Nodes are simply devices or computers that participate in a network.
Blockchain is a type of distributed system. In a blockchain, a consensus mechanism establishes the principles by which the nodes validate and confirm transactions before adding them to the blocks in the chain. The goal is to ensure that, at any point, the state of the blockchain has a single version of the truth.
Consensus mechanisms:
- Prevent issues like double-spending whereby the same digital token is spent twice.
- Establish trust and transparency since all network participants view the same ledger.
- Enhance security by requiring multiple nodes to validate transactions. This prevents data from tampering.
- Eliminate reliance on a central authority.
These functions contribute to the reliability and effectiveness of blockchain technology across various sectors.
The Evolution of Consensus Mechanisms
The earliest consensus mechanisms were permissioned, meaning a single organization decided which nodes could join the network. Now, this goes against the core principles of blockchain and Web3, which emphasize decentralization and transparency.
In response, permissionless consensus mechanisms emerged, allowing anyone to participate in the network without needing approval from a central authority. Proof of Work (PoW), introduced by Bitcoin, became the first permissionless consensus protocol. However, PoW demands significant computational power and has a slower speed of reaching consensus. These inefficiencies have led to the development of alternative consensus mechanisms like Proof of Stake (PoS), which aim to be more sustainable and faster.
Popular Consensus Mechanisms
Most Layer 1 blockchains use Proof of Work or Proof of Stake. Other mechanisms are also used, each with its own unique pros and cons.
Proof of Work (PoW)
In PoW, participants, known as miners, compete to find a special number called a nonce. This number, when combined with the block’s transaction data and passed through a hashing function, produces a unique number known as a hash. The hash must meet a certain requirement, like starting with a specific number of zeros.
The complexity lies in the trial-and-error process of adjusting the nonce and repeatedly hashing the block's data until the correct combination that produces the correct hash is found. That’s where the “work” comes from. This process requires lots of computing power, as you would imagine.
The first miner to find the correct nonce broadcasts their solution to the network. Other miners verify the correctness of the solution. Once a majority of the network agrees, the block is added to the blockchain, and the miner is rewarded in cryptocurrency.
Pros:
- Highly secure because for any bad actor to alter transactions or control the network, they would have to invest in significant resources (computational power and energy), which would not be economically feasible considering the potential gain.
- Fully decentralized.
- Proven track record with Bitcoin, Litecoin, and other major cryptocurrencies.
Cons:
- Energy-intensive, which has raised environmental concerns. (In 2022, Bitcoin, which has the largest number of miners compared to any blockchain network, had an electricity consumption higher than that of Finland.)
- Slower transaction speeds. It can take as long as 10 min to verify and add a new block.
- Mining equipment can be expensive, leading to centralization where only large-scale miners dominate.
- Gas fees can be expensive.
Proof of Stake (PoS)
PoS was introduced as an energy-efficient and low-cost alternative to PoW. Instead of miners who require computational power to create new blocks, validators are chosen based on the number of cryptocurrencies they hold and are willing to "stake" as collateral. The more coins a validator stakes, the higher their chances of being randomly chosen to validate the next block.
Once a validator proposes a new block, other validators verify its accuracy before adding it to the blockchain. If the block is valid, the original validator receives transaction fees as a reward. However, if the validator acted dishonestly or proposed invalid blocks, their stake is at risk of being "slashed" or lost. Blockchains that use PoS include Ethereum 2.0, Cardano, and Polkadot.
Comparison of Validation between PoW and PoS:
In PoW, a miner’s block is correct if it produces the correct hash that meets the network’s criteria. On the other hand, in PoS, a validator’s block is valid if it complies with the protocol’s rules, such as ensuring no double-spending and verifying that the block structure and its headers are correct.
Pros:
- Energy efficient since validating block transactions only requires stacking.
- Faster transactions. New blocks are created within seconds.
- Lower costs in terms of gas fees and equipment.
- Encourages holding and staking of cryptocurrency, which stabilizes the network.
Cons:
- Validators with large stakes have more influence, potentially leading to centralization.
- Less secure because owning at least 51% of the tokens gives you a higher chance of manipulating transaction validation.
Delegated Proof of Stake (DPoS)
DPoS is a variation of Proof of Stake where token holders vote for a small number of delegates (also called witnesses) to validate transactions and create new blocks on behalf of the network. The voting power is proportional to the amount of cryptocurrency each user stakes. Delegates can be voted out if they misbehave or underperform. If they perform well, they are rewarded using transaction fees. Several blockchains, including EOS and TRON, use DPoS.
Pros:
- Fast and scalable due to the limited number of delegates.
- Lower energy consumption, similar to PoS.
- Democratic, as users have the power to vote for their representatives.
- Allows for on-chain governance.
Cons:
- Can become centralized if a few delegates consistently receive the majority of votes.
- Potential for vote buying.
Practical Byzantine Fault Tolerance (PBFT)
In the previous consensus mechanisms we have explored, nodes typically compete or cooperate to validate transactions. But what if some nodes act maliciously or fail? PBFT guarantees consensus even if up to one-third of the nodes are faulty or malicious.
In PBFT, nodes are organized into primary (leader) and secondary (replica) nodes. After a successful transaction, the primary node proposes the block containing the transaction to the network. The process is divided into three phases:
- Pre-prepare: The primary node sends a “pre-prepare” message to the replica nodes, indicating the proposed block.
- Prepare: The replica nodes receive the message, verify the block’s contents, and then broadcast a “prepare” message to other nodes in the network indicating their agreement that the block is valid.
- Commit: Once a node receives matching "prepare" messages from two-thirds of the nodes, it broadcasts a "commit" message to finalize the block.
This structure allows for quick consensus even in the presence of faulty nodes while providing strong finality. PBFT is commonly used in permissioned blockchain networks such as Hyperledger Fabric, where the participants are known.
Pros:
- High fault tolerance since it can handle up to one-third of malicious nodes.
- High transaction throughput with low latency.
- Transactions have finality once committed, meaning they cannot be altered.
Cons:
- PBFT can face scalability issues as the number of nodes increases due to high communication overhead.
- The protocol can be complex to implement and understand.
- Limited use cases due to its structure that favors permissioned blockchains.
Proof of Authority (PoA)
Proof of Authority replaces mining and staking with a small group of trusted validators, known as authorities. Validators are chosen based on their reputation and reliability within the network. Their identity is also made public to ensure accountability.
Validators take turns proposing and validating new blocks. When a transaction occurs, it is submitted to one of the authorized validators, who then verifies its accuracy. Once validated, the transaction is added to a block in the blockchain. The participants can only trust the authority that the transactions added to the blocks are valid.
PoA is often used in private or permissioned blockchains where a central entity or consortium controls the network and can guarantee the trustworthiness of validators. VeChain and various Ethereum testnets such as Rinkbey use PoA.
Pros:
- Highly efficient with fast transaction times due to the limited number of validators.
- Low energy consumption.
Cons:
- Centralized, as only a few trusted validators control the network.
- Validators need to maintain high reputational standards to preserve trust.
- Limited scalability and may not be suitable for large-scale public networks where many participants are needed for true decentralization.
Other Emerging Consensus Mechanisms
- Proof of Elapsed Time (PoET): Validators are chosen randomly based on waiting time. Hyperledger Sawtooth uses this mechanism.
- Proof of History (PoH): A cryptographic timestamping method used by Solana to order transactions before consensus is reached.
- Proof of Burn (PoB): To earn mining rights, validators must "burn" or remove coins from circulation.
- Proof of Capacity (PoC): Also called Proof of Space, this mechanism requires validators to use their storage space to mine new blocks (e.g., Chia).
- Proof of Storage (PoStorage): Nodes earn the right to validate transactions based on the amount of data they store for the network. It’s used by blockchains that promote decentralized data storage, such as Filecoin.
Conclusion
Consensus mechanisms enable blockchains to agree on the validity of transactions without relying on a central authority. Whether Proof of Work, Proof of Stake, or emerging alternatives, each method offers unique advantages and addresses specific challenges. The consensus mechanism that a blockchain uses determines its security, scalability, energy efficiency, and overall performance.