DAY 27 / 40

>> Module 03 / Day 27 / Lecture

Proof of Stake

Polkadot's energy-efficient consensus

Proof of Work burns electricity. Polkadot chose a different path — stake your tokens as collateral. Today we understand why, and simulate it in Python.

Lecture 75 min | Lab 60 min · Simulate validator selection | M3 · Blockchain Basics

>> Today's Roadmap

Six stops today

  1. PoW problems — what Proof of Work gets wrong
  2. Proof of Stake — the core idea
  3. Slashing — the punishment mechanism
  4. NPoS — Polkadot's version
  5. Python simulation — weighted_choice()
  6. Lab — run 10 validator elections

>> 01 / 04 · The problem with PoW

Proof of Work has three big problems

ENERGY WASTE

Bitcoin uses as much electricity as Argentina. All that computation produces nothing useful — it just proves work was done.

HARDWARE ARMS RACE

Mining profitably requires specialised hardware (ASICs) worth thousands of dollars. Rich miners dominate; regular people can't compete.

SLOW FINALITY

After a PoW block is added, you still have to wait for 6+ more blocks before it's considered final. Banks need instant finality.

Proof of Stake solves all three — no wasted computation, no special hardware needed, and Polkadot achieves finality in seconds via GRANDPA.

>> 02 / 04 · Proof of Stake

Instead of burning electricity, stake tokens

In Proof of Stake, validators are chosen based on how many tokens they lock up ("stake"). If they behave honestly, they earn rewards. If they cheat — they lose their stake. This economic threat replaces computational work.

BECOMING A VALIDATOR

Lock up a minimum amount of tokens (called bonding). The protocol chooses you to create blocks based on your stake size. No specialised hardware needed.

THE PUNISHMENT (SLASHING)

Double-sign a block (produce two conflicting blocks)? Your stake gets slashed — cut by a percentage or entirely. Your reputation is destroyed. This is why validators behave honestly.

>> 03 / 04 · Polkadot's twist

Nominated Proof of Stake (NPoS)

Polkadot doesn't just let anyone stake solo. It uses a two-role system: Validators and Nominators.

VALIDATORS

Run a node 24/7. Produce blocks and verify parachain proofs. Must stake a large amount of DOT. Currently ~300 active validators.

NOMINATORS

Regular DOT holders who back validators with their stake. They vote for validators they trust. They share rewards — and share slashing risk.

The election algorithm distributes stake evenly across validators to avoid power concentration. This is Polkadot's clever NPoS mechanism — designed for fairness.

>> 04 / 04 · Python model

Simulating validator selection with Python

pos_sim.py
import random # Validators and their stakes (in DOT) validators = { "Alice": 5000, "Bob": 3000, "Carol": 8000, "Dave": 2000, "Eve": 1000, } def weighted_choice(validators): total_stake = sum(validators.values()) r = random.uniform(0, total_stake) cumulative = 0 for name, stake in validators.items(): cumulative += stake if r <= cumulative: return name # Run 10 elections: for round_num in range(1, 11): winner = weighted_choice(validators) print(f"Round {round_num}: {winner} produces the next block")
Carol has 42% of the stake (8000/19000), so she wins roughly 42% of elections. Bigger stake = more chances, but it's never guaranteed — and cheating loses it all.

>> Side by side

PoW vs PoS — the key differences

Feature
Proof of Work
Proof of Stake (NPoS)
Energy
Enormous (Bitcoin = Argentina)
Minimal — no mining
Hardware
Specialised ASICs required
Any modern computer
Attack cost
51% of hashrate
51% of total stake
Used by
Bitcoin
Polkadot, Ethereum 2.0, Cardano

>> The deterrent

Slashing — losing your stake for cheating

If a validator signs two different blocks at the same height (equivocation), the protocol automatically slashes their stake. No human decision needed.

MINOR SLASH

Small percentage cut for accidental offline time. Usually 0.1% — a warning.

MAJOR SLASH

Large percentage for deliberate equivocation. Can be 100% — total loss.

NOMINATORS LOSE TOO

Nominators backing a slashed validator also lose a portion. Choose your validators carefully.

This is why validators behave. The economic stake at risk outweighs any potential gain from cheating. No electricity burned — pure economic incentive.

>> 11:00 – 12:00 · Lab

Today's lab — Validator Election Simulator

CORE

weighted_choice()

Write weighted_choice() and run 100 elections. Count how many times each validator was selected and print the results as a percentage. Verify that Carol wins roughly 42% of the time.

★ STRETCH

Stake shift

After 50 rounds, double Alice's stake (she nominated herself more). Run 50 more rounds. Print the before/after win percentages. Show how stake changes affect outcomes.

How to submit. Create students/<username>/D27_proof_of_stake.py. Full brief in lab/module_3_blockchain/D27_pos/problem.md. PR before 12:00.

>> End of Day 27

Stake, don't burn

✓

PoS replaces computation with economic stake: validators risk losing tokens if they cheat.

✓

NPoS adds nominators: regular DOT holders back validators and share rewards and risk.

✓

weighted_choice() models the election: higher stake = higher probability of selection.

01 / 8
←/→ navigate   F fullscreen