Chapter 01
Chapter 01
• Blockchain is a technology that has promised to positively alter the existing paradigms of nearly all
industries including, but not limited to, the IT, finance, government, media, medical, and law sectors.
• With the invention of Bitcoin in 2008, the world was introduced to a new concept, which
revolutionized the whole of society. It was something that promised to have an impact upon every
industry. This new concept was blockchain.
• Many prominent organizations all around the world have moved on from the proof-of-concept stage
and are already writing production systems utilizing blockchain. The disruptive potential of
blockchain has now been fully recognized. For example, Decentralized Finance (DeFi) has recently
emerged as a new disruptive idea that aims to decentralize the existing financial system. (Refer
https://defipulse.com)
3
Distributed systems 4
• It can be thought of as a system that has properties of the both decentralized and distributed
paradigms.
• It is a decentralized-distributed system.
5
• A distributed system is a computing paradigm whereby two or more nodes work with one another, in
a coordinated fashion, to achieve a common outcome.
• A distributed system is modeled in such a way that end users see it as a single logical platform.
• For example, Google's search engine is based on a large distributed system; however, to a user, it
looks like a single, coherent 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 they have memory and a processor.
• A node that exhibits irrational behavior is also known as a Byzantine node after the Byzantine
Generals problem.
The Byzantine Generals Attack?
5
problem Attack ?
Retreat ?
Retreat?
Attack ?
Attack or retreat?
Consensus required to win
https://www.microsoft.com/en-us/research/publication/byzantine-generals-problem/
Design of a distributed system 7
• This type of inconsistent behavior of Byzantine nodes can be intentionally malicious, which is
detrimental to the operation of the network.
• Any unexpected behavior by a node on the network, whether malicious or not, can be categorized as
Byzantine.
• The primary challenge of a distributed system design is the coordination between nodes and fault
tolerance.
• Even if some (a certain threshold dictated by the consensus protocol) of the nodes become faulty or
network links break, the distributed system should be able to tolerate this and continue to work to
achieve the desired result.
• This problem has been an active area of distributed system design research for many years, and
several algorithms and mechanisms have been proposed to overcome these issues.
CAP theorem 9
• Distributed systems are so challenging to design that a theory known as the CAP theorem has
been proven, which states that a distributed system cannot have all three of the desired properties
simultaneously; that is:
• Consistency
• Availability
• Partition tolerance
10
• Consistency is a property that ensures that all nodes in a distributed system have a single, current,
and identical copy of the data.
• Availability means that the nodes in the system are up, accessible for use, and are accepting
incoming requests and responding with data without any failures as and when required. In other
words, data is available at each node and the nodes are responding to requests.
• Partition tolerance ensures that if a group of nodes is unable to communicate with other nodes due
to network failures, the distributed system continues to operate correctly. This can occur due to
network and node failures.
11
• The preceding diagram shows that only two properties at a time can be achieved. Either AP, CA, or
CP.
• In summary:
• Usually, a network partition cannot be ignored; therefore, the choice mostly becomes either
consistency or availability in the case of a network partition.
12
• Blockchain was introduced with the invention of Bitcoin in 2008. Its practical implementation
then occurred in 2009
• 1970s – Early work on secure network communication including public key cryptography
• 1982 – The Byzantine Generals Problem (Bitcoin can be considered a solution to the Byzantine
Generals Problem; however, the original intention of the Bitcoin network was to address the
previously unsolved double-spending problem)
• 1985 – Work on elliptic curve cryptography by Neal Koblitz and Victor Miller
• 1991 – Haber and Stornetta work on tamper proofing document timestamps. This can be considered
the earliest idea of a chain of blocks or hash chains
14
• 1992 – Cynthia Dwork and Moni Naor publish Pricing via Processing or Combatting Junk Mail.
This is considered the first use of Proof of Work (PoW)
• 1993 – Haber, Bayer, and Stornetta upgraded the tamper-proofing of document timestamps system
with Merkle trees
• 1995 – David Chaum's Digicash system (an anonymous electronic cash system) started to be used in
some banks
• 1998 – Bit Gold, a mechanism for decentralized digital currency, invented by Nick Szabo. It used
hash chaining and Byzantine Quorums
• 1999 – Emergence of a file-sharing application mainly used for music sharing, Napster, which is a
P2P network, but was centralized with the use of indexing servers
• 1999 – Development of a secure timestamping service for the Belgian project TIMESEC
15
• 2005 – Prevention of Sybil attacks by using computation puzzles, due to James Aspnes et al.
• The concept of electronic cash (e-cash), or digital currency, is not new. Since the 1980s, e-cash protocols have
existed.
• Two fundamental e-cash system issues need to be addressed: accountability and anonymity.
• Accountability is required to ensure that cash is spendable only once (addressing the doublespending problem)
and that it can only be spent by its rightful owner. The double-spending problem arises when the same money
can be spent twice. As it is quite easy to make copies of digital data, this becomes a big issue in digital
currencies as you can make many copies of the same amount of digital cash.
• Anonymity is required to protect users' privacy. With physical cash, it is almost impossible to trace back
spending to the individual who actually paid the money, which provides adequate privacy should the consumer
choose to hide their identity. In the digital world, however, providing such a level of privacy is difficult due to
inherent personalization, tracing, and logging mechanisms in digital payment systems such as credit card
payments. This is indeed a required feature for ensuring the security and safety of the financial network, but it is
also often seen as a breach of privacy.
How did blockchain technology develop? 11
• 1970s – Merkle trees - hashes in a tree structure • 1992 – Hashcash idea to combat junk emails
• 1970s continued – Research in distributed systems, consensus, • 1994 – S/KEY application for Unix login.
state machine replication
• 1997/2002 – Hashcash
• 1980s – Hash chains for secure logins
• 2008/2009 – Bitcoin (the first blockchain)
• 1990s – e-Cash for e-payments
Blockchain 18
• In 2008, a groundbreaking paper, entitled Bitcoin: A Peer-to-Peer Electronic Cash System, was
written on the topic of peer-to-peer e-cash under the pseudonym of Satoshi Nakamoto.
• It introduced the term chain of blocks. No one knows the actual identity of Satoshi Nakamoto. After
introducing Bitcoin in 2009, he remained active in the Bitcoin developer community until 2011. He
then handed over Bitcoin development to its core developers and simply disappeared. Since then,
there has been no communication from him whatsoever, and his existence and identity are shrouded
in mystery. The term "chain of blocks" evolved over the years into the word "blockchain."
Defining ‘Blockchain’ 19
Peer-to-peer
• The first keyword in the technical definition is peer-to-peer, or P2P This means that there is no
central controller in the network, and all participants (nodes) talk to each other directly. This
property allows for transactions to be conducted directly among the peers without third-party
involvement, such as by a bank.
Distributed ledger
• blockchain is a "distributed ledger," which means that a ledger is spread across the network among
all peers in the network, and each peer holds a copy of the complete ledger.
21
Cryptographically secure
• ledger is "cryptographically secure," which means that cryptography has been used to provide
security services that make this ledger secure against tampering and misuse. These services
include non-repudiation, data integrity, and data origin authentication.
Append only
• blockchain is "append-only," which means that data can only be added to the blockchain in
time-sequential order. This property implies that once data is added to the blockchain, it is
almost impossible to change that data and it can be considered practically immutable. In other
words, blocks added to the blockchain cannot be changed, which allows blockchain to become
an immutable and tamper-proof ledger of transactions.
22
• In this scenario, no central authority is in control of updating the ledger. Instead, any update made to
the blockchain is validated against strict criteria defined by the blockchain protocol and added to the
blockchain only after a consensus has been reached among all participating peers/nodes on the
network.
• To achieve consensus, there are various consensus algorithms that ensure all parties agree on the final
state of the data on the blockchain network.
Architectural view of Blockchain 12
24
• the lowest layer is the Network, which is usually the internet and provides a base communication
layer for any blockchain.
• A peer-to-peer network runs on top of the Network layer, which consists of information propagation
protocols such as gossip or flooding protocols.
• Cryptography layer, which contains crucial cryptographic protocols that ensure the security of the
blockchain.
• Consensus layer, which is concerned with the usage of various consensus mechanisms to ensure
agreement among different participants of the blockchain.
25
• Execution layer, which can consist of virtual machines, blocks, transaction, and smart contracts. This
layer, as the name suggests, provides executions services on the blockchain and performs operations
such as value transfer, smart contract execution, and block generation. Virtual machines such as
Ethereum Virtual Machine (EVM) provide an execution environment for smart contracts to
execute.
• Finally, the Applications layer, which is composed of smart contracts, decentralized applications,
DAOs, and autonomous agents. This layer can effectively contain all sorts of various user level
agents and programs that operate on the blockchain. Users interact with the blockchain via
decentralized applications.
Generic structure of a blockchain 13
Addresses
• Addresses are unique identifiers used in a blockchain transaction to denote senders and recipients. An
address is usually a public key or derived from a public key.
Transactions
• A transaction is the fundamental unit of a blockchain. A transaction represents a transfer of value from
one address to another.
Blocks
• A block is composed of multiple transactions and other elements, such as the previous block hash
(hash pointer), timestamp, and nonce.
Peer-to-peer network
• As the name implies, a peer-to-peer network is a network topology wherein all peers can communicate
with each other and send and receive messages.
Generic elements of a blockchain
28
Virtual machine
• A virtual machine allows Turing complete code to be run on a blockchain (as smart
contracts).
• However, virtual machines are not available on all blockchains. Various blockchains use
virtual machines to run programs such as Ethereum Virtual Machine (EVM) and Chain
Virtual Machine (CVM). EVM is used in the Ethereum blockchain, while CVM is a virtual
machine developed for and used in an enterprise-grade blockchain called "Chain Core."
29
State machine
• A blockchain can be viewed as a state transition mechanism whereby a state is modified from its initial
form to the next one by nodes on the blockchain network as a result of transaction execution.
Nodes
• A node in a blockchain network performs various functions depending on the role that it takes on.
Smart contracts
• These programs run on top of the blockchain and encapsulate the business logic to be executed when
certain conditions are met. The smart contract feature is not available on all blockchain platforms, but it
is now becoming a very desirable feature due to the flexibility and power that it provides to blockchain
applications. Smart contracts have many use cases, including but not limited to identity management,
capital markets, trade finance, record management, insurance, and e-governance.
Generic block structure 16
A block is composed of multiple transactions and other elements, such as the previous block hash
(hash pointer), timestamp, and nonce. A block is composed of a block header and a list of
transactions bundled together and organized logically.
31
How blockchain works? 32
• A critical decision that every blockchain network has to make is to figure out which node will append
the next block to the blockchain. This decision is made using a consensus mechanism
33
• Transaction is initiated
Transaction is initiated: A node starts a transaction by first creating it and then digitally signing it
with its private key. A transaction can represent various actions in a blockchain. Most commonly,
this is a data structure that represents the transfer of value between users on the blockchain
network. The transaction data structure usually consists of some logic of transfer of value, relevant
rules, source and destination addresses, and other validation information. Transactions are usually
either a cryptocurrency transfer (transfer of value) or smart contract invocation that can perform
any desired operation. A transaction occurs between two or more parties.
Find new block: When the transaction is received and validated by special participants called miners
on the blockchain network, it is included in a block, and the process of mining starts. This process is
also sometimes referred to as "finding a new block." Here, nodes called miners race to finalize the
block they've created by a process known as mining.
New block found: Once a miner solves a mathematical puzzle (or fulfills the requirements of the
consensus mechanism implemented in a blockchain), the block is considered "found" and finalized.
At this point, the transaction is considered confirmed. Usually, in cryptocurrency blockchains such
as Bitcoin, the miner who solves the mathematical puzzle is also rewarded with a certain number of
coins as an incentive for their effort and the resources they spent in the mining process.
Add new block to the blockchain: The newly created block is validated, transactions or smart
contracts within it are executed, and it is propagated to other peers. Peers also validate and execute
the block. It now becomes part of the blockchain (ledger), and the next block links itself
cryptographically back to this block. This link is called a hash pointer.
How a blockchain works 36
1. User X transacts with User Y 2. Transaction broadcast 3. Find new block (mining) 4. New block found (mined)
• Decentralization
This is a core concept and benefit of blockchain. There is no need for a trusted third party or intermediary to
validate transactions; instead, a consensus mechanism is used to agree on the validity of transactions
As blockchains are shared and everyone can see what is on the blockchain, this allows the system to be
transparent. As a result, trust is established. This is more relevant in scenarios such as the disbursement of funds
or benefits where personal discretion in relation to selecting beneficiaries needs to be restricted.
• Immutability
Once the data has been written to the blockchain, it is extremely difficult to change it back. It is not genuinely
immutable, but because changing data is so challenging and nearly impossible, this is seen as a benefit to
maintaining an immutable ledger of transactions.
Benefits of blockchain 38
• High availability
As the system is based on thousands of nodes in a peer-to-peer network, and the data is replicated and updated
on every node, the system becomes highly available. Even if some nodes leave the network or become
inaccessible, the network as a whole continues to work, thus making it highly available. This redundancy results
in high availability.
• Highly secure
All transactions on a blockchain are cryptographically secured and thus provide network integrity. Any
transactions posted from the nodes on the blockchain are verified based on a predetermined set of rules. Only
valid transactions are selected for inclusion in a block. The blockchain is based on proven cryptographic
technology that ensures the integrity and availability of data. Generally, confidentiality is not provided due to
the requirements of transparency. This limitation is the leading barrier to its adoption by financial institutions
and other industries that require the privacy and confidentiality of transactions.
Benefits of blockchain 39
• Faster transactions
In the financial industry, especially in post-trade settlement functions, blockchain can play a vital
role by enabling the quick settlement of trades. Blockchain does not require a lengthy process of
verification, reconciliation, and clearance because a single version of agreed-upon data is already
available on a shared ledger between financial organizations.
• Cost saving
As no trusted third party or clearing house is required in the blockchain model, this can massively
eliminate overhead costs in the form of the fees, which are paid to such parties.
Benefits of blockchain 40
A blockchain is a platform on which programs can run that execute business logic on behalf of
the users. This is a very useful feature but not all blockchains have a mechanism to execute
smart contracts; however, this is a very desirable feature. It is available on newer blockchain
platforms such as Ethereum and MultiChain, but not on Bitcoin.
Limitations of blockchain 41
• Scalability
Currently, blockchain networks are not as scalable as, for example, current financial networks. This is a known
area of concern and a very ripe area for research.
• Adaptability
Often, blockchain is seen as a nascent technology. Even though this perspective is rapidly changing, there is
still a long way to go before the mass adoption of this technology. The challenge here is to allow blockchain
networks to be easier to use so that adoption can increase. In addition, several other challenges such as
scalability exist, which must be solved in order to increase adoption.
• Relatively immature technology
As compared to traditional IT systems that have benefited from decades of research, blockchain is still a new
technology and requires a lot of research to achieve maturity.
Limitations of blockchain 42
• Regulation
Due to its decentralized nature, regulation is almost impossible on blockchain. This is sometimes seen as a
barrier toward adoption because, traditionally, due to the existence of regulatory authorities, consumers have a
certain level of confidence that if something goes wrong they can hold someone accountable. However, in
blockchain networks, no such regulatory authority and control exists, which is an inhibiting factor for many
consumers.
Privacy is a concern on public blockchains such as Bitcoin where everyone can see every single transaction.
This transparency is not desirable in many industries such as the financial, law, or medical sectors. This is also a
known concern and a lot of valuable research with some impeccable solutions has already been developed.
However, further research is still required to drive the mass adoption of blockchain.
Types of blockchain 43
• Distributed ledgers
• a distributed ledger is a broad term describing shared databases;
• hence, all blockchains technically fall under the umbrella of shared databases or distributed ledgers.
• Although all blockchains are fundamentally distributed ledgers, all distributed ledgers are not necessarily
blockchains.
• A critical difference between a distributed ledger and a blockchain is that a distributed ledger does not
necessarily consist of blocks of transactions to keep the ledger growing. Rather, a blockchain is a special type of
shared database that is comprised of blocks of transactions.
• R3's Corda (https://www.corda.net) is a distributed ledger developed to record and manage agreements and is
especially focused on the financial services industry. On the other hand, more widely known blockchains like
Bitcoin and Ethereum make use of blocks to update the shared database.
44
• a distributed ledger is distributed among its participants and spread across multiple sites or
organizations.
• The fundamental idea here is that, unlike many other blockchains, the records are stored
contiguously instead of being sorted into blocks.
• This concept is used in Ripple, which is a blockchain- and cryptocurrency-based global payment
network.
45
• Distributed ledger or DLT commonly used to describe blockchain in the finance industry.
• In fact, DLT is now a very active and thriving area of research in the financial sector.
• From a financial sector point of view, DLTs are permissioned blockchains that are used by consortiums.
• DLTs usually serve as a shared database, with all participants known and verified.
• They do not have a cryptocurrency and do not require mining to secure the ledger.
• At a broader level, DLT is an umbrella term that represents Distributed Ledger Technology as a whole,
comprising of blockchains and distributed ledgers of different types
46
• Public blockchains
• They are open to the public, and anyone can participate as a node in the decision-making process.
• All users of these "permissionless" or "un-permissioned“ ledgers maintain a copy of the ledger on their
local nodes and use a distributed consensus mechanism to decide the eventual state of the ledger.
• Bitcoin and Ethereum are both considered public blockchains.
47
• Private blockchains
• That is, they are open only to a consortium or group of individuals or organizations who have
decided to share the ledger among themselves.
• There are various blockchains now available in this category, such as Kadena and Quorum.
• Optionally, both of these blockchains can also run in public mode if required, but their primary
purpose is to provide a private blockchain.
48
• Semi-private blockchains
• With semi-private blockchains, part of the blockchain is private and part of it is public.
• this is still just a concept today, and no real-world proofs of concept have yet been developed.
• With a semi-private blockchain, the private part is controlled by a group of individuals, while the public part is
open for participation by anyone.
• This hybrid model can be used in scenarios where the private part of the blockchain remains internal and shared
among known participants, while the public part of the blockchain can still be used by anyone, optionally
allowing mining to secure the blockchain.
• This type of blockchain can also be called a "semidecentralized“ model, where it is controlled by a single entity
but still allows for multiple users to join the network by following appropriate procedures.
49
• Permissioned ledger
• A permissioned ledger is a blockchain where participants of the network are already known and trusted.
• Permissioned ledgers do not need to use a distributed consensus mechanism; instead, an agreement protocol is
used to maintain a shared version of the truth about the state of the records on the blockchain.
• In this case, for verification of transactions on the chain, all verifiers are already preselected by a central
authority and, typically, there is no need for a mining mechanism.
• By definition, there is also no requirement for a permissioned blockchain to be private, as it can be a public
blockchain but with regulated access control.
• For example, Bitcoin can become a permissioned ledger if an access control layer is introduced on top of it that
verifies the identity of a user and then allows access to the blockchain.
50
• Shared ledger
• This is a generic term that is used to describe any application or database that is shared by the public or a
consortium. Generally, all blockchains fall into the category of a shared ledger.
• Tokenized blockchains
• These blockchains are standard blockchains that generate cryptocurrency as a result of a consensus process via
mining or initial distribution. Bitcoin and Ethereum are prime examples of this type of blockchain.
• Tokenless blockchains
• These blockchains are designed in such a way that they do not have the basic unit for the transfer of value.
However, they are still valuable in situations where there is no need to transfer value between nodes and only the
sharing of data among various trusted parties is required. This is similar to fully private blockchains, the only
difference being that the use of tokens is not required. This can also be thought of as a shared distributed ledger
used for storing and sharing data between the participants.