bitcoin - beyond the basics
DESCRIPTION
An overview of the Bitcoin protocol, source code, data structures and algorithms. This presentation was delivered at Nova Southeastern University on June 20, 2014 by Chris DeRose of bitcoinfl.orgTRANSCRIPT
Beyond the Basics
What is a Bitcoin?● Lots of misconceptions
● Terrible analogies
● Forget what you heard
● Mostly Elegant
● Often simple
Early History
● Whitepaper on metzdowd.com Oct 31, 2008
● Release 0.1 on Jan 9, 2009
– Windows only,– No CLI. – Used wxWidgets,
BerkeleyDB & Boost– Compiled using MVS
● Maintainership by Gavin Andresen & Jeff Garzik in mid-2010
Current Release● Splitting the 'ball of spaghetti' into pieces
● Gavin turned over to Jeff earlier this year
● Intent of development is to restrict new features keep the code stable
● Now uses Qt for the GUI, LevelDB for storage
● 'testnet' vs 'mainnet'
● Most Integers are little endian. Only IP or port number are big endian
Modules
● P2P network
● Mining
● GUI / Interface
● Blockchain
● Transactions
● Contracts
● Wallet Management
● Payment Processing
Structures and Algorithms● Hashes (SHA-256 & RIPEMD-160)
● Public Keys vs Public Key hashes
● ECDSA / secp256k1
● Merkle Trees
● Bloom Filters
Bitcoin's P2P network● Connects to the seed servers via DNS
● Downloads a list of (up to) 1000 peers
● Prior versions used IRC (<0.6)
● Listens on TCP/8333
● Messages are received and relayed via peers
● Synchronizes to latest state via 'inv'
What is a Transaction?● Contains most of the protocol's complexity
● Inputs and Outputs
● Code aka Contracts.
● Sometimes 'data'
● Currently Unspent output is 'UTXO'
● Miner Tips are unallocated inputs
● Sometimes, a 'coinbase'
Transactions Up-CloseTXID: 'B'
Input 1 of 1: From: TX 'A' (Bob)Input Amt.: 5 BTC
Output 1 of 1:To: Charlie's KeyOutput Amt: 4 BTC
Miner Tip: 1 BTC
CoinBase TXID 'A'
Base: 25 BTCMined by: BobTo: Bob's Key
TXID: 'C'
Input 1 of 1: From: TX 'A' (Bob)Input Amt.: 7 BTC
Output 1 of 1:To: Alice's KeyOutput Amt: 6.5 BTC
Miner Tip: 0.5 BTC
UTXO's / BalancesMiner Bob: 13 BTCCharlie: 4 BTC Alice: 6.5 BTC
Miner Tips: 1.5 BTC
So Many Transactions!
TXID 'B'
TXID 'C' (Multiple Inputs)
CoinBase TXID 'A'
Non-Contiguous!
Block #300(Oldest)
Block #301 Block #302 Block #303(Newest)
Transactions are contracts● A 'spend' isn't specifically an action.
● All transactions are contracts
● Forth-like, stack-based (no registers), not turing complete
● Stack is little-endian, variable-length integers, MSB controls 'sign'
● False is zero, True is non-zero
● Transaction valid if no errors and the topmost stack int is true
● Miners 'validate' transaction/contract scripts for 'truth'
● All peers validate
About those contracts...
● Approximately 100 instructions available
● Only a dozen are typically used
● 'Standard' vs non-standard
● Only four contract 'templates'
● Mistakes are final
What is a Block?● Mined Transactions
● 250-600 transactions typically
● 750 KiB max (currently)
● One Coinbase transaction
● Hashed header of prior block
● Merkle root of mined transactions
● Nonce
Blocks Up-close
Transaction A
Transaction B
Transaction C
Transaction D
Transaction E
Transaction F
Block #299
Header
Transaction G
Hashed Fields:
Version Future-planning
hashPrevBlock Identify Neighbor
hashMerkleRoot Validates transactions
Time Generation Timestamp
Target Bits Difficulty. Lower is harder.
Nonce Proof of work / Entropy
Non-Hashed Fields:
Magic No Type-Identification
Blocksize malloc() and sanity
Transaction count Sanity/speed opt.
What is the Blockchain ?● Ordered blocks
● Contains *every* transaction on the Bitcoin network
● Approximately 305k blocks at 18 GiB at the time of writing
● Block Height is a measure of absolute time and distance.
● Block depth is a measure of relative time/distance since 'now'
● 0.9 supports header-only/SPV-mode at 80 bytes per header (23 MiB total) '
● 'Pruning' non-UTXO's is an option down the line
What does a miner do?● Prevents Double-spends, and creates money!
● Appends transactions from the transaction 'mempool' for tips.
● Establishes a valid hash for the block header
● Announces a successful block to the network
● Difficulty adjusted every 2016 blocks/two-weeks
● Block header hashes are contingent on prior block state. Race restarts from scratch each block.
The Blockchain in action
300
301 302 303
304 305 306
Time and Block Height
Failed BlockNo Reward
Wasted TimeWasted Miner Money
Alternate Ordering / History
Approximately Seventy Minutes. Exactly Seven Blocks.
= Successful Block25 BTC Award=
What is a Bitcoin?
100,000,000 Satoshis
What is a Bitcoin?
What is a Satoshi?● An unspent output value (UTXO)
● Addressed to your public key hash
● In a transaction
● In a block
● In the blockchain
The near future
● x.509 and http integration
● NFC via 'bonds'
● BIP 70 (instant conf)
● More contracts
● Sidechains
● Look at the BIPs!
Notes on Scalability
● Visa handles 4,000 tps on average 10tps peak, Paypal handles 46 tps
● Bitcoin averages 1 tps
● Current constraints are artificially imposed
● Biggest current constraint is in hash verification time on blocks/transactions
● Current estimates suggest a 'desktop cpu' can validate ~4k tps
● That's 2 MiB of network traffic per second
● The blockchain will get large
● Satoshis biggest fears were that the network grows too quickly.
● Not because of the technology.
Find this Useful?(Show us some love!)
bitcoinfl.org