BC-M3 Sem
BC-M3 Sem
Accredited
1 by NBA and NAAC – ‘A’ Grade
Blockchain Technology
Module 3
Course Coordinator
Dr. M.Sridevi
Asst. Professor & Head
Dept. of MCA
BMSITM, Bengaluru
01/05/2025
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
2 Hashing in Blockchain
Blockchain technology is an intricate web of several
technological innovations working together
Among the most important pieces of the blockchain puzzle
is hashing
Hashing is a cryptographic function that converts a string
of characters of any length into a unique output, or hash, of
fixed length
This means that no matter what combination of symbols
are used as the input, they will always produce a one-of-a-
kind string of digits and characters.
A Bitcoin hash looks like this:
00000000000000000025e2ba026a8ad462b9a693d80fd0887d
ef167f5f888a11
(hash of block 540807)
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
3 Hashing Essentials
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
4 Hashing in
Cryptocurrencies
Hashing is an integral part of all blockchain-based transactions,
including the trading of cryptocurrency
Hash functions are necessary in everything from mining blocks
to signing transactions to generating private keys
Bitcoin SHA-256
Bitcoin Cash SHA-256
Ethereum keccak256
Litecoin scrypt
Ripple SHA-512
A hash function is a mathematical algorithm used to calculate
the hash
Different cryptocurrencies use different hash functions but all of
them follow the same basic principles of hashing
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
5 Main Properties of
Hashing
Hashing produces outputs of fixed length
Input: hello
Output:
2CF24DBA5FB0A30E26E83B2AC5B9E29E1B161E5C1FA7425E
73043362938B9824
Input: It’s a good day to HODL
Output:
6B89D5D4AD6A3364410DD9BAB95FD250EF4A663D9D3C47C
BD7388535A5912E03
Input: The entire novel of Oliver Twist
Output:
4F144CC612CA27E2DD6DFD6663F68BABC3B758D602B5102
BF14E717E823EB741
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
6 Main Properties of
Hashing
Here, the SHA-256 hash function is used to generate
the hashes of two different inputs
In all three cases, the hash is completely unique,
but its length remains the same
SHA-256 generates hashes that are 256 bits long,
usually represented as 64 symbols comprised of
numbers 0–9 and letters A–F
No matter how short or how long the input is – be it
a single word (hello) or even a whole novel (Oliver
Twist by Charles Dickens) – the hash is fixed at 64
characters
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
7 Main Properties of
Hashing
Hashing is deterministic
The same input will always produce the same output
Input: fun
Output:
00C4285274FCC5D6FBA2EE58DAF0D8C2B9B825B68D
35D65D0E90A9BB333A51B5
Input: sun
Output:
27756F050E14A1CB1C1EE867F0EACE9EA4D9FCB81B8
BEE089469F1EBD5FD7B17
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
8 Main Properties of
Hashing
Hashing is a one-way function
It is infeasible to determine what the input was from any
given output
That is to say, it is virtually impossible to reverse the hash
function with contemporary technology
The only way to determine what the input was is trying out
random strings until you find the right one
This method is known as brute force.
Using brute force to reverse the hash back to the original
string is easier said than done
Even IBM Summit, currently the fastest computer in the
world, capable of making several trillion calculations per
second, would need many years and an astounding amount
of electricity to find the answer for a single hash
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
9 Main Properties of
Hashing
Hashing is resistant to collisions
A collision occurs when a hashing mechanism produces the
same output for two different inputs
This is possible in theory for hashing, as the number of unique
hashes is limited but the number of inputs is not
The probability of collisions is extremely small
Hashing is thus said to be resistant, but not immune, to
collisions
SHA-256, the algorithm used by Bitcoin, outputs hashes that
are 256 bits long (a 256 digit-long string of 1s and 0s)
This means there are a total of 2256 unique hashes that it can
produce
As soon as the number of inputs is larger than the number of all
possible outputs, let us say 2256+1, at least two of the inputs
will have the same output – that’s a collision.
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
10 Concept of Double Spending
Double-spending is the risk that a cryptocurrency can be used twice or more
Transaction information within a blockchain can be altered if specific conditions are met
The conditions allow modified blocks to enter the Blockchain
If this happens, the person that initiated the alteration can reclaim spent coins
When a block is created, it receives a hash—or encrypted number—that includes a
timestamp, information from the previous block, and transaction data
This information is encrypted using a security protocol like the SHA-256 algorithm used
by Bitcoin
Once that block's information is verified by miners (in proof-of-work consensus), it is
closed, and a new one is created with the timestamp, transaction information, and
previous block's hash
A Bitcoin is awarded to the miner whose machine verified the hash
For someone to double spend, a secret block has to be mined that outpaces the creation
of the real Blockchain
They would then need to introduce that chain to the network before it caught up
If this happened, then the network would recognize it as the latest set of blocks and add
it to the chain
The person that did this could then give themselves back any cryptocurrency they had
spent and use it again.
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
11 Preventing Double
Spending
Double spending remains a risk; however, it is minimized by the Blockchain
The likelihood of a secret block being inserted into the blockchain is very
slim because it has to be accepted and verified by the network of miners
The only chance a miner with illicit intentions has of inserting an altered
block is to attempt to get another user to accept a transaction using their
secret block and cryptocurrency
Even then, the likelihood that the modified block will be accepted is very
less
The blockchain and consensus mechanism move so quickly that the
modified block would be outdated before it was accepted
Even if it was accepted, the network would still have passed up the
information in the block and would reject it
Cryptocurrency transactions take some time to verify because the process
involves randomly selecting numbers to solve the complex hash—this also
takes up a great deal of computational power
It is, therefore, exceedingly difficult to duplicate or falsify the blockchain
because of the immense amount of computing power needed to stay ahead
of all of the other miners on the network
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
12 Double Spending
Attacks
The most significant risk for blockchains comes in the form of
a 51% attack
It can occur if a miner controls more than 50% of the
computing power that validates the transactions, creates
blocks, and awards cryptocurrency
If this user—or users—controls a majority of the hashing in the
blockchain, they will be able to dictate transaction consensus
and control the award of currency
In more popular cryptocurrencies such as Bitcoin, this is very
unlikely due to the number of miners and hashing difficulty it
has reached
New or forked cryptocurrencies with smaller networks are
susceptible to this attack
The unconfirmed transaction attack is used to fool
cryptocurrency users
If you see one of these transactions, you shouldn't accept it
because it can cause an attempted double-spend attack
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
13 Mining
Blockchain mining is a peer-to-peer computer process and is used
to secure and verify bitcoin transactions
Mining involves blockchain miners who add bitcoin transaction data
to Bitcoin’s global public ledger of past transactions
In the ledgers, blocks are secured by blockchain miners and are
connected to each other forming a chain
Bitcoin transactions are generally verified in decentralized clearing
systems wherein people contribute computing resources to verify
the same
This process of verifying transactions is called mining
It is probably referred to as mining as it is analogous to mining of
commodities like gold
A lot of computing power is consumed in the process of mining
bitcoins
The number of bitcoins that are generated from mining dwindles
over time. In the words of Satoshi Nakamoto, there is only a limited
supply of bitcoins
Only 21 million bitcoins will ever be created
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
14 Mining
The term ‘Blockchain mining’ is used to describe the process of adding
transaction records to the bitcoin Blockchain
This process of adding blocks to the blockchain is how transactions are
processed and how money moves around securely on Bitcoins
It is performed by a community of people around the world called
‘Blockchain miners.’
Anyone can apply to become a blockchain miner
These Blockchain miners install and run a special blockchain mining
software that enables their computers to communicate securely with
one another
Once a computer installs the software, joins the network, and begins
mining bitcoins, it becomes what is called a ‘node.’
Together, all these nodes communicate with one another and process
transactions to add new blocks to the blockchain which is commonly
known as the bitcoin network
This bitcoin network runs throughout the day
It processes equivalent to millions of dollars in bitcoin transactions and
has never been hacked or experienced downtime since its launch in
2009
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
15 Types of Mining
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
16 Individual Mining
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
17 Pool Mining
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
18 Cloud Mining
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
19 Mining Bitcoins (in
Cloud)
Obtain a bitcoin wallet:
Bitcoins are stored in digital wallets in an encrypted manner.
This will keep your bitcoins safe.
Secure the wallet:
Since there is no ownership of bitcoins, anyone who gains access to your blockchain wallet can use it
without any restriction.
So, enable two-factor authentication and store the wallet on a computer that does not have access to
the Internet or store it on an external device.
Choose a cloud mining service provider:
Cloud mining service providers allow users to rent processing or hashing power to mine bitcoins
remotely.
Popular cloud mining service providers are Genesis Mining and HashFlare.
Choose a cloud mining package:
To choose a package, you will need to decide on how much you are willing to pay and keep your eyes
open to the hashing power the package will offer.
Cloud mining companies will mostly envisage the Return on Investment (ROI) based on the current
market value of Bitcoins.
Pick a mining pool:
This is the best shot you can get to earn bitcoins easily.
There are many mining pools which charge a mere 2 percent of your total earnings.
Over here, you will have to create workers which are basically subaccounts that can be used to track
your contributions to the pool.
Put your earnings in your own secure wallet:
01/05/20
Whenever you witness an ROI, simply withdraw your earnings and put them in your own secure25
wallet.
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
20 Mining Bitcoins (on your own)
Purchase custom mining hardware:
You need to purchase an Application-specific Integrated Circuit (ASIC) miner to mine
bitcoins.
While purchasing an ASIC Blockchain miner, you should consider its efficacy in
hashing power and take note of its pricing policies.
Purchase a power supply:
Blockchain miners consume a lot of power.
So, get a dependable power supply that is compatible with the ASIC miner that you
purchase.
Obtain a bitcoin wallet:
Bitcoins are stored in digital wallets in an encrypted manner.
This will keep your bitcoins safe.
Secure the wallet:
Since there is no ownership on bitcoins, anyone who gains access to your wallet can
use it without any restriction.
So, enable two-factor authentication and store the wallet on a computer that does
not have access to the Internet or store it in an external device.
Pick a mining pool:
This is the best shot you can get to earn bitcoins easily.
There are many mining pools that charge a mere 2 percent of your total earnings.
01/05/20
Over here, you will have to create workers which are basically subaccounts that
25 can
be used to track your contributions to the pool.
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
21 Uses of Blockchain
Mining
a. Validating Transactions
Bitcoin transactions take place in huge figures every day.
Cryptocurrencies function without a central administrator and the
insecurity can be substantial with the transactions that transpire.
With each transaction, new blocks are added to the blockchain in
the network and the validation lies in the mining results from the
blockchain miners.
b. Confirming Transactions
Miners work the blockchain mining process to confirm whether
the transaction is authentic or not.
All confirmed transactions are then included in the blockchain.
c. Securing Network
To secure the transaction network, bitcoin miners work together.
With more users mining the blockchain, blockchain network
security increases.
Network security ensures that there are no fraudulent activities
happening with cryptocurrencies.
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
22 Proof of Work (PoW)
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
23 Consensus Mechanism
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
24 Consensus Mechanism
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
25 Proof of Work (PoW)
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
26 Proof of Work (PoW)
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
27 Proof of Work (PoW)
Adding a new block to the chain is considered a new update to the current
system.
It, therefore, requires permission from network participants.
In order to decide whether to add a new block or not, Proof-of-Work (PoW), a
consensus mechanism, is used.
Only verified transactions are added to the network.
In contrast, not all blocks are valid.
Most proposed block networks are considered invalid.
The Blockchain protocol defines the validity of a block.
The blockchain network has an arbitrary “Difficulty” setting managed by the
protocol that changes how hard it is to mine a block.
Mining here means adding a new block.
Miners design new blocks in the chain.
They are externals who want to add their block to the network.
The work required to develop a valid block is where the value comes from.
Miners receive rewards in proportion to their share of the computing power they
spend mining a new block.
The miner proves the work done by mining a valid block.
01/05/20
The difficulty level can vary in blockchains such as the Bitcoin network or 25
Ethereum to ensure that blocks are created at regular intervals.
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
28 How does PoW algorithm work?
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
30 How does PoW algorithm work?
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
31 How does PoW algorithm work?
Harry will change the nonce until he gets the first 3 digits as zeros.
After continuously changing the nonce for hours, he finally got the hash.
Harry block Hash: 000383ec5
Hash difficulty: 001000000
Nonce: 6778
The difficulty threshold has now been reached. Block Hash < Hash
Difficulty.
Therefore, Harry’s block will be marked as valid and added to the
blockchain.
For mining a block in the Bitcoin blockchain, Harry gets a few Bitcoins as a
block reward for spending the computing power to find a valid hash
This process is completely based on chance
So the miner’s job is to change the nonce value until the total hash of the
block is lower than the difficulty hash.
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
32 Advantages of Proof-of-
Work
A hard-to-find solution
Easy verification.
As an initial consensus mechanism, PoW does not need
initial stakes of coins before mining.
One can start with 0 coins and it will only be positive.
Ease of implementation compared to other blockchain
consensus mechanisms.
It is fault tolerant.
Give miners the opportunity to earn by adding a block.
PoW is the oldest, most trusted, and most popular
consensus protocol.
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
33 Limitations of Proof-of-
Work
A lot of energy is wasted because only one miner can
finally add their block.
Massive consumption of resources and energy.
51% risk of network attack
A controlling person can get 51% to control the network.
Spread environmental hazards with attachment
machines.
PoW is a time and energy wipe-out process.
It required a lot of hardware costs.
Risk of Denial of Service Attacks by Intruders.
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
34 Proof of Work vs. Proof of Stake
Proof of work and Proof of stake are two discrete consensus mechanisms for
cryptocurrency, but there are important differences between them.
Both methods confirm incoming transactions and add them to the
blockchain.
With Proof of Stake, network participants are known to as “validators” other
than miners.
One important difference is that instead of solving math problems,
validators lock up a set amount of cryptocurrency – their stake – in a smart
contract on the blockchain.
In interchange for “staking” cryptocurrency, they get a chance to prove new
transactions and earn a reward.
If they incorrectly verify wrong or fraudulent data, they may lose some or all
of their deposit as a penalty.
Proof of stake makes it easy to involve more people in blockchain systems
as validators.
There is no need to buy expensive computing systems and consume huge
amounts of electricity to bet cryptocurrencies except a few coins.
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
35 Introduction to Merkel
Tree
A hash tree, also known as a Merkle tree, is a tree in
which
each leaf node is labelled with the cryptographic hash
of a data block
each non-leaf node is labeled with the cryptographic
hash of its child nodes' labels
The majority of hash tree implementations are
binary (each node has two child nodes), but they
can also have many more child nodes.
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
36 What is a Merkel Tree?
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
37 What is a Merkel Tree?
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
38 What is a Merkel Root?
A Merkle root is a simple mathematical method for confirming
the facts on a Merkle tree.
They're used in cryptocurrency to ensure that data blocks
sent through a peer-to-peer network are whole, undamaged,
and unaltered.
They play a very crucial role in the computation required to
keep cryptocurrencies like bitcoin and ether running.
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
39 Working of Merkel Trees
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
41 Example
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
42 Benefits of Merkle Tree in Blockchain
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
43 Why is it essential to Blockchain?
Think of a blockchain without Merkle Trees to get a sense of how vital they
are for blockchain technology.
Let’s take Bitcoin scenario because its use of Merkle Trees is essential for
the cryptocurrency.
If Bitcoin didn't include Merkle Trees, per se, every node on the network
would have to retain a complete copy of every single Bitcoin transaction
ever made
One can imagine how much information that would be
Any authentication request on Bitcoin would require an enormous amount of
data to be transferred over the network: therefore, you'll need to validate
the data on your own
To confirm that there were no modifications, a computer used for validation
would need a lot of computing power to compare ledgers
Merkle Trees are a solution to this issue
They hash records in accounting, thereby separating the proof of data from
the data itself
Proving that giving tiny amounts of information across the network is all
that is required for a transaction to be valid
01/05/20
Furthermore, it enables you to demonstrate that both ledger variations
25 are
identical in terms of nominal computer power and network bandwidth
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
44 Data Privacy and Blockchain
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
47 Data Threat Mitigation
steps
Limit personal data stored in the blockchain:
Avoid putting personal data on a blockchain.
The financial system does not involve a naïve user.
Avoid payload for storing personal data on the
blockchain.
Use one-time addresses to secure data in the
blockchain.
Supply management chain to limit data on the
blockchain.
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
48 Blockchain Privacy Management
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
49 Payment Verification
Simple Payment Verification, usually abbreviated to
SPV, is a system that enables light clients (wallets
running on low-end systems) to verify that a
transaction has been included in Bitcoin and therefore
a payment has been made.
This is possible by using the Merkle tree to store the
transactions in each block
A Merkle tree is a structure created by grouping all the
transactions in pairs and hashing them together, then
proceeding to hash the resulting hashes together and
continuing this process till there is only one hash left,
called the merkle root.
This creates a tree where every node has two children,
which can be used to create their parent node.
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
50 Payment Verification
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
51 Payment Verification
Someone that only knows the Merkle root/top hash can verify
if a transaction is part of the tree, that is, if it’s been included
into a Bitcoin block.
This is done by taking the nodes that are in the path that
connects the Merkle root with one of the bottom transactions
and bundling them together to create a proof:
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
52 Payment Verification
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
53 Resolving Conflicts and Creation
of Blocks
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
54 Resolving Conflicts and Creation
of Blocks
From the above-given steps, in step 5, a conflict can arise
where multiple miners create blocks at the same time and try
to add them to the last valid block of the Blockchain
In this case which block will be appended to the blockchain?
Consider Steve, Jake and Iris are miners in the blockchain and
they simultaneously create their respective blocks which are
known as candidate blocks (represented in green, yellow, and
blue respectively).
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
55 Resolving Conflicts and Creation
of Blocks
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
57 Resolving Conflicts and Creation
of Blocks
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
58 Resolving Conflicts and Creation
of Blocks
01/05/20
25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
59 Resolving Conflicts and Creation
of Blocks
01/05/20
25