1 of 59

Bitcoin Tutorial

Bitcoin and Cryptocurrency Workshop

CITP, Princeton

Joseph Bonneau

Thanks to Andrew Miller, Arvind Narayanan, Jeremy Clark, Joshua Kroll, Ed Felten

2 of 59

Bitcoin has many different parts!

3 of 59

Part I: Bitcoin in 6 easy steps

4 of 59

Double spending: why ecash is hard

BANK

Alice

Bob

SignA(Transfer X to B)

Charlie

SignA(Transfer X to C)

SignZ(Transfer X to A)

Redeem X?

Redeem X?

5 of 59

Step 1: Make the bank a global log

SignA(Transfer X to C)

...

SignA(Transfer X to B)

...

SignA(Transfer X to C)

(the block chain)

SignatureBANK

SignatureBANK

SignatureBANK

SignatureBANK

6 of 59

Step 2: Participants vote on blocks

SignatureA SignatureB SignatureC ...

SignatureA SignatureB SignatureC ...

SignatureA SignatureB SignatureD ...

7 of 59

Step 3: A random user picks

N-2

N-1

SignA(Transfer X to C)

SignatureB

SignatureA

N

SignatureC

N

C

8 of 59

Step 4: Resolve conflicts by forking

SignA(Transfer X to B)

SignatureB

SignatureA

SignA(Transfer X to C)

SignatureC

SignatureD

SignatureE

9 of 59

Step 5: Incentivise correct blocks

SignatureB

SignatureA

SignatureC

SignatureD

SignatureE

Mint(X, A)

Mint(X, B)

Mint(X, D)

Mint(X, E)

Mint(X, C)

10 of 59

Step 6: Choose by hash power!

Mint(X, A)

Mint(X, B)

Mint(X, C)

SHA-256(BlockN-1, n) = 0x00000000000000003f89...

SHA-256(BlockN-1, n) = 0x00000000000000008c71...

Mining difficulty

Mining difficulty

11 of 59

Preventing double spending

SignA(Transfer X to B)

SignA(Transfer X to C)

SignA(Transfer X to B)

Longest chain wins

12 of 59

Transaction confirmation (~6 blocks)

13 of 59

Bitcoin is transaction-based

IN:

scriptSig ...

scriptSig ...

OUT:

scriptPub A, 5.9

...

...

IN:

scriptSig A

OUT:

scriptPubB, 5.0

scriptPubA, 0.9

IN:

scriptSig A

scriptSig A

OUT:

scriptPubC, 10.0

IN:

scriptSig ...

OUT:

scriptPubA, 9.2

...

14 of 59

Bitcoin transactions specify scripts

scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG

IN:

scriptSig ...

scriptSig ...

OUT:

scriptPub A, 5.9

IN:

scriptSig A

OUT:

scriptPubB, 5.0

scriptPubA, 0.9

<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG

scriptSig: <sig> <pubKey>

Redemption script:

15 of 59

Bitcoin transactions specify scripts

<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG

<sig>

<pubKey>

<pubKey>

<pubKeyHash>

<pubKeyHash>

16 of 59

Bitcoin script features

  • multiple signatures
  • escrow
  • time locking
  • commitment opening

...

  • smart contracts?

17 of 59

Part II: Mining & Consensus

18 of 59

51% attacks

Goldfinger Attack?

19 of 59

Checkpointing

How decentralized is Bitcoin?

20 of 59

Selfish mining

Observation: for 0.33 < x < 0.5, a fraction x of selfish miners can earn greater than a fraction x of rewards

Secret Block

Secret Block

Majority is not enough: Bitcoin mining is vulnerable

Ittay Eyal and Emin Gün Sirer. Financial Crypto 2014

21 of 59

Mining difficulty

bitcoinwisdom.com

22 of 59

Difficulty adjustment

bitcoinwisdom.com

10 minutes

2 weeks

23 of 59

Mining rewards

Courtesy:

Brian Warner

24 of 59

Total network capacity

  • 264 hashes per block (every 10 minutes!)
  • 275 hashes in 2013
    • In exchange for ~US$250M
  • Consuming > 100 MW

25 of 59

Bitcoin mining hardware

26 of 59

Should I mine bitcoins?

Chilkoot pass, Klondike 1898

27 of 59

Mining pools

Mint(25, KPOOL)

0x00000000000000003f89...

0x000000000000490c6b00...

0x00000000000000003f89...

0x0000000000001e8709ce...

0x00000000000007313f89...

0x00000000000045a1611f...

0x000000000000a877902e...

28 of 59

Mining pools

29 of 59

Part III: Bitcoin as a currency

30 of 59

Why does Bitcoin have value?

Consensus

  • Consensus in state (blockchain)
  • Consensus in payment
  • Consensus in rules

The Economics of Bitcoin Mining, or Bitcoin in the Presence of Adversaries

Joshua Kroll, Ian Davey, Ed Felten. WEIS 2013

31 of 59

Price during 2013

