Lecture Notes - Basics of Blockchain
Lecture Notes - Basics of Blockchain
Blockchain Basics
Session 1 – Basic Idea Of Blockchain
In this session you have learnt the basic components of blockchain technology as follows:
• Database systems
• Role of intermediaries
• What is a blockchain?
Further in the session, you learned important concepts related to blockchain technology as follows:
Listed below are the critical points of differentiation between the three types of systems we encountered so far.
Substantial processing
overheads to ensure Massive overheads to
Low; Redundancy is ensure appropriate
Overheads and Costs
minimized proper coordination coordination among
multiple nodes
among servers
Points of Failure / Single point of failure; A limited number of points of Multiple points of failure;
Maintenance Easy to maintain failure; Maintenance more Difficult to maintain
Feature Centralised Decentralised Distributed
complex than centralised
systems
Stability better than centralised
Highly unstable; if the systems; the network can The highest level of
central server fails, continue to operate at a reduced stability; single node
Stability
entire network level failure doesn’t affect the
collapses network
if any one server fails
Scalability Low scalability Moderately scalable Infinitely scalable
Ease of Setup Easy to set up Difficult to set up Difficult to set up
Intermediary
An intermediary generally plays the role of a trusted middle party in any transaction, which connects two
parties that are usually unknown to each other.
Disadvantages of Intermediaries
Traditionally, the significance of intermediaries lay in establishing trust among unknown parties. However,
involving intermediaries also carries with it a fair share of drawbacks such as:
• Monetary charges
• Process inefficiencies
• Security concerns.
To create the blockchain network, Satoshi used various existing technologies and techniques. You learnt
those in detail.
Digital Signatures
Just like the normal signature, a digital signature also acts as verifier of the authenticity of the sender.
There are two types of digital signatures:
• Symmetric digital signatures: In symmetric digital signatures, one single key is used to encrypt
the messages. The sender encrypts the message with that key and sends it to the receiver. Once
the receiver receives it, they need the same key to decrypt or unlock that message. So, the sender
also shares the key he/she encrypted the message with so that the receiver can use it to decrypt
the message.
• Asymmetric Digital Signatures: In Asymmetric Digital Signatures, a pair of public and private key
is used. A message encrypted with a public key can only be decrypted with the corresponding
private key of the public-private key pair and vice versa. The public key of each participant is shared
across the network and private key is held secret only with the individual.
Hashing
Hashing is an encryption technique which is used to encrypt the data to ensure data security. Hashing is
done using hash functions. The hash function is a mathematical function that can take in any length of
input and convert it to an output of fixed length.
The hash of a data serves like a fingerprint for that data. Hash uniquely represents that data. Even a small
change in the data generates an entirely random and different hash. Also, you learnt that each hashing
algorithm, irrespective of the size of the data generates the hash of a fixed length which is a characteristic
of that hashing algorithm.
The hash function has many properties. Some of them are listed below.
Public Hash functions are publicly Encryption services using hash functions can be
availability available easily rolled out
Any-length The inputs to cryptographic hash Any length of input strings can be processed
input functions can be of any length through the hash function for encryption
Merkel Tree
Merkel Tree is a way of organizing data points in the blockchain. The output of a Merkle tree is a
Merkle root. The Merkle tree utilizes hash functions to arrive at the Merkle root by recursive hashing.To
arrive at the Merkle root of “n” number of elements, you have to follow the below steps:
.Even the smallest of the changes in any of the data points will change its hash and hence the root hash
will also be changed. Thus root hash is the fingerprint representing all the datapoints.
The Merkle trees help in verifying transaction data on a block by acting as a unique identifier for the transactions.
Hash Cash
Hash cash
Hash cash is a proof of work the sender of an email must do before sending an email. The sender must
calculate the hash of the email data and make sure that the calculated hash satisfies a predefined
condition. This limits the scope of spam emails. The technique of hash cash is used in the process of
creation of blocks in the blockchain.
TCP/IP
The TCP/IP is a communication protocols which sends the data in the form of packets over a server using
the IP addresses of sender and receiver.
In a client-server architecture, a client can be a machine or a program that allows the user to make
requests to the server. For example, WWW is a client-server program. Users can request data and the web
will provide it. On the other hand, a server is essentially a program and NOT A DEVICE. In contrast, in a
peer-to-peer network, each device can act as a server and as a client at different points in time.
In a blockchain peer-to-peer network, the peers use TCP/IP protocols to connect to other peers and
transfer the data.
Basic Architecture of Blockchain
Satoshi used all the above-mentioned techniques to create the ideal business network, i.e., blockchain. The
architecture of blockchain network is as follows:
• There is a peer-to-peer network created between all the participants of the network.
• Each network participant has a digital signature for identifying the participants
• Any transaction happening between two network participants gets flooded in the network with the
help of gossip protocol to all the participants for validation.
• Each participant has a transaction pool which is a memory space allocated to store the verified
transactions.
• Each transaction is secured using the hashing algorithm.
• The transaction pool is at a node level.
• There are designated nodes which create the blocks out of the transactions happening in the
network at a frequency known as mining rate.
• Once the block is created it gets flooded in the network and each network participant verifies the
block of data and once there is a single source of truth for the block, the block gets added to the
blockchain.
Blockchain Basics-Session 2
Introduction
You already learnt about the various technologies that Satoshi envisioned for the ideal network that he
proposed. In this session, you learnt how those technologies come together and create the first blockchain
network, the Bitcoin blockchain network. The main topics you learnt as part of this session are:
● How blockchain has evolved
● Layers of blockchain network
● Fundamentals of Bitcoin blockchain network
● Consensus mechanism
●
Since Satoshi's network was an open source network, the developers across the world started working on it
Step 1: The
and created many variants of the same technology, first
also model
known as forks.
Two main networks have evolved in the market today:
1. Cryptocurrency Networks: The main intention of these networks is to introduce cryptocurrencies
that work the same as common currencies such as rupees, dollars etc. However, these currencies
only have a digital life and can be used only on a digital network. Examples of this type of network
are Ethereum, Bitcoin etc. These are used to process transactions without the use of any central
organisation like a bank
2. Enterprise Networks: Enterprises use these networks for record keeping and many other purposes.
Examples of these networks include Hyperledger, R3 Corda etc.
All these layers together form the blockchain network and users can have a different set of capabilities or
applications that they use over the network.
Bitcoin was the first implementation of the blockchain, and it has many use cases. In the bitcoin network the
transaction is validated as follows:
All the above-mentioned steps are a part of the record keeping mechanism of the blockchain network.
There are several methods in which records are maintained in networks. One of the basic methods is the
Account/Balance model wherein balance related to every account is maintained. However, bitcoin uses a
different method for recordkeeping. Bitcoin uses the concept of unspent transaction output (UTXO) for
record keeping.
Every transaction in a bitcoin is based upon an unspent transaction output (UTXO). Whenever a
transaction is performed in bitcoin, it primarily consumes existing UTXOs called as inputs and creates new
UTXOs called outputs. The outputs generated from a transaction can be utilized further in the network by
the node.
There are two primary ways to get the UTXO in a bitcoin network:
● Either from another node in the network whenever the transaction is performed.
● Network reward which a miner gets for mining a new block.
There is also a transaction fees which can be a part of a transaction which is paid to the miner for adding
the transaction into a block.
Types of Nodes
The miner node takes the unconfirmed transactions in the mining pool and creates a block. Once a block is
created, it gets flooded across the network using the gossip protocol. All the nodes receive the block and
first validate the block if the block passes the validation, they add it to their respective blockchain otherwise
not.
Block Anatomy
• Merkle root - aggregation of all the hash values of the transactions into a single hash value.
• Timestamp - Timestamp of the block creation time.
• Nonce - Random Value that is altered/updated to try different permutations to achieve the required
difficulty level. You will learn more about this in the upcoming section.
• Transaction counter - Count of the number of transactions in a block.
Mining Process
The process of mining means that a new block is created and added to the blockchain. Every miner creates a
block from the transaction existing in its transaction pool.
• For a block to be valid and added to the network, the miner needs to solve a puzzle which is defined
as below in the case of bitcoin blockchain.
• In case the above condition is not met, the miners need to recompute the hash.
• To recompute the hash nonce is used whose value is changed in every iteration to arrive at a new
hash. This is because all the other data in the block such as time stamp, Merkel root, number of
transactions etc. are all fixed and can not be changed.
• To change the hash the only thing that can be changed is the nonce value. The difficulty to attain the
acceptable hash in the network is termed as the difficulty of the network. Once the condition is
satisfied, the block becomes a valid block.
• The miner who calculated a valid hash first can claim the creation of the block
Mining Reward
A miner competes with other miners in the network to form a block. The miner who is able to first generate
a block in the network is given a block reward. The block reward started from 50 BTC and currently, the
miner earns a block reward of 12.5 BTC for every block.
Block Validation
Once a block gets created it is propagated to the entire network and all the peers don’t add the block as such
to their respective blockchains. Each peer node performs validations on the incoming block.
The block header also contains a previous hash pointer of the block which precedes this block. Blockchain
being a chain of blocks has link between the blocks. The previous hash acts as this link between the blocks.
Each node in the network checks whether the last block in its blockchain has the same hash as the previous
hash pointer of the incoming block, it adds the block otherwise not.
In the blockchain, mathematical algorithms are used to verify transactions and ensure trust between
transacting parties. Transacting parties have to trust the output achieved using these mathematical
algorithms. These algorithms together are known as the consensus mechanism in the blockchain. The
consensus can for a transaction or for an entire block.
• The consensus for the transaction verification of transaction includes the checks for the following:
o Sender Balance
o Valid Authority
o Valid signatures
• The consensus for a block is for the following condition:
The consensus mechanism is difficult to achieve and easy to verify. The above-mentioned consensus
mechanism is known as proof of work. In the proof of work consensus, miner nodes have to solve a
computationally difficult problem to compute the hash for the current block. The network sets a difficulty
target for the miners. This difficulty level plays a vital role in the consensus as well as the mining process.
Difficulty Level
The difficulty value, also known as the target value, sets the difficulty level of the network. The difficulty
level is used to regulate the mining of blocks in the network. The bitcoin network has a block creation time
set to 10 mins and this value has to be maintained. The difficulty value adjusts with every block creation
such that the value of block creation remains constant.
The formula for calculation of difficulty level in bitcoin blockchain network is:
Difficulty Level = (Previous Difficulty Level * 20160) / (Time taken to mine last 2016 block)
In case the time taken for the last block is greater than 10, the new value of difficulty level is lower than the
previous one such that the blocks are created faster. In case the time taken for the last block is less than 10,
the new value of difficulty level is greater than the previous one such that the blocks are created slower.
Blockchain offers one more important feature that differentiates it from other networks: Data Immutability.
Immutability means something which is permanent and cannot be changed. In practical terms, it refers to the
extreme difficulty that one will face in trying to alter or make changes to the existing data.
So how does blockchain ensure data immutability? Blockchain offers data immutability as follows:
• Blockchain forms a chain of blocks which are connected to each other via a link also known as the
previous hash pointer or simply previous hash.
• The hash of a block is calculated for all the contents in the block header using a hashing algorithm.
• Merkel root is a part of the block header and any change in any constituent transaction results in the
change in the Merkel root.
• Hashing algorithms are deterministic and result in a different output in case the input is changed.
• Change in the Merkel root will result in changing the hash of the entire block.
• In case the hash of one block is changed, the block next to it will not have a link to this block as the
previous hash will not match the new block.
• Hence, the link between the blocks will be broken and these blocks will become invalidated.
Immutability is an important feature of the blockchain which helps in data from being manipulated and also
helps in identifying malicious nodes in the network.
SPV Nodes
The primary purpose of having SPV nodes is to validate the transactions without having computationally
intensive machines. The SPV nodes just store the block headers and can validate whether a transaction is
present in a block or not. They don’t have the entire blockchain data and use the Merkel Root to arrive at a
conclusion regarding a transaction.
The use of SPV nodes is done due to the fact that proof of work is computationally heavy and requires a lot
of resources by the nodes. This is one of the challenges that has prompted developers to think of alternative
solutions to proof of work.
The major challenge with pool mining is that it creates a monopoly in the network and only specified nodes
get the reward. In case the mining pool exceeds 51% of the network strength, the miners can derail the
network from its original intent and tamper with the data as their data could get accepted by the majority
rule.
a. It is energy inefficient: In proof of work millions of miners try to mine one block, and only one miner is
successful. Rest of the energy spent by the miners goes to waste.
b. It is computationally heavy: Proof of work requires a lot of computation by the miners to mine one block
successfully.
c. 51% attack: In case more than 51% of the nodes in the network are malicious the network could become
unstable.
Bitcoin follows the longest chain rule which states that in case the blockchain branches out into
multiple branches, the longest branch is accepted by the network. The branches are known as forks.
In case there 51% of the network comes together to form a mining pool they can create the longest chain
with faulty transactions as they are computationally superior making the network unstable.
Apart from the 51% attack which can cause the blockchain network not to behave properly, there is one
more problem similar to 51% attack known as Byzantine Generals problem. The Byzantine Generals
problem occurs when a malicious node propagates wrong message or tampered transactions in the network
that could compromise the security of data in the blockchain network. The blockchain network needs to be
tolerant to such activities and needs to ensure that all the transaction data in the network is tamper free. Such
networks are called as Byzantine Fault Tolerant Networks and they use the Byzantine fault tolerant
consensus.
BFT Network
For a network to be byzantine fault tolerant the number of malicious nodes in the network should be less
than 1/3rd of the total nodes in the network. Whenever a node receives two conflicting messages, it goes for
a majority vote and accepts the message which comes from majority number of nodes. To ensure that the
correct message is accepted by the nodes in the network the total number of malicious nodes needs to less
than 33.33% or 1/3rd of the network.
Proof-of-work is a BFT consensus mechanism provided the 51% attack and pool mining does not happen.