fg
fg
Chester Rebeiro
Assistant Professor
Department of Computer Science and Engineering
IIT Madras
Traditional Currencies
• Not Reversible
– Once transaction is done, cannot be undone
• Privacy
– Besides Alice and Bob, no body else knows about the
transaction
CR! 3
Electronic Money
• What if Alice and Bob want to transact over the Internet
• Naïve Approach
– Alice sends a file ($5.jpg) to Bob
$5.jpg
Problems
Alice Bob
• Double Spending
Sally
CR! 4
PayPal (Trusted 3rd Party)
verify
Alice’s account minus
every transaction Alice : $29 $5
Walter : $12
Carr : $23
Bob : $121
Ledger Bob’s account plus $5
3rd party
Alice Bob
Advantages Disadvantages
CR! 5
Bitcoins
• Crypto currency (called bitcoins (BTC))
• Invented by unkown person or group (goes by
the name Satoshi Nakamoto)
• Uses cryptography to achieve
– Privacy
– Untrusted transactions
Just as in traditional currency
– Unreversible
– No double spending
CR! 6
The Bitcoin Irony
• Bitcoins have
– no bank
– no trusted third party (like Paypal)
– no paper money
CR! 7
Big Idea
Ledgers maintained by several (1000s) of computers on the
Internet
ledgers
ledgers
CR! 8
Transactions
• Every transactions logged in all ledgers
• Every transaction is checked if it has been previously done
– Verification done by 1000s of computers
• Double spending not possible
– Since all transactions are logged
update
update
send 5 BTC
to bob update
update ledger
update
called blockchain
CR! 10
Under the hood
CR! 11
Bitcoin Private Keys
Alice’s Private Private keys:
Key
• Most important component
CR! 12
Bitcoin Public Keys
• Derived from the private key by a complex
process called elliptic curve scalar
multiplication
• Remember oneway ness,
Alice’s Private
Alice’s Public Key
Key
CR! 13
Bitcoin Addresses
• Share with anyone who wants to send you money
(appears in transactions as the recipient of funds)
• Derived from the public key
Bitcoin address
1J7mdg5rbQyUHENYdx39WVWK7fsLpEoXZy
CR! 14
More Oneways
Alice’s Private
Alice’s Public Key
Key
Alice’s Address
CR! 15
Wallets
• Collection of secret keys owned by a user
• Different types of wallets possible
CR! 16
Bitcoin Transactions
How does Alice transfer 5 bitcoins to Bob?
(destination address)
Transaction Hash
OUTPUT
INPUT
Bob’s
5BTC Address
Locktime
1021ab3582939214221 68434322468acd935
Locktime Locktime
632346299790305735 ab428582b423523
CR! 18
Transaction Input
Where did Alice get the 5BTC from?
1021ab3582939214221
Jane to Alice
3BTC
a234345456234462cbacdef
Kane to Alice
3BTC change
Jane Alice
3BTC
a234345456234462cbacdef
Kane Alice
3BTC change
20442….
a234345456234462…
20442……
1021a…
5623a….
5623a…… 5623a……
a342b… Genesis
20442….
5623….
a234345456234462…
bdefac32342…
20442……
5623……
3321a…
3255a….
5623a….
• A change in one transaction
causes a change in the all
5623a……
3255a…… others because
1. the transaction hash
a342a… changes
2. hash included in
subsequent transactions
so subsequent hashes change
CR! 22
Bitcoin Ledger
is actually a list of transaction hashes so privacy
is maintained
Alice à Bob 5BTC 23343…..
Bob à Carr 3BTC 434134…..
Carr à Alice 1BTC 43684…..
John àEmily .3BTC 21232…..
Jane -> Alice 4BTC 67847…..
Joe à Alice 3BTC Is actually 656464….
Bitcoin Ledger
(Transaction hashes)
CR! 24
How to Claim Transactions?
1021ab3582939214221
Alice
Alice’s address
a234345456234462cbacdef
Locking script
1021ab358…
Unlocking
script
This is a mathematical puzzle.
Anyone who can solve this puzzle
Can claim the bitcoins
This is the answer the mathematical
Puzzle
Since Alice has the solution, she can claim
the previous transaction
Based on digital
signatures
CR! 25
Locking and Unlocking Scripts
• Uses a script (a simple programming language)
– Locking has one half of the script
– Unlocking has the other half of the script
• Anyone can join the scripts to validate it (thus
validating the transactions)
• Since a script is used, the puzzles are flexible.
CR! 26
Locking and Unlocking Scripts
• Example : Pay-to-Public Key
Locking Script: <Public key of Alice>
Unlocking Script : <Dig. signature from Alice’s
private key>
Script:
<Dig. Signature from Alice’s private key>
<Public key of Alice>
OP_CHECKSIG
CR! 27
Validation of Scripts
<Dig. Signature from Alice’s private key>
<Public key of Alice> Everyone else
OP_CHECKSIG
Alice
Alice’s
Alice’s Transaction Public Key
Transaction Private Key
Signature
Sign for M
Verify
function
function
CR! 29
Double Spending
How to ensure that Alice is not trying to
spend bitcoins twice?
CR! 30
So far…
1. We have seen how Alice creates a transaction
2. We have seen how the transaction can be validated.
– For authenticity
– And for double spending
CR! 31
Who validates transactions?
• Alice sends transaction to any node in the bitcoin network
• Node validates, adds it to the ledger, and then sends it to other
nodes
• In a few seconds several 1000 nodes have validated and
broadcasted the transaction
CR! 32
Ordering Transactions
• Transactions hop from one node to another in a random manner
• It is therefore possible for nodes to have different ledgers
• A dishonest node could prioritize one transaction over another
• Could lead to double spending What goes in the
ledger here?
CR! 33
Double spending
(due to transaction order)
• Alice initiates a transaction , waits for Bob to deliver her coffee
• Then immediately initiates another transaction with the same inputs
CR! 34
Bitcoins solution for ordering
transactions
Block Chains
Blocks
Miners
More Puzzles
CR! 35
Blocks & Blockchains
• Ledgers are now stored as blockchains
• Each blockchain now has blocks instead of transactions
• Blocks contain multiple transactions
transactions
All the way
to the
genesis Block N-3 Block N-2 Block N-1 Block N
transaction
Transaction chain
CR! 36
Miners Candidate blocks
CR! 38
Solving the Puzzle
• When a miner solves the
puzzle, he announces
the result to all others
• His candidate block is
adopted by all others and
I solved it
added to the block chain
• Incentives for the winning
miners
CR! 39
Mathematical Puzzle
• Three Requirements
– Should be difficult to solve
– But still solvable in 10 minutes
• Independent of the computing power of the miners
– Once solved, the solution should be easily verified
• The only way to solve the puzzle must be by
randomly trying different inputs
CR! 40
Hash function randomness
Short
Text Hash fixed length
Function
hash
CR! 41
A Puzzle
Concatenate a number to the message ‘M’ so
that the hash begins with a 0.
M = “I am
Satoshi
Nakamoto”
CR! 42
Satisfying the requirements
• Should be difficult to solve
– The only way to solve the puzzle is by
randomly varying the inputs
• Once solved, the solution should be easily
verified
– Easily checked!!!
• Solvable in 10 minutes. Independent of the
computing power of the miners.
– Scalable difficulty (next!!!)
CR! 43
Scalable Difficulty
• Why?
– Computing power of miners increases with technology
– More miners in the network over time
– Problem difficulty should be adjusted so that solution (on
average) obtained in 10 minutes
• How?
Concatenate a number to the message ‘M’ so that the
hash begins with N zeros.
– If N is less (easily solved)
– If N is large (more difficult to solve)
– Every 2016 blocks, difficulty adjsted depending on average time
taken for the last 2016 blocks
CR! 44
Summarizing Miners
1021ab3582939214221
Jane to
3BTC Alice
ab3582939214221
Jane to
3BTC Alice
1021ab358
ab35829… out
CR! 46
Summary of Bitcoins
1. Build a transaction from previous unused bitcoins
1021ab3582939214221
ab3582939214221
Jane to
3BTC Alice
CR! 47
Summary of Bitcoins
2. Push transaction to network, where it is broadcasted
358293921422112322a
Locking
1021ab358 script,
ab35829… Value
CR! 48
Summary of Bitcoins
2. Miners on network validate Alice’s transaction.
If found valid, add to a candidate block
358293921422112322a
Locking
1021ab358 script,
ab35829… Value
CR! 49
Summary of Bitcoins
3. Miners simultaneously try to solve a mathematical
puzzle. If a miner succeeds, the result is broadcasted.
The winning miner’s candidate block is adopted by all others
358293921422112322a
Locking
1021ab358 script,
ab35829… Value
CR! 50
Summary of Bitcoins
4. The transaction shows up in Bob’s wallet and
can be claimed in any transaction Bob makes
CR! 51
Conclusions
• Bitcoins are an alternative to physical
currency
• Trust is achieved by using cryptography
and by large number of users
• Still not fool proof (attacks stell exist)
– Tokyo based bitcoin exchange Mt. Gox
hacked
CR! 52
Potential Problems
• Theft of private keys
• Tracing coin’s history
• Sybil attack : Attacker controllers large number of nodes
in the network
• Side channel analysis
• Denial of Service Attakcs
• Malware in systems
• Energy requirements for mining
CR! 53