Bitcoin and Blockchain Part 2
Bitcoin and Blockchain Part 2
Ravi Mittal
Acknowledgements
⚫ The contents for this lecture have been taken from following sources.
Thanks are due to authors who have prepared original contents and
presentations:
1. CS795: Blockchain Technologies, Class notes and slides, George Mason University, Prof
Foteini Baldimtsi, http://www.baldimtsi.com/teaching/cs795_sp17
2. Talk: Introduction to Cryptocurrencies, by Prof Stephen Dziembowski, Univ of Warsaw,
https://www.crypto.edu.pl/dziembowski-talks
3. CS419 Computer Security, Lecture Blockchain and Bitcoin, Prof Paul Krzyzanowski,
Rutgers University
4. https://learnmeabitcoin.com/beginners/getting-started
5. ECE/CS 598AM: Cryptocurrency Security, Fall 2016, Class presentation, Prof Andrew
Miller, http://soc1024.ece.illinois.edu/teaching/ece598am/fall2016/
6. http://blockchain.mit.edu/blockchain
7. Book: Bitcoin and Cryptocurrency Technologies, Arvind Narayanan, Joseph Bonneau,
Edward Felten, Andrew Miller, Steven Goldfeder
8. https://people.cs.rutgers.edu/~pxk/419/notes/bitcoin.html
9. Book: Mastering Bitcoin: Programming the open blockchain, Andreas M.Antonopoulos
2
In this class we will study
⚫ Decentralization Risks (self study)
⚫ Bitcoin Design Principles
⚫ Bitcoin - Identity Management
⚫ Where does the money come from?
⚫ Double Spending
⚫ No Stealing
⚫ Transactions and Transaction Table – Blockchain
⚫ Block Creation
⚫ Proof of Work
⚫ Process Steps – Self reading
⚫ Lecture Summary
⚫ More information on Bitcoin (Self reading)
3
4
5
Decentralization – Risks
Downsides of decentralization (1/2)
9
Bitcoin Design Principles
⚫ Analogy
⚫ Public Key: Similar to bank account number
⚫ Private Key: Secret Pin to do a transaction
12
Everybody can generate his own key pair
keep sk1
secret
announce
pk1
keep sk3 keep sk2
secret secret
(sk1 , pk1) := Gen()
announce announce
pk3 pk2
17
25-36 characters
In the rest of our discussion, we will restrict ourselves to Public Key only
18
(not compressed addresses)
Keys are generated by users – Can there be a clash?
Address
PK: hUK67H9fyg
SK: z4Pxc2kKn3
Alice
Bob
≈ 4 years
⚫ for the first 210,000 blocks: 50 BTC
⚫ for the next 210,000 blocks: 25 BTC
⚫ Advantages:
1. It provides incentives to be a miner
2. It also makes the miners interested in broadcasting new block asap
Bitcoin Design Principles
Double Spending
Main problem: Double Spending
Double spending…
16fab13fc6890
16fab13fc6890
you’ve
already
spent this
coin!
16fab13fc6890
A
C
A
C
30
Slide courtesy of Ittay Eyal
Bitcoin Design Principles
⚫ Properties
⚫ Authentication
⚫ Signature – non-repudiation – Proof of ownership
⚫ Integrity
⚫ Other requirements
⚫ Available funds
⚫ No other transactions using the same funds
32
Bitcoin Transactions
Based in digital signatures
Recall use of Private key for Digital Signature
Alice Bob
PK: hUK67H9fyg PK: p2Pknb7frT
hUK67H9fyg sends 1 to p2Pknb7frT ; H()
SK: z4Pxc2kKn3 SK: n52Hb9Klp
Transaction
34
When a bitcoin node receives a transaction, it
performs several checks
⚫ Validate the signature using Alice’s public key (in the
transaction)
⚫ This proves that whoever created the signature has the private key
corresponding to the public key
⚫ The transactions listed in the inputs are validated to make
sure that those transactions have not been used by any other
transaction
⚫ This ensures there will be no double spending
35
Transaction Table (Blockchain)
The users emulate a public trusted bulletin-board containing a
list of transactions.
A transaction is of a form:
37
Transaction table: the Bitcoin Blockchain
Time t
Stores every transaction and checks
Alice sends 1 to Bob users balances
Alice sends 0.7 to Chris You can see the complete blockchain
since Satoshi created the first block –
Bob sends 1.2 to Dave
All bitcoin transactions happened so
... far
Time t+1
Time t
Stores every transaction and checks
Alice sends 1 to Bob users balances
example:
Bob sends 1.2 to Dave
Time t
...
Dave sends 0.2 to Chris 2 5
Time t+1
Alice Bob
Time t
Stores every transaction and checks
Alice sends 1 to Bob users balances
example:
Bob sends 1.2 to Dave
Time t Time t+1
...
2 5 0.3 4.8
Dave sends 0.2 to Chris
Time t+1
Alice Bob Alice Bob
Time t
Stores every transaction and checks
Alice sends 1 to Bob users balances
...
Time t
Alice sends 1 to Bob
Time t+1
Alice sends 1 to Bob
...
peer-to-peer
Anyone can have full copy of the blockchain
Ref: Lecture 1 CS795/ISA Spring 2017, Prof. Foteini Baldimtsi
Blockchain: Trusted Bulletin-board Emulation
the “ideal” world a protocol that
implements the
ideal world
peer-to-peer
...
Time t
Alice sends 1 to Bob
Alice sends 0.7 to Chris
1 block A block is added every 10 minutes and
Bob sends 1.2 to Dave
... has size < 1MB
Dave sends 0.2 to Chris
Time t+1
Alice sends 1 to Bob
Alice sends 0.7 to Chris
Bob sends 1.2 to Dave
...
Dave sends 0.2 to Chris
...
...
Time t
Alice sends 1 to Bob
Alice sends 0.7 to Chris
1 block A block is added every 10 minutes and
Bob sends 1.2 to Dave
... has size < 1MB
Dave sends 0.2 to Chris
Time t+1
Alice sends 1 to Bob
Alice sends 0.7 to Chris
Bob sends 1.2 to Dave
...
Dave sends 0.2 to Chris
...
Blockchain
Alice Broadcast
Miners
And hope they will add it to the next block. the miners are incentivized
to do it.
Important:
They never add an invalid
transaction (e.g. double spending) a chain with an invalid transaction
is itself not valid, so no rational
miner would do it.
How to add a transaction to a block?
Alice Broadcast
Miners
Miners compete on who will make the next block. They receive new transactions. Then solve PoW.
...
Alice sends 1 to Bob
Alice sends 0.7 to Chris
Bob sends 1.2 to Dave
Dave sends 1 to Bob ...
= Dave sends 0.2 to Chris
52
Main principles – Block addition
I extended the
blockchain!
Here is the new
block
Time t+1
Alice sends 1 to Bob
Alice sends 0.7 to Chris
Bob sends 1.2 to Dave
...
Dave sends 0.2 to Chris
...
Acceptance of new block by miners
Time t+1
Alice sends 1 to Bob
Alice sends 0.7 to Chris
Bob sends 1.2 to Dave
...
Dave sends 0.2 to Chris
...
Works well if users are all honest but this is not the case in
practice!
New block is added to the blockchain
...
Alice sends 1 to Bob Alice sends 1 to Bob Alice sends 1 to Bob
Alice sends 0.7 to Chris Alice sends 0.7 to Chris Alice sends 0.7 to Chris
Bob sends 1.2 to Dave Bob sends 1.2 to Dave Bob sends 1.2 to Dave
New block
How are blocks added to chain? - Another view
blockchain
I am the
signed leader
6.25 BTC
skA verify
verify block
block
skB
skC
How are blocks added to chain? – Another view
blockchain
…
I am the
6.25 BTC leader
skA
skB
6.25 BTC
skC
Bitcoin Design Principles
Proof of work
f(x) = y
random x
Prover s Verifier
finds s such that checks if
H(s,x) starts with n zeros (in binary) H(s,x) starts
with n zeros
nonce “hardness parameter
66
Consensus: Proof of work (summary)
⚫ Not everyone is allowed to add blocks to the blockchain
⚫ People who create and propose blocks are called miners
⚫ In order to propose a block, a miner must include Proof-of-
Work - solution to a hash puzzle
⚫ Hash puzzle can only be solved using brute-force
computation, which spends resources
⚫ Hash puzzle: The hash of the new block (which includes the hash of
blocks, so far). Ex: the hashed output must start with 33 zero bits
⚫ Miners to include a random number in the block (say, Nonce). This
number increments thus hash changes until the proof of the work is
solved
⚫ Once a miner solves a proof of work, it includes all
transactions it heard about after checking that they are
correct
67
How are the PoWs used?
H – hash function more concretely in Bitcoin: H is SHA256.
Main idea: to extend the chain one needs to find nonce such that
H(nonce, H(blocki),transactions) starts with some number n of zeros
“hardness parameter”
70
71
Lecture Summary
⚫ Proof of Work
⚫ The blockchain only accepts blocks for which proof of work is
completed at the earliest
⚫ Based on consensus from miners
73
Backup Slides
Information about the state of the blockchain is
propagated in the network
A new user can ask the other users what is the current state of
the blockchain.
blockchain blockchain
new user
In more details:
H(blocki-1)
has to start with n
zeros
blocki-1: blocki:
H H
H(blocki-1)
A new user can ask the other users what is the current
state of the blockchain.
blockchain blockchain
new user
blocki+1
fork
blocki+2 block’1+2
blocki+3 block’1+3
No! blocki+1
blocki+2 block’i+2
blocki+3 block’i+3
blocki+4
If anyone is ever able to link your Bitcoin address to your real world identity,
then all of your transactions — past, present, and future — will have been
linked back to your identity.
De-anonymizing Bitcoin users
Address
PK: hUK67H9fyg All transactions and correspond public
keys are published on the blockchain
SK: z4Pxc2kKn3
Alice
Bitcoin scalability
~46000
~7
Can transactions be “reversed”?
current reward
Special
hardware
Huge mining
pools
How many cryptocurrencies do we have?
~3000
How to store Bitcoin?
Cold storage
Mining attacks
Network attacks
98
©2017 by Stefan Dziembowski. Permission to make digital or hard copies
of part or all of this material is currently granted without fee provided that
copies are made only for personal or classroom use, are not distributed
for profit or commercial advantage, and that new copies bear this notice
and the full citation.