32 of 59

Black Markets

Silk Road: US$14M in Revenue in 2012 [Christin 2012]

Traveling the Silk Road: A measurement analysis of a large anonymous online marketplace

Nicolas Christin, WWW 2013

33 of 59

Capital controls

34 of 59

E-commerce

35 of 59

Bitcoin exchanges

Beware the middleman: Empirical analysis of Bitcoin-exchange risk

Tyler Moore and Nicolas Christin, Financial Crypto 2013

36 of 59

Part IV: Neat applications

37 of 59

Green Addresses

(speeding up payments)

IN:

scriptSig ...

OUT:

scriptPub A, 10.0

IN:

scriptSig A

OUT:

scriptPub O, 1.0

scriptPub A, 9.0

x 6

38 of 59

Green Addresses

(speeding up payments)

IN:

scriptSig ...

OUT:

scriptPub G, 10.0

IN:

scriptSig A

OUT:

scriptPub O, 1.0

scriptPub A, 9.0

I promise to never double-spend!

39 of 59

Sequential micropayments

IN:

scriptSig ...

OUT:

scriptPub G, 10.0

I promise to never double-spend!

IN:

scriptSig A

OUT:

scriptPub O, 0.1

scriptPub A, 9.9

IN:

scriptSig A

OUT:

scriptPub O, 0.2

scriptPub A, 9.8

IN:

scriptSig A

OUT:

scriptPub O, 0.3

scriptPub A, 9.7

IN:

scriptSig A

OUT:

scriptPub O, 0.4

scriptPub A, 9.6

40 of 59

Secure commitments (timestamping)

Hash

Data

CommitCoin: carbon dating commitments with Bitcoin

Jeremy Clark, Aleksander Essex. Financial Crypto 2012

41 of 59

Randomness Beacon

Hash

=

42 of 59

Part V: Anonymity

43 of 59

Tracing Bitcoin transactions

IN:

scriptSig A1

scriptSig A2

OUT:

scriptPub A3, 5.9

...

...

IN:

scriptSig A3

OUT:

scriptPubB, 5.0

scriptPubA4, 0.9

Joint control

Change addresses

44 of 59

Building the transaction graph

A Fistful of Bitcoins: Characterizing Payments Among Men with No Names

Sarah Meiklejohn et al, IMC 2013

45 of 59

Bitcoins carry a transaction history

  • identification
  • censorship

  • recovery from theft
  • economic analysis

Towards Risk Scoring of Bitcoin Transactions

Möser, Malte, Rainer Böhme, and Dominic Breuker, BITCOIN 2013

46 of 59

Mixes

47 of 59

Mixes today

Caution: Mixing services may themselves be operating with anonymity. As such, if the mixing output fails to be delivered or access to funds is denied there is no recourse. Use at your own discretion.

-The Bitcoin Wiki

An inquiry into money laundering tools in the Bitcoin ecosystem

Möser, Malte, Rainer Böhme, and Dominic Breuker, ECRIME 2013

48 of 59

Better mixes with warranties

If v kesc by tin, but not vkout by tout

The client publishes

If I send you v bitcoins by time tin

Will you send v to my address kout by time tout?

Sure! Just send your coins kesc

Sign(v, tin, tout ,kout ,kesc}

Anyone can verify cheating

(Ideally) no one trusts anymore

Mixcoin: Anonymity for Bitcoin with accountable mixes

J. Bonneau, A. Narayanan, A. Miller, J. Clark, J. Kroll, E. Felten. Financial Crypto 2013

49 of 59

Coin Join

IN:

scriptSig P

scriptSig M

scriptSig S

OUT:

scriptPub P’, 1.0

scriptPub M’, 1.0

scriptPub S’, 1.0

50 of 59

Zerocoin

Bitcoin

Zerocoin

CRYPTO!

Zerocoin: Anonymous distributed e-cash from bitcoin

Ian Miers, Christina Garman, Matthew Green, Avi Rubin. IEEE Oakland 2013

51 of 59

Zerocash

“Cryptocurrencies are just a gateway drug to SNARKS”

Zerocash: Decentralized Anonymous Payments from Bitcoin

E. Ben-Sasson, A. Chiesa, C. Garman, M. Green, I. Miers, E. Tromer, M. Virza IEEE Oakland 2014

52 of 59

Part VI: Extensions & Altcoins

53 of 59

Types of changes to Bitcoin

  • overlay
  • soft fork
  • hard fork
  • alternate chain
  • alternate systems

Easy

Hard

Deployment

difficulty

54 of 59

Overlays

55 of 59

Soft fork changes

  • Pay-to-script-hash
  • Pay-to-SNARK (CoinWitness)
  • ECDSA-P256 replacements
  • Zerocoin

56 of 59

Hard fork changes

  • Change block size
  • Change block frequency
  • Various bug fixes
  • Restructuring the chain

57 of 59

Altcoins (Bitcoin-like chain)

58 of 59

Other altcoins

59 of 59

Questions