Transactions & UTXO

Lesson, slides, and applied problem sets.

View Slides

Lesson

Transactions & the UTXO Model

Why this module exists

Bitcoin does not track balances; it tracks unspent outputs. Transactions consume UTXOs and create new UTXOs. Understanding this model is essential for validation, fees, and double-spend prevention.


1) Transaction structure

A legacy tx is:

  • Version
  • Inputs (outpoints + scripts)
  • Outputs (value + locking script)
  • Locktime

The txid is the double SHA-256 of the serialized bytes.


2) UTXO set

The UTXO set is the authoritative ledger state. Validation rules include:

  • Every input must exist in UTXO
  • Inputs are unique within a tx
  • sum(inputs) >= sum(outputs)
  • Outputs become new UTXOs

3) Fees and coinbase

  • Fee = inputs minus outputs
  • Coinbase creates new coins (no inputs)
  • Coinbase outputs become spendable after maturity (ignored in this toy)

4) Serialization pitfalls

  • CompactSize counts are part of consensus
  • Non-canonical encodings are invalid
  • Endianness is easy to get wrong

What you will build

  1. Transaction serialization + txid
  2. UTXO validation and updates

Key takeaways

  • State = UTXO set, not balances.
  • Fees come from conservation of value.
  • Serialization correctness is consensus-critical.

Module Items