Blockchain & Bitcoin: The Mathematics
Strip away the hype and blockchain is a chain of cryptographic data structures protected by hash puzzles. Every node in the Bitcoin network independently verifies the same mathematics — hash functions, Merkle trees, elliptic curve signatures — to agree on a single transaction history without trusting anyone.
1. Cryptographic Hash Functions
Bitcoin uses SHA-256 (Secure Hash Algorithm, 256-bit output). A hash function maps arbitrary-length input to a fixed-length output with these properties:
- Deterministic: Same input → same output, always
- Fast: Computing H(x) takes microseconds
- Pre-image resistance: Given H(x), finding x is computationally infeasible (requires ~2²⁵⁶ guesses)
- Collision resistance: Finding x₁ ≠ x₂ where H(x₁) = H(x₂) requires ~2¹²⁸ trials (birthday bound)
- Avalanche effect: Changing one bit of input flips ~50% of output bits
Bitcoin applies SHA-256 twice: SHA-256(SHA-256(block_header)). This double hashing prevents length-extension attacks and is a design choice from Satoshi's original protocol.
2. Merkle Trees
Each block contains thousands of transactions. Instead of listing them all in the block header, Bitcoin builds a Merkle tree — a binary tree of hashes:
- Leaf nodes: hash of each individual transaction
- Internal nodes: hash of concatenation of two children. H(AB) = SHA-256(H(A) || H(B))
- Root: a single 32-byte Merkle root that commits to all transactions in the block
This allows Simple Payment Verification (SPV): to prove a transaction is in a block, you only need log₂(N) hashes (a "Merkle proof"), not the full block. For 4,000 transactions, that's 12 hashes × 32 bytes = 384 bytes instead of the full block (~1–2 MB).
3. Proof of Work
The block header contains: version, previous block hash, Merkle root, timestamp, difficulty target, and a 32-bit nonce. A block is valid if and only if:
There is no shortcut — the only way to find a valid hash is to guess. This is why mining requires enormous computational power. The current Bitcoin network hash rate (2025) is ~700 EH/s (700 × 10¹⁸ SHA-256d per second). Total energy consumption: ~100 TWh/year.
Once a miner finds a valid nonce, broadcasting the block is trivial — any node can verify the hash in microseconds. This asymmetry (hard to produce, easy to verify) is the foundation of proof-of-work security.
4. Difficulty Adjustment
Bitcoin targets 10-minute block intervals. Every 2,016 blocks (~2 weeks), the protocol recalculates the difficulty:
This negative feedback loop keeps block time near 10 minutes regardless of how much hash power joins or leaves the network. When China banned mining in 2021, hash rate dropped 50% overnight — difficulty adjusted down over 3 retargets, and block times stabilised within 6 weeks.
5. ECDSA: Digital Signatures
Every Bitcoin address is derived from an elliptic curve public key. Bitcoin uses the secp256k1 curve:
To spend Bitcoin, the owner signs the transaction with their private key using ECDSA (Elliptic Curve Digital Signature Algorithm). Any node verifies the signature using only the public key. The signature proves ownership without revealing the private key — this is the core authentication mechanism.
6. Byzantine Fault Tolerance
The Byzantine Generals Problem (Lamport, 1982): how do N distributed parties agree on a decision when up to f of them may lie or act maliciously? Classical theory proved that consensus requires N ≥ 3f+1 honest participants — a majority assumption.
Bitcoin's breakthrough (Nakamoto, 2008) reframes the problem: instead of counting identities (which can be Sybil-attacked), attach a computational cost to each vote. A block is a "vote" that cost real energy to produce. An attacker needs >50% of the network's total hash power to produce a longer chain — the 51% attack.
The longest chain rule: nodes always consider the chain with the most cumulative proof of work as the valid chain. This probabilistic consensus converges exponentially: after 6 confirmations (~60 min), the probability of a transaction being reversed by an attacker with 10% hash power is less than 0.001%.
7. Game Theory & Mining Economics
Mining is an economic game. A rational miner mines honestly because:
- Block reward: Currently 3.125 BTC (after April 2024 halving). Halvings occur every 210,000 blocks (~4 years). Total supply: 21 million BTC (reached ~2140).
- Transaction fees: As block rewards shrink, fees become the dominant incentive. Average fee in 2025: ~$2–$10.
- Cost of attacking: To sustain 51% of hash power would cost ~$10 billion in hardware plus ~$20 million/day in electricity. The attacker's reward (double-spending) is usually less than the cost.
The Nash equilibrium is honest mining: defecting (trying to cheat) is strictly less profitable than cooperating. This game-theoretic security is what allows a trustless, permissionless network to function without any central authority.