Sub topic 4
Bitcoin: UTXOs, Limited Scripting, and Design Goals
This chapter assumes you understand hashing and public/private keys at a high level. It also assumes you can read short Python programs. The central idea is that Bitcoin does not store balances in accounts. It stores spendable transaction outputs.
The UTXO model
A UTXO is an unspent transaction output. Each output records an amount of bitcoin and a locking condition that says who may spend it. When a transaction spends that output, the output becomes spent and disappears from the current UTXO set.
A transaction creates new outputs. Its inputs point to older outputs and provide data that satisfies their locking conditions. The total input value must cover the total output value. The difference becomes the transaction fee.
| Part | Role |
|---|---|
| Input | References an earlier UTXO and proves it may be spent |
| Output | Creates a new spendable amount and its spending condition |
| Fee | Input total minus output total |
Suppose your wallet controls UTXOs worth 0.30 BTC and 0.15 BTC. To pay 0.40 BTC plus a 0.01 BTC fee, it can consume both UTXOs and create:
- A 0.40 BTC payment output
- A 0.04 BTC change output
- A 0.01 BTC fee
The change output usually goes to a new address controlled by your wallet. If the wallet forgets to create change, the entire leftover amount becomes a fee.
utxos = [
{"txid": "a1", "value": 30_000_000},
{"txid": "b2", "value": 15_000_000},
]
payment = 40_000_000
fee = 1_000_000
selected = []
total = 0
for utxo in utxos:
selected.append(utxo)
total += utxo["value"]
if total >= payment + fee:
break
change = total - payment - fee
print("selected:", selected)
print("payment:", payment, "satoshis")
print("change:", change, "satoshis")
print("fee:", fee, "satoshis")A satoshi is the smallest Bitcoin unit: 1 BTC equals 100,000,000 satoshis.
Limited scripting
Bitcoin outputs use a small, deliberately constrained scripting language. A common pattern requires a valid digital signature from the private key associated with a public key hash. The network checks the script when the output is spent.
Bitcoin Script is designed to be predictable and easy for every full node to validate. It is not a general-purpose language with unrestricted loops and application state. Bitcoin supports features such as multisignature spending, timelocks, and conditional payment paths, but it does not aim to run arbitrary programs inside each transaction.
Design goals and trade-offs
Bitcoin prioritizes independent verification, resistance to unauthorized spending, and monetary rules that do not depend on a central issuer. Anyone can run a full node and verify the chain using the consensus rules.
These choices have costs:
- UTXOs can make transaction construction and wallet accounting more complex than account balances.
- Public transaction history can reveal relationships between addresses.
- Limited scripting reduces programmability compared with Ethereum's smart contracts.
- Block size and block timing limits restrict on-chain throughput.
- More validation and decentralization can mean slower settlement and higher fees during demand spikes.
Unlike an account model, Bitcoin's ledger does not directly say, “Alice has this balance.” A wallet calculates control over unspent outputs. Losing the private keys means losing the ability to satisfy those outputs' spending conditions.
Exercise
A transaction consumes 70,000 satoshis and creates outputs totaling 68,500 satoshis. What is the transaction fee?
Show answer
The fee is 1,500 satoshis, calculated as 70,000 minus 68,500.