Lecture 3: Scaling Bitcoin Andrew Miller SJTU 2017 Winter School on - - PowerPoint PPT Presentation

lecture 3 scaling bitcoin
SMART_READER_LITE
LIVE PREVIEW

Lecture 3: Scaling Bitcoin Andrew Miller SJTU 2017 Winter School on - - PowerPoint PPT Presentation

Lecture 3: Scaling Bitcoin Andrew Miller SJTU 2017 Winter School on Cryptocurrency and Blockchain Technologies - Jan 14, 2017 3.2 transactions per second VISA: 2000 transactions/sec on average, (2015) peak rate of 56,000 transactions/sec


slide-1
SLIDE 1

Lecture 3: Scaling Bitcoin

Andrew Miller SJTU 2017 Winter School on Cryptocurrency and Blockchain Technologies - Jan 14, 2017

slide-2
SLIDE 2

3.2 transactions per second

slide-3
SLIDE 3

VISA: 2000 transactions/sec on average, (2015) peak rate of 56,000 transactions/sec

Can decentralized blockchains be scaled up to match the performance of a mainstream payment processor?

Bitcoin: 3.2 transactions/sec on average (as of Jan. 2017) 3.3-7 transactions/sec max

slide-4
SLIDE 4

Bitcoin faces an imminent scaling hurdle

Jan ‘16 Jan ‘17 1.0MB (HARD LIMIT)

slide-5
SLIDE 5

Last updated: April 2016! (as of Jan 17)

slide-6
SLIDE 6

Last updated: April 2016! (as of Jan 17)

slide-7
SLIDE 7

Last updated: April 2016! (as of Jan 17)

slide-8
SLIDE 8

Last updated: April 2016!

slide-9
SLIDE 9

Goal of this lecture: understand the technical topics underlying the Bitcoin scaling controversy

  • 1. Bitcoin’s underlying P2P communication network
  • 2. Upgrade mechanisms “hard-fork” and “soft-fork”
  • 3. “Off-chain” payment channels, e.g. “Lightning”
slide-10
SLIDE 10

3.1: Bitcoin’s P2P Network

slide-11
SLIDE 11

P2P Network consists of ~5500 nodes

slide-12
SLIDE 12
slide-13
SLIDE 13
slide-14
SLIDE 14

P2P Network consists of ~5500 nodes

Network nodes (aka reachable/full nodes):

  • bootstrap new nodes into the network
  • provide service to mobile clients
  • relay blocks and transactions
  • sound alarms if they see invalid blocks
slide-15
SLIDE 15

Nodes communicate by sending messages

PING PONG

Ping/Pong Respond within 60 seconds, or disconnected!

slide-16
SLIDE 16

Nodes communicate by sending messages

(connect) VERSION VERACK VERACK VERSION

Initial Handshake / S a t

  • s

h i : . 1 3 . 1 / , 4 4 7 9 2 4 b l

  • c

k s

slide-17
SLIDE 17

Forming connections:

  • 1. Learn about new nodes by connecting to hardcoded “Seeder” nodes

$ dig seed.btc.petertodd.org

  • 2. Form 8 outgoing connections
  • 3. Accept up to 125 total connections (incoming and outgoing)
  • 4. Propagate information about nodes to each other
slide-18
SLIDE 18
slide-19
SLIDE 19

Nodes communicate by sending messages

ADDR GETADDR

Propagate information about other peers ADDR messages sent in response to GETADDR, also spontaneously

ADDR

Sampled from local “addrMan” database

slide-20
SLIDE 20

Nodes communicate by sending messages

GETHEADERS GETBLOCKS BLOCK HEADERS

Blockchain Download

BLOCK BLOCK BLOCK

slide-21
SLIDE 21

Nodes communicate by sending messages

INV BLOCK GETDATA

Learn about new transactions

TX

Only sends GETDATA if it doesn’t have it and hasn’t already asked

slide-22
SLIDE 22

I found a block!

INV(h) I N V ( h )

slide-23
SLIDE 23

I found a block!

I N V ( h ) INV(h) GETDATA(h) G E T D A T A ( h )

slide-24
SLIDE 24

I found a block!

I N V ( h ) INV(h) GETDATA(h) B L O C K ( b ) G E T D A T A ( h ) B L O C K ( b )

slide-25
SLIDE 25

I found a block!

I N V ( h ) INV(h) GETDATA(h) B L O C K ( b ) G E T D A T A ( h ) B L O C K ( b ) INV(h) INV(h) INV(h)

slide-26
SLIDE 26

I found a block!

I N V ( h ) INV(h) GETDATA(h) B L O C K ( b ) G E T D A T A ( h ) B L O C K ( b ) INV(h) GETDATA(h) INV(h) INV(h) GETDATA(h)

