Foundations of Blockchain Technology Basics (1)
Foundations of Blockchain Technology Basics (1)
Mr. Ismankhan Y M
Assistant Professor(OG),
SREC, Coimbatore
CONCEPTS NEEDED FOR
BLOCKCHAIN
TECHNOLOGY
KHOOR
HELLO HELLO
CRYPTOGRAPHY
Authentication:FUNCTIONS
act of validating that users (passwords)
or proving one’s identity (ID card)
Authorisation: giving the user permission to
accessa specific resource (eg file)
Keys authenticate user to enter the house. But you may not
have permission to ransack your sibling’s cupboard.
Encryption: readable not
text into format (symbols) – understandable
to transfer information securely
/confidentiality
Non-repudiation: provesthe sender really sent this
message
(e-commerce)
Integrity: ensures message is not altered during transit
(download)
Trust – belief on the participants ( e g parent gives you
their car )
PUBLIC-KEY CRYPTOSYSTEMS
Double S
HA256
ECC
The user first hashes the transaction / message data
using a hash function (double-SHA256) for later
verification of data integrity.
The hashed data is then encrypted using the user’s
private key to provide user authentication and the
encrypted output is known as the digital signature of
that transaction.
The transaction data and the signature are broadcasted
to network.
At the receiver end, the digital signature is decrypted
using public key of sender to obtain message digest.
Message digest is calculated from the received data
This is this checked to see if it is the same as MD
decrypted from the digital signature
KEY PAIR
GENERATION
Private key : d
in range 1
to (n-1)
P is a point on the
curve
Public key Q = d
*
G(x,y)
G(x,y) base point
GF(p) prime field
integers modulo p;
y² = x³ + ax + b. over
a prime field
modulo 23.
Hash of the message is found h(m)
Random value k is found
d is private key; Q(x,y) public key
Signature needs r & s
(x1,y1) = k x G(x,y) mod p
r = x1 mod n
s = (k-1 (h(m) + d * r) mod n
r & s should be non zero. Else k has to be
regenrated
Encryption
‘m’ is message to be sent , represented by M o
n the curve. Randomly select ‘k’ from [1 – (n-1
)]. C1 & C2 are 2 cipher texts
C1 = k*G(x,y)
C2 = h(m) + k*Q
C1 and C2 will
be send.
Decryption
h(m) = C2 – d *
C1
w=s-1 mod n
u1 = (h(m) * w) mod n
u2 = (r * w) mod n (x2, y2) = (u1 × G(x, y) + u2 × Q(x, y)) mod
n x2 is equal to r verifies message integrity
P2P NETWORK
Web 3.0 – devices are connected in decentralized manner – better
connected, secure, private, user centric dApps, no
central authority, data flow
BLOCKCHAIN STRUCTURE
STRUCTURE OF A
BLOCK Contents of a block
Contents of a Header description
size field
block
4 Version A version number to
size field Description bytes track software/ protocol
upgrades
4 Block Size Block size
bytes in bytes, 32 Previous A reference to the hash
following bytes Block Hash of the previous (parent)
this field block in the chain
80 Block Header Several 32 Merkle A hash of the root of the
bytes fields bytes Root merkle tree of this block’s
form the
block header transactions
https://blockchair.com/bitcoin/block/639190
BLOCK 0
GENESIS
BLOCK
HOW IS HASH OF A BLOCK COMPUTED
Block_header =
Version(4)+hash(PrevBlock(32))+
Hash(MerkleRoot(32))
+Time(4)+Bits(4)+Nonce(4)
1) VERSION: The block version is a decimal number denoted by 4 bytes. Translate the ver
sion into a little-endian hex.
#Big endian encoding:
0x3fffc000 #Little endian
encoding: 0x00c0ff3f
2) PREVIOUS BLOCK HASH: Translate the previous block hash to a little endian hex.
#Big endian :
0x0000000000000000000556bf387e8eb38206dd9cc2021d4f9ad4fde
fc0fc73fd #Little endian:
0xfd73fcc0effdd49a4f1d02c29cdd0682b38e7e38bf56050000000000
HOW IS HASH OF A BLOCK
COMPUTED
3) MERKLE ROOT: Translate the merkle root to a little endian hex.
Hash pointer = value of prev block + digest of cur value
#Big
endian :0x79db64466f31628f75241e4688eb678aa7cd7d23a8ae54a820d681
73f1d96c41 #Little endian:
0x416cd9f17381d620a854aea8237dcda78a67eb884
61e24758f62316f4664db79
https://www.unixtimestamp.com/
HOW IS HASH OF A BLOCK
COMPUTED
https:/
/www.rapidtables.com/convert/number/decimal-to-hex.ht
ml
HOW IS HASH OF A BLOCK
COMPUTED
7) Append all the parameters together.
00c0ff3ffd73fcc0effdd49a4f1d02c29cdd0682b38e7e38bf560500000000000000000041
6cd9f1
7381d620a854aea8237dcda78a67eb88461e24758f62316f4664db799AC2EB5Dd2db15
17ee7cc7 49
0x00000000000000000008dc07079dc7649636a1a6e127f422a7b617edc15dfd90
To understand the power of blockchain systems we need
to differentiate between bitcoin currency (Bitcoin
app), the specific blockchain that underpins it (Bitcoin
network) and the idea of blockchains in general
(blockchain technology)
Source: Statistica
BANK VS BITCOIN TRANSACTION
Bank
Do not physically transfer money
providers need to facilitate the actual transfer between them
Centralised authority
Bob sends Rs100 to Alice using his mobile banking app,
Alice’s
account could be credited instantly by her bank based on the
trust that Bob’s bank will settle this payment later.
Bitcoin
its ability to virtually move the money over a digital medium and settle the
payment almost immediately – Pseudonymity.
without the need for a central body (P2P consensus).
If Bob sends 100 BTC to Alice, she receives the amount in her wallet
straightway. There will be no institutional involvement and no need for a
further settlement process
Key mgt. – Availability, Security and Convenience – Taint Analysis (relation
b/w 2 addresses) Eg: Wikileaks
Bitcoin is a digital cash system.
It allows for people to move bitcoins, the currency unit of
Bitcoin, between each other without using a bank or any other
trusted third party.
No government or company controls Bitcoin. Instead, thousands
of computers around the globe—the Bitcoin network
Security
Minting new coins
Processing payments – verifies and confirms payments
It is permissionless
• BIPS (Bitcoin Improvement Protocols)
• Bitcoin foundation – 2012 – funding and
“voice of bitcoin” in US
DOUBLE SPENDING PROBLEM
We send digital money as if sending an image or an email
Technically OK but how many times the same money is sent?
Physical currency cannot be counterfeited
Digital currency allows a person to spend the same money more than
once. Chuck makes copy of money before spending
5
9
DOUBLE SPENDING
Suppose Alice makes a transaction of 0.15 BTC towards Bob for a
●
1
2
DOUBLE SPENDING
●
Suppose Alice makes a transaction of 0.15 BTC towards Bob for a coffee and duplic
●
ates the same payment towards herself.
●
Bob gives the coffee to Alice without confirmation of payment.
●
Now, the payment made towards Alice is the confirmed payment and the pay
ment to Bob fails. Hence, Alice receives the coffee without paying for it.
0.15 BTC
1
3
HOW DOUBLE SPENDING IS PREVENTED IN BITCOINS
Bob must wait for atleast 6 new blocks in the blockchain before
confirming payment.
●
1
4
BITCOIN NETWORK AND ECOSYSTEM
USER
S
End users—People using Bitcoin for their day-to-day
needs, such as savings, shopping, speculation, or
salaries
Corporate users—Companies using Bitcoin to solve
their business needs, such as paying wages
internationally
Merchants—For example, a restaurant or a bookstore accepting
Bitcoin
payments
Bitcoin services—Companies providing Bitcoin-related
services to customers, such as topping up mobile phones,
anonymization services, remittance services, or tipping
services
Exchanges—Commercial services people can use to exchange
their
local currency to and from bitcoins
Protocols on top—Systems that operate “on top” of Bitcoin to
perform certain tasks, such as payment network protocols,
specialized tokens, and decentralized exchanges
RECAP - BITCOIN
Bitcoin, Bitcoin network, blockchain
decentralised, permissionless, P2P
cost is Rs 15 lakhs as on July 3, 2022; Block size 324
GB
vs Bank - physical transfer, no intermediaries,
ownership, decentralised
double spending
ecosystem - corporate, users, merchants, exchanges,
protocol services, developers
max of 21 million BTC… max 2041
WHAT IS
MINING?
PROCEDURE - VALIDATION AND CONSENSUS
New transaction types can often be added as soft forks, requiring only that the participants (e.g.
sender and receiver) and miners understand the new transaction type. This is done by having the
new transaction appear to older clients as a "pay-to-anybody" transaction (of a special form) and
getting the miners to agree to reject blocks including these transactions unless the transaction
validates under the new rules. This is how pay-to-script hash (P2SH) was added to bitcoin.
P2SH or Pay-to-Script-Hash addresses are a special type of address in Bitcoin,
which
allows you to create addresses that can receive or send transactions in which
a series of
instructions must be fulfilled in order to unlock the balances that these
addresses
contain.
This kind of fork requires only a majority of the miners upgrading to enforce the new rules, as
opposed to a hard fork that requires all nodes to upgrade and agree on the new version.
Fork
Resolution
1 2
3 4
Wallet
Submits transactions to bitcoin
network
Transactions Validated by other
nodes
Validated transactions are pooled
Miner forms the block using PoW
Broadcasts to other nodes
Other nodes validate the blocks
Blocks are added to local chain
Darkcoin (11 diff. hash alg.) – difficulty high
Proof of useful work - Primecoin, permacoin (proof of storage –
Virtual mining
Overlay currency - investor outsourcing currency risk
management to a specialist firm, known as the overlay manager.
Buy/sell assets in a foreign currency.
Colored coins - colored coin is a denomination of a
cryptocurrency, often Bitcoin, that is repurposed by marking it
with metadata - allowing the creation of tokens that serve to
represent other currencies or assets of interest on blockchain.
Consensu
s
Two Types of Consensus Mechanisms
● Lottery Based : A lottery draw or a lucky draw elects the leader or
validator, who gets the privilege to propose and add the next block
of transactions. Example : Proof of work, Proof of stake
● Voting Based : They work based on voting mechanisms.
0
2) Vote
The non-faulty processes listen to the value being proposed by the
leader, validate it, and propose it as the next valid value.
3) Decide
The non-faulty processes must come to a consensus on a
single correct output value. If it receives a threshold number
of identical votes which satisfy some criteria, then the
processes will decide on that value commit
Otherwise, the steps start over.
I) CONSENSUS - POW
Every miner tries to solve a puzzle
computing a hash value of block header < target
Add different nonces – Bernoulli Trial – adding diff. nonces to solve the puzzle
I am Satoshi Nakamoto0 => a80a81401765c8eddee25df36728d732...
I am Satoshi Nakamoto1 => f7bc9a6304a4647bb41241a677b5345f..
am Satoshi Nakamoto6 => 4a2fd48e3be420d0d28e202360cfbaba...
I am Satoshi Nakamoto7 => 790b5a1349a5f2b909bf74d0d166b17a...
I am Satoshi Nakamoto8 => 702c45e5b15aa54b625d68dd947f1597...
I am Satoshi Nakamoto9 => 7007cf7dd40f5e933cd89f f f5b791ff0...
I am Satoshi Nakamoto10 => c2f38c81992f4614206a21537bd634a...
I am Satoshi Nakamoto11 => 7045da6ed8a914690f087690e1e8d66...
I am Satoshi Nakamoto12 => 60f01db30c1a0d4cbce2b4b22e88b9b...
Block_header = Version(4)+hashPrevBlock(32)+hashMerkleRoot(32)+Time(4)+Bits(4)
T = coefficient * 2^(8-(exp-3))
= 1432530 * 2^160 (Decimal)
= 00000000000000000015DBD2000000000000000000000000000000000
0000000
18 zeros
Hash =
49810A64972C55C19AAAF1420B6C5CB50D941D755855848CA7D210E0D36D685B
Hash = 0CB81BE5B4081E187A8CA4839390AE08DCF239CABB2F0A9E04D178F5955CA084
10) Perform double SHA256 algorithm with nonce value : (Hex – 64 chars)
Hash =
00000000000000000006412b5dc298916fb5d148e9eca74d89a
II) CONSENSUS - POS
III) CONSENSUS - DPOS
An iteration of the concept known as Delegated Proof of Stake
(DPoS) works similarly, but features a voting and delegation
mechanism that makes the process more democratic.
A limited number of delegates (most protocols choose between 20
and 100) are chosen for each new block, so the delegates of one
block might not be the delegates of the next.
The first iteration of DPoS was developed in 2014 by former EOS
Chief Technology Officer (CTO) Dan Larimer. Larimer first
implemented the consensus algorithm on decentralized crypto
exchange platform BitShares in 2015. Today, a number of
blockchains, including Cardano, EOS, and TRON, use DPoS.
This concept has shown immense promise for increasing the
efficiency, transaction speed, and throughput of blockchain
protocols, which is necessary for more enterprise uses as the
industry grows and looks to disrupt more complex and larger
markets.
OTHER CONSENSUS MECHANISMS
Proof of Work (PoW)
protocol
● In general terms, ‘proof of work’ is a piece of data that :
○ Satisfies certain requirements
○ Hard to produce
○ Easy to verify
1 2
Key steps – Independent Creation of
blocks
● Every mining node collects some transactions from its mempool and
creates candidate blocks
● Miners then try to solve the ‘proof of work’ puzzle.
● Once a miner solves the puzzle, they publish their candidate block
to the network.
● If a miner receives a valid block from a different miner, they will stop the
mining for current height and starts mining for the next height.
3 4
Proof-of
work
● Popular implementations: Bitcoin, Litecoin, Dogecoin
etc.
● Pros: We know it works (decentralized, internet scale
consensus)
● Cons: Slow throughput; 51% attack
Proof of
Stake
Proof-of-
Stake
● Using an election process, one node is randomly chosen to validate the
next block
● Miners –> Validators
● Mining –> Minting / Forging / Proposing
● A node has to deposit a certain amount(Stake) of coins into the network.
● The size of stake determine the chances of a validator to be chosen to
forge the next block.
● Chance & stake has a linear correlation
Proof-of-
Stake
● After a validator is chosen it will check all the transactions within
a block.
● Simple Fail Stop Fault Tolerance : Nodes can crash, not return
values , crash detectable by other nodes.
Source : https://rustie.xyz/
IV) CONSENSUS - PBFT