<p>Nothing directly prevents it in Bitcoin, and indeed the attack has been demonstrated on testnet3 many times---it's the primary reason that testnet3 currently has almost three times as many blocks as Bitcoin, despite being launched several years after Bitcoin mainnet and with a something similar to[1] Bitcoin's 10-minute average block interval.</p>

<p>Indirectly, there are several reasons the time warp attack is less practical on Bitcoin mainnet than testnet3 or altcoins like Verge:</p>

<ol>
<li><p><strong>Obvious:</strong> once blocks used in a time-warp attack are broadcast, anyone can see that median-time-past (the monotonic clock in Bitcoin) is lagging far behind real time.</p></li>
<li><p><strong>Slow:</strong> the time warp attack exploits the formula used for retargeting, but retargeting only runs once every 2,016 blocks (two weeks at normal rate) and can only reduce difficulty by a maximum of 75% per period.  Now, 75% is a lot, but so is spending two weeks executing a publicly-visible attack.  Further difficulty decreases can be executed faster due to the modified difficulty, but they're still pretty slow: 3.5 days for the second retarget; about 1 day for the third; about 6 hours for the fourth; etc...</p></li>
<li><p><strong>Easily fixable by miners:</strong> if honest miners control the majority of the hashrate, they can simply refuse to build on top of blocks whose timestamps are too far in the past.  If median-time-past is restored to its normal trailing average before the end of the initial 2,016-block retarget period, difficulty won't be changed any more than normal.</p></li>
</ol>

<p>If all these reasons do indeed provide indirect mitigation, then why do we see the attack on testnet3 every few months?  Mainly because testnet3 uses the same SHA256d proof of work function as Bitcoin and so anyone who wants to mine blocks really quick can hook up some modern ASIC miners to create a bunch of testnet blocks quickly.  This would normally rapidly increase difficulty, but the increase is prevented using the time warp attack.  That said, in at least one case in the past where a time warp attacker made testnet3 unusable for an extended amount of time, some generous person pointed their own huge mining rig at testnet3 to overwhelm the attacker and bring difficulty back up.</p>

<p>On Bitcoin mainnet, if the attack was ever executed, I think the story would be different.  Within days, a large percentage of the userbase would know the attack was ramping up and would start to pressure honest miners to reject the attacker's blocks.  I personally expect miners would comply (as the next step would be for people to start throwing around phrases like "PoW function change"), which would defeat the attacker and cost him expected revenue for every rejected block.</p>

<p>If attackers expect the scenario would play out basically the same way I think it would, then there's no point in them starting the attack in the first place---which I think is what ultimately prevents time warp attacks on Bitcoin.</p>

<p>[1] Testnet3, unlike Bitcoin, has a rule that if no block has been mined within 20 minutes (according to block header time), that a miner can create a difficulty-1 block (the lowest difficulty).  That means that even completely honest mining on testnet3 is faster than on mainnet, as on mainnet something like 20% of blocks take longer than 20 minutes to find.</p>

<hr>

<p>Some extra notes:</p>

<ol>
<li><p>A fork could change the retarget calculation to use median-time-past instead of raw block header time.  This could fix the time warp attack on Bitcoin, but it would probably have to be a hard fork.</p></li>
<li><p>Since the <a href="https://github.com/bitcoin/bips/blob/master/bip-0113.mediawiki" rel="nofollow noreferrer">BIP113</a> soft fork, median-time-past has been used to restrict which nLockTime transactions miners can include in their blocks.  Not many transactions use nLockTime with a time at present, but if there was a time warp attack, users could start doing so to create a large fee incentive for miners to bring median-time-past closer to real time.</p></li>
</ol>

CC BY-SA 4.0
2018-05-23T00:12:24.637Z
It's interesting that most of these defenses are social rather than technical. It depends on majority of miners not colluding.
Karel Bílek
CC BY-SA 4.0
2018-05-23T00:49:45.423Z
@KarelBílek: If a majority (>50%) of miners are colluding, then you've already lost.
Kevin
CC BY-SA 4.0
2018-05-23T05:59:29.490Z
Also, on testnet3, due to a quirk of how the difficult readjustment works, if the last block in a retarget period takes longer than 20 minutes to find, it will not only reset that block's difficulty to 1 but all blocks for the next retarget period will also have a difficulty of 1. That makes testnet3 easily gameable to have a very low difficulty.
Ava Chow
CC BY-SA 4.0
2018-10-03T09:48:30.700Z
@David A. Harding.  In this sentence:  "Further difficulty increases can be executed faster due to the modified difficulty", do you mean “decreases”  or the generic “changes” rather than "increases" ?
dbkeys
CC BY-SA 4.0
2018-10-03T11:04:57.490Z
@dbkeys fixed, I meant "decreases".  Thanks.
David A. Harding
CC BY-SA 4.0
2018-05-22T23:36:17.010Z
2018-10-03T11:04:25.517Z
2018-10-03T11:04:25.517Z
David A. Harding
<p>Right now (may 2018), Verge (an altcoin with proof of work)  was attacked by time-warp attack. More can be read here</p>

<p><a href="https://blog.theabacus.io/the-verge-hack-explained-7942f63a3017" rel="noreferrer">https://blog.theabacus.io/the-verge-hack-explained-7942f63a3017</a></p>

<p>What exactly prevents from similar attack to happen to Bitcoin? </p>

