Mastering Blockchain

Book description

Distributed ledgers, decentralization and smart contracts explained

About This Book

  • Get to grips with the underlying technical principles and implementations of blockchain.
  • Build powerful applications using Ethereum to secure transactions and create smart contracts.
  • Explore cryptography, mine cryptocurrencies, and solve scalability issues with this comprehensive guide.

Who This Book Is For

This book appeals to those who wish to build fast, highly secure, transactional applications. This book is for those who are familiar with the concept of blockchain and are comfortable with a programming language.

What You Will Learn

  • Master the theoretical and technical foundations of blockchain technology
  • Fully comprehend the concept of decentralization, its impact and relationship with blockchain technology
  • Experience how cryptography is used to secure data with practical examples
  • Grasp the inner workings of blockchain and relevant mechanisms behind Bitcoin and alternative cryptocurrencies
  • Understand theoretical foundations of smart contracts
  • Identify and examine applications of blockchain technology outside of currencies
  • Investigate alternate blockchain solutions including Hyperledger, Corda, and many more
  • Explore research topics and future scope of blockchain technology

In Detail

Blockchain is a distributed database that enables permanent, transparent, and secure storage of data. The blockchain technology is the backbone of cryptocurrency – in fact, it's the shared public ledger upon which the entire Bitcoin network relies – and it's gaining popularity with people who work in finance, government, and the arts.

Blockhchain technology uses cryptography to keep data secure. This book gives a detailed description of this leading technology and its implementation in the real world.

This book begins with the technical foundations of blockchain, teaching you the fundamentals of cryptography and how it keeps data secure. You will learn about the mechanisms behind cryptocurrencies and how to develop applications using Ethereum, a decentralized virtual machine. You will explore different blockchain solutions and get an exclusive preview into Hyperledger, an upcoming blockchain solution from IBM and the Linux Foundation. You will also be shown how to implement blockchain beyond currencies, scability with blockchain, and the future scope of this fascinating and powerful technology.

Style and approach

This comprehensive guide allows you to build smart blockchain applications and explore the power of this database. The book will let you quickly brush up on the basics of the blockchain database, followed by advanced implementations of blockchain in currency, smart contracts, decentralization, and so on.

