Proof of Stake in Blockchain (Part 8- Blockchain Series)

Techskill Brew
Blockchain 101 by Techskill Brew
12 min readJan 27, 2022

Welcome to the eighth part of the 100 part series on Blockchain.

Previous parts: Part 1, Part 2, Part 3, Part 4, Part 5, Part 6, and Part 7

The other type of consensus mechanism, Proof of stake or POS, was introduced in 2011 to solve the problems of Proof of work or POW (discussed in Part 7). While they both share the same goal of reaching the consensus in Blockchain, the process is different. The first cryptocurrency to adopt the POS mechanism is Peercoin. Initially, Peercoin used the Proof-of-Work mechanism for mining, and after all the coins were mined, the transition to Proof of Stake took place. The first “clean” coins that worked on POS from the very beginning were Blackcoin and NXT.

Forging and forger: In the proof of stake consensus mechanism, blocks are considered to be forged or minted instead of mined. And the individuals who validate the blocks are not known as miners; instead, they are known as validators or forgers.

Validators and how are they selected

In the Proof of stake or POS consensus mechanism, a pseudo-random process selects a node to validate the next block. The chosen node is called a validator. The selection of validator is based on various factors like:

(i) Node’s wealth: Individuals must have cryptocurrency coins with them to participate in the POS consensus mechanism. They are required to stake coins by depositing them to a node. The nodes then compete for the opportunity to validate transactions. This is where the term “stake” comes from. The size of stake determines the chances of a node being chosen as the validator/forger for the next block. The forger validates transactions and creates new blocks in the network. The process of creating new blocks in POS system is known as forging. The higher the stake, the higher the chances of getting selected as the validator to forge the next block in the network. Therefore, unlike the proof of work mechanism, in which the miner creates new blocks by performing computational work, a proof of stake system requires the validator to show ownership of a certain number of cryptocurrency units to add a new block to the Blockchain.

POS mechanism requires the validator to stake cryptocurrency to participate in consensus

To ensure that the POS process does not support the dominance of only the richest nodes in the network, other methods like coin age and randomized block selection are added to the selection process.

(ii) Coin age: The coin age selection method selects nodes based on for how long their coins have been at stake. It is determined by multiplying the number of coins at stake with the number of days the coins have been held at stake. For instance, the staking age for 100 tokens held for 30 days is 3000. The nodes who have staked larger sets of coins and have also staked for a long time have a greater chance of being assigned to forge the next block. The age of the coins is reset to zero as soon as a node forges a block. He/she needs to wait for at least 30 days before being able to create another one. This prevents the dominance of large share nodes in the blockchain.

An important point to note here is that in order to participate in the forging process, the crypto coins must have been at stake for a minimum of 30 days. If it’s less than 30 days, the node cannot participate in validation. The stake holding duration is essential in order to avoid repetitive selection of a forger having more number of coins and to make the process semi-random.

Additionally, the maximum period for which the coins can be at stake is 90 days. It prevents the nodes with a significant stake from dominating the participation by holding the stake for an extended period of time. Thus, giving a fair chance to all the nodes to participate in the validation process.

Peercoin cryptocurrency uses the coin age selection process combined with the randomized selection method to select who will get the chance to forge the next block.

(iii) Randomized Block Selection: In the randomized block selection method, a node with a hit value below the target value is selected for forging the next block. To calculate the hit value, each forger encrypts the hash of the previous block using his private key. The encrypted value is 64 bytes, which is then hashed by SHA 256 hash function. The first 8-bytes of the hash output are referred to as hit value. Since each forger’s private key is unique, the use of a private key in calculation generates a unique hit value for each forger in the network. The forger having the hit value below a target value is then selected for the process of forging. The calculation of the target value involves the amount of coins staked by the forger. Consequently, the target value of each forger in the network is different, and the value is higher for a forger having more coins at stake.

The target value T is calculated by the formula:

T = Tb * S * Be

Where Tb is the base target value calculated by multiplying the previous block’s target value and the amount of time that was required to forge that block, S is the time (in seconds) since the last block was forged and Se are the coins at stake. As can be seen from the formula, the target value increases with an increase in S because of each passing second since the timestamp of the previous block. With more coins at stake, the value of Se increases, and as a result, the target value becomes high, which provides an opportunity for the hit value to be less and the forger to be selected.

Therefore, forger with the highest stake and hit value below a target value is selected for the process of forging the next block in the Blockchain.

Nxt and BlackCoin are two cryptocurrencies that use the randomized block selection method.

