62
Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P

Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Demystifying Bitcoin

Prof R. GuerraouiEPFL & Collège de France & UM6P

Page 2: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Have you heard about?

Blockchain Bitcoin

Ethereum

Turing Completeness NP vs PConsensus

Proof of workSignatures

Smart contracts

Snapshot

Page 3: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Perspectives(1) The journalist

(2) The user

(3) The participant

(4) The engineer

(5) The scientist

Page 4: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

(1) The Journalist

2008: Financial crisis – Nakamoto (1/21m) From 1c to 8000$ through 20000$

2014: Ethereum (CH) - Now 800 $

From trading hardware to general trading

2020: Libra - FacebookCoin

Page 5: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin
Page 6: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Perspectives(1) The journalist

(2) The user

(3) The participant

(4) The engineer

(5) The scientist

Page 7: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

(2) The User

Page 8: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

(2) The User

The wallet: 1 private key + several public keys

Transaction validation signing + gossiping + mining + chaining

Transaction commitment After time t: thousands of users have seen it

Page 9: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

(3) The Participant

Page 10: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

(3) The Participant

Page 11: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

(3) The ParticipantTo validate a transaction, a miner has to solve a puzzle including it

Fairness and cooperation

Total: 21 millions bitcoins Now: 17 millions

Incentive: 12 bitcoins / puzzle50 bitcoins 3 years ago

Page 12: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

(4) The EngineerJoinning (a P2P network)

Gossiping (the transaction)

Mining (proof of work - nonce)Chaining (hash)

Committing/Aborting

Gathering (a block)

Signing (a transaction)

Gossiping (the block)

Page 13: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin
Page 14: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin
Page 15: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin
Page 16: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin
Page 17: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

The Big Picture

Special Reward TXTX-2 (signed)

TX-2452 (signed)

•••

Prev# nonce This

#

Bitcoinblock

Special Reward TX2 (signed)

2478 (signed)

•••

nonce This #

Special Reward TXTX-2 (signed)

TX-2325 (signed)

•••

Prev# nonce

Mining:findsuchthat<dnonce This #

How?Bytryingdifferentnonces (bruteforce)

Page 18: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin
Page 19: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin
Page 20: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin
Page 21: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Perspectives(1) The journalist

(2) The user

(3) The participant

(4) The engineer

(5) The scientist

Page 22: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

(5) The Scientist

Conjecture 1: Turing Universality

Conjecture 2: P is not NP

Theorem 1: Lamport (Consensus) Universality

Theorem 2: Consensus Impossibility

Page 23: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Turing Universality (36)

Page 24: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

P vs NP (Nash/GV 50 – Ford 70)

? * ? = 91

7 * 13 = ?

Page 25: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Lamport Universality (78)

Page 26: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Every service can be implemented in a highly available manner using Consensus

Safety: No two nodes must choose different values.The chosen value must have been proposed by a node.

Liveness: Each node must eventually choose a value.

Consensus Universality (78)

Page 27: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Consensus is impossible in an asynchronous system

Consensus Impossibility (84)

Page 28: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Perspectives(1) The journalist

(2) The user

(3) The participant

(4) The engineer

(5) The scientist

Page 29: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Payment System

Can we implement a payment system asynchronously?

Page 30: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

The infinitely big

The infinitely small

Page 31: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Message Passing

p1

p2

p3

Send

Receive

Page 32: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Shared Memory

p1

p2

Write()

Read()

1

1

ó Message Passing

Registers

Page 33: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Atomic Shared Memory

p1

p2

p3

write(1) - ok

read() - 1

read() - 1

Page 34: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Atomic Shared Memory

p1

p2

p3

write(1) - ok

read() - 1

read() - 0

Page 35: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Non-Atomic Shared Memory

p1

p2

p3

write(1) - ok

read() - 0

read() - 1

Page 36: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Non-Atomic Shared Memory

p1

p2

p3

write(1) - ok

read() - 0

read() - 1

Page 37: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Message Passing ó Shared Memory

p1

p2

p3

Write(1) Ok

Read() 1

Quorums (asynchrony)

Page 38: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Message Passing ó Shared Memory

p1

p2

p3

Write(1) Ok

Read() 1

Quorums (asynchrony)

Page 39: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Message Passing ó Shared Memory

p1

p2

p3

Write(1) Ok

Read() 1

Quorums (asynchrony)

