1 / 46

Cryptotransactions

Learn the mechanics of Bitcoin transactions, including the process of transferring ownership, validating transactions, and the use of cryptographic hash functions.

mcelfresh
Download Presentation

Cryptotransactions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Innovation and Cryptoventures Cryptotransactions Campbell R. Harvey Duke Universityand NBER January 2, 2019

  2. Class discussion focuses on pp. 32-78 Campbell R. Harvey 2019

  3. The Mechanics Simplified example: Alice buys something from Bob and sends him 1 bitcoin Alice Bob 1 BTC Campbell R. Harvey 2019

  4. 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 (more later on this!) • Alice broadcasts the transaction on the Bitcoin network for all to see. Campbell R. Harvey 2019

  5. The Mechanics Quoted in satoshi so 50 bitcoins Examples • Alice sends to Bob Campbell R. Harvey 2019 Graphics from King, Williams and Yanofsky (2013)

  6. The Mechanics Examples • Transaction sent to every Bitcoin node on the Internet • If the transaction is validated, it will be included in a block and eventually added to the ledger. Campbell R. Harvey 2019 Graphics from King, Williams and Yanofsky (2013)

  7. The Mechanics Examples continue: Bob buys something from Carol and sends her 1 bitcoin Alice Bob Carol 1 BTC 1 BTC Campbell R. Harvey 2019

  8. The Mechanics Examples • 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 Campbell R. Harvey 2019 Graphics from King, Williams and Yanofsky (2013)

  9. The Mechanics Examples • Proposed transaction gets sent to all on network to ensure Bob has not already spent the bitcoin from Alice Other transactions that have occurred since Alice’s original transfer to Bob Campbell R. Harvey 2019 Graphics from King, Williams and Yanofsky (2013)

  10. The Mechanics Examples • If transaction validated, then added to a candidate block Campbell R. Harvey 2019 Graphics from King, Williams and Yanofsky (2013)

  11. The Mechanics The 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 All of the blocks are called ablockchain Campbell R. Harvey 2019 Graphics from King, Williams and Yanofsky (2013)

  12. The Mechanics 2 Transferring 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. Campbell R. Harvey 2019

  13. The Mechanics 2 Two people, Alice and Ted, send you bitcoin Ted Campbell R. Harvey 2019 https://www.cryptocoinsnews.com/bitcoin-transaction-really-works/

  14. The Mechanics 2 Contents of the wallet are not mixed up Campbell R. Harvey 2019 https://www.cryptocoinsnews.com/bitcoin-transaction-really-works/

  15. The Mechanics 2 You send 0.15BTC to Bob Campbell R. Harvey 2019 https://www.cryptocoinsnews.com/bitcoin-transaction-really-works/

  16. The Mechanics 2 Spending destroys UTXO (unspent transaction output) and creates new ones Campbell R. Harvey 2019 https://www.cryptocoinsnews.com/bitcoin-transaction-really-works/

  17. The Mechanics 3 Validation • 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) Campbell R. Harvey 2019

  18. The Mechanics 3 Hash (SHA-256) • SHA-256 (Secure Hash Algorithm) developed by the NSA • Output is 64 numbers/characters (called hexadecimal, a-f + 0-9) no matter how long the input it receives Campbell R. Harvey 2019

  19. The Mechanics 3 Hash • It only goes one way. Once you have the output, you cannot go back to the input. Think of it as generating a unique identifier • Even a trivial change in the input, produces a completely different hash • On-line calculator example: http://www.xorbin.com/tools/sha256-hash-calculator • You also will have access to a Python program • SHA-512 at http://abunchofutils.com/u/computing/sha512-hash-calculator/ Campbell R. Harvey 2019

  20. The Mechanics 3 Hash • SHA-256 maximum input size is 264-1 bits • Large number? Suppose you put one penny on the first square of a chess board, two pennies on next, etc. • How much is on the 64th square? Campbell R. Harvey 2019

  21. The Mechanics 3 Hash • SHA-256 maximum message size is 264-1 bits • Large number? Suppose you put one penny on the first square of a chess board, two pennies on next, etc. • How much is on the last square? • $9,223,372,036,854,780.00 ($9.2 quadrillion) • US GDP $19,000,000,000.00 • Hash allows for 18.5 quadrillion bits of input Importantly, we are only talking about the inputs. To break the SHA-256, you need to evaluate 2256 (See FAQs). Campbell R. Harvey 2019

  22. The Mechanics 3 Hash • Some previous hashes, SHA-1 and SHA-0 have been abandoned because of actual or theoretical “collisions” • A collision is when two different inputs lead to the same output • Note SHA-256 also used for SSL (Secure Sockets Layer) for secure traffic on the Internet • Also there is SHA-512 which is in the category of SHA-2 (allows for 2128 -1 bits) and a new class of SHA-3 which uses 5x5 arrays of 64-bit words Campbell R. Harvey 2019

  23. The Mechanics 3 What is the proof of work? • Miners take a hash of the contents of the block they are working on (transactions, time stamps, reference to previous block) plus a random number called a “nonce” Nonce is a 32-bit block of data Campbell R. Harvey 2019 Graphics from King, Williams and Yanofsky (2013)

  24. The Mechanics 3 What is the proof of work? • Their goal is to find a hash that has at least a certain number of leading zeroes, e.g. 00000eb9c313a3c87d4b1fadb69a9d1395cdbc802b10707fa7e620ad722c0f63 • More leading zeroes means fewer solutions – and more time to solve the problem – it determines the “difficulty” (currently 18 zeros) • Every 2016 blocks (two weeks), the difficulty is reset • If it takes less than 10 minutes on average to solve the 2016 blocks, the difficulty is reset automatically Campbell R. Harvey 2019

  25. The Mechanics 3 https://blockexplorer.com/ Campbell R. Harvey 2019

  26. The Mechanics 3 What 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 Campbell R. Harvey 2019 Graphics from King, Williams and Yanofsky (2013)

  27. 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 Campbell R. Harvey 2019 Graphics from King, Williams and Yanofsky (2013)

  28. The Mechanics 3 It 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 Campbell R. Harvey 2019

  29. The Mechanics 3 80 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. See appendix. Campbell R. Harvey 2019

  30. The Mechanics 3 Miner will vary the nonce – but a good machine can try all possible 32-bit nonce combinations in about 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) Campbell R. Harvey 2019

  31. The Mechanics 3 Hash of the transactions is a Merkle tree (or hash tree) which includes multiple hashes Block averages 2,000 transactions Each data block is a transaction Campbell R. Harvey 2019 https://blockchain.info/charts http://chimera.labs.oreilly.com/books/1234000001802/ch07.html#merkle_trees

  32. The Mechanics 3 Merkle trees very efficient. Note Merkle is Ralph Merkle not Angela Merkel. Campbell R. Harvey 2019 http://chimera.labs.oreilly.com/books/1234000001802/ch07.html#merkle_trees

  33. The Mechanics 3 Lots of hashes!15 million terahashesper second! https://blockchain.info/charts Campbell R. Harvey 2019

  34. The Mechanics 3 Lots of hashes!15 million terahashesper second! 15 million TH/s divided by 13.5 = 1.1 million machines Cost of matching current network power= $6 billion Realistically, you would have buy much more because by the time you get delivery, you will have less than half the hashing power http://www.bitcoinx.com/profit/ [Profitability calculator] Campbell R. Harvey 2019

  35. The Mechanics 3 Miners’ 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 Campbell R. Harvey 2019

  36. The Mechanics 3 Vulnerability • 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) Campbell R. Harvey 2019

  37. The Mechanics 3 Vulnerability • January 9, 2014 Ghash.io had 45% of all mining • Had to appeal to people to exit the pool Campbell R. Harvey 2019 See their press release: https://ghash.io/ghashio_press_release.pdf

  38. The Mechanics 3 Vulnerability • January 2018: Three pools controlling almost 50% Campbell R. Harvey 2019 See https://blockchain.info/pools

  39. The Mechanics 3 Vulnerability • January 2018: Three pools controlling almost 50% Campbell R. Harvey 2019 See https://blockchain.info/pools

  40. The Mechanics What does a mining farm look like? Mongolia Campbell R. Harvey 2019 https://qz.com/1055126/photos-china-has-one-of-worlds-largest-bitcoin-mines/

  41. The Mechanics What does a mining farm look like? Iceland Campbell R. Harvey 2019 http://www.businessinsider.com/photos-of-iceland-bitcoin-ethereum-mine-genesis-mining-cloud-2017-5?op=0

  42. The Mechanics Campbell R. Harvey 2019 See https://bitnodes.earn.com/

  43. The Mechanics 3 Vulnerability • Not clear what the incentive is to “take over” • If it ever happened, the value of the Bitcoin might disappear Campbell R. Harvey 2019

  44. The Mechanics 4 Private 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 know as the “key pair” • Collection of keys is called a “wallet” Campbell R. Harvey 2019

  45. The Mechanics 4 Signing: • Signing involves your private key and a nonce • Anyone can use the nonce and public key to verify that the message was created with the private key • Creation of a transaction address is very secure, involves • Cryptographic “Elliptic Curve DSA” on curve secp256k1 • Double application of SHA-256 hash • Application of RIPEMD-160 hash Campbell R. Harvey 2019

  46. The Mechanics 4 How it works: • Users connect to the Bitcoin Network • Client “wallet” (key management module) generates public/private key pairs based off of random number stream • Key pairs use Elliptic Curve Cryptography (ECDSA) • Public key is encoded into a 27-34 character address string that can be shared to receive payments • Private key is used to spend coins by digitally signing transaction messages that reference specific deposits sent to it Keypairs managed in Bitcoin Wallet Software 2^160 possible addresses! Cheap, expendable, easy to produce “Bank Account Number” “Signing Key” Source: Brad Wheeler, Bitcoin: What is it? Campbell R. Harvey 2019

More Related