Timewarp attack
Timewarp is an exploit of Bitcoin's difficulty adjustment
algorithm that allows miners controlling a large amount of
hashrate to increase how fast blocks are mined. The
attack could render the network non-viable with 6 blocks per
second, mine the remaining subsidy, and impact the
ability of users to run a full node.
Bitcoin adjusts mining difficulty every 2,016
blocks to maintain an average 10-minute block time.
However, the current difficulty adjustment compares
the timestamps of the first and last block of a period,
a span that covers only 2,015 block intervals. This creates an "off-by-one"
bug: the first block of a difficulty adjustment
period is different from the last block of the previous
period. Miners exploiting the timewarp attack manipulate
this gap by: This timestamp manipulation makes each period
appear to have taken longer than it actually did,
causing difficulty to decrease. The attack can be
repeated indefinitely with a compounding effect,
progressively reducing difficulty to its minimum value. Once difficulty reaches the minimum, a majority
of hashrate could mine blocks as fast as the Median
Time Past rule allows which is approximately six
blocks per second. At this rate: BIP54 prevents timewarp attacks by requiring a
minimum timestamp for the first block in a
difficulty period based on the timestamp of its
predecessor, the last block of the prior difficulty
period. This restriction on shifting the start of a
difficulty period precludes the timestamp
manipulation across period boundaries necessary for
the timewarp attack. The fix also includes a two-hour grace period
after each difficulty adjustment to accommodate
natural timestamp variation. The Murch-Zawy
timewarp variant circumvents the above
rule by setting the end timestamps of 2 difficulty
periods several weeks into the future to achieve a
greater decrease in difficulty by the time the chain
is accepted. To ensure the chain is eventually
accepted by the wider network and doesn't always
have timestamps too far in the future, this attack
has to alternate with 1 difficulty period which is
closer to the real time, thereby increasing the
difficulty momentarily. It therefore takes longer to
drain the subsidy. BIP54 also addresses this variant through
requiring that the timestamp of the last block in a
difficulty period must be greater than (or equal to)
the timestamp of the first block in the same
period. Since in any case, nodes will follow the chain
with most cumulative PoW, the attacks above both
require 51% control of hashrate. Even if blocks were
produced at a higher rate in one fork, the
preference for highest cumulative PoW still imposes
this constraint on an attacker. These new rules
limit the damage that can be inflicted, should an
attacker control 51% of the hashrate during a few
weeks/months. Read more: "The
timewarp attack" from BitMEX ResearchTechnical details and fix
How the attack works
Impact
nLockTime,
OP_CHECKLOCKTIMEVERIFY or
OP_CHECKSEQUENCEVERIFY providing a
stable measure of time. Accelerated block
production would cause timelocks to expire much
faster than intended, potentially allowing theft
of fundsBIP54's fix
Variants