Day 3. Consensus Algorithms

Blockchain operates based on a mechanism called a consensus algorithm, which is used for achieving agreement among participants. In this guide, we will explain these algorithms and reveal the mechanisms within the blockchain.

TOC

Consensus

A ‘consensus algorithm’ is an algorithm used in distributed systems or networks to form an agreement among different participants (Consensus means agreement, and algorithm refers to a procedure for solving problems in English). In the case of blockchain, nodes participating in the network generate new blocks based on a specific algorithm. These generated blocks are verified by other nodes while being propagated throughout the network, maintaining data consistency and preventing data tampering and attacks.

In the case of the famous Bitcoin, the ‘Nakamoto Consensus’ includes elements such as PoW (explained later), the longest chain rule, and Sybil resistance.

What is the Longest Chain Rule?
If an attacker tries to tamper with data after a certain block, the blockchain will fork into two. In this case, the chain that is longer is always considered to be correct. In the case of PoW explained later, it requires more computational power than the majority, making it quite difficult in reality.

What is Sybil Resistance?
Sybil resistance refers to the inability of an attacker, even with multiple accounts, to perform fraudulent activities. In the case of PoW mentioned later, significant computational power is required, making it impractical to do so with numerous accounts (hence, it has Sybil resistance). Similarly, in the case of PoS, also discussed later, it is very difficult because it requires a significant amount of assets as collateral in each of the numerous accounts.

Common examples of consensus algorithms include ‘Proof of Work’ and ‘Proof of Stake.’ These algorithms are used by nodes on the network to reach a consensus and maintain a common transaction history and state.

PoW – Proof of Work

In PoW, participants known as miners engage in computational work (mining) to solve problems in order to add new blocks to the blockchain. This computation involves finding the nonce value, as previously mentioned in the data structure section. Participants compete to find the correct nonce value. The one who solves it can add the block and receive rewards (both block rewards and transaction fees).

When a block is added, other nodes sequentially verify if the solution is correct (this can be done simply by calculating the hash value of the data containing the nonce value). This process allows the new block to spread across the entire network.

As such, adding a block in PoW involves computational work to solve a problem, which prevents fraud (Sybil resistance), motivates miners with rewards, and allows other nodes to easily verify and quickly prove the correctness of the blocks.

Bitcoin is a well-known blockchain that adopts PoW.

PoS – Proof of Stake

One of the challenges of PoW is the need for extensive computer calculations, which require a large amount of electricity, raising concerns about environmental impacts. To address this issue, the PoS mechanism was devised. In PoS, instead of providing computational power, participants offer tokens as collateral (Staking). The mechanism works as follows:

  1. A node to generate the block is chosen randomly.
  2. Other nodes act as validators to verify (approve) whether the block is correct.
  3. Validators receive rewards for their work.

Validators are selected considering the amount of tokens they have staked.
If a validator acts maliciously, the staked tokens are forfeited.

Ethereum 2.0 (Ethereum after The Merge) is a well-known blockchain that adopts PoS.

Let's share this post !

Author of this article

After joining IBM in 2004, the author gained extensive experience in developing and maintaining distributed systems, primarily web-based, as an engineer and PM. Later, he founded his own company, designing and developing mobile applications and backend services. He is currently leading a Tech team at a venture company specializing in robo-advisory.

Comments

To comment

CAPTCHA


TOC