In the third article in the blockchain series, I will answer the following questions:
- What is a consensus algorithm in blockchain?
- What are its most important applications in cryptocurrencies?
- What are the algorithm types?
We will also learn what a network validator is and describe the Byzantine Generals' Problem. If you want to learn more about blockchain, check out the previous articles:
The Guide to Blockchain: How Does It Work?
Blockchain: A Deep-Dive into Its Future
Sit comfortably, grab your favorite coffee, and let's start the journey!
Consensus Algorithm: What Is It?
The blockchain consensus algorithm is a set of rules by which nodes reach an agreement when approving transactions.
Without clear and transparent rules defining the operation of the agreement in a distributed network, blockchain would make no sense and nodes would not be able to add new blocks to the blockchain in a strictly defined manner. Adding new blocks is associated with a reward for nodes that validate a given network. Without this award, no one would want to lose their computing power, and thus waste electricity (Proof-of-Work or PoW) or deposit their funds (Proof-of-Stake or PoS) in a place other than their pocket. The consensus algorithm is at the heart of the operation of distributed and decentralized databases.
In traditional solutions, in order to confirm transactions, there must be a third party collecting the data to allow one to decide which version of events presented by the process participants is valid. With the blockchain technology, it is not needed as it is replaced by a consensus algorithm.
In the context of cryptocurrencies, the consensus algorithm ensures compliance with the rules of the protocol. It guarantees that all transactions are carried out correctly, so that the funds cannot be spent twice. Thus they solve the Problem of Byzantine Generals.
What Are the Byzantine Generals' Problem and the Tolerance of the Byzantine Defects?
The Byzantine Generals' Problem is a well-known concept in distributed computing systems created and formalized by an American computer scientist, RobertShostak. It is a logical dilemma of several Byzantine generals struggling with communication problems as they try to agree to the joint and coordinated movement of three different armies. Each of the generals has their army in a different place and they must jointly decide whether they want to attack a given point or withdraw from their positions together.
Most of the generals must make the same decisions about whether to attack or retreat for the whole operation to be successful. They communicate with each other by courier (third party). Consequently, the main challenge they face is that messages with the decision may be delayed in time or lost. Even if the courier delivers a message from one general to another, one of the generals may choose to act maliciously and send a false message of their intentions in order to confuse other generals and thus lead to a complete defeat.
Translating the analogies of Byzantine generals into the blockchain network works as follows.
The general is the node,and attack or retreat - is the correct operation of the network. Most nodes in a distributed network must agree and do the same to avoid downtime or failure. This is the only way to achieve consensus in distributed systems. There is no centralized oversight unit here. The nodes decide whether a transaction is true or false, meaning not using a consensus algorithm.
Given the above, the only way to achieve consensus in the blockchain is to have at least ⅔ or more reliable nodes on the network. This means that if the majority of nodes decide to act maliciously, the system is vulnerable to various types of failures and attacks (51% attack).
Along with the problem of Byzantine generals, there’s also the tolerance of Byzantine defects.
It is the ability of a given system to survive and overcome problems known from the dilemma of the Byzantine Generals. In the blockchain world, this means that even if some nodes wanted to act unfairly, the majority of remaining nodes would act justly and detect false intent.
Consensus Algorithm: Application in Cryptocurrencies
There are different types of consensus algorithms in cryptocurrencies. All of them, however, have a few common elements. Nodes that want to be validators of the network and want to be responsible for adding new blocks to the blockchain to get the prize later - must first provide the appropriate fee rate. The rate is collateral as each node maintains an identical copy of the blockchain. In case a node wants to cheat and add a counterfeit block - it will be detected very quickly by other nodes and it will lose its previously deposited rate, as well as reputation and base computing power. In any case, cheating is the least profitable.
The only way you could do it with impunity and add your new counterfeit block to the blockchain is a 51% attack in which we, as a validator or a group of validators, have nodes with computing power over 51% of the network condition.
In reality, it is almost impossible to do, because the costs of such an undertaking for top chains would be unimaginably huge. Scamming the network is - as mentioned before - unprofitable. It is better to act without malicious intent as a validator and get a reward that is composed of the protocol's native cryptocurrency - it consists of fees paid on other users' transactions and from the unit of the given cryptocurrency produced by mining.
What is a Blockchain Validator?
The network validator is a special node (full node) that records the entire state of the blockchain network, noting the details of each transaction. Node validation and consensus maintenance are their primary applications. There are a few other nodes in the blockchain network, but the full node is the most important.
Blockchain Node Types
Apart from the validator, the following node types can also be mentioned:
A light node saves disk space by downloading only selected information. They are used for simplified payment verification. Without a full node, they are useless.
Masternodes - these are nodes similar to full nodes, but are not able to add blocks to the network and are only used to verify and record transaction information.
There are many more types of nodes such as pruned nodes, mining nodes, authority, and lightning nodes. They all have specialized applications, and help networks run faster, be safer and more decentralized.
What Are the Types of Consensus Algorithms?
There are several different types of consensus algorithms. The most popular are Proof-of-Work: Bitcoin network, Ethereum network (before the Merge) and Proof-of-Stake networks: Ethereum (after the Merge), Cosmos, Solana, and Cardano.
Proof-of-Work (PoW) is the first blockchain network consensus algorithm. The theoretical concept already existed before bitcoin was invented. In PoW, validators that can be called miners hash the data they want to add until they create a specific solution. The hash is the result of the hash function. It is just a random string of alphanumeric characters. If you pass the same data through the hash function again, you'll always get the same results. Changing at least one detail will make your hash completely different.
Proof-of-Work is about guessing the hash by brute-force method, to get the reward. For this purpose, cryptocurrency miners are being built. Based on their computing power, cryptocurrency miners solve complicated calculations in order to guess the hash and get a lucrative reward. It's easy to verify that the correct block has actually been created.
Even if you've tried trillions of different combinations to get the right hash, you only need to pass the data through the function once. If your data generate a valid hash, it will be accepted and you will receive a reward. Otherwise, the network will reject your attempt and you will lose time and electricity.
PoW has been criticized for not being eco-friendly. Cryptocurrency miners consume large amounts of electricity. For example, mining bitcoin consumes more energy each year than Finland needs. However, the bitcoin network is one of the most secure networks. It is secured with such computing power that it is practically impossible to launch an attack on the network.
Proof-of-Stake (PoS) - it is much more ecological. It was proposed as a Proof-of-Work alternative in the early days of bitcoin. In Proof-of-Stake, you don't need miners to mine, you don't have to sacrifice your equipment, you just need to block the appropriate amount of a given cryptocurrency for staking. Staking is simply storing funds in a crypto wallet to ensure the stability, security, and operation of the blockchain network. So in short: you block your cryptocurrencies in order to get a reward.
There are many other consensus algorithms - however, the above two are the most popular and used. In addition to them, there are also: Delayed Proof-of-Work (dPoW), Leased Proof-of-Stake, Proof-of-Authority (PoA), Proof-of-Burn (PoB), and various hybrids.
Summary
In this article, I wanted to describe the core of the correct operation of the blockchain network - the consensus algorithm.
At first glance, you can get the impression that its principles of it are not simple, but when you think about the fact that, in short, a consensus algorithm is a list of rules by which nodes decide to add new blocks, you hopefully get the gist of it.
Stay tuned for my next articles for the Monterail blog!