Unit 1 - Blockchain Basic.docx
Unit 1 - Blockchain Basic.docx
In 1992, Merkle Trees were incorporated into the design, which makes blockchain more
efficient by allowing several documents to be collected into one block. Merkle Trees are used
to create a 'secured chain of blocks.' It stored a series of data records, and each data records
connected to the one before it. The newest record in this chain contains the history of the entire
chain. However, this technology went unused, and the patent lapsed in 2004.
The evolution of blockchains has been steady and promising. The words block and chain were
used separately in Satoshi Nakamoto's original paper but were eventually popularized as a
single word, the Blockchain, by 2016. In recent time, the file size of cryptocurrency blockchain
containing records of all transactions occurred on the network has grown from 20 GB to 100
GB.
Blockchain Version
The brief description of the evolution of blockchain technology and its versioning from 1.0 to
3.0 are explained below.
The idea of creating money through solving computational puzzles was first introduced
in 2005 by Hal Finney, who created the first concept for cryptocurrencies (The implementation
of distributed ledger technology). This ledger allows financial transactions based on blockchain
technology or DLT to be executed with Bitcoin. Bitcoin is the most prominent example in this
segment. It is being used as cash for the Internet and seen as the enabler of an Internet of
Money.
The main issues that came with Bitcoin are wasteful mining and lack of network scalability. To
overcome these issues, this version extends the concept of Bitcoin beyond currency. The new
key concepts are Smart Contracts. It is small computer programs that "live" in the blockchain.
They are free computer programs which executed automatically and checked conditions which
are defined earlier like facilitation, verification or enforcement. The big advantage of this
technology that blockchain offers, making it impossible to tamper or hack Smart Contracts. A
most prominent example is the Ethereum Blockchain, which provides a platform where the
developer community can build distributed applications for the Blockchain network.
Quickly, the blockchain 2.0 version is successfully processing a high number of daily
transactions on a public network, where millions were raised through ICO (Initial Coin
Offerings), and the market cap increased rapidly.
Blockchain Basics
Blockchain is a constantly growing ledger that keeps a permanent record of all the transactions
that have taken place in a secure, chronological, and immutable way. It can be used for the
secure transfer of money, property, contracts, etc. without requiring a third-party intermediary
such as bank or government. Blockchain is a software protocol, but it could not be run without
the Internet (like SMTP is for email).
What is Blockchain?
A blockchain is a constantly growing ledger which keeps a permanent record of all the
transactions that have taken place in a secure, chronological, and immutable way.
Let's breakdown the definition,
o Ledger: It is a file that is constantly growing.
o Permanent: It means once the transaction goes inside a blockchain, you can put up it
permanently in the ledger.
o Secure: Blockchain placed information in a secure way. It uses very advanced
cryptography to make sure that the information is locked inside the blockchain.
o Chronological: Chronological means every transaction happens after the previous one.
o Immutable: It means as you build all the transaction onto the blockchain, this ledger can
never be changed.
A blockchain is a chain of blocks which contain information. Each block records all of the
recent transactions, and once completed goes into the blockchain as a permanent database. Each
time a block gets completed, a new block is generated.
Note: A blockchain can be used for the secure transfer of money, property, contracts, etc.
without requiring a third-party intermediary like bank or government. Blockchain is a software
protocol, but it could not be run without the Internet (like SMTP used in email).
Blockchain technology can be integrated into multiple areas. The primary use of blockchains is
as a distributed ledger for cryptocurrencies. It shows great promise across a wide range of
business applications like Banking, Finance, Government, Healthcare, Insurance, Media and
Entertainment, Retail, etc.
Need of Blockchain
Blockchain technology has become popular because of the following.
o Time reduction: In the financial industry, blockchain can allow the quicker settlement of
trades. It does not take a lengthy process for verification, settlement, and clearance. It is
because of a single version of agreed-upon data available between all stakeholders.
o Unchangeable transactions: Blockchain register transactions in a chronological order
which certifies the unalterability of all operations, means when a new block is added to
the chain of ledgers, it cannot be removed or modified.
o Reliability: Blockchain certifies and verifies the identities of each interested parties. This
removes double records, reducing rates and accelerates transactions.
o Security: Blockchain uses very advanced cryptography to make sure that the information
is locked inside the blockchain. It uses Distributed Ledger Technology where each party
holds a copy of the original chain, so the system remains operative, even the large
number of other nodes fall.
o Collaboration: It allows each party to transact directly with each other without requiring
a third-party intermediary.
o Decentralized: It is decentralized because there is no central authority supervising
anything. There are standards rules on how every node exchanges the blockchain
information. This method ensures that all transactions are validated, and all valid
transactions are added one by one.
Blockchain
A blockchain is a database or a ledger that stores information in a data structure called blocks. It
is based on distributed ledger technology which can be used between parties that don't trust each
other with data. It is because when you add anything onto the blockchain, it requires verification
from all other users available on the network.
Blockchain keeps information permanently in uniformly sized blocks, where each block stores
the hashed information from the previous block to provide cryptographic security. The
blockchain hashing uses SHA256 hashing algorithm, which is a one-way hash function. The
hashed information is the data and a digital signature from the previous block. The hashes of
previous blocks that go back to the very first block produced in the blockchain are known as
the genesis block. A blockchain data structure is in the form of a Merkle Tree, which is used as
an efficient way to verify data.
Advantage of Blockchain
o Time reduction: In the financial industry, blockchain can allow the quicker settlement of
trades. It does not take a lengthy process for verification, settlement, and clearance.
o Unchangeable transactions: Blockchain only allows insertion of data, which means
when a new block is added to the chain of ledgers, it cannot be removed or modified.
o Reliability: Blockchain certifies and verifies the identities of each interested parties. This
removes double records, reducing rates and accelerates transactions.
o Security: Blockchain uses very advanced cryptography to make sure that the information
is locked inside the blockchain. It uses Distributed Ledger Technology where each party
holds a copy of the original chain, so the system remains operative, even the large
number of other nodes fall.
o Decentralized: It is because there is no central authority supervising anything. There are
standards rules on how every node exchanges the blockchain information.
Databases
A database is a kind of central ledger where the administrator manages everything. Here the
administrator gives rights to read, write, update, or delete operation. Since it is centralized in
nature, their maintenance is easy, and output is high. But it also has a drawback which, when
corrupted, can compromise the entire data and can even change the ownership of digital
records.
A database uses a client-server network architecture. Here database administrator has rights to
make changes in any part of the data and its structure.
Advantage of Database
o Controls database redundancy: It is because it stores all the data in one single database
file and that recorded data is placed in the database.
o Data sharing: In DBMS, the authorized users of an organization can share the data
among multiple users.
o Easily Maintenance: It can be easily maintainable due to the centralized nature of the
database system.
o Reduce time: It reduces development time and maintenance need.
o Backup: It provides backup and recovery subsystems which create an automatic backup
of data from hardware and software failures and restores the data if required.
o Multiple user interfaces: It provides different types of user interfaces like graphical user
interfaces, application program interfaces.
Blockchain vs Database
We can see the difference between blockchain and database in the below table.
SN Blockchain Database
6. Blockchain has only Insert The database has Create, Read, Update, and
operation. Delete operation.
7. It is a fully robust technology. It is not entirely robust technology.
9. Anyone with the right proof of Only entities entitled to read or write can do
work can write on the so.
blockchain.
Components of Blockchain
1. Node: Nodes are network participants and their devices permit them to keep track of the
distributed ledger and serve as communication hubs in various network tasks. A block
broadcasts all the network nodes when a miner looks to add a new block in transactions
to the blockchain.
2. Transactions: A transaction refers to a contract or agreement and transfers of assets
between parties. The asset is typically cash or property. The network of computers in
blockchain stores the transactional data as a copy with the storage typically referred to as
a digital ledger.
3. Block: A block in a blockchain network is similar to a link in a chain. In the field of
cryptocurrency, blocks are like records that store transactions like a record book, and
those are encrypted into a hash tree. There are a huge number of transactions occurring
every day in the world. The users need to keep track of those transactions, and they do it
with the help of a block structure. The block structure of the blockchain is mentioned in
the very first diagram in this article.
4. Chain: Chain is the concept where all the blocks are connected with the help of a chain
in the whole blockchain structure in the world. And those blocks are connected with the
help of the previous block hash and it indicates a chaining structure.
5. Miners: Blockchain mining is a process that validates every step in the transactions while
operating all cryptocurrencies. People involved in this mining they called miners.
Blockchain mining is a process to validate each step in the transactions while operating
cryptocurrencies.
6. Consensus: A consensus is a fault-tolerant mechanism that is used in computer and
blockchain systems to achieve the necessary agreement on a single state of the network
among distributed processes or multi-agent systems, such as with cryptocurrencies. It is
useful in record keeping and other things.
Data Storage and Management
1. Header: It is used to identify the particular block in the entire blockchain. It handles all
blocks in the blockchain. A block header is hashed periodically by miners by changing
the nonce value as part of normal mining activity, also Three sets of block metadata are
contained in the block header.
2. Previous Block Address/ Hash: It is used to connect the i+1th block to the ith block
using the hash. In short, it is a reference to the hash of the previous (parent) block in the
chain.
3. Timestamp: It is a system that verifies the data into the block and assigns a time or date
of creation for digital documents. The timestamp is a string of characters that uniquely
identifies the document or event and indicates when it was created.
4. Nonce: A nonce number which used only once. It is a central part of the proof of work in
the block. It is compared to the live target if it is smaller or equal to the current target.
People who mine, test, and eliminate many Nonce per second until they find that
Valuable Nonce is valid.
5. Merkel Root: It is a type of data structure frame of different blocks of data. A Merkle
Tree stores all the transactions in a block by producing a digital fingerprint of the entire
transaction. It allows the users to verify whether a transaction can be included in a block
or not.
Types of Blockchain
1. Public Blockchain
A public blockchain is a concept where anyone is free to join and take part in the core activities
of the blockchain network. Anyone can read, write, and audit the ongoing activities on a public
blockchain network, which helps to achieve the self-determining, decentralized nature often
authorized when blockchain is discussed. Data on a public blockchain is secure as it is not
possible to modify once they are validated.
The public blockchain is fully decentralized, it has access and control over the ledger, and its
data is not restricted to persons, is always available and the central authority manages all the
blocks in the chain. There is publicly running all operations. Due to no one handling it singly
then there is no need to get permission to access the public blockchain. Anyone can set his/her
node or block in the network/ chain.
After a node or a block settle in the chain of the blocks, all the blocks are connected like
peer-to-peer connections. If someone tries to attack the block then it forms a copy of that data
and it is accessible only by the original author of the block.
Public Blockchain
Advantages:
1. Decentralization: High level of decentralization, which reduces the risk of single points
of failure and increases security.
2. Transparency: All transactions are visible to anyone, enhancing transparency and trust.
3. Immutability: Once data is recorded, it cannot be altered or deleted, providing a
permanent record.
Disadvantages:
1. Scalability Issues: Public blockchains often face scalability problems, with limited
transaction throughput and slower processing times.
2. Energy Consumption: Some consensus mechanisms, like Proof of Work (PoW), require
significant computational power and energy.
3. Privacy Concerns: Public visibility of transactions may lead to privacy issues, as
sensitive data can be exposed.
2. Private Blockchain
Miners need permission to access a private blockchain. It works based on permissions and
controls, which limit participation in the network. Only the entities participating in a transaction
will know about it and the other stakeholders not be able to access it.
It works based on permissions due to this it is also called a permission-based blockchain.
Private blockchains are not like public blockchains it is managed by the entity that owns the
network. A trusted person is in charge of the running of the blockchain it will control who can
access the private blockchain and also control the access rights of the private chain network.
There may be a possibility of some restrictions while accessing the network of the private
blockchain.
Private Blockchain
Advantages:
1. Performance and Speed: Faster transaction processing and higher throughput compared
to public blockchains due to fewer nodes and reduced consensus requirements.
2. Privacy: Transactions and data are visible only to authorized participants, enhancing
privacy.
3. Control: Centralized control allows for easier governance and compliance with
regulations.
Disadvantages:
1. Centralization: Less decentralized than public blockchains, which can introduce single
points of failure and reduce the security benefits.
2. Trust: Requires participants to trust the central authority or consortium managing the
blockchain.
3. Limited Transparency: Reduced transparency can make it harder for external auditors
to verify data.
3. Consortium Blockchain
A consortium blockchain is a concept where it is permissioned by the government and a group
of organizations, not by one person like a private blockchain. Consortium blockchains are more
decentralized than private blockchains, due to being more decentralized it increases the privacy
and security of the blocks. Those like private blockchains connected with government
organizations’ block networks.
Consortium blockchains lie between public and private blockchains. They are designed by
organizations and no one person outside of the organizations can gain access. In Consortium
blockchains all companies in between organizations collaborate equally. They do not give
access from outside of the organizations/ consortium network.
Advantages:
1. Efficiency: Better performance and efficiency than public blockchains due to fewer
nodes and optimized consensus mechanisms.
2. Shared Control: Governance is shared among consortium members, which can enhance
trust and cooperation.
3. Privacy and Security: Improved privacy and security compared to public blockchains,
as access is restricted.
Disadvantages:
1. Complex Governance: Decision-making can be complex due to multiple stakeholders
with potentially conflicting interests.
2. Less Decentralization: While more decentralized than private blockchains, consortium
blockchains still have a limited number of participants, which can reduce some
decentralization benefits.
3. Interoperability: Challenges can arise when integrating with other blockchain networks
or systems.
4. Hybrid Blockchain
Hybrid blockchains combine elements of both public and private blockchains. They aim to offer
the benefits of both types, allowing for controlled access and transparency. Examples include
Dragonchain and IBM’s Food Trust.
Advantages:
1. Flexibility: Offers the ability to balance transparency and privacy based on the needs of
the organization or project.
2. Scalability and Performance: Can be designed to optimize performance and scalability
while maintaining some degree of transparency.
3. Customizable Access: Allows organizations to control who can access certain data while
making some data available to the public.
Disadvantages:
1. Complexity: Implementation can be more complex due to the need to manage different
access levels and integrations.
2. Governance Challenges: Balancing governance between public and private aspects can
be challenging.
3. Potential for Confusion: This may requires lead to confusion among users and
stakeholders about the nature and scope of access and transparency.
Consensus Mechanisms in Blockchain
There are different kinds of consensus mechanism algorithms, each of which works on different
principles:
1. Proof of Work (PoW): Proof of Work requires a stakeholder node to prove that the work
is done and submitted by them certifying them to receive the right to add new
transactions in the blockchain. Examples include Bitcoin and Ethereum (before Ethereum
2.0).
2. Proof of Stake (PoS): The Proof of Stake is also a common consensus algorithm that
evolved as a low-cost low-energy-consuming, low-energy-consuming alternative for the
PoW algorithm. For providing the responsibilities the public ledger provides by the
virtual currency token like Bitcoin and Ethereum. Examples include Ethereum 2.0 and
Cardano.
3. Proof of Elapsed Time (PoET): PoET encrypts the passage of time cryptographically to
reach an agreement without expending many resources.
4. Delegated Proof of Stake (DPoS): Stakeholders elect a limited number of delegates to
validate transactions and create blocks on their behalf. It has higher transaction
throughput and faster block creation. In DPoS, risk of centralization and reliance on
elected delegates. Examples include EOS and TRON.
5. Proof of Authority (PoA): A small number of pre-approved validators are responsible
for creating blocks and validating transactions. PoA has high efficiency and low energy
consumption. There is a risk of centralization and dependency on the trustworthiness of
validators. Examples include VeChain and private Ethereum networks.
6. Practical Byzantine Fault Tolerance (PBFT): In PBFT, nodes reach consensus through
voting, even if some nodes act maliciously or fail. It is effective in handling Byzantine
faults and offers fast transaction processing. There is a complexity in scaling to large
networks. Examples include Hyperledger Fabric.
Cryptographic Foundations in Blockchain
Cryptography is important to the security and functionality of blockchain technology. Here is an
overview of the key cryptographic foundations used in blockchain:
1. Hash Functions: Hash functions are algorithms that generate a fixed-size output (hash)
from variable-size input data. They are designed to be fast and produce unique outputs for
different inputs. Hash functions are used to create block hashes, ensuring the integrity of
the data within the block and linking blocks together in the chain. Examples include
SHA-256 used in Bitcoin.
2. Digital Signatures: Digital signatures use asymmetric cryptography to verify the
authenticity and integrity of messages or transactions. They involve a private key to sign
data and a public key to verify the signature. Digital signatures secure transactions by
allowing users to sign transactions with their private keys and enabling others to verify
these signatures with the corresponding public keys. Examples include the Elliptic Curve
Digital Signature Algorithm (ECDSA) used in Bitcoin and Ethereum.
3. Public and Private Keys: In asymmetric cryptography, a key pair consists of a public
key, which is shared with others, and a private key, which is kept secret. The public key
encrypts data, and the private key decrypts it, or vice versa. Public and private keys are
fundamental for creating and managing wallets, securing transactions, and authenticating
users on the blockchain. Examples include RSA (Rivest-Shamir-Adleman), ECC (Elliptic
Curve Cryptography), etc.
4. Merkle Trees: Merkle trees are a type of hash tree where each leaf node represents a
hash of data, and each non-leaf node represents a hash of its child nodes. They are used to
efficiently and securely verify the integrity of large sets of data. Merkle trees are used to
organize and verify transactions within a block, allowing for efficient and secure
validation. Examples include the Merkle root in Bitcoin blocks.
Double Spending Problem
Double spending means spending the same money twice. As we know, any transaction can be
processed only in two ways. One is offline, and another is online.
Offline: A transaction which involves physical currency or cash is known as an offline
transaction.
Online: A transaction which involves digital cash is known as an online transaction.
Let us consider this example:
You go to Restaurants and order a cappuccino worth $5. You pay in cash. The service provider
at Restaurants instantly confirmed that you have paid, and you received your coffee in exchange
for the money. Now is it possible to spend the same $5 somewhere else to make another
purchase? The answer is NO. But what if the answer is YES? It means the same person can use
the same cash more than one times. This type of problem is known as Double Spending
Problem.
In case of Bitcoin, if you ever lose the private key to your Bitcoin wallet, the entire
contents of your wallets would be instantly vulnerable to theft and before you know
it, all your money (the contents of your wallet) would be gone with no mechanism
in the system to trace out who stole it - that is the anonymity in the system that I
mentioned earlier.
The PKI accomplies two functions - authentication and the message privacy
through encryption/decryption mechanism
Authentication Function
In the first place, if Bob wants to send some money to Lisa, he has to create a
private/public key of its own. Note that both keys are always paired together and
you cannot mix the private and public keys of different individuals or different
instances.
Now, Bob says that he is sending $10 to Lisa. So he creates a message (a plain-text
message) containing Bob’s (sender) public key, Lisa’s (receiver) public key, and the
amount ($10).
The purpose of this remittance such as “I want to buy pumpkin from you” is also
added into the message. The entire message is now signed using Bob’s private key.
When Lisa receives this message, she will use the signature verification algorithm
of PKI and Bob’s public key to ensure that the message indeed originated from Bob.
How the PKI works is beyond the scope of this tutorial. The interested reader is
referred to this site for a more detailed discussion on PKI. This establishes the
authenticity of the message originator. Now, let us look at the message privacy.
Message Privacy function
Now, as Lisa has received her payment, she wants to send the link to her ebook
which Bob wants to buy. So Lisa would create a message and send it to Bob as
shown in image −
The Lisa creates a message such as “Here is the link to my ebook which you had
requested”, signs it with Bob’s public key that she has received in Bob’s request
message and also encrypts the message using some secret key which is shared
between the two during HTTPS handshake.
Now, Lisa is sure that only Bob can decode the message using the private key that is
held by Bob alone. Also, somebody intercepting the message would not be able to
recover its contents because the contents are encrypted by a secret key held only by
Bob and Alice. This guarantees to Lisa that access to her ebook is granted only to
Bob.
Having seen both the features, Authentication and Message Privacy, implied by
PKI, let us move ahead to see how Bitcoin makes use of PKI to secure the public
ledger that I mentioned in the chapter “What is Bitcoin?”.
Blockchain - Hashing
One of the most important function in PKI is the hashing function. 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). This is illustrated
in image –
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.
Blockchain Hash Function
A hash function takes an input string (numbers, alphabets, media files) of any
length and transforms it into a fixed length. The fixed bit length can vary (like
32-bit or 64-bit or 128-bit or 256-bit) depending on the hash function which is
being used. The fixed-length output is called a hash. This hash is also the
cryptographic byproduct of a hash algorithm. We can understand it from the
following diagram.
The hash algorithm has certain unique properties:
1. It produces a unique output (or hash).
2. It is a one-way function.
In the context of cryptocurrencies like Bitcoin, the blockchain uses this
cryptographic hash function's properties in its consensus mechanism. A
cryptographic hash is a digest or digital fingerprints of a certain amount of data. In
cryptographic hash functions, the transactions are taken as an input and run through
a hashing algorithm which gives an output of a fixed size.
SHA-256
A Bitcoin's blockchain uses SHA-256 (Secure Hash Algorithm) hashing algorithm.
In 2001, SHA-256 Hashing algorithm was developed by the National Security
Agency (NSA) in the USA.
How does the hashing process works?
For this hash function, we are going to use a program developed by Anders
Brownworth. This program can be found in the below link.
Anders Brownworth Hash
Program: https://anders.com/blockchain/hash.html
If we type any character in the data section, we will observe its corresponding
cryptographic hash in the hash section.
For example: We have type in data section: This is a great tutorial.
It will generate the corresponding Hash:
1. 759831720aa978c890b11f62ae49d2417f600f26aaa51b3291a8d21a4216582a
Now if we change the text: "This is a great tutorial." To "this is a great tutorial."
You will find the corresponding Hash:
1. 4bc35380792eb7884df411ade1fa5fc3e82ab2da76f76dc83e1baecf48d60018
In the above, you can see that we have changed only the first character case
sentence from capital "T" to small "t" and it will change the whole Hash value.
Note: If we write the same text again in a data section, it will always give the same
output. It is because you are creating a message digest of that one's specific amount
of data.
Since the Hash function is a one-way function, there is no way to get back entire
text from the generated hash. This is different from traditional cryptographic
functions like encryption where you can encrypt something using the key and by
using decryption, you can decrypt the message to its original form.
Blockchain Block Hashing
In this section, we are going to learn how SHA-256 applies to build a block within a
blockchain. We will discuss here in the context of the Bitcoin blockchain and
understand how this ties into the role of miners. The minors are actually in the
process of building blocks, and these blocks are added to a blockchain to build out
what the Bitcoin blockchain will be.
In the below image, you can see that this block is composed of a block number, data
field, cryptographic hash associated with it and a Nonce.
In the above image, the generated hash would look like 00001acbm010gfh1010xxx.
I'd like to point out that this hash has four leading zeros. The four leading zero's
describes whether the block is valid or not. For practical purposes, you will see that
this hash is corresponding to the nonce, and the block number is corresponding to
the available data. Since the hash has four leading zeroes, therefore, it is a valid
block.
If we make any change in the data section, it will give the completely different hash
that can be shown in the below image.
If the newly generating hash does not have four leading zeroes, then it will not a
valid block. To make the block valid, we will do it by using the field called nonce.
Nonce stands for a Number Used Once in a cryptographic communication such
that the block's hash meets a certain criterion. This criterion could be generated a
hash that must have its leading four digits to be zero. Thus, the generated hash
would look like 00001acbm010gfh1010xxx.
A nonce is basically a random number which figures out how you can actually
make this specific block provide you with a valid hash. The way you can do this is
by changing the nonce manually. Generally, the miner starts with a Nonce value of
1 and keeps on incrementing it until the generated hash meets the specified
criterion. Thus, it may take several iterations until the desired hash with four
leading zeros is generated. The expected time for generating a block in
the bitcoin system is 10 minutes. Once the miner successfully mines the block, he
releases that block in the system and making it the last block in the chain.
In Anders Brownworth Hash Program, when we click mine button as shown in the
image, it will give the valid block. This block has a unique nonce with hash leading
four zeroes in the beginning.