>> Module 03 / Day 27 / Lecture
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.
>> Today's Roadmap
>> 01 / 04 · The problem with PoW
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.
>> 02 / 04 · Proof of Stake
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
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.
>> 04 / 04 · Python model
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")>> Side by side
>> The deterrent
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.
>> 11:00 – 12:00 · Lab
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.
>> End of Day 27
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.