Introduction To Blockchain Technology (River Publishers Series in Rapids in Computing
Introduction To Blockchain Technology (River Publishers Series in Rapids in Computing
www.riverpublishers.com
© 2023 River Publishers. All rights reserved. No part of this publication may be
reproduced, stored in a retrieval systems, or transmitted in any form or by any
means, mechanical, photocopying, recording or otherwise, without prior written
permission of the publishers.
Ahmed Banafa
Professor of Engineering at San Jose State University USA
Instructor of Continuing Studies at Stanford University USA
River Publishers
Contents
Preface vii
1 What is Blockchain? 1
2 Consensus Protocols 13
3.4 Insurance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Contents
3.6 Energy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.8 Crowdfunding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.3 Sharding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
References 39
Index 41
vi
Preface
This is book is for everyone who would like to have a good understanding of
Blockchain Technology and its applications and its relationship with business
operations including: C-Suite executives, IT managers, marketing and sales
people, lawyers, product and project managers, business specialists, students.
It’s not for programmers who are looking for codes or exercises on the different
platforms of Blockchain.
Acknowledgment
I am grateful for all the support I received from my family during the stages of
writing this book.
vii
ix
CHAPTER
What is Blockchain?
What is Blockchain?
quantum computing will make analysis much faster which will, in turn, makes
decision-making in real time possible, which is not always possible with current
computing tools. In cybersecurity, quantum computing will help in the detection
and prevention of cyber-attacks and open the door to new quantum encryption
algorithms which will make it very hard for hackers to access systems and data.
2
What is Blockchain?
one of the 30 people will have a list with pictures of people who are authorized
to be in the room so if somebody came in, and that person was not on the list,
they would start talking to each other, asking “Hey, can you please check if
this person belongs here?” That is synchronization and is referred to as gossip
protocol within Blockchain. Human logic is the list you have, and everybody
3
What is Blockchain?
starting to talk to each other. On top of the current system using encryption
(user name and password), we added human logic, consensus protocols, and
algorithms (Figure 1.3).
1. Cryptography
2. P2P network
3. Consensus mechanism
4. Ledger
5. Validity rules.
4
What is Blockchain?
The first block, called the genesis block, was created by a miner or validator
based on consensus protocols, each block having five elements (index, time
stamp, previous hash, hash, and data). A Blockchain is initialized using the
genesis block which is the foundation of the trading system and the prototype
for the other blocks in the Blockchain. When you change any of these data you
will change the whole block and the following blocks will see that something
has changed, as will the other nodes with copies of the blocks, and the altered
5
What is Blockchain?
node will be rejected. All nodes sync using a gossip protocol – Figure 1.6 shows
this type of mechanism.
There are many differences between Blockchain and traditional databases and
Table 1.1 summarizes them.
Like any other technology, Blockchain can be defined by its stack; Figure 1.7
explains it and it is worth emphasizing the importance of each layer as an
opportunity for improvement and new business (startups), for example, UI/UX
for different devices including smartphones, tablets, desktops, and laptops, in
addition to the wide field of new consensus protocols for specific applications
and industries, the introduction of smart contracts in the design process to avoid
any surprises, and secure ways to connect the stack to the internet.
6
What is Blockchain?
Data Handling Read and Write CRUD (Create, Read, Update, Delete)
7
What is Blockchain?
• Pure R&D track: This track is focused on understanding what it means to develop a
Blockchain-based system. Ideally, working on real use-cases, the ultimate goal is investigation
and learning, and not necessarily delivery of a working system.
• Immediate business benefit track: This track covers two bases: (1) learning how to work
with this promising technology and (2) delivering an actual system that can be deployed in a
real business context. Many of these projects are intra-company.
• Long-term transformational potential track: This is the track of the visionaries who
recognize that to realize the true value of Blockchain-based networks means reinventing entire
processes and industries as well as how public-sector organizations function.
8
What is Blockchain?
Every new technology faces challenge and Blockchain is not an exception. Both
technical and non-technical challenges are listed below (Figure 1.9):
Technical Challenges
• Scalability
• Processing time
• Processing power
• 51% attack
• Double spending
• Bad smart contracts
• Storage
• First mile and last mile problem (data before and after going through the Blockchain).
9
What is Blockchain?
Non-technical Challenges
• Regulations
• Public perception (Blockchain is Bitcoin)
• Lack of skilled staff,
10
What is Blockchain?
11
CHAPTER
Consensus Protocols
This is where consensus protocols come into play. They assure that the
protocol rules are being followed and guarantee that all transactions occur in a
trustless way.
13
Consensus Protocols
The miner must find a result starting with a number of zeroes. The greater
the number of zeroes, the more difficult it is for the miner to find the result and
the more it will have to try his luck before finding it.
Yet the number of zeroes (and therefore the difficulty) is adjusted to the
number of miners on the network (and their computer capacity or hashing
power) to be sure that it will take an average of 10 minutes to find the solution.
Once it has found this figure, the other members of the network can instantly
check the solution.
Since the miner may not find the input data (“input”) from the result
(“output”), they are going to try their luck until they locate the input data
enabling them to obtain the output data corresponding to the objective of
difficulty required, which is the number starting with a number of zeroes
sufficient to be validated by the protocol Bitcoin and thus be added to the
Blockchain.
Figure 2.1 is an example of the mathematical puzzle, the goal is to have three
leading zeroes:
14
Consensus Protocols
Proof of stake will make the entire mining process virtual and replace miners
with validators.
Unlike the proof of work, where the algorithm rewards miners who solve
mathematical problems with the goal of validating transactions and creating
new blocks, with the proof of stake, the creator of a new block is chosen in
a deterministic way, depending on their wealth, also defined as stake. Also
defined as stake with no block rewards.
Also, all digital currencies are created at the beginning, and their number
never changes. This means that in the PoS system there is no block reward, so
the miners take the transaction fees.
DPoS is similar to PoS in regard to staking but has a different and more
democratic system that is said to be fair. Like PoS, token holders stake their
tokens in this consensus protocol.
15
Consensus Protocols
PoA is known to bear many similarities to PoS and DPoS, where only a group of
pre-selected authorities (called validators) secure the Blockchain and are able
to produce new blocks.
As these validators’ identities are at stake, the threat of their identity being
ruined incentivizes them to act in the best interest of the network. Due to the
fact that PoA’s trust system is predetermined, concerns have been raised that
there might be a centralized element with this consensus algorithm.
16
Consensus Protocols
To win, they must attack simultaneously. But they know that there is at least
one traitor among them. So, how do they launch a successful attack with at least
one, unknown, bad actor in their midst?
However, with leased proof of stake, users are able to lease their balance to
full nodes. The higher the amount that is leased, the better the chances are that
the full node will be selected to produce the next block. If the node is selected,
the user will receive some part of the transaction fees that are collected by the
node.
17
Consensus Protocols
the block winners on the network. Based on the basis of a fair lottery system
where every single node is equally likely to be a winner, the PoET mechanism
is based on spreading the chances of winning fairly across the largest possible
number of network users.
The timer is different for every node. Every user in the network is assigned
a random amount of time to wait, and the first user to finish waiting gets to
commit the next block to the blockchain. Compare this to pulling straws, but
this time the shortest stem in the stack wins the lottery.
Proof of activity is a mixed approach that conjoins the other two commonly
used algorithms, proof of work (POW) and proof of stake (POS).
Unlike PoW, proof of burn (PoB) is a consensus mechanism that does not waste
energy. The real computing power is not critical to avoid manipulation. In this
18
Consensus Protocols
case, the nodes destroy or burn their tokens if they want to create the next
blocks and receive a reward.
With PoB, every time a user decides to destroy some of their tokens, they
buy part of the virtual computing power that gives them the ability to validate
the blocks. The more tokens they burn, the higher the possibility of receiving
the reward.
19
CHAPTER
Blockchain use cases fall into two fundamental categories: record keeping,
static registries of data about highly valuable assets, and transactions, dynamic
registries of the exchange of tradeable assets:
21
• Record keeping use cases include the long-term safeguarding of data on valuable physical and
digital assets, keeping track of identity-related information about individuals and executable
smart contracts based on pre-defined conditions.
• Transaction use cases include keeping track of data about frequently exchanged assets, near-
real-time digital payments, and emerging digital assets.
Here are four ways that Blockchain is actually useful in avoiding pilot-to
production failure:
• The first use case is for guaranteed and verified data dissemination.
• The second use case is an asset and product tracking.
• The third use case is asset transfer.
• The fourth use case is certified claims.
22
Key Blockchain Use Cases
item number (based on GS1 standard), a serial number, a batch number, and
expiration date. Using this PoC tracking will be easy, efficient, and fast.
Informed patient consent involves making the patient aware of each step in the
clinical trial process including any possible risks posed by the study. Clinical
trial consent for protocols and their revisions need to be transparent for patients
and traceable for stakeholders.
3.4 Insurance
The average homeowner sells his or her home every five to seven years, and the
average person will move nearly 12 times during his or her lifetime. With such
23
Key Blockchain Use Cases
3.6 Energy
Yet managing this data can be difficult, and to this day some of these records
only exist in paper form, which means sometimes citizens have to physically
go to their local government offices to make changes; this is time-consuming,
unnecessary, and frustrating. Blockchain technology can simplify this record
keeping.
3.8 Crowdfunding
Blockchain technology, among all its benefits, can be best put to use by
providing provable milestones as contingencies for giving, with smart contracts
releasing funds only once milestones establish that the money is being used
the way that it is said to be. By providing greater oversight into individual
campaigns and reducing the amount of trust required to donate in good
conscience, crowdfunding can become an even more legitimate means of
funding a vast spectrum of projects and causes. Figure 3.1 shows how blockchain
is revolutionizing crowdfunding. [4]
24
Key Blockchain Use Cases
25
Key Blockchain Use Cases
4 Smart contracts to enforce funding terms: There are several ways in which blockchain
enabled smart contracts could provide greater accountability in crowdfunding. Primarily, these
contracts would provide built-in milestones that would prevent funds from being released
without provenance as to a project or campaign’s legitimacy. This would prevent large sums
of money from being squandered by those who are either ill-intended or not qualified to be
running a crowdfunding campaign in the first place. [4]
26
CHAPTER
There are many topics related to Blockchain that are equally important as
the technology itself because they solve specific problems and challenges facing
Blockchain, including forks, sharding, ZKP, and
27
the system reaches consensus that this block is not valid, and this “orphan
block” is very soon abandoned by the other miners.
Forks in Blockchain are of two types: soft fork and hard fork.
A soft fork is a software upgrade that is backward compatible with older versions.
This means that participants that did not upgrade to the new software will still
be able to participate in validating and verifying transactions.
Hard forks refer to a software upgrade that is not compatible with older
versions. All participants must upgrade to the new software to continue
participating and validating new transactions. Those who did not upgrade
would be separated from the network and would not be able to validate the
new transactions. This separation results in a permanent divergence of the
Blockchain.
Ethereum had a hard fork to reverse the effects of a hack that occurred in
one of their applications (called the Decentralized Autonomous Organization or
28
Important Topics in Blockchain
It is important to note that since the majority transited to the new chain,
they still retained the original ETH symbol, while the minority supporting the
old chain were given the term Ethereum Classic or ETC.
Bitcoin was forked to create Bitcoin Cash because the developers of Bitcoin
wanted to make some important changes to Bitcoin. The developers of the
Bitcoin community could not come to an agreement concerning some of the
changes that they wanted to make, so a small group of these developers forked
Bitcoin to create a new version of the same code with a few modifications. [7]
The changes that define the difference between Bitcoin Cash and Bitcoin
are these (Table 4.1):
• Bitcoin Cash has cheaper transfer fees, so making transactions in BCH will save you money
against using BTC.
• BCH has faster transfer times, so you do not have to wait the 10 minutes it takes to verify a
Bitcoin transaction!
• BCH can handle more transactions per second. This means that more people can use BCH at
the same time than with BTC.
29
Important Topics in Blockchain
they know the value of x. Zero-knowledge proof is the ability to prove a secret
without revealing what the secret is.
The best way to explain the process of zero-knowledge proofs is with a non
digital example, which is, of course, far from the complexity of zero-knowledge
proofs but very well explains how they work.
Scenario 1
Let us assume there is a blind person who has two balls, one black and one
white. You then would like to prove to the blind person that these balls are
indeed of different colors without revealing the color of each ball. For this, you
ask the blind person to hide both balls under the table and bring one ball back
up for you to see. After that, he should hide the ball back under the table and
then either show the same ball or the other one. As a result, you can prove to
the blind person that the colors are different by saying whether he changed the
balls under the table or not.
Scenario 2
Pretend that there’s a circular cave, with only one entrance or exit and at
the back of this circular cave there’s a door that can be unlocked using a secret
code entered onto a keypad (Figure 4.1). If I want to prove to you that I know
the unlock code without revealing that unlock code to you, all I need to show is
that I can walk into one end of the cave, open the door, and come out the other
end.
30
Important Topics in Blockchain
31
Important Topics in Blockchain
4.3 Sharding
The Ethereum network will be logically divided into multiple shards in the
same way that a country is divided into multiple states in order to have a better
governance system. Transactions created by users or a particular Shard will be
validated by miner’s percentage in that shard alone.
If you think sharding is the holy grail of all the scaling and performance issues,
then you are mistaken. Sharding does come with its share of issues. The biggest
32
Important Topics in Blockchain
flaw with sharding is that inter-shard communication is not very easy. What
this basically means is that, as long as communication occurs with a shard, the
picture remains rosy and nice. But if a user (e.g. Bob) who belongs to shard
1 wants to transact with another user (say John) from shard-2, the transaction
would require some special protocols to complete the transaction.
The developer community is the most affected as they will have to program
their codes to handle this.
Smart contracts are automatically executable lines of code that are stored
on a Blockchain which contain predetermined rules (Figure 4.2) [11]. When
these rules are met, these codes execute themselves and provide the output. In
the simplest form, smart contracts are programs that run according to the format
that they’ve been set up in by their creator. Smart contracts are most beneficial
in business collaborations in which they are used to agree upon the decided
terms set up by the consent of both the parties. This reduces the risk of fraud and
33
Important Topics in Blockchain
as there is no third-party involved and the costs are reduced too. To summarize,
smart contracts usually work on a mechanism that involves digital assets
along with multiple parties where the involved participants can automatically
govern their assets. These assets and be deposited and redistributed among the
participants according to the rules of the contract. Smart contracts have the
potential to track real-time performance and save costs.
Figure 4.2: Example of smart contract code using Solidity (storage contract).
contract SimpleStorage {
unit storedData;
storedData = x;
return storedData;
}
34
CHAPTER
35
API
Database
DApps are similar to a conventional web application. The front end uses
the exact same technology to render the page. The one critical difference is
that instead of an API connecting to a Database, you have a smart contract
connecting to a Blockchain (Figure 5.2).
36
Decentralized Applications – DApps
• Frontend (what you can see) and backend (the logic in the background).
• A smart contract, on the other hand, consists only of the backend, and often only a small part of
the whole DApp.
DApps can have frontend code and user interfaces written in any language
(just like an App) that can make calls to its backend. Furthermore, its frontend
can be hosted on decentralized storage.
This is a Bitcoin or a token native to its system that is necessary for access to
the application and any contribution of value from miners should be rewarded
with the application’s tokens.
37
Decentralized Applications – DApps
Financial Applications
Providing users with more powerful ways of managing and entering into
contracts using their money.
Semi-financial Applications
Where money is involved, but there is also a heavy non-monetary side to what
is being done
Governance Applications
Such as online voting and decentralized governance that are not financial at all.
38
References
[1] https://en.wikipedia.org/wiki/Gossip_protocol
[2] https://medium.com/the-daily-bit/9-types-of-consensus-mecha-nisms-th
at-you-didnt-know-about-49ec365179da
[3] https://www.businessinsider.com/blockchain-technology-applica-tions
use-cases-2017-9
[4] https://www.disruptordaily.com/blockchain-use-cases-crowdfund-ing/
[5] https://due.com/blog/a-new-era-of-crowdfunding-blockchain/
[6] https://en.wikipedia.org/wiki/Bitcoin_Cash
[7] https://www.bitdegree.org/tutorials/bitcoin-cash-vs-bitcoin/
[8] https://btcmanager.com/us-authorities-blockchain-covid-19-critical-ser
vices/?q=/us-authorities-block-chain-covid-19-critical-services/&
[9] https://www.investopedia.com/terms/s/smart-contracts.asp
[10] https://hackernoon.com/everything-you-need-to-know-about-smart-con
tracts-a-beginners-guide-c13cc138378a
39
Index
51% attack 9 D
DAO 29
A DApps 35, 37
API 36
Database 2, 7, 32
Autonomous 28, 37
35,
B Double-spending 14
Backend 36, 37
BCH 29
E
Bitcoin Cash 28, 29, 30
ETH 29
Block 2, 5, 14, 28
Ethereum 28, 31, 38
Blockchain 1, 14, 30
Blockchain Tracks 7
F
BTC 29
First mile 9
(BFT) 17
G
C Go 5
C++ (Bitcoin) 5
Gossip protocol 3, 6
Chain 15, 28
Connectivity 2
H
Consensus Mechanism 4, 18
Hack 28
Consensus Protocols 4, 13
Hard Fork 27, 29
Consortium Blockchain 16
Human Logic 2, 4
Cost 7, 25, 33
Hybrid Blockchain 10
Crypto 18
Cryptocurrency 17, 29
I
Cryptography 2, 4, 29
IBAC 1, 2
Cybersecurity 1, 2
Internet of Things (IoT) 1
41
Index
Java 5
Proof of View (PoV) 22
JavaScript 5, 36
Proof of Work (PoW) 15, 18
Public Blockchain 10
L Python 5
Last mile 9
Ledger 4, 10
Scalability 9, 16, 32
Security 2
N Sharding 27, 32
Networks 6, 10, 35
Smart Contracts 6, 22, 26
Nodes 5, 13, 19
Smartphones 6
Soft Fork 27
O Solidity 5, 34
Open-source 37
Stack of Blockchain 6
P T
P2P Network 4, 35
Token 16, 19, 37
Peer-to-peer communication 6
Transaction 10, 13, 22
Peer-to-peer 31, 35
Privacy 31
U
Private Blockchain 11
UI/UX 6
Processing power 9
Processing time 9
V
42