In nutshell, the staking age and random block selection processes promote a healthy and decentralized forging network.

How does POS work?

1. To become a validator, an individual must “stake” a specific amount of coins. For instance, Ethereum 2.0 Blockchain will require 32 ETH (ether) to be staked before an individual can become a validator.

2. Validators are then selected in a pseudo-random way depending on their wealth by the randomized selection system to validate the block. This system randomizes who gets to “forge” rather than using a competition-based mechanism like proof of work. In other words, contrary to the POW where the block creation depends on the computational power, the block creation in POS is directly proportional to the individual’s holding of the cryptocurrency or the underlining token of the network.

3. When a node gets chosen to forge the next block, it will check if the transactions in the block are valid. Each transaction is signed with a private key of the sender (digital signature). Since the public key is the sender’s address, it can be used to identify if it is the correct key for the given address from which the transaction has been done. The validator also verifies that the sender of a transaction is not spending the same cryptocurrency twice and actually has the coins in his account that he wants to spend. This solves the problem of “double-spending.” Then, the hash function SHA-256 groups the number of verified hashed transactions into a Merkle tree, required to form a block containing one root hash.

4. After verifying the transactions, the forger signs the block using his private key and broadcast it on the network. Other validators on the network not chosen for forging are called attestors. A number of attestors are required to “attest” that the block is valid and is signed by the appropriate forger using his public key. For instance, in the case of Ethereum 2.0 Blockchain, 128 validator nodes are selected from the entire pool of validators to attest the block. At least attestations from 2/3rd of attestors are required for the block to become finalized and add it to the Blockchain. The attested block can never be reverted or changed, thus becoming an immutable and permanent part of the Blockchain.

5. Time in proof of stake is divided into slots and epochs. One slot is the time set to create a block. For instance, in the case of Ethereum 2.0 Blockchain, one slot is of 12 seconds. 32 slots make up an “epoch,” thus one epoch is 6.4 minutes. Each slot represents the opportunity for a block to be added to the Blockchain. Under normal operation, each slot will generate a block, but if a forger misses an assigned duty, a slot may be empty.

At the end of an epoch, a new group of 128 validators is formed for the next validation. Out of them, 1 is forger, and 127 are attestors. This regular and random selection process increases security preventing collusion and other bad acts.

6. After the block has been validated and added to the Blockchain, the node who got the chance to forge the block gets a reward. As a reward, the forger receives the transaction fees that are associated with the transactions in the block. The attestors also get rewarded for making correct attestations. Different cryptocurrencies that use this mechanism have their own way of calculating and distributing rewards.

Additionally, to provide the network with some time to check the validity of the transactions, the stake, as well as the reward received, are locked up for some time. They are only released once the network verifies that the transaction isn’t incorrect or fraudulent.

Proof of Stake consensus mechanism

Mining coins in proof of stake: In the Proof of Stake mechanism, cryptocurrency units are created initially at the time of launch of the currency, and their numbers are also fixed. Because the energy consumption in Proof of Stake is negligible as compared to Proof of work, the block creators are not rewarded with the network coins. Instead, they are rewarded with transaction fees for creating new blocks.

Alternatively, cryptocurrencies can be launched with the Proof of Work algorithm. When all the coins are mined, they can be later switched over to Proof of Stake like Ethereum. Ethereum has two different versions, Ethereum 1.0 and Ethereum 2.0. Ethereum 1.0 uses proof of work (PoW), but its switch to Ethereum 2.0 uses proof of stake (PoS).

Other cryptocurrencies that run the proof of stake system are Cardano (ADA), Raydium (RAY), Digital cash (DASH), Tezos (XTZ), NEO, EOS, NAV, etc.

Penalties for malicious activities

There are severe penalties for the malicious behavior of the validators.

(i) Trust is developed on the network by means of stake. Staking coins is similar to holding an escrow account; in case the validator validates a fraud transaction, he will lose his stake as well as his right to participate as a forger in the future. So, as long as the stake is higher than the reward, the validator who tries to participate in fraudulent activities would lose more than what would earn. Therefore, staking cryptocurrency acts as a financial motivator for the validators to perform their job honestly.

(ii) In order for a validator to receive the full reward amount, the entire process of validation and signing block must take place within a 12-second ‘slot.’ Time taken over 12 seconds leads to reduced reward, and in case he misses the slot, then he receives no reward.

