Module 1 Blockchain
Module 1 Blockchain
Module 1
Distributed Systems
Understanding distributed systems is essential for understanding blockchain.
Blockchain is a distributed system.
It is a distributed ledger that can be centralized or decentralized.
A blockchain is usually used as a decentralizedplatform.
It can be thought of as a system that has properties of the both decentralized
anddistributed paradigms.
It is a decentralized-distributed system.
Distributed systems are a computing paradigm whereby two or more nodes work with
each other in a coordinated fashion to achieve a common outcome.
It 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.
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.
This distributed system has six nodes, out of which one (N4) is a Byzantine node leading
to possible data inconsistency.
L2 is a link that is broken or slow, and this can lead to a partition in the network.
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
toleratethis and continue to work to achieve the desired result.
This problem has been an active areaof distributed system design research for many
years, and several algorithms and mechanismshave been proposed to overcome these
issues.
Distributed systems are so challenging to design that a theory known as the CAP
theorem has been proven.
CAP theorem states that a distributed system cannot have all three of the much-desired
properties simultaneously; that is, consistency, availability, and partition tolerance.
Even though blockchain can be considered to be both a distributed and decentralized
system, there are, however, critical differences between distributed systems and
decentralized systemsthat make both of these systems architecturally different.
Electronic cash
The concept of electronic cash (e-cash), or digital currency, is not new.
Since the 1980s, e-cash protocols have existed that are based on a model proposed by
David Chaum.
The idea of e-cash is essential in order to appreciate the first, and astonishingly
successful, application of blockchain, Bitcoin, and more broadly, cryptocurrencies in
general.
David Chaum solved both of these problems(Accountability and Anonymity) during his
work in the 1980s by using twocryptographic operations, namely, blind signatures and
secret sharing.
Blind signatures allow for signing a document without actuallyseeing it.
Secret sharing is a concept that enables the detection of double-spending, that is,using
the same e-cash token twice.
In 2009, the first practical implementation of an e-cash system named Bitcoin appeared.
The term cryptocurrency emerged later.
For the very first time, it solved the problem of distributedconsensus in a trustless
network.
It used public key cryptography with a PoW mechanism to provide a secure, controlled,
and decentralized method of minting digital currency.
The key innovation was the idea of an ordered list of blocks composed of transactions
which is cryptographically secured by the PoW mechanism to prevent double-spending in
a trustless environment.
Figure 1.2: The various ideas that supported the invention of Bitcoin and blockchain
Introduction to Blockchain
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.
The term "chain of blocks" evolved over the years into the word "blockchain.
Blockchain technology incorporates a multitude of applications that can be implemented
in various economic sectors.
Particularly in the finance sector, significant improvement in the performance of financial
transactions and settlements manifests as highly desirable time-and-cost reductions.
Nearly all economicsectors have already realized the potential and promise of blockchain,
and have embarked, orwill do so soon, on the journey to capitalize on the benefits of
blockchain technology.
2. Technical definition
Blockchain is a peer-to-peer, distributed ledger that is cryptographically secure, append-only,
immutable (extremely hard to change), and updateable only via consensus or agreement
among peers.
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.
Cryptographically secure
Cryptographically secure means that cryptography has been used to provide security
services that make this ledger secure against tampering andmisuse.
These services include non-repudiation, data integrity, and data origin
authentication.
Append-only
Append-only 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.
The most critical attribute of a blockchain is that it is updateable only via consensus.
This is what gives it the power of decentralization.
1. Address
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.
2. Transaction
A transaction is the fundamental unit of a blockchain.
A transaction represents a transfer of value from one address to another.
3. Block
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 selection of transactions bundled together
and organized logically.
A block contains several elements,
i) Pointer’s to Previous Block’s Hash
A reference to a previous block is also included in the block unless it is a genesis block.
4. Peer-to-peer network
A peer-to-peer network is a network topology wherein all peers can communicate with
each other and send and receive messages.
5. The scripting or programming language
Scripts or programs perform various operations on a transaction in order to facilitate
various functions.
For example, in Bitcoin, transaction scripts are predefined in a language called Script,
which consists of sets of commands that allow nodes to transfer bitcoins from one
address to another.
Script is a limited language, it only allows essential operations that are necessary for
executing transactions, but it does not allow for arbitrary program development.
To facilitate arbitrary program development on a blockchain, a Turing complete
programming language is needed, and it is now a very desirable feature to have for
blockchains.
6. Virtual Machine
A virtual machine allows Turing complete code to be run on a blockchain (as smart
contracts); whereas a transaction script is limited in its operation.
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).
7. 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.
8. Smart contracts
These programs run on top of the blockchain and encapsulate the business logic to be
executed when certain conditions are met.
These programs are enforceable and automatically executable.
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.
9. Node
A node in a blockchain network performs various functions depending on the role that it
takes on.
A node can propose and validate transactions and perform mining to facilitate consensus
and secure the blockchain.
This goal is achieved by following a consensus protocol (most commonly PoW).
Nodes can also perform other functions such as simple payment verification (lightweight
nodes), validation, and many other functions depending on the type of the blockchain
used and the role assigned to the node.
Nodes also perform a transaction signing function.
Transactions are first created by nodes and then also digitally signed by nodes using
private keys as proof that they are the legitimate owner of the asset that they wish to
transfer to someone else on the blockchain network.
A high-level diagram of blockchain architecture highlighting the key elements is shown in
Figure 1.5.
The preceding diagram shows a four-node blockchain network (top), each maintaining a
chain of blocks, virtual machine, state machine, and address.
The blockchain is then further magnified(middle) to show the structure of the chain of
blocks, which is again magnified (bottom) to showthe structure of a transaction.
1. 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. 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.
Features of Blockchain
The features of a blockchain are as follows:
1. Distributed consensus
Distributed consensus is the primary underpinning of a blockchain.
This mechanism allows a blockchain to present a single version of the truth, which is
agreed upon by all parties without the requirement of a central authority.
2. Transaction verification
• 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.
3. Platform for smart contracts
• A blockchain is a platform on which programs can run to execute business logic on
behalf of the users.
• Not all blockchains have a mechanism to execute smart contracts.
• However, this is a very desirable feature, and it is available on newer blockchain
platforms such as Ethereum and MultiChain.
4. Transferring value between peers
• Blockchain enables the transfer of value between its users via tokens.
• Tokens can be thought of as a carrier of value.
5. Generation of cryptocurrency
• This feature is optional depending on the type of blockchain in use.
• A blockchain can create cryptocurrency as an incentive to its miners who validate the
transactions and spend resources to secure the blockchain.
6. Smart property
• It is now possible to link a digital or physical asset to the blockchain in such a secure and
precise manner that it cannot be claimed by anyone else.
• You are in full control of your asset, and it cannot be double-spent or double-owned.
• Compare this with a digital music file, for example, which can be copied many times
without any controls.
• While it is true that many Digital Rights Management (DRM) schemes are being used
currently along with copyright laws, but none of them is enforceable in such a way as
blockchain based DRM can be.
• Blockchain can provide DRM functionality in such a way that it can be enforced fully.
7.Provider of security
• 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 privacy and confidentiality of transactions.
• As such, the privacy and confidentiality of transactions on the blockchain is being
researched very actively, and advancements are already being made.
• It could be argued that, in many situations, confidentiality is not needed and transparency
is preferred.
8.Immutability
• This is another critical feature of blockchain.
• Once records are added to the blockchain, they are immutable.
• There is the remote possibility of rolling back changes, but this is to be avoided at all
costs as doing so would consume an exorbitant amount of computing resources.
• For example, with Bitcoin if a malicious user wants to alter previous blocks, then it
would require computing the PoW once again for all those blocks that have already been
added to the blockchain.
• This difficulty makes the records on a blockchain essentially immutable.
9. Uniqueness
• This blockchain feature ensures that every transaction is unique and has not already been
spent (double-spend problem).
• This feature is especially relevant with cryptocurrencies, where detection and avoidance
of double spending are a vital requirement.
Benefits of Blockchain
The benefits of blockchain technology are as follows:
1. 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.
2. Transparency and trust
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
wherepersonal discretion in relation to selecting beneficiaries needs to be restricted.
3. 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 sochallenging and nearly
impossible, this is seen as a benefit to maintaining an immutable ledger of transactions.
4. High availability
As the system is based on thousands of nodes in a peer-to-peernetwork, and the data is
replicated and updated on every node, the system becomeshighly available.
Even if some nodes leave the network or become inaccessible, thenetwork as a whole
continues to work, thus making it highly available.
This redundancy results in high availability.
5. Highly secure
All transactions on a blockchain are cryptographically secured and thusprovide 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 technologythat ensures the integrity and
availability of data.
Other security services, such as non-repudiation and authentication, are
also provided by blockchain, as all actions are secured using private keys and digital
signatures.
6. Simplification of current paradigms
The current blockchain model in many industries, such as finance or health, is somewhat
disorganized.
In this model, multiple entities maintain their own databases and data sharing can become
very difficult due to the disparate nature of the systems.
However, as a blockchain can serve as a single shared ledger among many interested
parties, this can result in simplifying the model by reducing the complexity of managing
the separate systems maintained by each entity.
7. Faster dealings
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.
8. 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 arepaid to
such parties.
9. Platform for smart contracts
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.
It is available on newer blockchain platforms such as Ethereum and MultiChain, but not
on Bitcoin.
10. Smart property
It is possible to link a digital or physical asset to the blockchain in such a secure and
precise manner that it cannot be claimed by anyone else.
You are in full control of your asset, and it cannot be double-spent or double-owned.
Compare this with a digital music file, for example, which can be copied many times
without any controls.
While it is true that many Digital Rights Management (DRM) schemes are being used
currently along with copyright laws, none of them are enforceable in the way a
blockchain-based DRM can be.
Blockchain can provide digital rights management functionality in such a way that it can
be enforced fully.
On a blockchain, however, if you own an asset, no one else can claim it unless you decide
to transfer it.
Limitations of Blockchain
The most sensitive blockchain problems are as follows:
1. Scalability
Currently, blockchain networks are not as scalable as, for example, currentfinancial
networks.
This is a known area of concern and a very ripe area for research.
2. Adoption
3. Regulation
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.
• Some of these advancements have already been realized, while others are anticipated in
the near future based on the current rate of advancement in blockchain technology.
Different tiers of blockchain are as follows:
1. Blockchain 1.0
• This tier was introduced with the invention of Bitcoin, and it is primarily used for
cryptocurrencies.
• This first generation of blockchain technology include only cryptographic currencies.
• All alternative cryptocurrencies as well as Bitcoin fall into this category.
• It includes core applications such as payments and applications.
• This generation started in 2009 when Bitcoin was released and ended in early 2010.
2. Blockchain 2.0
• This second blockchain generation is used by financial services and smart contracts.
• This tier includes various financial assets, such as derivatives, options, swaps, and bonds.
• Applications that go beyond currency, finance, and markets are incorporated at this tier.
• Ethereum, Hyperledger, and other newer blockchain platforms are considered part of
Blockchain 2.0.
• This generation started when ideas related to using blockchain for other purposes started
to emerge in 2010.
3. Blockchain 3.0
• This third blockchain generation is used to implement applications beyond the financial
services industry and is used in government, health, media, the arts, and justice.
• Ethereum, Hyperledger, and newer blockchains with the ability to code smart contracts
are considered part of this blockchain technology tier.
• This generation of blockchain emerged around 2012 when multiple applications of
blockchain technology in different industries were researched.
4. Blockchain X.0
• This generation represents a vision of blockchain singularity where one day there will be
a public blockchain service available that anyone can use just like the Google search
engine.
• It will provide services for all realms of society.
• It will be a public and open distributed ledger with general-purpose rational agents
(Machina economicus) running on a blockchain, making decisions, and interacting with
other intelligent autonomous agents on behalf of people, and regulated by code instead
of law or paper contracts.
• This does not mean that law and contracts will disappear, instead law and contracts will
be implementable in code.
• Machina Economicus is a concept which comes from the field of Artificial Intelligence
(AI) andcomputational economics.
• It can be defined as a machine that makes logical and perfect decisions.
Example:
• Consider a distributed system with two nodes.
• Apply the three theorem properties on this smallest of possible distributed systems only
with two nodes:
1. Consistency is achieved if both nodes have the same shared state; that is, they have the
same up to-date copy of the data.
2. Availability is achieved if both nodes are up and running and responding with the latest
copy of data.
3. Partition tolerance is achieved if, despite communication failure or delay between nodes,
the network (distributed system) continues to operate.
Consider scenario where a partition occurs, and nodes can no longer communicate with
each other.
If new updated data comes in now, it can only be updated on one node only.
In that case, if the node accepts the update, then only that one node in the network is
updated and therefore consistency is lost.
If the update is rejected by the node, that would result in loss of availability.
In that case, due to partition tolerance, both availability and consistency are unachievable.
The choice of the consensus algorithm to utilize is governed by the type of blockchain
in use; that is, not all consensus mechanisms are suitable for all types of blockchains.
For example, in public permissionless blockchains, it would make sense to use PoW
instead of mechanisms that are more suitable for permissioned blockchains, such as
Proof of Authority (PoA) or traditional Byzantine fault-tolerant consensus mechanisms.
Therefore, it is essential to choose an appropriate consensus algorithm for a particular
blockchain project.
Consensus is a process of achieving agreement between distrusting nodes on the final
state of data.
To achieve consensus, different algorithms are used.
It is easy to reach an agreement between two nodes (in client-server systems, for
example), but when multiple nodes are participating in a distributed system and they need
to agree on a single value, it becomes quite a challenge to achieve consensus.
This process of attaining agreement on a common state or value among multiple nodes
despite the failure of some nodes is known as distributed consensus.
Consensus in Blockchain
Consensus is a distributed computing concept that has been used in blockchain in order to
provide a means of agreeing to a single version of the truth by all peers on the blockchain
network.
Following describes the two main categories of consensus mechanisms:
This scheme is a combination of PoS and PoW, which ensures that a stakeholder is
selected in a pseudorandom but uniform fashion.
This is a comparatively more energy-efficient mechanism as compared to PoW. It utilizes
a new concept called "Follow the Satoshi."
In this scheme, PoW and PoS are combined together to achieve consensus and a good
level of security.
This scheme is more energy efficient as PoW is used only in the first stage of the
mechanism; after the first stage, it switches to PoS, which consumes negligible energy.
11. Proof of Capacity (PoC)
This scheme uses hard disk space as a resource to mine the blocks.
This is different from PoW, where CPU resources are used.
In PoC, hard disk space is utilized for mining and, as such, is also known as hard drive
mining.
This concept was first introduced in the BurstCoin cryptocurrency.
12. Proof of Storage
This scheme allows for the outsourcing of storage capacity.
This scheme is based on the concept that a particular piece of data is probably stored by a
node, which serves as a means to participate in the consensus mechanism.
Several variations of this scheme have been proposed, such as Proof of Replication, Proof
of Data Possession, Proof of Space, and Proof of Space-time.
13. Proof of Authority (PoA)
This scheme utilizes the identity of the participants called validators as a stake on the
network.
Validators are known and have the authority to propose new blocks.
Validators propose the new blocks and validate them as per blockchain rules.
Commonly used PoA algorithms are Clique and Aura.