What is a "Time Warp Attack"?

This article is machine translated
Show original

The first part of the text is a response by David A. Harding on the Bitcoin Stack Exchange Q&A site, explaining the "time warp attack". The time warp attack is a weakness at the consensus layer that the "Great Consensus Cleanup" soft fork proposal attempts to address. However, on the testnet 4 where the consensus cleanup soft fork was applied, developer Zawy found a similar attack. The second part is an introduction by murch on the Delving Bitcoin forum about this attack method and his recommended mitigation.

Time Warp Attack

Original link: https://bitcoin.stackexchange.com/questions/75831/what-is-time-warp-attack-and-how-does-it-work-in-general/75834#75834

Author: David A. Harding

The Bitcoin protocol (consensus rules) has two relevant rules regarding the timestamp in the Block header:

  1. Nodes will not accept a Block with a timestamp more than 2 hours ahead of their local time.
  2. A Block's timestamp must be greater than the median of the previous 11 Blocks, which is a requirement for it to be accepted by nodes. This rule is called the "Median Time Past (MTP)".

As you mentioned in your question, the change in mining difficulty is calculated based on the difference between the timestamp of the first and last Blocks in a 2016 Block difficulty adjustment period.

Given the above rules, if all miners act in collusion, they can, in the first 2015 Blocks of a period, advance the timestamp of each Block by only 1 second (the minimum increment allowed by the MTP rule) compared to the previous Block. This would only result in a slight decrease in difficulty, but imagine when they set the timestamp of the last Block slightly ahead of the current real time: the median would not change at all.

Real timestamps are in seconds, but here we'll use days to represent a set of 11 timestamps centered around the current time:

[-13, -13, -13, -13, -13, -13, -13, -13, -13, -13, 0]

Note: The "-13" means these timestamps represent a time 13 days in the past.

So, the median of these 11 Block timestamps is still -13, meaning that in the last Block of the difficulty adjustment period, when the miners use a timestamp slightly ahead of the current time, going forward they don't need to advance the timestamp more than 1 second - the first Block of the next difficulty period can use the -13 timestamp, effectively starting that period 13 days in the past.

At the end of this second difficulty adjustment period, the miners can again push the timestamps as far forward as possible, so the protocol will think it took 28 days to mine all the Blocks in that period - only half the expected rate - and will therefore halve the mining difficulty for the next period.

At this point, the values used in the MTP rule would look like this:

[-27, -27, -27, -27, -27, -27, -27, -27, -27, -27, 0]

The miners can repeatedly execute this attack (pushing the timestamps of the early Blocks in a period as far back as possible, and the last Block's timestamp as far forward as possible), continually reducing the difficulty, until they can mine 2016 Blocks in less than 2016 seconds, at which point they can no longer lower the difficulty further (because the MTP requires each Block's timestamp to advance by at least 1 second).

Your main question was how this attack could be possible without collusion among the majority of miners. Now you can see how it is possible when all miners are colluding. You should be able to see that the choice of timestamps allows a sufficiently lucky attacking miner to reliably prevent the median time from jumping to an honest value.

For example, imagine the timestamps of the previous 11 Blocks were:

[-27, 0, -27, 0, -27, 0, -27, 0, -27, 0, -27]

If you sort these timestamps and find the median, you'll see the median is -27, even if 5/11 (45%) of the hash power is honestly mining. But doesn't this mean the attacking miner still needs 55% of the hash power? Maybe not - a large miner with over 30% hash power could use a "selfish mining" attack to gain an advantage, or that miner could directly threaten to orphan Blocks with honest timestamps, forcing honest miners to earn less revenue.

Personally, I don't think this attack is very likely to occur on Bitcoin, as it is slow to execute and very visible, but designers of other protocols may want to keep an eye on parameter changes that could make such attacks easier to execute.

Zawy's Alternating Timestamp Attack

Original link: https://delvingbitcoin.org/t/zawy-s-alternating-timestamp-attack/1062

