Every Byte Tells a Story

A Complete Guide to Bitcoin Transaction Anatomy
Imagined by Brian Hirschfield
Magic Internet Math Academy · 2026
Web Edition — Interactive
20 chapters 7 appendices 23 tools 13 real specimens
Part I — Foundations
1The Raw Transaction
Satoshi → Hal Finney, 275 bytes parsed byte by byte. Version, inputs, outputs, locktime.
2The Script Machine
Bitcoin's stack-based VM. Opcodes, evaluation model, Script as predicate.
3Hashing and Signing
SHA-256d, sighash preimages, ECDSA, DER encoding, SIGHASH flags, ANYONECANPAY.
Part II — The Classic Era (2009–2017)
4Pay to Public Key (P2PK)
The original output type. Exposed keys, quantum implications, Genesis Block.
5Pay to Public Key Hash (P2PKH)
The "1-address" revolution. Hash160, Base58Check, the quantum firewall.
6Pay to Script Hash (P2SH)
BIP 16, "3-addresses," redeem scripts, two-phase evaluation.
7Multisig
OP_CHECKMULTISIG, the off-by-one bug, m-of-n combinations.
Part III — The SegWit Revolution (2017–2021)
8Segregated Witness
Malleability, marker/flag bytes, weight vs size vs vsize.
9P2WPKH: Native SegWit
bc1q addresses, empty scriptSig, Bech32 encoding.
10P2WSH: SegWit Script Hash
Witness scripts, P2WSH multisig, the witness stack.
11Wrapped SegWit: The Backward-Compatible Bridge
P2SH-P2WPKH and P2SH-P2WSH — backward compatibility for legacy wallets.
Part IV — The Taproot Era (2021–present)
12Taproot: P2TR and Schnorr Signatures
BIP 340/341/342, 64-byte Schnorr sigs, x-only keys, key path spending.
13Tapscript: The Script Path
Merkle tree of scripts, control blocks, TapLeaf and TapBranch.
Part V — Special Transactions
14The Coinbase Transaction
Null input, block height, witness commitment, mining pool tags.
15OP_RETURN: Data on the Blockchain
Provably unspendable outputs, 80-byte data limit.
16Timelocks: Programming in Time
nLockTime, CLTV, CSV, relative timelocks, HTLCs.
17RBF and CPFP: Fee Market
Replace-by-fee, child-pays-for-parent, TRUC transactions, package relay.
Part VI — Protocol Layer Transactions
18Lightning Network
Funding, commitment, HTLC, cooperative close, force close, penalty.
19Ordinals and Inscriptions
Ordinal theory, the envelope protocol, commit/reveal, inscription #0.
20Runes: Fungible Tokens
Runestones, LEB128, etching, minting, edicts, cenotaphs.
Appendices
AComplete Opcode Reference
Every Script opcode by functional category — hex, decimal, behavior, status.
BTransaction Size Calculator
Byte-level sizing for every standard input and output type; weight and vsize tables.
CHex Parsing Cheat Sheet
Field-by-field lookup for reading any raw transaction hex at sight.
DRust Implementations
Self-contained Rust code: parser, hasher, DER decoder, Script interpreter, weight calculator.
EMining a Block — From Mempool to Chain
The eight-stage mining pipeline with an in-browser nonce grinder that hashes real 80-byte headers.
FConsensus vs. Relay Policy
The two rule sets, side by side. Every check in Bitcoin Core's IsStandardTx, with an in-browser standardness checker.
GSelective Witness Pruning
Why a node operator can't strip just inscription data — the C++ code, the on-disk byte layout, and the two architectures that could make it work.

Interactive Tools

Twenty-four browser-native demos — all real Bitcoin math, no mocks. Click any card to open the tool in a new context.

Parsing & Analysis
🔬

Transaction Dissector

Paste raw hex — get color-coded byte-by-byte parsing with a structure tree.

Transaction Validator

End-to-end transaction validation: structure, scripts, sighash, signatures.

⚖️

Weight Lab

Interactively compute weight, size, and vsize for any transaction shape.

🪞

Malleability Attack

Reproduce the Mt. Gox OP_PUSHDATA2 malleability technique from February 2014.

🧹

Why Selective Pruning Fails

Bitcoin Core's block storage internals — why witness pruning requires rewriting the storage layer.

Script Execution
⚙️

Script VM

Step through Bitcoin Script with animated stack. P2PK, P2PKH, P2SH multisig, P2WPKH.

🔒

P2SH Two-Phase Evaluator

Watch the push-phase and redeem-phase evaluation of a P2SH spend unfold step by step.

🗝️

Redeem Script Explorer

Build redeem scripts and observe how they hash into the P2SH scriptPubKey.

🔎

Redeem Script Anatomy

From redeem-script bytes to 3-address, field by field.

📏

Linear Scan Visualizer

The OP_CHECKMULTISIG key-ordering pitfall visualized across an m-of-n scan.

Addresses & Hashing Pipelines
🧬

Address Pipeline

Public-key → Hash160 → Base58Check / Bech32 — every step live.

🧮

Hash160 Pipeline

SHA-256 then RIPEMD-160, with intermediate state exposed.

🧾

P2SH Address Derivation

From redeem-script hash to "3-address," checksum and all.

🥇

The First P2PKH

Block 728, August 19 2009 — the first "1-address" output on the chain, parsed live.

📜

Genesis Block Message

Decode "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks" from its raw scriptSig.

Signatures & SIGHASH
✍️

ECDSA Signing Lab

Generate deterministic (RFC 6979) signatures over secp256k1 with visible r, s, k.

🩺

Sighash Surgeon

Build the exact preimage for every SIGHASH flag — ALL, NONE, SINGLE, ANYONECANPAY.

🧪

DER Signature Autopsy

Dissect every byte of a DER-encoded ECDSA signature; catch low-S and length quirks.

ANYONECANPAY Demo

The real Block 207,733 assurance contract — the first 0x81 transaction on mainnet.

Taproot & Schnorr
🌱

Schnorr Verifier

secp256k1 math playground: lift_x, scalar multiplication, full BIP 340 verification.

🌿

TapTweak Demo

Derive the Taproot output key Q = P + H(P‖c)·G, with script-tree and key-path modes.

🌳

Taproot Tree Builder

Assemble a TapLeaf / TapBranch Merkle tree and inspect the resulting commitment.

Timelocks & Data Protocols

Timelock Decoder

Decode nLockTime, nSequence, CLTV, and CSV values into wall-clock and block meanings.

Runestone Decoder

Parse a raw Runes protocol OP_RETURN: tags, edicts, LEB128-encoded fields.