Table of contents

  1. Mastering Blockchain
    1. Mastering Blockchain
    2. Credits
    3. About the Author
    4. About the Reviewer
    5. www.PacktPub.com
      1. Why subscribe?
    6. Customer Feedback
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Blockchain 101
      1. Distributed systems
        1. CAP theorem
        2. Byzantine Generals problem
        3. Consensus
          1. Consensus mechanisms
          2. Types of consensus mechanism
      2. The history of blockchain
        1. Electronic cash
          1. The concept of electronic cash
      3. Introduction to blockchain
        1. Various technical definitions of blockchains
        2. Generic elements of a blockchain
          1. Addresses
          2. Transaction
          3. Block
          4. Peer-to-peer network
          5. Scripting or programming language
          6. Virtual machine
          7. State machine
          8. Nodes
          9. Smart contracts
        3. Features of a blockchain
          1. Distributed consensus
          2. Transaction verification
          3. Platforms for smart contracts
          4. Transferring value between peers
          5. Generating cryptocurrency
          6. Smart property
          7. Provider of security
          8. Immutability
          9. Uniqueness
          10. Smart contracts
        4. Applications of blockchain technology
          1. How blockchains accumulate blocks
        5. Tiers of blockchain technology
          1. Blockchain 1.0
          2. Blockchain 2.0
          3. Blockchain 3.0
          4. Generation X (Blockchain X)
      4. Types of blockchain
        1. Public blockchains
        2. Private blockchains
        3. Semi-private blockchains
        4. Sidechains
        5. Permissioned ledger
        6. Distributed ledger
        7. Shared ledger
        8. Fully private and proprietary blockchains
        9. Tokenized blockchains
        10. Tokenless blockchains
        11. Consensus in blockchain
          1. Proof of Work
          2. Proof of Stake
          3. Delegated Proof of Stake
          4. Proof of Elapsed Time
          5. Deposit-based consensus
          6. Proof of importance
          7. Federated consensus or federated Byzantine consensus
          8. Reputation-based mechanisms
          9. Practical Byzantine Fault Tolerance
      5. CAP theorem and blockchain
      6. Benefits and limitations of blockchain
        1. Decentralization
        2. Transparency and trust
        3. Immutability
        4. High availability
        5. Highly secure
        6. Simplification of current paradigms
        7. Faster dealings
        8. Cost saving
        9. Challenges and limitations of blockchain technology
      7. Summary
    9. 2. Decentralization
      1. Decentralization using blockchain
      2. Methods of decentralization
        1. Disintermediation
        2. Through competition
      3. Routes to decentralization
        1. How to decentralize
          1. Examples
      4. Blockchain and full ecosystem decentralization
        1. Storage
        2. Communication
        3. Computation
      5. Smart contract
      6. Decentralized organizations
      7. Decentralized autonomous organizations
      8. Decentralized autonomous corporations
      9. Decentralized autonomous societies
      10. Decentralized applications
        1. Requirements of a decentralized application
        2. Operations of a DAPP
          1. Examples
            1. KYC-Chain
            2. OpenBazaar
            3. Lazooz
      11. Platforms for decentralization
        1. Ethereum
        2. Maidsafe
        3. Lisk
      12. Summary
    10. 3. Cryptography and Technical Foundations
      1. Introduction
        1. Mathematics
          1. Set
          2. Group
          3. Field
          4. A finite field
          5. Order
          6. Prime fields
          7. Ring
          8. A cyclic group
          9. An abelian group
          10. Modular arithmetic
        2. Cryptography
        3. Confidentiality
        4. Integrity
        5. Authentication
          1. Entity authentication
          2. Data origin authentication
        6. Non-repudiation
        7. Accountability
      2. Cryptographic primitives
        1. Symmetric cryptography
          1. Stream ciphers
          2. Block ciphers
            1. Block encryption mode
            2. Keystream generation modes
            3. Message authentication modes
            4. Cryptographic hashes
            5. Electronic code book
            6. Cipher block chaining
            7. Counter mode
        2. Data Encryption Standard (DES)
        3. Advanced Encryption Standard (AES)
          1. AES steps
            1. An OpenSSL example of how to encrypt and decrypt using AES
      3. Asymmetric cryptography
        1. Integer factorization
        2. Discrete logarithm
        3. Elliptic curves
      4. Public and private keys
        1. RSA
          1. Encryption and decryption using RSA
          2. Elliptic curve cryptography (ECC)
            1. Mathematics behind ECC
            2. Point addition
            3. Point doubling
        2. Discrete logarithm problem
          1. How to generate public and private key pairs
            1. Private key
            2. Generate public key
          2. How to encrypt and decrypt using RSA with OpenSSL
            1. Encryption
            2. Decrypt
          3. ECC using OpenSSL
            1. ECC private and public key pair
            2. Private key
            3. Private key generation
        3. Cryptographic primitives
        4. Hash functions
          1. Compression of arbitrary messages into fixed length digest
          2. Easy to compute
          3. Pre-image resistance
          4. Second pre-image resistance
          5. Collision resistance
          6. Message Digest (MD)
          7. Secure Hash Algorithms (SHAs)
            1. Design of Secure Hash Algorithms (SHA)
            2. SHA-256
            3. Design of SHA3 (Keccak)
            4. OpenSSL example of hash functions
            5. Message Authentication codes (MACs)
            6. MACs using block ciphers
            7. HMACs (hash-based MACs)
          8. Merkle trees
          9. Patricia trees
          10. Distributed hash tables (DHTs)
          11. Digital signatures
            1. Sign then encrypt
            2. Encrypt then sign
        5. Elliptic Curve Digital signature algorithm (ECDSA)
          1. How to generate a digital signature
          2. ECDSA using OpenSSL
          3. Homomorphic encryption
          4. Signcryption
          5. Zero knowledge proofs
          6. Blind signatures
          7. Encoding schemes
      5. Financial markets and trading
        1. Trading
        2. Exchanges
          1. Orders and order properties
          2. Order management and routing systems
          3. Components of a trade
          4. General attributes
          5. Economic
          6. Sales
          7. Counterparty
        3. Trade life cycle
        4. Order anticipators
        5. Market manipulation
      6. Summary
    11. 4. Bitcoin
      1. Bitcoin
        1. Bitcoin definition
          1. Keys and addresses
          2. Public keys in bitcoin
          3. Private keys in bitcoin
          4. Bitcoin currency units
          5. Base58Check encoding
          6. Vanity addresses
      2. Transactions
        1. The transaction life cycle
        2. The transaction structure
          1. The script language
          2. Commonly used Opcodes
        3. Types of transaction
          1. Coinbase transactions
          2. What is UTXO?
            1. Transaction fee
            2. Contracts
            3. Transaction malleability
            4. Transaction pools
            5. Transaction verification
      3. Blockchain
        1. The structure of a block
        2. The structure of a block header
        3. The genesis block
          1. Mining
          2. Task of miners
          3. Synching up with the network
          4. Proof of Work
          5. The mining algorithm
          6. The hashing rate
          7. Mining systems
          8. CPU
          9. GPU
          10. FPGA
          11. ASICs
          12. Mining pools
        4. The bitcoin network
        5. Wallets
          1. Wallet types
            1. Non-deterministic wallets
            2. Deterministic wallets
            3. Hierarchical deterministic wallets
            4. Brain wallets
            5. Paper wallets
            6. Hardware wallets
            7. Online wallets
            8. Mobile wallets
      4. Bitcoin payments
        1. Bitcoin investment and buying and selling bitcoins
        2. Bitcoin installation
          1. Setting up a bitcoin node
          2. Setting up the source code
          3. Setting up bitcoin.conf
          4. Starting up a node in testnet
          5. Starting up a node in regtest
          6. Starting up a node in live mainnet
          7. Experimenting with bitcoin-cli
        3. Bitcoin programming and the command-line interface
        4. Bitcoin improvement proposals (BIPs)
      5. Summary
    12. 5. Alternative Coins
      1. Theoretical foundations
        1. Alternatives to Proof of Work
          1. Proof of Storage
          2. Proof of Stake
            1. Proof of coinage
            2. Proof of deposit
            3. Proof of burn
            4. Proof of activity
          3. Non-outsourceable puzzles
        2. Difficulty adjustment and retargeting algorithms
          1. Kimoto Gravity Well
          2. Dark Gravity Wave
          3. DigiShield
          4. MIDAS
      2. Bitcoin limitations
        1. Privacy and anonymity
          1. Mixing protocols
          2. Third-party mixing protocols
          3. Inherent anonymity
        2. Extended protocols on top of bitcoin
          1. Colored coins
          2. Counterparty
        3. Development of altcoins
          1. Consensus algorithms
          2. Hashing algorithms
          3. Difficulty adjustment algorithms
          4. Inter-block time
          5. Block rewards
          6. Reward halving rate
          7. Block size and transaction size
          8. Interest rate
          9. Coin age
          10. Total supply of coins
      3. Namecoin
        1. Trading Namecoins
        2. Obtaining Namecoins
        3. Generating Namecoin records
      4. Litecoin
      5. Primecoin
        1. Trading Primecoin
        2. Mining guide
      6. Zcash
        1. Trading Zcash
        2. Mining guide
          1. Address generation
          2. GPU mining
            1. Downloading and compiling nheqminer
      7. Summary
    13. 6. Smart Contracts
      1. History
      2. Definition
      3. Ricardian contracts
        1. Smart contract templates
        2. Oracles
        3. Smart Oracles
        4. Deploying smart contracts on a blockchain
        5. The DAO
      4. Summary
    14. 7. Ethereum 101
      1. Introduction
        1. Ethereum clients and releases
        2. The Ethereum stack
      2. Ethereum blockchain
        1. Currency (ETH and ETC)
        2. Forks
        3. Gas
        4. The consensus mechanism
        5. The world state
          1. The account state
            1. Nonce
            2. Balance
            3. Storageroot
            4. Codehash
        6. Transactions
          1. Nonce
          2. gasPrice
          3. gasLimit
          4. To
          5. Value
          6. Signature
          7. Init
          8. Data
        7. Contract creation transaction
        8. Message call transaction
      3. Elements of the Ethereum blockchain
        1. Ethereum virtual machine (EVM)
          1. Execution environment
            1. Machine state
            2. The iterator function
            3. Runtime byte code
          2. Opcodes and their meaning
            1. Arithmetic operations
            2. Logical operations
            3. Cryptographic operations
            4. Environmental information
            5. Block Information
            6. Stack, memory, storage and flow operations
            7. Push operations
            8. Duplication operations
            9. Exchange operations
            10. Logging operations
            11. System operations
      4. Precompiled contracts
        1. The elliptic curve public key recovery function
        2. The SHA-256 bit hash function
        3. The RIPEMD-160 bit hash function
        4. The identity function
      5. Accounts
        1. Types of accounts
      6. Block
        1. Block header
          1. Parent hash
          2. Ommers hash
          3. Beneficiary
          4. State root
          5. Transactions root
          6. Receipts root
          7. Logs bloom
          8. Difficulty
          9. Number
          10. Gas limit
          11. Gas used
          12. Timestamp
          13. Extra data
          14. Mixhash
          15. Nonce
        2. The genesis block
        3. Transaction receipts
          1. The post-transaction state
          2. Gas used
          3. Set of logs
          4. The bloom filter
        4. Transaction validation and execution
          1. The transaction sub state
            1. Suicide set
            2. Log series
            3. Refund balance
        5. The block validation mechanism
          1. Block finalization
            1. Ommers validation
            2. Transaction validation
            3. Reward application
            4. State and nonce validation
          2. Block difficulty
      7. Ether
        1. Gas
        2. Fee schedule
      8. Messages
        1. Calls
      9. Mining
        1. Ethash
        2. CPU mining
        3. GPU mining
          1. CPU benchmarking
          2. GPU benchmarking
        4. Mining rigs
          1. Motherboard
          2. SSD hard drive
          3. GPU
        5. Mining pools
      10. Clients and wallets
        1. Geth
        2. Eth
        3. Pyethapp
        4. Parity
        5. Light clients
        6. Installation
          1. Eth installation
          2. Mist browser
          3. Geth
          4. The geth console
          5. Funding the account with bitcoin
        7. Parity installation
          1. Creating accounts using the parity command line
      11. Trading and investment
      12. The yellow paper
        1. Useful symbols
      13. The Ethereum network
        1. MainNet
        2. TestNet
        3. Private net(s)
        4. Supporting protocols
          1. Whisper
          2. Swarm
      14. Applications developed on Ethereum
      15. Scalability and security issues
      16. Summary
    15. 8. Ethereum Development
      1. Setting up a development environment
        1. Test Net (Ropsten)
        2. Setting up a Private Net
          1. Network ID
          2. The genesis file
          3. Data directory
            1. Flags and their meaning
          4. Static nodes
        3. Starting up the private network
          1. Running Mist on Private Net
          2. Deploying contracts using Mist
      2. Development tools and clients
        1. Languages
        2. Compilers
          1. Solc
          2. Integrated Development Environments (IDEs)
            1. Browser solidity
            2. Remix
            3. Installation
          3. Tools and libraries
            1. Node.js version 7
            2. Local Ethereum block explorer
          4. EthereumJS
        3. Contract development and deployment
      3. Introducing solidity
        1. Types
          1. Value types
            1. Boolean
            2. Integers
            3. Address
            4. Array value types (fixed size and dynamically sized byte arrays)
          2. Literals
            1. Integer literals
            2. String literals
            3. Hexadecimal literals
          3. Enums
          4. Function types
            1. Internal functions
            2. External functions
          5. Reference types
            1. Arrays
            2. Structs
            3. Data location
          6. Mappings
          7. Global variables
          8. Control structures
            1. Events
            2. Inheritance
            3. Libraries
            4. Functions
            5. Layout of a solidity source code file
      4. Introducing Web3
        1. POST requests
        2. The HTML and JavaScript frontend
          1. Installing web3.js
            1. Example
        3. Development frameworks
          1. Truffle
            1. Installation
            2. Testing using truffle
            3. Build
            4. Another example
            5. Example project: Proof of Idea
            6. Permissioned distributed ledgers
      5. Summary
    16. 9. Hyperledger
      1. Projects
        1. Fabric
        2. Sawtooth lake
        3. Iroha
        4. Blockchain explorer
        5. Fabric chaintool
        6. Fabric SDK Py
        7. Corda
      2. Hyperledger as a protocol
        1. Reference architecture
        2. Requirements
          1. Modular approach
          2. Privacy and confidentiality
          3. Identity
          4. Auditability
          5. Interoperability
          6. Portability
      3. Fabric
      4. Hyperledger Fabric
        1. Fabric architecture
          1. Membership services
          2. Blockchain services
            1. Consensus manager
            2. Distributed ledger
            3. Peer to Peer protocol
            4. Ledger storage
          3. Chaincode services
          4. Events
          5. APIs and CLIs
        2. Components of the Fabric
          1. Peers or nodes
          2. Applications on blockchain
            1. Chaincode implementation
            2. Application model
      5. Sawtooth lake
        1. PoET
        2. Transaction families
        3. Consensus in Sawtooth
        4. Development environment
      6. Corda
        1. Architecture
          1. State objects
          2. Transactions
          3. Consensus
          4. Flows
        2. Components
          1. Nodes
          2. Permissioning service
            1. Network map service
            2. Notary service
            3. Oracle service
            4. Transactions
            5. Vaults
            6. CorDapp
        3. Development environment
      7. Summary
    17. 10. Alternative Blockchains
      1. Blockchains
        1. Kadena
          1. Ripple
          2. Transactions
            1. Payments related
            2. Order related
            3. Account and security related
            4. Application layer
            5. Transport layer
            6. Interledger layer
            7. Ledger layer
          3. Stellar
          4. Rootstock
            1. Drivechain
          5. Quorum
            1. Transaction manager
            2. Crypto Enclave
            3. QuorumChain
            4. Network manager
          6. Tezos
          7. Storj
          8. Maidsafe
          9. BigChainDB
          10. Multichain
          11. Tendermint
            1. Tendermint Core
            2. Tendermint Socket Protocol (TMSP)
      2. Platforms
        1. BlockApps
          1. Installation
          2. Application development and deployment using BlockApps
        2. Eris
      3. Summary
    18. 11. Blockchain-Outside of Currencies
      1. Internet of Things
        1. Physical object layer
        2. Device layer
        3. Network layer
        4. Management layer
        5. Application layer
        6. IoT blockchain experiment
          1. First node setup
          2. Raspberry Pi node setup
          3. Circuit
      2. Government
        1. Border control
        2. Voting
        3. Citizen identification (ID cards)
        4. Miscellaneous
      3. Health
      4. Finance
        1. Insurance
        2. Post trade settlement
        3. Financial crime prevention
      5. Media
      6. Summary
    19. 12. Scalability and Other Challenges
      1. Scalability
        1. Block size increase
        2. Block interval reduction
        3. Invertible Bloom lookup tables
        4. Sharding
        5. State channels
        6. Private blockchain
        7. Proof of Stake
          1. Sidechains
          2. Subchains
          3. Tree chains
      2. Privacy
        1. Indistinguishability obfuscation
        2. Homomorphic encryption
        3. Zero knowledge proofs
        4. State channels
        5. Secure multiparty computation
        6. Usage of hardware to provide confidentiality
        7. Coinjoin
        8. Confidential transactions
        9. MimbleWimble
      3. Security
        1. Smart contract security
          1. Why3 formal verification
          2. Oyente tool
      4. Summary
    20. 13. Current Landscape and Whats Next
      1. Emerging trends
        1. Application-specific blockchains (ASBCs)
        2. Enterprise-grade blockchains
        3. Private blockchains
        4. Start-ups
        5. Strong research interest
        6. Standardization
        7. Enhancements
        8. Real-world implementations
        9. Consortia
        10. Answers to challenges
        11. Convergence
        12. Education of blockchain technology
        13. Employment
        14. Crypto-economics
        15. Research in cryptography
        16. New programming languages
        17. Hardware research and development
        18. Research in formal methods and security
        19. Alternatives to blockchains
        20. Interoperability efforts
        21. Blockchain as a service
        22. Efforts to reduce electricity consumption
      2. Improvement proposals
        1. BIPs
          1. BIP 152
          2. BIP 151
          3. BIP 150
          4. BIP 147
          5. BIP 146
        2. EIPs
          1. EIP 170
          2. EIP 150
          3. EIP 161
          4. EIP 160
          5. EIP 155
      3. Other challenges
      4. Dark side
      5. Blockchain research
        1. Smart contracts
        2. Centralization issues
        3. Limitations in cryptographic functions
        4. Consensus Algorithms
        5. Scalability
        6. Code Obfuscation
      6. List of notable projects
        1. Zcash on Ethereum
        2. CollCo
        3. Cello
        4. Qtum
        5. Bitcoin-NG
        6. Solidus
        7. Hawk
        8. Town-Crier
        9. SETLCoin
        10. TEEChan
        11. Falcon
        12. Bletchley
        13. Casper
        14. Metropolis
      7. Miscellaneous Tools
        1. Solidity extension for Microsoft Visual studio
        2. MetaMask
        3. Stratis
        4. Embark
        5. DAPPLE
        6. Meteor
        7. uPort
        8. INFURA
      8. Convergence with other industries
      9. Future
      10. Summary

Product information

  • Title: Mastering Blockchain
  • Author(s): Imran Bashir
  • Release date: March 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781787125445