Study notesWeek 4: Consensus
Week 4

Consensus

Outcomes

What You Will Be Able To Do

Why it is hard

The Agreement Problem

Framework

Four Questions Every Protocol Answers

Bitcoin's answer

Proof Of Work In One Slide

Locked capital

Proof Of Stake

WorkStake
ResourceEnergyLocked coins
Cheat costWasted energySlashing
ExampleBitcoinEthereum
Real numbers

Ethereum'S Proof Of Stake

slot    = 12 seconds
epoch   = 32 slots
        = 384 seconds
        = 6.4 minutes
Temporary splits

Forks: Two Blocks At Once

A1 - A2 - A3
   \
    B2 - B3 - B4   <- heavier, wins
Fork choice

The Longest-Chain Rule

Demo

Fork Choice In Python

def choose(chains):
    return max(chains, key=lambda c: sum(b['work'] for b in c))

base = [{'n': 1, 'work': 1}]
A = base + [{'n': i, 'work': 1} for i in range(2, 7)]
B = base + [{'n': i, 'work': 1} for i in range(2, 5)]
print(len(choose([A, B])))
Rule changes

Soft And Hard Forks

TypeOld nodes
Soft forkStill accept blocks
Hard forkReject new blocks
How final is final

Finality

Threat model

The 51 Percent Attack

Demo

Stake-Weighted Selection In Python

import random
from collections import Counter

stake = {'Ana': 32, 'Ben': 64, 'Cem': 160}
names = list(stake)
weights = list(stake.values())
picks = random.choices(names, weights, k=10000)
print(Counter(picks))
Judging a network

How Decentralised Is It?

Week 4 in five lines

Recap

Week 5

Next Week: Ethereum

Hands-on

Questions And Exercise