Proof of Work and Proof of Stake for dummies

Proof of Work

The idea of ​​PoW was first proposed in 1993 Moni Naorom And by Cynthia Dwork as a mechanism to combat DoS attacks and spam. However, its most famous application was realized in 2009 with the launch of the network Bitcoinwhere PoW was used to achieve consensus in a decentralized network and to protect against double spending.

Besides Bitcoin, there are other cryptocurrencies that use PoW, such as Bitcoin Cash, which attempt to improve scalability and transaction speed over Bitcoin by increasing the block size. However, these changes also raise debate regarding the centralization and security of the network.

Principle of operation

PoW requires network participants to perform complex computational tasks to prove that they have spent a certain amount of computing resources (time, energy). In crypto, for example, this means that whoever solves the problem first gets the right to add a new block to the blockchain and is rewarded for this with a certain amount of cryptocurrency.

PoW is based on mining process. Miners compete to solve mathematical problems, and the first one to find a solution can add a block to the chain and receive a reward in the form of cryptocurrency. Technically, this process involves finding a value that, when passed through a hash function along with the data from the previous block and the transaction network, will produce a hash that meets certain difficulty criteria. Thus, creating a new block requires significant computational effort, which makes attacking the network economically impractical.

The difficulty of the problem in PoW is adjusted automatically so that the average time to create a new block remains constant, for example, 10 minutes for Bitcoin. When the overall computing power of the network increases, the complexity of the problem increases accordingly, and vice versa.

Conditionally implemented in Python

Let's imagine that we are creating a system in which “work” must be done to add each new block to the chain. This “work” comes down to finding a number noncewhich, when added to the block data, produces a hash starting with a certain number of zeros.

Main components:

  • Block data: The information we want to store in the block.

  • Nonce: The number we will change to change the block hash.

  • Target condition: the number of leading zeros in the hash that we want to get.

Pseudo code:

import hashlib

def proof_of_work(header, difficulty_bits):
    # вычисляем целевое значение на основе сложности
    target = 2 ** (256-difficulty_bits)
    for nonce in range(100000000000):
        # создаем хеш из данных блока и nonce
        input = f'{header}{nonce}'.encode()
        hash_result = hashlib.sha256(input).hexdigest()
        
        # проверяем, удовлетворяет ли хеш условию сложности
        if int(hash_result, 16) < target:
            print(f"Успех с nonce {nonce}")
            print(f"Хеш: {hash_result}")
            return (hash_result, nonce)
            
    print("Не удалось найти новый блок")
    return nonce

# юзаем 
header="Пример блока"
difficulty_bits = 20 # сложность
proof_of_work(header, difficulty_bits)

difficulty_bits determines the difficulty of the task (the higher the value, the more difficult it is to find a suitable hash). In this case, the system is looking for noncewhich, when added to headergives a hash corresponding to the given difficulty.

Mining farms, which use huge amounts of equipment, consume large amounts of electricity, raising concerns about environmental impact. In response to this, alternative consensus mechanisms have recently emerged, such as Proof of Stake, offering more energy efficient solutions.

Proof of Stake

The first mention of PoS can be traced back to 2011 on forums BitcoinTalkwhere it was proposed as a better alternative for verifying transactions and ensuring network security. Peercoinlaunched in 2012 by Sunny King and Scott Nadel, became the first cryptocurrency to implement PoS, introducing a hybrid model that also included PoW to simplify initial coin distribution.

The basic idea of ​​PoS is to select validators based on their share of the network to validate blocks of transactions. Unlike PoW, where miners expend enormous amounts of computing power (and thus energy) to solve complex problems, PoS validators are selected based on the amount of cryptocurrency they hold and are willing to “pledge” as a guarantee. This mechanism significantly reduces energy consumption.

Several problems in the design of PoS systems have been identified and addressed, including the initial distribution of coins, the potential for monopolization by large stakeholders, vulnerability to 51% attacks, and the “Nothing at Stake” problem. Iterations in PoS design have sought to address these issues in a variety of ways, such as using coin age for distribution, implementing delegated PoS to more democratically select validators, and implementing PoS-based Byzantine error tolerance to improve security.

One of the most significant events in the history of PoS was the transition of Ethereum from PoW to PoS in September 2022. This upgrade, known as “The Merge“, represented a major step towards a more sustainable structure for one of the largest blockchain networks, reducing Ethereum's energy consumption by an estimated 99%.

Shipped!

The Merge was executed on September 15, 2022. This completed Ethereum's transition to proof-of-stake consensus, officially deprecating proof-of-work and reducing energy consumption by ~99.95%.

Written on the Ethereum website

Pictures from ethereum.org

Principle of operation

While PoW requires computational work to validate and add new blocks to the chain, PoS operates on based on the participation of cryptocurrency owners, using their share (stake) of the network to make decisions.

Instead of miners, as in PoW, in PoS blocks are created validators, which are selected based on their share of the network. The more cryptocurrency you have, the more likely you are to be chosen to create a new block.

To participate in the block creation process, cryptocurrency owners must stake their coins on the network as a guarantee of their participation and reliability. It is called staking.

The process of selecting validators may depend on various factors, such as the size and duration of the stake, randomness, the use of special selection algorithms and other parameters, the purpose of which is to ensure decentralization and security of the network.

Validators who successfully create blocks receive rewards in the form of transaction fees or the issuance of new coins. However, if validators act incorrectly or do not follow network rules, they may be subject to penalties, including loss of stake.

Variations of PoS

Chain-based PoS: In this modification, the difficulty of the task depends on the participant's share. Fewer computations for large shareholders help avoid excessive hardware requirements.

DPoS: Systems using DPoS introduce a two-step process: first, token holders elect a committee of validators, and then these validators alternately propose new blocks, which are then approved by the validators​​.

LPoS: In LPoS, any token holder can declare himself a validator, but it is more profitable for small holders to delegate their voting rights to large players in exchange for some benefits, such as periodic payments.

Implementation example

Cardano is an open-source blockchain platform that is designed to provide a more resilient and resilient cryptocurrency ecosystem. Based on research and academic science, Cardano implements PoS principles into its network to ensure consensus.

Cardano uses a consensus protocol Ouroboroswhich is based on Proof of Stake.

ADA holders have the opportunity to participate in the staking process by staking their coins to the network as a guarantee of their participation. They can also delegate their coins to other network participants so that they can act as validators.

Cardano also uses the Shelley protocol, which introduces full decentralization to the network, allowing participants to create their own stake pools and participate more actively in the staking process.

Cardano has a three-layer architecture consisting of a settlement layer, an agreement layer, and a computation layer.

Let's compare

Characteristic

PoW

PoS

Consensus principle

Requires complex calculations to be performed to create a new block

Based on share of cryptocurrency ownership; coin owners use their share to create new blocks

Energy consumption

High power consumption due to complex calculations

Energy efficient as it requires no computational work

Decentralization

Mining may become centralized due to power concentration

Can provide greater distribution of power and control

Safety

High level of security thanks to proof of work

If implemented correctly can also provide a high level of security

Scalability

Scalability is limited due to mining difficulties

Can be more scalable because it does not require complex calculations

Initial distribution

New coins are created through mining, which can lead to uneven distribution

Coin distribution can be more even due to ownership share

Blockchain Examples

Bitcoin, Ethereum

Cardano, Tezos,


As a result, the choice between PoW and PoS depends on the specific blockchain project.

In conclusion, I would like to recommend free webinarwhere you'll learn how to effectively decompose applications into microservices, focusing on functional decomposition.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *