Blockchain Merged
Blockchain Merged
• To avoid all the hypes and apply Blockchain as a solution at the right
place ...
Why this course ...
• To avoid all the hypes and apply Blockchain as a solution at the right
place ...
Crude
Purchase
Supply Chain in Petroleum Industry
Crude Crude
Purchase Transportation
Supply Chain in Petroleum Industry
Refining
Supply Chain in Petroleum Industry
Distribution Refining
Supply Chain in Petroleum Industry
Upstream Downstream
Exploration and Industry Refining and
Production Marketing
Bodies
Petroleum Supply Chain in India
ONGC
Upstream OVL
Exploration and
Production
Oil India Ltd
Pvt E&P Co
Petroleum Supply Chain in India
later
Moving towards Decentralization ...
- Buy Refinery
Cloud
2:30 pm
on Dec 26, 2020 at
from amazon
Moving towards Decentralization ...
- Buy Refinery
Cloud
2:30 pm
on Dec 26, 2020 at
from amazon
Who will manage it and provide the cost?
Moving towards Decentralization ...
• Efficiently computable
Cryptographic Hash Functions: Properties
• Deterministic
Always yields identical hash value for identical input data
• Collision-Free
If two messages are different, then their digests also differ
• Hiding
Hide the original message; remember about the avalanche
effect
• Puzzle-friendly
Given X and Y, find out k such that 𝑌 = 𝐻(𝑋| 𝑘 - used to
solve the mining puzzle in Bitcoin Proof of Work
Collision Free
• Hash functions are one-way; Given an 𝑥, it is easy to find
𝐻(𝑥). However, given an 𝐻(𝑥), one cannot find 𝑥
http://www.blockchain-basics.com/HashFunctions.html
H(M,KA),M,KA H(M,KA),M,KA
KA is the public key of Alice – A public identity that only Alice can have
Puzzle Friendly
Message
Digest
256 bit
Initialization
Vector
C C C
Patterns of Hashing Data
• Independent hashing
• Repeated hashing
• Combined hashing
• Sequential hashing
• Hierarchical hashing
Types of Hashing
• Independent hashing
• Repeated hashing
Courtesy: Blockchain Basics: A Non-Technical Introduction in 25 Steps by Daniel Drescher
Types of Hashing
Combined hashing
Sequential hashing
Hierarchical hashing
Illustration
http://www.blockchain-basics.com/HashFunctions.html
DATA
Hash Pointer
Illustration
http://www.blockchain-basics.com/HashFunctions.html
L1 Hash L1 Hash
H0= Hash(H00+H01) H1=Hash(H10+H11)
T1 T2 T3 T4
Blockchain as a Hashchain
M’
Public Key Encryption - RSA
• Named over (Ron) Rivest – (Adi) Shamir – (Leonard) Adleman
– inventors of the public key cryptosystem
M, M’
Reduce the Signature Size
• Use the message digest to sign, instead of the original
message
M, S
http://www.blockchain-basics.com/HashFunctions.html
Digital Signature in Blockchain
• Used to validate the origin of a transaction
• Prevent non-repudiation
• Alice cannot deny her own transactions
• No one else can claim Alice’s transaction as his/her
own transaction
A:10, Sig(A)
H(0) H(1)
A:10, Sig(A) A->B:5, Sig(A)
• Consensus
The Three Pillars
Distributed Economic
Crypto Models
Systems
Our Core Problem
4 9
1
10
2 5
7
3
6
8 11
Our Core Problem
4 9
1
10
2 5
7
3
6
8 11
Our Core Problem
4 9
1
10
2 5
7
3
6
8 11
Our Core Problem
4 9
1
Other nodes in the network need to
agree on this new block 10
2 5
7
3
6
8 11
Our Core Problem
4 9
1 Other nodes in the network need to
agree on this new block
10
2 5
The Classical Distributed
Consensus Problem7
3
6
8 11
Distributed Consensus
Distributed Consensus
Distributed Consensus
Distributed Consensus
• Inability of the
A complete distributed
third parties toplatform for
determine payee, time, or
the amount of payments made by individuals – Even the
cryptocurrency
banks exchange
will not be able to track it
Distributed Consensus
• Open Consensus
• PoW
The Open Question
Distributed Consensus
Message Passing
Distributed Consensus: The Limitation
Message Passing
Needs the identity
of others
Distributed Consensus: The Limitation
We need a leader
But nobody knows each other!
Consensus in an Open Network: Puzzle Solving
Pizza or Burger?
Can't say immediately
Bitcoin Proof of Work: An Open Consensus
• Popularity of Cryptocurrencies
• Mining and Miners
• Mining reward
• Bitcoin Price
• Beyond Bitcoins
Bitcoin Mining: The Key to Consensus
Encourage the
community to
participate in the
mining through
incentivization
The Economics behind Reward
Encourage the
Produces new Bitcoins in
community to
the System
participate in the
(Similar to a Minting new
mining through
Coins)
incentivization
The Economics behind Reward
Growing interests in
developing decentralized
applications (Dapps)
What are these Dapps?
• Permissioned Blockchain
• Smart Contracts
• Permissioned Models
• Enterprise Blockchains
DLTs for Code Execution
Input
Traditional Way of Maintaining Digital Contacts
Response
Traditional Way of Maintaining Digital Contacts
Input
Traditional Way of Maintaining Digital Contacts
Response
Traditional Way of Maintaining Digital Contacts
• Advantages:
• Go back to the classical distributed consensus protocols –
low latency for commitment and high transaction
throughput
• Use "Witness Cosigning" instead of "Proof Mining" for new
block generation
• Classical Distributed Consensus + Digital Signature
Permissioned Blockchain
• Cryptographic
security – Ensures
that participants can
only view information
on the ledger that
they are authorized to
see Image source: http://dataconomy.com/
Structure of a Block
• A block is a container data structure that contains a series of
transactions
• In Bitcoin: A block may contain more than 500 transactions on
average, the average size of a block is around 1 MB (an upper
bound proposed by Satoshi Nakamoto in 2010)
• May grow up to 8 MB or sometime higher (several
conflicting views on this!!)
• Larger blocks can help in processing large number of
transactions in one go.
• But longer time for verification and propagation
Structure of a Block (Reference: Bitcoin)
• Two components:
• Block Header
• List of Transactions
Find out the nonce which generates the desired hash (certain
number of zero bits at the prefix) -
0000000000000000004a2b84f93a285b7a7………
Block Header (Reference: Bitcoin)
• Mining – the mechanism to generate the hash
• The mechanism needs to be complicated enough, to
make the blockchain tamper proof
• Bitcoin Mining: Hk = Hash(Hk-1 || T || Nonce ||
Something more)
• Find the nonce such that Hk has certain predefined
complexity (number of zeros at the prefix)
• The header contains mining statistics – timestamp, nonce and
difficulty
Block Header (Reference: Bitcoin)
• Understanding Difficulty and Bits
• “Bits” written in Hex, e.g., 0x170e2632
• First byte is index and next three bytes form coefficient
• Target = Coefficient*2^(8*(index-3))
• Difficulty is the largest possible target
(0x00000000FFFF00000000000000000000000000000000000000000
00000000000) divided by the current target , e.g.,
• (0x0000000000000000000E2631FFFFFFFFFFFFFFFFFFFFFBB0C4B0219
13E000000)
• Remember: “Cost of Mining” – Pretty High (Computing Power
and Energy)
[Number conversion utility: https://www.rapidtables.com/convert/number/hex-to-
decimal.html]
Hashes in a Block Header (Reference: Bitcoin)
Demonstration
https://dlt-repo.net/bitcoin-block-hash-verification-tool/
Block Source: https://btc.com/btc/blocks
• We have described the structure of a block in blockchain
• Main components of a block header
• How to solve block generation puzzle
• What is meant by mining of a block
• Cryptography and Network Security – Principles and Practice
by William Stallings, Pearson (2017)
• Blockchain Basics: A Non-Technical Introduction in 25 Steps
by Daniel Drescher, Apress (2017)
• Any other standard textbook on blockchain/bitcoin
Blockchain and its applications
Prof. Shamik Sural
Department of Computer Science & Engineering
Indian Institute of Technology Kharagpur
• Requirements
• All the replicas need to be updated with the last mined
block
• All the replicas need to be consistent – the copies of the
Blockchain at different peers need to be exactly similar
Transactions in a Block
L1 Hash L1 Hash
H0= Hash(H00+H01) H1=Hash(H10+H11)
T1 T2 T3 T4
Transactions in a Block
TX TX
TX
1 3
0
input() input()
input()
100 BTC
output1() output1()
output1()
output2()
output2()
TX TX
2 4
input() input()
output1() output1()
Bitcoin Scripts – A Simple Example
T(A->B)
T(A->B)
KAPUB, SA(T(A->B))
T(A->B)
KAPUB, SA(T(A->B))
T(A->B)
scriptPubKey, scriptSig
T(A->B)
scriptPubKey, scriptSig
Transaction 18E14A7B6A30…
scriptSig:
Input D61967F63C7DD…
OP_DUP
OP_HASH160
Transaction scriptPubKey: 16UwLL9Risc3QfPqBUvKof…
OP_EQUALVERIFY
Output OP_CHECKSIG
scriptPubKey: OP_DUP
OP_HASH160 <pubKeyHash>
OP_EQUALVERIFY
OP_CHECKSIG
The stack is initially empty.
scriptSig: <sig> Both the scripts are
combined – input followed by output
<pubKey>
<sig> <pubKey> OP_DUP
OP_HASH160 <pubKeyHash>
OP_EQUALVERIFY OP_CHECKSIG
A real example
For more examples to explore: https://btc.com/btc/blocks
from Bitcoin
Bitcoin Scripts
<pubK
<sig> <pubKey> OP_DUP <si
ey>
OP_HASH160 <pubKeyHash> g>
OP_EQUALVERIFY OP_CHECKSIG
The top two items are pushed to Stack one
after another
OP_DUP OP_HASH160
<pubKeyHash> OP_EQUALVERIFY
OP_CHECKSIG
Bitcoin Scripts
<pubK
OP_DUP OP_HASH160 ey>
<pubK
<pubKeyHash> OP_EQUALVERIFY ey>
<si
OP_CHECKSIG g>
Top stack item is duplicated
OP_HASH160 <pubKeyHash>
OP_EQUALVERIFY OP_CHECKSIG
Bitcoin Scripts
<pubH
ash>
<pubK
OP_HASH160 <pubKeyHash>
ey>
<s
OP_EQUALVERIFY OP_CHECKSIG
ig
Top stack item is hashed (RIPEMD-160
hashing)
>
<pubKeyHash> OP_EQUALVERIFY
OP_CHECKSIG
Bitcoin Scripts
<pubKey
<pubHa
Hash>
<pubKeyHash> <pubKe
sh>
<si
y>
OP_EQUALVERIFY OP_CHECKSIG g>
The constant is pushed in the stack
OP_EQUALVERIFY OP_CHECKSIG
Bitcoin Scripts
<pubKey
<pubHa
Hash>
<pubKe
sh>
OP_EQUALVERIFY OP_CHECKSIG <si
y>
g>
Equality is checked between the top two items
in the stack
OP_CHECKSIG
Bitcoin Scripts
<pubK
OP_CHECKSIG <si
ey>
g>
Signature is checked based on the top two
stack item
TRUE
Bitcoin Script Instructions
Source: https://en.bitcoin.it/wiki/Script
• Use of scripts in generating input and output of bitcoin
transactions
• Public key cryptography and digital signature for
cryptographically protecting transactions
• Blockchain Basics: A Non-Technical Introduction in 25 Steps
by Daniel Drescher, Apress (2017)
• Any other standard textbook on blockchain/bitcoin
Blockchain and its applications
Prof. Shamik Sural
Department of Computer Science & Engineering
Indian Institute of Technology Kharagpur
Give me the
address
Joining in a Bitcoin P2P Network
Seed Node
<address list>
Joining in a Bitcoin P2P Network
Seed Node
Joining in a Bitcoin P2P Network
Start transaction
Transactions in a Bitcoin Network
Validate the
Transaction
Transaction Flooding in a Bitcoin Network
Flood the
Transaction
Transaction Flooding in a Bitcoin Network
I have already
A->B:BTC10 seen the
transaction
Which Transactions Should You Relay?
• The transaction is valid with current blockchain
– No conflict
– No double spending
• The script matches with a pre-given set of whitelist scripts
– Avoid unusual scripts, avoid infinite loops
• Does not conflict with other transactions that I have
relayed after getting the blockchain updated – avoid
double spending
Transaction Flooding in a Bitcoin Network
A->B:BTC10
C->D:BTC20 A->B:BTC10
C->D:BTC20
A->B:BTC10
A->B:BTC10 A->B:BTC10
C->D:BTC20
C->D:BTC20
C->D:BTC20
A->B:BTC10
A->B:BTC10
Different nodes Accept the first
may have different transactions that
transaction pools you have heard
Transaction Flooding in a Bitcoin Network
A->B:BTC10
C->D:BTC20 A->B:BTC10
C->D:BTC20
A->B:BTC10
A->B:BTC10 A->B:BTC10
C->D:BTC20
C->D:BTC20
C->D:BTC20
A->B:BTC10
Accept the first set of
A->B:BTC10
transactions that you
have heard
Mining in a Bitcoin Network
• “Accidental” forks occur rarely. Even if they occur, eventually only one
becomes part of the longest chain
• There are “intentional” forks of two type: hard forks and soft forks to come
up with new versions like Bitcoin Cash, etc., or to upgrade software versions
Which Block to Relay
• Safety vs Liveness
Permissionless Model
• Open network
• Anyone can join in the network and initiate transactions
• Participants are free to leave the network, and can join
later again
Permissionless Model
• Open network
• Anyone can join in the network and initiate transactions
• Participants are free to leave the network, and can join
later again
B3
Consensus Challenges
B1 B2 B3
B3 B2
Consensus Challenges
TX11 TX10
TX19 TX16
TX13
TX42 TX55
TX45 TX40
TX67
TX56 TX32
• Block Mining
• PoW
• Block Mining
TX22
TX16 TX17 TX17
TX17 TX22 TX16
TX37 TX87 TX31
Unconfirmed TX TX87 Unconfirmed TX TX37 Unconfirmed TX
TX16 TX16
TX17
TX17 TX17
TX22
TX87 TX22
TX87
TX49 TX31
TX37
TX37 Miner 1 TX88 Miner 2 Miner 3
• No fixed ordering of transactions
Safety vs Liveness • No fixed number of transactions
TX10 per block
TX11
TX13
TX19 TX16 • Limit on the Block size
TX45
TX42 TX55
TX67 TX40
TX56
TX32
TX22
TX16 TX17 TX17
TX17 TX22 TX16
TX37 TX87 TX31
Unconfirmed TX TX87 Unconfirmed TX TX37 Unconfirmed TX
TX16 TX16
TX17
TX17 TX17
TX22
TX87 TX22
TX87
TX49 TX31
TX37
TX37 Miner 1 TX88 Miner 2 Miner 3
Safety vs Liveness • Generate the proof (nonce)
TX11 TX19
TX10
TX16
• Generation: Complex
TX13
TX45
TX42 TX55
TX40
• Verification: Easy
TX56 TX67
TX32
TX22
TX16 TX17 TX17
TX17 TX22 TX16
TX37 TX87 TX31
Unconfirmed TX TX87 Unconfirmed TX TX37 Unconfirmed TX
TX16 TX16 ?
? TX17 ? TX17
TX17 TX22
TX87 TX22
TX87
TX49 TX31
TX37
TX37 Miner 1 TX88 Miner 2 Miner 3
Safety vs Liveness • Expectation: One of
TX11 TX19
TX10
TX16
the miners will be able
TX13
TX45
TX42 TX55
TX40
to generate the proof
TX56 TX67
TX32
TX22
TX16 TX17 TX17
TX17 TX22 TX16
TX37 TX87 TX31
Unconfirmed TX TX87 Unconfirmed TX TX37 Unconfirmed TX
TX16 TX16 ?
? TX17 ? TX17
TX17 TX22
TX87 TX22
TX87
TX49 TX31
TX37
TX37 Miner 1 TX88 Miner 2 Miner 3
Safety vs Liveness • Expectation: One of
TX11 TX19
TX10
TX16
the miners will be able
TX13
TX45
TX42 TX55
TX40
to generate the proof
TX56 TX67
TX32
TX22
TX16 TX17 TX17
TX17 TX22 TX16
TX37 TX87 TX31
Unconfirmed TX TX87 Unconfirmed TX TX37 Unconfirmed TX
TX16 TX16 NM3
? TX17 ? TX17
TX17 TX22
TX87 TX22
TX87
TX49 TX31
TX37
TX37 Miner 1 TX88 Miner 2 Miner 3
Safety vs Liveness
TX10
TX11 TX19 TX22
TX16
TX13 TX17
TX45
TX42 TX55
TX16
TX67 TX40
TX56 TX31
TX32
TX10
TX11 TX19 TX22
TX16
TX13 TX17
TX45
TX42 TX55
TX16 Miner 4
TX67 TX40
TX56 TX31
TX32
• Attacks on PoW
• Security
• 51% attack
PoW: Mining a New Block
TX10
TX11 TX19 TX22
TX16
TX13 TX17
TX45
TX42 TX55
TX16
TX67 TX40
TX56 TX31
TX32
• Sybil Attacks
• Attacker attempts to fill the network with the clients under
its control
• Create multiple identities (multiple public key addresses) to
control the network – refuse to relay valid blocks or relay
attacked blocks
• Solution: Diversify the connections – Bitcoin allows one
outbound connection to per /16 block of IP addresses –
cannot make both 202.141.81.2/16 and
202.141.80.18/16 as the peers
Security Measures for PoW
Carbon Footprint
825.47 kg / TX
Equivalent
to 137,578 hours of
watching YouTube
Electrical Energy
Carbon Footprint
1737.82 kWh / TX
825.47 kg / TX
Equivalent to power
Equivalent
consumption of an
to 137,578 hours of
average U.S. household
watching YouTube
over 59.56 days.
• PoW vs PoS
• PoW: Probability of mining a block depends on the work
done by the miner
• PoS: Amount of bitcoin that the miner holds – Miner
holding 1% of the Bitcoin can mine 1% of the PoS blocks.
Proof of Stake (PoS)
• Variants of “stake”
• Randomization in combination of the stake (used
in Nxt and BlackCoin)
• Coin‐age: Number of coins multiplied by the
number of days the coins have been held (used in
Peercoin)
Proof of Burn (PoB)
• Basic idea:
• Each participant in the blockchain network waits a
random amount of time
• The first participant to finish becomes the leader for the
new block
Proof of Elapsed Time (PoET)
• Geth
• Testnets
Ethereum
https://ethereum.org/en/what‐is‐ethereum/
Ethereum Network
• No central server
https://ethstats.net/
https://www.ethernodes.org/countries
Interacting with an Ethereum Network
Interacting with an Ethereum Network
Mainnet / Testnet
Go Ethereum (Geth)
• Official Go implementation of the Ethereum protocol
• Main Ethereum CLI client
• Entry point into the Ethereum network
• main, test, or private net
• Capable of running as:
• Full node (default)
• Archive node (retaining all historical state)
• Light node (retrieving data live).
• Provides JSON RPC endpoints exposed on top of HTTP,
WebSocket and/or IPC transports.
Installing Geth
For Ubuntu
COMMANDS:
list Print summary of existing accounts
new Create a new account
update Update an existing account
import Import a private key into a new account
Create an account
geth account new
List Accounts
geth account list
JSON Payload:
{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": [
"0x9808f22453Ee87cc23eA76ca7Ed66a4F294d54D4",
"latest"
],
"id": 1
}
Query using curl
Querying the balance of an account:
POST request using curl:
• Ethereum
• Permissionless, smart contract support
• Go ethereum
• Main network, test networks
• Accounts
• Gas
• Faucet
Query Balance
Ensure Geth is running.
JSON Payload:
{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": [
"0x9808f22453Ee87cc23eA76ca7Ed66a4F294d54D4",
"latest"
],
"id": 1
}
Query Balance
Querying the balance of an account:
POST request using curl:
Requires:
1. Access to account private key
2. Gas
Gas
• Goerli faucet:
• Social faucet: https://faucet.goerli.mudit.blog/
• Simple faucet: https://goerli-faucet.slock.it/
Parameters
Object - The transaction object
from: DATA, 20 Bytes - The address the transaction is send from.
to: DATA, 20 Bytes -The address the transaction is directed to.
gas: QUANTITY - (optional, default: 90000) Integer of the gas provided for the transaction execution. It
will return unused gas.
gasPrice: QUANTITY - (optional, default: To-Be-Determined) The gasPrice used for each paid gas
value: QUANTITY - (optional) Integer of the value sent with this transaction
data: DATA - The compiled code of a contract OR the hash of the invoked method signature and
encoded parameters. For details see Ethereum Contract ABI
nonce: QUANTITY - (optional) Integer of a nonce. This allows to overwrite your own pending
transactions that use the same nonce.
Returns
DATA, 32 Bytes - the transaction hash, or the zero hash if the transaction is not yet available.
Prepare Transaction
{
"jsonrpc": "2.0",
"method": "eth_sendTransaction",
"params": [
{
"from": "0xd84a0607843b28c3f468857f82f784d9ff743bf8",
"to": "0x5f2316ff45c1c782e027b548f6f6e604655148f1",
"value": "0x2386F26FC10000"
}
],
"id": 0
} 0.1 eth
Submit Transaction
curl -X POST http://localhost:8545 \
-H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0", "method":"eth_sendTransaction", "params":[{"from":
"0xd84a0607843b28c3f468857f82f784d9ff743bf8","to":
"0x5f2316ff45c1c782e027b548f6f6e604655148f1","value": "0x2386F26FC10000"}],
"id":0}'
View Transaction on Etherscan
https://goerli.etherscan.io/
Get Transaction by Hash
{
"jsonrpc": "2.0",
"method": "eth_getTransactionByHash",
"params": [
"0x576f04f98e8eb109e018d0727a69c9ebde64028491b4d17ddb
c01af6cfa24a65"
],
"id": 1
}
Get Transaction by Hash
curl -X POST http://localhost:8545 \
-H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0", "method":"eth_getTransactionByHash",
"params":["0x576f04f98e8eb109e018d0727a69c9ebde64028491b4d17ddbc01af6cfa24a65"],
"id":1}'
Query Blocks
{
"jsonrpc": "2.0",
"method": "eth_getBlockByNumber",
"params": [
"0x5828AD",
true
],
"id": 1
}
https://playground.open-rpc.org/?schemaUrl=https://raw.githubusercontent.com/ethereum/eth1.0-
apis/assembled-spec/openrpc.json
Conclusion
• Ethereum Transactions
• Obtaining Ether for testnets
• Unlocking Account
• Submit Transactions and monitor transactions
Blockchain and its applications
Bishakh Chandra Ghosh
• DAPPS
DAPPS in Ethereum
• DAPP - decentralized application
Smart Contracts
• Application that is built for decentralized
networks like Ethereum
1. Smart Contracts
2. User interface for executing
transactions and contracts
Programmatically access Ethereum networks
DAPP UI
Mainnet / Testnet
web3.js
• Ethereum JavaScript API
https://web3js.readthedocs.io/
DAPP UI
• Collection of libraries that allow you to
interact with a local or remote ethereum Web3.js
nodes. • HTTP
• IPC
• WebSocket
• It can connect using:
Geth
• HTTP
• IPC
• WebSocket
Install web3.js
• Install Node.js
https://nodejs.org/en/
wget https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-x64.tar.xz
export PATH=/home/<username>/nptel/node-v16.13.0-linux-x64/bin:$PATH
npm --version
Install web3.js
• Install web3.js
npm install web3
// Import web3
var Web3 = require('web3');
// Prepare transaction
var transaction = {
from: "0x7dad3a076678a05b2b4e2b93206dbecef0d7bbf0",
to: "0x35F18427567108F800BDC2784277B9246eED37fA",
value: Web3.utils.numberToHex(10000000000000000)
}
• Solidity language
• EVM
• Solidity
Smart Contracts
• Program that is executed in a
decentralized setting.
• Transactions deterministically
change the machine from one
state to another.
Compiler
Deploy
Bytecode Smart Contract
Compiler
• Solidity
• Vyper
Application Binary
Interface (ABI) Web3.js
https://vyper.readthedocs.io/en/stable/
https://docs.soliditylang.org/en/v0.8.9/
Solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.16 <0.9.0;
• High-level language for implementing
smart contracts contract SimpleStorage {
uint storedData;
• Statically typed
• Supports inheritance function set(uint x) public {
storedData = x;
• Libraries }
• Complex user-defined types
function get() public view returns (uint) {
return storedData;
• Syntax influenced by Javascript and C++ }
https://docs.soliditylang.org/en/v0.8.9/
Compiling Solidity
• solc compiler • Remix editor
• Compile .sol files to bytecode • Browser based
• Command line tool • Compile, emulate, deploy contracts
• https://remix.ethereum.org/
https://docs.soliditylang.org/en/v0.8.9/installing-solidity.html#installing-solidity
Simple Storage Contract
// SPDX-License-Identifier: GPL-3.0
contract Storage {
uint256 positivenumber;
}
Executing with Web3
var Web3 = require('web3');
var Contract = require('web3-eth-contract');
Contract.setProvider(new Web3.providers.HttpProvider('http://localhost:8545'));
"0xb3f36458FFc0C686DB4f2FF6002a55bFD85C03C8",
{
from: "0xd84a0607843b28c3f468857f82f784d9ff743bf8",
gasPrice: "20000000000"
}
);
Read data
Executing with Web3
var Web3 = require('web3');
var Contract = require('web3-eth-contract');
Contract.setProvider(new Web3.providers.HttpProvider('http://localhost:8545'));
"0xb3f36458FFc0C686DB4f2FF6002a55bFD85C03C8",
{
from: "0xd84a0607843b28c3f468857f82f784d9ff743bf8",
gasPrice: "20000000000"
}
);
Write data
Conclusion
• Remix editor
S1:
while (moreGoods == 1)
DeliverGoods();
S2:
if (allOrderComplete == 0) goto S1;
else {
S3:
printf("Goods transfer complete");
}
State Machine Replication Replicate the state machine
on multiple independent
servers
State Machine Replication T1:
I have delivered 100kg
potatoes
T1
State Machine Replication
T1
T2:
I have delivered
50kg tomatoes
T2
State Machine Replication
T1
T2
State Machine Replication
T1
Consensus on the
Ordering of the
transactions
T2
State Machine Replication T1
T2
T1 T1
T2 T2
State Machine Replication T1
T2
T1 Independently T1
T2 execute the T2
transactions
on the state
machine
State Machine Replication T1
T2
T1 Independently T1
T2 execute the T2
transactions
on the state
machine
State Machine Replication
S2
S2
Consensus on the
Final State
S2
State Machine Replication
S2
S2
S2
Importance of Consensus
S2
S3
S2
Importance of Consensus
S2
Majority Voting – S3
Agree on S2
S2
Conclusion
• Consensus is still required within a closed environment
• Paxos
State Machine Replication as Consensus
• CFT Consensus
• Paxos (Proposed by Lamport, the most fundamental CFT) --
used in DynamoDB
• RAFT (Much simpler than Paxos) -- Used in Fabric Transaction
Ordering
CFT Consensus
We'll see how Paxos works
• CFT Consensus
• Paxos (Proposed by Lamport, the most fundamental CFT) --
used in DynamoDB
• RAFT (Much simpler than Paxos) -- Used in Fabric Transaction
Ordering
CFT in a Synchronous System
CFT in a Synchronous System
Let's go for
a dinner
CFT in a Synchronous System
Let's go for
a dinner
Perfect!
I'm in ...
Let's go ...
CFT in a Synchronous System
Let's go for
a dinner Majority agreed …
Perfect!
Perfect consensus
I'm in ...
Let's go ...
CFT in an Asynchronous System
Let's go for
a dinner
CFT in an Asynchronous System
Let's go for
a dinner
I'm in
CFT in an Asynchronous System
Let's go for
a dinner
I'm in
I'm okay
CFT in an Asynchronous System
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
CFT in an Asynchronous System
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
prefer movie
CFT in an Asynchronous System
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
CFT in an Asynchronous System
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
CFT in an Asynchronous System
Let's go for
a dinner Consensus on a
I'm in Movie
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
CFT in an Asynchronous System
Nopes ! We decided
for a movie!
CFT in an Asynchronous System
Nopes ! We decided
for a movie!
Umm! May
not like, but that's
the only option for
me :(
CFT in an Asynchronous System
How many
We are going for people can be
dinner, right?
sleeping at a time?
Nopes ! We decided
for a movie!
Umm! May
not like, but that's
the only option for
me :(
CFT in an Asynchronous System
Nopes ! We decided
for a movie!
2
Umm! May
not like, but that's
the only option for
me :(
Asynchronous CFT
• If there are F faulty nodes (crash fault), we need atleast 2F+1
nodes to reach consensus
• CFT
Paxos – The Roles of Individuals
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Paxos – The Roles of Individuals
Proposer Proposer
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Paxos – The Roles of Individuals
Acceptor Proposer Acceptor Acceptor Proposer
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Acceptor Acceptor
Acceptor Proposer Acceptor Acceptor Proposer
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Learner Learner
Learner Acceptor Learner Learner Acceptor
Acceptor Proposer Acceptor Acceptor Proposer
Let's go for
a dinner
I'm in
Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Learner Learner
Learner Acceptor Learner Learner Acceptor
Acceptor Proposer Acceptor Acceptor Proposer
Let's go for
a dinner
I'm in
A node can have any or all of
the three roles Can we go
I'm okay for a movie?
I would
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Learner Learner
Learner Acceptor Learner Learner Acceptor
Acceptor Proposer Acceptor Acceptor Proposer
Let's go for
a dinner
A node can have any or all of the three roles
I'm in
However, the nodes must knowCan howwe go
I'm okay for a movie?
many acceptors aI majority
would
is
Movie is a prefer movie
better idea
I'm okay with
movie too ...
Learner Learner
Learner Acceptor Learner Learner Acceptor
Acceptor Proposer Acceptor Acceptor Proposer
Let's go for
a dinner
Two majorities will always overlap in
I'm in
atleast I'm
one okay nodes Can we go
for a movie?
5 acceptors, majority = 3,I would
Movie is a 2 proposers: prefer movie
better idea
To accept based on majority voting, at least one acceptor
I'm okay with
movie need
too ... to choose between one of the two proposals
Paxos Basics
Acceptor
Acceptor
Acceptor
Paxos Algorithm
Proposer
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
Acceptor
PROMISE 100
Acceptor
Acceptor
Acceptor
PROMISE 100
Acceptor
Acceptor
Acceptor
PROMISE 100
Acceptor
Acceptor
Acceptor
PROMISE 100
Acceptor
Acceptor
Acceptor
PROMISE 100 ACCEPT 100, "Dinner"
Acceptor
Acceptor
Acceptor
PROMISE 100 ACCEPT 100, "Dinner"
Acceptor
Acceptor
Acceptor
ACCEPT 100, "Dinner"
Paxos – Multiple Proposers
PREPARE 150
Proposer Proposer
PROMISE 150,
accepted 100,
Acceptor "Dinner"
Acceptor
Acceptor
ACCEPT 100, "Dinner"
• Acceptor received a PREPARE message with IDp:
• Did it promised to ignore requests with this IDp?
• YES: Ignore
• NO: Will promise to ignore any request lower than IDp
• Has it ever accepted anything? (Assume accepted ID = IDa)
• YES: Reply with PROMISE IDp accepted IDa, VALUE
• NO: Reply with PROMISE IDp
Paxos – Multiple Proposers
PREPARE 150
Proposer Proposer
PROMISE 150,
accepted 100,
Acceptor "Dinner"
Acceptor
Acceptor
ACCEPT 100, "Dinner"
• Leader Election
• Multi-Paxos
Paxos – Message Exchanges
PREPARE 100 ACCEPT-REQUEST 100, "Dinner"
Proposer
Learner
Acceptor
Acceptor
Acceptor
PROMISE 100 ACCEPT 100, "Dinner"
Proposer 2
Acceptor 1
Acceptor 2
Acceptor 3
Majority Voting
Proposer 1
PREPARE 100
Proposer 2
Acceptor 1
PROMISE 100
Acceptor 2
Acceptor 3
Majority Voting
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100
Acceptor 2
Acceptor 3
Majority Voting
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100
Acceptor 2
PROMISE 100
Acceptor 3
Majority Voting
If the majority of the acceptors
PREPARE 100
Proposer 1 promised on ID100, ID50 cannot
PREPARE 50 get through (those acceptors will
Proposer 2
ignore)
Acceptor 1
PROMISE 100
Acceptor 2
PROMISE 100
Acceptor 3
Majority Voting
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 ignore
Acceptor 3
Majority Voting
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 ignore
Acceptor 3
Majority Voting
Proposer 1
PREPARE 100 Not a majority
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 ignore
Acceptor 3
PROMISE 50
Majority Voting
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 ignore
Acceptor 3
PROMISE 50 PROMISE 100
Majority Voting – Case 2
Proposer 1
PREPARE 100
Proposer 2
Acceptor 1
PROMISE 100
Acceptor 2
Acceptor 3
Majority Voting – Case 2
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
Acceptor 3
Majority Voting – Case 2
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 50
Acceptor 3
Majority Voting – Case 2
PREPARE 100 Becomes the
Proposer 1
majority
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 50
Acceptor 3
PROMISE 50
Majority Voting – Case 2
Proposer 1
PREPARE 100
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 50
Acceptor 3
PROMISE 50
Majority Voting – Case 2
Proposer 1
PREPARE 100
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 50 PROMISE 100
Acceptor 3
PROMISE 50
Majority Voting – Case 2
Proposer 1
PREPARE 100
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 50 PROMISE 100
Acceptor 3
PROMISE 50 PROMISE 100
Majority Voting – Case 2
Proposer 1
PREPARE 100
Acceptor 1
PROMISE 100 ignore ignore
ignore
Acceptor 2
PROMISE 50 PROMISE 100 ignore
Acceptor 3
PROMISE 50 PROMISE 100
Majority Voting – Case 2 100 Becomes the
majority
Proposer 1
PREPARE 100
Acceptor 1
PROMISE 100 ignore ignore
ignore
Acceptor 2
PROMISE 50 PROMISE 100 ignore
Acceptor 3
PROMISE 50 PROMISE 100
Liveness
Proposer 1
PREPARE 100
Proposer 2
Acceptor 1
Acceptor 2
Acceptor 3
Liveness
Proposer 1
PREPARE 100
Proposer 2
Acceptor 1
PROMISE 100
Acceptor 2
PROMISE 100
Acceptor 3
Liveness
Proposer 1
PREPARE 100
PREPARE 150
Proposer 2
Acceptor 1
PROMISE 100
Acceptor 2
PROMISE 100
Acceptor 3
Liveness
Proposer 1
PREPARE 100
PREPARE 150
Proposer 2
Acceptor 1
PROMISE 100 PROMISE 150
Acceptor 2
PROMISE 100 PROMISE 150
Acceptor 3
Liveness
PREPARE 100 ACCEPT-REQUEST 100, "Dinner"
Proposer 1
PREPARE 150
Proposer 2
Acceptor 1
PROMISE 100 PROMISE 150
Acceptor 2
PROMISE 100 PROMISE 150
Acceptor 3
Liveness
PREPARE 100 ACCEPT-REQUEST 100, "Dinner"
Proposer 1
PREPARE 150
Proposer 2
ignore
Acceptor 1
PROMISE 100 PROMISE 150
ignore
Acceptor 2
PROMISE 100 PROMISE 150
Acceptor 3
Liveness
PREPARE 100 ACCEPT-REQUEST 100, "Dinner" PREPARE 200
Proposer 1
PREPARE 150
Proposer 2
ignore
Acceptor 1
PROMISE 100 PROMISE 150
ignore
Acceptor 2
PROMISE 100 PROMISE 150
Acceptor 3
Liveness
PREPARE 100 ACCEPT-REQUEST 100, "Dinner" PREPARE 200
Proposer 1
PREPARE 150
Proposer 2
ignore
Acceptor 1
PROMISE 100 PROMISE 150 PROMISE 200
ignore
Acceptor 2
PROMISE 100 PROMISE 150 PROMISE 200
Acceptor 3
Liveness
PREPARE 100 ACCEPT-REQUEST 100, "Dinner" PREPARE 200
Proposer 1 There is no termination guarantee
PREPARE 150 on Paxos
Proposer 2
ignore
Acceptor 1
PROMISE 100 PROMISE 150 PROMISE 200
ignore
Acceptor 2
PROMISE 100 PROMISE 150 PROMISE 200
Acceptor 3
Majority of Accepts
• Majority of acceptors accept a request with an ID and a
value
• Consensus has been reached
• The consensus is on the value
Acceptor
Acceptor
Acceptor
PROMISE 100 ACCEPT 100, "Leader"
Multi-Paxos
• Applications often needs a continuous stream of agreed
values
• Commit the transactions in a replicated database – each
transaction needs a consensus to be agreed upon by the
replicas
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 PROMISE 50
Acceptor 3
Blockchain and its applications
Prof. Sandip Chakraborty
• BFT Agreement
Malicious Behavior on Paxos
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 PROMISE 50
Acceptor 3
Malicious Behavior on Paxos
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 PROMISE 50
Acceptor 3
PROMISE 50
Malicious Behavior on100Paxos
is the
majority
Proposer 1
PREPARE 100
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 PROMISE 50
Acceptor 3
PROMISE 50
Malicious Behavior on100Paxos
is the
majority
50 is the
Proposer 1
PREPARE 100 majority
PREPARE 50
Proposer 2
Acceptor 1
PROMISE 100 ignore
Acceptor 2
PROMISE 100 PROMISE 50
Acceptor 3
PROMISE 50
Malicious Behavior on Paxos
Proposer 1
A-R 100, "Dinner"
Acceptor 1
ACCEPT 100, ignore
"Dinner"
Acceptor 2
ACCEPT 100, ACCEPT 50,
"Dinner" "Movie"
Acceptor 3
ACCEPT 50,
"Movie"
We agreed
Malicious Behavior on Paxos
for Dinner
Proposer 1
A-R 100, "Dinner"
Acceptor 1
ACCEPT 100, ignore
"Dinner"
Acceptor 2
ACCEPT 100, ACCEPT 50,
"Dinner" "Movie"
Acceptor 3
ACCEPT 50,
"Movie"
We agreed
Malicious Behavior on Paxos
for Dinner No, we
A-R 100, "Dinner" agreed for
Proposer 1
Movie
A-R 50, "Movie"
Proposer 2
Lieutenant - 1
Commander
Lieutenant - 2
Byzantine Generals Problem
Attack
Lieutenant - 1
Commander
Lieutenant - 2
Attack
Byzantine Generals Problem
Faulty Attack
Commander
Lieutenant - 1
Commander
Lieutenant - 2
Retreat
Byzantine Generals Problem We need a consensus
mechanism to decide
who is faulty
Faulty Attack
Commander
Lieutenant - 1
Commander
Lieutenant - 2
Retreat
Byzantine Generals Problem
Faulty Attack
Commander
Lieutenant - 1
Attack
Commander
Lieutenant - 2
Retreat
Byzantine Generals Problem
Faulty Attack
Commander
Lieutenant - 1
Attack Retreat
Commander
Lieutenant - 2
Retreat
Byzantine Generals Problem
Can we reach
consensus?
Faulty Attack
Commander
Lieutenant - 1
Attack Retreat
Commander
Lieutenant - 2
Retreat
Byzantine Generals Problem
Good Attack
Commander
Lieutenant - 1
Commander
Attack Lieutenant - 2
Byzantine Generals Problem
Good Attack
Commander
Lieutenant - 1
Attack Retreat
Commander
Attack Lieutenant - 2
Faulty
Lieutenant
Byzantine Generals Problem
Good Attack
Commander
Lieutenant - 1
Consensus is NOT POSSIBLE with one
commander and two lieutenants,
when one is faulty Attack Retreat
Commander
Attack Lieutenant - 2
Faulty
Lieutenant
Byzantine Generals Problem – Case 2
Faulty
Commander Attack
Attack
Retreat
Byzantine Generals Problem – Case 2
Faulty
Commander Attack
Attack
Retreat
Retreat
Retreat
Byzantine Generals Problem – Case 2
Faulty
Commander Attack
Attack Attack
Attack
Retreat
Attack
Retreat
Retreat
Attack
Byzantine Generals Problem – Case 2
Faulty Attack: 2
Commander Attack Retreat: 1
Attack Attack
Attack
Retreat
Attack
Retreat
Retreat
Attack: 2 Attack: 2
Attack
Retreat: 1 Retreat: 1
Byzantine Generals Problem – Case 2
Faulty Attack: 2
Commander Attack Retreat: 1
Attack Attack
Consensus is reached !Attack
Retreat
Attack
Retreat
Retreat
Attack: 2 Attack: 2
Attack
Retreat: 1 Retreat: 1
Byzantine Generals Problem – Case 2
Good
Commander Attack
Attack
Attack
Byzantine Generals Problem – Case 2
Good
Commander Attack
Attack
Attack
Retreat
Faulty Attack
Lieutenant
Byzantine Generals Problem – Case 2
Good
Commander Attack
Attack Attack
Attack
Attack
Attack
Retreat
Faulty
Commander
Attack
Attack
Byzantine Generals Problem – Case 2
Good Attack: 2
Commander Attack Retreat: 1
Attack Attack
Attack
Attack
Attack
Retreat
Faulty
Commander
Attack
Attack: 3 Attack: 3
Attack
Retreat: 0 Retreat: 0
Byzantine Generals Problem – Case 2
Good Attack: 2
Commander Attack Retreat: 1
Attack Attack
Consensus is reached !Attack
Attack
Attack
Retreat
Faulty
Commander
Attack
Attack: 3 Attack: 3
Attack
Retreat: 0 Retreat: 0
Asynchronous Byzantine Agreement
• F faulty nodes – need 3F + 1 nodes to reach consensus
Asynchronous Byzantine Agreement
• F faulty nodes – need 3F + 1 nodes to reach consensus
• Faulty nodes create partition in the network
Asynchronous Byzantine Agreement
• F faulty nodes – need 3F + 1 nodes to reach consensus
• Faulty nodes create partition in the network
3F
Asynchronous Byzantine Agreement
• F faulty nodes – need 3F + 1 nodes to reach consensus
• Faulty nodes create partition in the network
F F F
Asynchronous Byzantine Agreement
• F faulty nodes – need 3F + 1 nodes to reach consensus
• Faulty nodes create partition in the network
F F F
PL PF PR
Asynchronous Byzantine Agreement
• F faulty nodes – need 3F + 1 nodes to reach consensus
• Faulty nodes create partition in the network
F F F
0 1
0 1
PL PF PR
Asynchronous Byzantine Agreement
Either PL or PR
• F faulty nodes – need 3F + 1 nodes to reach consensus must break the
• Faulty nodes create partition in the network tie
F F F
0 1
0 1
PL PF PR
Asynchronous Byzantine Agreement
Put
• F faulty nodes – need 3F + 1 nodes to reach consensus one additional
• Faulty nodes create partition in the network node to PL / PR
F F F
0 1
0 1
PL PF PR
Asynchronous Byzantine Agreement
Put
• F faulty nodes – need 3F + 1 nodes to reach consensus one additional
• Faulty nodes create partition in the network node to PL / PR
F+1 F F
0 1
Breaks the
tie to
reach 0 1
consensus
PL PF PR
Conclusion
• Paxos does not work with Byzantine faults
• Much harder to solve than crash faults
• Quorum in PBFT
BFT Consensus
• Lamport-Shostak-Peas Algorithm*
• Synchronous environment
• Reliable communication channel
• Fully Connected Network
• Receivers always know the identity of the Senders
Backups
PBFT – Broad Idea
Request
Client Primary
Request
Request Request
Request Request
Backups
PBFT – Broad Idea
Request Client waits for 2F+1 replies,
Client Primary where F is the maximum
number of faulty nodes
Reply
Reply
Reply
Backups
PBFT – The Algorithm
Request
C
R1
R2
R3
R1
R2
R3
R1
R2
R3
• Primary assigns a sequence number n to the Request (or a set of
Requests) and multicast a message <<PRE-PREPARE, v, n, d>β_p, m> to
all the backups
PBFT – The Algorithm
C
Pre-prepare
P
R1
R2
R3
• Pre-prepare works as a proof that the Request was assigned a
sequence number n for the view v
Accepting Pre-Prepare
• A backup accepts the Pre-prepare message, if
• The signature is correct and d is the digest of the
message m
• The backup is in view v
• It has not received a different Pre-Prepare message with
sequence n and view v with a different message digest
• The sequence number is within a threshold (the message
is not too old – prevents a reply attack)
PBFT – The Algorithm
C
P
Prepare
R1
R2
R3
• The correct backups send a Prepare message to all other backups
including the primary – works as proof that the backups agree on the
message with the sequence number n under view v
PBFT – The Algorithm
C
P
Prepare
R1
R2
R3
• Message format for backup k : <PREPARE, v, n, d, k>β_k
Accepting Prepare Message
• Primary and backups accepts the Prepare message, if
• The signatures are correct
• View number is equal to the current view
• Sequence number is within a threshold (note that
messages may be received out of order – so a backup
may receive the Prepare message before the
corresponding Pre-prepare message – so it needs to keep
track of all the messages received)
Three Phase Commit
• Pre-prepare and Prepare ensure that non-faulty replicas
guarantee on a total order for the requests within a view
Three Phase Commit
• Pre-prepare and Prepare ensure that non-faulty replicas
guarantee on a total order for the requests within a view
R1
R2
R3
• Message format for replica k : <COMMIT, v, n, d, k>β_k
PBFT – The Algorithm
Reply
C
R1
R2
R3
• The protocol is committed for a replica when
• It has sent the Commit message
• It has received 2f Commit messages from other replicas
Conclusion
• PBFT works with 3f+1 replicas over 2f+1 quorum
R1
R2
R3
Safety in PBFT
• Unlike multiple Paxos proposers, PBFT works with a single
Primary
• Ping-pong does not arise from the proposals from
multiple replicas
• However, a replica needs to wait for 2f + 1 votes (Prepare
and Commit messages)
Safety in PBFT
• PBFT is safe with 2f+1 quorum
• The leader can always have the majority votes to support
its proposal
• The leader can reach to the consensus even when it does not
receive messages from some of the replicas due to
asynchronous nature of the channel
Liveness in PBFT
• However, a primary may fail – the liveness gets hampered as
the protocol cannot progress any further
• Primary failure cannot be handled in a pure
asynchronous system – you do not know whether it is a
message delay from the primary, or a primary failure
Weak Synchrony Assumption
• Weak Synchrony:
• (1) Both sender and the receiver is correct,
• (2) Sender keeps retransmitting the messages until it is
received,
• (3) There is an asymptotic upper bound on the message
transmission delay
The View Change Protocol
• What if the primary is faulty ?
• Non-faulty replicas detect the fault
• Replicas together start view change operation
R1
P(v+1)
R3
R4
Multicast the View Change message <VIEW-CHANGE, v+1, n, C, P, k>β_k
• n is the sequence number of last stable checkpoint s known to k
• C is a set of 2f + 1 valid checkpoint messages corresponding to s
• P is a set containing a set Pm for each request m that prepared
at k with a sequence number higher than n
The View Change Protocol
R1
View-Change
p(v)
R1
P(v+1)
R3
R4
• The new view is initiated after receiving 2f + 1 View Change messages
• Next primary selection
• Round Robin (Hyperledger Sawtooth)
• Leader election (Hyperledger Fabric)
The View Change Protocol
View-Change View-Change ACK New-View
R1
p(v)
R1
P(v+1)
R3
R4
• Replicas send a View Change ACK – quorum is formed on these
messages
• New View message to initiate a new view
Conclusion
• PBFT is safe under 2f+1 quorum over an asynchronous
environment
• Hyperldger Fabric
Blockchain – The Application Space
Auditor’s
records
Enables
ReducesRisk NewBusiness
ReducesTime Removes Cost
Models
Figure source: “Distributed Ledger Technology: Beyond Blockchain”, A report by UK Govt Chief Scientific Adviser
Permissionless vs Permissioned Blockchains
Permissionless Permissioned
Access Open read/write access to Permissioned read/write access to
database database
Scale Scale to a large number of Scale in terms of transaction
nodes, but not in transaction throughput, but not to a large
throughput number of nodes
Consensus Proof of work/ proof of stake Closed membership consensus
algorithms
Identity Anonymous/pseudonymous Identities of nodes are known, but
transaction identities can be
private/anonymous/pseudonymous
Asset Native assets Any asset/data/state
The Linux Foundation Hyperledger Project
A collaborative effort created to advance blockchain technology by identifying and addressing important
features for a cross-industry open standard for distributed ledgers that can transform the way business
transactions are conducted globally.
https://www.hyperledger.org/
Hyperledger Members
https://www.hyperledger.org/about/members
Premier General (Partial list)
• Fabric Installation
• Hyperledger
• Fabric
• Permissioned Network
Hyperledger Foundation
https://www.hyperledger.org/
• Open source community - focused on
enterprise-grade blockchain deployments.
https://hyperledger-fabric.readthedocs.io/
Install Hyperledger Fabric - Prerequisites
Install Prerequisites
• Git
• https://git-scm.com/downloads
• cURL
• https://curl.se/download.html
• Docker (Docker version 17.06.2-ce or greater is required)
• https://docs.docker.com/engine/install/
• Go
• https://golang.org/doc/install
• Docker Compose (Docker Compose version 1.14.0 or greater installed)
• https://docs.docker.com/compose/install/
https://hyperledger-fabric.readthedocs.io/en/release-2.2/prereqs.html
Install Hyperledger Fabric - Prerequisites
Install Prerequisites
• Git
• sudo apt install git
• cURL
• sudo apt install curl
• Go
• wget https://golang.org/dl/go1.17.3.linux-amd64.tar.gz
• sudo rm -rf /usr/local/go
• sudo tar -C /usr/local -xzvf go1.17.3.linux-amd64.tar.gz
https://hyperledger-fabric.readthedocs.io/en/release-2.2/prereqs.html
Install Hyperledger Fabric - Prerequisites
Install Prerequisites
Docker
sudo apt install ca-certificates gnupg lsb-release
Docker Compose
sudo curl -L
"https://github.com/docker/compose/releases/download/1.29.2/docker-
compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
https://hyperledger-fabric.readthedocs.io/en/release-2.2/prereqs.html
Install Hyperledger Fabric 2.2
Install Samples, Binaries, and Docker images
Determine a location on your machine where you want to place the fabric-samples repository and enter that directory
in a terminal window.
mkdir fabric
cd fabric
curl -sSL https://bit.ly/2ysbOFE | bash -s -- <fabric_version> <fabric-ca_version>
Example:
curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.2.4 1.5.2
https://hyperledger-fabric.readthedocs.io/en/release-2.2/prereqs.html
Conclusion
• Hyperledger Foundation
• Sample Chaincode
• Chaincode Transactions
Fabric Architecture
A
0 1 2 3
O2
Ledger
Blockchain WorldState O3
Orderer
Fabric Test Network
• Real network consists of multiple organizations. Each maintain
their own set of:
• Peers
• Client Applications
• Optionally Orderers
• MSP
• Test Network:
• All organizations in a single system
• Development and testing purposes
• 2 Orgs, each having 1 peer and optionally one CA
• 1 orderer
• All components are containerized
Start Test Network
Navigate to the directory where you have installed fabric samples.
cd fabric-samples
cd test-network
./network.sh up
Monitor Containers
docker ps
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export
CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.exa
mple.com/peers/peer0.org1.example.com/tls/ca.crt
export
CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.exampl
e.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:7051
Invoke Chaincode
peer chaincode invoke -o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls --cafile
${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp
/tlscacerts/tlsca.example.com-cert.pem \
-C mychannel \
-n basic \
--peerAddresses localhost:7051 \
--tlsRootCertFiles
${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/t
ls/ca.crt \
--peerAddresses localhost:9051 \
--tlsRootCertFiles
${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/t
ls/ca.crt -c '{"function":"InitLedger","Args":[]}'
Invoke Chaincode
Query Chaincode
peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'
Conclusion
• Chaincode
• Fabric Transactions
Fabric Smart Contracts
• Defines common data, rules and processes for businesses to transact
through the ledger.
• Smart contracts are packaged as chaincodes.
https://hyperledger-fabric.readthedocs.io/en/release-2.2/smartcontract/smartcontract.html
Fabric Transaction Flow
https://hyperledger-fabric.readthedocs.io/en/release-2.2/txflow.html
Writing Fabric Chaincode
• Written in Go, Node.js, or Java.
• Go: https://pkg.go.dev/github.com/hyperledger/fabric-contract-api-go/contractapi
• Node.js: https://hyperledger.github.io/fabric-chaincode-node/release-2.2/api/
• Java: https://hyperledger.github.io/fabric-chaincode-java/release-
2.2/api/org/hyperledger/fabric/contract/package-summary.html
Define SmartContract
package main
import (
"fmt"
"github.com/hyperledger/fabric-contract-api-go/contractapi"
)
if err != nil {
return fmt.Errorf("Failed to put to world state. %s", err.Error())
}
return nil
}
GetState and PutState
// CreateKey
func (s *SmartContract) CreateKey(ctx contractapi.TransactionContextInterface, key string, val string) error
{
return ctx.GetStub().PutState(key, []byte(val))
}
// QueryKey
func (s *SmartContract) QueryKey(ctx contractapi.TransactionContextInterface, key string) (string,error) {
val, err := ctx.GetStub().GetState(key)
if err != nil {
return "", fmt.Errorf("Failed to get from world state. %s", err.Error())
}
if err != nil {
fmt.Printf("Error creating chaincode: %s", err.Error())
return
}
err = chaincode.Start();
if err != nil {
fmt.Printf("Error starting chaincode: %s", err.Error())
}
}
Conclusion
• Fabric CAs
• Fabric CA
• DAPP
Fabric Application
A
0 1 2 3
O2
Ledger
Blockchain WorldState O3
Orderer
Fabric Application
https://hyperledger-fabric.readthedocs.io/en/release-2.2/write_first_app.html
Prerequisites
https://hyperledger-fabric.readthedocs.io/en/release-2.2/getting_started.html#hyperledger-fabric-application-sdks
Imports
const FabricCAServices = require('fabric-ca-client')
const {Wallets, Gateway} = require('fabric-network')
const fs = require('fs')
const path = require('path')
main()
https://hyperledger-fabric.readthedocs.io/en/release-2.2/getting_started.html#hyperledger-fabric-application-sdks
Connection Profile and CA
// Org1 connection profile
const ccpPath = path.resolve('../organizations/peerOrganizations/org1.example.com/connection-org1.json')
const ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'))
// Org1 Ca
const caInfo = ccp.certificateAuthorities['ca.org1.example.com']
const caTLSCACerts = caInfo.tlsCACerts.pem
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName)
Connection Profile and CA
// Org1 connection profile
const ccpPath = path.resolve('../organizations/peerOrganizations/org1.example.com/connection-org1.json')
const ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'))
// Org1 Ca
const caInfo = ccp.certificateAuthorities['ca.org1.example.com']
const caTLSCACerts = caInfo.tlsCACerts.pem
const ca = new FabricCAServices(caInfo.url, { trustedRoots: caTLSCACerts, verify: false }, caInfo.caName)
Configure CA admin
// Get admin identity
const x509Identity = {
credentials: {
certificate: enrollment.certificate,
privateKey: enrollment.key.toBytes(),
},
mspId: 'Org1MSP',
type: 'X.509',
};
// connect to channel
const network = await gateway.getNetwork('mychannel')
// disconnect
await gateway.disconnect()
Conclusion
• Scalability
• Consensus Finality
Blockchain Consensus Protocols
• Permissionless Blockchain
• Proof of Work (PoW)
• Proof of State (PoS)
• Proof of Burn (PoB)
• Proof of Elapsed Time (PoET)
Blockchain Consensus Protocols
• Permissioned Blockchain
• Byzantine Agreement
• PBFT
PoW vs PBFT
• PoW
• Open environment, works over a large number of nodes
• Scalable in terms of number of nodes
• Transaction throughput is low
• PBFT
• Closed, not scalable in terms of number of nodes
• High transaction throughput
PoW Scalability
• Two magic numbers in PoW
• Block frequency - 10 minutes
• Block size - 1 MB / 8MB
• For Bitcoin:
• Let's assume, block size = 1 MB.
• Average transaction size = 380.04 bytes
• Number of transactions per block = 1048576/380.04
= 2,759.12
PoW Scalability
• Two magic numbers in PoW
• Block frequency - 10 minutes
• Block size - 1 MB / 8MB
• For Bitcoin:
• With 10 minutes (600 seconds) as block mining time,
• 2759.12 transactions in 600 seconds
• 4.6 transactions per second
PoW Scalability
• Two magic numbers in PoW
• Block frequency - 10 minutes
• Block size - 1 MB / 8MB
https://towardsdatascience.com/the-blockchain-scalability-problem-the-race-for-
visa-like-transaction-speed-5cce48f9d44
Performance vs Scalability Vukolić, Marko. "The
quest for scalable
blockchain fabric: Proof-
of-work vs. BFT
replication." International
Workshop on Open
Problems in Network
Security. Springer, Cham,
2015.
PoW vs PBFT – Consensus Finality
• If a correct node p appends block b to its copy of blockchain
before appending block b’, then no correct node q appends block
b’ before b to its copy of the blockchain (Vukolic, 2015)
• Bitcoin-NG
• Transaction Serializability
• A node may hear a forked microblock but not new key block
• This can be prevented by ensuring the reception of the key
block
• When a node sees a microblock, it waits for propagation time
of the network to make sure it is not pruned by a new key
block
Bitcoin-NG Performance
Bitcoin-NG Performance
Conclusion
• A major source of latency in Bitcoin is that every block needs
to be mined by different miners
• Schnorr Multisignature
• Multisignature
Collective Signing
• Method to protect “authorities and their clients” from
undetected misuse or exploits
Use CoSi
Merging BFT Consensus with PoW
• Scalability
• number of users not clear (1M, 10M, 100M??),
high latency(~10minutes)
• Ambiguity
• fork in blockchain
Conclusion: The Blockchain Performance Triangle
Is it ever possible to
achieve all three
simultaneously?
Blockchain and its applications
Prof. Sandip Chakraborty
• BA*
The Blockchain Performance Triangle
Is it ever possible to
achieve all three
simultaneously?
Algorand: Scaling Byzantine Agreements for
Cryptocurrencies
Gilad, Y., Hemo, R., Micali, S., Vlachos, G., & Zeldovich, N.
(2017, October). Algorand: Scaling byzantine agreements for
cryptocurrencies. In Proceedings of the 26th Symposium on
Operating Systems Principles (pp. 51-68). ACM.
Algorand: Overview
• Key Idea:
• Consensus through Byzantine Agreement Protocol
• Communication:
• Gossip protocol
• Key Assumption:
• Honest majority of money
Algorand: Technical Advancement
• Trivial computation
• simple operation like add, count
• True decentralization
• no concentration of mining pool power, all equal miners
and users
• Finality of payment
• fork with very low probability, block appears, and
the payment is fixed forever
Algorand: Technical Advancement
• Scalability
• millions of users, only network latency (~1minute)
• Security
• against bad adversary
Architecture of Algorand
• Select a random user
• prepare a block
• propagate block through gossiping
• <hash,proof> ← VRFsk(x)
• x: input string
• (pki,ski): public/private key pair
• hash: hashlenbit-long value that is uniquely determined
by sk and x
• proof: enables to check that the hash indeed
corresponds to x
Committee Member Selection
• Two phase:
• Two phase agreement –
• Final Consensus
• Tentative Consensus
Byzantine Agreement in Algorand: BA*
Public Sector
Bank Services
Post Office
Identity Database
Mobile
Recordkeeping Companies for
Agency (IDP) user identity
verification
User
Decentralizing Digital Identity
• No Centralized Trusted Identity Provider / Registry
• Digital representation of physical identity
• Two major problems:
• Verifying the identity issuer
• Verifying the identity holder
https://www.w3.org/TR/did-core/
DID Architecture
https://www.w3.org/TR/did-core/
DID Architecture
1. Unique URI –
identifies a subject.
http://www.faqs.org/rfcs/rfc2396.html https://www.w3.org/TR/did-core/
DID Document
• A set of data describing the DID subject, including mechanisms such as cryptographic
public keys, that the DID subject or a DID delegate can use to authenticate itself and
prove its association with the DID.
• DID document consists of a map of entries, each entry consisting of a key/value pair.
Represent
ation-
specific
entries
include
JSON,
XML, etc
https://www.w3.org/TR/did-core/
DID Document Example (JSON)
{
"id": "did:example:123456789abcdefghi", DID for a particular DID subject
"authentication": [{
"id": "did:example:123456789abcdefghi#keys-1", Verification Method specifying
"type": "Ed25519VerificationKey2020", how the DID subject can
"controller": "did:example:123456789abcdefghi", authenticate itself.
"publicKeyMultibase":
"zH3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV
" Service Endpoint
}], denoting ways of
"service": [{ communicating with
"id":"did:example:123456789abcdefghi#linked-domain", the DID subject
"type": "LinkedDomains", // external (property value)
"serviceEndpoint": https://bar.example.com It tells how to reach the
}] subject. Otherwise,
} there is no meaningful
use of authentication
https://www.w3.org/TR/did-core/
Relationship between Different Components of DID
• A DID is an identifier
assigned by a DID controller
to refer to a DID subject and
resolve to a DID document
that describes the DID
subject.
• The DID document is an
artifact of DID resolution and
not a separate resource
distinct from the DID subject.
• DID document resides inside
verifiable data registry
Relationship between Different Components of DID
Verifiable Data
Registry -
(registry1)
DID Method
Implementation
DID Flow – DID Registration
Alice
Bob
(wants to authenticate the subject DID Method
of did:registry1:alice) Implementation
DID Method Security
• DID Registry ideally enforces DID Method
protocols.
• Centralized DID Registry brings in risks
• Manipulating DID Documents
• Changing authentication methods
• Censoring DID Documents Verifiable Data
• Refusing to resolve certain DID Registry - (registry1)
Documents DID Method Implementation
https://identity.foundation/sidetree/spec/
Binding DID to Physical Identity
DIDs only allow a DID controller to prove its control over its DID Document.
This is useful to authenticate an entity with respect to its DID
Authenticate
based on Pk Fetch DID Doc
If some physical detail is presented, then that is only self attested by the
DID controller, and not any verified information.
Binding DID to Physical Identity
DIDs only allow a DID controller to prove its control over its DID Document.
This is useful to authenticate an entity with respect to its DID
Authenticate
based on Pk Fetch DID Doc
DID are not inherently tied to any physical identity (real world identity).
Verifiable Credentials
• Verifiable Credentials Data Model – W3C Recommendation
• Digital Representation of Credentials
• Driver's licenses - assert that capability of operating a motor
vehicle
• University degrees - assert our level of education
• Government-issued passports - permit to travel between
countries
• Identity – Birth Certificate, Citizenship Certificate, etc.
• Decouples Issuer, Holder and Verifier
• Cryptographically secure
• Privacy respecting
• Machine-verifiable https://www.w3.org/TR/vc-data-model/
• Implementation of DID
• Use of blockchain for DID registry implementation
• Verifiable credentials and their relationship with DID
• Web resources as mentioned from time to time
Blockchain and its applications
Prof. Shamik Sural
Department of Computer Science & Engineering
Indian Institute of Technology Kharagpur
https://www.w3.org/TR/vc-data-model/
VC Data Model Components
Holder - possesses one or more VC and
generating verifiable presentations from them.
Example holders include students, employees,
and customers.
Alice
University
Verifiable
Data Registry
Alice 4. Alice authenticates as
2. Alice controller of
Requests Transcript VC did:registry1:alice
issued to 5. University issues Transcript VC
did:registry1:alice Holder: did:registry1:alice
Issuer: did:registry1:university
Industry
DID Method Implementation
Use of Blockchain for VCs
Hyperledger Aries is meant for creating, transmitting and storing
verifiable digital credentials
• Explained the complete workflow of VCs
• VC trust model
• Combining DID and VC
• Introduced Hyperledger Aries
• Web resources as mentioned from time to time
Blockchain and its applications
Prof. Shamik Sural
Department of Computer Science & Engineering
Indian Institute of Technology Kharagpur
• Permissionless Blockchain
• Asset Transfer
• Crypto currency driven
• Permissioned Blockchain
• Data Transfer
• Consensus-driven
Public Blockchains as Isolated Silos
1 BTC 33 ETH
Alice
Alice
Ethereum Network
Bitcoin Network
Cross Chain Asset Transfer
1 BTC 33 ETH
Bob
Alice
Ethereum Network
Bitcoin Network
1 BTC 33 ETH
Bob
Alice
Ethereum Network
Bitcoin Network
To do the transfer, Alice must use some third party who owns ≥ 33 ETH
Cross Chain Asset Transfer - TTP
1 BTC 33 ETH
Trusted
Third Party
Bob
Alice
https://bitcointalk.org/index.php?topic=576337
https://www.reuters.com/article/us-bitcoin-mtgox-wallet-idUSBREA2K05N20140321
https://www.reuters.com/article/us-bitfinex-hacked-hongkong-idUSKCN10E0KP
TTP based Asset Transfer
● Lack of security: There has been numerous cases of
theft from centralized exchanges.
● 650,000 bitcoins lost when the MtGox exchange shut
down in 2014.
● Users of the Bitfinex exchange lost approximately
120,000 bitcoins in 2016
https://bitcointalk.org/index.php?topic=576337
https://www.reuters.com/article/us-bitcoin-mtgox-wallet-idUSBREA2K05N20140321
https://www.reuters.com/article/us-bitfinex-hacked-hongkong-idUSKCN10E0KP
Asset Exchange
Bob
33 ETH
Alice Alice
Bob
1 2
Transfer in both the networks from Alice to Bob (1) and from Bob to Alice (2) must be ATOMIC
Asset Exchange - Problems
1 BTC
33 ETH 33 ETH
Alice Jack Jack Alice
2 3 Bob
(Sender) 1 (Exchanger) (Exchanger) (Sender) (Receiver)
Atomic
Hashlock and Timelock
Example:
• Alice generates a timelocked contract with 1 BTC, and
time = 2Δ ( Δ = some time unit )
Alice
1 BTC
Funding Contract - 1 BTC
Hash: ...Fa4509
Timeout: 2Δ
Timeout
Key revealed
OR
key: I love strawberries +
Signature BOB Time > 2Δ
1 BTC 1 BTC
Alice
Bob
Poon, Joseph, and Thaddeus Dryja. "The bitcoin lightning network: Scalable off-chain instant payments." (2016).
HTLC for Atomic Swap
Generate
Secret - key
Compute
Hash H
Alice H
1 BTC refunded to Alice
Challenges
● Here interoperation is specifically Verifiable Data
Transfer between two separate permissioned
blockchain networks
● Data in a blockchain network is generated by
transactions going through consensus process
● Data consistent with the source network’s state
● Multiparty Trust - When one network consumes state
from another, it needs to establish the state validity as
per shared consensus view of parties in the network
Use Case
9. Obtain Bill of Lading (Inter-Blockchain)
SELLER
7. Create Consignment
Simplified
SELLER’S BANK 5. Request Booking TradeLens
according to an data Abebe, E. et al., 2019, December. Enabling enterprise blockchain interoperability with trusted
data transfer (industry track). In Proceedings of the 20th International Middleware Conference
acceptance policy Industrial Track
Architecture
Abebe, E. et al.,
2019, December.
Enabling enterprise
blockchain
interoperability with
trusted data transfer
(industry track). In
Proceedings of the
20th International
Middleware
Conference Industrial
Track
● Relay Service: Provides the means of communication between the two separate networks
● Configuration Management Contract: Maintain identity (public keys) of the interoperating
networks
● Exposure Control Contract: Define and enforce policies on what data to expose to which network
● Data Acceptance: Validate the data received from a foreign network against the policy that defines
how many signatures are required (and other conditions) to verify a data
Protocol Overview
Steps:
1. Proof request is generated BUYER’s SELLER CARRIER
BANK
consisting of a verification
policy which has to be met
by the source network SELLER’s
BANK
2. Access control policies are
checked BUYER SELLER
proofs (endorsements)
sent back through relay
4. Proofs validated against
verification policy
Abebe, E. et al., 2019, December. Enabling enterprise blockchain interoperability with trusted
data transfer (industry track). In Proceedings of the 20th International Middleware Conference
Industrial Track
Protocol Details
Abebe, E. et al., 2019,
December. Enabling
enterprise blockchain
interoperability with
trusted data transfer
(industry track). In
Proceedings of the
20th International
Middleware
Conference Industrial
Track
• Explained how HTLC is used for three-party swap
• Permissioned blockchain interoperability
• Data transfer across different Hyperledger Fabric networks
• Web resources as mentioned from time to time
Blockchain and its applications
Bishakh Chandra Ghosh
• DIDs in Indy
• Indy
• DIDs
Hyperledger Indy
https://wiki.hyperledger.org/display/indy
Indy Key Characteristics
• Distributed ledger purpose-built for decentralized identity
• BFT by design
• DIDs that are globally unique and resolvable (via a ledger) without
requiring any centralized resolution authority
https://wiki.hyperledger.org/display/indy
Indy Overview
Indy Overview
Indy Overview
Indy Overview
Indy Projects
• Indy-Plenum:
• Implements Byzantine Fault Tolerant Protocol
• Used for consensus in Indy
• Based on RBFT
• https://github.com/Hyperledger/indy-plenum
• Indy-Node:
• Implements the blockchain with Indy-Plenum consensus
• Defines identity specific transactions.
• https://github.com/Hyperledger/indy-node
• Indy-SDK
• Provides APIs to applications for accessing Indy network
• Indy- https://github.com/Hyperledger/indy-sdk
Install Indy – Starting an Indy Pool
Clone indy-sdk
Clone indy-node
git clone https://github.com/hyperledger/indy-node.git
https://github.com/hyperledger/indy-sdk
Scenario
1 2
University Alice Company
Indy Network
DIDs, Credential Schema, Definitions, Revocation Lists
Configuring Identities in Indy
Roles:
STEWARDS
• Public permissioned network
• Only pre-approved participants, known as stewards, are permitted to participate in the validation
process.
Trust Anchor(TA)
• Link between User and Stewards.
• E.g. banks, universities, hospitals, service providers, insurance companies.
• Onboarded by approvals of Stewards.
• Accepts the request from user and forwards this request to Stewards in case of writing into the ledger.
Configuring Identities in Indy
STEP1 - Connect to Indy Pool
- Genesis txn
• Presentations
• Indy
• Verifiable Credentials
• Verifiable Presentations
Scenario
Transcript
Transcript Verifiable
Verifiable Presentation in
Credential Job Application
1 2
University Alice Company
Indy Network
DIDs, Credential Schema, Definitions, Revocation Lists
Indy Credential - Presentation Flow
STEP4 – Register Credential Schema
- Government creates transcript schema.
• Verifiable Credentials
• Verifiable Presentations
• Aries Architecture
• Aries
Hyperledger Aries
Hyperledger Aries provides a shared, reusable,
interoperable tool kit designed for initiatives
and solutions focused on creating, transmitting
and storing verifiable digital credentials.
https://www.hyperledger.org/use/aries
Aries Architecture
ACA-Py
• ACA-Py exposes a REST API to
access Aries capabilities
• Install python3-indy
• python3 -m pip install python3-indy
• Install aries-cloudagent
• python3 -m pip install aries-cloudagent
Installation
If you installed the PyPi package, the executable aca-py should be
available on your PATH.
Use the following commands to check the version, list the available modes
of operation, and see all of the command line parameters:
• aca-py --version
• aca-py --help
• aca-py provision --help
• aca-py start --help
Starting Aries Agent
Provisioning a Wallet
It is possible to provision an Indy wallet before running an agent:
aca-py provision --wallet-type indy --seed $SEED
Use the SEED to configure existing nodes in the indy pool, e.g. Stewards.
Starting Aries Agent
When starting an agent instance, at least one inbound and one outbound transport MUST
be specified.
For example:
aca-py start --inbound-transport http 0.0.0.0 8000 --outbound-transport http
More Parameters:
• Transports: inbound, outbound, endpoint • Protocol automation flags
• Logging/debugging settings • Ledger parameters (e.g. genesis URL, etc.)
• Label: self-attested agent name • Add timing information to messaging
• Wallet implementation and related info • Optional protocols to load
• For controller: Admin API configuration • From controller: Event webhook URL
• URL
• Security selection
Using Aries with Indy
aca-py start --inbound-transport http 0.0.0.0 8000 \
--outbound-transport http \
--admin-insecure-mode \
--admin 0.0.0.0 8001 \
--seed 000000000000000000000000Steward1 \
--replace-public-did \
--wallet-type indy \
--genesis-file
/home/bishakh/Documents/TA/Blockchain/indytutorial/pool1.txn \
--wallet-name agent1 \
--wallet-key agent1 \
--log-level debug \
--log-file /tmp/arieslog.txt
--admin-insecure-mode \ For experimentation and debugging
--admin 0.0.0.0 8001 \ only
Aries Admin OpenAPI Interface
Conclusion
• Aries
• Digital Credentials
Blockchain and its applications
Prof. Shamik Sural
Department of Computer Science & Engineering
Indian Institute of Technology Kharagpur
Risks
Common Risks Specific Risks
Blockchain Development,
operation mechanism deployment and
(Blockchain 1.0, 2.0) execution of
smart contract
(Blockchain 2.0)
"A Survey on the Security of Blockchain Systems", Xiaoqi Li, Peng Jiang, Ting Chen, Xiapu Luo and Qiaoyan
Wen, Future Generation Computer Systems
Risks in Blockchain
Risk
Blockchain operation Smart contract
mechanism execution
51% vulnerability Criminal smart contract
Private key security Vulnerabilities in smart contract
Criminal activity Under-optimized smart contract
Double spending Under-priced operations
Transaction privacy leakage
Common Risk: 51% Vulnerability
Hashing power
Hashing power
Common Risk: 51% Vulnerability
Coins
Coins
Common Risk: Private Key Security
Steal Alice's
private key
Alice's private key to sign the Alice's public key to verify the
Alice message message Bob
Common Risk: Criminal Activities
Valid
Chaff
Ransomware coin
coin
Money
Underground laundering
market
Common Risk: Double Spending
1. TXv is added to the wallet of the targeted vendor
Vendor
Attacker
Each transaction input explicitly Each transaction input identifies a set of coins,
identifies the coin being spent, including the real coin along with several chaff
thus forming a linkage graph coins called “mixins.”
Many mixins can be ruled out by deduction
The real input is usually the “newest” one
• Introduced the basic risk types in blockchain
• Discussed in detail some of the common risks
• Web resources as mentioned from time to time
Blockchain and its applications
Prof. Shamik Sural
Department of Computer Science & Engineering
Indian Institute of Technology Kharagpur
Others
Mining Pool
"Majority Is Not Enough: Bitcoin Mining Is Vulnerable", Ittay Eyal and Emin Guen Sirer, Financial Cryptography, 2014
Selfish Mining Attack
Others
Mining Pool
Selfish Mining Attack
Pool intentionally forking the chain for keeping
discovered blocks private
When the public branch approaches the pool’s private branch in length,
the selfish miners reveal blocks from their private chain to the public
Selfish Mining Attack
1. Any state but two branches of length 1, pools finds a block
The pool appends one block to its private branch, increasing its lead on the public branch by one
Revenue from this block will be determined later
11pub Others' public chain
10 1
0
10
10 10
11pool 12pool
11pool 11pool 12pool
Selfish Mining Attack
3. Was two branches of length 1, others find a block after pool head
The pool and the others obtain a revenue of one each - the others for the new head, the pool for its
predecessor
10 10
11pool 11pool
Selfish Mining Attack
4. Was two branches of length 1, others find a block after others’ head
10 10
11pool 11pool
Selfish Mining Attack
Both the pool and the others start mining on the new head
The others obtain a revenue of one
11pub
10
10
Selfish Mining Attack
There are two branches of length one, and the pool publishes its single secret block
The revenue from this block cannot be determined yet
11pub 11pub
10 10 10
11pool 11pool 11pool
Selfish Mining Attack
11pub 12pub
11pub
10
10
11pool 12pool 13pool
11pub 12pub
11pub 12pub
10
10
11pool 12pool 13pool
11pool 12pool 13pool
Selfish Mining Attack
8. Lead was more than 2, others win
11pub
The pool now reveals its i’th block
Pool obtains a revenue of one
10
10
10
To be victim
node
"Eclipse Attacks on Bitcoin’s Peer-to-Peer Network", Ethan Heilman, Alison Kendler, Aviv
Zohar and Sharon Goldberg, 24th USENIX Security Symposium, 2015
Eclipse Attack
Normal
Attacker
nodes
node
Victim node
Eclipse Attack
Attacker
nodes Normal
nodes
Victim node
Eclipse Attack
Victim Attacker
node node
Rest of
network
Off-path attack - attacker controls end-hosts, but not key
network infrastructure between the victim and the rest of the
bitcoin network
Eclipse Attack
40%
30% < 40% Hashing 40% >30%
power
30%
Hashing Attacker partitions miners so they can't build on each other blocks
power The attacker then outcompetes each partitioned miner
Eclipse Attack
Attacker populates the victim node's peer tables with attacker's IP addresses
Software/security updates
Packets of death/DoS attacks
Power/network failures
ISP outages
Eclipse Attack
3. Bucket eviction
The bucket is full, and an IP is inserted into it
1. Randomly selects 4 IPs
2. Delete oldest IP
3. Insert new IP
Eviction Bias: Attacker IPs will always have the most recent
timestamps
Attacker
2. Detects
Buy (1000)
Ethereum Network
Alice
"SoK: Transparent Dishonesty: Front-Running Attacks on Blockchain", Shayan
Eskandari, Seyedehmahsa Moosavi and Jeremy Clark, FC 2019 Workshops, 2020
Front-running Attack
Front-running Attack
Bulk Attacker is trying to run a large set of functions and Alice is trying
to buy a limited set of shares offered by a firm on a blockchain
Front-running Attack
Markets and Exchanges: Spotting a profitable cancellation transaction
(Unordered) mempool Reordered Block
[…] Block Height #N
Cancel (order 100) Register (Bi)
Breed (cryptokittie 1, Buy (order 100)
cryptokittie 2) Adversarial
miner Cancel (order 100)
Buy (order 101) mines a Buy (order 101)
Bid (Bj) block with
preferred Bid (Bj)
Register (Bi) order Breed (cryptokittie 1,
[…] Ethereum Network cryptokittie 2)
Front-running Attack
Users
Attacker DApps
• Described eclipse attack and front-running attack
• Importance of identifying attacks on blockchain and suggesting
remedies
• Combining multiple attacks
• Web resources as mentioned from time to time
Blockchain and its applications
Prof. Sandip Chakraborty
• Tradeoff analysis
Maintaining Land Registry Records
• Historically, land registries were paper-based
• Can be lost, destroyed, falsified, or otherwise manipulated
• Public Blockchain
• Pros: Open network, anyone can
invest or participate as a startup
• Cons: You do not know to whom you
are investing
Public or Private Blockchain
• Private Blockchain
• Pros: The identity of the participants
are known, better security (?)
• Cons: Who will validate the
authenticity? May fallback to a
centralized system
Advantages of using blockchain
• Project Ubin
• Steller Protocol and Network
• Project Ubin
Cross-Border Payments
• Classic use case for which Bitcoin was created and perhaps the
holy grail of cryptocurrencies
• To date, we have over 6000 cryptocurrencies!
• But, what qualifies as a currency. In economics, the following
criteria must be satisfied:
• Medium of exchange: Are merchants willing to accept the
currency in exchange for goods and services
• Unit of account: Is it a measure of the real value of goods and
services (e.g., would a merchant be willing to accept the same
value regardless of relative currency fluctuations)
• Store of value: A mode of investment
Steller Protocol and Network
• Decentralized, hybrid blockchain platform with open membership;
launched in 2014; Lumens as native asset
• Federated Byzantine Agreement (FBA) – quorums formed based on
participants individual trust decisions, followed by agreement within
quorums (Steller Consensus Protocol)
• 2-5 second transaction clearance
• Anchors act as bridges between a given currency and Stellar
network
• Has a distributed exchange: pay in EUR with INR balance
and network will automatically convert it at lowest rate
for you https://www.stellar.org/
Steller Protocol and Network
• The idea got published in a SOSP 2019 Paper --
• Lokhava, Marta, et al. "Fast and secure global payments with
Stellar." Proceedings of the 27th ACM Symposium on Operating
Systems Principles. 2019.
Vote y
Federated Voting in Steller
Vote x
Vote x Vote x
Vote x
Vote y
Vote y Vote y
Federated Voting in Steller
Accept x
Vote x Accept x
Accept x
Vote y
Vote y Vote y
Federated Voting in Steller
Accept x
Accept x Accept x
Accept x
Accept x
Vote y Vote y
Federated Voting in Steller
Accept x
Accept x Accept x
Accept x
Accept x
Accept x Accept x
Steller Protocol and Network
• Partially synchronous protocol
• Safety under asynchronous assumptions
• Liveness require a synchronous network
• Performance:
Ripple Protocol and Network
• Protocol for banks to clear and settle payments in real time through a
distributed network
• Consensus (XRP Ledger – XRPL -- https://xrpl.org/ ) allows payment
exchanges and remittance to happen without need for a centralized clearing
house
• Average 5 second confirmations; no mining, custom protocol that hasn’t yet
been validated for correctness and fault tolerance
• Gateway nodes convert fiat currencies to XRP (currency in Ripple)
• Market-makers convert from one currency to another
• Centralized governance, with Ripple still holding a large fraction
of the cryptocurrency
• https://ripple.com
Ripple Protocol and Network
• Five-phase project
• Phase 1: Tokenized SGD
• Phase 2: Re-imagining RTGS
• Phase 3: Delivery versus Payment (DvP)
• Phase 4: Cross-border Payment versus Payment (PvP)
• Phase 5: Enabling Broad Ecosystem Collaboration
Project Ubin: SGD on Distributed Ledger
• Public taxation
• National strategies
Blockchain and Government
• Government needs to maintain (in digital or in paper form)
• Daily operations and activities
• Government assets (land records, buildings etc.)
• Details of people, organizations and institutions
• Records of people
• Business transactions
Multi-institutional and Multi-Organizational
• Different levels of governance
• Note
• Directly store the data on blockchain?
• The data cannot be altered without colluding majority of
the blocks
• Data access as transactions - can check or verify who
has accessed what
Government and Cyber Crime
• Government database is a major target for
hackers
• In 2020, there are 1001 cases of data breaches that
affected 155.8 million individuals
(Source: https://www.statista.com/)
Passport
Data
Ministry of foreign
Affairs - Passport
data management
Sharing of Passport Data: An Example
Passport
Data
Ministry of foreign
Affairs - Passport
data management
Sharing of Passport Data: An Example
National Army
Defense Agency
Passport
Data
Ministry of foreign
Affairs - Passport
data management
Sharing of Passport Data: An Example
National Army
Defense Agency
National Police Agency
Airport/ Sea port CBI/CID - Crime department
Custom Check
Public Service
Identity Database
Passport
Data
Ministry of foreign
Affairs - Passport
data management
Sharing of Passport Data: An Example
National Army
Defense Agency
National Police Agency
Airport/ Sea port CBI/CID - Crime department
Custom Check
Public Service
Identity Database
Passport
Data
Ministry of foreign
Income Tax Department Affairs - Passport
National Intelligence data management
National Audit Agency
Sharing of Passport Data: An Example
National Army
Defense Agency
National Police Agency
Airport/ Sea port CBI/CID - Crime department
Custom Check
Public Service
Identity Database
Passport
Data
Ministry of foreign
Income Tax Department Affairs - Passport
Ministry of
National Intelligence data management
Public Service
National Audit Agency
Government Information Sharing System: A
Typical Example
Service
Requester Agency Directory
Service Broker
Service Broker
Organization Service
Service Gateway
Trade Logistics
Ecommerce Platform Network
Seller 1 Seller 3
Ban
k
Seller 2
Existing Consortia -- Centralized
Consumers
Ecommerce Platform
Seller 1 Seller 3
Seller 2
Consumers
Limitations
● Usually governed by a single authority (service
broker / marketplace )
○ Unfair business advantage to the broker
● Only service broker or marketplace provider
is responsible for communicating with end-users.
SP 1 SP 3
● Profit sharing with central broker
SP 2
● Bias of broker towards a particular provider
● Risk of manipulation & unfair dispute resolution
Objective
• Design a transparent decentralized architecture for
service providing consortium, while eliminating any
centralized broker/marketplace.
Objective
• Design a transparent decentralized architecture for
service providing consortium, while eliminating any
centralized broker/marketplace.
SP
SP
broker / marketplace
SP SP SP
SP
SP
Requirements
• While eliminating the central broker/marketplace, all its
functionalities must be preserved in the decentralized
consortium architecture:
● Unified Interface
○ The consortium should have a unified interface to its consumers.
○ The interface should be without any centralized broker or agent.
○ Consumers should be able to view catalog, query prices, request
for resources, get resource access information and credentials,
make payment, etc., through the interface.
Challenges
Consumer Consumers
s SP SP
Service SP SP Service
Request Response
SP SP
SP Process
SP Request SP SP
2
Decentralized Consortium Interface
1. Agreement on each user request and the ordering of user requests.
2. Service response must be verifiable by end-users. Confidentiality of
response must be preserved.
Decentralized Consortium Interface
SP
SP
Consumers
SP
Private SP
Blockchain
Decentralized Consortium Interface
● How user requests reach the Consortium?
● No single spokesperson for the consortium.
- No single web portal or address available for communication.
● Simple solutions like a broadcast from the consumers to the closed
network will not work.
○ Messages might be lost
○ Messages might arrive out of order.
● Consumers might be byzantine faulty and try
to partition the consortium.
Decentralized Consortium Interface
Required Guarantees:
1. Consortium Interface Safety - Non faulty SPs receive
the same set of consumer requests and in the same
order.
Servic ?
e SP
reques SP
Consumer t
s
Public SP Private SP
Blockchain Blockchain
Transferring Consensus to the Consortium
Consortium SPs cannot simply pick requests from the
permissionless blockchain and start processing:
1. Some consortium members might not get the mined
block in time and thus cannot participate in its
scheduling.
2. Malicious consortium members may introduce and
schedule invalid consumer requests that are
not mined at all.
3. Consensus protocol like PoW, often goes
through temporary forks. (Network is partitioned into
two or more parts with different accepted blocks.)
Transferring Verifiable Response
Servic
e SP
reques
SP
Consumer
s
t
Service
response
?
SP SP
Public
Blockchain
Private
Blockchain
Transferring Verifiable Response
A single SP cannot simply post a response of the
Consortium back to the users.
1. Consortium response is always based on a consensus
on the same.
2. The consortium consensus has no manifestation
outside the private blockchain.
3. The consortium consensus on response must be
verifiable by the end-users.
4. Confidentiality of the response has to be preserved
while transferring across the public blockchain network.
Transferring Verifiable Response
A single SP cannot simply post a response of the
Consortium back to the users.
1. Consortium response is always based on a consensus
on the same.
How do consensus
2. The consortium we solve this
has problem?
no manifestation
outside the private blockchain.
3. The consortium consensus on response must be
verifiable by the end-users.
4. Confidentiality of the response has to be preserved
while transferring across the public blockchain network.
Blockchain and its applications
Prof. Sandip Chakraborty
• Consensus on Consensus
Transferring Consensus to the Consortium
Servic ?
e SP
reques SP
Consumer t
s
Public SP Private SP
Blockchain Blockchain
Transferring Verifiable Response
Servic
e SP
reques
SP
Consumer
s
t
Service
response
?
SP SP
Public
Blockchain
Private
Blockchain
Consensus on Consensus
Consensus propagation from public blockchain to private
consortium blockchain
T1
SP 1 SP2 SPk
Initialize Propagation
BFT Consensus Contract & Send
endorsement - E(T1)
E(T1)
BFT Consensus
Private Ledger BFT Consensus
E(T1)
[21] Syta, Ewa, Iulia Tamas, Dylan Visher, David Isaac Wolinsky, Philipp Jovanovic, Linus Gasser, Nicolas Gailly, Ismail Khoffi,
and Bryan Ford. "Keeping authorities" honest or bust" with decentralized witness cosigning." In 2016 IEEE Symposium on
Security and Privacy
Verifiable Response Transfer
● Consortium response is accepted as valid only if it has ≥ ⅔ of the SPs’
signatures.
● For preserving confidentiality, a response to a consumer is encrypted
using its public key.
● Signature Collection:
● Multisignature collection is carried out off-chain to improve latency.
● A communication tree is formed along which the singing request
and the signatures are exchanged.
● Each node of the tree aggregates signatures collected from its
descendants.
● Fallback to smart contract based signature collection in case of
denial of service attack by some SP.
Verifiable Response Transfer
Private Ledger
PB0 PB1 PB14 PB15 PB16 PB17 PB18
E(T1) E(T1) E(T1)
Response S(M)
EC = 1 EC = 2 EC = k R1 SC = 1
B10, O1
M = Encrypt(R1)
B10, O1 B10, O1
Initialize Signature
Scheduling Collection Fallback
BFT Consensus
Contract Contract
BFT Consensus
Aggregated
Public signatures SM
Public Ledger Blockchain
SP1
M
Tx
B0 B1 B9 B10 M
Miner SP2 SP3
M
M M
SM M
SP4 SP5 SP6 SP7
VM
Request
Consume
r VM access
credentials
Cloud federation
consortium
Testbed Setup
Results
Results
Results
Conclusion
● There are interesting research/design problems in the blockchain
space
● You need to think of applying the right technology at the right
place!