Leanpub Header

Skip to main content

Mastering Taproot

Unlocking Bitcoin’s Future: Taproot Script Engineering for Developers

This book is 90% completeLast updated on 2026-06-19

The first comprehensive guide to Taproot script engineering. Learn Bitcoin from the inside out — through real testnet transactions, stack execution, and Merkle trees. This book is evolving into an open, testnet-driven Taproot engineering lab.

Minimum price

Free!

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
About

About

About the Book

A practical, developer-focused guide to real Taproot engineering.

This book is not a conceptual overview. It is a build-and-verify walkthrough: you construct transactions, inspect witness data, and validate results on testnet.

You will learn how to:

  • Build script-path spends (single-leaf → multi-leaf)
  • Verify control blocks and Merkle paths
  • Debug failures at the script / witness layer
  • Read real transactions like an engineer
Free to download
Suggested price: $29

If you can pay, your support funds ongoing updates. If you can’t, you’re still welcome to learn.

Open Engineering Repository

This project is actively maintained as an open engineering effort.

Repository:

https://github.com/aaron-recompile/mastering-taproot

If this book helped you, starring the repository is the simplest way to support the project.

Contact:

aaron.recompile@gmail.com

Author

About the Author

Aaron Zhang

Aaron Zhang is a Bitcoin infrastructure builder and educator focused on reproducible transaction construction, control block analysis, and consensus-level clarity in Bitcoin’s script system.

He publishes technical deep-dives and executable labs to help developers bridge theory and real-world implementation.

Medium: https://medium.com/@aaron.recompile

GitHub: https://github.com/aaron-recompile

Contents

Table of Contents

Chapter 1: Private Keys, Public Keys, and Address Encoding

  1. 1.1 The Derivation Chain
  2. 1.2 Private Keys: The Foundation of Ownership
  3. 1.3 Public Keys: Cryptographic Verification Points
  4. 1.4 Address Generation: From Public Keys to Payment Destinations
  5. 1.5 Address Types and Encoding Formats
  6. 1.6 Address Format Comparison
  7. 1.7 The Derivation Model
  8. 1.8 What Carries Into Taproot

Chapter 2: Bitcoin Script Fundamentals - Stack Operations and P2PKH

  1. 2.1 The UTXO Model: Digital Cash, Not Digital Banking
  2. 2.2 Bitcoin Script and P2PKH Fundamentals
  3. 2.3 Practical Implementation: Building a P2PKH transaction
  4. Chapter Summary

Chapter 3: P2SH Script Engineering - From Multi-signature to Time Locks

  1. 3.1 P2SH Architecture: Scripts Behind the Hash
  2. 3.2 2-of-3 Multisig
  3. 3.3 Time Locks with CSV
  4. 3.4 P2SH vs P2PKH: What P2SH Adds, and Where It Stops
  5. Chapter Summary

Chapter 4: Building SegWit Transactions — Construction, Stack Execution, and Malleability

  1. 4.1 Transaction Malleability: The Problem SegWit Solves
  2. 4.2 Creating a Complete SegWit Transaction
  3. 4.3 SegWit Transaction Construction and Analysis
  4. 4.4 P2WPKH Stack Execution
  5. 4.5 From SegWit to Taproot
  6. 4.6 Chapter Summary

Chapter 5: Taproot: The Evolution of Bitcoin’s Script System

  1. Schnorr Signatures
  2. Key Tweaking
  3. A Simple Taproot Transaction
  4. On-Chain Example: Testnet Taproot Transfer
  5. Key-Path Stack Execution
  6. Output Shape: Legacy -> SegWit -> Taproot
  7. SegWit -> Taproot: Code Differences
  8. Cooperative vs Script Path: Cost Asymmetry
  9. Chapter Summary

Chapter 6: Building Real Taproot Contracts — Single-Leaf Hash Lock and Dual-Path Spending

  1. The Scenario: A Conditional Payment
  2. Two Spending Paths
  3. The Commit–Reveal Pattern
  4. Single-Leaf Hash Lock: From Commit to Reveal
  5. When Script-Path Spending Fails: A Checklist
  6. Stack Execution: Walking the Hash Lock
  7. Key Path vs Script Path
  8. How This Differs from P2SH
  9. Chapter Summary

Chapter 7: Taproot Dual-Leaf Script Tree — Hash Lock and Bob Script

  1. From One Leaf to Two
  2. The Merkle Structure of a Two-Leaf Tree
  3. Two On-Chain Transactions
  4. Commit: Building the Two-Leaf Tree
  5. Reveal: Spending Each Script Path
  6. Control Blocks, Read From the Chain
  7. Script Path 1: Hash Script
  8. Script Path 2: Bob Script
  9. What Changed From the Single-Leaf Case
  10. Patterns for Building Two-Leaf Taproot
  11. Cost and Privacy of the Three Paths
  12. Chapter Summary

Chapter 8: Four-Leaf Taproot Script Tree — Hashlock, Multisig, Timelock, and Signature

  1. From Two Leaves to Four
  2. The Tree, and One Shared Address
  3. Building the Tree
  4. Spending Each Path
  5. How OP_CHECKSIGADD Runs
  6. The Four-Leaf Control Block
  7. Three Things That Bite
  8. Chapter Summary

Chapter 9: Ordinals and BRC-20 — Data Envelopes in Single-Leaf Script Paths

  1. A Single Leaf That Carries Data
  2. The Data Envelope: OP_0 OP_IF ... OP_ENDIF
  3. On-Chain Example: Testnet BRC-20 Mint Transaction Pair
  4. Code: Building the Inscription Leaf and Temporary Address
  5. Code: Commit and Reveal (Key Fragments)
  6. Indexer
  7. Chapter Summary

Chapter 10: RGB and Tapret — Commitments Inside the Script Tree

  1. What RGB Is
  2. The Opposite of Ordinals: Nothing Visible On-Chain
  3. Tapret: An Unspendable Leaf at Depth 1 of the Script Tree
  4. Seals: Binding State to a UTXO
  5. On-Chain Example: Testnet Transfer Transaction
  6. Code: Six-Step Transfer Flow
  7. What Bitcoin Sees vs What the RGB Client Sees
  8. How Tapret Changes the Output Key
  9. Chapter Summary

Chapter 11: Lightning Network Channels — From P2WSH Multisig to Taproot Privacy Channels

  1. Lightning: One of Taproot’s Original Motivations
  2. P2WSH: The SegWit v0 Script Hash
  3. On-Chain Example: P2WSH Channel Funding and Close
  4. Taproot Channel: MuSig2 Key Aggregation
  5. MuSig2 Cooperative Close: The Four-Round Signing Protocol
  6. Side-by-Side Comparison
  7. Chapter Summary

Chapter 12: Silent Payments — Elliptic Curve Arithmetic and Address Privacy

  1. Back to Chapter 5’s Tweak
  2. The Address Reuse Problem
  3. On-Chain Example: Testnet Silent Payment
  4. The Mathematics: Same as Taproot’s Tweak
  5. The Two-Key Split
  6. Chapter Summary
  7. Taproot Applications

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub