CS201 Report Template
CS201 Report Template
1. Introduction
You might have often come across the word ’BLOCKCHAIN’. Let us try to understand what exactly is a
blockchain system and how it works.
A blockchain is a decentralized, distributed and public digital ledger that is used to record transactions across
many computers so that the record cannot be altered retroactively without the alteration of all subsequent
blocks and the consensus of the network. Too much jargon right? So let us see what each of these terms really
mean in a simplified manner.
A decentralized system is a system where there is no single point of control or authority. The planning and
decision making are distributed evenly among several independent entities or nodes. Each node can act inde-
pendently and autonomously, without relying on a central coordinator or leader. A decentralized system can
be resilient to failures, censorship, and attacks, as there is no single point of failure or vulnerability.
A public digital ledger is a database that is consensually shared and synchronized across and accessible to
multiple people. It allows transactions to have public "witnesses." The participant at each node of the network
can access the recordings shared across that network and can own an identical copy of it. Any changes or
additions made to the ledger are reflected and copied to all participants in a matter of seconds.
1
1.2. Peer-to-Peer Network
A peer-to-peer network in blockchain is the basic framework where individual computers, known as nodes, work
together to store and update a common record of digital transactions. In this decentralized system, each node
holds its own local copy of the blockchain and communicates directly with others to confirm and share data,
eliminating the need for a central authority and enhancing security and transparency.
A Merkle tree is a binary tree data structure where every leaf node represents a piece of data, and every non-
leaf node is a cryptographic hash of its child nodes. This hierarchical structure allows for efficient and secure
verification of data integrity.
In blockchain, Merkle trees are primarily used to ensure the security and efficiency of transaction verification.
It is specified hereby.
Data Integrity: Merkle trees help ensure the integrity of transaction data within a block. Each leaf node of the
tree represents an individual transaction, and the internal nodes are cryptographic hashes of their child nodes.
This hierarchical structure makes it easy to check if any transaction has been tampered with, as any change in
the data would lead to a different root hash. Users and nodes in the network can quickly verify that the data
in a block hasn’t been altered.
Proof of Inclusion: Merkle trees allow for the creation of proofs that a specific transaction is included in a block
without revealing the entire content of the block. This is useful for lightweight clients or applications that don’t
want to download and store the entire blockchain but still need to verify specific transactions.
2
Figure 4: Merkle Tree
Consensus algorithms play a fundamental role in ensuring the security, reliability, and integrity of distributed
systems, including blockchain technology. These algorithms help network participants (nodes) agree on the
validity of transactions added to the blockchain.
Some of the consensus algorithms primarily used in the actual blockchain technology are:
1.Proof of Work (PoW)
2.Proof of Stake (PoS)
3.Proof-of-Authority (PoA)(Clique Consensus)
2. Our Simulation
Basic idea of implementation:
The idea involves creation of four local nodes(on the same computer) which are forming a peer-to-peer network.
Now, when a transaction is added by reading input, which includes the users between whom the transaction
has taken place and the amount of transaction, its validation is subjected to the consensus of all the users in
the network(including the user adding the transactions).
At first, according to this algorithm, a transaction will only be added to the blockchain when it gets a major-
ity(>=51 percent) in the network. In this project, due to constraints of programming language and required
knowledge, this part is taken as input from all the users if they want to validate this transaction or not. Once
it gets a majority, the block(transaction) gets added in the chain.
When the block gets added to the chain, it is added to the local copy of each user in the network. Each local
copy is simple a blockchain containing various data like block number, transactions data, current and previous
hash.
The current hash value in the block of the chain contains a pointer to the root of the Merkle tree, which itself
contains the hash value obtained in the tree. The Merkle tree is simply a binary tree. For the sake of simplicity,
the height of Merkle tree is kept three.
The first as well as second node of the last level contains the unique and non-duplicable value of transaction
data obtained using SHA512 function(algorithm).
The third node contains the unique and non-duplicable value of the block number, whereas the fourth node
3
contains the unique and non-duplicable value of the previous hash value, both of which are again obtained using
SHA512 function(algorithm).
Now, in a blockchain network when a user(in most cases an unauthorized user) tries to corrupt any data in
the existing blockchain it is prevented by running a thread in the background. The thread simply checks all
the local copies in the network after a certain time(which is much less in an actual network). Whenever there
is a change in data, as thread simultaneously checks all the local chains, and if any chain has different data,
then it is compared with rest of the local chains, and if this change reflects in the majority of the local chains,
then change is made in the rest of the local chains as well. As there are thousands or more nodes in an actual
blockchain so it is a tedious task to change/corrupt data in the majority of the local chains thus preventing
hackers/ unauthorized users from making changes in the blockchain.
Now, this is again simulated as an algorithm in which when a change is made in a local chain, then the
current hash of the block gets changed, leading to the change of current and previous hash from thereon.Then
a comparison is called in which each local chain is compared with rest of chains in the network and the rest
follows as in threading i.e. if the change in a local copy is there in the majority then it copies this change in
the rest of the chains else, reverse the change from that very chain as well.
4
Algorithm 3 Reverting the Transaction Data
1: function compareNcopy(first, second):
2: temp1 = first
3: temp2 = second
4: while temp1isnotN U LLandtemp2isnotN U LLandtemp1′ shashisequaltotemp2′ shash do
5: move to the next node in both lists
6: end while
7: while temp2isnotN U LL do
8: copy data from temp2 to temp1
9: move to the next node in both lists
10: end while
4. Conclusions
Basically this project is a simulation of the actual blockchain network in which a local p2p network is created
and the transaction is done, which gets added to the blockchain after getting validated.
Now the main advantage of the blockchain technology is that it is very difficult( nearly impossible in a public
blockchain network) to make changes in the blockchain as after an interval the blockchains(local) are compared
to each other simultaneously so if any changes is to be made in the blokchain it is to be made in majority of
the local chains.
To simulate this in the project, when any change is made in a local chain of an user then it is compared to each
local file in the network. As this change would not be in majority so this change would be prevented in the
blockchain.
5. Bibliography
Acknowledgement
We would like to extend a heartful thanks to our project mentor Mr.Neeraj Dwivedi for guiding us throughout
the project and providing invaluable inputs.
Further we are pleased to mention Ms.Shruti Mishra(2022csz0011) for giving us useful insights about concepts
of blockchain technology.
References