(iii) Validators are also penalized for not following through with their responsibilities when it is their turn to do so, i.e., if they are offline. Penalties for being offline are relatively mild and equate to about the same as the expected rewards over time. So, if a validator participates correctly more than half the time, the rewards will be a net positive.

(iv) Additionally, if a validator wants to quit the forging process, its stake along with the earned rewards will be released only after verifying that there are no fraudulent blocks added to the Blockchain by it.

(v) There is also the risk of chosen validator not doing the job it is assigned to do. This is solved by appointing backup validators.

Benefits of Proof of Stake mechanism

(i) The proof of stake mechanism is much less wasteful as compared to the proof of work mechanism. Unlike POW, POS doesn’t require high-powered computing to achieve consensus. Therefore, it’s better for the environment. It uses owned cryptocurrency as the stake to participate in the consensus mechanism.

(ii) Proof of stake mechanism can be run on any average computing device. It does not require expensive equipment for mining. This is why proof of stake attracts a large number of validators which ensures that the system grows while also making it more robust. But only a few validators are selected in a random fashion that can verify the block, thus making the system more decentralized and secure.

(iii) When using a POS consensus mechanism, it would not make financial sense for an individual to attempt to perform a 51% attack. A 51% attack is defined as the event where a group or individual gains more than 50% control of a blockchain network. For this to be achieved, the bad actor would be required to own 51% of the total amount of staked cryptocurrency. For instance, the 51% attack on Ethereum 2.0. Blockchain will cost between 55 to 85 billion USD. If he attempts to do malicious activity, he would lose all of his staked coins. As a result, he would end up spending significantly more than he could gain from the attack.

Nothing at stake problem

As already discussed in POW, the miner can only mine one chain at a time according to the “longest chain rule.” Additionally, choosing the wrong chain is costly. For example, suppose a fork in Blockchain creates two chains, A and B. A miner can choose to mine one chain or the other one. But it’s not possible to mine both the chains. It is because mining requires the miner to use high-powered computation devices. Therefore, if the miner chooses to mine the wrong chain, the money that went into mining the block goes wasted.

Fork in Blockchain creates two chains, A and B

On the other hand, in the case of POS, the validator can forge both chains. Thus, when there is a fork in Blockchain, validators have three choices:

(a) work only on the chain A

(b) work only on the chain B

(c) work on both chains A and B

Also, choosing the wrong chain is not costly because it costs a validator nothing to validate transactions on multiple chains. Also, if validators forge both (or more) chains, they will collect transaction fees regardless of which chain is confirmed. Thus, the problem is called “nothing at stake.”

Both chains A and B can be forged in the POS mechanism

If every validator keeps on validating blocks on every possible chain of a blockchain network, then the multiple chains could potentially increase the chances of double-spending. Let’s take a scenario to understand it better. An attacker who attempts to double-spend money creates a fork in Blockchain before sending 5 ETH to Alice. Assume this transaction is stored on the chain A and then he begins to validate and add blocks only on another chain B. Since all other validators are hypothetically validating on both chains, the second chain will gain more attestations and eventually becomes the longest true chain. This means the original cryptocurrency 5 ETH paid to Alice will no longer be valid as this transaction is stored on the chain A. So if he again spends the same 5 ETH (those sent to Alice) for some other purpose, this transaction is stored on the chain B and gets validated. This creates double-spending of the 5 ETH.

Double spending problem

It is more likely that an attacker with just a 1% stake in the network can also do fraudulent activities. Therefore, early PoS algorithms were less secure from attack than PoW algorithms, which are secure up until a 51% attack is possible.

The solution to the “nothing at stake” problem

So there can be three ways by which the nothing-at-stake problem might be addressed:

(i) Punishment to validators for choosing to validate two different versions of the same block.

(ii) Punishment to validators for validating the wrong block, regardless of whether or not they double-attested.

(iii) The network contains validation software that will not allow for forging all chains, so validators would need to choose a “true” chain for forging.

Casper: To eliminate the issue of nothing at stake, Ethereum developers have designed the Casper protocol in which the validators will be penalized for the fraudulent activities. To reduce the likelihood that validators forge all chains, they would need to deposit security on the Blockchain. If validators are found to validate blocks on both chains or found to validate wrong blocks, they will be penalized by losing a portion or all of their security deposit. The security deposit attaches a cost to being dishonest; thus, it is in the best economic interest of all of the validators to behave honestly.

If you liked this article and want to know more about Blockchain, NFTs, Metaverse, and their applications, click the below link.

Happy learning!

--

--