slide-27
SLIDE 27

I found a block!

I N V ( h ) INV(h) GETDATA(h) B L O C K ( b ) G E T D A T A ( h ) B L O C K ( b ) INV(h) GETDATA(h) B L O C K ( b ) INV(h) INV(h) GETDATA(h) BLOCK(b)

slide-28
SLIDE 28

I found a block!

I N V ( h ) INV(h) GETDATA(h) B L O C K ( b ) G E T D A T A ( h ) B L O C K ( b ) INV(h) GETDATA(h) B L O C K ( b ) INV(h) INV(h) GETDATA(h) BLOCK(b) I N V ( h )

slide-29
SLIDE 29

Demonstration: Tiny Bitcoin Peer

  • Fun for a demo - connects immediately to a random Testnet node

https://github.com/amiller/tinybitcoinpeer

  • Good starting point for exploring/experimenting with the network
  • For more info: https://en.bitcoin.it/wiki/Protocol_documentation

https://bitcoin.org/en/developer-reference#p2p-network

slide-30
SLIDE 30
slide-31
SLIDE 31

Bitcoin faces an imminent scaling hurdle

Jan ‘16 Jan ‘17 1.0MB (HARD LIMIT)

slide-32
SLIDE 32

Why not just increase the limit?

slide-33
SLIDE 33

Concern #1: Orphaned blocks → Decrease in power (caused by delay in propagation)

slide-34
SLIDE 34

Counter argument: Many Bitcoin miners use alternative networks

Examples:

  • Bitcoin Fibre http://bitcoinfibre.org/public-network.html
  • Falcon http://www.falcon-net.org/

Features: Optimized topology (not random) Compression / prediction Transmits and validates in a “pipelined” fashion

slide-35
SLIDE 35

Let’s do science! Idea: use empirical measurements about the P2P network to determine an appropriate block size scaling limit Miners are not the only nodes in the network. We also care about the full nodes.

slide-36
SLIDE 36

I found a block!

Measuring the Bitcoin Peer-to-Peer Network

I N V ( h ) Measurement node: connects to all nodes, records messages & timestamps

Measurement Study #1

slide-37
SLIDE 37

I found a block!

Measuring the Bitcoin Peer-to-Peer Network

I N V ( h ) INV(h) INV(h) INV(h) Measurement node: connects to all nodes, records messages & timestamps

Measurement Study #1

slide-38
SLIDE 38

I found a block!

Measuring the Bitcoin Peer-to-Peer Network

I N V ( h ) INV(h) INV(h) INV(h) I N V ( h ) Measurement node: connects to all nodes, records messages & timestamps

Measurement Study #1

slide-39
SLIDE 39

Measurement results (Propagation rate vs block size)

slide-40
SLIDE 40

4.1MB in 10 minutes, reaches 90% of the nodes

Def’n: X% effective throughput (block size)/(X% block propagation delay)

slide-41
SLIDE 41

Physical Limits indicate 10-100x greater capacity

Measurement Study #2

slide-42
SLIDE 42

Caveats and limitations

  • Measurements pertain to the network as it exists today
  • Affected by protocol changes
  • Affected by participation and provisioning
  • Our measurements efforts could be easily attacked
  • Should we even care about the P2P network?
  • We’ve used # nodes as a proxy for decentralization. (Not an axiom!)
  • Why 90%? Do the most poorly provisioned nodes provide relevant service?
  • Miners already route around the P2P network (e.g., Bitcoin Relay Network)
slide-43
SLIDE 43

A contentious scaling debate rages on

Appropriate size: 1MB, 2MB, 4MB, 8MB? Change over time? No limit at all? Measuring consensus: what’s the threshold? Who is represented? Upgrade mechanism: Hard-fork or soft-fork? Failure modes: will the p2p network grow to match policy? Underlying values: decentralization? adoption? risk vs. urgency ………….

slide-44
SLIDE 44

3.1: How to Upgrade Bitcoin with “Hard Forks” and “Soft Forks”

slide-45
SLIDE 45

What ways would we want to change Bitcoin?

  • Increase the block size limit
  • Add support for a new signature type

(Post-Quantum signatures?)

  • Reverse a transaction that was made by mistake
  • Add “encryption” to the P2P protocol

Let’s focus on this for now

slide-46
SLIDE 46

Hard forks - the obvious way

OldTx OldTx OldTx OldTx OldTx OldTx

Time Activation day! (block number) New code deployed, with time for everyone to switch

slide-47
SLIDE 47

Hard forks - the obvious way

