Cryptocurrencies & Security on the Blockchain Bitcoin Transactions, High-level Prof. Tom Austin San José State University
Lab Review
Bitcoin Blocks • Collections of transactions • Fixed size • Collectively, form a blockchain • Genesis block – the very first block
Block Information • Version • Timestamp • Previous block hash • Proof-of-work (PoW) target • Nonce (the "proof") • Merkle root
Block Information • Version Reviewed another day • Timestamp • Previous block hash • Proof-of-work (PoW) target • Nonce (the "proof") • Merkle root
Block Information • Version • Timestamp • Previous block hash • Proof-of-work (PoW) target • Nonce (the "proof") Determines transactions in • Merkle root block
Merkle Trees • Binary tree. • All nodes are hashes. • The leaves are hashes of the data. – In Bitcoin's case, the data is transactions. • Definitions – Merkle root – the root of a Merkle tree. – Merkle path – ONLY the nodes needed to reconstruct the Merkle root from a transaction.
Merkle Trees H1 = H(H(A),H(B)) MR H2 = H(H(C),H(D)) H2 H1 MR = H(H1,H2) H(A) H(B) H(C) H(D) (Merkle root) B D A C
Storing Merkle Trees More efficient to 1 store in an array. Left child = n*2 3 2 Right child = n*2 +1 4 5 6 7 (A little adjustment is needed when indexing from 0).
Using Merkle Trees • Merkle root is known • Validator requests specific transaction • Miner provides Merkle proof – Pieces needed to reconstruct Merkle root
Merkle Path Merkle path for MR block B: • Block B H2 H1 • H(A) • H2 H(A) H(B) H(C) H(D) B D A C
Why a Merkle Tree? • Requires log n hashes to verify a transaction. • Minimal data needed to transmit across the network. • Old transactions may be pruned more easily.
Lab: Implement a Merkle Tree Details in Canvas and course website.
Double-entry Bookkeeping • Each transaction specifies inputs and outputs • All inputs must be spent – Transaction fee = sum(inputs) – sum(outputs) – Change address = Address spender gives to reclaim unused bitcoins. • Special case: coinbase transactions – New coins generated as a reward for miners.
Transaction Chains • Not the same as blockchains • Each transaction output can be a future transaction input. • Each output can only be spent once • To know what bitcoins are available you only need to keep track of the Unspent Transaction Outputs (UTXOs) .
Transaction Chains Figure from Mastering Bitcoin
Transaction Chains Figure from Mastering Bitcoin
Transaction Forms
Common Transactions Most typical: Alice pays Bob, and keeps the change Figure from Mastering Bitcoin
Aggregating Transaction Alice has many private keys and wants to combine them. Figure from Mastering Bitcoin
Distributing Transaction Alice pays several different people simultaneously. Figure from Mastering Bitcoin
Reading for Next Time • Mastering Bitcoin, Chapter 9 – Reviews the blockchain • Mastering Bitcoin, Chapter 10 – Reviews mining and consensus
Recommend
More recommend