Bitcoin Institute

Bitcoin's time-warp attack — the difficulty bug still in Satoshi's code, and the Great Consensus Cleanup (2024–2026)

Figures: Satoshi Nakamoto

Dark navy diagram titled "The time-warp gap": three retarget windows side by side, each measured from its first block to its last, with the last block's time jumping up to real time. Between the windows, dashed lines marked "not measured" show the next window's first block going back into the past. A small chart shows difficulty falling after the second retarget.

Bitcoin’s difficulty-adjustment algorithm contains a long-known off-by-one bug in Satoshi’s original code. The retarget window is documented as 2,016 blocks — two weeks at 10-minute block intervals — but the code that computes the elapsed time measures from the first block to the last block of each window: 2,015 intervals, not 2,016. And because each window is timed only from its own first block, the interval between one window’s last block and the next window’s first block is never measured at all. The bug is small, the consequences are not.

1 How the attack works

If miners holding a majority of the hashrate collude, they can carry out the attack shown in the diagram below. A block’s time must exceed the median of the previous eleven, but a single outlying timestamp on the last block of a window does not move that median, so the rule is never broken. Difficulty stays the same at the first retarget but falls at the second and at every one after it, so the colluding majority ends up finding blocks faster than one every ten minutes without adding any hashrate.

The attack is not free or instant. According to published descriptions, an attacker would need to hold a majority of the hash rate for roughly four weeks before the attack did meaningful damage. Four weeks is long enough for the rest of the network to notice any real attempt well before difficulty falls. That is the main reason the bug has stayed unfixed for so long: it can be exploited in principle but is expensive in practice, and a majority able to coordinate that openly would have easier and more profitable ways to cause trouble than gaming the retarget window.

2 How the bug got into Satoshi’s code

The v0.1.0 source — preserved in trottier/original-bitcoin’s pinned src/main.cpp at commit 4184ab2, lines 685–707 — shows that the bug was present from the initial release in January 2009. The loop that walks the previous retarget window starts at the latest block and counts back 2,015 entries, then takes the time difference between the block it lands on and the current block. The intent was clearly to span 2,016 blocks; the implementation spans 2,015. There is no surviving evidence that Satoshi was aware of the discrepancy.

On September 12, 2011, ArtForz explained on BitcoinTalk how to exploit the bug: because retargeting ignores one block interval every period, an attacker’s fork chain can “jump backwards in time” and create a large number of low-difficulty blocks. He ended the post with a reference to GeistGeld, an alternative currency: “This was done on the GeistGeld chain yesterday/today, so it’s not a theoretical problem.” A Bitcoin Optech newsletter in October 2018 described the attack as well known among experts and noted that it had been used in demonstration attacks against Bitcoin’s testnet and in real attacks against altcoins.

3 The Great Consensus Cleanup

Antoine Poinsot has championed a soft-fork proposal known as the Great Consensus Cleanup that bundles a fix for the time-warp bug with several other long-known protocol curiosities. The proposal would constrain the timestamp of the first block of each retarget window so that the off-by-one cannot be exploited regardless of hashrate share. As of 2026 the proposal remains in active community discussion: several Bitcoin Core developers support it, but miners and node operators have not lined up behind it the way they did behind SegWit and Taproot before those upgrades activated.

The difficulty-adjustment section of this site’s page on Bitcoin’s consensus design lists two flaws that remain in the original code: the time-warp vulnerability that this proposal targets, and a small bias that arises because each retarget window measures 2,015 intervals instead of 2,016. The other flaws developers found in Satoshi’s code are set out in “Where Developers Said Satoshi Was Wrong”.

The pace of activation reflects Bitcoin’s institutional caution. Soft-fork changes to the consensus rules require both broad developer agreement and clear miner / node-operator readiness, and the bar for a “cleanup” fork — one that does not deliver any new user-facing feature — is higher than for capability-adding forks. As a result, a known but costly-to-exploit bug has been left alone: nobody has wanted to push through a fork just to close an attack that has never been used on Bitcoin’s main network.

4 What the bug shows

The time-warp bug shows that Satoshi’s original code is still running: a piece of mainnet logic, seventeen years old, that nobody is in a hurry to touch. It illustrates both the resilience of Bitcoin’s design (a real bug that has not threatened the chain) and the conservatism that defines its protocol-evolution culture (no rush to fix what has not broken). Satoshi’s consensus code has been fixed by a soft fork before: in the 2010 value-overflow incident, the bug was patched within hours of discovery. If the Great Consensus Cleanup activates, it will stand out for the opposite reason: it will be a careful fix, years in the making, for a latent flaw that has never been exploited on Bitcoin’s main network, not an emergency response to an attack already under way.