OldTx OldTx OldTx OldTx OldTx OldTx NewTx NewTx NewTx NewTx NewTx NewTx NewTx NewTx NewTx

Activation day! (block number) New code deployed, with time for everyone to switch Time

slide-48
SLIDE 48

<oldsig> | <pubkey> OP_CHECKSIGVERIFY <newsignature> | <pubkey> OP_CHECKSIGVERIFY

What happens to nodes that fail to upgrade in time?

Two conflicting blocks! Un-upgraded nodes will view a weaker and smaller chain with old-style transactions

slide-49
SLIDE 49

/Satoshi:0.11.2/ - Nov 12, 2015

https://bitnodes.21.co/nodes

slide-50
SLIDE 50

Let’s accept (for now) the following premises:

  • Full nodes are important for maintaining the health and robustness of the Bitcoin

network

  • Full nodes do not all “upgrade” quickly
  • Full nodes have limited bandwidth, CPU power, etc.
  • Non-upgraded full nodes must not be allowed to “fall off the main chain.”

Otherwise, they will a) be vulnerable to attacks b) form a “split currency” which threatens the economic stability

slide-51
SLIDE 51

How can we “Soft Fork” to add a new signature type?

<oldsig> | <pubkey> OP_CHECKSIGVERIFY OP_UNUSED1 <newsig> | <pubkey> OP_CHECKSIGVERIFY Occasional old-style blocks, get discarded

This OpCode exists, but has no effect. In the old rules, anyone can spend this!

slide-52
SLIDE 52

To recap: Hard forks are a “loosening” of the rules

  • Un-upgraded full nodes view new blocks as “invalid”,

find themselves on weaker/smaller divergent chain Soft forks are a “narrowing” of the rules, but a “loosening” of conventions

  • Un-upgraded nodes will still view the new chain as valid
  • Un-upgraded miners waste hashpower on invalid blocks
  • What happens if someone already uses “unused” opcode?
slide-53
SLIDE 53

Measuring consensus with a “flag day”

  • Miners signal their “support” for an upgrade. Once this support

reaches a threshold percentage, the upgrade is “committed”. If the threshold is not reached by a deadline, the upgrade is “canceled”

  • After the threshold is established, there is a delay (weeks?

months?) to leave time for full nodes to upgrade as well.

slide-54
SLIDE 54

SegWit (Segregated Witness): A soft-fork Bitcoin upgrade that introduces a new signature type

  • Improves transaction verification performance
  • Fixes “transaction malleability”, needed for future upgrades (Lightning Network)
  • Modest increase in transaction capacity (up to 1.7x, depending on wallet support)
  • Currently pending activation
slide-55
SLIDE 55

How would we “blacklist” a particular address A?

(assume that everyone agrees to do so)

With a hard fork? After activation time, create a new transaction that transfers balance of A to some alternative recovery address With a soft fork? After activation time, any transactions that spend from A are considered invalid

slide-56
SLIDE 56

How would we add “encrypted” P2P channels?

  • Right now, the communication between P2P nodes is

unencrypted, unauthenticated. We may want to change this

  • Is a fork required at all?

No, it does not affect the validity rules for blocks

slide-57
SLIDE 57

Soft-fork to undo a failed database upgrade

  • On March 11, 2013, an accidental fork occurred

A block B (height 225430) was created by version 0.8 nodes … but considered invalid by version 0.7 nodes Caused by an edge case in the database library The fork lasted 24 blocks (6 hours) Deployed an immediate “soft fork” where miners rejected the

slide-58
SLIDE 58

What about decreasing the block time (2min blocks)?

  • 10 minute block time is enforced by looking at timestamps of the

previous 2016 blocks, and updating the mining difficulty target

  • We could hard fork to change the difficulty rule!
  • Clever alternative without forks:

Every node could change its system clock to run at 5x speed!

slide-59
SLIDE 59

What about printing 1M additional coins?

Seems to require a hard fork! Open question - is there a way to approximate this with soft fork?

slide-60
SLIDE 60

Soft fork upgrades in Bitcoin

  • Pay-to-script-hash opcode soft fork

(More efficient transactions, multisig) September, 2011

  • Check-Locktime-Verify opcode

(Time lock smart contracts) June, 2015

  • Check-Sequence-Verify opcode

(Relative time lock smart contracts) July 4, 2016

  • SegWit → pending, has not been activated yet!
slide-61
SLIDE 61

Hard Fork upgrades in other cryptocurrencies

  • Ethereum has had several hard forks
  • July 20th, 2016 (to cancel “The DAO” attack)
  • October 18, 2016
  • November 22, 2016

