Master the theoretical and technical foundations of Blockchain technology and explore future of Blockchain technology
by Imran Bashir
Book Details
Price
|
3.00 USD |
---|---|
Pages
| 879 p |
File Size
|
11,952 KB |
File Type
|
PDF format |
ISBN
| 978-1-78712-544-5 |
Copyright
| 2017 Packt Publishing |
Imran Bashir has a 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 Institute of
Electrical and Electronics Engineers (IEEE) and
British Computer Society (BCS). Imran has sixteen
years of experience in the public and financial sectors.
He worked on large scale IT projects for public sector
before moving to financial services industry. Since then
he has worked in various technical roles for different
financial companies in Europe’s financial capital,
London. He is currently working for an investment bank
in London as Vice President in the technology department.
I would like to thank the talented team at Packt including
Ajith Menon, Nilesh Sawakhande, Sumeet Sawant, and
Tushar Gupta, who provided prompt guidance and very
valuable feedback throughout this project. I am also
extremely thankful to the reviewer, Daniel Kraft, who
provided constructive and very useful feedback
that helped tremendously to improve the material in this book.
I thank my wife and children for putting up with my allnight
and weekend-long writing sessions.
Finally, I would like to thank my parents, whose
blessings on me have made everything possible for me.
About the Reviewer
Daniel Kraft studied mathematics and physics, and
holds a PhD in applied mathematics from the University
of Graz in Austria. He has been involved in development
with cryptocurrencies since 2013, has been the lead
developer and chief scientist for both Namecoin and
Huntercoin since 2014, and has published two research
papers about cryptocurrency in peer-reviewed journals.
He works as a software engineer and is a co-founder of
Crypto Realities Ltd, a start-up that works on building
decentralised multi-player game worlds with blockchain
technology.
Preface
This book has one goal: to provide a comprehensive
introduction to the theoretical and practical aspects of
blockchain technology. This book contains all
the material that is required to fully understand
blockchain technology. After reading this book, readers
will be able to develop a deep understanding of inner
workings of blockchain technology and will be able to
develop blockchain applications. This book covers all
topics relevant to blockchain technology, including
cryptography, cryptocurrenices, Bitcoin, Ethereum, and
various other platforms and tools used for blockchain development.
It is recommended that readers have a basic
understanding of computer science and basic
programming experience in order 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.
Table of Contents
Mastering Blockchain
Credits
About the Author
About the Reviewer
www.PacktPub.com
Why subscribe?
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Blockchain 101
Distributed systems
CAP theorem
Byzantine Generals problem
Consensus
Consensus mechanisms
Types of consensus mechanism
The history of blockchain
Electronic cash
The concept of electronic cash
Introduction to blockchain
Various technical definitions of blockchains
Generic elements of a blockchain
Addresses
Transaction
Block
Peer-to-peer network
Scripting or programming language
Virtual machine
State machine
Nodes
Smart contracts
Features of a blockchain
Distributed consensus
Transaction verification
Platforms for smart contracts
Transferring value between peers
Generating cryptocurrency
Smart property
Provider of security
Immutability
Uniqueness
Smart contracts
Applications of blockchain technology
How blockchains accumulate blocks
Tiers of blockchain technology
Blockchain 1.0
Blockchain 2.0
Blockchain 3.0
Generation X (Blockchain X)
Types of blockchain
Public blockchains
Private blockchains
Semi-private blockchains
Sidechains
Permissioned ledger
Distributed ledger
Shared ledger
Fully private and proprietary blockchains
Tokenized blockchains
Tokenless blockchains
Consensus in blockchain
Proof of Work
Proof of Stake
Delegated Proof of Stake
Proof of Elapsed Time
Deposit-based consensus
Proof of importance
Federated consensus or federated Byzantine consensus
Reputation-based mechanisms
Practical Byzantine Fault Tolerance
CAP theorem and blockchain
Benefits and limitations of blockchain
Decentralization
Transparency and trust
Immutability
High availability
Highly secure
Simplification of current paradigms
Faster dealings
Cost saving
Challenges and limitations of blockchain technology
Summary
2. Decentralization
Decentralization using blockchain
Methods of decentralization
Disintermediation
Through competition
Routes to decentralization
How to decentralize
Examples
Blockchain and full ecosystem decentralization
Storage
Communication
Computation
Smart contract
Decentralized organizations
Decentralized autonomous organizations
Decentralized autonomous corporations
Decentralized autonomous societies
Decentralized applications
Requirements of a decentralized application
Operations of a DAPP
Examples
KYC-Chain
OpenBazaar
Lazooz
Platforms for decentralization
Ethereum
Maidsafe
Lisk
Summary
3. Cryptography and Technical Foundations
Introduction
Mathematics
Set
Group
Field
A finite field
Order
Prime fields
Ring
A cyclic group
An abelian group
Modular arithmetic
Cryptography
Confidentiality
Integrity
Authentication
Entity authentication
Data origin authentication
Non-repudiation
Accountability
Cryptographic primitives
Symmetric cryptography
Stream ciphers
Block ciphers
Block encryption mode
Keystream generation modes
Message authentication modes
Cryptographic hashes
Electronic code book
Cipher block chaining
Counter mode
Data Encryption Standard (DES)
Advanced Encryption Standard (AES)
AES steps
An OpenSSL example of how to encrypt and decrypt using
AES
Asymmetric cryptography
Integer factorization
Discrete logarithm
Elliptic curves
Public and private keys
RSA
Encryption and decryption using RSA
Elliptic curve cryptography (ECC)
Mathematics behind ECC
Point addition
Point doubling
Discrete logarithm problem
How to generate public and private key pairs
Private key
Generate public key
How to encrypt and decrypt using RSA with OpenSSL
Encryption
Decrypt
ECC using OpenSSL
ECC private and public key pair
Private key
Private key generation
Cryptographic primitives
Hash functions
Compression of arbitrary messages into fixed length digest
Easy to compute
Pre-image resistance
Second pre-image resistance
Collision resistance
Message Digest (MD)
Secure Hash Algorithms (SHAs)
Design of Secure Hash Algorithms (SHA)
SHA-256
Design of SHA3 (Keccak)
OpenSSL example of hash functions
Message Authentication codes (MACs)
MACs using block ciphers
HMACs (hash-based MACs)
Merkle trees
Patricia trees
Distributed hash tables (DHTs)
Digital signatures
Sign then encrypt
Encrypt then sign
Elliptic Curve Digital signature algorithm (ECDSA)
How to generate a digital signature
ECDSA using OpenSSL
Homomorphic encryption
Signcryption
Zero knowledge proofs
Blind signatures
Encoding schemes
Financial markets and trading
Trading
Exchanges
Orders and order properties
Order management and routing systems
Components of a trade
General attributes
Economic
Sales
Counterparty
Trade life cycle
Order anticipators
Market manipulation
Summary
4. Bitcoin
Bitcoin
Bitcoin definition
Keys and addresses
Public keys in bitcoin
Private keys in bitcoin
Bitcoin currency units
Base58Check encoding
Vanity addresses
Transactions
The transaction life cycle
The transaction structure
The script language
Commonly used Opcodes
Types of transaction
Coinbase transactions
What is UTXO?
Transaction fee
Contracts
Transaction malleability
Transaction pools
Transaction verification
Blockchain
The structure of a block
The structure of a block header
The genesis block
Mining
Task of miners
Synching up with the network
Proof of Work
The mining algorithm
The hashing rate
Mining systems
CPU
GPU
FPGA
ASICs
Mining pools
The bitcoin network
Wallets
Wallet types
Non-deterministic wallets
Deterministic wallets
Hierarchical deterministic wallets
Brain wallets
Paper wallets
Hardware wallets
Online wallets
Mobile wallets
Bitcoin payments
Bitcoin investment and buying and selling bitcoins
Bitcoin installation
Setting up a bitcoin node
Setting up the source code
Setting up bitcoin.conf
Starting up a node in testnet
Starting up a node in regtest
Starting up a node in live mainnet
Experimenting with bitcoin-cli
Bitcoin programming and the command-line interface
Bitcoin improvement proposals (BIPs)
Summary
5. Alternative Coins
Theoretical foundations
Alternatives to Proof of Work
Proof of Storage
Proof of Stake
Proof of coinage
Proof of deposit
Proof of burn
Proof of activity
Non-outsourceable puzzles
Difficulty adjustment and retargeting algorithms
Kimoto Gravity Well
Dark Gravity Wave
DigiShield
MIDAS
Bitcoin limitations
Privacy and anonymity
Mixing protocols
Third-party mixing protocols
Inherent anonymity
Extended protocols on top of bitcoin
Colored coins
Counterparty
Development of altcoins
Consensus algorithms
Hashing algorithms
Difficulty adjustment algorithms
Inter-block time
Block rewards
Reward halving rate
Block size and transaction size
Interest rate
Coin age
Total supply of coins
Namecoin
Trading Namecoins
Obtaining Namecoins
Generating Namecoin records
Litecoin
Primecoin
Trading Primecoin
Mining guide
Zcash
Trading Zcash
Mining guide
Address generation
GPU mining
Downloading and compiling nheqminer
Summary
6. Smart Contracts
History
Definition
Ricardian contracts
Smart contract templates
Oracles
Smart Oracles
Deploying smart contracts on a blockchain
The DAO
Summary
7. Ethereum 101
Introduction
Ethereum clients and releases
The Ethereum stack
Ethereum blockchain
Currency (ETH and ETC)
Forks
Gas
The consensus mechanism
The world state
The account state
Nonce
Balance
Storageroot
Codehash
Transactions
Nonce
gasPrice
gasLimit
To
Value
Signature
Init
Data
Contract creation transaction
Message call transaction
Elements of the Ethereum blockchain
Ethereum virtual machine (EVM)
Execution environment
Machine state
The iterator function
Runtime byte code
Opcodes and their meaning
Arithmetic operations
Logical operations
Cryptographic operations
Environmental information
Block Information
Stack, memory, storage and flow operations
Push operations
Duplication operations
Exchange operations
Logging operations
System operations
Precompiled contracts
The elliptic curve public key recovery function
The SHA-256 bit hash function
The RIPEMD-160 bit hash function
The identity function
Accounts
Types of accounts
Block
Block header
Parent hash
Ommers hash
Beneficiary
State root
Transactions root
Receipts root
Logs bloom
Difficulty
Number
Gas limit
Gas used
Timestamp
Extra data
Mixhash
Nonce
The genesis block
Transaction receipts
The post-transaction state
Gas used
Set of logs
The bloom filter
Transaction validation and execution
The transaction sub state
Suicide set
Log series
Refund balance
The block validation mechanism
Block finalization
Ommers validation
Transaction validation
Reward application
State and nonce validation
Block difficulty
Ether
Gas
Fee schedule
Messages
Calls
Mining
Ethash
CPU mining
GPU mining
CPU benchmarking
GPU benchmarking
Mining rigs
Motherboard
SSD hard drive
GPU
Mining pools
Clients and wallets
Geth
Eth
Pyethapp
Parity
Light clients
Installation
Eth installation
Mist browser
Geth
The geth console
Funding the account with bitcoin
Parity installation
Creating accounts using the parity command line
Trading and investment
The yellow paper
Useful symbols
The Ethereum network
MainNet
TestNet
Private net(s)
Supporting protocols
Whisper
Swarm
Applications developed on Ethereum
Scalability and security issues
Summary
8. Ethereum Development
Setting up a development environment
Test Net (Ropsten)
Setting up a Private Net
Network ID
The genesis file
Data directory
Flags and their meaning
Static nodes
Starting up the private network
Running Mist on Private Net
Deploying contracts using Mist
Development tools and clients
Languages
Compilers
Solc
Integrated Development Environments (IDEs)
Browser solidity
Remix
Installation
Tools and libraries
Node.js version 7
Local Ethereum block explorer
EthereumJS
Contract development and deployment
Introducing solidity
Types
Value types
Boolean
Integers
Address
Array value types (fixed size and dynamically sized byte arrays)
Literals
Integer literals
String literals
Hexadecimal literals
Enums
Function types
Internal functions
External functions
Reference types
Arrays
Structs
Data location
Mappings
Global variables
Control structures
Events
Inheritance
Libraries
Functions
Layout of a solidity source code file
Introducing Web3
POST requests
The HTML and JavaScript frontend
Installing web3.js
Example
Development frameworks
Truffle
Installation
Testing using truffle
Build
Another example
Example project: Proof of Idea
Permissioned distributed ledgers
Summary
9. Hyperledger
Projects
Fabric
Sawtooth lake
Iroha
Blockchain explorer
Fabric chaintool
Fabric SDK Py
Corda
Hyperledger as a protocol
Reference architecture
Requirements
Modular approach
Privacy and confidentiality
Identity
Auditability
Interoperability
Portability
Fabric
Hyperledger Fabric
Fabric architecture
Membership services
Blockchain services
Consensus manager
Distributed ledger
Peer to Peer protocol
Ledger storage
Chaincode services
Events
APIs and CLIs
Components of the Fabric
Peers or nodes
Applications on blockchain
Chaincode implementation
Application model
Sawtooth lake
PoET
Transaction families
Consensus in Sawtooth
Development environment
Corda
Architecture
State objects
Transactions
Consensus
Flows
Components
Nodes
Permissioning service
Network map service
Notary service
Oracle service
Transactions
Vaults
CorDapp
Development environment
Summary
10. Alternative Blockchains
Blockchains
Kadena
Ripple
Transactions
Payments related
Order related
Account and security related
Application layer
Transport layer
Interledger layer
Ledger layer
Stellar
Rootstock
Drivechain
Quorum
Transaction manager
Crypto Enclave
QuorumChain
Network manager
Tezos
Storj
Maidsafe
BigChainDB
Multichain
Tendermint
Tendermint Core
Tendermint Socket Protocol (TMSP)
Platforms
BlockApps
Installation
Application development and deployment using BlockApps
Eris
Summary
11. Blockchain-Outside of Currencies
Internet of Things
Physical object layer
Device layer
Network layer
Management layer
Application layer
IoT blockchain experiment
First node setup
Raspberry Pi node setup
Circuit
Government
Border control
Voting
Citizen identification (ID cards)
Miscellaneous
Health
Finance
Insurance
Post trade settlement
Financial crime prevention
Media
Summary
12. Scalability and Other Challenges
Scalability
Block size increase
Block interval reduction
Invertible Bloom lookup tables
Sharding
State channels
Private blockchain
Proof of Stake
Sidechains
Subchains
Tree chains
Privacy
Indistinguishability obfuscation
Homomorphic encryption
Zero knowledge proofs
State channels
Secure multiparty computation
Usage of hardware to provide confidentiality
Coinjoin
Confidential transactions
MimbleWimble
Security
Smart contract security
Why3 formal verification
Oyente tool
Summary
13. Current Landscape and Whats Next
Emerging trends
Application-specific blockchains (ASBCs)
Enterprise-grade blockchains
Private blockchains
Start-ups
Strong research interest
Standardization
Enhancements
Real-world implementations
Consortia
Answers to challenges
Convergence
Education of blockchain technology
Employment
Crypto-economics
Research in cryptography
New programming languages
Hardware research and development
Research in formal methods and security
Alternatives to blockchains
Interoperability efforts
Blockchain as a service
Efforts to reduce electricity consumption
Improvement proposals
BIPs
BIP 152
BIP 151
BIP 150
BIP 147
BIP 146
EIPs
EIP 170
EIP 150
EIP 161
EIP 160
EIP 155
Other challenges
Dark side
Blockchain research
Smart contracts
Centralization issues
Limitations in cryptographic functions
Consensus Algorithms
Scalability
Code Obfuscation
List of notable projects
Zcash on Ethereum
CollCo
Cello
Qtum
Bitcoin-NG
Solidus
Hawk
Town-Crier
SETLCoin
TEEChan
Falcon
Bletchley
Casper
Metropolis
Miscellaneous Tools
Solidity extension for Microsoft Visual studio
MetaMask
Stratis
Embark
DAPPLE
Meteor
uPort
INFURA
Convergence with other industries
Future
Summary
What 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, and benefits of blockchains along with
consensus mechanisms that are at the core of
blockchain technology.
Chapter 2, Decentralization, covers the concepts of
decentralization and its relationship with blockchain
technology. Various methods and platforms that can be
used to decentralize a process or system have also been introduced.
Chapter 3, Cryptography and Technical Foundations,
introduces the theoretical foundations cryptography,
which is necessary to fully understand blockchain
technology. Concepts such as public and private key
cryptography, with practical examples, are included.
Finally, an introduction to financial markets is also
included as there are many interesting use cases for
blockchain technology in the financial sector.
Chapter 4, Bitcoin, covers Bitcoin, the first and largest
blockchain. It introduces technical concepts related to
bitcoin cryptocurrency in detail.
Chapter 5, 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 6, Smart Contracts, provides an
in-depth discussion on smart contracts. Topics such as
history, the definition of smart contracts, Ricardian
contracts, Oracles, and the theoretical aspects of smart
contracts are presented in this chapter.
Chapter 7, Ethereum 101, introduces the design and
architecture of the Ethereum blockchain in detail. It
covers various technical concepts related to the
Ethereum blockchain that explains the underlying
principles, features, and components of this platform in depth.
Chapter 8, Ethereum Development, provides a detailed
practical introduction to development of decentralized
applications and smart contracts using the Ethereum
blockchain. An introduction to solidity and different
relevant tools have also been included in this chapter.
Chapter 9, Hyperledger, presents a discussion about the
hyperledger project from the Linux foundation, which
includes different blockchain projects introduced by its members.
Chapter 10, Alternative Blockchains, introduces
alternative blockchain solutions and platforms. It
provides technical details and features of alternative blockchains.
Chapter 11, Blockchain – Outside of Currencies,
provides a practical and detailed introduction to
applications of blockchain technology in fields others
than cryptocurrencies, including Internet of Things,
government, media, and finance.
Chapter 12, Scalability and Other Challenges, is
dedicated to a discussion of the challenges faced by
blockchain technology and how to address them.
Chapter 13, 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.
What you need for this book
All examples in this book have been developed on
Ubuntu 16.04.1 LTS (Xenial). As such, it is
recommended to use Ubuntu. However, any appropriate
operating system, either Windows or Linux, can be used,
but examples, especially those related to installation,
may need to be changed accordingly.
Examples related to cryptography have been developed
using the OpenSSL 1.0.2g 1 Mar 2016 command-line tool.
Ethereum solidity examples have been developed using
Browser Solidity, available online
Ethereum's homestead release is used to develop
Ethereum-related examples. At the time of writing, this is
the latest version available and can be downloaded from
Examples related to IoT have been developed using a
Raspberry Pi kit by Vilros, but any latest model or kit can
be used. Specifically, Raspberry Pi 3 Model B V 1.2 has
been used to build a hardware example of IoT. Node.js
V7.2.1 and npm V3.10.10 have been used to download
related packages and run Node.js server for IoT examples.
The Truffle framework has been used in some examples
of smart contract deployment, and is available at
http://truffleframework.com/. Any latest version available
via npm should be appropriate.
Who this book is for
This book is for anyone who wants to understand
blockchain technology in depth. It can also be used as a
reference by developers who are developing applications
for blockchain. In addition, this book can also 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 and certifications
related to cryptocurrency and blockchain technology.