CSEN4031-BLOCKCHAIN TECHNOLOGY (BCT)
Module 2 Notes
1. Cryptographic Hash Functions
A hash function in cryptography is like a mathematical function that takes various
inputs, like messages or data of a block, and transforms them into fixed-length
strings of characters (Hash Value or Message Digest). This means the input to the
hash function is of any length but output is always of fixed length. It works only in
one way. That is from input to output. The reverse is almost impossible.
The importance of this process lies in its generation of a unique "fingerprint" for
each block. Any minor alteration in the input results in a substantially different
fingerprint.
2. Key Points of Hash Functions
• Hash functions are mathematical operations that "map" a given collection of
data of any length into a fixed-length bit string that is referred to as the "hash
value” or “message digest”.
• Hash functions have a variety of complexity and difficulty levels and are used
in cryptography.
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS
• Cryptocurrency, password security, and communication security all use hash
functions.
3. Properties or Characteristics of cryptographic hash functions
To be a reliable cryptographic tool, the hash function should have the following
properties,
3.1 Pre-Image Resistance
• According to this feature, reversing a hash function should be
computationally difficult. Almost impossible.
• In other words, if a hash function h generates a hash value z, it should be
difficult to identify an input value x that hashes to z.
• This feature defends against an attacker attempting to locate the input with
just the hash value.
3.2 Collision Resistance
• This feature says that it should be difficult to identify two different inputs of
any length that produce the same hash. This characteristic is also known as a
collision-free hash function.
• In other words, for a hash function h, it is difficult to identify two distinct
inputs x and y such that h(x)=h(y).
• A hash function cannot be free of collisions because it is a compression
function with a set hash length. The collision-free condition simply indicates
that these collisions should be difficult to occur.
• This characteristic makes it very hard for an attacker to identify two input
values that have the same hash.
3.3 Efficiency of Operation
• Computation of h(x) for any hash function h given input x can be an easy
process.
• Hash functions are computationally considerably faster than symmetric
encryption.
3.4 Fixed Output Size
Hashing generates an output of a specific length, regardless of the input size, and
helps to make an output of the same size from different input sizes.
3.5 Deterministic
For a given input, the hash function consistently produces the same output, like a
recipe that always yields the same dish when followed precisely.
3.6 Fast Computation
Hashing operations occur rapidly, even for large amounts of data sets.
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS
4. Secure Hash Function (SHA)
The four SHA algorithms which make up the SHA family are SHA-0, SHA-1, SHA-2, and
SHA-3. Despite coming from the same family, the structure of it differs.
• The National Institute of Standards and Technology (NIST) released the first
iteration of the 160-bit hash algorithm, known as SHA-0, in 1993. It did not
gain much popularity and had few drawbacks. SHA-1 was created later in
1995 to address perceived flaws in SHA-0.
• SHA-1 is the most widely used of the existing SHA hash functions. It is used in
most of the applications and protocols including Secure Socket Layer (SSL)
security.
• In 2005, a technique was discovered for SHA-1 collision detection that can be
used in a realistic time frame. So it is doubtful on SHA-1's long-term usability.
• HA-224, SHA-256, SHA-384, and SHA-512 are the other four SHA variants in
the SHA-2 family, which vary based on the number of bits in their hash
value. The SHA-2 hash function has not yet been the target of any effective
attacks
• Though SHA-2 is a strong hash function. Though significantly different, its
basic design still follows the design of SHA-1. NIST thus demanded the
creation of new competitive hash function designs.
• The Keccak algorithm was selected by the NIST in October 2012 to replace the
SHA-3 standard. Keccak has several advantages, including effective operation
and strong attack resistance.
5. Hashing vs Encryption
Encryption transforms data into a disguised form, requiring a cipher (key) to decipher
and read it. Encryption and decryption are reversible processes enabled by the
cipher. Encryption is used with the goal of later deciphering the data.
Hashing transforms data of any size into a fixed-length output. Unlike encryption,
hashing is typically a one-way function. The high computational effort needed to
reverse a hash makes it difficult to retrieve the original data from the hashed output.
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS
6. Steps in SHA 256 Algorithm
https://infosecwriteups.com/breaking-down-sha-256-algorithm-2ce61d86f7a3
the above site gives a total working of SHA 256 Algorithm
M + P + 64 = n x 512
i.e M = length of the original message
P = padded bits
6.1 Append Padding bits
The first step of our hashing function begins with appending bits to our original
message, so that its length will be the same as the standard length required for the
hash function.
6.2 Append Length bits
Now that we have appended our padding bits to the original message we can further
go ahead and append our length bits which is equivalent to 64 bits, to the overall
message to make the entire thing an exact multiple of 512.
6.3 Initialize the buffers
We have our message block on which we will begin to carry out our computations to
figure out the final hash. Before we begin with that, I should tell you that we need
certain default values to be initialized for the steps that we are going to perform.
a = 0x6a09e667
b = 0xbb67ae85
c = 0x3c6ef372
d = 0xa54ff53a
e = 0x510e527f
f = 0x9b05688c
g = 0x1f83d9ab
h = 0x5be0cd19
64 Length Bits = 8 x 8 rounds and gets updated
6.4 Compression Function
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS
So, the main part of the hashing algorithm lies in this step. The entire message block
that we have ‘n x 512’ bits long is divided into ‘n’ chunks of 512 bits and each of
these 512 bits, are then put through 64 rounds of operations and the output
obtained is fed as input for the next round of operation.
W(i) = Wⁱ⁻¹⁶ + σ⁰ + Wⁱ⁻⁷ + σ¹where,
σ⁰ = (Wⁱ⁻¹⁵ ROTR⁷(x)) XOR (Wⁱ⁻¹⁵ ROTR¹⁸(x)) XOR (Wⁱ⁻¹⁵ SHR³(x))
σ¹ = (Wⁱ⁻² ROTR¹⁷(x)) XOR (Wⁱ⁻² ROTR¹⁹(x)) XOR (Wⁱ⁻² SHR¹⁰(x))
ROTRⁿ(x) = Circular right rotation of 'x' by 'n' bits
SHRⁿ(x) = Circular right shift of 'x' by 'n' bits
Ch(E, F, G) = (E AND F) XOR ((NOT E) AND G)
Ma(A, B, C) = (A AND B) XOR (A AND C) XOR (B AND C)
∑(A) = (A >>> 2) XOR (A >>> 13) XOR (A >>> 22)
∑(E) = (E >>> 6) XOR (E >>> 11) XOR (E >>> 25)
+ = addition modulo 2³²
6.5 Output
The output from every round acts as an input for the next round and this process
keeps on continuing till the last bits of the message remains and the result of the last
round for the nᵗʰ part of the message block will give us the result i.e. the hash for the
entire message. The length of the output is 256 bits.
7. Hash Pointers (Data Structure in Blockchain)
Hash pointers are a data structure containing the previous block’s hash value and a
pointer to that block. Here is a demonstration:
Hash pointers are the building blocks of blockchain. Each block contains a hash
pointer that points to the previous block and contains its hash. The immutability of
blockchain is one of its most significant aspects, and hash pointers allow us to
attain this property. Hash pointers help us validate if a block is modified or not.
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS
8. Distributed Ledger
A distributed ledger can be described as a ledger of any transactions or contracts
maintained in a decentralized form across different locations and people.
9. Merkel Tree
Technically, the Merkle tree is a data structure used to encrypt transactions
efficiently and securely. It is made up of the hashes of various transactions of a block
summed up. In short, it acts as a summary of transactions for a block in a blockchain
network. Merkel root represents the final hash obtained by summing up hashes of
transactions of a block summing up level by level.
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS
Note: Merkel Tree for an odd number of transactions in a blockchain
Merkle trees are part of a binary tree; therefore, it necessitates an even number of
leaf nodes. If Transactions are in odd numbers, then the last hash will be repeated
once to generate an even number of leaf nodes. The above example is the most
common and simplest form of a Merkle tree, i.e., a binary Merkle tree.
9. Types of Consensus Algorithms
In a distributed environment arriving at a common agreement is only through
consensus. The basis for the consensus is the Miner’s or Validator’s block validation
work submission to all the users.
There are several consensus algorithms. Some of them are listed below.
• Proof of Work (PoW)
• Proof of Stake (PoS)
• Delegated Proof of Stake (DPoS)
• Proof of Elapsed Time (PoET)
Let us now see Working. Pros and cons of each of the above consensus algorithms.
9.1 Proof of Work (PoW)
Working:
In PoW method, miners competing for block validation work should have a high
computational power system. These systems require or consume huge electricity
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS
power. One who solves the mathematical puzzle first declared as the winner and
block validation work will be given to that miner. The miner broadcasts the block
validation work done as PoW in a detailed manner to all the peers in the network.
The peers go through, and verify. If either all or majority of them
confirms(consensus) then Miner adds that block to the blockchain. On average, it
takes 10 minutes to validate a new block and add it to the block to the blockchain by
the Miners. After adding a new block to the blockchain Cryptocurrencies get minted.
Miner gets block reward along with applicable transaction fees.
Advantages of PoW
• It is a straightforward method.
Disadvantages of PoW
• It favors miners having a high computational power system. As a result, only a
few can participate in block validation work.
• Miner’s system consumes more electricity. Thus, it is energy intensive. This
will lead to ecological disorder in the future.
• It poses a puzzle to be solved for the Miners. It is so complex and time-
consuming. Thus, block validation work takes time. Thus, arriving at a
common agreement needs more time. Thus, it is slow.
• It has a risk of 51% attack when users with high computing power collide and
form a syndicate to dictate the terms and conditions of the network.
• No provision for accountability (holding responsible) of malicious miners for
their mischief (bad activity). As a result, malicious miners can escape for their
mischief.
Blockchains using proof-of-work (PoW)
Bitcoin, Litecoin, and Dogecoin.
9.2 Proof of Stake (PoS)
Working:
In PoS, Miners are called as validators. Validators have to deposit some number of bit
coins(tokens) as stake to compete for block validation work. Stakes act as collateral
for each validator and they are locked at the staking pool. Stakes are released after
the completion of the work. Stake aspect removes the requirement of high
computing power systems by validators. Validators with less computing power
system will also compete for block validation work. Based on any one of the
following criteria one validator is chosen and given block validation work. The criteria
are 1. Size of the stake, 2. Stake waiting for a long time and 3. Stake chosen in
random manner (lottery system). One who has been chosen based on any one of
these criteria will be given the work. The validator broadcasts the block validation
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS
work done as PoS in a detailed manner to all the peers in the network. The peers go
through, verify. If either all or majority of them confirms (consensus), then the
Validator adds that block to the blockchain. After adding a new block to the
blockchain Cryptocurrencies get minted. Validator gets block reward along with
applicable transaction fees.
Advantages of PoS
• Stakes restrict number of validators going for block validation work. Besides,
PoS method need not require validators to have high computing power
system to claim the work. Validator with less computing power system can
also have a chance to compete and get the work. These two points lead to
reduction in consumption of electricity power to a significant level as well as
giving fair chance to all validators to take part in the validation work. Also,
observe that it is not energy-intensive. Thus, PoS method is good and
ecologically viable option for arriving at consensus in distributed environment.
• As a way to stop validators from acting maliciously or adding fraudulent
transactions into the block, the total value of tokens staked needs to exceed
the transaction fees earned. If fraudulent activity is detected, the validator
loses the stake and will not be allowed to participate in the validation process
in the future. This is why larger stakes are favored since the validator stands to
lose more from acting maliciously. This ensures accountability and
punishment for defaulters.
Disadvantages of PoS
• One criticism of the PoS methodology is that its design favors the wealthy —
those who deposits the most cryptocurrency — since it chooses validators
with the most tokens staked. To combat this discrepancy, other methods for
validator selection and iterations on the concept of staking have been
developed: the most notable is delegated PoS.
• Users of the network have no voice in the selection of validators. Another
issue is users will not have a share in the rewards.
Blockchains using PoS
• Ethereum Blockchain shifted to PoS from PoW in September 2022.
• Tezos, Cosmos, Cardano, EOS, Algorand, and Synthetix Network are just a
few of the blockchains that currently utilize versions of PoS.
9.3 Delegated Proof of Stake (DPoS)
Working
Delegated Proof of Stake (DPoS) is an extension of the PoS concept. In this user can
vote and elect delegates by pooling their tokens into a staking pool and linking
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS
those to a particular delegate. These delegates do the block validation on behalf
their group of users. Delegates of each group participate in the block validation work.
User does not physically transfer the tokens(stake) to another wallet but instead
utilize a staking service provider to stake your tokens in a staking pool. Delegates
are also called Witnesses or Block Producers.
Advantages of DPoS
• In this method, users are actual validators through their delegates. Thus, it is
more democratic in nature than PoS.
• A limited number of delegates (most protocols choose between 20 and 100)
takes part in new block validation and addition. Further, the delegates of one
block might not be the delegates of the next. Observe that block validation
work is collective in nature.
• Elected delegates receive the transaction fees from the validated block, and
that reward is then shared with users who pooled their tokens in the
successful delegate’s staking pool. The more user stakes, the higher the
share of the block reward the user receives.
• All the above reflects the true democratic nature of the validation process.
Note: PoS and DPoS promise for increasing the efficiency, transaction speed, and
throughput of blockchain protocols.
Examples
• 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 the decentralized crypto exchange platform BitShares
in 2015.
• Today, several blockchains, including Cardano, EOS, and TRON, use DPoS.
9.4 Proof of Elapsed Time (PoET)
History
Proof of Elapsed Time in blockchain uses a time-lottery-based consensus
mechanism, distributing wait time to each participating node in the network.
The PoET algorithm was developed by Intel Corporation, the processor chip giant, in
early 2016.
Working
PoET Mechanism assigns an amount of wait time to each node of the user in the
network randomly. The node must sleep or do another task for that random wait
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS
time. Whichever node gets the shortest waiting time wakes up and adds its block
to the network. Later, the newly updated information is broadcast among other
network participants.
Important to note the following points in PoET
The Proof of Elapsed time in blockchain needs to ensure 3 significant factors for this
process to work:
• Ensure that the node or network participant gets the random waiting time.
• Check whether the method is choosing the shortest waiting time or not.
• Verify if the node has completed the given waiting time or not.
Advantages of PoET
The following are the advantages of the PoET consensus mechanism:
• PoET can go up to a million transactions per second (fastest).
• It is highly energy-efficient than PoW.
• It’s the fair block generation consensus algorithm, as it allows all the users
of the network not the wealthy alone to participate in validation work.
• It ensures the equal opportunity of all network users to participate in
validation work with a waiting time object assigned and activated. Thus,
need not require the election of delegates on behalf of the users. It brings
down the democratic process to the user level itself.
• It does not require stakes to be deposited, unlike PoS. As all the users are
allowed to participate fairly, malicious acts of any user will be noticed by
all the others and they can resist that act. This implies that doing malicious
acts by any user is difficult here in this method of consensus. Further, note
that accountability need not be required as malicious acts can be stalled
fully.
• PoET is suitable for privately controlled blockchains. Thus, it is meant for a
permissioned and closed network.
• As it’s a permission blockchain network, the process of selecting
validators ensures network security against cyber-attacks.
Disadvantages or Limitations of PoET
The following are the disadvantages of the PoET consensus mechanism:
• PoET is a permission and closed network. It is not suitable for
permissionless and open networks like Bitcoin and Ethereum.
• The mechanism highly depends on tools by Intel technology which might
raise compatibility issues with other tools later.
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS
Quiz
1. Which among the following is the main drawback of PoW?
A. Security B. Energy Inefficiency C. Extensive Computations
D. None of them
Answer)
2. The output of the cryptographic hash function is
i. Variable in length ii. Fixed in length
A. i B. ii C. None of them
Answer)
3. The output of the cryptographic hash function is called
i. Message Digest ii. Hash Value
A. i B. ii C. Both of them D. None of them
Answer)
4. SHA stands for _____________
Answer)
5. The purpose of Consensus Algorithm is ____________
Answer)
6. Which among the following consensus algorithms is truly democratic in nature?
A. PoW B. PoS C. DPoS D. PoET
Answer)
7. Which among the following consensus algorithms is truly random in nature?
A. PoW B. PoS C. DPoS D. PoET
Answer)
8. Which among the following consensus algorithms may favor wealthy users?
A. PoW B. PoS C. DPoS D. PoET
Answer)
9. Which among the following consensus algorithms needs high computing resources
and causes big environmental issues?
A. PoW B. PoS C. DPoS D. PoET
Answer)
10. Who invented PoET __________
Answer)
11. Which among the following requires election of validators?
A. PoET B. DPoS C. PoW D. None of them
Answer)
12. Which among the following allow all the users to participate equally in the
validation work?
A. PoW B. PoS C. DPoS D. PoET
Answer)
13. What is the most democratic method of selection of validator in PoS?
A. Largest Stake B. Longest Stake C. Random Stake D. None of them
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS
Answer)
14. Why accountability not arise in the PoET?
A. Democratic Election of Delegate B. All users equally participate in the
validation work C. Random selection of validator D. None of the
Answer)
15. PoET works fine if _____
A. waiting time is randomly assigned B. the shortest waiting time user is chosen
C. Both of them D. None of them
Answer)
16. PoET is better than PoS in terms of
A. elected validators competing for the validation work
B. all the peers competing for the validation work
C. staked validators competing for the validation work
D. None of them
Answer)
17. PoET is better than DPoS in terms of
A. no election of delegates required
B. all the peers compete for the validation work
C. both of them
D. none of them
Answer)
Question Bank
1. Define the cryptographic hash function with a neat diagram. Give its purpose
2. How do you differentiate between Cryptography and Hashing? Which one is
better? Justify your answer suitable.
3. Explain the characteristics or properties of a good hash function, like, SHA 256.
4. Write short notes on
• Distributed Ledger
• Merkel Tree
• Hash Pointers (Data Structures of Blockchain)
• SHA family of Hash Functions
5. Explain the steps involved in the SHA 256 algorithm.
6. Explain the working of Proof of Work (PoW). Give its advantages, disadvantages,
and examples of blockchain using it.
7. Explain the working of Proof of Stake (PoS). Give its advantages, disadvantages,
and examples of blockchain using it.
8. Explain the working of Delegated Proof of Stake (DPoS). Give its advantages,
disadvantages, and examples of blockchain using it.
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS
9. Explain the working of Proof of Elapsed Time (PoET). Give its advantages,
disadvantages, and examples of blockchain using it.
10. Differentiate between the following
• PoW and PoS
• PoS and DPoS
• PoW and PoET
• PoET and PoS as well as DPoS
Dr. NAGA RAJU M - Asso. Prof.- CSE | GITAM BENGALUR CAMPUS