Why we need consensus algorithms
Consensus algorithms are paramount to the blockchain. Let’s look at an example to illustrate this.
Chuck is a nefarious buyer looking to spend some of his cryptocurrency. We’ll call the currency BadCoin. He finds two merchants that accept BadCoin: Alice and Bob. Chuck goes ahead and purchases a pineapple from Alice. He then purchases a rubber duck from Bob using the same coin. Both transactions enter a pool of unconfirmed transactions.
Both Alice and Bob, excited for the sale, ship their products immediately. Unfortunately, the system will only confirm one of the transactions (Chuck only had enough to spend on one sale). One of them is down a product without any payment. This is the double spending problem, and one that Bitcoin has managed to solve.
To combat this problem, cryptocurrencies employ consensus mechanisms. This is important, because unlike banks that are a central authority that verify transactions, cryptocurrency transactions need to be verified by a decentralised, trustless network of nodes. Consensus means that the nodes on the network agree on the same state of the blockchain.
Sometimes the blockchain splits, where one chain contains blocks with transactions, and another chain also contains blocks with transactions. The longest chain is regarded as the “correct” chain, as the greatest effort has been invested in it. All the transactions in the second chain re-enter the pool as unconfirmed transactions once the network decides to proceed with the longer chain. It makes sense to abandon the secondary chain, as any computing power exerted to extend this chain will be wasted. Therefore, it’s important to wait for several “confirmations” before being sure that your transaction was successful.
A confirmation is the addition of a block onto the blockchain. For Bitcoin, 6 confirmations are usually enough to be sure your transaction is in the primary chain. At around 10 minutes per block, it’s roughly 60 minutes for 6 confirmations.
Now that we know why we need consensus algorithms. Let’s look at some of the most popular implementations by cryptocurrencies today.
This is likely one you would have heard about before. Well-known coins like Bitcoin and Ethereum both use PoW for their consensus algorithm. Ethereum plans to move to Proof of Stake at some point in the future. In a PoW system, nodes need to perform computationally intensive mathematical equations. These equations are time-consuming to compute, but the result is trivial to verify.
For example, say I ask you to determine the factors of 3,901 where each factor is higher than 40. You’ll need to iterate through all the possible numbers over 40 to determine which two, when multiplied, result in 3,901. This is the “work”/”mining” part that the nodes are competing to solve. Once a node has the answer, is broadcasts it to the other nodes. If a node tells you the answer is 83 and 47, it’s a trivial task to see if they’re right. Simply check if the numbers are more than 40, and multiple them. If all nodes agree, the block is added and the node with the answer is rewarded.
In the case of Bitcoin, the puzzle is to determine which number (nonce – number used once) to add to a list of transactions, so that the hash of the block starts with a certain number of zeros. The complexity and required computing power increases as the required number of zeros increases.
A hash of a string of data reduces it to a fixed length output. Bitcoin uses the SHA-256 function, which produces a 64-character string for any input.
As computing power increases, these puzzles are solved more easily. This is why Bitcoin employs a mechanism that increases difficulty (e.g. requiring a larger number of starting zeros for hashes) if it recognises that blocks are being determined too quickly.
PoW is not without its faults: it consumes large quantities of power.
In the PoS approach, the network requires nodes (minters) to stake a portion of the coins they hold. The more currency being staked, and the longer it’s been staked, the higher the chance that the minter will be chosen to confirmation (mint) the block.
Minters staking the most coins are the preferred nodes to complete blocks, as they have the greatest interest in seeing it succeed. These minters also have their stakes slashed if the system detects that they are being fraudulent. It’s thus in their best interest to remain honest, or risk losing their entire stake.
Unlike PoW systems where miners are rewarded for being first to solve the puzzle (thereby creating more coins), in PoS, the minter is rewarded with the transaction fees paid.
PeerCoin is an example of a coin that makes use of PoS.
Delegated Proof-of-Stake (DPoS)
Steem.it and EOS are examples of cryptocurrencies that employ DPoS. It’s similar to PoS, but instead of requiring users to stake their coins, all token holders vote for a select few “delegates”. These delegates are in charge of confirming transactions.
The weight of the token holder’s vote depends on the number of tokens the account holder possesses. It’s important that these token holders vote for delegates that have the system’s best interest at heart. Some DPoS systems also require the selected delegates to deposit their funds in a time-locked account (called deposit-based proof of stake) to show their commitment, and to dissuade malicious behaviour.
It’s important to note that while the system decentralised, there is still an element of centralisation.
Byzantine Fault Tolerance (BFT)
BFT aims to solve the Byzantine Generals’ Problem by allowing nodes to communicate safely, and be sure that the intended message has reached other nodes. Byzantine Fault Tolerance means that a system can still achieve consensus in the presence of Byzantine faults, a category of faults where nodes may be malicious.
Both Ripple and Stellar have implemented BFT in their systems.
BFT, like PoS, also has an element of centralisation.
Interesting note: airplane engine systems and nuclear power plants both employ the use of BFT. These systems receive feedback from a number of sensors, and make critical decisions based on these responses.
Other consensus mechanisms
There are several other algorithms:
- Proof of Burn
- Proof of Brain
- Direct Acyclic Graphs (DAGs) – IOTA’s Tangle is a type of DAG
- Proof of Elapsed Time (PoET)
Not all feedback has been good. Some of these options will only become viable once they’ve been through rigorous testing and usage. Programmers will develop more of these consensus algorithms as blockchain technology progresses and matures.
Disclaimer: I am not a financial advisor, and none of the content on this website should be construed as financial advice. The crypto market is highly volatile, and you should do your own thorough research before making any investments.