Home Data Mastering Blockchain - Fourth Edition

Mastering Blockchain - Fourth Edition

By Imran Bashir
books-svg-icon Book
Subscription FREE
eBook + Subscription €14.99
eBook €29.99
Print + eBook €37.99
READ FOR FREE Free Trial for 7 days. €14.99 p/m after trial. Cancel Anytime! BUY NOW BUY NOW BUY NOW
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
READ FOR FREE Free Trial for 7 days. €14.99 p/m after trial. Cancel Anytime! BUY NOW BUY NOW BUY NOW
Subscription FREE
eBook + Subscription €14.99
eBook €29.99
Print + eBook €37.99
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
  1. Free Chapter
    Blockchain 101
About this book
Blockchain is the backbone of cryptocurrencies, it has had a massive impact in many sectors, including finance, supply chains, healthcare, government, and media. It’s also being used for cutting edge technologies such as AI and IoT. This new edition is thoroughly revised to offer a practical approach to using Ethereum, Hyperledger, Fabric, and Corda with step-by-step tutorials and real-world use-cases to help you understand everything you need to know about blockchain development and implementation. With new chapters on Decentralized Finance and solving privacy, identity, and security issues, as well as bonus online content exploring alternative blockchains, this is an unmissable read for everyone who wants to gain a deep understanding of blockchain. The book doesn’t shy away from advanced topics and practical expertise, such as decentralized application (DApp) development using smart contracts and oracles, and emerging trends in the blockchain space. Throughout the book, you’ll explore blockchain solutions beyond cryptocurrencies, such as the IoT with blockchain, enterprise blockchains, and tokenization, and gain insight into the future scope of this fascinating and disruptive technology. By the end of this blockchain book, you will have gained a thorough comprehension of the various facets of blockchain and understand the potential of this technology in diverse real-world scenarios.
Publication date:
March 2023
Publisher
Packt
Pages
818
ISBN
9781803241067

 

Blockchain 101

It is very likely that if you are reading this book, you already have heard about blockchain and have some fundamental appreciation of its enormous potential. If not, then let me tell you that this 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, by making them more efficient, trustworthy, and transparent.

This chapter introduces blockchain technology, its technical foundations, the theory behind it, and various technologies that have contributed to building what is known today as blockchain. The theoretical foundations of distributed systems are described first. Next, the precursors of Bitcoin are presented. Finally, blockchain technology is introduced. This approach is a logical way of understanding blockchain technology, as the roots of blockchain are in distributed systems and cryptography. We will be covering a lot of ground quickly here, but don’t worry—we will go over a great deal of this material in much greater detail as you move throughout the book.

In this chapter, we’ll focus on:

  • The growth of blockchain technology
  • Distributed systems
  • The history of blockchain
  • Introducing blockchain
  • Types of blockchain
 

The growth of blockchain technology

With the invention of Bitcoin in 2008, the world was introduced to a new concept that revolutionized the whole of society. It was something that promised to have an impact upon every industry. This new concept was blockchain, the underlying technology that underpins Bitcoin.

Some describe blockchain as a revolution, whereas another school of thought believes that it is going to be more evolutionary, and it will take many years before any practical benefits of blockchain reach fruition. This thinking is correct to some extent, but, in my opinion, the revolution has already begun.

It is a technology that has an impact on current technologies too and possesses the ability to change them at a fundamental level.

Progress towards maturity

Around 2013, some ideas emerged regarding using blockchain technology for other applications instead of only cryptocurrencies. Then, in 2014, some research and experimentation began, which led to proofs of concept, further research, and full-scale trial projects between 2015 and 2017. In 2015, Ethereum was launched as the first smart contract programmable blockchain, which unlocked many possibilities. Interest in enterprise-grade blockchains originated around the same time. Around that time, we also saw several projects, such as Everledger, Quorum, and Corda.

In addition, the development of novel monolithic and multichain architectures rapidly evolved after 2018. Some key examples of novel protocols include Solana, Avalanche, and Polkadot, which we will discuss later in this book.