Page 40: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

« Optimization is the source of all evil » D. Knuth

« To understand a distributed computing problem: bring it to shared memory » T. Lannister

ó

Page 41: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

P vs NP

Asynchronous vs Synchronous

? * ? = 917 * 13 = ?

p1

p2

Write(P1)

Write(P2)

Page 42: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Atomicity

Wait-freedom

Payment System

Can we implement a payment system asynchronously?

Page 43: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Counter: Specification

A counter has two operations inc() and read(); it maintains an integer x init to 0

read():return(x)

inc():x := x + 1;return(ok)

Page 44: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Counter: AlgorithmThe processes share an array of registers Reg[1,..,N]inc():

Reg[i].write(Reg[i].read() +1);return(ok)

read():sum := 0;for j = 1 to N do

sum := sum + Reg[j].read();return(sum)

Page 45: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Counter*: Specification

Counter* has, in addition, operation dec()

dec():if x > 0 then x := x - 1; return(ok)else return(no)

Can we implement Counter* asynchronously?

Page 46: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

2-Consensus with Counter*

§ Registers R0 and R1 and Counter* C - initialized to 1

§ Process pI:§ propose(vI)§ RI.write(vI)§ res := C.dec()§ if(res = ok) then

ü return(vI)ü else return(R{1-I}.read())

Page 47: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Impossibility [FLP85,LA87]

§ Corollary: no asynchronous algorithm implements Counter* among two processes using registers

§ Theorem: no asynchronous algorithm implements consensus among two processes using registers

Page 48: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Sperner’s Lemma

§ Theorem: no asynchronous algorithm implements set-agreement using registers

Page 49: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

§ The consensus number of an object is the maximum number of processes than can solve consensus with it

Page 50: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Payment Object (PO): Specification

Pay(a,b,x): transfer amount x from a to b if a > x (return ok; else return no)NB. Only the owner of a invokes Pay(a,*,*)

§ Questions: can PO be implemented asynchronously? what is the consensus number of PO?

Page 51: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Payment Object (PO): Specification

Pay(a,b,x): transfer amount x from a to b if a > x (return ok; else return no)NB. Only the owner of a invokes Pay(a,*,*)

§ Questions: can PO be implemented asynchronously? what is the consensus number of PO?

Page 52: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Snapshot: Specification

A snapshot has operations update() and scan(); it maintains an array x of size N

scan():return(x)

update(i,v):x[i] := v;return(ok)

Page 53: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Algorithm?

The processes share one array of N registers Reg[1,..,N]scan():

for j = 1 to N do x[j] := Reg[j].read();

return(x) update(i,v):

Reg[i].write(v); return(ok)

Page 54: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Atomicity?

p1

p2

p3

update(1,1) - ok

scan() - [1,0,2]

update(3,2) - ok

Page 55: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Atomicity?

p1

p2

p3

update(1,1) - ok

scan() - [1,0,2]

update(3,2) - ok

Page 56: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Atomicity?

p1

p2

p3

scan() - [0,0,10]

update(2,1) - ok

update(3,10) - ok

Page 57: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Key idea for atomicity To scan, a process keeps reading the entire snapshot (i.e., collecting), until two arrays are the same

To update, scan then write the value and the scan

Key idea for wait-freedom

To scan, a process keeps collecting and returns a collect if it did not change, or some collect returned by a concurrent scan

Page 58: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

The Payment Object: Algorithm

Every process stores the sequence of its outgoing payments in its snapshot location

To pay, the process scans, computes its current balance: if bigger than the transfer, updates and returns ok, otherwise returns noTo read, scan and return the current balance

Page 59: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

PO can be implementedAsynchronously

Consensus number of PO is 1

Consensus number of PO(k) is k

Page 60: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

(5) The Scientist

Conjecture 1: Turing Universality

Conjecture 2: P is not NP

Theorem 1: Lamport (Consensus) Universality

Theorem 2: Consensus Impossibility

Theorem 3: PO < Consensus

Page 61: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

Payment System (AT2)

AT2_SAT2_D

AT2_R

Number of lines of code: one order of magnitude less

Latency: seconds (at most)

Page 62: Demystifying Bitcoin - École Polytechnique Fédérale de ...lpd · Demystifying Bitcoin Prof R. Guerraoui EPFL & Collège de France & UM6P . Have you heard about? Blockchain Bitcoin

References