Proof of Work: Mining & Difficulty Adjustment
Implement a PoW miner and understand nonce search and target difficulty.
Proof of Work: Mining & Difficulty Adjustment is a free Cryptology Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is Proof of Work?
Proof of Work (PoW) requires a block producer to perform a computationally expensive task to add a block. This deters spam and makes chain rewriting expensive. Verifying the proof is cheap (one hash). Work requires many hash computations.
The Mining Challenge
Bitcoin PoW: find a nonce such that SHA256d(block_header) < target. The target is a 256-bit number. A smaller target means more leading zeros required in the hash output, making valid nonces rarer and harder to find.
Python PoW Demo
import hashlib def mine(data, difficulty): target = "0"*difficulty nonce = 0 while True: h = hashlib.sha256(f"{data}{nonce}".encode()).hexdigest() if h.startswith(target): return nonce, h nonce += 1 nonce, h = mine("block data", 4) print(nonce, h) # hash starts with "0000"
Difficulty Target
Bitcoin block header has a "bits" field encoding the current target. Target = coefficient * 256^(exponent-3). Example: bits=0x1703a30c → target = 0x03a30c * 2^(8*(0x17-3)) = a 256-bit number with ~72 leading zero bits required.
Difficulty Adjustment
Bitcoin adjusts difficulty every 2016 blocks (~2 weeks). Target adjustment: new_target = old_target * (actual_time / 2016 * 10 minutes). If blocks came faster than 10 min average, target decreases (harder). If slower, target increases (easier). Maintains ~10 min block time.
Hash Rate and Security
Network hash rate (H/s) measures total mining power. Higher hash rate = smaller probability per unit time of finding a valid nonce by chance. To rewrite k blocks, an attacker needs >50% of network hash rate sustained for time proportional to k*10 minutes.
51% Attack
With >50% hash rate, an attacker can: (1) mine a secret fork, (2) include or exclude transactions, (3) double-spend by publishing a longer chain after a payment is confirmed. Cannot: steal others' coins, create coins from nothing, reverse transactions deep in the chain.
ASIC Mining and Centralization
Bitcoin SHA256d mining is dominated by ASICs (Application-Specific Integrated Circuits) — chips optimized for a single hash function. ASICs are 10^6x more efficient than CPUs. This concentrates mining in large data centers, raising centralization concerns.
Memory-Hard PoW
Ethereum used Ethash (now deprecated) — memory-hard PoW requiring a large DAG dataset. Memory-hardness resists ASICs (memory bandwidth is hard to optimize cheaply). Monero uses RandomX (CPU-optimized, ASIC-resistant). Zcash uses Equihash (memory-hard).
Selfish Mining
Selfish mining strategy: withhold a found block, mine a second block, then release both simultaneously. If timed correctly, honest miners waste work on the orphaned block. Requires ~33% hash rate to be profitable on average, not 51%.
Proof of Stake Alternative
Proof of Stake (PoS, used by Ethereum post-Merge) replaces hash work with staked cryptocurrency. Validators are chosen to propose blocks proportional to their stake. PoS uses 99.95% less energy than PoW. Trade-off: different trust assumptions and attack economics.
Quick Check
What does Bitcoin's difficulty adjustment try to maintain?
Recap
PoW requires finding a nonce such that SHA256d(header) < target. Difficulty adjusts every 2016 blocks. 51% hash rate enables double-spend attacks. ASICs dominate Bitcoin mining; memory-hard functions resist ASICs. Next: Bitcoin Script and UTXO signatures.
Frequently asked questions
Is the “Proof of Work: Mining & Difficulty Adjustment” lesson free?
Yes — the full text of “Proof of Work: Mining & Difficulty Adjustment” is free to read here on the web, and the Cryptology Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO.
What will I learn in “Proof of Work: Mining & Difficulty Adjustment”?
Implement a PoW miner and understand nonce search and target difficulty. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cryptology Academy?
No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Proof of Work: Mining & Difficulty Adjustment” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cryptology Academy lesson?
Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Hash Chains & Block Linking
- Merkle Trees: Transaction Integrity at Scale
- Proof of Work: Mining & Difficulty Adjustment
- Bitcoin Script & UTXO Signature Verification