CBGTBT - Part 4 - Mining

download CBGTBT - Part 4 - Mining

If you can't read please download the document

Transcript of CBGTBT - Part 4 - Mining

  1. 1. Mining @blockstrap #StartingBlock2015
  2. 2. Introduction & Primer First, some context These slides are from the #StartingBlock2015 tour by @blockstrap. 6 European countries in 8 days (Istanbul, Amsterdam, Barcelona, Prague, Berlin & London). We met lots of great people, answered lots of great questions and had a great time. We look forward to meeting many of them again in the near future. These slides might only make perfect sense if you were at the talks and can remember all the additional points we made whilst discussing the tech. This deck is 4th of 6. Questions? Comments? @MrAdamGiles [email protected]
  3. 3. Mining Refresher Transactions are broadcast to the network Blocks store records of transactions Blocks are created by Miners and then broadcast New blocks are added to the chain Miners then compete to build the next block
  4. 4. Mining So... Mining is the process of collecting transactions and solving a block Blocks are immutable, we need to make sure theyre right We make solving a block hard and slow - maths to the rescue but we want to make verifying a block easy Because we make mining hard, we reward miners with bitcoin! Mining is the process of securing the blockchain
  5. 5. Mining Proof of Work All the transactions in the block are used to create the Merkle Root hash Its added to the other metadata in the header, with a nonce We hash the whole thing, look at the resulting hash If it starts with a 0 then weve solved the block, and broadcast it If not, we increment the nonce and try again Repeat until we find the leading zero
  6. 6. Mining Overly Simplified Example #!/usr/perl use Digest::SHA qw(sha256_hex); $last_block_hash = '5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9'; $tns = 'from:01234567890,to:354635406540654,Amount:100.00000000BTC'; $found_block = false; $nonce=0; while (false == $found_block){ $hash = sha256_hex($last_block_hash . $tns . $nonce); if("0" == substr($hash,0,1)){ $found_block=true; print 'Found!'; }else{ $nonce++; } }
  7. 7. Mining Overly Simplified Example 5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9 6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35 4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce 4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a ef2d127de37b942baad06145e54b0c619a1f22327b2ebbcfbec78f5564afe39d e7f6c011776e8db7cd330b54174fd76f7d0216b612387a5ffcfb81e6f0919683 7902699be42c8a8e46fbbb4501726517e86b22c56a189f7625a6da49081b2451 2c624232cdd221771294dfbb310aca000a0df6ac8b66b696d90ef06fdefb64a3 19581e27de7ced00ff1ce50b2047e7a567c76b1cbaebabe5ef03f7c3017bb5b7 0a44dc15364204a80fe80e9039455cc1608281820fe2b24f1e5233ade6af1dd5 It took 11 tries to solve this block!
  8. 8. Mining Easy Peasy Lemon Squeezy 11 attempts isnt very many, we need to make it harder We introduce the concept of difficulty Difficulty defines how many leading zeros when solving the block The more zeros we have find, the more attempts at hashing we need More hashing power becomes the driving force amongst miners
  9. 9. Mining Increasing the Difficulty As a way of controlling how hard it is to solve a block Can be adjusted to make it easier or harder Target time of 10mins per block As miners add hashing power to the network, we need to make it harder so increase the difficulty to compensate Difficulty is recalculated every 2016 blocks (approx 2 weeks)
  10. 10. Mining Crazy Increases in Difficulty
  11. 11. Mining Its A Race Miners try to solve the block at the next height from the top of the chain The first to achieve it gets their block added to the chain All the other work done by the other miners is wasted To create more blocks than other people, youd have to have more hashing power than everyone else Current hashing power in the bitcoin network is more than the top 500 supercomputers combined
  12. 12. Mining Maintaining Blockchain Integrity Could someone with lots of hashing power control the blockchain? In theory, yes - simply compute blocks with double spend transactions & broadcast to the network But you need to control 50%+1 of the network for it to work reliably Network is currently at ~340 thousand terahashes per second That's 340,000,000,000,000,000 hashes per second!
  13. 13. Mining Too Much Math For One Man Club together in Mining Pools Each pool has many miners who split the problem up All members try to solve the same block in parallel Rewards are shared between the members
  14. 14. Mining Back in 2013
  15. 15. Mining Surviving miners have smaller %
  16. 16. Evolution of Mining Equipment
  17. 17. Mining 2009 CPU Nice Simple
  18. 18. Mining 2010-2011 GPU Faster speeds Parallel Computation
  19. 19. Mining GPU Scaling Up
  20. 20. Mining GPU Scaling Up
  21. 21. Mining GPU Scaling Up
  22. 22. FPGAs Off the shelf HW Programmable chips Mining 2012 - 2013
  23. 23. 2013 Mining ASICs Custom Built HW Specialist Hashing chips
  24. 24. Why Bother? Mining You get paid! When you collect the transactions into a block, the miner inserts a special transaction at the beginning called a coinbase transaction This pays the miner for the work they did, and collects the transaction fees from all the transactions The coinbase value declines over time (halved every 4 years) This is the only way bitcoin is created - Only 21m btc will be created
  25. 25. Could You Fake A Block? Mining The hashing work you did proof of work is easy to verify, a node will repeat the final hash you did to see if they get the same result as you. If not, the node wont add the block to the blockchain The coinbase payment amount is based on an algorithm, if you fake it, the block is rejected If the block is rejected by the nodes, you dont get any of the money you faked So no, you cant fake them!
  26. 26. Any Questions?