Table of Contents for
Programming Bitcoin

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Programming Bitcoin by Jimmy Song Published by O'Reilly Media, Inc., 2019
  1. Cover
  2. nav
  3. Programming Bitcoin
  4. Programming Bitcoin
  5. Preface
  6. 1. Finite Fields
  7. 2. Elliptic Curves
  8. 3. Elliptic Curve Cryptography
  9. 4. Serialization
  10. 5. Transactions
  11. 6. Script
  12. 7. Transaction Creation and Validation
  13. 8. Pay To Script Hash
  14. 9. Blocks
  15. 10. Networking
  16. 11. Simplified Payment Verification
  17. 12. Bloom Filters
  18. 13. Segwit
  19. 14. Advanced Topics and Next Steps
  20. A. Solutions
  21. Index
  22. About the Author
  23. Colophon
  1. Preface
    1. Who is this book for?
    2. What do I need to know?
    3. How is the book arranged?
    4. Setting Up
    5. Answers
    6. Conventions Used in This Book
    7. Using Code Examples
    8. O’Reilly Safari
    9. How to Contact Us
    10. Acknowledgments
  2. 1. Finite Fields
    1. Learning Higher Level Math
    2. Finite Field Definition
    3. Defining Finite Sets
      1. Constructing a Finite Field in Python
      2. Exercise 1
    4. Modulo Arithmetic
      1. Modulo Arithmetic in Python
    5. Finite Field Addition and Subtraction
      1. Exercise 2
      2. Coding Addition and Subtraction in Python
      3. Exercise 3
    6. Finite Field Multiplication and Exponentiation
      1. Exercise 4
      2. Exercise 5
      3. Coding Multiplication in Python
      4. Exercise 6
      5. Coding Exponentiation in Python
      6. Exercise 7
    7. Finite Field Division
      1. Exercise 8
      2. Exercise 9
    8. Redefining Exponentiation
    9. Conclusion
  3. 2. Elliptic Curves
    1. Definition
    2. Coding Elliptic Curves in Python
      1. Exercise 1
      2. Exercise 2
    3. Point Addition
    4. Math of Point Addition
    5. Coding Point Addition
      1. Exercise 3
    6. Point Addition for when x1≠x2
      1. Exercise 4
    7. Coding Point Addition for when x1≠x2
      1. Exercise 5
    8. Point Addition for when P1=P2
      1. Exercise 6
    9. Coding Point Addition for when P1=P2
      1. Exercise 7
    10. Coding One More Exception
    11. Conclusion
  4. 3. Elliptic Curve Cryptography
    1. Elliptic Curves over Reals
    2. Elliptic Curves over Finite Fields
      1. Exercise 1
    3. Coding Elliptic Curves over Finite Fields
    4. Point Addition over Finite Fields
    5. Coding Point Addition over Finite Fields
      1. Exercise 2
      2. Exercise 3
    6. Scalar multiplication for Elliptic Curves
      1. Exercise 4
    7. Scalar Multiplication Redux
    8. Mathematical Groups
      1. Identity
      2. Closure
      3. Invertibility
      4. Commutativity
      5. Associativity
      6. Exercise 5
    9. Coding Scalar Multiplication
    10. Defining the curve for Bitcoin
      1. Working with secp256k1
    11. Public Key Cryptography
    12. Signing and Verification
      1. Inscribing the Target
      2. Verification in-depth
      3. Verifying a Signature
      4. Exercise 6
      5. Programming Signature Verification
      6. Signing In-depth
      7. Creating a Signature
      8. Exercise 7
      9. Programming Message Signing
    13. Conclusion
  5. 4. Serialization
    1. Uncompressed SEC format
      1. Exercise 1
    2. Compressed SEC Format
      1. Exercise 2
    3. DER Signatures
      1. Exercise 3
    4. Base58
    5. Transmitting your Public Key
      1. Exercise 4
    6. Address Format
      1. Exercise 5
    7. WIF Format
      1. Exercise 6
    8. Big and Little Endian Redux
      1. Exercise 7
      2. Exercise 8
      3. Exercise 9
    9. Conclusion
  6. 5. Transactions
    1. Transaction Components
    2. Version
      1. Exercise 1
    3. Inputs
      1. Parsing Script
      2. Exercise 2
    4. Outputs
      1. Exercise 3
    5. Locktime
      1. Exercise 4
      2. Exercise 5
    6. Coding Transactions
    7. Transaction Fee
      1. Calculating the fee
      2. Exercise 6
    8. Conclusion
  7. 6. Script
    1. Mechanics of Script
    2. How Script works
    3. Example Operations
      1. Coding opcodes
      2. Exercise 1
    4. Parsing the Script fields
      1. Coding a Script parser and serializer
    5. Combining the Script fields
      1. Coding the combined instruction set
    6. Standard Scripts
    7. p2pk
      1. Coding Script Evaluation
      2. Stack elements under the hood
      3. Exercise 2
    8. Problems with p2pk
    9. Solving the problems with p2pkh
    10. p2pkh
    11. Scripts can be Arbitrarily Constructed
      1. Exercise 3
      2. Utility of Scripts
      3. Exercise 4
      4. Sha1 Piñata
    12. Conclusion
  8. 7. Transaction Creation and Validation
    1. Validating Transactions
    2. Checking the spentness of inputs
    3. Checking the sum of the inputs vs the sum of the outputs
    4. Checking the Signature
      1. Step 1: Empty all the ScriptSigs
      2. Step 2: Replace the ScriptSig of the input being signed with the previous ScriptPubKey
      3. Step 3: Append the hash type
      4. Exercise 1
      5. Exercise 2
    5. Verifying the entire transaction
    6. Creating transactions
    7. Creating a transaction
    8. Combining to make a transaction
    9. Signing a transaction
      1. Exercise 3
      2. Creating your own transactions on testnet
      3. Exercise 4
      4. Exercise 5
    10. Conclusion
  9. 8. Pay To Script Hash
    1. Bare Multisig
    2. Coding OP_CHECKMULTISIG
      1. Exercise 1
    3. Problems with Bare Multisig
    4. Pay-to-Script-Hash (p2sh)
    5. Coding p2sh
      1. More complicated scripts
      2. Addresses
      3. Exercise 2
      4. Exercise 3
      5. p2sh Signature Verification
      6. Step 1: Empty all the ScriptSigs
      7. Step 2: Replace the ScriptSig of the p2sh input being signed with the RedeemScript
      8. Step 3: Append the hash type
      9. Exercise 4
      10. Exercise 5
    6. Conclusion
  10. 9. Blocks
    1. Coinbase Transactions
      1. Exercise 1
      2. ScriptSig
      3. BIP0034
      4. Exercise 2
    2. Headers vs Full Blocks
      1. Exercise 3
      2. Exercise 4
      3. Exercise 5
    3. Version
      1. BIP9
      2. Exercise 6
      3. Exercise 7
      4. Exercise 8
    4. Previous Block
    5. Merkle Root
    6. Timestamp
    7. Bits
    8. Nonce
    9. Proof-of-work
      1. How a miner generates new hashes
      2. Target
      3. Exercise 9
      4. Difficulty
      5. Exercise 10
      6. Checking that the Proof-of-Work is Sufficient
      7. Exercise 11
    10. Difficulty Adjustment
      1. Exercise 12
      2. Exercise 13
    11. Conclusion
  11. 10. Networking
    1. Network Messages
      1. Exercise 1
      2. Exercise 2
      3. Exercise 3
    2. Parsing the payload
      1. Exercise 4
    3. Network handshake
    4. Connecting to the network
      1. Exercise 5
    5. Getting Block Headers
      1. Exercise 6
    6. Headers response
    7. Conclusion
  12. 11. Simplified Payment Verification
    1. Motivation
    2. Merkle Tree
    3. Merkle Parent
      1. Exercise 1
    4. Merkle Parent Level
      1. Exercise 2
    5. Merkle Root
      1. Exercise 3
    6. Merkle Root in Blocks
      1. Exercise 4
    7. Using a Merkle Tree
    8. Merkle Block
      1. Merkle Tree Structure
      2. Exercise 5
      3. Coding a Merkle Tree
      4. Merkle Block Command
      5. Exercise 6
      6. Using Flag bits and Hashes
      7. Exercise 7
    9. Conclusion
  13. 12. Bloom Filters
    1. What is a Bloom Filter?
      1. Exercise 1
    2. Going a step further
    3. BIP0037 Bloom Filters
      1. Exercise 2
      2. Exercise 3
    4. Loading a Bloom Filter
      1. Exercise 4
    5. Getting Merkle Blocks
      1. Exercise 5
    6. Getting Transactions of Interest
      1. Exercise 6
    7. Conclusion
  14. 13. Segwit
    1. Pay to Witness Pubkey Hash
      1. Transaction Malleability
    2. Fixing malleability
    3. Pay-to-Witness-Pubkey-Hash (p2wpkh)
    4. P2SH-P2WPKH
      1. Coding p2wpkh and p2sh-p2wpkh
    5. Pay-to-witness-script-hash (p2wsh)
    6. P2SH-P2WSH
      1. Coding p2wsh and p2sh-p2wsh
    7. Other improvements
      1. Conclusion
  15. 14. Advanced Topics and Next Steps
    1. Wallets
      1. Hierarchical Deterministic Wallets
      2. Mnemonic Seeds
    2. Payment Channels and Lightning Network
    3. Contributing
    4. Suggested Next Projects
      1. Testnet Wallet
      2. Block Explorer
      3. Web Shop
      4. Utility Library
    5. Finding a Job
      1. Conclusion
  16. A. Solutions
    1. Chapter 1: Finite Fields
      1. Exercise 1
      2. Exercise 2
      3. Exercise 3
      4. Exercise 4
      5. Exercise 5
      6. Exercise 6
      7. Exercise 7
      8. Exercise 8
      9. Exercise 9
    2. Chapter 2: Elliptic Curves
      1. Exercise 1
      2. Exercise 2
      3. Exercise 3
      4. Exercise 4
      5. Exercise 5
      6. Exercise 6
      7. Exercise 7
    3. Chapter 3: Elliptic Curve Cryptography
      1. Exercise 1
      2. Exercise 2
      3. Exercise 3
      4. Exercise 4
      5. Exercise 5
      6. Exercise 6
      7. Exercise 7
    4. Chapter 4: Serialization
      1. Exercise 1
      2. Exercise 2
      3. Exercise 3
      4. Exercise 4
      5. Exercise 5
      6. Exercise 6
      7. Exercise 7
      8. Exercise 8
      9. Exercise 9
    5. Chapter 5: Transactions
      1. Exercise 1
      2. Exercise 2
      3. Exercise 3
      4. Exercise 4
      5. Exercise 5
      6. Exercise 6
    6. Chapter 6: Script
      1. Exercise 1
      2. Exercise 2
      3. Exercise 3
      4. Exercise 4
    7. Chapter 7: Transaction Creation and Validation
      1. Exercise 1
      2. Exercise 2
      3. Exercise 3
      4. Exercise 4
      5. Exercise 5
    8. Chapter 8: Pay To Script Hash
      1. Exercise 1
      2. Exercise 2
      3. Exercise 3
      4. Exercise 4
      5. Exercise 5
    9. Chapter 9: Blocks
      1. Exercise 1
      2. Exercise 2
      3. Exercise 3
      4. Exercise 4
      5. Exercise 5
      6. Exercise 6
      7. Exercise 7
      8. Exercise 8
      9. Exercise 9
      10. Exercise 10
      11. Exercise 11
      12. Exercise 12
      13. Exercise 13
    10. Chapter 10: Networking
      1. Exercise 1
      2. Exercise 2
      3. Exercise 3
      4. Exercise 4
      5. Exercise 5
      6. Exercise 6
    11. Chapter 11: SPV
      1. Exercise 1
      2. Exercise 2
      3. Exercise 3
      4. Exercise 4
      5. Exercise 5
      6. Exercise 6
      7. Exercise 7
    12. Chapter 12: Bloom Filters
      1. Exercise 1
      2. Exercise 2
      3. Exercise 3
      4. Exercise 4
      5. Exercise 5
      6. Exercise 6
  17. Index
Back to top