29. 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
ブロックチェーン連続講義 第 3 回「ビットコインの技術」 — 2016-03-04 – p.29/47
30. Output Data Structure
Field Description Size (bytes)
Amount Value in 10−8BTC 8
Script length Positive var-int 1∼9
Script Variable
ブロックチェーン連続講義 第 3 回「ビットコインの技術」 — 2016-03-04 – p.30/47
31. 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
ブロックチェーン連続講義 第 3 回「ビットコインの技術」 — 2016-03-04 – p.31/47
32. 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
ブロックチェーン連続講義 第 3 回「ビットコインの技術」 — 2016-03-04 – p.32/47
35. 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
ブロックチェーン連続講義 第 3 回「ビットコインの技術」 — 2016-03-04 – p.35/47
36. Block Data Structure
Field Description Size (bytes)
Block header 6 items 80
# of TXs Positive var-int 1∼9
List of TXs Variable
ブロックチェーン連続講義 第 3 回「ビットコインの技術」 — 2016-03-04 – p.36/47
37. 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
ブロックチェーン連続講義 第 3 回「ビットコインの技術」 — 2016-03-04 – p.37/47
38. Merkle Tree
Digest = double SHA-256 value
ブロックチェーン連続講義 第 3 回「ビットコインの技術」 — 2016-03-04 – p.38/47
39. 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
ブロックチェーン連続講義 第 3 回「ビットコインの技術」 — 2016-03-04 – p.39/47
40. 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
ブロックチェーン連続講義 第 3 回「ビットコインの技術」 — 2016-03-04 – p.40/47
41. 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
ブロックチェーン連続講義 第 3 回「ビットコインの技術」 — 2016-03-04 – p.41/47