Table of Contents

Copyright

Brief Table of Contents

Table of Contents

Foreword

Preface

Acknowledgments

About this book

About the author

Chapter 1. Introduction to Bitcoin

What is Bitcoin?

The big picture

Problems with money today

The Bitcoin approach

How is Bitcoin used?

Other cryptocurrencies

Summary

Chapter 2. Cryptographic hash functions and digital signatures

The cookie token spreadsheet

Cryptographic hashes

Why are cryptographic hash functions useful?

How does a cryptographic hash function work?

Properties of a cryptographic hash function

Some well-known hash functions

Recap of cryptographic hashes

Exercises

Warm up

Dig in

Digital signatures

Typical use of digital signatures

Improving cookie token security

Preparation: John generates a key pair

Recap of key pairs

Where were we?

John signs his payment

Lisa verifies the signature

Private key security

Recap

Exercises

Warm up

Dig in

Summary

Chapter 3. Addresses

Cookie-eating habits disclosed

Replacing names with public keys

New payment process

Shortening the public key

Hashing the public key to 20 bytes

Why SHA256 and RIPEMD160?

Avoiding expensive typing errors

Where were we?

Base58check

Back to privacy

Recap

System changes

Exercises

Warm up

Dig in

Summary

Chapter 4. Wallets

First wallet version

Private key backups

A few words on password strength

Problems with password-encrypted backups

Hierarchical deterministic wallets

Deriving a master extended private key

Deriving a child extended private key

Where were we?

Back to backup

Mnemonic sentences

Encoding a seed into a mnemonic sentence

Decoding a mnemonic sentence into a seed

Extended public keys

Deriving hardened private keys

Public key math

Public key multiplication

Why is this secure?

Xpub derivation

Public key encoding

Recap

System changes

Exercises

Warm up

Dig in

Summary

Chapter 5. Transactions

Problems with the old system

Paying using a transaction

Creating the transaction

Lisa confirms the transaction

Anyone verifies the transaction

Account-based and value-based systems

Script

Why use a program?

Why signature script and pubkey script?

Where were we?

Fancy payment types

Multiple signatures

Pay-to-script-hash

More stuff in transactions

Rewards and coin creation

Transition from version 4.0

Trust in Lisa

Recap

System changes

Exercises

Warm up

Dig in

Summary

Chapter 6. The blockchain

Lisa can delete transactions

Building the blockchain

Lisa builds a block

How does this process protect you from deletes?

Why use a blockchain?

Lightweight wallets

Bloom filters obfuscate addresses

Where were we?

Merkle trees

Creating the merkle root

Proving that a transaction is in a block

How it really works

Security of lightweight wallets

Recap

System changes

Exercises

Warm up

Dig in

Summary

Chapter 7. Proof of work

Cloning Lisa

Block collisions

Drawing lucky numbers

Probability of splits

Where were we?

Forcing honest lucky numbers

Producing a valid proof of work

Why is this good?

Comparing with lucky numbers

What if you run out of nonces?

Miners have to move out

Adding more hashrate

Problems with a high block rate

What’s fixed?

Difficulty adjustments

Rules for timestamps

Chain strength vs. chain length

What harm can miners do?

Double spending

Protecting against double-spend attacks

Transaction fees

Bigger blocks are slower

But wasn’t this about transaction fees?

Block size is limited

When the block subsidy is 0

Recap

System changes

Exercises

Warm up

Dig in

Summary

Chapter 8. Peer-to-peer network

The shared folder

Let’s build a peer-to-peer network

How do peers talk?

The network protocol

John sends the transaction

Tom forwards the transaction

The cafe’s lightweight wallet is notified

Including the transaction in a block

Notifying wallets

More confirmations

Leaving the cookie token system

Bitcoin at a glance

Where were we?

Bootstrapping the network

Step 1—Run the software

Step 2—Connect to nodes

Step 3—Synchronize

Running your own full node

Downloading Bitcoin Core

Verifying the software

Unpacking and starting

Initial blockchain download

Recap

Part 1—Following a transaction

Part 2—Joining the network

System changes

Exercises

Warm up

Dig in

Summary

Chapter 9. Transactions revisited

Time-locked transactions

Time measurements

Relative time locks

Time-locked outputs

Absolute time-locked outputs

Relative time-locked outputs

Atomic swaps

Storing stuff in the Bitcoin blockchain

Bloated UTXO set

Creating a token in Bitcoin

Starting the car with proof of ownership

Replacing pending transactions

Opt-in replace-by-fee

Child pays for parent

Different signature types

Recap

Exercises

Warm up

Dig in

Summary

Chapter 10. Segregated witness

Problems solved by segwit

Transaction malleability

Inefficient signature verification

Waste of bandwidth

Script upgrades are hard

Solutions

Segwit addresses

Spending your segwit output

Verifying the segwit transaction

Including your segwit transaction in a block

Pay-to-witness-script-hash

New hashing method for signatures

Bandwidth savings

Upgradable script

Wallet compatibility

Recap of payment types

Block limits

Block size limit

Signature operations limit

Increasing the limits

Recap

Solutions

Exercises

Warm up

Dig in

Summary

Chapter 11. Bitcoin upgrades

Bitcoin forks

Nonconsensus rule changes

Hard forks

Soft forks

Differences between hard and soft forks

Transaction replay

Replay protection

Upgrade mechanisms

Using coinbase signaling—BIP16

Using incremented block version number signaling—BIP34, 66, and 65

Using block version bits signaling—BIP9

Using BIP9 to deploy relative lock time

Using BIP9 to deploy segwit

User-activated soft forks

Recap

Exercises

Warm up

Dig in

Summary

A. Using bitcoin-cli

Communicating with bitcoind

Using curl

Graphical user interface

Getting to know bitcoin-cli

Getting to work

Creating an encrypted wallet

Backing up the wallet

Receiving money

Sending money

B. Answers to exercises

Chapter 2

Chapter 3

Chapter 4

Chapter 5

Chapter 6

Chapter 7

Chapter 8

Chapter 9

Chapter 10

Chapter 11

C. Web resources

Index

List of Figures

List of Tables