Proof of Work & Difficulty
Lesson, slides, and applied problem sets.
View SlidesLesson
Proof of Work & Difficulty
Why this module exists
Proof-of-work is the security backbone of Bitcoin. It turns hashing into a measurable cost and anchors consensus on most work.
1) Block headers
The header is the data being mined:
- Version, PrevHash, MerkleRoot, Timestamp, Bits, Nonce
- Header hash is double SHA-256
2) Target and difficulty
Bits encodes the target in a compact form. A block is valid if:
hash(header) <= target
This is a numeric comparison with the hash interpreted as a big-endian integer.
3) Mining loop
Mining is a brute-force search over the nonce (and extra fields if needed). The first valid nonce wins.
4) Subtleties
- Endianness mistakes invalidate work
- Off-by-one on target comparison breaks consensus
- Canonical compact encoding matters
What you will build
- Compact target conversion
- Header hashing
- Nonce search (mining)
Key takeaways
- PoW = hard to find, easy to verify.
- Target math must be exact.
- Hash comparison is integer comparison, not string.