Download - Bitcoin - Beyond the basics

Transcript
Page 1: Bitcoin - Beyond the basics

Beyond the Basics

Page 2: Bitcoin - Beyond the basics

What is a Bitcoin?● Lots of misconceptions

● Terrible analogies

● Forget what you heard

● Mostly Elegant

● Often simple

Page 3: Bitcoin - Beyond the basics

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

Page 4: Bitcoin - Beyond the basics

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

Page 5: Bitcoin - Beyond the basics

Modules

● P2P network

● Mining

● GUI / Interface

● Blockchain

● Transactions

● Contracts

● Wallet Management

● Payment Processing

Page 6: Bitcoin - Beyond the basics

Structures and Algorithms● Hashes (SHA-256 & RIPEMD-160)

● Public Keys vs Public Key hashes

● ECDSA / secp256k1

● Merkle Trees

● Bloom Filters

Page 7: Bitcoin - Beyond the basics

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'

Page 8: Bitcoin - Beyond the basics

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'

Page 9: Bitcoin - Beyond the basics

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

Page 10: Bitcoin - Beyond the basics

So Many Transactions!

TXID 'B'

TXID 'C' (Multiple Inputs)

CoinBase TXID 'A'

Non-Contiguous!

Block #300(Oldest)

Block #301 Block #302 Block #303(Newest)

Page 11: Bitcoin - Beyond the basics

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

Page 12: Bitcoin - Beyond the basics

About those contracts...

● Approximately 100 instructions available

● Only a dozen are typically used

● 'Standard' vs non-standard

● Only four contract 'templates'

● Mistakes are final

Page 13: Bitcoin - Beyond the basics

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

Page 14: Bitcoin - Beyond the basics

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.

Page 15: Bitcoin - Beyond the basics

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

Page 16: Bitcoin - Beyond the basics

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.

Page 17: Bitcoin - Beyond the basics

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=

Page 18: Bitcoin - Beyond the basics

What is a Bitcoin?

100,000,000 Satoshis

What is a Bitcoin?

Page 19: Bitcoin - Beyond the basics

What is a Satoshi?● An unspent output value (UTXO)

● Addressed to your public key hash

● In a transaction

● In a block

● In the blockchain

Page 20: Bitcoin - Beyond the basics

The near future

● x.509 and http integration

● NFC via 'bonds'

● BIP 70 (instant conf)

● More contracts

● Sidechains

● Look at the BIPs!

Page 21: Bitcoin - Beyond the basics

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.

Page 22: Bitcoin - Beyond the basics

Find this Useful?(Show us some love!)

bitcoinfl.org