Currently, as of the second quarter of 2023, decentralized finance (DeFi), non-fungible tokens (NFTs), and tokenization in general are very popular applications of blockchain. They are already in mainstream usage by millions of users around the world who are engaging in DeFi services. It is expected that within three years or so, DeFi will stabilize into a mature mainstream technology. With all the activity and adoption in DeFi and NFT trading, we can say that to some extent blockchain is already part of our daily lives. Of course, further maturity is required, especially from a regulation and security perspective, but millions of users are already using blockchain regularly, either to make payments, trade NFTs, get loans, or play games.

See the following article for details on which platforms these millions are making use of: https://beincrypto.com/ethereum-defi-users-reach-new-highs-over-4m-growing-roughly-8x-in-a-year/

This trend is only expected to grow and, during 2022 and onwards, more and more research and development will be carried out. There will be more focus on the regulation and standardization of blockchain technology. Numerous projects are already production ready, and more adoption is expected in the coming years.

Progress in blockchain technology almost feels like the internet dot-com boom of the late 1990s.

Research in the scalability of blockchains, where blockchains can handle many transactions like traditional financial networks, has led to the development of layer 2 architectures and multi-chain architectures. Advancement in making zero-knowledge proofs practical helped tremendously in making layer 2 solutions a reality. Layer 2 solutions are under heavy research and development now, and many mechanisms have been introduced, such as Plasma, rollups, sidechains, Lightning Network, and many others.

As of 2022, blockchain is already something that many people use every day. With DeFi, NFTs, cryptocurrencies, and Metaverses, blockchain has attracted millions of users. Most of the attraction is because of financial incentives gained by the trading and investment of digital assets such as NFTs and other DeFi services; however, researchers and academics are also interested in studying and developing the theory of these applications and relevant protocols.

Undoubtedly, further maturation and the adoption of blockchain technology is expected in the coming years.

Rising interest

Interest in blockchain technology has risen quite significantly over the last few years. Once dismissed by some simply as “geek money” from a cryptocurrency point of view or as something that was just not considered worth pursuing, blockchain is now being researched by the largest companies and organizations around the world. Millions of dollars are being spent to adopt and experiment with this technology.

Also, the interest in blockchain within academia is astounding, and many educational establishments—including prestigious universities around the world—are conducting research and development on blockchain technology. There are not only educational courses being offered by many institutions, but academics are also conducting high-quality research and producing many insightful research papers on the topic. There are also several research groups and conferences worldwide that specifically focus on blockchain research. This research community is beneficial for the growth of the entire blockchain ecosystem. A simple online search of “blockchain research groups” would reveal hundreds, if not thousands, of these research groups.

There are also various consortiums, such as Enterprise Ethereum Alliance (EEA) at https://entethalliance.org and Hyperledger at https://www.hyperledger.org, that have been established for the research, development, and standardization of blockchain technology. Moreover, the Institute of Electrical and Electronics Engineers (IEEE) and the International Standards Organization (ISO) have also started their attempts to standardize various aspects of blockchain technology.

Many start-ups are providing blockchain-based solutions already. A simple trend search on Google reveals the immense scale of interest in blockchain technology over the last few years. Hot topics include decentralized autonomous organizations (DAOs), fully autonomous and transparent member-governed entities developed using smart contracts with no central authority. Meanwhile, NFTs, through which digital art is routinely bought and sold for millions of dollars, and Metaverses have been making the news.

A Metaverse is a computer-simulated three-dimensional environment. A convergence of our digital and real-world life, they provide a virtual world for the users to perform activities such as social interactions, engaging in business, and shopping. This virtual world is usually accessible via specialized hardware called VR headsets, enhancing the virtual world experience.

