Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
1
Bitcoin – Introduction for
programmers
Wojciech Langiewicz @ DRUG #61
2
Live Demo before we start
● Connect to WIFI or make sure you have cellphone reception
● Install Wallets
– Android (Mycel...
3
Scope of this talk
● Introduction – What is Bitcoin, History
● Core concepts
– Keys, Addresses
– Wallet
– Clients
– Tran...
4
What is Bitcoin
● Collection of concepts (and full “ecosystem” of tools)
● Decentralized peer-to-peer system
● Solves 2 ...
5
Key elements of the ecosystem
● Decentralized peer-to-peer network (Bitcoin protocol)
● Public transaction ledger (Block...
6
Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos
Licensed under a Creative Commons Attribution-ShareAlike...
7
Few words about history
● Introduced in 2009 by Satoshi Nakamoto
● https://bitcoin.org/bitcoin.pdf
● Combined concepts t...
8
Bitcoin Address
● Something like this:
19wQhQEF3ANe6Dsiiahq3BFkdzb4K8XZUf
● Usually shown as QR code:
● Address is a Bas...
9
Bitcoin Keys - ECDSA
● Private keys – numbers between 0 and 2^256
● Public key can be calculated from the private key
● ...
10
Wallet
● Client software running on: server, desktop, phone, “in the
cloud”, it manages keys, signs transactions, gener...
11
Wallet vs HD Wallet
Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos
Licensed under a Creative Commons A...
12
Trezor
13
Full nodes
● Full nodes store full copy of the blockchain
● Currently over 40GB of data
● Usually need for server-side ...
14
SPV nodes
● Lighweight nodes
● Use Simplified Payment Verification instead of ITV
● Suitable for desktops, phones
● Ins...
15
Transaction
● Coinbase transaction
● Each transaction has 1 or more inputs and 1 or more outputs
● Transaction “moves m...
16
Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos
Licensed under a Creative Commons Attribution-ShareAlik...
17
Spending a transaction - P2PH
● Example of transaction type “Pay to pubkey hash”
● ScriptPubKey:
OP_DUP OP_HASH160 <pub...
18
19
Executing a script
20
Advanced transaction types
● Multi signature (multisig)
● OP_RETURN
● Anyone can spend
● Pay to script hash
21
Blocks
● Genesis block
● Mining – process of confirming a block
● Each block points to a previous one creating a blockc...
22
Mining
● Merges transactions into blocks
● Finds nonce that “solves” the block
● Once the solution is found – block is ...
23
Mining pools
● Chance to find a solution to a block are small
● Small miners join in pools where they share a profit
● ...
24
Blockchain
● “A chain of blocks”
● Clever approach to consensus problem
● Miners after finding a new block publish it o...
25
Blockchain fork
● Situation when 2 blocks are found at the same time
● Bitcoin network is in the state of a fork
● 10 m...
26Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos
Licensed under a Creative Commons Attribution-ShareAlike...
27Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos
Licensed under a Creative Commons Attribution-ShareAlike...
28Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos
Licensed under a Creative Commons Attribution-ShareAlike...
29Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos
Licensed under a Creative Commons Attribution-ShareAlike...
30Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos
Licensed under a Creative Commons Attribution-ShareAlike...
31
Few words about the 51% attack
● Theoretically possible even with 40-50% of power
● Can be used to destabilize network ...
32
Please return testnet coins
33
Next time
● More about Bitcoin clients
● Bitcoin-core JSON-RPC API
● Bitcoinj
● Raw transactions
● Blockchain details
●...
Upcoming SlideShare
Loading in …5
×

Bitcoin for programmers - part 1 version 2

1,850 views

Published on

Bitcoin For Programmers part 1 of my talk (better version)

Published in: Technology
  • Be the first to comment

Bitcoin for programmers - part 1 version 2

  1. 1. 1 Bitcoin – Introduction for programmers Wojciech Langiewicz @ DRUG #61
  2. 2. 2 Live Demo before we start ● Connect to WIFI or make sure you have cellphone reception ● Install Wallets – Android (Mycelium testnet): – Online: ● http://testnetwallet.com/ ● Create payment requests for 0.01 BTC / 10mBTC ● Tweet them @xwlk
  3. 3. 3 Scope of this talk ● Introduction – What is Bitcoin, History ● Core concepts – Keys, Addresses – Wallet – Clients – Transaction – Block – Mining – Blockchain
  4. 4. 4 What is Bitcoin ● Collection of concepts (and full “ecosystem” of tools) ● Decentralized peer-to-peer system ● Solves 2 main problems: – Is that money authentic (not counterfeit) – Is there only singe occurrence of this specific coin (double spends) ● Has much similarities to cash and gold
  5. 5. 5 Key elements of the ecosystem ● Decentralized peer-to-peer network (Bitcoin protocol) ● Public transaction ledger (Blockchain) ● Decentralized currency issuing algorithms (mining) ● Decentralized transaction verification (transaction scripts)
  6. 6. 6 Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos Licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
  7. 7. 7 Few words about history ● Introduced in 2009 by Satoshi Nakamoto ● https://bitcoin.org/bitcoin.pdf ● Combined concepts that existed before ● But have not been combined until then ● POW algorithm + Blockchain
  8. 8. 8 Bitcoin Address ● Something like this: 19wQhQEF3ANe6Dsiiahq3BFkdzb4K8XZUf ● Usually shown as QR code: ● Address is a Base58 encoded form of the public key ● Based on the address prefix, you can figure out what type of address it is. ● Types of addresses: Pubkey hash, script hash, private key ● Address reuse ● A word about HD Wallets
  9. 9. 9 Bitcoin Keys - ECDSA ● Private keys – numbers between 0 and 2^256 ● Public key can be calculated from the private key ● Public key can be represented as Base58 encoding, HEX number, etc ● Private keys can also be encoded as Base58 – this is called WIF format – most common way to export/import keys between wallets
  10. 10. 10 Wallet ● Client software running on: server, desktop, phone, “in the cloud”, it manages keys, signs transactions, generates new keys, etc ● Paper Wallets ● Bitcoin-qt ● Hardware wallets (Trezor) ● Electrum, Armory, Multibit ● Blockchain.info ● Mobile wallets with intermediate server ● Other web wallets
  11. 11. 11 Wallet vs HD Wallet Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos Licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Standard Wallet HD Wallet
  12. 12. 12 Trezor
  13. 13. 13 Full nodes ● Full nodes store full copy of the blockchain ● Currently over 40GB of data ● Usually need for server-side type of applications ● Provide JSON-RPC API ● Example: Satoshi client, btcd
  14. 14. 14 SPV nodes ● Lighweight nodes ● Use Simplified Payment Verification instead of ITV ● Suitable for desktops, phones ● Instead of downloading full blockchain ● Download transactions only for their addresses ● Security and privacy implications ● Example: bitcoinj
  15. 15. 15 Transaction ● Coinbase transaction ● Each transaction has 1 or more inputs and 1 or more outputs ● Transaction “moves money” - changes owner ● Transactions take inputs and translate it into outputs ● Those outputs can serve as inputs to the new transaction
  16. 16. 16 Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos Licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
  17. 17. 17 Spending a transaction - P2PH ● Example of transaction type “Pay to pubkey hash” ● ScriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG ● scriptSig: <sig> <pubKey> ● Script: <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
  18. 18. 18
  19. 19. 19 Executing a script
  20. 20. 20 Advanced transaction types ● Multi signature (multisig) ● OP_RETURN ● Anyone can spend ● Pay to script hash
  21. 21. 21 Blocks ● Genesis block ● Mining – process of confirming a block ● Each block points to a previous one creating a blockchain ● Quite few similarities to git (instead you can't merge)
  22. 22. 22 Mining ● Merges transactions into blocks ● Finds nonce that “solves” the block ● Once the solution is found – block is published ● Published – appended to the blockchain ● Published blocks are verified by other nodes ● This sends coinbase transaction to the miner + all fees ● Proof of Work – 10 minutes per block ● Difficulty
  23. 23. 23 Mining pools ● Chance to find a solution to a block are small ● Small miners join in pools where they share a profit ● Instead of finding a block every year and getting 25BTC ● You will get 0.5 BTC per week. ● You have to trust the pool operator or use p2pool
  24. 24. 24 Blockchain ● “A chain of blocks” ● Clever approach to consensus problem ● Miners after finding a new block publish it on the network ● You base your security on a height of a transaction ● Ensures that there are no duplication
  25. 25. 25 Blockchain fork ● Situation when 2 blocks are found at the same time ● Bitcoin network is in the state of a fork ● 10 minutes later a new block is found that is based on one of the forks ● All Bitcoin nodes quickly switch to the longer branch ● Transactions from the shorter branch are orphaned and will be processed shortly after ● Next slides: Fork example
  26. 26. 26Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos Licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
  27. 27. 27Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos Licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
  28. 28. 28Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos Licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
  29. 29. 29Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos Licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
  30. 30. 30Images from book “Mastering Bitcoin” by Andreas M. Antonopoulos Licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
  31. 31. 31 Few words about the 51% attack ● Theoretically possible even with 40-50% of power ● Can be used to destabilize network for some period of time ● Can help to create a double-spend ● In no case you'll be able to spend coins you don't have ● This attack is not practical ● Miners will make more BTC by being honest
  32. 32. 32 Please return testnet coins
  33. 33. 33 Next time ● More about Bitcoin clients ● Bitcoin-core JSON-RPC API ● Bitcoinj ● Raw transactions ● Blockchain details ● Security ● Bitcoin flaws

×