You are on page 1of 75

Blockchain Technology BE

(Sem-II)

Unit-II
Feature Engineering
Image courtesy: http://beetfusion.com/

A HISTORICAL PERSPECTIVE

20
The Fundamentals

Cryptographically Secured Hash Functions

Hash Functions: Map any sized data to a fixed size; Example H(x) = x %
n, where x and n are integers and % is the modular (remainder after division
by n) operations. x can be of any arbitrary length, but H(x) is within the
range [0,n-1].

Cryptographically Secured:
One way, given a x, we can compute H(x), but given a H(x), no deterministic
algorithm can compute x
For two different x1 and x2, H(x1) and H(x2) should be different
Cryptographic Hash Functions
Examples: MD5, SHA256

X is called the message and H(X) is called


the message digest

A small change in the data results in a


significant change in the output – called
the avalanche effect

Image source: Wikipedia


Cryptographically Secured Chain of Blocks

The first use - time-stamp a digital document (Harber and


H1=Hash(0,C1,TS1,H0)
Stornetta, 1991)
A sequence of timestamps [TS1, TS2, TS3, …] denoting
when the document is created or edited. H2=Hash(1,C2,TS2,H1)
Whenever a client access a document, construct a block
consisting of the sequence number of access, client ID,
timestamp, a hash value from the previous request; and H3=Hash(2,C3,TS3,H2)
the entire thing is hashed to connect it to the previous
blocks. H4=Hash(3,C4,TS4,H3)

Haber, Stuart; Stornetta, W. Scott (January 1991). "How to time-stamp a digital


document". Journal of Cryptology. 3 (2): 99–111
Merkle Trees (Ralph Merkle, 1979)
Also known as hash tree
Root Hash
every leaf node is Hroot=Hash(H0+H1)
labelled with the hash of
a data block
every non-leaf node is L1 Hash L1 Hash
H0= H1=Hash(H10+H11)
labelled with the Hash(H00+H01)
cryptographic hash of the
labels of its child nodes L2 Hash L2 Hash L2 Hash L2 Hash
H00=Hash(D H01=Hash(D H10=Hash(D H11=Hash(D
2) 3) 4)
1)

D1 D2 D3 D4
Use of Merkle Trees

Bayer, Harber and Stornetta used Merkle Tree in 1992 for timestamping and verifying a
digital document - improved the efficiency by combining timestamping of several
documents into one block

Other uses of Merkle Tree


Peer to Peer Networks: Data blocks received in undamaged and unaltered;
other peers do not lie about a block
Bitcoin implementation – shared information are unaltered; no one can lie
about a transaction
Bitcoin and Blockchain
What is Bitcoin?
⚫ Bitcoin is a completely decentralized, peer-to-peer, permissionless
cryptocurrency put forth in 2009
− Completely decentralized: no central party for ordering or recording anything
− Peer-to-peer: software that runs on machines of all stakeholders to form the
system
− Permissionless: no identity; no need to signup anywhere to use; no access
control – anyone can participate in any role

* Nakamoto, Satoshi. "Bitcoin: A peer-to-peer electronic cash system."


