SHARE
TWEET

Worked example of mining a bitcoin block

a guest Oct 15th, 2013 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. https://en.bitcoin.it/wiki/Protocol_specification#Block_Headers
  2.  
  3. Let's look at block 125552, because that's the one I used to slash through this conceptual forest a few months ago.
  4.  
  5. http://blockexplorer.com/block/00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d
  6.  
  7. $ cat btc-blocks/125552
  8. 01000000
  9. 81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000
  10. e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b
  11. C7F5D74D
  12. F2B9441A
  13. 42A14695
  14.  
  15. Nonce (the last field in the block header) is the primary thing you vary while mining. There's an "extraNonce" field in the coinbase transaction, which you can also use to take some more entropy. Here the value 42A14695 happens to solve the block:
  16.  
  17. $ xxd -p -r btc-blocks/125552 |sha256sum |xxd -p -r |sha256sum
  18. 1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000  -
  19.  
  20. All those zeroes at the end are what you're after. You're not strictly after "many zeroes at the end" but a value that's less than some threshold determined by network difficulty. It's backwards because of endianness getting into things. If you had used any other value for the nonce field (or indeed any of the fields in the block header - but the nonce is the one that's most convenient to vary while mining), the block hash would be overwhelmingly unlikely to satisfy the difficulty requirement.
RAW Paste Data
Top