Introduction to Blockchaining
Hash Tree
Consider one data is corrupted after
generating hash tree
• How many comparisons are needed to find out an error in the data of the hash tree
with 16 nodes?
• How many comparisons are needed to localize error block in the data of the hash
tree with 16 nodes?
• How many comparisons are needed to locate the error data in the data of the hash
tree with 16 nodes?
Consider one data is corrupted after
generating hash tree
• For a hash tree that covers 32 data blocks, how many hash checks do you need to
perform to detect the error? Assume that error occurred on only one block.
• For a hash tree that covers 16 data blocks, how many hash checks do you need to
perform to detect an error? Assume that error occurred in two different blocks.
• For a hash tree that covers 16 data blocks, how many hash checks (maximum) do you
need to perform to locate the error? Assume that error occurred on only one block.
H 1-16
H1-8 H9-16
H14 H58 H912 H1316
H12 H34 H56 H78 H910 H1112 H1314 H1516
H1 H 2 H 3 H 4 H5 H 6 H7 H8 H9 H10 H11 H12 H13 H14 H15 H16
D1 D 2 D 3 D 4 D5 D 6 D7 D8 D9 D10 D11 D12 D13 D14 D15 D16
Essentials to understand Blockchain
• Cryptographically Secured Hash Functions
• Hash Functions: Map arbitrary sized data to a fixed size
• X is called the message and H(X) is called the message digest
• Avalanche effect
• One way, given a x, we can compute H(x), but given a H(x), no deterministic
algorithm can compute x
• For two different x1 and x2, H(x1) and H(x2) should be different.
Cryptographic Hash Functions
Examples: MD5, SHA256
Image source: Wikipedia
Cryptographically Secured Chain of Blocks
H1=Hash(0,C1,TS1,H0)
• The first use - time-stamp a digital document
(Harber and Stornetta, 1991)
H2=Hash(1,C2,TS2,H1)
• A sequence of timestamps [TS1, TS2, TS3, …] denoting the
document creation or updation.
H3=Hash(2,C3,TS3,H2)
• A block consisting of the sequence number of access, client ID,
timestamp, a hash value from the previous request
H4=Hash(3,C4,TS4,H3)
Haber, Stuart; Stornetta, W. Scott (January 1991). "How to time-stamp a digital document". Journal of
Cryptology. 3 (2): 99–111
Merkle Trees (Ralph Merkle, 1979)
• Aka hash tree Root Hash
Hroot=Hash(H0+H1)
• Every leaf node is labelled
with the hash of a data
L1 Hash L1 Hash
block H0= Hash(H00+H01) H1=Hash(H10+H11)
• Every non-leaf node is
labelled with the L2 Hash L2 Hash L2 Hash
L2 Hash
H01=Hash(D2) H10=Hash(D3) H11=Hash(D4)
H00=Hash(D1)
cryptographic hash of the
labels of its child nodes D1 D2 D3 D4
Types of Network
www.menti.com
Blockchain
• A decentralised computation and information sharing platform that enables
multiple authoritative domains, who do not trust each other, to cooperate,
coordinate and collaborate in a rational decision making process.
Block 1 Block 2 Block 3 Block 4
Sharing Information
• Conventional way
Sharing Information
• Shared Google doc – Simultaneous editing
• Single Point of Failure
• Bandwidth Problem
• Server Crash?
Image source: http://www.youngupstarts.com
Ideal Solution
Blockchain
• The Internet Database to support Decentralization with Strong
consistency.
Blockchain Model
• Local copy of global data at every node.
• Ensure Consistency
• Identical Local Copies
• Updated Local Copies based
on Global Data
• Public Ledger
• Database of Historical
Information available to all
• Can be used for future
computations
Image Source:
• Eg: Public Ledger for Banking
What is Blockchain?
• Blockchain is a system comprised of..
• Transactions
• Immutable ledgers Every user agrees on the initial state of the system.
• Decentralized peers Every transaction is recorded on the blockchain.
• Encryption processes The current state is accepted based on the past data.
• Consensus mechanisms
• Optional Smart Contracts
Immutable Records
• Every record is stored as Hash in the blockchain
• Every block is connected to its next block using Hash
Banking Sector Block Chain
Public Ledger Alice Bob Public Ledger
of Alice of Bob
Initial State of Blockchain
Jane
Public Ledger
of Jane
Banking Sector Block Chain
Public Ledger Alice Bob Public Ledger
of Alice of Bob
Alice adds Rs. 100
to her wallet
Jane
Public Ledger
of Jane
Banking Sector Block Chain
Alice: Rs. 100 Alice: Rs. 100
Public Ledger Alice Bob Public Ledger
of Alice of Bob
Alice: Rs. 100
Jane
Public Ledger
of Jane
Banking Sector Block Chain
Alice: Rs. 100 Alice: Rs. 100
Alice -> Bob Alice -> Bob
Rs: 50 Rs: 50
Rs. 50
Public Ledger Alice Bob Public Ledger
of Alice of Bob
Alice: Rs. 100
Alice -> Bob
Rs: 50
Jane
Public Ledger
of Jane
Banking Sector Block Chain
Alice: Rs. 100 Alice: Rs. 100
Alice -> Bob Alice -> Bob
Rs: 50 Rs: 50
Bob -> Jane Bob -> Jane
Rs: 30 Rs: 30
Alice Bob
Public Ledger Public Ledger
of Alice of Bob
3 0
.
Alice: Rs. 100
Rs
Alice -> Bob
Rs: 50
Bob -> Jane
Rs: 30
Jane
Public Ledger
of Jane
Banking Sector Block Chain
Alice: Rs. 100 Alice: Rs. 100
Alice -> Bob Alice -> Bob
Rs: 50 Rs: 50
Bob -> Jane Bob -> Jane
Rs: 30 Rs: 30
Alice Bob
Public Ledger Public Ledger
of Alice
Rs
of Bob
.7
0
Alice: Rs. 100
Alice -> Bob
Rs: 50
Bob -> Jane
Rs: 30
Jane
Public Ledger
of Jane
Banking Sector Block Chain
Alice: Rs. 100 Alice: Rs. 100
Alice -> Bob Alice -> Bob
Rs: 50 Rs: 50
Bob -> Jane Bob -> Jane
Rs: 30 Rs: 30
Alice Bob
Public Ledger Public Ledger
of Alice
Rs
of Bob
.7
0
Alice: Rs. 100
Alice -> Bob
Rs: 50
Bob -> Jane
Rs: 30
Jane
Public Ledger
of Jane
Requirements of Blockchain
• Protocols for Commitment
• All valid transactions should be committed and included in the chain within valid time.
• Consensus
• Local copies to be updated and consistent.
• Security
• Data to be Tamper proof.
• Privacy and Authenticity
• Data to be secured and authentic.
Users of Block Chain - Cryptocurrency
• Permissionless model
• Distributed Ledger model
• Users will be anonymous
• Users
• Perform Transactions
• Miners
• Approve Transactions
Structure of a Block
Genesis Block
Previous Hash
Time Stamp
Data
Block Hash
Merkle Root
Data: Block Size, No. of Transactions, DB Type, Miner Reward etc
Structure of a Block
Block 1
Previous Hash
Time Stamp
Data
Block Hash
Nonce
Merkle Root
Difficulty
Structure of a Block (Reference: Bitcoin)