Skip to content
KALANBLON
Show contents

Chapter 2 of 6 · 20 min

Proof of stake and finality

By the end of this chapter, you'll be able to

  • Explain the role of validators, the stake and weighted selection
  • Compute whether a block reaches the two-thirds quorum and becomes final
  • Show why the two-thirds threshold guarantees that no conflicting block will be finalised
  • Detect a conflicting vote and apply a penalty (slashing)

Choosing the proposer by stake

At each slot (12 seconds on Ethereum), a validator is drawn at random to propose the block. The probability of being chosen is proportional to the stake. The draw must be unpredictable long in advance, but verifiable by everyone: it is derived from a shared random value (on Ethereum, RANDAO, built from the validators' contributions) and the slot number.

import hashlib

stakes = {"Awa": 3200, "Kofi": 1600, "Mei": 800, "Yao": 320, "Fatou": 80}
total = sum(stakes.values())

def proposer(seed, slot):
    """Stake-weighted draw, reproducible by everyone from the shared seed."""
    draw = int(hashlib.sha256(f"{seed}:{slot}".encode()).hexdigest(), 16) % total
    for validator, stake in stakes.items():
        if draw < stake:
            return validator
        draw -= stake

count = {v: 0 for v in stakes}
for slot in range(10_000):
    count[proposer("epoch-seed-42", slot)] += 1

for v, stake in stakes.items():
    print(f"{v:<6} stake {stake / total:>6.1%} → proposer for {count[v] / 10_000:>6.1%} of slots")
Awa    stake  53.3% → proposer for  53.4% of slots
Kofi   stake  26.7% → proposer for  26.8% of slots
Mei    stake  13.3% → proposer for  13.1% of slots
Yao    stake   5.3% → proposer for   5.6% of slots
Fatou  stake   1.3% → proposer for   1.1% of slots

Each validator proposes about as many blocks as its share of the total stake: the equivalent of the share of computing power in proof of work, without the energy cost.

Voting and finalising

The other validators vote (they are said to "attest") for the block they consider correct, by signing their vote. A block becomes final when it gathers the votes of at least two thirds of the total stake.

Going back on B would require at least a third of the stake to vote twice, and be penalised.

Step 5 of 5
Text description of the animation
  1. The proposer broadcasts its block.
  2. Each validator signs a vote for the block it considers correct.
  3. The voters' stakes are added up, not their number.
  4. The quorum is reached.
  5. Going back on B would require at least a third of the stake to vote twice, and be penalised.

Why two thirds? If two conflicting blocks B and B' each received at least two thirds of the votes, the sum would exceed 100%: at least a third of the stake would have voted for both. These conflicting votes are signed, hence provable, and punished. Likewise, a proposer who signs two different blocks for the same slot is penalised: this is called slashing, and part of the stake is destroyed. Security holds as long as less than a third of the stake is dishonest.

stakes = {"Awa": 3200, "Kofi": 1600, "Mei": 800, "Yao": 320, "Fatou": 80}
total = sum(stakes.values())

def final(votes_for, threshold=2 / 3):
    weight = sum(stakes[v] for v in votes_for)
    return weight, weight >= threshold * total

for voters in (["Awa", "Kofi", "Mei", "Yao"], ["Awa", "Mei", "Yao", "Fatou"], ["Kofi", "Mei", "Yao", "Fatou"]):
    weight, ok = final(voters)
    print(f"{', '.join(voters):<26} {weight:>5} / {total} → {'final' if ok else 'not yet'}")
Awa, Kofi, Mei, Yao         5920 / 6000 → final
Awa, Mei, Yao, Fatou        4400 / 6000 → final
Kofi, Mei, Yao, Fatou       2800 / 6000 → not yet

Note: four validators out of five are not always enough. Without Awa, who holds more than half the stake, no block can be finalised. A strong concentration of stake is a real risk: in practice, a large share of Ethereum's stake goes through a few large operators.

Mini-lab: stake concentrationPython 3.13

Output

Click “Run”: Python will load in your browser (about 10 MB the first time).

Your code runs in your browser, isolated from the page. · Ctrl/⌘ + Enter to run · Esc then Tab to leave the editor

Your turn

Worked exercise

Worked exercise: detecting and penalising conflicting votes

You receive the list of signed votes for a slot: (validator, slot, block). Write slash(votes, stakes, rate=0.5) that spots the validators who voted for two different blocks in the same slot, removes rate of their stake (the stake is "burned"), and excludes them. Then recompute whether each block reaches the two-thirds quorum, with the stakes after the penalty and without the excluded validators' votes.

Hint 1
Store the votes in a dictionary (validator, slot) → set of blocks: a set of size 2 or more proves the fault.
Hint 2
The reference total for the quorum is the sum of the remaining stakes of all validators, excluded ones included (their reduced stake stays locked until they leave), which makes finality harder, not easier.
Show the solution and common mistakes
def slash(votes, stakes, rate=0.5):
    seen = {}
    for validator, slot, block in votes:
        seen.setdefault((validator, slot), set()).add(block)
    culprits = sorted({v for (v, _), blocks in seen.items() if len(blocks) > 1})
    new = dict(stakes)
    for v in culprits:
        new[v] = int(stakes[v] * (1 - rate))
    return culprits, new

def quorum(votes, stakes, excluded):
    total = sum(stakes.values())
    support = {}
    for validator, _, block in votes:
        if validator not in excluded:
            support.setdefault(block, set()).add(validator)
    return {b: (sum(stakes[v] for v in vs), sum(stakes[v] for v in vs) >= 2 / 3 * total) for b, vs in support.items()}

stakes = {"Awa": 3200, "Kofi": 1600, "Mei": 800, "Yao": 320, "Fatou": 80}
votes = [("Awa", 812, "B"), ("Kofi", 812, "B"), ("Mei", 812, "B"), ("Yao", 812, "B"),
         ("Fatou", 812, "B"), ("Fatou", 812, "B-prime"), ("Mei", 813, "C")]

culprits, after = slash(votes, stakes)
print("culprits:", culprits, "| Fatou's stake:", stakes["Fatou"], "→", after["Fatou"])
for block, (weight, ok) in quorum(votes, after, culprits).items():
    print(f"block {block:<8} {weight:>5} → {'final' if ok else 'no quorum'}")
culprits: ['Fatou'] | Fatou's stake: 80 → 40
block B         5920 → final
block C          800 → no quorum

Fatou signed two conflicting votes in slot 812: the proof is irrefutable, half of that stake is burned and those votes no longer count. Block B stays final thanks to the others. Mei voted for C in slot 813: that is not a fault, it is another slot.

Common mistakes:

  • Treating as a culprit a validator who votes for different blocks in different slots: that is normal operation.
  • Counting the number of voters instead of their stakes: an attacker would create a thousand small validators.
  • Penalising without checking the signatures of both votes: anyone could accuse an honest validator.

Summary

  1. 1In proof of stake, validators lock up a stake and are drawn at random in proportion to it to propose blocks.
  2. 2A block becomes final when it gathers the votes of at least two thirds of the total stake.
  3. 3Two conflicting finalised blocks would mean that at least a third of the stake voted twice, which is provable and penalised.
  4. 4A simple-majority quorum does not protect against a small group of dishonest validators.
  5. 5The concentration of stake among a few actors remains a risk for finality and neutrality.

Your progress is saved on this device. Create a free account to keep your progress on all your devices.