Hashly / research · NOTE 01
How small PoW forks break difficulty adjustment: and what to check before you fork.
Slow windows, time warp, timestamp limits sized for Bitcoin and asymmetric clamps: the public history of difficulty bugs in small proof-of-work chains, with a pre-fork checklist.
Why small chains are different
On a large chain, the hashrate that can arrive or leave in an hour is a small fraction of the total. On a small fork it can be several times the total. Rented hashrate and profit-switching pools move to whichever coin pays the most per hash, so a chain with a few percent of its algorithm’s hashrate sees miners arrive when difficulty is low and leave when it rises.
That turns the difficulty adjustment algorithm (DAA) into the main consensus attack surface of a small chain. It decides how many cheap blocks the chain hands out when hashrate arrives, how long it stalls when hashrate leaves, and how far a miner can move difficulty by choosing timestamps. Most of the failures below were inherited: the fork kept parameters that were sized for its parent.
Slow windows and emergency rules
Bitcoin retargets every 2,016 blocks, about two weeks, and limits each step to a factor of four. For a fork that keeps the parent’s difficulty but loses most of its hashrate, two weeks of blocks can take months.
Bitcoin Cash met this in August 2017. Its first specification kept the 2,016-block retarget and added an emergency rule (REQ-7): if the median time past of the tip was 12 hours or more after that of the block six back, the target rose by 25%, a 20% cut in difficulty. The rule could only lower difficulty between retargets, and hashrate moved back and forth between the two chains as difficulty swung. In November 2017 it was replaced by an adjustment over the last 144 blocks of chainwork, with the first and last blocks each chosen as the median of three to blunt single-timestamp manipulation and the timespan bounded to between 72 and 288 block intervals. In November 2020 that was replaced again by ASERT.
The lesson is not that one algorithm is right. It is that a rule which only fires in an emergency, and only in one direction, creates its own oscillation, and that the fork had to hard-fork twice more to get out of it.
Time warp
Bitcoin’s retarget measures the time between the first and the last block of each 2,016-block period, and consecutive periods do not overlap. A miner with most of the hashrate can keep timestamps low inside a period, so that blocks look slow, then stamp the last block of the period near the real time. The retarget sees a long period and lowers difficulty, while the first block of the next period can start back in the past. Repeated, this drives difficulty down while blocks come faster and faster.
The attack has been known since the early years of Bitcoin forks and is the reason two recent proposals add one rule. BIP 54 (Consensus Cleanup) requires the first block of a period to be no more than 7,200 seconds earlier than the block before it. BIP 94, the specification of Bitcoin’s testnet4, uses 600 seconds, and documents how a time warp amplified “block storms” on the old testnet together with its 20-minute minimum-difficulty exception.
Rolling-window algorithms do not have period boundaries, but they are not immune by default: they read timestamps that the miner chooses, inside the bounds that validation enforces. What matters is whether those bounds are tight relative to the window.
Timestamp limits sized for Bitcoin
Two rules bound a block’s timestamp. The past limit: it must be later than the median of recent blocks (11 in Bitcoin; Monero uses a 60-block check window). The future limit: it must not be more than a fixed time ahead of the node’s clock, two hours in both Bitcoin and Monero.
Two hours is 12 blocks at Bitcoin’s 10-minute target. At a 60-second target it is 120 blocks, longer than many DAA windows. A miner who stamps one block two hours ahead makes the latest solve time look enormous; a short window then cuts difficulty sharply for the blocks that follow, until honest timestamps catch up. Forks that shorten the block time and the window but keep the parent’s future limit inherit this.
target block time T = 60 s
future time limit FTL = 7200 s -> FTL / T = 120 blocks
averaging window N = 60 blocks
^ one block can claim a solve time
larger than the whole windowSMA, DigiShield, LWMA, ASERT
The algorithms forks most often choose differ in how they weigh recent blocks and in what they let timestamps do.
- Simple moving average (SMA)
- Average difficulty over N blocks times the target time, divided by the time the N blocks took. Every block in the window has the same weight, so a burst keeps its effect until it leaves the window N blocks later, and on-off mining produces a regular oscillation. The original CryptoNote algorithm is an SMA over 720 blocks that sorts timestamps and drops the 60 earliest and 60 latest, computed with a 15-block lag.
- DigiShield (Zcash variant)
- A 17-block averaging window measured between medians of past times, with the difference from the expected timespan damped by a factor of four and asymmetric limits (32% down, 16% up per step). Damping makes it stable and slow; the median lowers the effect of a single timestamp but adds delay.
- LWMA
- Linearly weighted moving average of solve times, so the newest block weighs N times the oldest. It responds faster than an SMA of the same window with less noise than a shorter SMA. Public implementations clamp each solve time, typically to six target times, and treat out-of-order timestamps explicitly.
- ASERT
- Absolutely scheduled exponential rise targets: difficulty depends only on a fixed anchor block and on how far the latest block is ahead of or behind the ideal schedule, with a half-life (two days on Bitcoin Cash mainnet). No window means no effect when an old block leaves it, and the schedule makes it hard to gain from timestamps without paying for it later.
next_target = anchor_target
* 2^((time_delta - T * (height_delta + 1)) / halflife)
time_delta = parent timestamp - anchor parent timestamp
height_delta = parent height - anchor height
halflife = 172800 s on mainnet (2 days)None of these is safe with the wrong parameters. A window or half-life that is short relative to the future time limit, a damping factor chosen for a large chain, or limits that are tighter in one direction than the other each reopen the problems above.
Arithmetic and activation
Targets are 256-bit integers. Retarget code typically multiplies the previous target by a timespan before dividing, and for chains whose proof-of-work limit is close to the top of the range that intermediate product can exceed 256 bits. Litecoin’s public pow.cpp carries a guard for exactly this, shifting the target right by one bit before the multiplication and back after. A fork that changes the proof-of-work limit or the timespan bounds should re-check the same path.
The other common source of trouble is the activation block. When a fork switches algorithm at a height, the first windows contain blocks mined by the parent’s hashrate under the parent’s rules. Without an explicit reset or warm-up, the new algorithm starts from a difficulty that the remaining hashrate cannot meet, and the chain stalls on its first day.
Pre-fork checklist
Eight checks we run on a difficulty change before anything else. Each one comes from a public failure above.
Timestamp bounds match your block timeDAA-01Consensus / fundsWrite down the past limit (median-time-past and its span) and the future limit in blocks, not seconds. A future limit worth more than a small fraction of your averaging window lets one forward-dated block move difficulty. Peer-time adjustment, if your fork still has it, must stay below the future limit.
No time warp between periodsDAA-02Consensus / fundsIf difficulty is computed over fixed, non-overlapping periods, constrain the first timestamp of each period against the last one of the previous period (BIP 54 uses 7200 seconds, BIP 94 uses 600). With a rolling window, check that the timestamps the algorithm reads are the ones the validation rules bound.
Negative and out-of-order solve times are handled symmetricallyDAA-03Consensus / fundsClamping negative solve times to zero, or to one second, while leaving long ones unclamped lets an attacker alternate forward-dated and honest timestamps so that the gaps count and the corrections do not. Test the algorithm with out-of-order timestamps, not only with monotonic ones.
The window warms up after the fork heightDAA-04Liveness / DoSOn the first blocks after activation the window still holds the parent chain’s difficulty and timestamps. Decide explicitly: a reset to a fixed difficulty, a shorter warm-up window, or the old algorithm until the window is full. Then mine through it on a test network with the hashrate you actually expect.
Target arithmetic cannot overflow or round the wrong wayDAA-05Consensus / fundsMultiply before you divide, but check the 256-bit intermediate against the proof-of-work limit; Litecoin ships an explicit guard for this. Round-trip every result through the compact
nBitsencoding and compare every implementation that computes it.
Test-network rules are off on mainnetDAA-06Consensus / fundsMinimum-difficulty exceptions, emergency rules and retarget shortcuts copied from test parameters must be disabled for mainnet in chain parameters, and covered by a test that fails if someone flips them.
Every implementation agreesDAA-07Consensus / fundsThe node, any second client, pool software that validates templates and the explorer must compute the same difficulty for the same history. Publish test vectors (BCH’s upgrade specifications do) and run them in every codebase.
Parameters were chosen under attack, not at steady stateDAA-08Liveness / DoSReplay hashrate spikes, on-off mining, a lasting hashrate cliff and forward-dated timestamps against your candidate algorithm and window before you freeze them. The difficulty simulator does this in the browser.
Sources
Public documents only, checked on 3 Dec 2026. No client work, private report or undisclosed issue is used or referred to on this page.
- Bitcoin Core, src/pow.cpp (retarget and proof-of-work checks)
- BIP 54: Consensus Cleanup (timewarp fix, 7200-second rule)
- BIP 94: Testnet 4 (block storms, 600-second timewarp rule)
- Bitcoin Cash UAHF specification, REQ-7 emergency difficulty adjustment
- Bitcoin Cash November 2017 upgrade: 144-block difficulty adjustment
- Bitcoin Cash November 2020 upgrade: ASERT (aserti3-2d)
- Zcash, src/chainparams.cpp and src/pow.cpp (averaging window, damping, limits)
- Monero, src/cryptonote_config.h (difficulty window, cut, lag, future time limit)
- Litecoin, src/pow.cpp (intermediate uint256 overflow guard)
- zawy12, difficulty-algorithms: LWMA and public DAA analyses