The second edition of this book will provide in-depthinsights into decentralization, smart contracts, and various blockchain platforms such asEthereum, Bitcoin, and Hyperledger Fabric..
Trang 3Second Edition
Copyright © 2018 Packt Publishing
All rights reserved No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form
or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented However, the information contained in this book is sold without warranty, either express or implied Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals However, Packt Publishing cannot guarantee the accuracy
of this information.
Acquisition Editors: Ben Renow-Clarke, Suresh M Jain
Project Editor: Suzanne Coutinho
Content Development Editor: Alex Sorrentino
Technical Editor: Bhagyashree Rai
Indexer: Tejal Daruwale Soni
Graphics: Tom Scaria
Production Coordinator: Aparna Bhagat
First published: March 2017
Second edition: March 2018
Trang 4Mapt is an online digital library that gives you full access to over 5,000 books and videos, aswell as industry leading tools to help you plan your personal development and advanceyour career For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videosfrom over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF andePub files available? You can upgrade to the eBook version at www.PacktPub.com and as aprint book customer, you are entitled to a discount on the eBook copy Get in touch with us
at service@packtpub.com for more details
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for arange of free newsletters, and receive exclusive discounts and offers on Packt books andeBooks
Trang 5About the author
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 sixteen years' of experience in the public and financial sectors He worked onlarge 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 inEurope's financial capital, London He is currently working for an investment bank inLondon as Vice President in the Technology department
I would like to thank the talented team at Packt, including Ben Renow-Clarke, Suzanne
Coutinho, Alex Sorrentino, Gary Schwartz, and Bhagyashree Rai, who provided prompt
guidance and valuable feedback throughout this project I am also extremely thankful to the reviewer, Pranav Burnwal, who provided constructive and very useful feedback that helped
me tremendously to improve the material in this book.
I thank my wife and children for putting up with my all-night and weekend-long writing sessions.
Above all, I would like to thank my parents, whose blessings have made everything possible for me.
Trang 6Pranav Burnwal has a background in Research and Development, and he has been working
with cutting-edge technologies for the past few years The technologies he works on rangefrom blockchain, big data, analytics (log and data), cloud, to message queues, NoSQL, webservers, and so on He has worked across various domains ranging from BFSI, HLS, FMCG,and automobiles to name a few
Pranav is an active community member in multiple communities He is the Regional Headfor Blockchain Education Network (BEN), a registered NGO and a worldwide network ofpeople of blockchain He has also organized multiple meetups and a start-up weekend inIndia
Pranav has also been an active trainer in the blockchain space for an exciting period of threeyears now, for an audience ranging from junior developers to senior VPs This has alsogiven him insights into how people understand a new and complex technology, whichhelped him frame this book in the best interest of the readers
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com andapply today We have worked with thousands of developers and tech professionals, justlike you, to help them share their insight with the global tech community You can make ageneral application, apply for a specific hot topic that we are recruiting an author for, orsubmit your own idea
Trang 8Blockchain and full ecosystem decentralization 49
Chapter 3: Symmetric Cryptography 60
Working with the OpenSSL command line 60
Trang 9Keystream generation mode 73 Message authentication mode 73
ECC private and public key pair 99
Trang 10Collision resistance 104
Design of Secure Hash Algorithms 106
Design of SHA-3 (Keccak) 108 OpenSSL example of hash functions 109 Message Authentication Codes 109 MACs using block ciphers 109
How to generate a digital signature using OpenSSL 117
Trang 11Chapter 6: Bitcoin Network and Payments 179
The Bitcoin network 179
Trang 13Third-party mixing protocols 227
Downloading and compiling nheqminer 255
Trang 14The yellow paper 277
Ethereum – bird's eye view 280
The Ethereum network 284
Components of the Ethereum ecosystem 286
State storage in the Ethereum blockchain 296
Trang 15The genesis block 321
Funding the account with bitcoin 342
Creating accounts using the parity command line 347
Applications (DApps and DAOs) developed on Ethereum 347
Starting up the private network 358
Trang 16Block explorer for private net / local Ethereum block explorer 372
Trang 17Chapter 14: Introducing Web3 409
Checking availability by calling any web3 method 422
The reference architecture 466
Trang 18Consensus in Hyperledger Fabric 481 The transaction life cycle in Hyperledger Fabric 482
The permissioning service 494
Trang 19Platforms and frameworks 522
Trang 20Formal verification and analysis 576
Trang 23This book has one goal, to introduce theoretical and practical aspects of the blockchaintechnology This book contains all material that is necessary to become a blockchain
technical expert Since the publication of the first edition of this book, a lot has changed andprogressed further with regards to blockchain; therefore, a need to update the book hasarisen
The multitude of benefits envisaged by the implementation of blockchain technology hassparked profound interest among researchers from academia and industry who are
tirelessly researching this technology As a result, many consortia, working groups, projects,and professional bodies have emerged, which are involved in the development and furtheradvancement of this technology The second edition of this book will provide in-depthinsights into decentralization, smart contracts, and various blockchain platforms such asEthereum, Bitcoin, and Hyperledger Fabric After reading this book, readers will be able todevelop a deep understanding of inner workings of the blockchain technology and will beable to develop blockchain applications
This book covers all topics relevant to the blockchain technology, including cryptography,cryptocurrencies, Bitcoin, Ethereum, and various other platforms and tools used for
blockchain development It is recommended that readers have a basic understanding ofcomputer science and basic programming experience to benefit fully from this book
However, if that is not the case then still this book can be read easily, as relevant
background material is provided where necessary
Who this book is for
This book is for anyone who wants to understand blockchain in depth It can also be used as
a reference by developers who are developing applications for blockchain Also, this bookcan be used as a textbook for courses related to blockchain technology and
cryptocurrencies It can also be used as a learning resource for various examinations andcertifications related to cryptocurrency and blockchain technology
Trang 24What this book covers
Chapter 1, Blockchain 101, introduces the basic concepts of distributed computing on which
blockchain technology is based It also covers history, definitions, features, types, andbenefits of blockchains along with various consensus mechanisms that are at the core of theblockchain technology
Chapter 2, Decentralization, covers the concept of decentralization and its relationship with
blockchain technology Various methods and platforms that can be used to decentralize aprocess or a system have also been introduced
Chapter 3, Symmetric Cryptography, introduces the theoretical foundations of symmetric
cryptography, which is necessary to understand that how various security services such asconfidentiality and integrity are provided
Chapter 4, Public Key Cryptography, introduces concepts such as public and private keys,
digital signatures and hash functions with practical examples Finally, an introduction tofinancial markets is also included as there are many interesting use cases for blockchaintechnology in the financial sector
Chapter 5, Introducing Bitcoin, covers Bitcoin, the first and largest blockchain It introduces
technical concepts related to bitcoin cryptocurrency in detail
Chapter 6, Bitcoin Network and Payments, covers Bitcoin network, relevant protocols and
various Bitcoin wallets Moreover, advanced protocols, Bitcoin trading and payments is alsointroduced
Chapter 7, Bitcoin Clients and APIs, introduces various Bitcoin clients and programming
APIs that can be used to build Bitcoin applications
Chapter 8, Alternative Coins, introduces alternative cryptocurrencies that were introduced
after the invention of Bitcoin It also presents examples of different altcoins, their properties,and how they have been developed and implemented
Chapter 9, Smart Contracts, provides an in-depth discussion on smart contracts Topics such
as history, the definition of smart contracts, Ricardian contracts, Oracles, and the theoreticalaspects of smart contracts are presented in this chapter
Trang 25Chapter 10, Ethereum 101, introduces the design and architecture of the Ethereum
blockchain in detail It covers various technical concepts related to the Ethereum blockchainthat explains the underlying principles, features, and components of this platform in depth
Chapter 11, Further Ethereum, continues the introduction of Ethereum from pervious
chapter and covers topics related to Ethereum Virtual Machine, mining and supportingprotocols for Ethereum
Chapter 12, Ethereum Development Environment, covers the topics related to setting up
private networks for Ethereum smart contract development and programming
Chapter 13, Development Tools and Frameworks, provides a detailed practical introduction to
the Solidity programming language and different relevant tools and frameworks that areused for Ethereum development
Chapter 14, Introducing Web3, covers development of decentralized applications and smart
contracts using the Ethereum blockchain A detailed introduction to Web3 API is providedalong with multiple practical examples and a final project
Chapter 15, Hyperledger, presents a discussion about the Hyperledger project from the
Linux Foundation, which includes different blockchain projects introduced by its members
Chapter 16, Alternative Blockchains, introduces alternative blockchain solutions and
platforms It provides technical details and features of alternative blockchains and relevantplatforms
Chapter 17, Blockchain – Outside of Currencies, provides a practical and detailed introduction
to applications of blockchain technology in fields others than cryptocurrencies, includingInternet of Things, government, media, and finance
Chapter 18, Scalability and Other Challenges, is dedicated to a discussion of the challenges
faced by blockchain technology and how to address them
Chapter 19, Current Landscape and What's Next, is aimed at providing information about the
current landscape, projects, and research efforts related to blockchain technology Also,some predictions based on the current state of blockchain technology have also been made
Trang 26To get the most out of this book
All examples in this book have been developed on Ubuntu 16.04.1 LTS (Xenial)and macOS version 10.13.2 As such, it is recommended to use Ubuntu or anyother Unix like system However, any appropriate operating system, eitherWindows or Linux, can be used, but examples, especially those related toinstallation, may need to be changed accordingly
Examples related to cryptography have been developed using the OpenSSL1.0.2g 1 Mar 2016 command-line tool
Ethereum Solidity examples have been developed using Remix IDE, availableonline at https://remix.ethereum.org
Ethereum Byzantine release is used to develop Ethereum-related examples Atthe time of writing, this is the latest version available and can be downloadedfrom https://www.ethereum.org/
Examples related to IoT have been developed using a Raspberry Pi kit by Vilros,but any aapropriate latest model or kit can be used Specifically, Raspberry Pi 3Model B V 1.2 has been used to build the hardware example of IoT Node.jsV8.9.3 and npm V5.5.1 have been used to download related packages and runNode js server for IoT examples
The Truffle framework has been used in some examples of smart contractdeployment, and is available at http://truffleframework.com/ Any latestversion available via npm should be appropriate
Download the example code files
You can download the example code files for this book from your account at
www.packtpub.com If you purchased this book elsewhere, you can visit
www.packtpub.com/support and register to have the files emailed directly to you
You can download the code files by following these steps:
Log in or register at www.packtpub.com
Trang 27Once the file is downloaded, please make sure that you unzip or extract the folder using thelatest version of:
WinRAR/7-Zip for Windows
Zipeg/iZip/UnRarX for Mac
7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/
PacktPublishing/Mastering-Blockchain-Second-Edition In case there's an update to thecode, it will be updated on the existing GitHub repository
We also have other code bundles from our rich catalog of books and videos available
at https://github.com/PacktPublishing/ Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots/diagrams used in thisbook You can download it here: http://www.packtpub.com/sites/default/files/
downloads/MasteringBlockchainSecondEdition_ColorImages.pdf
Conventions used
There are a number of text conventions used throughout this book
CodeInText: Indicates code words in text, database table names, folder names, filenames,file extensions, pathnames, dummy URLs, user input, and Twitter handles Here is anexample: "After executing the command, a file named privatekey.pem is produced, whichcontains the generated private key as follows."
A block of code is set as follows:
Trang 28Trade tStruct = Trade({tradeid:123, quantity:1, price:1,
trader:"equinox"});
}
When we wish to draw your attention to a particular part of a code block, the relevant lines
or items are set in bold:
//This struct can be initialized and used as below
Trade tStruct = Trade({tradeid:123, quantity:1, price:1,
trader:"equinox"});
}
Any command-line input or output is written as follows:
$ sudo apt-get install solc
Bold: Indicates a new term, an important word, or words that you see onscreen For
example, words in menus or dialog boxes appear in the text like this Here is an example:
"Enter the password and click on SEND TRANSACTION to deploy the contract."
Warnings or important notes appear like this
Tips and tricks appear like this
Trang 29Get in touch
Feedback from our readers is always welcome
General feedback: Email feedback@packtpub.com and mention the book title in the
subject of your message If you have questions about any aspect of this book, please email
us at questions@packtpub.com
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes
do happen If you have found a mistake in this book, we would be grateful if you wouldreport this to us Please visit www.packtpub.com/submit-errata, selecting your book,clicking on the Errata Submission Form link, and entering the details
Piracy: If you come across any illegal copies of our works in any form on the Internet, we
would be grateful if you would provide us with the location address or website name.Please contact us at copyright@packtpub.com with a link to the material
If you are interested in becoming an author: If there is a topic that you have expertise in
and you are interested in either writing or contributing to a book, please visit
authors.packtpub.com
Reviews
Please leave a review Once you have read and used this book, why not leave a review onthe site that you purchased it from? Potential readers can then see and use your unbiasedopinion to make purchase decisions, we at Packt can understand what you think about ourproducts, and our authors can see your feedback on their book Thank you!
For more information about Packt, please visit packtpub.com
Trang 301 Blockchain 101
If you are reading this book, it is very likely that you already have heard about blockchainand have some fundamental appreciation of its enormous potential If not, then let me tellyou that this is a technology that has promised to positively alter the existing paradigms ofnearly all industries including, but not limited to IT, finance, government, media, medical,and law
This chapter serves an introduction to blockchain technology, its technical foundations, thetheory behind it, and various techniques that have been combined together to build what isknown today as blockchain
In this chapter, we first describe the theoretical foundations of distributed systems Next,
we address the precursors of Bitcoin by which blockchain technology was introduced to theworld Finally, we introduce you to blockchain technology This approach is a logical way
to understanding blockchain technology, as the roots of blockchain are in distributed
systems We will cover a lot of ground quickly here, but don't worry—we will go over agreat deal of this material in much greater detail as you move through the book
The growth of blockchain technology
With the invention of Bitcoin in 2008, the world was introduced to a new concept, which isnow likely to revolutionize the whole of society It is something that promises to have animpact on every industry, including but not limited to the financial sector, government,media, law, and arts Some describe blockchain as a revolution, whereas another school ofthought believes that it is going to be more evolutionary, and it will take many years beforeany practical benefits of blockchain reach fruition This thinking is correct to some extent,but in my opinion, the revolution has already begun
Trang 31Many prominent organizations all around the world are already writing proofs of conceptusing blockchain technology, as its disruptive potential has now been fully recognized.However, some organizations are still in the preliminary exploration stage, though they areexpected to progress more quickly as the technology matures It is a technology that has animpact on current technologies too and possesses the ability to change them at a
fundamental level
If we look at the last few years, we notice that in 2013 some ideas started to emerge thatsuggested usage of blockchain in other areas than cryptocurrencies Around that time theprimary usage of blockchain was cryptocurrencies, and many new coins emerged duringthat time The following graph shows a broad-spectrum outline of year wise progression
and adaption trend of blockchain technology Years shown on the x axis indicate the range
of time in which a specific phase of blockchain technology falls Each phase has a name
which represents the action and is shown on the x axis starting from the period of IDEAS &
THOUGHTS to eventually MATURITY & FURTHER STANDARDIZATION The y axis
shows level of activity, involvement and adoption of blockchain technology The graph
shows that eventually, roughly around 2025 blockchain technology is expected to become
mature with a high number of users
Blockchain technology adoption and maturity
Trang 32The preceding graph shows that in 2013 IDEAS & THOUGHTS emerged related to other
usages of blockchain technology apart from cryptocurrencies Then in 2014 some
RESEARCH & EXPERIMENTATION started which led to PROOF OF CONCEPTS, FURTHER RESEARCH, and full-scale TRIAL PROJECTS between 2015 and 2017 In 2018
we will see REAL WORLD IMPLEMENTATIONS Already many projects are underway and set to replace existing systems, for example, Australian Securities Exchange (ASX) is
soon to become the first organization to replace its legacy clearing and settlement systemwith blockchain technology
More information on this topic can be found at
https://www.asx.com.au/services/chess-replacement.htm
It is expected that during 2019 more research will be carried out along with some interesttowards regulation and standardization of blockchain technology After this, productionready projects and off the shelf products utilizing blockchain technology will be availablefrom 2020 and by 2021 mainstream usage of blockchain technology is expected to start
Progress in blockchain technology almost feels like the internet dot-com boom of the late
1990s More research is expected to continue along with adaption and further maturity ofblockchain technology, and finally, in 2025 it is expected that the technology will be matureenough to be used on day to day basis Please note that the timelines provided in the chartare not strict and can vary as it is quite difficult to predict that when exactly blockchaintechnology will become mature This graph is based on the progress made in the recentyears and the current climate of research, interest and enthusiasm regarding this technologywhich suggests that by 2025 blockchain technology is expected to become mature
Interest in blockchain technology has risen quite significantly over the last few years Oncedismissed as simply geek money from a cryptocurrency point of view, or as something thatwas just not considered worth pursuing, blockchain is now being researched by the largestcompanies and organizations around the world Millions of dollars are being spent to adaptand experiment with this technology This is evident from recent actions taken by EuropeanUnion where they have announced plans to increase funding for blockchain research toalmost 340 million euros by 2020
Interested readers can read more about this at
https://www.irishtimes.com/business/technology/boost-for-blockch ain-research-as-eu-increases-funding-four-fold-1.3383340
Trang 33More information regarding this can be found at
https://bitcoinmagazine.com/articles/report-suggests-global-spen ding-blockchain-tech-could-reach-92-billion-2021/
There are various consortiums such as Enterprise Ethereum Alliance (EEA), Hyperledger, and R3, which have been established for research and development of blockchain
technology Moreover, a large number of 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 Especially, since early 2017 the increase in
the search term blockchain is quite significant, as shown in the following graph:
Google trend graph for blockchain
Various benefits of this technology are envisioned, such as decentralized trust, cost savings,transparency, and efficiency However, there are multiple challenges too that are an area ofactive research on blockchain, such as scalability and privacy
In this book, we are going to see how blockchain technology can help bring about thebenefits mentioned earlier You are going to learn about what exactly is blockchain
technology, and how it can reshape businesses, multiple industries, and indeed everydaylife by bringing about a plenitude of benefits such as efficiency, cost saving, transparency,and security We will also explore what is distributed ledger technology, decentralization,and smart contracts and how technology solutions can be developed and implementedusing mainstream blockchain platforms such as Ethereum, and Hyperledger We will alsoinvestigate that what challenges need to be addressed before blockchain can become amainstream technology
Chapter 18, Scalability and Other Challenges, is dedicated to a discussion of the limitations
and challenges of blockchain technology
Trang 34Distributed systems
Understanding distributed systems is essential to the understanding of blockchain
technology, as blockchain is a distributed system at its core It is a distributed ledger whichcan be centralized or decentralized A blockchain is originally intended to be and is usuallyused as a decentralized platform It can be thought of as a system that has properties of bothdecentralized and distributed 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 away that end users see it as a single logical platform For example, Google's search engine isbased on a large distributed system, but 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 problem
In 1982, a thought experiment was proposed by Lamport and others in
their research paper, The Byzantine Generals Problem which is available at:
generals-problem/ whereby a group of army generals who lead differentparts of the Byzantine army are planning to attack or retreat from a city.The only way of communicating among them is via a messenger They
https://www.microsoft.com/en-us/research/publication/byzantine-need to agree to strike at the same time in order to win The issue is thatone or more generals might be traitors who could send a misleading
message Therefore, there is a need for a viable mechanism that allows foragreement among the generals, even in the presence of the treacherousones, so that the attack can still take place at the same time As an analogy
to distributed systems, the generals can be considered nodes, the traitors
as Byzantine (malicious) nodes, and the messenger can be thought of as achannel of communication among the generals
This problem was solved in 1999 by Castro and Liskov who presented the
Practical Byzantine Fault Tolerance (PBFT) algorithm, where consensus is
reached after a certain number of messages are received containing thesame signed content
Trang 35This 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 thenetwork, 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 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 partition
in the network
Design of a distributed system: N4 is a Byzantine node, L2 is broken or a slow network link
The primary challenge in distributed system design is coordination between nodes andfault tolerance Even if some of the nodes become faulty or network links break, the
distributed system should be able to tolerate this and continue to work to achieve thedesired result This problem has been an active area of distributed system design researchfor many years, and several algorithms and mechanisms have been proposed to overcomethese issues
Distributed systems are so challenging to design that a hypothesis known as the CAP
theorem has been proven, which states that a distributed system cannot have all three of the
much-desired properties simultaneously; that is, consistency, availability, and partitiontolerance We will dive into the CAP theorem in more detail later in this chapter
Trang 36The history of blockchain and Bitcoin
Blockchain was introduced with the invention of Bitcoin in 2008 Its practical
implementation then occurred in 2009 For the purposes of this chapter, it is sufficient toreview Bitcoin very briefly, as it will be explored in great depth in Chapter 5, Introducing
Bitcoin However, it is essential to refer to Bitcoin because, without it, the history of
blockchain is not complete
Electronic cash
The concept of electronic 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
Just as understanding the concept of distributed systems is necessary to comprehendblockchain technology, the idea of electronic cash is also essential in order to appreciate thefirst and astonishingly successful application of blockchain, Bitcoin, or more broadly
cryptocurrencies in general
Two fundamental e-cash system issues need to be addressed: accountability and
anonymity
Accountability is required to ensure that cash is spendable only once (double-spend
problem) and that it can only be spent by its rightful owner Double spend problem ariseswhen same money can be spent twice As it is quite easy to make copies of digital data, thisbecomes a big issue in digital currencies as you can make many copies of same digital cash
Anonymity is required to protect users' privacy As with physical cash, it is almost
impossible to trace back spending to the individual who actually paid the money
David Chaum solved both of these problems during his work in 1980s by using two
cryptographic operations, namely blind signatures and secret sharing These terminologies
and related concepts will be discussed in detail in Chapter 3, Symmetric Cryptography and
Chapter 4, Public Key Cryptography For the moment, it is sufficient to say that blind
signatures allow for signing a document without actually seeing it, and secret sharing is a
concept that enables the detection of double spending, that is using the same e-cash tokentwice (double spending)
Trang 37In 2009, the first practical implementation of an electronic cash (e-cash) system namedBitcoin appeared The term cryptocurrency emerged later For the very first time, it solved
the problem of distributed consensus in a trustless network It used public key
cryptography with a Proof of Work (PoW) mechanism to provide a secure, controlled, and
decentralized method of minting digital currency The key innovation was the idea of anordered list of blocks composed of transactions and cryptographically secured by the PoWmechanism This concept will be explained in greater detail in Chapter 5, Introducing
Bitcoin.
Other technologies used in Bitcoin, but which existed before its invention, include Merkletrees, hash functions, and hash chains All these concepts are explained in appropriatedepth in Chapter 4, Public Key Cryptography.
Looking at all the technologies mentioned earlier and their relevant history, it is easy to seehow concepts from electronic cash schemes and distributed systems were combined tocreate Bitcoin and what now is known as blockchain This concept can also be visualizedwith the help of the following diagram:
The various ideas that supported the invention of Bitcoin and blockchain
Trang 38In 2008, a groundbreaking paper entitled Bitcoin: A Peer-to-Peer Electronic Cash System was written on the topic of peer-to-peer electronic cash under the pseudonym 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 developercommunity until 2011 He then handed over Bitcoin development to its core developers andsimply 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.
As stated earlier, blockchain technology incorporates a multitude of applications that can beimplemented in various economic sectors Particularly in the finance sector, significantimprovement in the performance of financial transactions and settlements is seen as
resulting in desirable time and cost reductions Additional light will be shed on theseaspects of blockchain in Chapter 17, Blockchain – Outside of Currencies where practical use
cases will be discussed in detail for various industries For now, it is sufficient to say thatparts of nearly all economic sectors have already realized the potential and promise ofblockchain and have embarked, or will do so soon, on the journey to capitalize on thebenefits of blockchain technology
Blockchain defined
Layman's definition: Blockchain is an ever-growing, secure, shared record
keeping system in which each user of the data holds a copy of the records,which can only be updated if all parties involved in a transaction agree toupdate
Technical definition: Blockchain is a peer-to-peer, distributed ledger that
is cryptographically-secure, append-only, immutable (extremely hard tochange), and updateable only via consensus or agreement among peers.Now let's examine the preceding definitions in more detail We will look at all keywords inthe definitions one by one
Peer-to-peer
The first keyword in the technical definition is peer-to-peer This means that there is no
central controller in the network, and all participants talk to each other directly This
Trang 39Distributed ledger
Dissecting the technical definition further reveals that blockchain is a distributed ledger,
which simply means that a ledger is spread across the network among all peers in thenetwork, and each peer holds a copy of the complete ledger
Cryptographically-secure
Next, we see that this ledger is cryptographically-secure, which means that cryptography has
been used to provide security services which make this ledger secure against tampering andmisuse These services include non-repudiation, data integrity, and data origin
authentication You will see how this is achieved later in Chapter 3, Symmetric Cryptography
which introduces the fascinating world of cryptography
scenarios wherein collusion against the blockchain network succeeds in gaining more than
51 percent of the power There may be some legitimate reasons to change data in the
blockchain once it has been added, such as the right to be forgotten or right to erasure (also
defined in General Data Protection (GDPR) ruling, https://gdpr-info.eu/art-17-gdpr/).However, those are individual cases that need to be handled separately and that require anelegant technical solution For all practical purposes, blockchain is indeed immutable andcannot be changed
Updateable via consensus
Finally, the most critical attribute of a blockchain is that it is updateable only via consensus.
This is what gives it the power of decentralization In this scenario, no central authority is incontrol of updating the ledger Instead, any update made to the blockchain is validatedagainst strict criteria defined by the blockchain protocol and added to the blockchain onlyafter a consensus has been reached among all participating peers/nodes on the network Toachieve consensus, there are various consensus facilitation algorithms which ensure that allparties are in agreement about the final state of the data on the blockchain network andresolutely agree upon it to be true Consensus algorithms are discussed later in this chapterand throughout the book as appropriate
Trang 40Blockchain can be thought of as a layer of a distributed peer-to-peer network running ontop of the internet, as can be seen in the following diagram It is analogous to SMTP, HTTP,
or FTP running on top of TCP/IP
The network view of a blockchain
At the bottom layer in the preceding diagram, there is the internet, which provides a basiccommunication layer for any network In this case, a peer-to-peer network runs on top ofthe internet, which hosts another layer of blockchain That layer contains transactions,blocks, consensus mechanisms, state machines, and blockchain smart contracts All of thesecomponents are shown as a single logical entity in a box, representing blockchain above thepeer-to-peer network Finally, at the top, there are users or nodes that connect to the
blockchain and perform various operations such as consensus, transaction verification, andprocessing These concepts will be discussed in detail later in this book