Fundamentals of Blockchain
Fundamentals of Blockchain
S/AP-CSE/VISTAS
Blockchain 1.0, Blockchain 2.0, Blockchain 3.0, Types of Blockchain: Public Blockchain,
Private Blockchain, Semi-Private Blockchain, Sidechains.
Proof of Stake, Proof of Work, Delegated Proof of Stake, Proof Elapsed Time, Deposite-Based
Consensus, Proof of Importance, Federated Consensus or Federated Byzantine Consensus,
Practical Byzantine Fault Tolerance. Blockchain Use Case: Supply Chain Management
Text Books:
T1: Mastering Blockchain: Deeper insights into decentralization, cryptography, Bitcoin, and
popular Blockchain frameworks by Imran Bashir, Packt Publishing (2017).
1
SATHEA SREE.S/AP-CSE/VISTAS
What is blockchain?
Blockchain is a shared, immutable ledger that facilitates the process of recording transactions
and tracking assets in a business network.
A block chain network can track orders, payments, accounts, production and much more. And
because members share a single view of the truth, you can see all details of a transaction end to
end, giving you greater confidence, and new efficiencies and opportunities.
2
SATHEA SREE.S/AP-CSE/VISTAS
3
SATHEA SREE.S/AP-CSE/VISTAS
The hacker gets incentives as well for the fake blocks that have been mined and
confirmed.
Double spending can never arise physically. It can happen in online transactions. This mostly
occurs when there is no authority to verify the transaction. It can also happen if the user’s wallet
is not secured. Suppose a user wants to avail of services from Merchant ‘A’ and Merchant ‘B’.
Example: Suppose a user has 1 BTC. He/She wants to avail of services from merchant A and
merchant B. The user creates multiple copies of the same BTC and stores it. The user first sends
the original BTC to Merchant A and gets the service. Simultaneously, the user sends the copied
version of 1 BTC to Merchant B. Since the second transaction was not confirmed by other
miners, the merchant accepts the bitcoin and sends the service. But the cryptocurrency that was
sent is invalid. This is the case of Double Spending.
4
SATHEA SREE.S/AP-CSE/VISTAS
Finney Attack: Finney Attack is a type of Double spending Attack. In this, a merchant accepts
an unauthorized transaction. The original block is eclipsed by the hacker using an eclipse attack.
The transaction is performed on an unauthorized one. After that, the real block shows up and
again the transaction is done automatically for the real block. Thus the merchant loses money
two times.
Race attack: is an attack in which there is a ‘race’ between two transactions. The attacker sends
the same money using different machines to two different merchants. The merchants send their
goods but transactions get invalid.
51% Attack: This type of attack is prevalent in small blockchains. Hackers usually take over
51% of the mining power of blockchain and therefore can do anything of their own will.
Bitcoin is one of the most popular blockchains. To combat Double spending it uses some
security measures. There are two types of examples of double spending in BTC.
Case 1: Creating duplicates of the same Bitcoin and sending them to multiple users.
Case 2: Reversing a transaction after receiving the service.
To tackle these double-spending issues, some security measures are taken. They are:
Validation:
5
SATHEA SREE.S/AP-CSE/VISTAS
A block is added to the pending transactions list only after sufficient validations.
Timestamp:
Block Confirmations:
Network Redundancy:
A user wants to spend 2 BTC. He/She can create multiple copies of the same
cryptocurrency.
The user can send the same cryptocurrency to two different addresses say ‘Bob’ and
‘Alice’.
Both of these transactions are sent to the pool of unconfirmed transactions.
The first transaction T1 would be approved via the confirmation mechanism.
The confirmation mechanism states that a minimum of six confirmations by miners
should be done for block validation. The block is added to the network.
However, the second transaction T2 didn’t get sufficient confirmation so it would be
recognized as invalid by the confirmation process. The block with the highest number of
confirmations is accepted and the other one is rejected. So transaction T1 is valid, and
Alice received the bitcoin.
6
SATHEA SREE.S/AP-CSE/VISTAS
Double spending, a critical challenge in digital transactions, can be effectively mitigated through
centralized and decentralized approaches:
Centralized Approach:
o Utilizes a trusted third party to verify transactions and maintain user balances.
o Transactions are identified uniquely and verified by the third party before
approval.
o Limitations include dependency on a central authority and potential cross-border
transaction complexities.
o Failure of the centralized system can result in widespread access issues for users.
Decentralized Approach:
Double spending, a critical concern in digital transactions, can be effectively mitigated through
proactive measures and robust security features:
7
SATHEA SREE.S/AP-CSE/VISTAS
User Responsibilities:
o Transaction Confirmations:
Users should wait for a minimum of six confirmations before conducting
subsequent transactions.
Increased confirmations by various network participants reduce the
likelihood of double spending attacks in blockchain systems.
o Hardware Security:
Safeguarding hardware resources is essential to prevent unauthorized
access.
Hardware theft can potentially enable attackers to manipulate transactions
or alter data.
o Software Maintenance:
Regularly update software and install antivirus programs to mitigate
vulnerabilities.
Outdated software can harbor bugs that malicious actors exploit for
fraudulent activities.
8
SATHEA SREE.S/AP-CSE/VISTAS
The Byzantine army is divided into many battalions in this classic problem called the
Byzantine General’s problem, with each division led by a general.
The generals connect via messenger in order to agree to a joint plan of action in which all
battalions coordinate and attack from all sides in order to achieve success.
It is probable that traitors will try to sabotage their plan by intercepting or changing the
messages.
As a result, the purpose of this challenge is for all of the faithful commanders to reach an
agreement without the imposters tampering with their plans.
Requires all loyal generals to agree on a single course of action despite unreliable
communication. In Bitcoin, the agreed-upon truth is the blockchain.
Blockchain: A public, distributed ledger recording all Bitcoin transactions. All nodes
(users) need to agree on the order and occurrence of these transactions for the system to
function.
Decentralized Consensus: Since there's no central authority, Bitcoin relies on a consensus
mechanism (proof-of-work) to validate transactions.
Proof-of-Work (PoW): Miners compete to solve complex puzzles to add new transaction
blocks to the blockchain. This makes the system:
9
SATHEA SREE.S/AP-CSE/VISTAS
Byzantine Agreement: All honest nodes agree on a single initial value chosen by one
node.
10
SATHEA SREE.S/AP-CSE/VISTAS
Consensus: All honest nodes agree on a common value, but each node may have started
with a different value.
All ledgers must be consistent across the network, meaning they reflect the same reality.
A "Byzantine fault" can be a digital signal stuck between "0" and "1," causing
unpredictable outputs in circuits.
This is solvable with redundancy: even a faulty signal has minimal impact if there are
enough good ones (like a majority vote).
Distributed systems address this by using protocols like Byzantine Fault Tolerance (BFT)
inspired by BGP.
BFT ensures consistent data and reliable operations despite potential Byzantine failures .
Public-Key Cryptography:
Most of the time blockchain uses public-key cryptography, also known as asymmetric-key
cryptography. Public key cryptography uses both public key and private key in order to encrypt
and decrypt data. The public key can be distributed commonly but the private key cannot be
shared with anyone. It is commonly used for two users or two servers in a secure way.
11
SATHEA SREE.S/AP-CSE/VISTAS
Public Key: Public keys are designed to be public. They can be freely given to everyone or
posted on the internet. By using the public key, one can encrypt the plain text message into the
cipher text. It is also used to verify the sender authentication. In simple words, one can say that a
public key is used for closing the lock.
Private Key: The private key is totally opposite of the public key. The private key is always kept
secret and never shared. Using this key we decrypt cipher text messages into plain text. In simple
words, one can say that the private key is used for opening the lock.
In symmetric-key cryptography, a single key is used to encrypt and decrypt the message. Here,
the possibility of data loss or unauthorized access to data is high. To overcome the unauthorized
access of data and data sent securely without any loss, we use public-key cryptography.
Public-key cryptography is more secure than symmetric-key cryptography because the public
key uses two keys to encrypt and decrypt the data
Public-key cryptography allows users to hide the data that they want to send. The sender
encrypts the data and the receiver decrypts the data. The encrypted message is not understood by
unauthorized users.
Suppose, the sender wants to send some important message to the receiver.
The sender first creates a message in the form of plain text which is in a readable format.
The sender knows the public key of the receiver but doesn’t know the private key of the
receiver because the receiver keeps secret his private key. With the help of the public key
of the receiver and the private key of the sender, the sender generates the encrypted
message i.e. called cipher text. Cipher text is in an unreadable format. In this step, plain
text converts into cipher text.
Now, cipher text reaches the receiver end. The receiver knows its own private key, and
with the help of the private key receiver converts the cipher text into readable format i.e.
plain text.
12
SATHEA SREE.S/AP-CSE/VISTAS
Let us try to understand the working of public-key cryptography with an example. Suppose
Sachin is the sender who wants to send a message to Anurag. Here Anurag is the receiver.
Sachin uses Anurag’s public key to encrypt the message and Anurag uses his own private key to
decrypt the message.
First Sachin creates plain text. Sachin has access to Anurag’s private key and cipher text. Using
Anurag’s public key and his own public key,
Sachin will generate an encrypted message i.e. cipher text which is in an unreadable format.
After applying the encryption process plain text converts into cipher text.
Now, Anurag receives a cipher text. First Anurag will decrypt the cipher text message into a
readable format. For decrypting Anurag will use the private key. Now cipher text converts into
plain text and is readable by the receiver. Because Sachin keeps his private key, Anurag knows
that this message couldn’t have come from anyone else. This is also called a digital signature.
Authentication: It ensures to the receiver that the data received has been sent by the only
verified sender.
Data integrity: It ensures that the information and program are changed only in a
specific and authorized manner.
Data confidentiality: It ensures that private message is not made available to an
unauthorized user. It is referred to as privacy or secrecy.
Non-repudiation: It is an assurance that the original creator of the data cannot deny the
transmission of the said data to a third party.
Key management: Public-key cryptography allows for secure key management, as the
private keys are never transmitted or shared. This eliminates the need for a secure
channel to transmit the private key, as is required in symmetric key cryptography.
Digital signatures: Public-key cryptography allows for the creation of digital signatures,
which provide non-repudiation and can be used to verify the authenticity and integrity of
data.
Key exchange: Public-key cryptography enables secure key exchange between two
parties, without the need for a pre-shared secret key. This allows for secure
communication even if the parties have never communicated before.
Secure communication: Public-key cryptography enables secure communication over an
insecure channel, such as the internet, by encrypting the data with the public key of the
recipient, which can only be decrypted by the recipient’s private key.
Versatility: Public-key cryptography can be used for a variety of purposes, such as
secure communication, digital signatures, and authentication, making it a versatile tool
for securing data and communications.
13
SATHEA SREE.S/AP-CSE/VISTAS
One can encrypt and decrypt the fixed size of messages or data. If there is an attempt to
encrypt or decrypt a large size of the message then the algorithm demands high
computational power.
The main disadvantage of this algorithm is that if the receiver losses its private key then
data/message will be lost forever.
If someone has access private key then all data will be in the wrong hand.
There are many secret-key which is faster than public-key cryptography.
Key distribution: The process of securely distributing public keys to all authorized
parties can be difficult and time-consuming, especially in large networks.
Performance: Public-key cryptography is generally slower than symmetric-key
cryptography due to its more complex algorithms, making it less suitable for applications
that require fast processing speeds.
Security assumptions: Public-key cryptography relies on mathematical assumptions
about the difficulty of certain problems, such as factoring large numbers, which may not
hold true in the future. As a result, public-key cryptography is vulnerable to future
advancements in computing power and algorithmic breakthroughs.
Susceptibility to man-in-the-middle attacks: Public-key cryptography is vulnerable to
man-in-the-middle attacks where an attacker intercepts and alters the public key before it
reaches the intended recipient. This can result in the attacker being able to decrypt the
message or impersonate the sender.
Complexity: Public-key cryptography can be more complex to understand and
implement than symmetric-key cryptography, requiring specialized knowledge and
expertise.
Blockchain – Private Key Cryptography
Private key encryption is an encryption method that allows users to send and receive
information securely over a network. As part of the blockchain, private key cryptography is
used to ensure the security of transactions and ownership of digital assets.
What is Private-Key Cryptography?
Private key cryptography also known as symmetric-key cryptography is an encryption method
in which a single key is used to encrypt and decrypt data. This key is kept secret between the
sender and receiver and is used to encrypt and decrypt messages. Private key encryption is
widely used to secure communications over the Internet because it ensures that only the
intended recipient can read the message.
In private key cryptography, to encrypt a message, the sender uses a key to scramble the
plaintext into ciphertext. Cipher text can only be decrypted with the same key, known only
to the sender and receiver.
Although private key encryption is useful for secure communications, it has some
limitations. One of the biggest limitations is key distribution. Since the same key is used
for encryption and decryption, both the sender and receiver must have the key. This can be
difficult to achieve, especially when communicating with multiple parties.
To overcome this limitation, public key cryptography was developed. Public key
cryptography, also known as asymmetric key cryptography, uses two keys (public and
private) to encrypt and decrypt data. The public key is used for encryption and the private
key is used for decryption. It allows users to communicate securely without sharing keys.
14
SATHEA SREE.S/AP-CSE/VISTAS
1. Key generation: First, a secret key is generated. The key is a long string of random
characters that are kept secret by the sender and receiver.
15
SATHEA SREE.S/AP-CSE/VISTAS
2. Encryption: To encrypt a message, the sender uses a key to scramble the plaintext into
ciphertext. The sender then sends the ciphertext to the receiver.
3. Decryption: To decrypt the ciphertext, the recipient uses the same key that was used to
encrypt the message. The receiver applies the reverse operation of the encryption algorithm
to the ciphertext to recover the original plaintext message.
Private key cryptography provides security because the key is kept secret between the sender
and receiver. Anyone intercepting the ciphertext cannot decrypt it without knowing the key.
This means that private key cryptography can be used to ensure message confidentiality.
Hashing:
A hash function maps the data of any arbitrary size to data of fixed size. Bitcoin uses
SHA-256 hash function that produces a hash (output) of size 256 bits (32 bytes).
16
SATHEA SREE.S/AP-CSE/VISTAS
Bob, while placing an order with Lisa, creates a message similar to the one shown above.
This message is hashed through a hash function that produces a 32 byte hash. The beauty of
this hash is for all practical purposes the hash (the 256-bit number) is considered unique for
the contents of the message. If the message is modified, the hash value will change. Not only
that given a hash value, it is impossible to reconstruct the original message.
After having seen the importance of hashing, let us move on another concept in Bitcoin that
is mining.
Distributed systems:
Distributed systems are a computing paradigm whereby two or more nodes work with each other
in a coordinated fashion in order to achieve a common outcome and it's modeled in such a way
that end users see it as a single logical platform.
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. Nodes can be honest, faulty, or
malicious and have their own memory and processor. A node that can exhibit arbitrary behavior
is also known as a Byzantine node. This arbitrary behavior can be intentionally malicious, which
is detrimental to the operation of the network. Generally, any unexpected behavior of a node on
17
SATHEA SREE.S/AP-CSE/VISTAS
the network can be categorized as Byzantine. This term arbitrarily encompasses any behavior
that is unexpected or malicious:
The main challenge in distributed system design is coordination between nodes and fault
tolerance. Even if some of the nodes become faulty or network links break, the distributed
system should tolerate this and should continue to work flawlessly in order to achieve the desired
result. This has been an area of active research for many years and several algorithms and
mechanisms has been proposed to overcome these issues.
Distributed systems are so challenging to design that a theorem known as the CAP theorem has
been proved and states that a distributed system cannot have all much desired properties
simultaneously. In the next section, a basic introduction to the CAP theorem will be provided.
The CAP Theorem, also known as Brewer's Theorem, states that a distributed data system
can only guarantee two of the following three properties:
18
SATHEA SREE.S/AP-CSE/VISTAS
Consistency: All nodes in the system have the same, latest data at any given time.
Availability: Every request receives a response, even if the data is not yet consistent
(e.g., temporary error).
Partition Tolerance: The system continues to operate even if the network is divided
(partitioned) due to failures.
Fault Types:
The lecture will explore how Blockchain achieves properties that might seem to violate
CAP.
Key Points:
19
SATHEA SREE.S/AP-CSE/VISTAS
Lamport et al. (1982) proposed the Byzantine Generals Problem (BGP) as a thought
experiment for coordinating an attack despite unreliable messengers.
BGP is analogous to achieving consensus in distributed systems with potentially faulty nodes.
Generals represent nodes, traitors represent Byzantine nodes, and messengers represent
communication channels.
Practical Byzantine Fault Tolerance (PBFT) by Castro and Liskov (1999) and Bitcoin's Proof-
of-Work (PoW) (2009) offer solutions for achieving consensus.
BGP helps understand challenges in unreliable environments and the need for consensus
mechanisms in distributed systems.
Consensus
Consensus is a process of agreement between distrusting nodes on a final state of data. In order
to achieve consensus different algorithms can be used. It is easy to reach an agreement between
two nodes (for example in client-server systems) but when multiple nodes are participating in a
distributed system and they need to agree on a single value it becomes very difficult to achieve
consensus. This concept of achieving consensus between multiple nodes is known as distributed
consensus.
Consensus mechanisms
A consensus mechanism is a set of steps that are taken by all, or most, nodes in order to agree on
a proposed state or value. For more than three decades this concept has been researched by
computer scientists in the industry and Academia. Consensus mechanisms have recently come
into the limelight and gained much popularity with the advent of bitcoin and blockchain.
There are various requirements which must be met in order to provide the desired results in a
consensus mechanism. The following are their requirements with brief descriptions:
20
SATHEA SREE.S/AP-CSE/VISTAS
There are various types of consensus mechanism; some common types are described as
follows:
Example –
A number of processes in a network decide to elect a leader. Each process begins with a bid for
leadership. In traditional or conventional distributed systems, we apply consensus to ensure
reliability and fault tolerance. It means, in a decentralized environment when you have multiple
individual parties, and they can make their own decision, then it may happen that some node or
some parties are working maliciously or working as a faulty individual. So in those particular
cases, it is important to come to a decision or common point of view. So having a common point
of view in an environment where people can behave maliciously or people can crash the work in
a faulty way, is the main difficulty. So under this kind of distributed environment, our objective
is to ensure reliability which means to ensure correct operation in the presence of faulty
individuals.
Features :
21
SATHEA SREE.S/AP-CSE/VISTAS
Safety Property – It ensures that you will never converge to an incorrect value or correct
individuals in a network will never converge to an incorrect value.
Liveness Property – It states that every correct value must be accepted eventually which
means something good will eventually happen.
Termination Property – It guarantees that every correct process will eventually decide
on a value. This ensures that the protocol will eventually terminate.
Agreement Property – It guarantees that all correct processes will eventually agree on a
single value. This ensures that all correct nodes in the network will come to a consensus.
Fault Tolerance – Distributed consensus protocols must be able to handle failures and
errors, both in the network and in the participating nodes. This ensures that the system
remains correct and functional even in the presence of faults.
Byzantine Fault Tolerance – Some distributed consensus protocols, like PBFT, have the
additional property of Byzantine Fault Tolerance (BFT). This means they can tolerate up
to a certain number of malicious nodes in the network without compromising safety and
liveness properties.
Scalability – The protocol must be able to scale to handle large networks and increasing
numbers of nodes without sacrificing safety, liveness, or fault tolerance. This ensures that
the protocol can be used in real-world scenarios with a large number of participants.
Leader election in a fault-tolerant environment for initiating some global action without
introducing a single point of failure.
Maintaining consistency in a distributed network. Suppose you have different nodes
monitoring the same environment. If one of the nodes crashes, a consensus protocol
ensures robustness against such faults.
Blockchain technology: Distributed consensus is a fundamental concept in blockchain
technology, which allows multiple nodes to agree on a shared database without relying on
a central authority.
22
SATHEA SREE.S/AP-CSE/VISTAS
Introduction
The blockchain tech stack is a multi-layered architecture that enables the creation of
decentralized, trustless systems for securely storing and transferring digital assets without
intermediaries. Each layer of the stack has a specific role and is essential for the overall
functionality and security of the blockchain.
Protocols are a set of rules that allow data to be shared across the network. They are a set of
guidelines that facilitate the exchange of information in a simple, efficient, and secure way.
Different machines use different hardware and software but protocols help in communication
irrespective of the difference. The protocols play a very important role as they help to monitor
and secure a computer network.
A blockchain is a chain of blocks where each block is used to store information and each block is
associated with a unique address in terms of hash. It is a distributed, decentralized ledger that
stores data such as transactions and is shared publicly across all the nodes that are present in the
network. Ledger means the main record which holds the list of transaction records and
distributed means that each machine is connected to one another. So there is no involvement of
any central authority or middlemen which satisfies the property of decentralization.
But to maintain how data is transferred across the networks in a secured manner, a set of
protocols is required. Since blockchains are used for transactions, protocols play a very
important role in data sharing so as to maintain the security of the cryptocurrency networks.
Blockchain protocols are a set of protocols used to govern the blockchain network. The rules
define the interface of the network, interaction between the computers, incentives, kind of data,
etc. The protocols aim to address the four principles:
Security: Protocols maintain the security of the whole crypto network. Since the network
involves the transfer of money so protocols define the structure of data and also secure data from
the malicious users.
23
SATHEA SREE.S/AP-CSE/VISTAS
Consistency: Whenever a transaction occurs, protocols update the whole database at each step
so that each user is well versed with the whole crypto network.
Scalability: Scalability means an increase in the number of transactions. Earlier scalability was
an issue in the blockchain. But nowadays most protocols handle the issue of an increasing
number of transactions in the network and the addition of nodes to the network.
24
SATHEA SREE.S/AP-CSE/VISTAS
2. Quorum: Quorum is another enterprise blockchain protocol that aims to address the problems
related to finance. It is open source project associated with Ethereum. It is open-source and
nowadays has become one of the best enterprise blockchain frameworks.
4. Enterprise Ethereum: Ethereum is one of the public blockchain suite protocols. It defines the
platform for decentralized applications. It is the blockchain of choice for developers and
enterprises, who are creating technology based upon it to change the way many industries
operate.
25
SATHEA SREE.S/AP-CSE/VISTAS
1. Protocol Layer
2. Consensus Layer
Description: The consensus layer ensures that all nodes agree on the state of the
distributed ledger, maintaining security and consistency even with potential malicious
actors or network issues.
Functions: Achieves agreement on the ledger's state across the network.
Examples:
o Proof of Work (PoW): Used by Bitcoin.
o Proof of Stake (PoS): Used by Ethereum 2.0.
o Partial Byzantine Fault Tolerant (PBFT): Used by Hyperledger.
o Delegated Proof of Stake (DPoS): Used by EOS.
Description: This layer manages the storage of transactions and blocks in a blockchain,
utilizing specific data structures and distributed databases.
Functions: Stores transactional data, potentially includes off-chain data, and ensures
secure data management.
Examples:
o LevelDB and RocksDB: Databases used for blockchain data.
o IPFS and Filecoin: For off-chain data storage.
o AWS S3 or Google Cloud Storage: Traditional cloud storage options.
o Security Technologies: Secure key management systems (e.g., HSMs), multi-
signature wallets, and authentication mechanisms (e.g., OAuth, JWT).
4. Logic Layer
Description: The Logic or Smart Contracts layer encodes business logic and rules,
facilitating the execution of smart contracts.
Functions: Uses virtual machines (VMs) to execute smart contracts in an isolated
environment.
Examples:
o Bitcoin Script: For Bitcoin smart contracts.
26
SATHEA SREE.S/AP-CSE/VISTAS
5. Application Layer
Description: The Application Programming Interface (API) layer provides interfaces and
dashboards for developers and users to interact with the blockchain.
Functions: Facilitates the creation of applications that leverage blockchain functionality,
including accessing data, sending transactions, and managing accounts.
Examples:
o Web3.js and Ether.js: For Ethereum interaction.
o REST API: For Hyperledger Fabric.
o JSON-RPC and RESTful APIs: General APIs.
o Frontend Technologies: Node.js, Python, Go, HTML, CSS, JavaScript, React,
Angular, and GraphQL.
Description: Decentralized applications (dApps) built on the blockchain use its features
such as immutability, security, and decentralization.
Functions: Utilize smart contracts to enable various functionalities across different use
cases.
Use Cases:
o Finance: DeFi platforms, cryptocurrency exchanges.
o Supply Chain Management: Tracking and verifying goods.
o Digital Identity: Secure identity verification and management.
27