intro to block chain bitcoin. blocks ●ethereum - block chain ●dogecoin - block chain ●ripple -...

30
Intro to Block Chain Bitcoin

Upload: robert-young

Post on 13-Dec-2015

255 views

Category:

Documents


10 download

TRANSCRIPT

Page 1: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Intro to Block ChainBitcoin

Page 2: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Blocks

Page 3: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Blocks

● Ethereum - block chain● Dogecoin - block chain● Ripple - not a block chain● Stellar - not a block chain

● Bitcoin - definitely a block chain

Page 4: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Blocks

Q. What makes a block chain?A. Blocks + Proof of Work/Mining

Page 5: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Consensus

● Paxos - Google’s chubby● Raft - CoreOS etcd● Proof of work - Bitcoin

Page 6: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Proof of Work

A function which is hard to compute but easy to verify.

Page 7: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Proof of Work Examplevar target = '00';var data = 'block chain u';var result = '';var nonce = 0;

for(;;) { var f = crypto.createHash('sha256'); var h = f.update(data + ++nonce); result = h.digest('hex'); if (result.slice(0, target.length) == target) { break; }}

var check = crypto.createHash('sha256').update(data+nonce).digest('hex');if (check.slice(0, target.length) == target) { console.log('Verified nonce='+nonce);}

Page 8: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Proof of Work

ƒ(data,nonce) < 2^256 / difficulty

Page 9: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Block Creation

Page 10: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Coinbase Transactions

If you proved the work you send yourself 25 BTC as a reward.

You also get to collect fees.

Page 11: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Miners Are Important

They decide which transactions make it into a block and ingest new BTC.

Page 12: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Addresses

Private Key -> Public Key -> Address

Page 13: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Addresses

● Don’t contain 0 O I l (base58)● Start with a 1● 33 or 34 characters long● Shorter and more recognizable than public

key● Might help if there is an ECDSA Attack● Should be used only once

Page 14: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Private Key Storage

● If you lose your private key, the funds are forever gone

Page 15: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

var bitcoin = require('bitcoinjs-lib');

var prv = bitcoin.ECKey.makeRandom()var pub = prv.pub;

console.log('private=' + prv.toWIF());console.log('public=' + pub.toHex());console.log('address=' + pub.getAddress());

//Output:private=L44GNX8FAMENVyae31mK34p5mpSVGBfEW5xZvmVrD8gULNfTAv3Ypublic=02570b2cec80ac066f7ebbf3ac10f13710707525a5b2effca71c47b87ecd8b78ccaddress=19aHhFTKfH7Zuccjrkc4H1gkJNQJ8mC15Q

Creating an Address

Page 16: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Transactions

Page 17: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Satoshi

● 1 BTC = 100000000 Satoshis● Minimum transactions size = 5430 Satoshis

Page 18: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Transaction Outputs

● Must consume entire value● Value not consumed will be left as fee 😱● If an output isn’t named in an input, it is

considered unspent● You can be named in an output without

consent

Page 19: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Standard Transaction Types

● P2PKH - Pay to Public Key Hash● P2SH - Pay to Script Hash● Multisig - Most people use P2SH● Null Data - Store 40 arbitrary bytes● Public Key - Most people use P2PKH

Page 20: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

P2PKH Script Validation

Page 21: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Creating A Transactionvar key = bitcoin.ECKey.fromWIF("L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy")var tx = new bitcoin.TransactionBuilder()tx.addInput("aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31", 0);tx.addOutput("1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK", 15000);tx.sign(0, key);console.log(tx.build().toHex());

Page 22: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Smart Contracts

● Arbitration using P2SH● Wills & Inheritance using nLockTime● Bets using Oracles and hashed scripts

Page 23: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Payment Requests

● Generate addresses on demand● Meta-data for building the transaction

Page 24: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Software

● Libraries● Full nodes● SPV nodes● Wire protocol

Page 25: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Bitcoin Core (bitcoind)

● C++● The original Bitcoin software● Full node● Stores data on disk● JSON RPC● Wallet code will most likely be pulled

Page 26: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

btcd

● Go● btcwire● btcutil● btcscript● btcnet

Page 27: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

bitcoinj

● Java● Wallet features

Page 28: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

bitcoinlib-js

● Node.js / Browser● Really easy to use 👌

Page 29: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

APIs

● Unspents by address● Transactions by address● Transaction broadcasting● Network propagation levels● Push data

Page 30: Intro to Block Chain Bitcoin. Blocks ●Ethereum - block chain ●Dogecoin - block chain ●Ripple - not a block chain ●Stellar - not a block chain ●Bitcoin

Resources

● reddit.com/r/bitcoin● bitcoin.org/en/developer-guide● bitcoin.org/en/development● BIPS: github.com/bitcoin/bips● Testnet● http://blog.chain.com/post/92058053671/ios-

8-touch-id-wallet-demo