Professional Documents
Culture Documents
Blockchain in Depth
Blockchain in Depth
Blockchain in Depth
Blockchain
3
Immutable
Programmable Encrypted
Consensus
4
Blockchain Explained
Alice and Bob want to play
Chess through chat
How does this work?
Transactions
• Alice sends Bob 1 e4
(Pawn to e4)
• Bob sends back 1 .e5 • First of all both needs to agree on the state of the board
(Pawn to e5) • Both know the starting positions of the board
• Alice sends 2 Nf3 • Both know the sequence of messages so far
(Kinght to f3) • So they can reconstruct the state of the board
• How does this work?
If we agree on Initial state + history = we agree on the Current State of the System
We don’t want a trusted arbiter of the state of the World
We want some level of decentralization – not a single point of failure or compromise
We want the functionality of a trusted arbiter …. Without needing a trusted arbiter
“He who controls the past , controls the future”
A Network view of Blockchain
Users / Nodes
Blockchain Applications (smart Contracts • Initial State of the system is agreed upon by
the participating nodes
State machine • The Transactions between nodes are
broadcasted and verified
Consensus
• The verified transactions are added to Block
Blocks
• The block is validated with Distributed
Transactions Consensus and added to the blockchain
• The New State of the system is agreed upon
by the participating nodes
P-2-P Network
The Internet
6
Typical Blockchain Transaction Flow
Transaction Requested Transaction Broadcasted Transaction Verified Transaction Added to Pool
Transaction
Block Verified New Block Added to Blockchain Transaction Completed
Added to Block
Blockchain Nodes
Initiates Transaction
Verifies Transaction
Miner /
Node Light Node Full Node Validator node
Programmable Encrypted
Blockchain
Cryptography in Blockchain
Distributed Transparent
Consensus
10
Security Mechanisms
Hash Function
• Three basic building blocks are used:
– Checksums/hash algorithms
• They are used to provide integrity
protection, can provide authentication
– Encryption 010
1100
010101
• It is used to provide confidentiality, can 110101
– Digital signatures
• They are used to provide authentication,
integrity protection, and non-repudiation
Cryptographic functions used in Blockchain
13
Hash Function 1/3
• A cryptographic hash function is a one-way function that converts input data of arbitrary length and
produces a fixed-length output.
• The output is usually termed “hash value” or “message digest.”
Hash Function
Message of Hash Value of
Arbitrary Length Fixed Length
Hash
16 MB pdf Function
contract
Hash
12345678 90 e807f1fc
Function
1. Defined range
Much difference 2. Determinstic
by small change 3. Discontinuous
4. Uniformity
5. Non-invertible
12345678 91 Hash 0f7e44a92
Function
One way
Encryption
17
Encryption Basics
• Encryption takes plain text and turns it into cipher text by using a key or a key pair
• The result is a meaningless message, unless you have a key
• http://atom.smasher.or/bgp
http://www.networkdls.com/articles/keylength.pdf http://ietf.org/rfc/rfc2828.txt
18
Symmetric Encryption
Shared Key Shared Key
Alice Bob
To To To
+++_% +++_%
&&x&x &&x&x
++ +-x ++ +-x
Bob Bob Bob
%&+= %&+=
Top Secret Top Secret Top Secret
Encryption
Algorithm Decryption
Input Plain Text Algorithm Output Plain Text
Encrypted Text
20
Asymmetric Encryption
Encryption Key Decryption Key
Alice Bob
To To To
+++_% +++_%
&&x&x &&x&x
++ +-x ++ +-x
Bob Bob Bob
%&+= %&+=
Top Secret Top Secret Top Secret
Encryption
Algorithm Decryption
Input Plain Text Algorithm Output Plain Text
Encrypted Text
• Asymmetric Encryption consists of separate encryption and decryption keys, with users only being able to
decrypt an encrypted message if they have the appropriate decryption key.
• The asymmetric nature of public-key cryptography allows it a sizable advantage over symmetric-key algorithms
• Computationally more expensive
• It can be used for
– Encrypted Communications
– Authenticated Communications
– Confidential and Authenticated Communications
Asymmetric Encryption - Encrypted Communications
Only Bob should Alice Bob
be able to view
this message
Alice’s Bob’s
Public Bob’s
Public Private
Alice’s Key Key Key
Private Key
Plain Text Plain Text
Encrypted
communication
uses Recipient's
Encrypt Key Pair Decrypt
Encrypted Encrypted
Text
Text
Eve
Asymmetric Encryption
Encrypted Communications Demo
23
Asymmetric Encryption - Authenticated Communications
This could have
Alice Bob only been from
Alice
Alice’s Bob’s
Public Bob’s
Public Private
Alice’s Key Key Key
Private Key
Plain Text Plain Text
Authenticated
communication
uses Sender’s
Encrypt Key Pair Decrypt
Encrypted Encrypted
Text
Text
Eve
Asymmetric Encryption
Authenticated Communications Demo
25
Asymmetric Encryption - Confidential and Authenticated Communications
This could have
Alice Bob only been from
Alice
Alice’s Bob’s
Public Bob’s
Alice’s Public Private
Private Key Key Key
Key Plain Text Plain Text
Encrypted Encrypted
Text
Text
Eve
Asymmetric Encryption
Confidential and Authenticated Communications
Demo
27
Digital Signature
Digital Signature
A digital signature is a method to ensure the authenticity of electronically transmitted documents
like e-mail, spreadsheet, text file, etc. Authentic means that you know who created the document
and you know that it has not been altered in any way since that person created it.
Digital Signature - Explained
Alice Bob
Alice Bob
HASH ENCRYPT
Alice’s
Digital Private Digital Digitally
Contract Signature
Finger Key Signed
Document
Print Document
The contract document
Digital Signature - Verification is hashed to generate a
unique Digital Finger
Print If both hash are the
same , the document
is not tampered and is
HASH sent by Alice
Contract
Bob
Compare
Document
Digitally
Signed
Document
DECRYPT
Digital
Signature
The Digital Signature is
Decrypted to get the
Digital Finger Print
Verifying data using Digital signature
Hash
35
Immutable
Consensus Encrypted
Blockchain
Blocks and Chains
Programmable Transparent
Distributed
Blocks and Chains
• Data can be any type of data stored in the
Blockchain.
Data • Hash is digital fingerprint of Block
• Hash output of the previous block will be
served as one of the input to the next
Hash block
Hash of
Pervious Hash Hash
Output
Output
Block
Data
Blocks can store any values could represent transactions, contracts, assets,
identities, or practically anything that can be described in digital form.
Chaining the Blocks
Transactions
Transactions
Transactions
42
Timestamp
Digital Timestamp in Blockchain
• Timestamp
– A timestamp is a sequence of characters or encoded information identifying when a certain event occurred, usually
giving date and time of day, sometimes accurate to a small fraction of a second.
– This data is usually presented in a consistent format, allowing for easy comparison of two different records and
tracking progress over time; the practice of recording timestamps in a consistent manner along with the actual data
is called timestamping.
– Examples of timestamps: We need timestamp
• Wed 01-01-2009 6:00 to prevent
• 2005-10-30 T 10:45 UTC double spending.
• 1985-W15-5 T 10:15 UTC (year 1985, week 15, day 5 = 12 April 1985) - Satoshi Nakamoto
• 20180203073000 (02/03/2018 7:30:00)
• In Blockchain
– Each block contains a Unix time timestamp. In addition to serving as a source of variation for the block hash, they
also make it more difficult for an adversary to manipulate the block chain.
– A timestamp is accepted as valid if it is greater than the median timestamp of previous 11 blocks, and less than the
network-adjusted time + 2 hours.
44
Trusted Timestamping
• Trusted timestamping is the process of securely keeping track of the creation and modification time of a
document.
• Security here means that no one—not even the owner of the document—should be able to change it
once it has been recorded provided that the timestamper's integrity is never compromised.
• It allows interested parties to know, without a doubt, that a document in question existed at a particular
date and time.
• By including a cryptographic digest of a file you can later certify that the data existed at that time.
45
Merkle Root
Hash Tree or Merkle Tree
Hash 12345678 Merkle Root
Hash 1 Hash 2 Hash 3 Hash 4 Hash 5 Hash 6 Hash 7 Hash 8 Merkle Leaf
- Hash of Data block
D1 D2 D3 D4 D5 D6 D7 D8 Data Block
47
Blocks Using Merkle Tree
Block 20 Block 21 Block 22
Previous Block Hash Tx_root Previous Block Hash Tx_root Previous Block Hash Tx_root
Merkle Root
• Merkle root verifies a set of transactions.
• Transaction IDs are hashes of the transaction. Hash 12 Hash 34 Using a Merkle tree is
And the Merkle tree is constructed from these preferable over a
transactions. hash chain or
• Merkle root is cryptographic proof of which Hash 2 Hash 3 concatenated
Hash 1 Hash 4
transactions because
transactions are in the block, and which order it is easier to track a
they are in. transaction in a
• For odd number of transactions the last particular transaction
transaction ID (hash) is repeated Tx1 Tx2 Tx3 Tx4 is included in the set.
Merkle Tree
48
Merkle Tree - Data tampered
Hash 12345678
Hash
Hash 1234
1234 Hash 5678
D1 D2 D3 D4 D5 D6 D7 D8
tampered
49
Merkle Root Comparison
50
Identifying the Tampered Data
Hash 12345678
Hash 12 Hash 34
Hash 34 Hash 56 Hash 78
D1 D2 D3 D4 D5 D6 D7 D8
tampered
51
Nonce
52
Tampering with a Block in Blockchain
Hash : 2ca96e269bc36612004bcb85f77b5f325
000015783b764259d382017d91a36d2 Hash : 16f010289bc709a553cf9ca05f06cef4b79
000012fa9b916eb9078f8d98a7864e69 Hash : 0a56e7b99f43ec93838439ce4b0b6ef13b
0000b9015ce2a08b61216ba5a0778545
0ef969a9b6266c3173ab2f8112b99b4
06d0600e2cbb3567748f46a33fe9297cf 7049316c0b2f7aafcb3312af203bb
7ae83ed54f5146bd84452cdafd043c19 60309771128a72bcf9ecc0d94c3bda
bf4ddd7ceb7bbd85dd8062b29a9140bf
Partial Hash Inversion
Finding hash is very easy but the reverse is almost impossible. But what about partial hash inversion?
In other words to find an input which gives out a hash which lies in a specified range.
Total range of possible hash values
To create a new block, miners need to show “Nonce” value that together will other block header inputs
produces a hash value with in a valid range
Finding the Nonce
Pick a random
nonce
No
Compute the hash of
Yes Correct Version Timestamp Nonce
Hash Difficulty Level Time Stamp
Previous Block Hash TX Hash
00000000000000000003be1274ecad6192bca1241
Blockchain Challenge - nonce
PEER A
PEER B
PEER C
Immutable
Consensus Encrypted
Blockchain
Distributed Consensus
Distributed Transparent
Programmable
60
Decentralized system raises many questions
• Who runs the Distributed Ledger? Answer
• Who decides which blockchain transactions are valid?
• Who creates new blocks?
• Who validates the Blocks
Typical Blockchain Transaction Flow
Transaction Requested Transaction Broadcasted Transaction Verified Transaction Added to Pool
Transaction
Block Verified New Block Added to Blockchain Transaction Completed
Added to Block
Who creates the new Blocks?
Block I D Times tamp Nonce
Block I D Times tamp Nonce
Previous Block Hash TX Has h
Previous Block Hash TX Has h
**** ****
STR STR
**** ****
STR STR
New **** ****
Transactions
STR STR
Block **** ****
Transactions
STR STR
****
STR
**** New
STR
**** ****
Block STR STR
**** ****
Block I D Times tamp Nonce Block I D Times tamp Nonce STR STR
Block I D Times tamp Nonce **** ****
STR STR
Previous Block Hash TX Has h Previous Block Hash TX Has h
Previous Block Hash TX Has h
**** **** **** ****
STR STR **** **** STR STR
STR STR
**** **** **** **** ? What will be the next valid block?
Transactions
Transactions
**** ****
Transactions
STR STR STR STR
Block n Block n+1
STR STR
Block n+2
**** **** **** ****
STR STR **** **** STR STR
STR STR
**** **** **** **** Block I D Times tamp Nonce Block I D Times tamp Nonce
STR STR **** **** STR STR
STR STR
Previous Block Hash TX Has h Previous Block Hash TX Has h
Transactions
Transactions
STR STR STR STR
Block Block
Memory Pool (“Mempool”) Miners pick up transactions ****
STR
****
STR
****
STR
****
STR
All unconfirmed transactions posted to and aggregate them into **** **** **** ****
STR STR STR STR
next block
the blockchain network
The Mining Process
Find the
Transactions Miner Aggregate Blocks
2 Miner creates Nonce
transactions, compute Miner solves the
1 a Block puzzle (Nonce)
Merkle root, and fill other 3
inputs needed for the block and shows PoW
Proof of
Work
~10 minutes of transactions
are broadcast to the network
Successful miner broadcasts
PoW to the network 4
Newly created block
is appended to the
existing blockchain Miners Verify PoW 5
6 Adding the
new block Verification
Process starts all over again
What do the Miners get?
Miner Reward = Block reward + sum of all Transaction fees inside the block
• Process and confirm Transactions
• Solve specific math problems in competition
• Cryptocurrency awarded to winner
The Bitcoin Example
• Bitcoin miner creates a new block at every 10 minutes and gets 6.25 BTC as reward
• In every 21000 transactions, difficulty level of solving the cryptographic puzzle is adjusted to
maintain the time (10’)
• The reward will be halved every 210000 blocks
• There are currently 16million BTC in circulation and there is a cap of 21M BTC as per the rules
and the cap will be reached by 2140 AD
Elements of Consensus in General
• Consensus is the process of building agreement among a group of mutually distrusting participants
• There are the four elements that must be considered:
1. Investment of the validator or miner, the nodes that process the consensus algorithm on behalf of the network.
– Investment is the level of investment needed to be made on the part of the miner or validator.
– What does the potential validator or miner have to invest in order to be able to process transactions and verity blocks?
2. Selection process of the Validator or Miner
Investment by the
– The process of electing the leader / miner / validator Hashing power, tokens Validator
– Some sort of lottery to randomly select the miner to validate Validator
Random, round robin, election etc
– Raw elections and perform round robin selection Selection Process
3. Proof Element PoW, PoS, PoA, PBFT Proof Element
– PoW, PoS, Proof of Capacity, PBFT, Proof of elapsed time, Prof of Burn, Proof of activity, Ripple protocol etc.
Public / Private/ Federated Level of trust
4. Level of Trust
– The level of trust between the nodes , it varies considerably with different types of Blockchain.
Objective of different Consensus Algorithm
• There are four additional goals that a consensus algorithm will consider:
1. Performance
– How many transitions per second (tps)?
2. Scalability
– Number of concurrent users supported by the blockchain network within acceptable performance.
3. Threat resistance against potential outside attacks
– Various threat models need to be considered in order for the Blockchain to be able to fend off an
attack.
– If the attack cannot be completely prevented, the blockchain needs to make the cost of mounting an
attack more expensive to attempt than the potential benefit of being an honest miner/validator of a
Blockchain.
– 51% attack – immutability can be compromised
– Sybil attack - an attempt to control the peer network by creating multiple fake identities
4. Failure model
– Network failures , what % of nodes can be disconnected or down without affecting the operation of
the blockchain network
– For bitcoin it is 33%, means 33 % of the node failures can be tolerated while the system can continue
to process the block normally
Different Consensus Algorithms
69
Consensus Mechanisms compared
PoW requires validators to solve difficult cryptographic puzzles
Pros: Works in Permissionless Blockchain (untrusted networks)
Cons: Relies on energy use, slow to confirm transactions
Ex: Bitcoin and Ethereum
Proof of Work
PoS requires validators to hold currency in escrow
Pros: Works in Permissionless Blockchain (untrusted networks)
Cons: Requires cryptocurrency, “Nothing at stake” problem
Ex: Nxt
Proof of Stake
Wait time in a trusted execution environment randomizes block
generation
Pros: Efficient
Cons: Requires Processor extensions
Proof of Elapsed
Ex: Hyperledger Sawtooth
Time
70
Consensus Mechanisms compared
Validators apply received transactions without Consensus
Pros: Very quick , suited to development
Cons: No consensus; can lead to divergent chains
Ex: Hyperledger Fabric V1
Solo / No ops
Practical Byzantine Fault tolerant implementations
Pros: Reasonably efficient and tolerant against attacks
Cons: Validators and known are totally connected
Ex: Hyperledger Fabric V 0.6
PBFT Based
Ordering service distributes blocks to peers
Pros: Efficient and fault tolerant
Cons: Does not guard against malicious activity
Ex: Hyperledger Fabric 1
Zookeeper
71
Trust Model
Hunter
Gatherer
• Old Old Trust Model – Show me your armies
• Old Trust Model – Show me your reputation and relationships
• Current Trust Model – Show me your license
• New Trust Model – Show me your code Civilized
Society
As the level of trust increases, the need for resource usage as a measure of generating
trust decreases.
Forking
73
Forking 74
Forking
• A Fork takes place when a Blockchain splits into two different paths forward.
• Changes and modifications to the blockchain software need to be approved by consensus
• If a group of nodes modify their software without consensus, those nodes then invalidate
a rule held by the rest of the network and create their own fork of the blockchain.
• Hard Fork - Broadening or removing the rules Temporary Intentional
(split in consensus) (Change in rules)
– Introduces a change that forces every one to upgrade
• Soft fork – Tightening the rules
– Introduces a change that is backward compatible, does not need to upgrade
New
Rules
Alternative Version (follows New Rules)
75
Soft Fork, Hard Fork and Source Code Fork
1. Soft Fork • Hard Fork - Broadening or removing the rules
History Bitcoin cash
100 Original Version – Introduces a change that forces every one to
upgrade
Soft Fork • Soft fork – Tightening the rules Segwit
There may be temporary disagreement if two proposals occur at the same time; eventually, with
very high probability, one proposal will be established by picking the longest blockchain
76
Immutable
Consensus Encrypted
Distributed
77
What are SMART CONTRACTS?
In 1996, Nick Szabo described a smart contract as “a set of promises, specified in digital form,
including protocols within which the parties perform on these promises.”
“a set of promises”
“specified in digital form”
THE CONTRACT
“protocols”
THE CONTRACT IN THE CODE
“within which the parties perform”
THE RULES
THE AUTOMATED PERFORMANCE
78
Smart Contracts Defined
Smart contracts are computer programs that can automatically
executes the terms of a contract
✓ Owner
Owner Dave OwnerClaire
Dave
✓ ✓
6453899 PD 3452654 PC
✓ ✓
✓
How Does Smart Contract Work?
6
5
4 NETWORK
UPDATES
3 EXECUTION &
PROCESSING
2 ENCRYPTION &
BLOCKCHAIN
CODE THE TECHNOLOGY
1 SET
BUSINESS
LOGIC
CONDITIONS
IDENTIFY
AGREEMENT
83
How Smart Contract is Different
Traditional Contracts Smart Contracts
AUTOMATIC Manual Automated
Remittance Remittance
84
Smart Contract – A few examples
85
Crypto Assets
86
Cryptocurrency Types
Blockchain Derived
from Bitcoin
A crypto coin is a digital
or virtual currency on
decentralized networks Native Blockchain
based on blockchain - Not Derived
technology and is from Bitcoin
secured by cryptography
Mining-Based Stablecoins
Fiat-Collateralized Stablecoin
Crypto-Collateralized Stablecoin
Non-Collateralized Stablecoin
(algorithmic)
Types of Crypto Tokens
Cryptographic tokens
represent programmable
assets or access rights,
managed by a smart
contract and an A security token is a digital asset
underlying distributed that derives its value from an
ledger. external asset that can be traded.
Crypto Coin vs. Crypto Token
A coin is a digital currency similar to the A token is a digital asset issued on a particular
physical currency project
Coin operates on its own Blockchain with its Token does not operate on its own
own protocol Blockchain
Coins are purely used as source of payments Tokens are used for payments and signing
digital agreements
Crypto coins are mined in the Blockchain Crypto tokens are created by Smart contract
network by miners and used by DApps
“You can buy a token with a coin, but not a coin with a token.”
Crypto Wallets
Crypto Wallet / Blockchain Wallet
Privacy is maintained
Exchange of Funds
94
Crypto Wallet Security
• Level 1
– allows email verification and back up phrase / password hint to recover password
– This is to prevent users from losing access to their account
• Level 2
– Enable 2 step authorization by linking phone numbers and authenticate via OTPs
– To prevent unauthorized access
• Level 3
– Allows users to block tor requests
In Short….
Immutable
Consensus Encrypted
Blockchain
Programmable Transparent
Distributed
96
Do you need Blockchain?
98
Prerequisites for a Blockchain Solution
Multiple parties share data 4 Intermediaries add complexity
1 Multiple parties need a common view of
Removal of dependencies on
intermediaries can reduce cost and
the information at hand
complexity
If the 1s t condition is correct and three out of the remaining considered is desired , then blockchain
may be an effective solution to the problem
I need a Blockchain but which one?
Transaction Processing:
Public Data access: Private or Public Permissioned or Permission less
© 2018 InfosysLimited, Bengaluru, India. All Rights Reserved. Infosys believes the information in this document is accurate as of its publication date; such
information is subject to change without notice. Infosys acknowledges the proprietary rights of other companies to the trademarks, product names and
such other intellectual property rights mentioned in this document. Except as expressly permitted, neither this documentation nor any part of it may be
reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, printing, photocopying, recording or
otherwise, without the prior permission of Infosys Limited and/ or any named intellectual property rights holders under this document.