2. CO Num CO
CO742.1
Summarize the terminologies and types of
Blockchain.
CO742.2
Integrate yarious cryptographic algorithms in to
BlockChain.
CO742.3
Implement Ethereum Block Chain using various tools
and frameworks learnt.
CO742.4 Enumerate the Bitcoin feafures and its protocols.
CO742.5
Discuss about alternative block chains available and
various applications of BlockChain.
5. Blockchain consists of a list of records. Such records are stored in blocks.
These blocks are in turn linked with other blocks and hence constitute a
chain called Blockchain
7. A blockchain consists of programs called scripts that conduct the tasks you usually
would in a database: Entering and accessing information and
saving and storing it somewhere.
A blockchain is distributed, which means multiple copies are saved on many
machines, and they must all match for it to be valid.
The blockchain collects transaction information and enters it into a block, like a
cell in a spreadsheet containing information. Once it is full, the information is run
through an encryption algorithm, which creates a hexadecimal number called the
hash.
The hash is then entered into the following block header and encrypted with the
other information in the block. This creates a series of blocks that are chained
together.
8. What Is a Blockchain?
A blockchain is a peer-to-peer network of nodes that all talk to one
another.
These nodes are essentially computers that share responsibilities
similar to web servers, like running programs and storing data that
can be accessed whenever you're connected to the blockchain.
All the nodes work together to create a public network that anyone
can connect to.
Blockchain is used for the secure transference of items like money,
contracts, property rights, stocks, and even networks without any
requirement of Third Party Intermediaries like Governments,
banks, etc.
9. Blockchain nodes
A node is a computer connected to the Blockchain Network. Node gets
connected with Blockchain using the client.
The client helps in validating and propagating transactions onto the
Blockchain.
When a computer connects to the Blockchain, a copy of the Blockchain
data gets downloaded into the system and the node comes in sync with the
latest block of data on Blockchain.
The Node connected to the Blockchain which helps in the execution of a
Transaction in return for an incentive is called Miners.
10. The Blockchain is used for the secure transfer of items like
money, property, contracts, etc, without requiring a third-party
intermediary like a bank or government
Once data is recorded inside a Blockchain, it is very difficult to
change it.
11. Once the data is stored in the Blockchain it becomes very
difficult to manipulate the stored data.
A Blockchain is a Network Protocol like SMTP. However,
Blockchain cannot be run without the Internet.
Blockchain is useful in many areas like Banking, Finance,
Healthcare, Insurance, etc. A blockchain is an open,
distributed ledger that can record transactions between two
parties efficiently and in a verifiable and permanent way
without the need for a central authority.
12. Open: Anyone can access blockchain.
Distributed or Decentralized: Not under the control of
any single authority.
Efficient: Fast and Scalable.
Verifiable: Everyone can check the validity of
information because each node maintains a copy of the
transactions.
Permanent: Once a transaction is done, it is persistent
and can’t be altered
13. Blockchain can be defined as the Chain of Blocks that contain
some specific Information.
Thus, a Blockchain is a ledger i.e file that constantly grows
and keeps the record of all transactions permanently.
This process takes place in a secure, chronological
(Chronological means every transaction happens after the
previous one) and immutable way.
Each time when a block is completed in storing information, a
new block is generated.
14. A node can be defined as an individual player in a distributed
system.
All nodes are capable of sending and receiving messages to
and from each other.
There is no Central Server or System which keeps the data of
Blockchain.
The data is distributed over Millions of Computers around the
world which are connected with the Blockchain.
This system allows Notarization of Data as it is present on
every Node and is publicly verifiable.
15. We can view blockchain as an integration
of the following innovations:
1.Peer-to-peer networks.
2.Cryptography.
3.Smart contracts.
4.Consensus mechanisms.,
16. A network of nodes: A node is a computer connected to the
Blockchain Network.
Node gets connected with Blockchain using the client. Client
helps in validating and propagates transaction on to the
Blockchain.
When a computer connects to the Blockchain, a copy of the
Blockchain data gets downloaded into the system and the node
comes in sync with the latest block of data on Blockchain.
The Node connected to the Blockchain which helps in the
execution of a Transaction in return for an incentive is called
Miners.
21. A Characteristic Block Chain achieves data in block units,
where every block comprises the cryptographic hash of the
previous block in the block chain for connecting the two head-
to head blocks.
Connections of blocks are known as chains.
Here every party distributes information & scope consensus in
agreement with guidelines decided in advance.
22. Parts of a Block Chain:
Consortium Blockchain
Consortium blockchains are managed and run by a number of
organizations or entities.
As a permissioned blockchain, users must be asked to join and
have authorization before they can access the network.
Private Blockchain
private blockchain has an in-charge who monitor important task
and give access to read or block access.
It is also known as permissioned blockchain as it has restrictions
on who can participate in transactions and validations.
25. 1991 : The conceptual frame
work behind blockchain was first put
forward by a group of researchers
The idea was initially intended for time-stamping digital documents such
that backdating them will not be possible thereafter
2008 : The idea went mostly unused until it was again mentioned by
Satoshi Nakamoto in his white paper “Bitcoin: A Peer-to-Peer Electronic
Cash System”
Satoshi Nakamoto, an anonymous person/group is said to be behind the
first blockchain, which is Bitcoin
2009 : Bitcoin is the first blockchain came into existence
26. Cash can only be used in low amount transaction locally.
Huge waiting time in the processing of transactions.
Need to third party for verification and execution of
Transaction make the process complex.
If the Central Server like Banks is compromised, whole
System is affected including the participants.
Organization doing validation charge high process thus
making the process expensive.
27. Blockchain is a decentralized database that does not require a third
party to conduct transactions, whereas banks require third parties to
perform transactions.
Blockchain can allow for speedy transactions across international
borders, while traditional banking can be slower and more expensive.
Traditional banking offers a range of financial services that may not
be available through blockchain platforms.
The banking system is characterized by central banks which have
some degree of control over commercial banks, while a private
blockchain does not have a central authority and therefore the system
is decentralized.
28. Layman's definition: Blockchain is an ever-growing,
secure, shared record keeping system in which each user
of the data holds a copy of the records, which can only
be updated if all parties involved in a transaction agree
to update.
Technical definition: Blockchain is a digital,
decentralized, distributed public ledger database where
blocks are linked cryptographically, and transactions are
digitally signed and managed using consensus model.
29. Peer-to-peer – no central controller
Distributed ledger – ledger is spread across
the network
Cryptographically secure – for security
Append only
Immutable – can’t change the data
consensus-driven
30. Blockchain enhances trust across a business network.
Blockchain builds trust through the following five
attributes:
◦ Distributed: The distributed ledger is shared and updated with
every incoming transaction among the nodes connected to the
Blockchain. All this is done in real-time as there is no central
server controlling the data.
◦ Secure: There is no unauthorized access to Blockchain made
possible through Permissions and Cryptography.
31. ◦ Transparent: Because every node or participant in Blockchain
has a copy of the Blockchain data, they have access to all
transaction data. They themselves can verify the identities
without the need for mediators.
◦ Consensus-based: All relevant network participants must agree
that a transaction is valid. This is achieved through the use of
consensus algorithms.
◦ Flexible: Smart Contracts which are executed based on certain
conditions can be written into the platform. Blockchain
Network can evolve in pace with business processes.
33. Blockchain Vs Cryptocurrency
It is important to note that blockchain and cryptocurrency are
not the same thing.
Bitcoin is a cryptocurrency, but blockchain is the underlying
technology behind Bitcoin. Blockchains can be used for other
purposes besides cryptocurrency
36. How Does a Blockchain Work?
The transaction process in a blockchain can be summarized as follows:
1. Facilitating a transaction: A new transaction enters the blockchain network. All the
information that needs to be transmitted is doubly encrypted using public and private keys.
2. Verification of transaction: The transaction is then transmitted to the network of peer-
to-peer computers distributed across the world. All the nodes on the network will check for
the validity of the transaction like if a sufficient balance is available for carrying out the
transaction.
3. Formation of a new block: In a typical blockchain network there are many nodes and
many transactions get verified at a time. Once the transaction is verified and declared a
legitimate transaction, it will be added to the mempool. All the verified transactions at a
particular node form a mempool and such multiple mempools form a block.
37. 4. Consensus Algorithm: The nodes that form a block will try to add the
block to the blockchain network to make it permanent.
But if every node is allowed to add blocks in this manner then it will disrupt
the working of the blockchain network.
To solve this problem, the nodes use a consensus mechanism to ensure that
every new block that is added to the Blockchain is the one and only version
of the truth that is agreed upon by all the nodes in the Blockchain, and only a
valid block is securely attached to the blockchain.
The node that is selected to add a block to the blockchain will get a reward
and hence we call them “miners”. The consensus algorithm creates a hash
code for that block which is required to add the block to the blockchain.
38. 5. Addition of the new block to the blockchain: After the newly
created block has got its hash value and is authenticated, now it is
ready to be added to the blockchain.
In every block, there is a hash value of the previous block and that is
how the blocks are cryptographically linked to each other to form a
blockchain. A new block gets added to the open end of the blockchain.
6. Transaction complete: As soon as the block is added to the
blockchain the transaction is completed and the details of this
transaction are permanently stored in the blockchain. Anyone can fetch
the details of the transaction and confirm the transaction.
39. 1. Distributed Shared Ledger:
A Ledger is a record of all relevant transactions.
A Distributed shared Ledger is a replicated
ledger, maintained by the participating nodes as
a record of transactions.
In this case, Blockchain is the data structure of
the ledger.
A shared ledger allows the authorized
participants to access monitor and analyze the
state of a transaction in its lifecycle.
40. 2. Unlike the traditional databases, ledgers can only do manipulation
operations, which includes insertion and selection, within the data structure
of the block and its linked list.
Its equivalent time stamps combine the receipt, thus creating trusted data sets
that are linking and difficult to alter.
3. Decentralized governance:
It is a decentralized technology and every node will maintain the ledger, and
if any data changes happen, the ledger will get updated.
The process of updating takes place independently at each node.
Even small updates or changes made to the ledger are reflected and the
history of that change is sent to all participants in a matter of seconds.
41. 4. Traditional model VS Smart contacts
In traditional model, contract is signed manually by the business stakeholders,
once validated then only payment process is completed by finance team.
Smart contracts are simply programs stored on a blockchain that run when
predetermined conditions are met.
They typically are used to automate the execution of an agreement so that all
participants can be immediately certain of the outcome, without any
intermediary’s involvement or time loss.
They can also automate a workflow, triggering the next action when conditions
are met.
42. Smart contact is a set of logical guidelines that is coded using
script and can be integrated with the blockchain to manage
transaction.
Contract works as smart code agents.
Once integrated, it turns into an independent agent that is
always tamper proof.
A transaction is a sharing of assets(digital/physical) that is
governed under the guidelines and access rights of objective
service.
43. A consensus mechanism is a procedure through
which all the peers of the Blockchain network reach
a common agreement about the present state of the
distributed ledger.
It confirms that each newly appended block is
authentic.
45. All types of blockchains can be characterized as permissionless,
permissioned, or both.
Permissionless blockchains allow any user to pseudo-anonymously join the
blockchain network (that is, to become “nodes” of the network) and do not
restrict the rights of the nodes on the blockchain network.
Conversely, permissioned blockchains restrict access to the network to
certain nodes and may also restrict the rights of those nodes on that network.
46. Public blockchains are not owned by anyone.
They are permissionless & open to the public,
and anyone can participate or access it without
any kind of permission as a node in the
decision-making process.
Visible by anyone
Consensus process is open to all party.
Full decentralized.
Example: Bitcoin
47. A blockchain network that works in a restrictive
environment like a closed network, or that is under the
control of a single entity, is a private blockchain.
Open to individuals or organizations who have decided to
share the ledger among themselves.
Permissioned blockchains
Use privileges to govern.
private blockchains restrict access for users, only allowing
those within a specific organization or who have passed
Know Your Customer (KYC) checks and have been
approved by the system administrator into the network.
Example: Corda and Quorum(for financial transactions).
48. Consortium Blockchains
Consortium blockchains are permissioned blockchains
governed by a group of organizations, rather than one
entity, as in the case of the private blockchain.
consortium or federated blockchains allows multiple
organizations to share data across the network privately
and securely.
Consortium blockchains, result in higher levels of
security.
A popular set of consortium blockchain solutions for the
financial services industry developed by the enterprise
software firm R3.
49. Hybrid blockchains
Hybrid blockchains are blockchains derives its
features from public and private blockchains
Consensus model is governed by known nodes,
called priviledged nodes.
Agreement for the set of guidelines and
instructions agreed to by all parties.
Relplicas of the blockchain are shared only
among the permitted member nodes.
Network is partially is decentralized.
IPwe, powered by the IBM hybrid blockchain
50. A ledger is a collection of transactions
Works in append only mode
Before, pen and paper ledgers
In modern times, ledgers have been stored digitally, often in
large databases owned and operated by a centralized trusted
third party (i.e., the owner of the ledger)
Can be implemented in a centralized or distributed fashion.
Distributed ledgers use independent nodes to record, share,
and synchronize transactions in their respective electronic
ledgers instead of keeping them in one centralized server.
54. Public Distributed Ledger Technologies
Public DLT can be imagined as Bitcoin and Ethereum.
Object/ group of objects cannot take govern of the ledger and
insert into deceitful transactions.
It is included in public ledgers to check the current and
historical transactions without using any third party mediators.
These use consensus controls such as proof of work /proof of
stake.
55. Private Distributed Ledger Technologies
These are totally safe from non authenticated node and possess
all private transaction information, can only be accessed by the
ledger nodes.
Since number of nodes are less, they may be little bit more
vulnerable towards attacks.
These use consensus algorithms such as Practical Byzantine
Fault tolerance (PBFT), Raft and Paxos.
58. A block is actually the building block or the key element of a
blockchain.
Each block contains a different number of transactions.
These transactions are contained in blocks so that they would be
added to the distributed ledger.
The number of transactions is limited by the block size and gas
limit. Generally, the block contains more than 500 transactions.
Other than transactions, a block also consists of some metadata.
This metadata is stored in the header of the blockchain.
59. A transaction is a record that transfers assets such as currency and inventory
units from one party to another.
Visible transaction happens when these fields are contained in any operation:
1. Amount : total quantity of assets transferred over a
transaction.
2. Inputs: list of assets that will participate in a transaction.
input assets are identified by unique values that do not
match with other assets.
3. Outputs: these are the final parties that will receive the hashed processed
assets when the transaction occurs.
Output requires the value to be transacted to the new node, the
key(ID) of the new node, group of rules that ensure the new node
must receive the processed transaction based value.
60. 4. Hash Id: it’s a key or unique identity for any transaction.
5.Asymmetric key Public Private key cryptography: Asymmetric
cryptography is useful because it uses two different keys: a private key and a
public key.
The private key is used for signing messages and decrypting data, while the
public key is used for validating signatures and encrypting data.
6. Addresses: these are short alphanumeric strings.
An address is derived from the public key utilizing hash function. Its like an
ID on a blockchain for individual user.
Most of the time address will be changed into a QR code to use it in a easier
way.
7. Private key storage: Blockchain users use software wallet which can
store private keys, public keys and corresponding addresses.
61. 8. Ledgers: these are archived digitally, frequently in large
databases possessed and functioned by trusted and centralized
third party body for user community.
Blockchain ledger is replicated and shared between each node
within the network.
When a new transaction is appended to the block, this block will
be shared among all network nodes and all ledgers will be
reorganized by updating new transactions.
62. 9. Block
A block in a Blockchain contains list of records (called
transaction data), a timestamp (UNIX time) and cryptographic
hash of previous block (hash converts the previous block data
into a fixed length of random data).
63. Process of finding nonce:
•The person(miner) must guess a value of nonce (it can start with 000…0001)
•Get the hash value of block header of previous block (000dceb75a135c…)
•Append that nonce before the hash of block header (000…
0001000dceb75a135c…)
•Rehash the above appended value (xyz)
•Get the difficulty value from the block header (abc)
•Check if the above rehashed value is less than the difficulty value or not (xyz
< abc)
•If yes, then a new block is added in the current Blockchain of the Bitcoin
and this person is rewarded some bitcoins for his work
64. A Merkle tree is a representation of data
Bottom most row is the transaction data in a form of leaf and
child node.
Second to bottom row shows data being hashed.
This row’s data is joined and hashed again.
Finally the hash root is formed, which is the representation of all
the transaction data into a single hash key.
67. Hash of the previous block: Every block header gives
information about the previous or parent block.
Version: This field stores the version number to show software
upgrades.
Timestamp: This field contains the time at which the block was
created.
nonce: The nonce serves as a piece of arbitrary and unique data
that miners must include in their blocks when attempting to
solve the proof of work algorithm/ to resolve hash puzzle.
Merkle tree root: A Merkle tree is a structure obtained from
hashing the transactional data of a block.
68. What is hashing?
Hashing is a form of cryptography.
A hash function is any function that
can map arbitrary-size data to fixed-
size values.
Values returned by a hash function
are called hash values, hash codes,
digests, or simply hashes.
Hash function gives cryptocurrency
a high level of security.
69. Some famous hashing algorithms used in Blockchain are:
1.Secure Hash Algorithm (SHA-256) (collision resistant
algorithm)
2.Federal Information Processing Standard( FIPS)
3.Elliptic Curve Digital Signature Algorithm(ECDSA)
71. Blockchain applications can be classified based on:
1.Development Platform:
A blockchain network removes need for a centralized database
because everyone in the network can see the transactions and
also validate them.
This creates trust and transparency between participants in the
network.
There are too many blockchain development frameworks to
explore. The most popular and widely used frameworks in the
blockchain development world are:
Ethereum
Hyperledger Fabric
Corda
Quorum
72. 2. Smart Contract Accelerator
Smart contracts are simply programs stored on a blockchain
that run when predetermined conditions are met.
They typically are used to automate the execution of an
agreement so that all participants can be immediately certain of
the outcome, without any intermediary’s involvement or time
loss.
Smart contracts work by following simple “if/when…then…”
statements that are written into code on a blockchain.
Smart contracts can be used in:
Digital notarization for legal work.
Multi party transactions
73. 3. Marketplace
A blockchain-based marketplace enables crypto payments and
intermediary-free exchange of goods between sellers and buyers.
Buyers can view the origins and history of goods stored on the
blockchain, which builds trust to sellers and makes the deals
more transparent.
74. Banking and payments
◦ Bitcoin like cryptocurrencies can control the payment systems without
any geopolitical restrictions
Cyber Security
◦ Data is verified and secured using cryptography. It removes the
middlemen from the system so no one can make any unauthorized
changes
Supply chain
◦ Any product can be tracked completely using the blockchain supply
chain management
Online Data Storage
◦ Allows distributed data storage in a more secure and robust way
Networking and IoT
◦ Can be applied in Networking and IoT to create a decentralized
network of IoT devices
75. Insurance
◦ Blockchain ensures trust by mutual distrust between participants
Crowdfunding
◦ Trust is built through smart contracts and online reputation systems
◦ Eliminates the need for a central party
◦ New projects can release their own tokens that can later be exchanged
for products, services or cash
Multimedia and entertainment
◦ Will remove the middleman from the scenario
◦ Online music is one of the entertainment areas where blockchain has
already started their implementation
Real estate
◦ Can control the entire real estate systems with shared ledgers
78. Characteristics of Centralized
Systems:
1.Global clock:
The system comprises central system based
node, a master server and many nodes work
as client or slave.
All the nodes are synced on the basis of
the global clock that exist in the central
server.
2. Single Central Unit:
This consists of central unit that assists/
synchronizes all the other system nodes.
79. 3. Failure Prone:
If the central system fails, it becomes the reason of the
entire system failure.
4. Scaling:
Central system proposes on vertical scaling. Nodes can
add computing resources.
80. 5. Components and Architecture:
Components of centralized system comprise of nodes
that can be any device such as computer, mobile etc.
It also contains object such as cables and internet
components.
Example: Facebook, Twitter
81. Advantages of the centralized systems
It is easy to secure and service the server and client nodes by virtue of their
location.
Smooth and elegant personal experience — A client has a dedicated system
that he uses (personal computers) and the organization has a similar system
that can be modified to suit customer needs.
Dedicated resources (memory, CPU cores, etc.)
As the central systems take fewer funds to set up, they have an edge when
small systems must be built.
Quick updates are possible — Only one machine to update.
Easy detachment of a node from the system. Just remove the connection of the
client node from the server.
82. Disadvantages of the centralized systems
Centralized systems are highly dependent on network connectivity
— A system can fail if the nodes lose connectivity as there is only
one central node.
No graceful degradation of the system — abrupt(unconscious)
failure of the entire system.
Less possibility of data backup. If the server node fails and there is
no backup, you lose the data straight away.
Difficult server maintenance — There is only one server node and
due to availability reasons, it is inefficient and unprofessional to take
the server down for maintenance.
84. Characteristics of Decentralized systems
1.There is no global clock such as that of central system. Every
node is autonomous and owns different clocks and there is no
synchronization among them.
2.Comprises of various central processing units.
3.If one of the node fails, system does not fail; it only affects the
part of the system.
4.Decentralized systems can scale horizontally and vertically.
5.Components of Decentralized Systems are same as centralized
Systems
Example: Bit Torrent File sharing system
85. Advantages of Decentralized Systems
1.There’s no traffic issue as the load can be balanced
across nodes.
2.Highly available as one node can take charge of others
in case of failure at node, network etc.
3.Provide better overall control as nodes are independent
and follow self governing mechanisms.
86. Difficult to achieve global big tasks
Difficult to know which node failed – Each node must be
pinged for availability checking and partitioning of work has
to be done to actually find out which node failed by checking
the expected output with what the node generated
Difficult to know which node responded – When a request is
served by a decentralized system, the request is actually
served by one of the nodes in the system but it is actually
difficult to find out which node indeed served the request.
87. A distributed system is a collection of computer programs that
utilize computational resources across multiple, separate
computation nodes to achieve a common, shared goal. Also
known as distributed computing.
Example :
Electronic banking systems
88. Characteristics of distributed systems
1.Concurrency works here, and consensus controls are required
to have agreement on transaction values and log commands.
2.Nodes have their own clock; no global clock exists in the
network.
3.Failure of network node does not affect the whole system. So
provides high availability.
4.It can scale both horizontally and vertically.
5.Components of Decentralized Systems are same as centralized
Systems
89. Advantages of Distributed System –
Low latency than a centralized system – Distributed systems
have low latency because of high geographical spread, hence
leading to less time to get a response.
Disadvantages of Distributed System –
Consensus mechanism is difficult here because it looks for
logging into events at the absolute time when it happens, and it s
not possible.
90. Decentralization It is a type of distributed system where no single
entity has majority administrative control
The basic idea of decentralization is to distribute control
and authority to the peripheries of an organization instead of
one central body being in full control of the organization.
This configuration produces several benefits for organizations,
such as increased efficiency, expedited decision making, better
motivation, and a reduced burden on top management.
Any blockchain network such as Bitcoin, Ethereum,
Hyperledger Fabric, or Quorum can be used to provide
decentralization service.
91. The critical difference between a decentralized system and
distributed system is that in a distributed system, there still
exists a central authority that governs the entire system;
whereas, in a decentralized system, no such authority exists.
A Decentralized system is a type of network where nodes are not
dependent on a single master node; instead, control is
distributed among many nodes.
This mechanism came into play with Bitcoin, and it enables a
user to agree on something via a consensus algorithm without
the need for a central, trusted third party, intermediary, or
service provider.
92. Method can be used to achieve decentralization:
Disintermediation
Disintermediation
The concept of disintermediation can be
explained with the aid of
an example:
Imaginethat you want to send
money to a friend in another
country.
You go to a bank, for a fee, will transfer your money
to the
bank in that country.
Here the bank maintains a
central database that is updated,
confirming that you have sent the money.
93. 29-06-2021
With blockchain technology, it is possible to send this money
directly to your friend without the need for a bank.
All you need is the address of your friend on the blockchain.
This way, the intermediary; that is, the bank, is no
longer required, and decentralization is achieved by
disintermediation.
so we can say, Disintermediation is a process of achieving
transactions between two parties by removing the
requirements of mediators or third party.
94. 29-06-2021
DApp examples
Examples of some decentralized applications are
provided
here.
1.KYC-Chain
This application provides the facility to manage Know
Your Customer (KYC) data securely and conveniently
based on smart contracts.
2.OpenBazaar
This is a decentralized peer-to-peer network that enables
commercial activities directly between sellers and buyers
instead of relying on a central party, such as eBay and
Amazon.
95. 2.3 Blockchain Race
Conditions
Race conditions are a common
vulnerability in smart contracts.
A race condition occurs when multiple
transactions attempt to modify the
same state variable at the same time.
When this happens, it is unclear which
transaction will be processed first, and
the outcome of the smart contract
becomes unpredictable.
96. One example of a race condition vulnerability is the
reentrancy attack.
In this attack, a malicious actor exploits a race condition to
call a contract function multiple times before the function
has completed its previous execution.
This can lead to unexpected behavior, such as the
attacker being able to withdraw more funds than they are
entitled to.
To prevent race conditions in smart contracts, developers
should use locking mechanisms to ensure that only one
transaction can modify a state variable at a time.
97. Example:
Now, let’s say two users, Alice and David, want to transfer
tokens to each other at the same time. Alice calls the transfer
function with David's address as the recipient and 100 tokens as
the amount. At the same time, David calls the transfer function
with Alice's address as the recipient and 50 tokens as the
amount.
What is the result?
If two or more transactions try to increment the state
variable at the same time, a race condition can occur.