MASTERING-BITCOIN Β· Interactive Practice | Unit 13 Β· Video 4
| Formula | Name | Description |
|---|---|---|
| Expected hash attempts | For leading hex zeros | |
| Compact target decoding | E.g., 0x1903a30c β exponent 0x19, coefficient 0x03a30c |
|
| Difficulty retargeting | Every 2016 blocks; capped at 4Γ either way | |
| Median Time Past | Consensus time floor (BIP113) |
Mining is trial and error: keep changing the nonce until the hash starts with enough leading hex zeros. Each leading zero is 4 bits, so it multiplies the expected work by 16.
Use the slider to set the number of required leading hex zeros and watch the expected number of attempts explode.
β interactive visualization β coming to this page format soon
Notice: Each additional leading zero multiplies the expected work by 16. That's why Bitcoin uses a 256-bit target instead of "count the leading zeros" β it allows fine-grained adjustment of difficulty. Verification, however, stays trivial: one hash check.
Every 2016 blocks (~2 weeks at 10 min each = 20160 minutes), every node independently recomputes the target:
The adjustment is capped at 4Γ in either direction β a safety guardrail against hash-rate whiplash.
Drag the slider to set how long the previous 2016 blocks actually took.
β interactive visualization β coming to this page format soon
Reflect: If hash power doubles overnight, blocks arrive twice as fast and the multiplier would drop toward 0.5 β but only after 2016 blocks have been mined. Bitcoin doesn't adjust continuously; difficulty steps in discrete jumps every two weeks.
Miners write their own timestamps. To prevent lying, consensus requires a candidate block's timestamp to exceed the median of the previous 11 block timestamps (and be less than 2 hours ahead of wall-clock time). Since BIP113, all timelocks (CLTV, CSV, nLockTime, nSequence) compare against MTP β not the candidate's stamped time.
Use the slider to inject a "cheater" timestamp into one of the recent 11 blocks and see whether the median moves.
β interactive visualization β coming to this page format soon
Notice: Tampering a single timestamp barely moves the median. To shift MTP meaningfully, an attacker must lie consistently across at least 6 of the last 11 blocks β meaning they must have mined most of them. The incentive to single-block-lie collapses.
Question 1
You are mining a toy version of Bitcoin where the target requires the hash to start with 3 leading hex zeros. What is the expected number of nonce attempts to find a valid block?
β Correct! Each leading zero multiplies expected work by 16, so .
β Not quite. You multiplied 16 Γ 3 instead of exponentiating. Each leading zero is independent, so probabilities multiply.
β Not quite. Each additional leading hex zero multiplies expected attempts by 16.
Solution:
Each leading hex zero has probability (since each hex digit takes 16 possible values). For independent leading zeros:
For :
Note: is the common trap β multiplying instead of exponentiating.
Question 2
The previous retargeting period of 2016 blocks took 40,320 minutes (twice as long as the expected 20,160 minutes). What happens to the target at the next adjustment?
β Correct! When actual time > expected, target grows (easier), pushing block times back toward 10 minutes.
β Not quite. Remember: . If blocks are too slow, the target must grow to make mining easier.
Solution:
Apply the retargeting formula:
Question 3
True or False: A miner can unlock a time-locked transaction early by simply writing a future timestamp into the block header they're currently mining.
β Correct! Timelocks check against MTP (median of previous 11 timestamps), not the candidate block's own stamp. BIP113 anchors timelocks to consensus history.
β Not quite. Before BIP113 this attack was conceivable, but the rule was changed precisely to prevent it. Timelocks now check MTP.
Solution:
False. Since BIP113, all timelocks (CLTV, CSV, nLockTime, nSequence) are evaluated against Median Time Past (MTP) β the median of the previous 11 block timestamps β not against the candidate block's own stamped time.
Question 4
Block 277,316 stored its target as the compact value 0x1903a30c. Using , what is the exponent in base-10 and what power of 2 does the formula evaluate?
β
Correct! 0x19 = 25, and .
β Not quite. Watch the conversion: 0x19 is hex for 25, not 19.
β Not quite. The compact format is: first byte is the exponent (), next three bytes are the coefficient, and the formula is .
Solution:
Split 0x1903a30c into its compact form:
0x19 = 25 in decimal0x03a30cPlug into the formula:
This yields a 256-bit number with roughly 60 leading zero bits β the ceiling that any valid header hash must fall below.
Solved: 0 / 4