<p>Verge has different hash logic (more frequent retarget, more concurrent hash algorithms), but the logic of the attack should, in my reading, apply also to bitcoin. </p>

<p>Since it did never happen in Bitcoin, I probably missed something. How is Verge different from Bitcoin that this happened in Verge, but not in bitcoin? </p>

<proof-of-work><attack><timestamp><time-warp-attack>
What prevents similar time-warp attacks in Bitcoin as happened to Verge?
Karel Bílek
# What prevents similar time-warp attacks in Bitcoin as happened to Verge?

(Asked by: username_0 on 2018-05-22)

Right now (may 2018), Verge (an altcoin with proof of work) was attacked by time-warp attack. More can be read here

<https://blog.theabacus.io/the-verge-hack-explained-7942f63a3017>

What exactly prevents from similar attack to happen to Bitcoin?

Verge has different hash logic (more frequent retarget, more concurrent hash algorithms), but the logic of the attack should, in my reading, apply also to bitcoin.

Since it did never happen in Bitcoin, I probably missed something. How is Verge different from Bitcoin that this happened in Verge, but not in bitcoin?

**Tags:** proof-of-work, attack, timestamp, time-warp-attack


---

## 1 answers

### Answer by username_1 on 2018-05-22. Score: 10 | Accepted answer

Nothing directly prevents it in Bitcoin, and indeed the attack has been demonstrated on testnet3 many times---it's the primary reason that testnet3 currently has almost three times as many blocks as Bitcoin, despite being launched several years after Bitcoin mainnet and with a something similar to[1] Bitcoin's 10-minute average block interval.

Indirectly, there are several reasons the time warp attack is less practical on Bitcoin mainnet than testnet3 or altcoins like Verge:

1. **Obvious:** once blocks used in a time-warp attack are broadcast, anyone can see that median-time-past (the monotonic clock in Bitcoin) is lagging far behind real time.
2. **Slow:** the time warp attack exploits the formula used for retargeting, but retargeting only runs once every 2,016 blocks (two weeks at normal rate) and can only reduce difficulty by a maximum of 75% per period. Now, 75% is a lot, but so is spending two weeks executing a publicly-visible attack. Further difficulty decreases can be executed faster due to the modified difficulty, but they're still pretty slow: 3.5 days for the second retarget; about 1 day for the third; about 6 hours for the fourth; etc...
3. **Easily fixable by miners:** if honest miners control the majority of the hashrate, they can simply refuse to build on top of blocks whose timestamps are too far in the past. If median-time-past is restored to its normal trailing average before the end of the initial 2,016-block retarget period, difficulty won't be changed any more than normal.

If all these reasons do indeed provide indirect mitigation, then why do we see the attack on testnet3 every few months? Mainly because testnet3 uses the same SHA256d proof of work function as Bitcoin and so anyone who wants to mine blocks really quick can hook up some modern ASIC miners to create a bunch of testnet blocks quickly. This would normally rapidly increase difficulty, but the increase is prevented using the time warp attack. That said, in at least one case in the past where a time warp attacker made testnet3 unusable for an extended amount of time, some generous person pointed their own huge mining rig at testnet3 to overwhelm the attacker and bring difficulty back up.

On Bitcoin mainnet, if the attack was ever executed, I think the story would be different. Within days, a large percentage of the userbase would know the attack was ramping up and would start to pressure honest miners to reject the attacker's blocks. I personally expect miners would comply (as the next step would be for people to start throwing around phrases like "PoW function change"), which would defeat the attacker and cost him expected revenue for every rejected block.

If attackers expect the scenario would play out basically the same way I think it would, then there's no point in them starting the attack in the first place---which I think is what ultimately prevents time warp attacks on Bitcoin.

[1] Testnet3, unlike Bitcoin, has a rule that if no block has been mined within 20 minutes (according to block header time), that a miner can create a difficulty-1 block (the lowest difficulty). That means that even completely honest mining on testnet3 is faster than on mainnet, as on mainnet something like 20% of blocks take longer than 20 minutes to find.

---

Some extra notes:

1. A fork could change the retarget calculation to use median-time-past instead of raw block header time. This could fix the time warp attack on Bitcoin, but it would probably have to be a hard fork.
2. Since the [BIP113](https://github.com/bitcoin/bips/blob/master/bip-0113.mediawiki) soft fork, median-time-past has been used to restrict which nLockTime transactions miners can include in their blocks. Not many transactions use nLockTime with a time at present, but if there was a time warp attack, users could start doing so to create a large fee incentive for miners to bring median-time-past closer to real time.

> **Comments:**
> **username_0**: It's interesting that most of these defenses are social rather than technical. It depends on majority of miners not colluding.  
> **username_2**: @username_0: If a majority (>50%) of miners are colluding, then you've already lost.  
> **username_3**: Also, on testnet3, due to a quirk of how the difficult readjustment works, if the last block in a retarget period takes longer than 20 minutes to find, it will not only reset that block's difficulty to 1 but all blocks for the next retarget period will also have a difficulty of 1. That makes testnet3 easily gameable to have a very low difficulty.  
> **username_4**: @username_1.  In this sentence:  "Further difficulty increases can be executed faster due to the modified difficulty", do you mean “decreases”  or the generic “changes” rather than "increases" ?  
> **username_1**: @username_4 fixed, I meant "decreases".  Thanks.  

---