Mitigate DoS attacks Ethereum’s July 20 fork led to a split: ETH and ETC (Ethereum Classic) ETC is traded on exchanges, currently 1/100 size of ETH (market cap) No evidence of “un-upgraded nodes” ETC has also hard forked, Oct 25, 2016

  • Monero
  • Hard Fork to add new transaction type (RingCT) Jan 10, 2016
slide-62
SLIDE 62
slide-63
SLIDE 63

What have we learned from hard forks in practice?

  • Bitcoin soft forks have been repeated several times successfully

SegWit is the first not to be adopted immediately

  • Not all hard forks result in harm

This is not necessarily strong evidence that they are “safe”

  • Even the “Split currency” scenario (Eth / Eth Classic) is not immediately

catastrophic

slide-64
SLIDE 64

3.3: Off-Chain Payment Channels

slide-65
SLIDE 65

Scalability - the traditional distributed systems view

A desirable property of a distributed system design Means: You can increase capacity by adding more hardware (more nodes) to the system. The Bitcoin protocol does not exhibit this property! All nodes verify all of the transactions. To build a scalable cryptocurrency we need a redesign

slide-66
SLIDE 66

“Off-chain” protocols - the Very High Level Avoid blockchain transactions except in rare cases

Blockchain

slide-67
SLIDE 67

“Off-chain” protocols - the Very High Level Avoid blockchain transactions except in rare cases

Blockchain

Parties deposit money into a special transaction called a “smart contract”

slide-68
SLIDE 68

“Off-chain” protocols - the Very High Level Avoid blockchain transactions except in rare cases

Blockchain Out-of-band communication

slide-69
SLIDE 69

“Off-chain” protocols - the Very High Level Avoid blockchain transactions except in rare cases

Blockchain Out-of-band communication

Dispute raised Blockchain determines outcome Blockchain executes the remedy

slide-70
SLIDE 70

Unidirectional Payment Channels

Blockchain

Alice deposits $100

signature(Alice, “$1”)

Alice pays Bob by sending signatures on incrementally larger payments signature

slide-71
SLIDE 71

Unidirectional Payment Channels

Blockchain

Alice deposits $100

signature(Alice, “$1”) signature(Alice, “$2”) ….

Alice pays Bob by sending signatures on incrementally larger payments signature

slide-72
SLIDE 72

Unidirectional Payment Channels

Blockchain

Alice deposits $100

Alice pays Bob by sending signatures on incrementally larger payments signature

signature(Alice, “$1”) signature(Alice, “$2”) ….

At any point, Bob closes the channel by posting the largest signed message on the blockchain. If Bob aborts, Alice can claim a refund (after a time limit)

$2 $8

slide-73
SLIDE 73

def refund(): assert(msg.sender == alice) assert(block.number > deadline) // only after deadline send(alice, self.balance) def finalize(signature, amount): assert(msg.sender == bob) assert(verify_signature(alice, amount, sig))) send(bob, amount) send(alice, self.balance)

Unidirectional Payment Channels (Implemented in Ethereum)

Blockchain

slide-74
SLIDE 74

Lightning Network

  • Implemented in Bitcoin (“Raiden”: Lightning Network in Ethereum)
  • Channels support payments in two directions (Bob can pay Alice too)
  • Channels can be linked to each other, forming a payment chain

Similar to credit networks

  • Relies on the SegWit upgrade
  • Alpha software implementation in testing
  • Open questions: What will be the resulting topology? What impact on privacy?
slide-75
SLIDE 75

The details get more complicated….

slide-76
SLIDE 76

The future vision of off-chain scalability with Lightning:

  • Most users will store significant amount of Bitcoins in payment channels,
  • channels to peers that they trust
  • channels to “hubs” with high connectivity
  • Most transactions will occur along paths of established channels
slide-77
SLIDE 77

Last updated: April 2016! (as of Jan 17)

slide-78
SLIDE 78

Roughly, there are two factions*

*my perception

Bitcoin XT / Unlimited / Classic

  • “big blockers”
  • Volunteer nodes don’t matter, miners

have incentive to operate the system

  • Bitcoin is an experiment, market

growth is most important now

  • Hard forks have worked out for others
  • Road map: immediate relief

Blockstream, Bitcoin Core

  • “small blockers”
  • Concerned about full nodes
  • Risk averse, slow growth is fine
  • Prefer soft forks
  • Core road map: SegWit soft fork

→ Lightning Network

slide-79
SLIDE 79

Conclusion

  • The Bitcoin scaling controversy is only partially about “scalability”
  • The debate is about short term needs, and upgrade methods
  • Root disagreement about underlying priorities & assumptions
  • Empirical/scientific measurements don’t clearly favor either faction
  • Off-chain applications are promising approach for future

scalability