This is not a new concept; in the Web 2.0 days (the usual internet that we know and use daily), Second Life, World of Warcraft, and quite a few other similar platforms rose to prominence, as entities centrally owned by shareholders. In the Web 3.0 era (post blockchain), Decentraland and the Sandbox, among many others, are becoming popular, based on decentralized foundations and community governance.

In this book, we are going to learn what exactly blockchain technology is and how it can reshape businesses, multiple industries, and indeed everyday life by bringing about a plenitude of benefits such as decentralized trust, efficiency, cost savings, transparency, and security. We will also explore what decentralization is, smart contracts, and how solutions can be developed and implemented using blockchain platforms such as Ethereum.

While there are many benefits of blockchain technology, there are some challenges too that can cause hurdles in adoption and are being actively researched, such as scalability, privacy, and security. We’ll also take a critical look at blockchain and discuss its limitations and challenges.

We shall begin our exploration of blockchain by looking at distributed systems in the following section. This is a foundational paradigm on which blockchain is based, and we must have a good grasp of what distributed systems are before we can meaningfully discuss blockchain in detail.

 

Distributed systems

Understanding distributed systems is essential to our understanding of blockchain, as blockchain is a distributed system at its core. It is a distributed ledger that can be centralized or decentralized. A blockchain is originally intended to be and is usually used as a decentralized platform. It can be thought of as a system that has properties of both decentralized and distributed paradigms. It is a decentralized-distributed system.

A distributed system is 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. It is composed of processes (nodes) and channels (communication channels) where nodes communicate by passing messages. A blockchain is a message-passing distributed system.

A node is an individual player (a computer) in a distributed system. All nodes can send and receive messages to and from each other. Nodes can be honest, faulty, or malicious, and they have memory and a processor. A node that exhibits arbitrary behavior is known as a Byzantine node after the Byzantine Generals problem.

The Byzantine Generals problem

In 1982, a thought experiment was proposed by Lamport et al. in their research paper, The Byzantine Generals Problem, which is available here: https://www.microsoft.com/en-us/research/publication/byzantine-generals-problem/

In this problem, a group of army generals who lead different parts of the Byzantine army is planning to attack or retreat from a city. The only way of communicating with them is via a messenger. They need to agree to strike at the same time to win. The issue is that one or more generals might be traitors who could send a misleading message. Moreover, the messenger could be captured by the city, resulting in no message delivery. Therefore, there is a need for a viable mechanism that allows agreement among the generals, even in the presence of the treacherous ones, and message loss, so that the attack can still take place at the same time. As an analogy for distributed systems, the generals can be considered as honest nodes, the traitors as Byzantine nodes (that is, nodes with arbitrary behavior), the messenger can be thought of as a channel of communication with the generals, and a captured messenger as a delayed or lost message. Several solutions were presented to this problem in the paper by Lamport et al. in 1982.

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.

A small-scale example of a distributed system is shown in the following diagram. This distributed system has six nodes, 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:

Diagram  Description automatically generated

Figure 1.1: Design of a distributed system: N4 is a Byzantine node and L2 is broken or a slow network link

Two key challenges of a distributed system design are 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.

Distributed systems are challenging to design. It has been proven that a distributed system cannot have all three of the much-desired properties of consistency, availability, and partition tolerance simultaneously. This principle is known as the CAP theorem.

CAP theorem

The CAP theorem, also known as Brewer’s theorem, was introduced by Eric Brewer in 1998 as a conjecture. In 2002, it was proven as a theorem by Seth Gilbert and Nancy Lynch. The theorem states that any distributed system cannot have consistency, availability, and partition tolerance simultaneously:

  • Consistency is a property that ensures that all nodes in a distributed system have a single, current, and identical copy of the data. Consistency is achieved using consensus algorithms to ensure that all nodes have the same copy of the data. This is also called state machine replication (SMR). The blockchain is a means of achieving state machine replication.
  • Availability means that the nodes in the system are up, accessible, 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.

A Venn diagram is commonly used to visualize the CAP theorem, as shown below:

Diagram, venn diagram  Description automatically generated

