BlockChain Assignment
Blockchain
‹#›
‹#›
‹#›
‹#›
‹#›
Nov 30th, 2017
‹#›
Disclaimer (and warning)!
This is a particularly complex topic (if you are not familiar with blockchain technology).
The more you dig, the more you learn, the more you discover, the more complicated it gets, the more there is to learn.
Skepticism is natural for something as revolutionary as blockchain.
Keep an open mind.
There is a lot of tech jargon but those are good to know.
Hopefully we will reach the ‘a-ha’ moment when it all comes together.
You will be thinking about this for days and months to come…It will consume you. I promise.
Do not dabble in bitcoin unless you know what you are doing!
There is no financial advice in this (or any other) lecture.
‹#›
Strongly Recommended Reading
Read this paper first, before you explore blockchain technology https://bitcoin.org/bitcoin.pdf
9 pages only (one page is for references)
A seminal paper, also referred to as the Holy Book of Satoshi
Quite technical, but this course will cover several of the topics in the paper
Has the potential to change the world (internet email web e-commerce mobile social financial? blockchain?)
Then read the paper again, and again, and again. You will discover additional nuances each time!
‹#›
Our actors (standard convention in cryptography)
Alice
Charlie
Sybil
Bob
Minnie
You
‹#›
Blockchain Basics
‹#›
https://bitcoin.org/bitcoin.pdf
‹#›
What problem does bitcoin solve?
Bitcoin is the latest attempt to create digital cash.
Why do we need email? A way for a person to send a message to another person digitally without depending on a third party (well, that got centralized quickly, didn’t it?)
Why do we need digital cash? A way for a person to send cash to another person digitally without the use of an intermediary (custodian).
Why is this such a hard problem to solve?
A peer-to-peer electronic cash system.
Not a bank account (custodial), but an instrument of payment from person to person without the use of an intermediary.
Can you think why digital cash has evaded computer scientists for so long?
‹#›
Bitcoin used a distributed ledger (blockchain) to create a peer-to-peer electronic cash system (without the use of an intermediary) and thereby solved a long-standing problem in implementing digital cash.
‹#›
What is Blockchain?
Technical Definition
A blockchain is a linked list that is built with hash pointers instead of regular pointers
Socio-political-economic-semi-technical libertarian definition
A blockchain is an open*, borderless, decentralized, public, trustless, permissionless, immutable record of transactions
* All terms in red are debatable
Financial-accounting definition
A blockchain is a public, distributed ledger of peer-to-peer transactionspage
Growth of blockchain
‹#›
Block = collections of transactions
14
Block 0
Block 1
Block 2
Block n
…
What is Blockchain?
Cryptocurrency encryption techniques are used to verify the transfer of funds; operating independently of a (central) bank.
Distributed ledger consensus of replicated, shared digital data spread across multiple sites, countries, or institutions. No central administrator or centralized data storage.
Architectural concept that enables the decentralized, secure, direct, digital transfer of values and assets.
Bitcoin
Blockchain
Distributed Ledger Technology
‹#›
15
Types of networks (from the viewpoint of control)
https://blog.maidsafe.net/2015/12/04/evolving-terminology/
‹#›
Centralized systems are systems that use client/server architecture where one or more client nodes are directly connected to a central server.
In decentralized systems, every node makes its own decision.
16
Immutable Once committed, data cannot be changed. No updates. Only append. [2016 DAO attack: Ethereum, Ethereum Classic]
Consensus The network uses consensus (some form of agreement) to add data to the blockchain.
Censorship resistant Anyone can join. Transactions/nodes/users cannot be censored so long as they adhere to protocol rules.
Distributed/decentralized
Peer-to-peer network
No single point of control or failure (very resilient)
Peers can join and leave as they wish
Network functions even when peers may be
Selfish
Competitive
Dishonest
Adversarial
Malicious
Ledger Records transactions.
Trustless No requirement for a trusted intermediary. The trust is in the software/network even when peers are outright malicious.
Cryptographic Identity Peers assume any number of cryptographic identities. No central authority issues identities.
Some definitions
‹#›
Why Blockchain technology will change the world
Enhanced security. Resists hacking by decentralizing the data storage layer. Spread the data thin, make it more difficult to attack. It is easier to attack a single central database than to attack numerous copies of the decentralized database.
Append only. No updates and deletes. Makes it an immutable record of historical facts. Proof of State.
Can be used to store anything of value that can be digitized.
Improves efficiencies in transaction clearing especially when dealing with multiple agencies.
Lowers transaction fees (?)
No central authority means no central trust. The blockchain itself provides digital trust. It is trustless.
Open and transparent. All transactions in history can be seen, tracked, and validated by anyone.
May become the ultimate proof of value ownership, bypassing governments, corporations, individuals, and criminals.
Provides powerful audit trails.
‹#›
Why Blockchain technology will change the world
Enhanced security. Resists hacking by decentralizing the data storage layer. Spread the data thin, make it more difficult to attack. It is easier to attack a single central database than to attack numerous copies of the decentralized database.
Append only. No updates and deletes. Makes it an immutable record of historical facts. Proof of State.
Can be used to store anything of value that can be digitized.
Improves efficiencies in transaction clearing especially when dealing with multiple agencies.
Lowers transaction fees (?)
No central authority means no central trust. The blockchain itself provides digital trust. It is trustless.
Open and transparent. All transactions in history can be seen, tracked, and validated by anyone.
May become the ultimate proof of value ownership, bypassing governments, corporations, individuals, and criminals.
Provides powerful audit trails.
‹#›
Why Blockchain technology will change the world
Enhanced security. Resists hacking by decentralizing the data storage layer. Spread the data thin, make it more difficult to attack. It is easier to attack a single central database than to attack numerous copies of the decentralized database.
Append only. No updates and deletes. Makes it an immutable record of historical facts. Proof of State.
Can be used to store anything of value that can be digitized.
Improves efficiencies in transaction clearing especially when dealing with multiple agencies.
Lowers transaction fees (?)
No central authority means no central trust. The blockchain itself provides digital trust. It is trustless.
Open and transparent. All transactions in history can be seen, tracked, and validated by anyone.
May become the ultimate proof of value ownership, bypassing governments, corporations, individuals, and criminals.
Provides powerful audit trails.
‹#›
Where is blockchain?
It is decentralized
Nodes on the network hold copies of the blockchain (not all nodes need to have the entire copy).
When a new block is relayed, the other nodes validate it and add it to their blockchain.
You can think of it as nodes (participants) each having a copy of the entire database of transactions.
Any attempt to tamper with the history of the database will be evident to all other nodes and they will immediately reject the change.
All nodes abide by the same consensus rules that govern the creation and validation of transactions. Otherwise, other nodes will reject the offending transaction.
‹#›
Proof of State
The blockchain provides a Proof of State:
Existence: system of record, with timestamp
Ownership: who owns what
Integrity: no double spend of digital assets
Provenance: history of owners
Traceability: trail of movement
‹#›
Where is Blockchain?
Explorers for Bitcoin blockchain
https://blockchair.com/bitcoin
You can install the bitcoin blockchain on your own computer.
Download and install bitcoin core. https://bitcoin.org/en/download
Then let it gather the bitcoin blockchain. It validates all transaction and blocks (this can take days) in the entire history of bitcoin.
The current bitcoin blockchain is over 335GB. https://blockchair.com/bitcoin
Another option is to install a wallet and let it download the blockchain.
‹#›
Blockchain
Tx2
Tx3
Tx5
Tx4
‹#›
Block N
…
Block 2
Block 1
Block 0
Nodes validate the blocks and add it to their own copy of the blockchain
Tx1
Block N
…
Block 2
Block 1
Block 0
Block N
…
Block 2
Block 1
Block 0
Block
TX1
TX2
TX3
TX4
TX5
Blockchain structure
Hash of Block 0
Hash of Block 1
Hash of Block 2
Hash of Block N
Hash ~ Fingerprint
‹#›
Block 0
Block 1
Hash of Block 0
Block N
Hash of Block N-1
Block 2
Hash of Block 1
How is a Blockchain built
‹#›
Alice sends Bob a transaction
Transaction is broadcast through the blockchain network to other nodes
Nodes validate transactions
A (volunteer) node collects valid transactions and puts them into a block
Then broadcasts the block to the network
Changes to the history of the blockchain are tamper evident and in some cases tamper proof
Everyone in the network now knows that Alice has sent Bob a transaction
Other nodes validate and append their blockchain with the new block
The blockchain can only be appended
The block contains a hash (fingerprint) of the previous block
If the transaction is valid, the nodes propagate it further
Blockchain Exploration
Go to https://blockchain.com
What is the latest block number (height) you see?
How many transactions are in block 400,000?
What is the size of that block (in kB)?
How many transactions per second were relayed in the last 24 hours?
Can you see all the transactions in a block? Explain
‹#›
Now what?
So now you know that the blockchain is an immutable, temper evident, cryptographic ledger of transactions
What can we do with this ledger?
How can you innovate on it?
How could it be disruptive?
What are its use cases?
What can it do better than a traditional database?
Satoshi Nakamoto combined the blockchain with Proof of Work consensus and clever game theory to create a cryptocurrency called bitcoin.
It uses a public, permissionless blockchain.
It uses clever game theory to incentivize actors to be honest.
Let’s dig deep into BITCOIN!
It is, so far, the best application of blockchain technology.
‹#›
Bitcoin “In Us We Trust” “In Code We Trust”
‹#›
What is Bitcoin?
The online post announcing the white paper that became bitcoin http://www.mail-archive.com/[email protected]/msg09959.html
Created in Jan 2009 with the first bitcoin being issued (created, mined)
It is described as a cryptocurrency. Crypto – secured by advanced cryptography (in the absence of a central trusted authority). Currency – a medium of exchange, a system of money.
Created by Satoshi Nakamoto, most likely a pseudonym for a person or persons.
Transact by sending and receiving bitcoins using a public address (like an email address)
Private key is used to unlock and sign bitcoin transactions.
Owner of the private key is the owner of the bitcoin. Possession (of private key) is ownership.
No concept of accounts. Only transactions.
It exists completely digitally. No physical manifestation of bitcoin.
‹#›
Double spend problem
Alice sends Bob a selfie.
Alice sends Charlie the same selfie.
Alice has double spent her selfie jpg files!
For a currency to succeed, there must be no double spends.
How can a digital asset not be double spent!
The most important breakthrough in Nakamoto’s invention is the solution to the double spend problem without the need for a trusted intermediary (no arbiter).
Previous attempts at digital currencies needed a central service to validate transactions and to prevent double spends.
This innovation can then be extended to other non-currency assets. E.g. land titles.
Alice
Bob
Charlie
‹#›
‹#›
Deep dive into bitcoin
Technology behind bitcoin
‹#›
Hashing
Hashing is the conversion of data of any size through a hash function into data of fixed size.
E.g., SHA256 is one example of hash function (created by NSA). It generates a 256-bit hash of 1s and 0s. The binary hash can then be converted to other bases such as hexadecimal etc.
‹#›
TEXT Twinkle, twinkle, little star, How I wonder what you are! Up above the world so high, Like a diamond in the sky.
HASH FUNCTION SHA256
HASH 9d33551 7ee91c63d 10fc2fc3 aafdeca6 38233481d44 80cd40064c7 b912158775 (HEXADECIMAL)
Let’s try some hash
https://andersbrownworth.com/blockchain/hash
Enter Data: Alice sends Bob a token
What are the last three characters of the hash?
Go to the Block tab
Enter Data: Alice sends Bob a token
What is the hash?
Why is it different than the previous hash?
‹#›
Properties of Hash function
Deterministic – same input yields same output. This can be used to verify that two documents are the same
Non-invertible – Given the hash, one cannot discover the input
Uniform – the probability of a hash value is the same as any other. This helps in creating a puzzle that has no solving strategy except brute force. Big data analytics cannot help here.
Collision resistance – it is infeasible to find two inputs that yield the same hash
‹#›
Input
SHA256
Output
a591a6d40b f420404a011 733cfb7b19 0d62c65bf0b cda32b57b27 7d9ad9f146e
Hello World
Hashes in blockchain
Hashes are used to create a digest or fingerprint of each block in the blockchain
This hash is included in the next block
The next block’s data along with the hash of the previous is hashed again
That hash is then included in the next block
This is what a blockchain is
The chain of hashes serves as a digest of all transactions
What would happen if one of the transactions was changed?
Any tampering of a block will change its hash which will change the hash of the next block and so on. This makes blockchain tamper evident.
‹#›
Blockchain structure
Hash of Block 0
Hash of Block 1
Hash of Block 2
Hash of Block N
Hash ~ Fingerprint
‹#›
Block 0
Block 1
Hash of Block 0
Block N
Hash of Block N-1
Block 2
Hash of Block 1
Generating public address and private key
The private key is similar to a password.
The public key is generated from the private key through a one-way transformation. It uses ECDSA – Elliptic Curve Digital Signature Algorithm (lot of math).
The public key is then hashed to create a public address.
Go to bitaddress.org
Move your mouse to generate a public address and private key to ‘unlock’
You now see a pair of public address and private key
Click on paper wallet where you can generate a printed version of the wallet
Enter the public address on blockchain.info to see if that address has been used before. Was it? Why? Why not?
‹#›
Keys
ECDSA
HASH
‹#›
Private Key
Known only to Alice
KxTRGmkJwiwP5mWueT6oB8NN3ZJMnvz6pPyo1Z6CDDFo95YK9SnB
Public Key
Revealed when Alice redeems her coins
02347A9CC5A0DE6B4CED592C6BCECCFD940BFD11B42867836E338A4020E75A48AB
Public Address
Publicly available on the blockchain. Not linked to Alice. Only Bob knows that is belongs to Alice.
15L2F3ZToMtHJjQzLfw7o8e323XTcBxrm4
Transactions
‹#›
Peer-to-peer Network
Node 1
Node 2
Node 3
Node 4
Node 5
Bob
Alice
TX1
TX1
TX1
TX1
TX1
TX1
TX1
TX1
‹#›
Gossip protocol
42
Bitcoin Transaction
“Alice sends Bob a token” Translation: A user that controls the private key of a public address sends to another public address a token that is the sum of their UTXOs
UTXO: Unspent transaction output
No concept of account which means that a user can spend the total of all UTXOs for which they have the private keys (for the public address to which the transaction was sent)
Owns 1BTC
‹#›
Tx
Send .9 BTC
Bitcoin Transaction structure
Alice wants to send Bob 0.9 BTC
Alice uses her private key to digitally sign the transaction
Alice broadcasts the transaction to the network.
Bob verifies that Alice was the owner and signer of the transaction by using Alice’s public address and the UTXO of the transaction which Alice claims to be controlled by her.
In other words, Alice must have the private key of the public address to which a previous transaction sent BTC and are unspent
The private key is needed to sign transactions and for spending UTXO (unspent transaction outputs)
In other words, knowing the public address and private key pair is all that is needed to ‘steal’ bitcoin
‹#›
Satoshis (Denomination)
Value of a transaction is measured in satoshis.
Each transaction can have multiple inputs and multiple outputs. This means that a transaction can combine the UTXOs of several transactions and then send them to multiple other public addresses.
1 bitcoin = 100,000,000 satoshis
With over 18 million bitcoins mined so far, that is 1,800,000,000,000,000 = 1.8 quadrillion satoshis.
The value of a satoshi will adjust to accommodate the bitcoin economy (just as other fiat currencies).
A transaction can send any amount of bitcoin (no upper or lower limit)
‹#›
Change Address
When the output of a transaction is used as the input of another transaction, it must be spent in its entirety.
Sometimes the coin value of the output is higher than what the user wishes to pay.
In this case, the client generates a new Bitcoin address, and sends the difference back to this address. This is known as change address (the address to which the leftover change is sent).
In fact, when you spend bitcoin, you must use the entire amount of the unspent output of a previous transaction and make it the input of a new transaction.
When Alice owns the private key to the address that has a UTXO 1 BTC, and sends .9 BTC to Bob, the entire 1 BTC is destroyed and a new .9 is sent to Bob and a new .1 is sent to a new address (controlled by Alice)
This way the 1 BTC is destroyed and cannot be double spent. The new BTCs are the .9 and the .1 (controlled by Bob and Alice respectively)
‹#›
Cost of transactions
Transaction fees are paid by the sender and are voluntary
Transactions are broadcast to the entire bitcoin network but are only confirmed when it is included in a block
The fees are collected by the miner who mines the block in which the transaction is included
The sender can incentivize the miner to include their block by including higher transaction fee
A low fee transaction may have to wait for several blocks before it is included into to a block by a miner
As mining reward reduces and bitcoin participation increases, the transaction fees will be the majority incentive for miners
Total inputs >= Total outputs
Total inputs – Total outputs = Transaction Fees
‹#›
Trust Minnie?
Why should the network trust Minnie’s block?
Minnie should have to earn the trust and must be rewarded for her work in extending the blockchain.
Why not task Minnie to expend some resources to prove her trust. This should keep her honest.
This proof should be such that there is not short cut. Only brute force spending of resources is acceptable proof of her trust. This proof is called Proof-of-work (mining).
As a reward, Minnie will get bitcoins (in other words, Minnie the miner has mined bitcoins).
This is similar to expending resources to mine gold, silver and diamonds.
‹#›
Economics
‹#›
Bitcoin Supply and asymptote
When a miner “mines” (discovers) a block, it gets a block reward in BTC. In 2009, the award was 50 BTC. It is 6.25 bitcoin now. The miner also collects all of the transaction fees for the block they mined.
A block is mined every 10 mins on average.
Every 210,000 blocks, the reward is halved to slowly diminish the reward and therefore limit the total supply of bitcoins. 50 25 12.5 6.25 … (next halving to 3.125 BTC is expected in May/June 2024, after block 840,000 is mined)
Because this geometric series halves every 4 years, it has an asymptote of 21 million bitcoin. The last bitcoin will be mined in approx. in the year 2140
https://plot.ly/~BashCo/5.embed?share_key=ljQVkaTiHXjX2W41UiqzCn
As usage gets widespread, the cryptocurrency appreciates in value. The inflation rate slows over time. Deflationary? Disinflationary?
‹#›
https://en.bitcoin.it/w/images/en/4/42/Controlled_supply-supply_over_block_height.png
‹#›
Bitcoin economy
What percentage of the total bitcoin supply has been mined?
What happens after all bitcoins have been mined?
What are your thoughts on a ‘limited’ supply currency like bitcoin? Is deflation a bad thing for an economy? Is deflation bad for a cryptocurrency?
‹#›
Consensus
‹#›
Consensus building
After a new block is mined and broadcast, other miners express acceptance of the block by building the next block on top of the block they received (and validated). They do this by including the hash of the received block in their own block
Consensus in bitcoin is represented by the most cumulative proof of work chain (difficulty)
If a majority of computing power is controlled by honest nodes, the honest chain will grow fastest and outpace any competing chains.
To modify a past block, an attacker would have to redo the proof-of-work of that block and all blocks after it and then surpass the work of the honest nodes.
The probability of a slower attacker catching up diminishes exponentially as subsequent blocks are added
‹#›
What happens if two miners mine two blocks around the same time and broadcast it to the network?
Some miners will receive block A and other will receive block B. Both blocks are valid.
Some miners will add block A to their blockchain and other will add block B. Now you have a fork in the chain!
The race begins again. The fork can deepen if two more blocks are found at around the same time.
The bitcoin consensus rules say that the chain with the most cumulative proof of work wins. This means the miners will abandon the shorter chain. The miners who were mining the shorter chain lose their reward (transaction) and the all the work they did.
The blockchain self corrects by abandoning the shorter branch of the fork.
Chain Fork
‹#›
Chain Fork
https://bitcoin.org/en/developer-guide#block-height-and-forking
‹#›
When is a transaction confirmed?
A transaction appears on the bitcoin network within seconds for being broadcast
Within 10 minutes (on average) a miner would validate and include the transaction in a new block. The transaction would have one confirmation.
After another block is found, the transaction would have 2 confirmations.
However, there is a possibility that the block may become orphaned during consensus (a longer alternate chain is created)
It is recommended that a transaction have at least 6 confirmation to be considered immutable (very low probability of being attacked, more on this later)
‹#›
How to acquire bitcoin*
Mine it yourself (impractical)
Join a mining pool
Buy it on an exchange with fiat currency
Offer your services
Use a BTM (bitcoin ATM)
On the street. Trade using localbitcoins.com (face to face; highly discouraged)
* ALL have pros and cons. Beware!!
‹#›
Exchanges
Place (online) to buy (and sell) bitcoin in exchange of other currencies
Exchanges store your bitcoin in an online wallet
A centralized service for a decentralized currency
Questions for security and privacy are been raised. The exchange could be required by local governments to reveal customer data. The exchange could freeze funds. Exchanges have been hacked and bitcoins stolen.
Users can move their bitcoin from the exchange to their own wallet. Until then the exchange only promises you ownership of the bitcoin with no real proof on the blockchain. Similar to banks - show you a balance of money in your account until you ask for a cash withdrawal.
coinbase.com
‹#›
Storing and using bitcoin
One feature (goal?) of bitcoin is that a user is their own bank (in the absence of intermediaries)
The disintermediation puts the responsibility of storing, using and protecting bitcoin solely in the hand of the user
Wallets are used to store bitcoin
To send bitcoin, use your wallet to find unspent transactions and then use a public address of the received to send bitcoin
The wallet keeps track of balances (no account)
‹#›
Wallets
A wallet essentially stores the keys (credentials) to the unspent bitcoins. With the keys you can spend those bitcoins.
Using cryptography, pairs of public and private keys are generated. Each wallet can have multiple pairs of keys. You can (should) use new pairs of keys for each new bitcoin transaction.
Loss of keys means loss of bitcoin!!
It should be called a keychain rather than a wallet. Why?
‹#›
Types of wallets
Types of wallets:
Online wallet: Held with an exchange
Software wallet: A client that stores wallets (and keys) on the user’s device
Hardware wallet: A specialized device that is used to store keys (offline)
Paper wallet: Keys are printed on paper with a QR code to read keys
Brain wallet: Memorize a series of words that can be turned into private key
‹#›
The slides are a courtesy of Dr. Nitin Kalé
Professor
Information Technology Program and
Epstein Department of Industrial and Systems Engineering
Viterbi School of Engineering
University of Southern California
‹#›