PoW and Pos Consensus Algorithms
Prior to describing the importance of consensus algorithms, let's first address the basic concepts. Namely, what blockchain is and how it functions.
For example, A had four coins, one of which they sent to B and two — to C, thus ending up with one coin. All these actions are stored on a blockchain, allowing uses to check how many coins all the transaction participants have at any given moment and, also, track all the transactions on the blockchain.
Referring to the traditional banking system, imagine a “data center” that receives data on any changes from one of the participants, verifies them, enters them into a “general accounting ledger,” and distributes new confirmed data to other participants (for example, bank branches). However, if there’s a central entity, it has the ability to change information “on the go” and, thus, “deceive” other participants.
What consensus algorithms are important
Putting things simple, blockchain is a digital ledger that is being constantly populated with new data, or transactions. It was created as a completely decentralized network, distributed between thousands of computers. Blockchain is operational until there are at least a few participants in it. This means that any participant in the network has equal rights to make new entries and there is no “central validator” in the network.
Not only network participants are anonymous, but they can freely connect to or disconnect from the network. At the same time, blockchain, being a decentralized system, has censorship resistance and objectivity (to determine the current version of the transaction log, you don’t need to trust some authoritative sources).
Now, let's get back to the analogy with a “ledger.” Every certain period of time, a new “row” is added to it, containing all the changes (transactions) that have occurred during this period. Later, this data will be stored and distributed between the thousands of computers in the blockchain network.
This row is called a block, which explains the essence of the term "blockchain,” a chain of blocks. Since blockchain allows for equal and open rights to all participants, the following dilemma arises — why would anyone trust the data on a blockchain if there’s no “central validator?” How to make sure that the entry “A sent one coin to B” is true and that “A sent one coin to C” is fake? Consensus algorithms were created exactly to resolve this issue.
The work and functioning of the blockchain participants can be illustrated with the picture below:
In the scheme, the blue cylinders are building consensus and making new entries. In a classic blockchain network, this is done by miners. The green cylinders keep copies of the blockchain, check the validity of new records, and distribute tasks to save the next group of transactions in blocks.
These are usually fully functional wallet nodes. The yellow squares are the simplest blockchain users, such as mobile e-wallets, who usually have access to records associated only with themselves or certain fragments of the “ledger”.
The result of the consensus algorithm is a unique electronic signature (hash), each block is signed with (a new row of the ledger). This signature’s authenticity can be verified and confirmed by any participant in the blockchain.
Any change to the data in the block will cause its signature mismatch. Moreover, each subsequent signature is based on the previous one, so any participant can determine whether a new block is a real continuation of the blockchain (remember, a blockchain is a chain of blocks).
The consensus algorithm is designed to ensure the reliability of transactions by checking the accuracy of the actions taken, which is distributed among many network participants. Currently, there are four main consensus algorithms, each of which has unique advantages of its own. In this article, we will review the two most popular ones.
PoW consensus algorithm
The proof-of-work (PoW) algorithm is the oldest, most sophisticated, and secure. In PoW, all transactions are proven using complex mathematical calculations, the reliability of which can be double-checked by any user of the network.
In other words, miners solve a problem. If a miner has managed to solve the problem, a new block is formed, the next set of transactions is placed in it, and they are considered confirmed. The miner receives a reward for their work, which is formed from the reward for creating a block and transaction commissions.
This approach has several advantages:
• PoW solves the issue of network hacking, in which an attacker creates a huge number of fake participants with false information in order to "crush" the resulting majority. Implementing such a mechanism in PoW will take a huge amount of computing power.
• PoW ensures fairness. Each miner's reward is proportional to their computing power (hash rate). If the miner has 2% of the hash rate from the entire network, then they will create 2% of blocks on average and receive 2% of the distributed reward.
• Dishonest behavior can cost real money. Since physical resources are spent on computing (which, in the case of the Bitcoin network, are measured in thousands of dollars per minute), miners have a completely new incentive to follow the rules.
It’s also worth noting that if a 51% attack — when a group of attackers gains control of 51% or more of the computing power — occurs, the attackers will only be able to ignore the blocks from all other miners, to take all the reward for mining in the network.
However, even if all the miners in the network conspire, they will not be able to bypass the basic security mechanisms of bitcoin. For example, they won’t be able to steal bitcoins from users.
PoS consensus algorithm
The proof-of-stake (PoS) algorithm functions like PoW to some extent, with the difference that miners do not have to solve complex computational problems.
PoS was first implemented in 2012 in the PPCoin cryptocurrency (renamed to PeerCoin). The idea behind proof-of-stake lies in solving the proof-of-work problem associated with high energy costs.
The transaction's validity is confirmed by validators. PoS requires that participants hold the coins they store on the network to verify and confirm transactions. These coins are blocked (staked) and become unavailable for any other use during staking, thus, acting as votes entitled to the very “signature.”
At the same time, there is no remuneration “for solving a mathematical problem” in PoS, as the miner (staker) gets a reward from transaction fees. The more “votes” are blocked by a staker in the network and the longer this period is, the greater their reward is.
Which one is better?
The POW’s major advantage, which is its biggest drawback at the same time, is that to ensure security,a user needs to "work," that is, to produce proof of work. The computations performed within PoW do not serve any useful purpose, and this is an architectural feature.
Until now, no proof of work has been invented that would fulfill a socially useful role. Therefore, it is generally accepted that resources for mining (primarily electricity) are wasted (unless you consider that they are spent on ensuring the safety of users). PoS does not produce "unnecessary" calculations and, from this point of view, it is more energy-efficient.
The low transaction processing speed is a pain point of blockchains, as they work much slower than traditional systems. This is the price to pay for security and decentralization. Scalability can increase performance.
From this point of view, PoW has the worst scalability. Accelerating transaction processing is possible by “sharding” blockchain. In theory, sharding is possible for any blockchain, but in practice, functioning sharding models still exist only in blockchains utilizing the PoS consensus.
The balance between decentralization and centralization is a key issue when it comes to blockchain networks. While both consensus algorithms are decentralized, several factors can push blockchain towards centralization.
In the case of PoW, an entire industry is involved in mining, and the main computing power is concentrated in a relatively small number of their owners, who earn most of the network's reward.
PoS has similar problems, as wealthy users who have invested large amounts in staking have more chances and opportunities to receive rewards. Accordingly, if we assume that a few percent of miners or stakers control 30% to 40% of the network, decentralization can hardly be called real.
Network security is the priority of any blockchain. In theory, the only possible attack on a blockchain network is the so-called “51% attack,” in which someone or a group of ill-minded users gains control of more than half of the network.
In a PoW network, such an attack is possible by controlling the mining power, which requires huge computing resources.
In a PoS network, such an attack would require more than half of the coins staked. Accordingly, the attacker will need to acquire them, which is economically unprofitable, since such an acquisition would automatically multiply the price, due to increased demand.
Thus, PoW and PoS can be considered equally safe, since a “51% attack” would not give the benefit relative to the cost of its implementation.