Figure 1.2: CAP theorem

The preceding diagram depicts that only two properties at a time can be attained; either AP, CA, or CP.

In summary:

  • If we opt for CP (consistency and partition tolerance), we sacrifice availability.
  • If we opt for AP (availability and partition tolerance), we sacrifice consistency.
  • If we opt for AC (availability and consistency), we sacrifice partition tolerance.

Note that AC does not really exist. The CAP theorem in practice means that in the case of a network partition, a distributed system is either available or consistent. As network partitions cannot be ignored, the choice is between consistency or availability when a network partition occurs.

We can explain this concept with the following example.

Let’s imagine that there is a distributed system with two nodes. Now, let’s apply the three theorem properties to this smallest of possible distributed systems with only two nodes:

  • Consistency is achieved if both nodes have the same shared state; that is, they have the same up-to-date copy of the data.
  • Availability is achieved if both nodes are up and running and responding with the latest copy of data.
  • Partition tolerance is achieved if, despite communication failure or delay between nodes, the network (distributed system) continues to operate.

Now think of a scenario where a partition occurs and nodes can no longer communicate with each other. If newly updated data comes in now, it can only be updated on one node. If the node accepts the update, then only one node in the network is updated, and consistency is lost. If the node rejects the update, that will result in a loss of availability. This means that either availability or consistency is unachievable due to the network partition. This is strange because somehow, blockchain manages to achieve all these properties, violating the theorem (especially in its most successful implementation, Bitcoin)—or does it?

In blockchains, consistency is sacrificed in favor of availability and partition tolerance. In this scenario, consistency (C) in the blockchain is not achieved simultaneously with partition tolerance (P) and availability (A), but it is achieved over time. This is called eventual consistency, where consistency is achieved due to validation from multiple nodes over time. There can be a temporary disagreement between nodes on the final state, but it is eventually agreed upon. For example, in Bitcoin, multiple transaction confirmations are required to achieve a good confidence level that transactions may not be rolled back in the future. Eventually, a consistent view of transaction history is available in all nodes. Multiple confirmations of a transaction over time provide eventual consistency in Bitcoin. For this purpose, the process of mining was introduced in Bitcoin. Mining is a process that facilitates the achievement of consensus by using the Proof of Work (PoW) algorithm. At a higher level, mining can be defined as a process that’s used to add more blocks to the blockchain. We will cover more on this later in Chapter 6, Bitcoin Architecture.

PACELC theorem

An extension of the CAP theorem called PACELC was first proposed by Daniel J. Abadi from Yale University. It states that, in addition to the three properties proposed by CAP, there are also tradeoffs between latency and consistency. It states that tradeoffs between consistency and latency always exist in replicated systems, whereas CAP is only applicable when there are network partitions. In other words, it means that even if no network partitions occur, under normal operation the tradeoff between consistency and latency exists. For example, some databases may choose to give up consistency for lower latency, and some databases could pay the availability and latency costs to achieve consistency. This is true for replicated systems and presents a more inclusive picture of consistency tradeoffs in distributed systems.

PACELC was formally proved in a paper available here: https://dl.acm.org/doi/10.1145/3197406.3197420

With a better understanding of distributed systems, let’s now talk about blockchain itself. First, we’ll begin with a brief rundown of the history of blockchain and Bitcoin.

       
About the Author
  • Imran Bashir

    Imran Bashir has an M.Sc. in Information Security from Royal Holloway, University of London, and has a background in software development, solution architecture, infrastructure management, and IT service management. He is also a member of the Institute of Electrical and Electronics Engineers (IEEE) and the British Computer Society (BCS). Imran has extensive experience in both the public and financial sectors, having worked on large-scale IT projects in the public sector before moving to the financial services industry. Since then, he has worked in various technical roles for different financial companies in Europe's financial capital, London.

    Browse publications by this author
Mastering Blockchain - Fourth Edition
Unlock this book and the full library FREE for 7 days
Start now