Saturday, October 23, 2021

Ethereum Proof-of-Stake

Ethereum is moving to a consensus mechanism called proof-of-stake (PoS) from proof-of-work (PoW). This was always the plan as it's a key part in the community's strategy to scale Ethereum via the Eth2 upgrades. However getting PoS right is a big technical challenge and not as straightforward as using PoW to reach consensus across the network.

When it comes to blockchains like Ethereum, which are, in essence, distributed databases, the network's nodes must reach an agreement on the network's current state. This agreement is achieved using consensus mechanisms.

Although consensus mechanisms aren't directly related to building a dapp, understanding them will illuminate concepts relevant to you and your users' experience, like gas prices and transaction times.

WHAT IS A SMART CONTRACT?

A "smart contract" is simply a program that runs on the Ethereum blockchain. It's a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain.

Smart contracts are a type of Ethereum account. This means they have a balance and they can send transactions over the network. However they're not controlled by a user, instead they are deployed to the network and run as programmed. User accounts can then interact with a smart contract by submitting transactions that execute a function defined on the smart contract. Smart contracts can define rules, like a regular contract, and automatically enforce them via the code. Smart contracts can not be deleted by default, and interactions with them are irreversible.

WHAT IS PROOF-OF-STAKE (POS)?

Proof of stake is a type of consensus mechanism used by blockchain networks to achieve distributed consensus.

It requires users to stake their ETH to become a validator in the network. Validators are responsible for the same thing as miners in proof-of-work: ordering transactions and creating new blocks so that all nodes can agree on the state of the network.

Proof-of-stake comes with a number of improvements to the proof-of-work system:

  • Better energy efficiency – you don't need to use lots of energy mining blocks
  • Lower barriers to entry, reduced hardware requirements – you don't need elite hardware to stand a chance of creating new blocks.
  • Stronger immunity to centralization – proof-of-stake should lead to more nodes in the network.
  • Stronger support for shard chains – a key upgrade in scaling the Ethereum network.


PROOF-OF-STAKE, STAKING, AND VALIDATORS


Proof-of-stake is the underlying mechanism that activates validators upon receipt of enough stake. For Ethereum, users will need to stake 32 ETH to become a validator. Validators are chosen at random to create blocks and are responsible for checking and confirming blocks they don't create. A user's stake is also used as a way to incentivize good validator behavior. For example, a user can lose a portion of their stake for things like going offline (failing to validate) or their entire stake for deliberate collusion.

HOW DOES ETHEREUM'S PROOF-OF-STAKE WORK?

Unlike proof-of-work, validators don't need to use significant amounts of computational power because they're selected at random and aren't competing. They don't need to mine blocks; they just need to create blocks when chosen and validate proposed blocks when they're not. This validation is known as attesting. You can think of attesting as saying "this block looks good to me." Validators get rewards for proposing new blocks and for attesting to ones they've seen. If you attest to malicious blocks, you lose your stake.

No comments: