0% found this document useful (0 votes)
2 views5 pages

CS201 Report Template

This document outlines a project simulating a blockchain system using a local peer-to-peer network, focusing on transaction validation and security measures against unauthorized changes. Key components include linked lists for block connections, Merkle trees for data integrity, and consensus algorithms for transaction approval. The simulation demonstrates how transactions are added and how the system maintains security by comparing local copies across the network to prevent data tampering.

Uploaded by

2023aib1008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

CS201 Report Template

This document outlines a project simulating a blockchain system using a local peer-to-peer network, focusing on transaction validation and security measures against unauthorized changes. Key components include linked lists for block connections, Merkle trees for data integrity, and consensus algorithms for transaction approval. The simulation demonstrates how transactions are added and how the system maintains security by comparing local copies across the network to prevent data tampering.

Uploaded by

2023aib1008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Simulation of a Blockchain System

March 26, 2025


Ojas Jain (2022CSB1099) ,
Sanat Gupta (2022CSB1119) ,
Jitender Jangra (2022MCB1318)

Summary: In this CS201 Project, we tend to create a local peer-to-peer network of


Instructor: users that work on the system of blockchain technology. This simulation involves
Dr. Anil Shukla the use of linked lists for connecting the blocks in a blockchain and the use of
Merkle trees to get the hash value of all the combined information stored in the
Teaching Assistant: given block. In this simulation, we would see how transactions are added into a
Neeraj Dwivedi blockchain system by a valid user and how security is ensured, that is what happens
when a hacker tries to break into the system and change the details of some of the
transactions.

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.

1.1. Distributed and Decentralized

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.

Figure 1: Types of Network

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.

Figure 2: P2P Network with 4 nodes


Showing each node with its own local copy

1.3. Components of a Block in a Blockchain

Each block in a blockchain system has four major components:


1.Block Number: These block numbers serve as a way to track the chronological order of transactions and
data stored within the blockchain.
2.Transaction Data: Transactions are like the essential pieces of information stored in a block. They repre-
sent digital actions, like sending or receiving cryptocurrency, running smart contracts, or sharing data. Each
transaction includes details about who sent it, who received it, how much, and other important information.
3.Previous Hash: This component contains the pointer to the root of the Merkle tree of the previous block,
thereby establishing a connection between the two blocks. Hence, this part is responsible for linking the
blockchain.
4.Current Hash: It contains the pointer to the root of the Merkle tree of the current block. SHA512 algorithm
is used to obtain the hash values, which is derived from all the other three components of the block. Any changes
made to these components are reflected in the changed hash value.

Figure 3: Components of Blockchain

1.4. Merkle Tree

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

1.5. Consensus Algorithm

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).

2.1. Consensus Algo

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.

2.2. Linked List

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.

Figure 5: Linking of Blocks

2.3. Merkle Tree

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).

2.4. How Secure Is The Blockchain Network?

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.

3. Psuedo-Codes & Algorithms

Algorithm 1 Adding Transaction to a Block


1: function transaction(amount, user1, user2, root):
2: transactionstr = concatenate(user1, amount, user2)
3: if rootisN U LL then
4: create and initialize a new block
5: else
6: find the last block in the chain
7: create and initialize a new block linked to the last block
8: end if
9: increment blockNo
10: return root

Algorithm 2 Comparing the Local Chains


1: function check(comparant, c1, c2, c3):
2: counter = 0
3: create a temporary pointer ’temp’ to the comparant
4: create a temporary pointer ’temp1’ to the c1
5: if temp′ slastblock ′ shash = temp1′ slastblock ′ shash then
6: increment counter
7: end if
8: create a temporary pointer ’temp2’ to the c2
9: if temp′ slastblock ′ shash = temp2′ slastblock ′ shash then
10: increment counter
11: end if
12: create a temporary pointer ’temp3’ to the c3
13: if temp′ slastblock ′ shash = temp3′ slastblock ′ shash then
14: increment counter
15: end if
16: return counter

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

The resources utilized for this project are listed hereby:


1.www.geeksforgeeks.com
2.GITHUB
3.ChatGPT (For getting precise and useful information about blockchain)
4.YouTube Channels:
a.5 Minutes Engineering
b.CppNuts
6.www.investopedia.com

You might also like