Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ブロックチェーン連続講義 第2-3回 ビットコインの技術 / Bitcoin Technology

ブロックチェーン連続講義 第2-3回 ビットコインの技術 / Bitcoin Technology

ブロックチェーンハブ主催で開催している第2期ブロックチェーン連続講義の第3回「ビットコインの技術」のスライドです。2016年7月15日(金) に使用しました。

Kenji Saito

July 15, 2016
Tweet

More Decks by Kenji Saito

Other Decks in Technology

Transcript

  1. Satoshi Nakamoto, “Bitcoin: A Peer-to-Peer Electronic Cash System”, 2008 P2P

    http://bitcoin.org/ BTC (ISO XBT ) 2013 11 1BTC 10 — 2016-07-15 – p.6/47
  2. 21 ( 4 ) ( ) 2,100 BTC 1 1

    BTC 2140 20,999,999.9769 BTC — 2016-07-15 – p.21/47
  3. POW ( ) Proof Of Work . . . —

    2016-07-15 – p.25/47
  4. Transaction Data Structure Field Description Size (bytes) Version Currently 1

    4 # of inputs Positive var-int 1∼9 List of inputs Variable # of outputs Positive var-int 1∼9 List of outputs Variable Lock time 4 — 2016-07-15 – p.29/47
  5. Output Data Structure Field Description Size (bytes) Amount Value in

    10−8BTC 8 Script length Positive var-int 1∼9 Script Variable — 2016-07-15 – p.30/47
  6. Input Data Structure Field Description Size (bytes) Referred TX Double

    SHA-256 value 32 Referred output Index of the output 4 Script length Positive var-int 1∼9 Script Variable Sequence # 4 — 2016-07-15 – p.31/47
  7. Major Script Operators Operator Code Description OP_0 0 Push 0

    byte N/A 1∼0x4b Push # bytes OP_PUSHDATA1 0x4c Push length specified by 1-byte suffix OP_PUSHDATA2 0x4d Push length specified by 2-byte suffix OP_PUSHDATA4 0x4e Push length specified by 4-byte suffix OP_NOP 0x61 Do nothing OP_VERIFY 0x69 TX invalid if not true OP_DUP 0x76 Copy 1 item OP_EQUAL 0x87 If 2 items match OP_EQUALVERIFY 0x88 OP_EQUAL → OP_VERIFY OP_HASH160 0xa9 Apply SHA-256→RIPEMD-160 OP_CHECKSIG 0xac If signature for TX verified OP_CHECKMULTISIG 0xae If multiple signatures for TX verified Script is a stack-oriented language with postfix notation — 2016-07-15 – p.32/47
  8. Script (General) Output: OP_DUP OP_HASH160 OP_PUSHDATA* <Public-key digest> OP_EQUALVERIFY OP_CHECKSIG

    Input: OP_PUSHDATA* <Signature> OP_PUSHDATA* <Public key> TX output addressed to a public-key digest and referring input — 2016-07-15 – p.33/47
  9. Script (Generation) Output: OP_PUSHDATA* <Public key> OP_CHECKSIG Input: OP_PUSHDATA* <Signature>

    Gen. TX otuput and referring input No need to specify public key by its digest Can avoid compromising security down to 160bit — 2016-07-15 – p.35/47
  10. Block Data Structure Field Description Size (bytes) Block header 6

    items 80 # of TXs Positive var-int 1∼9 List of TXs Variable — 2016-07-15 – p.36/47
  11. Block Header Data Structure Field Description Size (bytes) Version 4

    Digest Double SHA-256 value 32 Merkle root Double SHA-256 value 32 Time Seconds (since 1970-01-01T00:00 UTC) 4 Target Compressed format 4 Nonce Appropriate value 4 Merkle root is the digest of all TXs — 2016-07-15 – p.37/47
  12. Networking No structure All TCP, default port number: 8333 IPv6

    supported since v0.7 of reference implementation (v0.9.4 as of Jan. 2015) Can use IPv4, IPv6 or Tor In reference implementation Max # of outbound connections : 8 Max # of all connections : 125 (by default) Only one outbound connection to an address group High 16bit in IPv4 High 32bit in IPv6 — 2016-07-15 – p.39/47
  13. Major Messages Category Name Function Connection version Sends version and

    block # verack Acknowledges version addr (address) Sends list of IP address/port # getaddr Requests addr Data inv (inventory) Sends (new) blocks and/or txs transfer getblocks Requests inv for all blocks within range getdata Requests block/tx by the digest block Sends block replying to getdata tx (transaction) Sends tx replying to getdata Header getheaders Requests headers for all blocks within range transfer headers Sends block headers up to 2,000 Others alert Broadcasts alert ping Confirms connection pong Acknowledges ping — 2016-07-15 – p.40/47
  14. Message Structure Field Description Size (bytes) Magic number 0xd9b4bef9 4

    Command Message name (ASCII string) 12 Payload length Size of payload in bytes 4 Checksum Double SHA-256 value of payload First 4 Payload Message data Variable All integers are encoded in Little Endian except IP address and port # We’ve just seen the payloads for block and tx messages — 2016-07-15 – p.41/47
  15. BTC ( ) LTC ( ) DOGE ( ) ETH

    ( ) — 2016-07-15 – p.46/47