Content

  • Introduction

  • Consensus algorithms and cryptocurrencies

  • Types of consensus algorithms

    • Proof of Work (PoW)

    • Proof of Stake (PoS)

  • Other consensus algorithms

  • Final considerations


Introduction

A consensus algorithm is a mechanism that allows users or machines to coordinate in a distributed setting. It must ensure that all members of a system can agree on a single source of truth, even if some of the members fail. In other words, the system must be fault tolerant (see also: What is Byzantine Fault Tolerance?).

In a centralized setup, a single entity has power over the system. In most cases, she can make changes as she pleases – there is no complex governance system to achieve consensus among multiple administrators.

In a decentralized setting, it is quite different. Let’s say we’re working with a distributed database – how do we reach agreement on which entries to add?

Overcoming this challenge in an environment where strangers do not trust each other was perhaps the most important development that paved the way for blockchains. In this article, we will see how consensus algorithms are vital for the functioning of cryptocurrencies and distributed ledgers.


Consensus algorithms and cryptocurrencies

In cryptocurrencies, user balances are recorded in a database – the blockchain. It is essential that all users (or more precisely, all nodes/nodes) maintain an identical copy of the database. Otherwise, there would be conflicting information, undermining the entire purpose of a cryptocurrency network.

Public key cryptography ensures that users cannot spend other people’s coins. But still, a single source of truth that network participants trust is needed to determine whether funds have already been spent or not.

Satoshi Nakamoto, the creator of Bitcoin, proposed a Proof of Work system to coordinate participants. We will soon explain how PoW works – for now, we will identify some of the common characteristics of the different existing consensus algorithms.

First, we require users who want to add blocks (we’ll call them validators) to provide a stake. The stake is a type of value that the validator must present, which discourages them from acting dishonestly. If they cheat, they will lose their stake value. Examples of staking include computing power, cryptocurrencies or even reputation.

Why would they risk their own resources? Additionally, there is a reward available. Generally, the reward is the protocol's native cryptocurrency and is made up of fees paid by other users, new units of cryptocurrency generated, or both.

The last necessary item is transparency. We need to be able to detect when someone is cheating. Ideally, block production should be expensive, but validation by any user should be cheap. This ensures that validators are constantly checked by regular users.


Types of consensus algorithms

Proof of Work (PoW)

Proof of Work (PoW) is the godfather of blockchain technology consensus algorithms. It was first implemented in Bitcoin, but the concept has been around for some time. In Proof of Work, validators (known as miners) hash the data they want to add until they produce a specific valid solution.

A hash is a seemingly random sequence of letters and numbers created when you submit data through a hash function. However, if you submit the same data again, you will always have the same output. However, if you change just one detail, your resulting hash will be completely different.

Looking at the output, it is not possible to tell what information was entered into the function. Therefore, it is possible to prove that you were aware of a piece of data or information before a certain point. You can give someone a hash, and when you reveal the data later, they can submit it through the function to confirm that the output will be the same.

In Proof of Work, the protocol establishes conditions regarding what makes a block valid. There may be, for example, a condition that says only a block whose hash starts with 00 will be valid. The only way for the miner to create a block that matches this condition is by trying different inputs. They can adjust parameters in their data to produce a different result each time until they get the correct hash.

On major blockchains, the difficulty level is incredibly high. To compete with other miners, you would need a warehouse full of specialized hashing hardware (ASICs) to have a chance of producing a valid block.

When you're doing mining, your stake is the cost of the machines and the electricity needed to run them. ASICs (application-specific integrated circuits) are built for a purpose, so they have no other use than mining cryptocurrencies. Your only way to recoup your initial investment is to mine, which provides a significant reward if you successfully add a new block to the blockchain.

Checking whether you actually created a valid block is a very simple process for the network. Even if you've tried trillions of combinations to get the correct hash, you only need to submit your data through the function once. If your data produces a valid hash, it will be accepted and you will receive a reward. Otherwise, the network will reject the hash and you will have wasted time and electricity.


Proof of Stake (PoS)

Proof of Stake (PoS) was proposed in the early days of Bitcoin as an alternative to Proof of Work. In a PoS system, there are no concepts of miners, specialized hardware and no need for large energy consumption. All you need is a regular computer.

Well, actually it's not just that. Some effort is still required. In PoS, you do not provide an external resource (like electricity or hardware), but rather an internal one – cryptocurrency. Rules vary depending on the protocol, but generally a user needs to maintain a minimum amount of funds to qualify for staking.

From there, you lock your funds in a wallet (they cannot be moved while you are staking). Typically, there is a consensus among validators about which transactions will be inserted into the next block. In a way, you make a bet on which block will be selected. The protocol will choose one of the candidate blocks.

If your block is selected, you will receive a proportion of the transaction fees depending on your stake value. The more funds you have locked, the more rewards you will receive. But if you try to cheat by proposing invalid transactions, you will lose part (or all) of your stake value. Therefore, we have a similar mechanism to PoW – acting honestly is more profitable than acting dishonestly.

Generally, new coins are not created as rewards for validators. The blockchain's native currency must therefore be issued in another way. This can be done through an initial distribution (i.e. an ICO or IEO) or by launching the protocol as PoW, and then transitioning to the PoS system.

To date, pure Proof of Stake has only actually been implemented in smaller cryptocurrencies. Therefore, it is not yet clear whether it can serve as a viable alternative to PoW. Although it seems theoretically correct, in practice it is very different.

Once PoS is implemented on a network with large amounts of value, the system becomes a playing field of game theory and financial incentives. Anyone with the know-how to “hack” a PoS system probably wouldn't do it if they couldn't profit from it – so the only way to find out if it's a viable system is to evaluate a working network in practice.

We will soon see PoS being tested on a large scale – Casper will be implemented as part of a series of upgrades to the Ethereum network (collectively known as Ethereum 2.0).


Other consensus algorithms

Proof of Work and Proof of Stake are the most discussed consensus algorithms. But there are a wide variety of others, all with their own advantages and disadvantages. Check out the following articles:

  • What is Delayed Proof of Work?

  • Algoritmo de Consenso Leased Proof of Stake

  • What is Proof of Authority?

  • What is Proof of Burn?

  • What is Delegated Proof of Stake?

  • PoW/PoS Hybrid Consensus


Final considerations

Mechanisms for achieving consensus are vital for the functioning of distributed systems. Many believe that Bitcoin's greatest innovation was its use of Proof of Work to allow users to agree on a set of shared facts.

Today, consensus algorithms underpin not only digital money systems but blockchains, allowing developers to run code across a distributed network. They now represent the cornerstone of blockchain technology and are critical to the long-term viability of the various existing networks.

Of all the consensus algorithms, Proof of Work remains dominant. A more reliable and secure alternative has yet to be proposed. There is a lot of research related to developing replacements for PoW and we will probably have more proposals emerging in the coming years.