What Is a Blockchain Consensus Algorithm? A consensus algorithm is a mechanism that allows users or machines to coordinate in a distributed setting. It needs to ensure that all agents in the system can agree on a single source of truth, even if some agents fail. In other words, the system must be fault-tolerant (see also: Byzantine Fault Tolerance Explained).
In a centralized setup, a single entity has power over the system. So, in most cases, they can make changes as they please – there isn’t some complex governance system for reaching consensus amongst many administrators.
But in a decentralized setup, it’s a whole other story. Say we’re working with a distributed database – how do we reach an agreement on what entries get added?
Overcoming this challenge in an environment where strangers don’t trust each other was perhaps the most crucial development paving the way for Blockchains. In this article, we’ll take a look at how consensus algorithms are vital to the functioning of cryptocurrencies and distributed ledgers.
Consensus algorithms and cryptocurrency
What Is a Blockchain Consensus Algorithm? In Cryptocurrencies, users’ balances are recorded in a database – the Blockchain. It’s essential that everyone (or more accurately, every node) maintains an identical copy of the database. Otherwise, you’d soon end up with conflicting information, undermining the entire purpose of the cryptocurrency network.
Public-key cryptography ensures that users cannot spend each other’s coins. Network participants still require a single source of truth that enables them to determine whether funds have already been spent.
Satoshi Nakamoto, the creator of Bitcoin, proposed a Proof of Work system to coordinate participants. We’ll get into how PoW works shortly – for now, we’ll identify some of the common traits of the many consensus algorithms in existence.
Firstly, we require that users who want to add blocks (we’ll call them validators) provide a stake. The stake is some kind of value that a validator must put forward, which discourages them from acting dishonestly. If they cheat, they’ll lose their stake. Examples include computing power, cryptocurrency, or even reputation.
Why would they bother risking their own resources? Well, there’s also a reward available. Users typically compose this with the protocol’s native cryptocurrency, comprising fees paid by other users, freshly generated cryptocurrency units, or a combination of both.
The last thing we need is transparency. We need to be able to detect when someone is cheating. Ideally, it should be costly for them to produce blocks, but cheap for anyone to validate them. This ensures that validators are kept in check by regular users.
Types of Consensus Algorithms
PoW is the blockchain consensus algorithm’s parent. It was initially implemented in Bitcoin, but the idea is older. Validators (miners) hash the data they want to add to Proof of Work until they find a solution.
A hash function creates an apparently random stream of letters and numbers. However, running the same data through it again yields the same result. But change one detail and your hash will change dramatically.
The output shows no indication of what was passed into the function. So they’re handy for proving you know data before a given time. When you release the data, someone can run it through the function to ensure sure the outcome is the same after receiving the hash.
In Proof of Work, the protocol defines block validity. It may state that only blocks with hashes starting with 00 are valid. The miner must brute-force inputs to build one that matches that combination. They can change a data parameter to acquire a new hash for each guess until they get it.
Major blockchains set high standards. To compete with other miners, you need a warehouse full of ASICs to produce a valid block.
Your mining stake is the cost of these machines and their electricity. Because of their exclusive purpose, ASICs are useless outside of cryptocurrency mining. The only way to return your initial investment is to mine, which pays well if you add a block to the network.
The network can easily verify that you created the proper block. They just need to run your data through a function once, even if you tried trillions of possibilities to acquire the appropriate hash. Your data will be approved and rewarded if it has a valid hash. Otherwise, the network will reject it, wasting time and electricity.
Proof of Stake (PoS)
What Is a Blockchain Consensus Algorithm? Proof of Stake (PoS) was introduced early in Bitcoin as an alternative to Proof of Work. PoS systems don’t have miners, specialized hardware, or enormous energy consumption. You only need a PC.
But not all. Put some skin in the game. In PoS, you use Cryptocurrency instead of electricity or hardware. Staking requires a minimum sum of funds, but protocols vary.
You then store your funds in a wallet (they can’t be moved while staking). You usually agree with other validators on the next block’s transactions. The protocol will choose a block, and you wager on it.
If your block is picked, your stake determines your transaction fee share. Locking up more funds increases your chances of profit. Cheating by proposing invalid transactions will cost you some or all of your stake. Thus, like PoW, honesty is more profitable than dishonesty.
Validators rarely receive new coins. The blockchain’s native currency must originate from elsewhere, either through an ICO or IEO or by launching the system with PoW before transitioning to PoS.
Tiny coins have predominantly utilized Pure Proof of Stake. Thus, its viability as a PoW alternative is unknown. Though sounds theoretical, it will be drastically different in practice.
Once PoS is implemented on a valuable network, game theory and financial incentives take over. Anyone with the skills to “hack” a PoS system would only do it if they could profit, hence the only way to test it is on a live network. The Ethereum 2.0 network updates will include Casper, which will test PoS on a massive scale.
Other consensus algorithms
Proof of Work and Proof of Stake is the most-discussed consensus algorithms. But there’s a wide variety of other ones, all with their own advantages and disadvantages. Check out the following articles:
-
Delayed Proof of Work Explained
-
Leased Proof of Stake Consensus Explained
-
Proof of Authority Explained
-
Proof of Burn Explained
-
Delegated Proof of Stake Explained
-
Hybrid PoW/PoS Consensus Explained
Closing thoughts
What Is a Blockchain Consensus Algorithm? Mechanisms for achieving consensus are vital to the functioning of distributed systems. Many believe that the greatest innovation in Bitcoin was the use of Proof of Work to enable users to agree on a shared set of facts.
Consensus algorithms today underpin not only digital money systems but also Blockchains allowing developers to run code across a distributed network. They’re now a cornerstone of blockchain technology and are critical to the long-term viability of the various networks in existence.
Of all of the consensus algorithms, Proof of Work remains the dominant offering. An alternative that’s more reliable and more secure has yet to be proposed. That said, there’s a tremendous amount of research and development into replacements for PoW, and we’re likely to see more of them surface in the coming years.