Proof of Stake vs Proof of Work

Nicolas Gatien
7 min readJan 8, 2022

--

If you’re reading this, I assume you’ve heard of crypto currencies. But you’re probably left with a question: how are they secured? That’s what this article covers, I’ll be explaining the basics of blockchain, and how blocks are confirmed before being added to the chain! Theres quite a bit to cover here so buckle up!

What are blockchains?

Blockchains are decentralized networks. What does that mean? It’s a network that no one, in particular, owns or controls. It’s the people who use and support it that do. Wait… Wouldn’t I be able to change values then? If I manage it?

Well, kind of, but not really. Blockchains keep track of all transactions that have ever happened. Each block in the chain references the block that came before it. If the block before changes, than the reference leads nowhere and the blockchain is broken. So it’s almost impossible to change a blockchain.

On top of this step that stops past transactions from being changed, the network is constantly being checked by validator nodes. Whenever a block is added, it needs to be added by a validator node. These nodes run consensus algorithms (which I will explain in the next section) that check if the transactions in the block are valid. If they are, the block can be added. If not, the block is rejected.

The reason they’re called consensus algorithms is that they are used by the entire network to come to a consensus on wether a transaction is valid or not. Once the network agrees it is valid, it’s added to the chain.

What’s a consensus algorithm?

The consensus algorithm runs on validator nodes, which are people supporting the network in some way (methods of validation are coming up soon!) Different blockchains use different consensus algorithms, but recently we’ve been seeing more and more blockchains move away from one to the other.

The algorithm allows validators across the network to agree and come to a conclusion over something. Whenever a block is added to the chain it needs to be confirmed first. This is where consensus algorithms come in.

What are the different types of consensus algorithms?

Proof of work

Proof of work (PoW) was the first consensus algorithm, implemented in Bitcoin. It works by making computers guess numbers until they find the right one. Each block, when added to the blockchain has a SHA256 hash attached to it.

Wat? What’s SHA256?

It’s an encryption algorithm that changes the output significantly when you change the input slightly. It’s also irreversible, so you can encrypt a message into SHA256, but you can’t decrypt the SHA256 into the message (easily).

So each block has a hash attached to it that is calculated by combining all of its values + the nonce into a long string of characters and numbers that seem random.

What’s a nonce?

Here’s where the actual algorithm comes in. Now that each block has a hash attached to it, validators (which are known as miners in proof of work) need to guess a nonce (which just holds a number) value until they find a hash that contains a set number of 0s in front of it.

For example in my mockup blockchain, the difficulty is currently set to 3, which means that when a miner mines a block, it needs to find a hash starting with 3 zeros.

In more popular blockchains, the difficulty is much, much higher. Bitcoin miners currently need to find hashes starting with 17 to 19 zeros. That’s a lot of computing power, because the amount you need scales exponentially as the difficulty goes up.

When computers are guessing the nonce, the amount of guesses to guess per second is called the hash rate (h/s). On average to find the hash for 1 bitcoin, a computer would need to guess an average of 72 Sextillion times. (72 with 21 zeros after) Whereas to find a hash with 3 zeros, you’d need to guess an average of 4096 times.

When a miner guesses the right hash, that miner gets to add the block to the chain and gets a reward. Miners make sure the blockchain stays valid and safe, so it makes sense for them to be rewarded when they do.

Proof of stake

Proof of Stake (PoS) is a newer consensus algorithm that aims to solve a few problems that come with PoW.

First, due to the fact PoW takes a lot of computing power, it also takes a lot of electricity. Over the years, places called mining farms have been popping up. These are basically buildings, full of computers optimized for 1 thing and 1 thing only: Mine Bitcoin. These buildings take a lot of electricity, and as more of these mining farms pop up, it starts to impact the environment.

Secondly, because of these mining farms having a LOT more guesses than anyone else on the network, it centralizes the network to some extent. If enough mining farms combine together, they could start approving fraudulent transactions, and the rest of the network wouldn’t be able to do much about it.

Okay so we have 2 problems to solve, power consumption, and centralization.

PoS works by letting people stake their currency to have a chance to be chosen to forge a block. (forging a block is the terminology used when referencing PoS it’s the same as mining a block in PoW) The more currency you stake the higher your chances of being chosen to forge. But even if you stake a very little amount, there’s still a chance.

Forgers are randomly selected, but their chances are heavily affected by how much money they have staked.

For example here, Forger 1 has 10$ staked, whereas Forger 2 has 1000$, Forger 2 is 100x more likely to be chosen to forge the block, but forger 1 still has a chance. We can include a few other variables in this calculation, like how long the currency has been staked for, etc…

How do we stop fraudulent blocks from being added?

Well there’s a consequence now to adding a fraudulent block. If you add a fraudulent block to the blockchain after being chosen to forge it. You lose all of the currency you have staked + the rewards. This incentivises forgers to act in good will for the blockchain, because they will gain better benefits by playing by the rules.

Once a forger has validated a block, it gets added to the chain, and the forger gets a reward! The reward in PoS is often the transaction fees that came with that block.

Using PoS we solve the 2 problems listed above, it’s not worth it anymore for validators to fill their houses with miners because your computational power only matters once you’ve been chosen to forge the block. To bring your chances of getting a reward up, you need to stake money.

And depending on how the choosing algorithm is implemented, it also solves centralization. If we only reward the accounts that have the most money staked, than that becomes a problem. But if we implement more variables like the amount of time a currency has been staked, than it allows accounts that don’t have as much to help the network too.

100% Secure Network!

Well not quite, even if these algorithms are very, very good at their jobs, they are still not 100% secure. Both are susceptible to something called the 51% attack. It manifests in different ways in both, but is still a possibility. The 51% attack in PoW is when 51% or more of the mining CPU decides to start adding fraudulent blocks to the chain. This could technically happen, but you’d need the top 4 mining pools in Bitcoin to combine, and you’d also need everyone in those pools to keep mining.

In PoS, the 51% attack manifests if someone owns 51% of all the circulating currency. Which again, is extremely unlikely to happen. In the example of Ethereum, it’s current circulating supply stands at 118.6 million. To execute a 51% attack on Ethereum (once it swaps to PoS) you’d need to own 246 billion dollars worth of Ethereum. Again, not a very likely scenario.

Well now you know how consensus algorithms work! There are a lot more than these 2, but these are the most prevalent and used out of them. Who knows, maybe in the future we’ll see even more efficient ones popping up. If you want to learn about them, subscribe to my Medium account! I’ll most likely be writing about them when I learn of their existence. See you then! 👋

--

--

Nicolas Gatien

Hi! I'm Nicolas! A 17-year-old game designer & maker. I build things and write about them!