Blockchain is a distributed and decentralized network that ensures the immutability, privacy, security, and transparency of transactions between two parties. In other words, there is no central authority to verify and validate these transactions.
A consensus algorithm is a mechanism that ensures users maintain coordination while in a distributed setting. It ensures that all parties in the system agree on a single truth, irrespective of whether a party fails or not. By implication, this consensus algorithm ensures a system is false tolerant.
Meanwhile, in a decentralized setup, the story is different. Overcoming the challenge of reaching consensus in a decentralized network where strangers don’t trust each other was the crucial s
event that ushered in blockchains’ development. Let us look at how a consensus algorithm is vital to the functioning of cryptocurrencies and blockchain technology.
Cryptocurrency and Consensus Algorithm.
In a cryptocurrency transaction, users’ balances are recorded on the blockchain. Every user (node) must hold an identical copy of the database; otherwise, users will have conflicting information. Having conflicting information undermines the entire purpose of the cryptocurrency network. With public-key cryptography, users cannot spend each other’s coins. However, there still needs to be a single source of “truth” that network participants rely on to determine whether funds have already been spent. Satoshi Nakamoto, the originator of Bitcoin, proposed the proof-of-work consensus algorithm to coordinate network participants.
In the course of this article we will discuss the different consensus protocols. Before we explore these consensus algorithms, let us consider the different characteristics of most of the consensus algorithms in existence.
Users that want to add blocks to a blockchain network (validators) provide a stake to the network. The stake is a kind of value (collateral) that a validator must forward to prevent him/her from acting fraudulently. If a validator cheats, he/she will lose his/her stake. Examples of stake include computing power, cryptocurrency, reputation, etc.
Validators would not bother to risk their resources or reputation if there was nothing to gain in the first place. Therefore, in a consensus algorithm, there is a reward available. It is usually made of the protocol’s native cryptocurrency and consists of fees paid by other users on the network, newly generated cryptocurrency units, or both.
The last general trait of consensus protocols is transparency. Users must be able to detect when someone is cheating. It should be costly for scammers to produce blocks but cheap for anyone to validate these blocks in an ideal sense. Therefore, the consensus algorithm ensures that network validators are kept in check by regular network users by being transparent.
Types of Consensus Algorithms
1 Proof-Of-Work (PoW) Consensus Algorithm
This is the pioneer of blockchain consensus algorithms and was first implemented in Bitcoin. However, the actual concept has been around for quite some time. In proof-of-work, validators (called miners) hash the data they want to add until they solve a particular problem. Hashing is the process of generating a specific amount of output from an input of a different size. Hashing is done through a mathematical formula called “hash function.” You create a “hash” when you run data through a “hash function.” If you run the same data through the hash function again, you will still have the same output. If you as much as change one detail, your hash will be completely different. By merely looking at the output, there is no way to tell the kind of information fed into the function. It serves as proof that you knew a piece of data before a particular time. You can give someone a hash, and when you reveal the data, the person can cross-check the function to make sure the output is exact. In the proof-of-work consensus protocol, the algorithm sets the conditions for what constitutes a valid block. For example, the proof-of-work consensus protocol might say that only blocks whose hash starts with “oo” will be valid. As a miner, the only way for you to create a block that matches this combination is to brute-force inputs. A miner can tweak a parameter in their data to generate a different outcome for every guess until they get the correct hash. When it comes to the major blockchains, the standard is set incredibly high. To compete favorably with other miners, you will need a warehouse filled with special hashing hardware (ASICs) to stand a chance of generating a valid block. These Application-Specific Integrated Circuits (ASICs) are specifically designed for cryptocurrency mining purposes; therefore, they have no use outside cryptocurrency mining. When mining, your stake is those machines’ cost and the electricity required for you to run them. As a miner, your only way to recoup your initial investment is to successfully mine and add a new block to the blockchain. The reward is huge and worth all the investment and “trouble” of mining. Once the network runs your data through a function, it will tell if you have generated a valid hash or not. If it is a valid hash, it will be accepted, and you will be rewarded. If your data doesn’t produce a valid hash, it will be rejected, and you would have wasted time and enormous resources for nothing.
2 Proof-of-Stake (PoS) Consensus Protocol
It was proposed in the early years of Bitcoin as an alternative to the proof-of-work protocol. In the PoS system, you don’t need to become a miner, and neither do you need specialized hardware or massive energy consumption. You only need to have your regular personal computer. Also, you need to have good knowledge of the process. In proof-of-stake consensus protocol, you don’t need an external resource like hardware and electric power, but you need to have an internal resource (cryptocurrency). Although rules differ with every consensus protocol, there is generally an agreed minimum amount of money you must hold to qualify for staking. You can lock your fund in a wallet from where it can be moved while you are staking. Typically, you will have to reach an agreement with other validators on what transactions will go into the next block. In the real sense of it, you are betting on a particular block that will be selected while the protocol chooses one. If your block is selected, you will be given a part of the transaction fees, depending on your stake. Therefore, the more funds you have staked, the more you stand to gain if your block is selected. In an event where you try to cheat by proposing invalid transactions, you will lose part or all of your stakes. Just like the proof-of-work, PoS ensure that acting honestly is more rewarding than acting dishonestly.