(2008)
(https://bitcoin.org/bitcoin.pdf)
Bitcoin Value Proposition
⚫ The last few years have seen a lot of interest in Bitcoin and cryptocurrencies in general.
⚫ Used as a cross-country, untraceable currency which is not under the control of any
government and hence free from regulation
⚫ Current BTC price 1 BTC = $ 23,341.90 (as of 03rd August, 2022 at 3:00 pm)
⚫ The Bitcoin blockchain size as of April 2022 is approximately 394.02 GB.

Blockchain Size Bitcoin Price

Source: Statistica
The Technology behind Bitcoin – The Blockchain
A = ₹100 A = ₹100
₹ 50
A -> B ₹50 A -> B ₹50

B -> J ₹30 B -> J ₹30


Bob
Alice
₹ 100 ₹ 30

A = ₹100 A = ₹100

A -> B ₹50 Note: A block may A -> B ₹50


contain multiple
B -> J ₹30 Eve transactions Jane B -> J ₹30
The Bitcoin Transaction Life Cycle – The Sender

Alice opens her Provides the address of Bob and


Bitcoin Wallet the amount to transfer, and sends
The Bitcoin Transaction Life Cycle – The Network

The wallet The network


constructs the nodes validate the The miners
transactions, sign transactions based include the
using Alice’s on the existing transaction to the
private key, and Blockchain, and next block to be
broadcasts it to the propagate the mined
network transaction to the
miners
The Bitcoin Transaction Life Cycle – The Miners

Miners construct a new Once the mining is


block and tries to over and the hash is
The miners collect
connect it with the obtained, the block is
all the transactions
existing blockchain, included in the
for the a time
through a cryptographic existing blockchain.
duration, say for 10
hash computation The updated
Minutes blockchain is
-
The Mining Procedure propagated in the
network
The Bitcoin Transaction Life Cycle – The Receiver

Bob opens his


Bitcoin Wallet and The transaction reflects
refreshes, the at Bob’s wallet
blockchain gets
updated
Blockchain 2.0

⚫ Interested by the Bitcoin revolution, mainstream companies are trying to


use the central blockchain idea and build alternative systems around it for
use in industry, manufacturing, supply chain, finance, governance, IoT etc

⚫ This movement of academia, industry, startups is termed Blockchain 2.0.


Blockchain 2.0 and Smart Contracts

Blockchain is a powerful technology – capable of going much further than financial


transactions

A decentralized platform – can be utilized to avoid intermediates (the middleman)

Smart Contracts: An automated computerized protocol used for digitally facilitating,


verifying or enforcing the negotiation or performance of a legal contract by avoiding
intermediates and directly validating the contract over a decentralized platform – faster,
cheaper and more secure
Smart Contracts

The term was coined by Nick Szabo, a computer scientist and cryptographer, in 1996

Szabo claimed that smart contracts can be realized with the help of a public ledger

Blockchain can be a pioneering technology to realize smart contracts


Contracts in a Centralized Platform – Crowdfunding
1. You have an interesting
project, but do not have
sufficient money to execute
the project

3. Multiple supporters 4. The platform ensures


commit to support the that you get the complete 2. Submit the project in a
project with small funds money if the project is crowdfunding platform
successful
The Crowdfunding Platform
Both the product team and the supporters need to trust the
crowdfunding platform

The product team expects the money to be get paid based on the
project progress

The supporters expect the money to go to the project

However, the crowdfunding platform, the middleman, takes


significant charge to manage the entire process
Crowdfunding Platform using Smart Contracts

The contract is written in a code which is available to all the stakeholders – the supporters and
the product team – Do you see an application of Blockchain here?
Crowdfunding Platform using Smart Contracts

If certain goals of the project are reached, then the code automatically transfers the money from
supporters to the production team
Crowdfunding Platform using Smart Contracts

If the project goals (contracts) fail, then the code can transfer the money back to the supporters
Smart Contracts – The Advantage

Immutable: No party will be able to change the contract once it is fixed and written to
the public ledger (the Blockchain)

Distributed: All the steps of the contract can be validated by every participating party –
no one can claim later that the contract was not validated

Why Blockchain?
The blocks are immutable
The information is open – everyone can check and validate
Smart Contract Platforms
Image courtesy: http://beetfusion.com/

THE ARCHITECTURAL
PRINCIPLES
44
The Blockchain

A Platform for executing transactional services

Spanned over multiple organizations or individuals who may not trust each other

An append-only shared ledger of digitally signed and encrypted transactions replicated


across a network of peer nodes
The Block in a Blockchain – Securing Data Cryptographically

Digitally signed and encrypted transactions verified


by the peers

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 (as of March 2018)
Larger blocks can help in processing large number of transactions in one go.
Structure of a Block (Reference: Bitcoin)
Two components:
Block Header
List of Transactions

Block Source: https://blockchain.info/


Block Header (Reference: Bitcoin)

Metadata about a block – (1) Previous block hash, (2) Mining


H0
statistics used to construct the block, (3) Merkle tree root

Previous block hash: Every block inherits from the previous H1 =


block – we use previous block’s hash to create the new block’s Hash(H0)
hash – make the blockchain tamper proof. H2 =
Hash(H1)
H3 =
Hash(H2)
H4 =
Hash(H3)
Block Header (Reference: Bitcoin)

Mining – the mechanism to generate the hash


H0
The mechanism needs to be complicated enough, to make the
blockchain tamper proof
Bitcoin Mining: Hk = Hash(Hk-1 || T || Nonce) H1 =
Find the nonce such that Hk has certain predefined complexity Hash(H0)
(number of zeros at the prefix) H2 =
Hash(H1)
The header contains mining statistics – timestamp, nonce and difficulty
H3 =
Hash(H2)
H4 =
Hash(H3)
Block Header (Reference: Bitcoin)
Merkle Tree Root: The transactions Root Hash
are organized in a Merkle Tree Merkle Root
Hroot=Hash(H0+H1)
structure. The root of the Merkle tree is
a verification of all the transactions.
L1 Hash L1 Hash
H0= H1=Hash(H10+H11)
Hash(H00+H01)

L2 Hash L2 Hash L2 Hash L2 Hash


H00=Hash(T H01=Hash(T H10=Hash(T H11=Hash(T
2) 3) 4)
1)

T1 T2 T3 T4
Block Header (Reference: Bitcoin)

Block Source: https://blockchain.info/


The Hashes in a Block Header (Reference: Bitcoin)

Block identifier – the hash of the current block header (Hash algorithm: Double SHA256)
Previous block hash is used to compute the current block hash
Transactions in a Block (Reference: Bitcoin)

Transactions are organized as a Merkle Tree. The Merkle Root is used to construct the block
hash

If you change a transaction, you need to change all the subsequent block hash

The difficulty of the mining algorithm determines the toughness of tampering with a block in a
blockchain
Transactions in a Block (Reference: Bitcoin)

Block Source: https://blockchain.info/


The Block in a Blockchain - Summary

The Block contains two parts – the header and the data (the transactions)

The header of a block connects the transactions – any change in any transaction will
result in a change at the block header

The headers of subsequent blocks are connected in a chain – the entire blockchain
needs to be updated if you want to make any change anywhere
Layers of Blockchain
Image courtesy: http://beetfusion.com/

THE MINERS
2
The Life of a Miner
• Validate transactions and construct a block

• Use hash power to vote on consensus andcommit transactions with a newblock

• Store andbroadcast theblockchain tothepeers


Mining Bitcoins
• Join the network and listen for transactions – validate the proposed
transactions

• Listen for new blocks – validate and re-broadcast a new block when it is
proposed

• Collect transactions for a predefined time and construct a new block


Mining Bitcoins
• Find a nonce to make the new block valid

• Broadcast the new block – everybody accepts it if it is a part of the main


chain

• Earn the reward for participating in the mining procedure


Mining
• Ameasure of how difficult Difficulty
it is to fond a hash below a given target
– Bitcoin network has a global block difficulty
– Mining pools also have a pool-specific share difficulty

• The difficulty changes for every 2016 blocks


– Desired rate – one block each 10 minutes
– Two weeks to generate 2016 blocks
– The change in difficulty is in proportion to the amount of time over or
under two weeks the previous 2016 blocks took to find (en.bitcoin.it)
Setting the Difficulty
• Compute the following for every two weeks

current_difficulty = previous_difficulty *
(2 weeks in milliseconds)/(milliseconds to
mine last 2016 blocks)
Hash-rate versus Difficulty
• The hash is a random number between 0 and 2256-1
– Tofind a block, the hash must be less than a given target

• The offset for difficulty 1 is 0xffff * 2208

• The offset for difficulty Dis 0xffff * 2208/D

• The expected number of hashes we need to calculate to find a block with


difficulty Dis (D * 2256) / (0xffff * 2208)
Mining
• Difficulty(as of 2nd April, 2018)
Current difficulty: 3511060552899.72
– https://blockexplorer.com/api/status?q=getDifficulty
Mining Difficulty

Source: http://bitcoin.sipa.be/
MiningHardware
• Specialized hardware
– GPU
– FPGA
• ASIC
– Released in 2013
– Fast computation of
SHA256
Image source:
https://steemkr.com/bitcoin/@pawank/bitcoin-mining
TerraMiner IV
• ASIC based bitcoin mining rig
• 2Terahash per second
• Cost: USD 3500 approx
MiningPool
• Pooling of resources by the miners

– Share the processing power over


a network to mine a new block

– Split the reward proportionally to


the amount of work they
contributed
Hash-rate Distribution: blockchain.info
MiningPool Methods
• Contains hundreds or thousands of miners through special protocols

• 𝐵: Block reward minus pool fee

• 𝑝: Probability of finding a block in a share attempt (𝑝 = 1/𝐷), 𝐷 is the


block difficulty
MiningPool Methods
• Pay per Share (PPS)
– Instant guaranteed payout to a miner
– Miners are paid from pool’s existing balance, share of a miner is
𝑅=𝐵 ×𝑝
– Miners get almost equal payment, risk is at the pool operator
MiningPool Methods
• Proportional
– Miners earn share until the pool finds a block (end of mining round)
– 𝑅 = 𝐵 × 𝑛 , where 𝑛 is amount of his own share, and 𝑁 is amount of
𝑁
all shares in theround
– Payments are made once apool finds out a block
MiningPool Methods
• Pay per Last N Share (PPLNS)
– Similar to proportional
– Miner’s reward is calculated on the basis of Nlast shares
– Miners get more profit for a short round
MiningPools –ProsandCons
• Pros
– Small miners can participate
– Predictable mining

• Cons
– Leads to centralization
– Discourages miners for running complete mining procedure
Summary –Permissionless BlockchainandBitcoin
• The permissionless or open model of blockchain – any user can join the network
and participate in transactions
– Bitcoin is developed on this principle

• The blockchain provides the backbone of the permissionless digital currency


– Provides a decentralized architecture
– Tamper-proof through hash-chain

• Miners ensures the consensus in the system

You might also like