Sub topic 1
What a blockchain ledger does
Prerequisites
This chapter assumes you know what a cryptocurrency is at a high level, can read short Python snippets, and have a basic idea of hashing and public/private key pairs.
What a blockchain ledger does
A blockchain is an append-only ledger, a record of transactions that is copied across many computers. Transactions are grouped into blocks. Each block stores a hash of the previous block, so changing an old record would change every later hash and break the chain. Nodes that hold a full copy check each new block against the protocol rules before accepting it.
Keys, addresses, and what a wallet really holds
A wallet does not store coins. It stores private keys, which are secret numbers that prove ownership. A public key is derived from the private key, and an address is a shortened form of the public key. Coins live on the ledger, and the private key authorizes spending them.
How networks agree: proof of work and proof of stake
Nodes must agree on one history. Proof of work makes block producers solve a hard hashing puzzle, so rewriting history costs real energy. Proof of stake selects block producers according to coins they lock as collateral, and dishonest behavior can lead to that collateral being destroyed.
Bitcoin: UTXOs, limited scripting, and design goals
Bitcoin tracks unspent transaction outputs (UTXOs), which are leftover amounts that can be spent once. A transaction consumes UTXOs and creates new ones. Bitcoin's scripting language is deliberately limited, which keeps validation simple and predictable.
Bitcoin's fixed supply and halving schedule
The block subsidy is the new bitcoin paid to a block producer. It halves every 210,000 blocks, and the code below uses integer shifts to compute it in satoshis (1 BTC = 100,000,000 satoshis).
SATS_PER_BTC = 100_000_000
HALVING_INTERVAL = 210_000
INITIAL_SUBSIDY = 50 * SATS_PER_BTC
def subsidy(height):
halvings = height // HALVING_INTERVAL
if halvings >= 64:
return 0
return INITIAL_SUBSIDY >> halvings
print(subsidy(0) / SATS_PER_BTC) # 50.0
print(subsidy(210_000) / SATS_PER_BTC) # 25.0Exercise
Using the subsidy function above, what is the block subsidy at height 420,000?
Show answer
12.5 BTC. Height 420,000 is two halvings in (420,000 // 210,000 = 2), so 50 / 2 / 2 = 12.5.