campbell r. harveycharvey/teaching/697... · 2019. 1. 31. · •basically, you're using your...

40
Cryptotransactions Campbell R. Harvey Duke University and NBER Innovation and Cryptoventures

Upload: others

Post on 04-Feb-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

  • CryptotransactionsCampbell R. Harvey

    Duke University and NBER

    Innovation and Cryptoventures

  • Campbell R. Harvey 2019 2

    Class discussion focuses on pp. 32‐78

  • The MechanicsLet’s start with Bitcoin transaction mechanics. 

    Simplified example: Alice buys something from Bob and sends him 1 bitcoin

    3

    Alice Bob

    1 BTC

    Campbell R. Harvey 2019

  • The Mechanics

    Examples: Alice 1 BTC  Bob• Bob generates a random number (private key). There is a public address that is mathematically linked to the random number.

    • Bob sends the public address to Alice • Public address can change for every transaction.• Alice adds Bob’s address and the amount of bitcoins to a 'transaction' message.

    • Alice signs the transaction • Alice broadcasts the transaction on the Bitcoin network for all to see.

    4Campbell R. Harvey 2019

  • The MechanicsExamples• Alice sends to Bob

    5

    Quoted in satoshiso 50 bitcoins

    Graphics from King, Williams and Yanofsky (2013) Campbell R. Harvey 2019

  • The MechanicsExamples• Transaction sent to every Bitcoin node on the Internet (the memory pool)• If the transaction is validated (and there is a non‐zero transaction fee), it will be 

    included in a block and eventually added to the ledger.

    6Graphics from King, Williams and Yanofsky (2013) Campbell R. Harvey 2019

  • The Mechanics

    Examples continue:Bob buys something from Carol and sends her 1 bitcoin

    7

    Alice Bob Carol

    1 BTC 1 BTC

    Campbell R. Harvey 2019

  • The MechanicsExamples• Bob sends Carol 1 bitcoin• Carol sets up a private key and a public address• Bob takes the bitcoin he got from Alice, uses his address and his private key to sign 

    it over to Carol

    8Graphics from King, Williams and Yanofsky (2013) Campbell R. Harvey 2019

  • The MechanicsExamples• Proposed transaction gets sent to all on network to ensure Bob has not already spent the bitcoin from Alice

    9

    Other transactions that have occurred since Alice’s original transfer to Bob

    Graphics from King, Williams and Yanofsky (2013) Campbell R. Harvey 2019

  • The MechanicsExamples• If transaction validated, then added to a candidate block

    10Graphics from King, Williams and Yanofsky (2013) Campbell R. Harvey 2019

  • The MechanicsThe ledger• Ledger broken up into 10 minute “blocks”• Every block contains a reference to the block before it so you can trace every 

    transaction all the way back to 2009

    11

    All of the blocks are called a blockchainGraphics from King, Williams and Yanofsky (2013) Campbell R. Harvey 2019

  • The MechanicsThe Bitcoin Blockchain• All full nodes (running bitcoind or Bitcoin‐Qt) (includes miners) have the complete blockchain

    • If a computer is turned off, when it starts up again, it will send a message to get the blocks created when computer was down

    • Current size of blockchain is approximately 200gb• Updates are provided by the system of miners

    12Campbell R. Harvey 2019

    https://blockchain.info/charts/blocks‐size

  • The Mechanics 2Transferring ownership• A better metaphor for transferring ownership of bitcoins (instead of serial numbers) is to use the concept of lock boxes. 

    • Basically, you're using your private key to open your lockbox and take out the values, then you're inserting it (say, via a one‐way slot) into someone else's lockbox that can only be opened with a different key.

    13Campbell R. Harvey 2019

  • The Mechanics 2Two people, Alice and Ted, send you bitcoin

    14Campbell R. Harvey 2019

    Ted

    https://www.cryptocoinsnews.com/bitcoin‐transaction‐really‐works/

  • The Mechanics 2Contents of the wallet are not mixed up

    15Campbell R. Harvey 2019https://www.cryptocoinsnews.com/bitcoin‐transaction‐really‐works/

  • The Mechanics 2You send 0.15BTC to Bob

    16Campbell R. Harvey 2019https://www.cryptocoinsnews.com/bitcoin‐transaction‐really‐works/

  • The Mechanics 2Spending destroys UTXO (unspent transaction output) and creates new ones

    17Campbell R. Harvey 2019https://www.cryptocoinsnews.com/bitcoin‐transaction‐really‐works/

  • The Mechanics 3Validation• Miners compete to add a new block to the chain• Need to complete a cryptographic “proof of work”• Problem is different for each block and involves a cryptographic hash functions which take an input and delivers an output

    • Each block contains the “Proof of Work” (it is difficult to produce but easy to check)

    18Campbell R. Harvey 2019

  • The Mechanics 3

    19Campbell R. Harvey 2019https://blockexplorer.com/

  • The Mechanics 3

    20Campbell R. Harvey 2019https://etherscan.io/

  • The Mechanics 3What is the proof of work?• When the miner finds the nonce that works, they “win” the block.• They provide the nonce with the block contents and everyone (not just miners) verifies

    21Graphics from King, Williams and Yanofsky (2013) Campbell R. Harvey 2019

  • The Mechanics 3

    What is the proof of work?• The block gets sent to every miner

    • They get the winner’s nonce and verify the hash

    • Work is hard to solve but easy to verify

    22Graphics from King, Williams and Yanofsky (2013) Campbell R. Harvey 2019

  • The Mechanics 3It is a little more complicated …• In previous example, there might be an incentive  to have a small number of transactions in block

    • This is solved by having miners represent a block (no matter the number of transactions in the block) with only 80 bytes (which is small)

    • The key is to understand what is in it

    23Campbell R. Harvey 2019

  • The Mechanics 380 bytes*• 4 bytes: version number (same for all miners)• 32 bytes: previous block (same for all miners)• 32 bytes: hash of the transactions in the candidate block• 4 bytes: time stamp• 4 bytes: difficulty of task (same for all miners)• 4 bytes: nonce

    *Each component in hexadecimal or translated to hexadecimal. The hexadecimal is then expressed in little‐endian format, i.e. 12345678 in little‐endian is 78563412. The string is hashed twice with SHA‐256 and final hash is presented in little‐endian format. 

    24Campbell R. Harvey 2019

  • The Mechanics 3Miner will vary the nonce – but a good machine can try all possible 32‐bit nonce combinations in less than 1 second (about 4 billion calculations)• Time stamp can also be varied (naturally changes after nonces are tried)• Miners may also vary the order to which transactions are grouped (in a Merkle tree)

    25Campbell R. Harvey 2019

  • The Mechanics 3Hash of the transactions is a Merkle tree (or hash tree) which includes multiple hashes

    26

    Each data block is a transaction

    Block averages 2,000 transactions

    https://blockchain.info/chartsCampbell R. Harvey 2019http://chimera.labs.oreilly.com/books/1234000001802/ch07.html#merkle_trees

  • The Mechanics 3Merkle trees very efficient. Note Merkle is Ralph Merkle not Angela Merkel. 

    27Campbell R. Harvey 2019http://chimera.labs.oreilly.com/books/1234000001802/ch07.html#merkle_trees

  • The Mechanics 3Lots of hashes! 44 million terahashes per second!

    28Campbell R. Harvey 2019https://blockchain.info/charts

  • The Mechanics 3Lots of hashes! 44 million terahashes per second!

    29Campbell R. Harvey 2019

    1 million machines to buy 50% of mining power= $1.8b

    Realistically, you would have buy much more because by the timeyou get delivery, you will have less than half the hashing power

    http://www.bitcoinx.com/profit/[Profitability calculator]

  • The Mechanics 3Miners’ role:• Mining code is open source• Miners are competitive• Miners pool resources and can be strategic

    Miners’ purpose:• New bitcoins are distributed to those that are doing the work• Miners provide Proof of Work that makes the network work (i.e., transactions validated and blocks cryptographically linked) so that no trust is needed

    30Campbell R. Harvey 2019

  • The Mechanics 3Vulnerability• If a mining pool gains a large amount of computing capacity, they can attack the network

    • They could theoretically attempt to rewrite some history (though likely only recent history)

    31Campbell R. Harvey 2019

  • The Mechanics 3Vulnerability• January 9, 2014 Ghash.io had 45% of all mining• Had to appeal to people to exit the pool

    32See their press release: https://ghash.io/ghashio_press_release.pdf

    Campbell R. Harvey 2019

  • The Mechanics 3Vulnerability• Not clear what the incentive is to “take over”

    • If it ever happened, the value of the Bitcoin might disappear

    33Campbell R. Harvey 2019

  • The Mechanics 3Vulnerability• January 2019: Three pools controlling almost 50%

    34See https://blockchain.info/pools Campbell R. Harvey 2019

  • The Mechanics 3Vulnerability• January 2019: Three pools control nearly 40%

    35See https://blockchain.info/pools Campbell R. Harvey 2019

  • The MechanicsWhat does a mining farm look like? Mongolia

    36https://qz.com/1055126/photos‐china‐has‐one‐of‐worlds‐largest‐bitcoin‐mines/

    Campbell R. Harvey 2019

  • The MechanicsWhat does a mining farm look like? Iceland

    37http://www.businessinsider.com/photos‐of‐iceland‐bitcoin‐ethereum‐mine‐genesis‐mining‐cloud‐2017‐5?op=0

    Campbell R. Harvey 2019

  • The Mechanics

    38See https://bitnodes.earn.com/

    Campbell R. Harvey 2019

  • The Mechanics 4Private Key/Public Key:• Bitcoin based on strong cryptography• Usually we think of using a key to encrypt and decrypt• It is possible to use two keys: private (secret) and public (give to anyone)• You can sign a message using a private key such that the signature is unforgeably tied to the public key

    • Two keys are known as the “key pair”• Collection of keys is called a “wallet”

    39Campbell R. Harvey 2019

  • The Mechanics 4Signing:• Signing involves: message, your private key and a nonce• Anyone can use the message, digital signature coordinates, and public key to verify that the message was created with the private key

    • Three key properties of a digital signature:– Authorization (I can/I am the owner)– Non‐repudiation (I meant to)– Integrity (This what I meant)

    40Campbell R. Harvey 2019