Author: murch

@zawy yesterday introduced an attack in the Testnet 4 PR. I'll try to explain my understanding of it.

Similar to the time warp attack, this attack requires the attacker to be able to choose the timestamps of the majority of Blocks, but unlike the time warp attack, it does not rely on the difficulty adjustment periods not aligning (the off-by-one error). This attack appears theoretically viable, although it would require 16 weeks of selfish mining (and possibly 50% hash power as a prerequisite), which should make it impractical.

The basic idea of this attack is to lock in the timestamps of the vast majority of Blocks, but alternate between placing timestamps representing the future and the past on the last Block of each difficulty adjustment period, thereby oscillating between maximally lowering and raising the difficulty. This hot and cold cycle allows the attacker to produce many more Blocks than the expected output of honest miners in the same time period.

Specifically, the attacker does the following:

  1. The attacker first pushes the timestamps as far back as possible. In the initial description, the timestamps only advanced 1 second per Block, but timestamps only need to advance every 6 seconds. The miners control a slight majority of hash power, so we expect Blocks to appear about every 20 minutes. Let's assume the Block rate is constant within a difficulty period for simplicity: 'Bit' must be translated into 'Bit'. 'Block' must be translated into 'Block'. 'Consensus' must be translated into 'Consensus'. 'TRON' must be translated into 'TRON'. 'Amp' must be translated into 'Amp'. 'BTC' must be translated into 'BTC'. 'HT' must be translated into 'HT'. 'ENS' must be translated into 'ENS'. 'AR' must be translated into 'AR'. 'XCH' must be translated into 'XCH'. 'AMP' must be translated into 'AMP'. 'RON' must be translated into 'RON'. 'ONG' must be translated into 'ONG'.

    LabelHeightMTP [s]Timestamp [s]Actual Time ElapsedDifficulty
    Start0< 000D
    1< 0020 minD
    2< 0040 minD
    3< 0060 minD
    6012 hD
    12124 hD
    The attacker sets the timestamp of the last block of the difficulty adjustment period to 8 weeks after the attack start date. This block will not be accepted by other nodes, as it is more than two hours ahead of the local time of the nodes, so the attacker will be temporarily forked out of the network here. However, this future timestamp allows the attacker to reduce the difficulty of the next period to 1/4 of the current period. The timestamp of the first block of the second difficulty adjustment period also needs to be set to 8 weeks after the attack start date, to meet the requirements of the consensus cleanup proposal.
    LabelHeightMTP [s]Timestamp [s]Actual Time ElapsedDifficulty
    Start0< 000D
    20143353364 weeks - 40 minD
    20153358 w4 weeks - 20 minD
    20163368 w4 weeksD/4
    The attacker continues to mine in the second difficulty period, pushing the timestamp forward as little as possible, and again pushes the timestamp of the last block forward by another 8 weeks, further reducing the difficulty by a factor of 4. Since the attacker controls about half the hash power, it takes 4 weeks to complete the first difficulty period, but only 1 week for the second difficulty period.
    LabelHeightMTP [s]Timestamp [s]Actual Time ElapsedDifficulty
    Start0< 000D
    1< 001200D
    20143353364 weeks - 40 minD
    20153358 w4 weeks - 20 minD
    20163368 w4 weeksD/4
    20173363374 weeks + 5 minD/4
    20183363374 weeks + 10 minD/4
    40306716725 weeks - 10 minD/4
    403167116 w5 weeks - 5 minD/4
    403267216 w5 weeksD/16
    40336726735 weeks + 75 secD/16
    Zawy also mentions that the attacker can switch between setting the smallest possible timestamp and the largest possible timestamp for the last block of the difficulty adjustment. This can result in some difficulty adjustment periods having a nominal elapsed time of a negative number. However, the difficulty adjustment algorithm will treat this as half a week having elapsed, and still only increase the difficulty by a factor of 4. Even with the new constraint from the consensus cleanup proposal (not allowing the timestamp of the first block of the next difficulty period to be earlier than the last block of the previous period), the attacker can still switch between 1/4 and 1/16 of the starting difficulty. The attacker can complete two difficulty periods every 5/4 weeks.

    LabelHeightMTP [s]Timestamp [s]Actual elapsed timeDifficulty
    Start0< 000D
    1< 001200D
    20143353364 weeks - 40 minutesD
    20153358 w4 weeks - 20 minutesD
    20163368 w4 weeksD/4
    20173363374 weeks + 5 minutesD/4
    20183363374 weeks + 10 minutesD/4
    40306716725 weeks - 10 minutesD/4
    403167116 w5 weeks - 5 minutesD/4
    403267216 w5 weeksD/16
    40336726735 weeks + 75 secondsD/16
    6047100710085 w 42 h - 75 sD/16
    6048100810095 w 42 hD/4
    6049100810095 w 42 h + 5 minD/4
    8063134313446 w 42 h - 5 minD/4
    8064134416 w6 w 42 hD/16
    8065134416 w6 w 42 h + 75 sD/16
    10079167916806 w 84 h - 75 sD/16
    10080168016816 w 84 hD/4
    10081168016816 w 84 h + 5 minD/4
    12095201520167 w 84 h - 5 minD/4
    12096201616 w7 w 84 hD/16
    12097201616 w7 w 84 h + 75 sD/16
    Once the actual elapsed time reaches 16 weeks, the attacker can publicly reveal the chain they have secretly mined, and (according to the assumption) their cumulative work will be slightly higher, thereby invalidating the 16-week transaction activity on the public network, reorganizing approximately 8064 blocks, and obtaining approximately 39816 block rewards, and may receive more transaction fees than on the public network, as they can package all non-conflicting transactions that have been broadcast during the slow block period on the public network.

    labelheightMTP [s]timestamp [s]elapsed time [s]difficulty
    start0< 000D
    1< 001200D
    2< 002400D
    3< 003600D
    6017200D
    121214400D
    20143353364 w − 40 minD
    20153358 w4 w − 20 minD
    2nd diff period20163368 w4 wD/4
    20173363374 w + 5 minD/4
    20183363374 w + 10 minD/4
    40306716725 w − 10 minD/4
    403167116 w5 − 5 minD/4
    3rd diff period403267216 w5 wD/16
    40336726735 w + 75 sD/16
    6047100710085 w 42 h − 75 sD/16
    6048100810095 w 42 hD/4
    6049100810095 w 42 h + 5 minD/4
    8063134313446 w 42 h − 5 minD/4
    806413448 w6 w 42 hD/16
    806513448 w6 w 42 h + 75 sD/16
    10079167916806 w 84 h − 75 sD/16
    10080168016 w6 w 84 hD/64
    10081168016 w6 w 84 h + 19 sD/64
    1209520152016D/64
    1209620162017D/16
    1209720162017D/16
    1411123512352D/16
    1411223528 wD/64
    1411323528 wD/64
    1612726872688D/64
    16128268816 wD/256
    16129268816 wD/256
    1814330233024D/256
    1814430243025D/64
    1814530243025D/64

    This not only allows attackers to create more blocks, but also exponentially reduces the difficulty.

    Conclusion

    It may be useful to impose additional requirements on the timestamp for the soft fork, requiring the timestamp of the last block in a difficulty period N to be greater than the first block in the same period. That is, to require:

    $$n ∈ ℕ; timestamp_{2016×n} < timestamp_{2016×n+2015}$$

    I do not believe that honest mining advancing the timestamp (at least one second, which is indirectly caused by the existing MTP rule) across difficulty periods will conflict with this rule, unless the timestamp is manipulated as extremely as described above. However, to my knowledge, such a rule should be able to reduce this attack surface.

Source
Disclaimer: The content above is only the author's opinion which does not represent any position of Followin, and is not intended as, and shall not be understood or construed as, investment advice from Followin.
Like
Add to Favorites
1
Comments