Mastering Bitcoin, 3rd Edition

Book description

Join the technological revolution that's taking the financial world by storm. Mastering Bitcoin is your guide through the seemingly complex world of Bitcoin, providing the knowledge you need to participate in the internet of money. Whether you're building the next killer app, investing in a startup, or simply curious about the technology, this revised and expanded third edition provides essential detail to get you started.

Bitcoin, the first successful decentralized digital currency, has already spawned a multibillion-dollar global economy open to anyone with the knowledge and passion to participate. Mastering Bitcoin provides the knowledge. You supply the passion.

The third edition includes:

  • A broad introduction to Bitcoin and its underlying blockchain—ideal for nontechnical users, investors, and business executives
  • An explanation of Bitcoin's technical foundation and cryptographic currency for developers, engineers, and software and systems architects
  • Details of the Bitcoin decentralized network, peer-to-peer architecture, transaction lifecycle, and security principles
  • New developments such as Taproot, Tapscript, Schnorr signatures, and the Lightning Network
  • A deep dive into Bitcoin applications, including how to combine the building blocks offered by this platform into powerful new tools
  • User stories, analogies, examples, and code snippets illustrating key technical concepts

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Writing the Bitcoin Book
    2. Intended Audience
    3. Why Are There Bugs on the Cover?
    4. Conventions Used in This Book
    5. Code Examples
    6. Using Code Examples
    7. Changes Since the Previous Edition
    8. Bitcoin Addresses and Transactions in This Book
    9. O’Reilly Online Learning
    10. How to Contact Us
    11. Contacting the Authors
    12. Acknowledgments for the First and Second Editions
    13. Acknowledgments for the Third Edition
    14. Early Release Draft (GitHub Contributions)
  2. 1. Introduction
    1. History of Bitcoin
    2. Getting Started
      1. Choosing a Bitcoin Wallet
      2. Quick Start
      3. Recovery Codes
      4. Bitcoin Addresses
      5. Receiving Bitcoin
      6. Getting Your First Bitcoin
      7. Finding the Current Price of Bitcoin
      8. Sending and Receiving Bitcoin
  3. 2. How Bitcoin Works
    1. Bitcoin Overview
    2. Buying from an Online Store
    3. Bitcoin Transactions
      1. Transaction Inputs and Outputs
      2. Transaction Chains
      3. Making Change
      4. Coin Selection
      5. Common Transaction Forms
    4. Constructing a Transaction
      1. Getting the Right Inputs
      2. Creating the Outputs
      3. Adding the Transaction to the Blockchain
    5. Bitcoin Mining
    6. Spending the Transaction
  4. 3. Bitcoin Core: The Reference Implementation
    1. From Bitcoin to Bitcoin Core
    2. Bitcoin Development Environment
    3. Compiling Bitcoin Core from the Source Code
      1. Selecting a Bitcoin Core Release
      2. Configuring the Bitcoin Core Build
      3. Building the Bitcoin Core Executables
    4. Running a Bitcoin Core Node
    5. Configuring the Bitcoin Core Node
    6. Bitcoin Core API
      1. Getting Information on Bitcoin Core’s Status
      2. Exploring and Decoding Transactions
      3. Exploring Blocks
      4. Using Bitcoin Core’s Programmatic Interface
    7. Alternative Clients, Libraries, and Toolkits
      1. C/C++
      2. JavaScript
      3. Java
      4. Python
      5. Go
      6. Rust
      7. Scala
      8. C#
  5. 4. Keys and Addresses
    1. Public Key Cryptography
      1. Private Keys
      2. Elliptic Curve Cryptography Explained
      3. Public Keys
    2. Output and Input Scripts
    3. IP Addresses: The Original Address for Bitcoin (P2PK)
    4. Legacy Addresses for P2PKH
    5. Base58check Encoding
    6. Compressed Public Keys
    7. Legacy Pay to Script Hash (P2SH)
    8. Bech32 Addresses
      1. Problems with Bech32 Addresses
      2. Bech32m
      3. Private Key Formats
      4. Compressed Private Keys
    9. Advanced Keys and Addresses
      1. Vanity Addresses
      2. Paper Wallets
  6. 5. Wallet Recovery
    1. Independent Key Generation
      1. Deterministic Key Generation
      2. Public Child Key Derivation
      3. Hierarchical Deterministic (HD) Key Generation (BIP32)
      4. Seeds and Recovery Codes
      5. Backing Up Nonkey Data
      6. Backing Up Key Derivation Paths
    2. A Wallet Technology Stack in Detail
      1. BIP39 Recovery Codes
      2. Creating an HD Wallet from the Seed
      3. Using an Extended Public Key on a Web Store
  7. 6. Transactions
    1. A Serialized Bitcoin Transaction
    2. Version
    3. Extended Marker and Flag
    4. Inputs
      1. Length of Transaction Input List
      2. Outpoint
      3. Input Script
      4. Sequence
    5. Outputs
      1. Outputs Count
      2. Amount
      3. Output Scripts
    6. Witness Structure
      1. Circular Dependencies
      2. Third-Party Transaction Malleability
      3. Second-Party Transaction Malleability
      4. Segregated Witness
      5. Witness Structure Serialization
    7. Lock Time
    8. Coinbase Transactions
    9. Weight and Vbytes
    10. Legacy Serialization
  8. 7. Authorization and Authentication
    1. Transaction Scripts and Script Language
      1. Turing Incompleteness
      2. Stateless Verification
      3. Script Construction
      4. Pay to Public Key Hash
    2. Scripted Multisignatures
      1. An Oddity in CHECKMULTISIG Execution
    3. Pay to Script Hash
      1. P2SH Addresses
      2. Benefits of P2SH
      3. Redeem Script and Validation
    4. Data Recording Output (OP_RETURN)
      1. Transaction Lock Time Limitations
      2. Check Lock Time Verify (OP_CLTV)
      3. Relative Timelocks
      4. Relative Timelocks with OP_CSV
    5. Scripts with Flow Control (Conditional Clauses)
      1. Conditional Clauses with VERIFY Opcodes
      2. Using Flow Control in Scripts
    6. Complex Script Example
      1. Segregated Witness Output and Transaction Examples
      2. Upgrading to Segregated Witness
    7. Merklized Alternative Script Trees (MAST)
    8. Pay to Contract (P2C)
    9. Scriptless Multisignatures and Threshold Signatures
    10. Taproot
    11. Tapscript
  9. 8. Digital Signatures
    1. How Digital Signatures Work
      1. Creating a Digital Signature
      2. Verifying the Signature
      3. Signature Hash Types (SIGHASH)
    2. Schnorr Signatures
      1. Serialization of Schnorr Signatures
      2. Schnorr-based Scriptless Multisignatures
      3. Schnorr-based Scriptless Threshold Signatures
    3. ECDSA Signatures
      1. ECDSA Algorithm
      2. Serialization of ECDSA Signatures (DER)
    4. The Importance of Randomness in Signatures
    5. Segregated Witness’s New Signing Algorithm
  10. 9. Transaction Fees
    1. Who Pays the Transaction Fee?
    2. Fees and Fee Rates
    3. Estimating Appropriate Fee Rates
    4. Replace By Fee (RBF) Fee Bumping
    5. Child Pays for Parent (CPFP) Fee Bumping
    6. Package Relay
    7. Transaction Pinning
    8. CPFP Carve Out and Anchor Outputs
    9. Adding Fees to Transactions
    10. Timelock Defense Against Fee Sniping
  11. 10. The Bitcoin Network
    1. Node Types and Roles
    2. The Network
    3. Compact Block Relay
    4. Private Block Relay Networks
    5. Network Discovery
    6. Full Nodes
    7. Exchanging “Inventory”
    8. Lightweight Clients
    9. Bloom Filters
      1. How Bloom Filters Work
      2. How Lightweight Clients Use Bloom Filters
    10. Compact Block Filters
      1. Golomb-Rice Coded Sets (GCS)
      2. What Data to Include in a Block Filter
      3. Downloading Block Filters from Multiple Peers
      4. Reducing Bandwidth with Lossy Encoding
      5. Using Compact Block Filters
    11. Lightweight Clients and Privacy
    12. Encrypted and Authenticated Connections
    13. Mempools and Orphan Pools
  12. 11. The Blockchain
    1. Structure of a Block
    2. Block Header
    3. Block Identifiers: Block Header Hash and Block Height
    4. The Genesis Block
    5. Linking Blocks in the Blockchain
    6. Merkle Trees
    7. Merkle Trees and Lightweight Clients
    8. Bitcoin’s Test Blockchains
      1. Testnet: Bitcoin’s Testing Playground
      2. Signet: The Proof of Authority Testnet
      3. Regtest: The Local Blockchain
    9. Using Test Blockchains for Development
  13. 12. Mining and Consensus
    1. Bitcoin Economics and Currency Creation
    2. Decentralized Consensus
    3. Independent Verification of Transactions
    4. Mining Nodes
      1. The Coinbase Transaction
      2. Coinbase Reward and Fees
      3. Structure of the Coinbase Transaction
      4. Coinbase Data
    5. Constructing the Block Header
    6. Mining the Block
      1. Proof-of-Work Algorithm
      2. Target Representation
      3. Retargeting to Adjust Difficulty
    7. Median Time Past (MTP)
    8. Successfully Mining the Block
    9. Validating a New Block
    10. Assembling and Selecting Chains of Blocks
    11. Mining and the Hash Lottery
      1. The Extra Nonce Solution
      2. Mining Pools
    12. Hashrate Attacks
    13. Changing the Consensus Rules
      1. Hard Forks
      2. Soft Forks
      3. Consensus Software Development
  14. 13. Bitcoin Security
    1. Security Principles
      1. Developing Bitcoin Systems Securely
      2. The Root of Trust
    2. User Security Best Practices
      1. Physical Bitcoin Storage
      2. Hardware Signing Devices
      3. Ensuring Your Access
      4. Diversifying Risk
      5. Multisig and Governance
      6. Survivability
  15. 14. Second-Layer Applications
    1. Building Blocks (Primitives)
    2. Applications from Building Blocks
    3. Colored Coins
      1. Single-Use Seals
      2. Pay to Contract (P2C)
      3. Client-Side Validation
      4. RGB
      5. Taproot Assets
    4. Payment Channels and State Channels
      1. State Channels—Basic Concepts and Terminology
      2. Simple Payment Channel Example
      3. Making Trustless Channels
      4. Asymmetric Revocable Commitments
      5. Hash Time Lock Contracts (HTLC)
    5. Routed Payment Channels (Lightning Network)
      1. Basic Lightning Network Example
      2. Lightning Network Transport and Pathfinding
      3. Lightning Network Benefits
  16. A. The Bitcoin Whitepaper by Satoshi Nakamoto
    1. Bitcoin - A Peer-to-Peer Electronic Cash System
      1. Introduction
      2. Transactions
      3. Timestamp Server
      4. Proof-of-Work
      5. Network
      6. Incentive
      7. Reclaiming Disk Space
      8. Simplified Payment Verification
      9. Combining and Splitting Value
      10. Privacy
      11. Calculations
      12. Conclusion
      13. References
    2. License
  17. B. Errata to the Bitcoin Whitepaper
    1. Abstract
    2. Transactions
    3. Proof of Work
    4. Reclaiming Disk Space
    5. Simplified Payment Verification
    6. Privacy
    7. Calculations
  18. C. Bitcoin Improvement Proposals
  19. Index
  20. About the Authors

Product information

  • Title: Mastering Bitcoin, 3rd Edition
  • Author(s): Andreas M. Antonopoulos, David A. Harding
  • Release date: November 2023
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098150099