Learning Crypto #2: Consensus

Perrybiz
5 min readFeb 6, 2022

--

  1. Consensus
  2. Proof-Of-Work
  3. Chain selection
  4. Proof-Of-Stake
  5. Other mechanisms

Consensus

Consensus is one of the most important concepts in the blockchain. It’s the mechanism that is used to agree on the state of a blockchain at a particular time. As discussed in the last post, blockchain is distributed and operated by a number of nodes. Each node has a copy of the existing blockchain and adds new blocks to the end of the chain by processing the transactions, then eventually broadcast to the whole network so that other nodes can follow up. If any node does not follow the consensus mechanism, then it will be considered as “trustless” and get kicked out of the blockchain.

This consensus mechanism can be broken down into two main concepts:

  1. Chain selection algorithm
  2. Sybil resistance mechanism

Sybil resistance mechanism gives the blockchain the ability to defend against users who created a large number of sudo-anonymous identities, to gain a disproportional advantage of influence over the blockchain network. In short, it avoids users to create a bunch of fake nodes so that they can get more block rewards. We will discuss what block rewards are later in this article.

Proof-Of-Work

Proof-Of-Work(POW) is a Sybil resistance mechanism, it involves a computationally expensive process to solve a cryptographical problem. The node that solves this problem first will get the block rewards we mentioned earlier, which consists of a number of BTC. This is the “mining” process.

From this, even a particular user created a large number of fake nodes, each of them still needs to perform this computationally expensive activity to find the cryptographical problem.

You might be curious about what this cryptographical problem is and why it is so computationally expensive, I will try my best to explain it in simple terms:

The reason why the blockchain is called blockchain can be explained by this image:

From the BTC whitepaper

I know it is very confusing (at least for me when I saw this diagram for the first time), so I have a better example:

https://andersbrownworth.com/blockchain/tokens

I strongly suggest you go to https://andersbrownworth.com/blockchain/tokens and play around with it, it is one of the best introduction websites if you are new to blockchain.

As you can see, each block contains the hash code of the previous block (the “Prev” field in block #2 matches the “Hash” field in block #1), note that the hash function will be varied between different blockchains. The computationally expensive problem we discussed above is that: the node needs to find the correct “Nonce”, such that the hash of the current block which includes “Prev” and “Tx”, will start with four 0s (again, the number of 0s can be different, it’s just an example).

If you know what hash function does then you should know that even a simple change to the hash function input, will produce a completely different answer. Therefore, the only way to solve the problem is by trying different “Nonce” and see if the generated hash satisfies the requirement(the number of 0s).

From the BTC whitepaper diagram, you can see that private/public keys are also utilized to verify the author of the generated block. With the signature verification and the hardcore problem solving to generate a block, POW is one of the most secure consensus mechanisms.

However, because the process of solving the “Nonce” problem is such a computationally expensive operation, it is consuming a lot of energy which is not very environmentally friendly. All the nodes are competing with each other to try to be the first one who solves the “Nonce” problem for a particular block, since whoever solves it will get the block reward.

Chain selection

Another aspect of the consensus mechanism is the Chain selection algorithm. Because all nodes have a copy of the blockchain, and over time they can append blocks generated by themselves to the blockchain, how do we know who has the “real” or the “true” blockchain? This is when the Chain selection algorithm comes into play.

The decentralized network will use the blockchain with the longest chain or with the most number of blocks on it, this makes sense because every additional block that a chain is behind is going to take more and more computation for it to catch up.

When you start trading, you might notice that there are Block Confirmations in your transaction. The block confirmation is the number of blocks added to the chain after your transaction is processed in a block.

It is also worth talking about the famous “51% attack”. As we just saw as part of the consensus mechanism, the blockchains in a network will follow up with the longest chain, as long as it matches up with 51% of the rest of the network. This means that if you have control of more than 51% of the network and the longest chain, you can actually bring the network over to your longest chain and force it to cooperate with it.

For example, let's say there are 6 nodes in the network and node #5 has the longest chain. But if you have control over the 4 nodes out of the 6 nodes, then you can force the network to follow onto your chain because that’s more than 51% of the overall power. From this, you can produce fake transactions without getting kicked out of the network.

Proof-Of-Stake

Due to the high power required to run a POW network, Proof-Of-Stake(POS) consensus mechanism was invented to address the environmental issue. Solana, Avalanche, Polygon, Polkadot and Terra are some of the popular crypto projects that leverage POS. In addition, when ETH is updated to ETH 2.0, it will also start using POS as its consensus mechanism.

POS is also a Sybil resistance mechanism. It requires the nodes to put up collateral so that if they do not behave honestly, their collateral will be taken away, this is also known as “staking”. Again, even if you create a number of anonymous accounts, you still have to put up some stake, and if you misbehave then you might lose the collateral.

Unlike the “mining” concepts in the POW network where every node is competing with each other, a node is randomly selected to generate the new block as long as they have put up some collateral. Then other nodes will verify if the chosen node has behaved honestly and these validating nodes are considered as the validators in POS. The randomness of choosing the node to propose a new block is varied among different projects, so we will not dive deep into this.

Other mechanisms

There are other consensus mechanisms out there used by many crypto projects, such as Proof-Of-Authority and Proof-Of-History which I am not very familiar with. But if you are interested, feel free to take a look by yourself.

--

--