What is a timewarp attack and how does it affect the mining difficulty?

When thinking about possible attacks on the Bitcoin network, the first thing that comes to mind is the 51% attack, in which a group of miners holds the majority of the network hashrate, so as to be able to carry out double spending. However, another less known but equally dangerous threat is the timewarp attack.

Changing the timestamp

In simple terms, a timewarp attack occurs when a miner manages to put an incorrect timestamp into the blocks in order to reduce the subsequent mining difficulty.

In fact, some cryptocurrencies such as bitcoin, periodically update the difficulty in relation to the block generation rate, so that the latter remains at the default value, which for Bitcoin is an average time of 10 minutes per block.

By inserting wrong timestamps a miner can deceive the algorithm that deals with adjusting the difficulty pushing it to lower its value, causing the extraction of blocks to become faster and therefore more profitable. This has negative effects on the economy of a cryptocurrency since a timewarp attack increases the inflation rate of the currency.

If we look at the Bitcoin source code, we can see that a block can have an incorrect timestamp up to a maximum of 2 hours beyond the actual time. If this limit is exceeded, the block is automatically rejected.

This margin is designed to take account of any errors in the internal clocks of computers

There have been numerous cases in Bitcoin’s history where a block had a higher timestamp than the next block’s timestamp, especially in the early years of the coin’s life, when the network’s total hashrate was very low.

But is this type of attack so easy to carry out?

The 2-hour margin for block timestamps is what actually paves the way for malicious attacks. However, it is not as easy as it may seem.

For Bitcoin, in fact, it would be very difficult to conduct a significant timewarp attack, since it would immediately become public knowledge on the blockchain. Moreover, in order for the attack to be completely successful, it would still need the majority of the hashrate which at present is almost impossible on Bitcoin.

However, there is another remote possibility. If the majority of the miners were to join forces, they could theoretically progressively reduce the difficulty of mining with continuous timewarp attacks. They could even go as far as reducing the extraction time of a block to just one second, which is the minimum possible extraction time for a block.

A remote hypothesis for Bitcoin

In any case, it is very unlikely that the Bitcoin miners will cooperate with each other and carry out a timewarp attack, since the entire ecosystem would be damaged.

The major mining farms have invested millions of dollars in dedicated infrastructure, and the damage to the ecosystem caused by such an attack would frustrate their investment.

However, for some cryptocurrencies, it is much easier to perform a timewarp attack.

For example, Verge continually recalculates the difficulty of mining, unlike Bitcoin which adjusts the difficulty once every 2 weeks. So, in the event of an attack, there is much more time to start a chain mechanism that allows generating blocks more quickly. In addition, Verge uses multiple mining algorithms, resulting in multiple fronts of attack.

The possible solution to the timewarp attack

This remote attack scenario has created a lot of discussion in the Bitcoin community over the years.

One of the developers of Bitcoin Core, Johnson Lau, proposed an easy additional check. A simple check that does not allow a block to have a lower timestamp than the block that precedes it. However, since this modification could lead to a fork, the solution has not yet been considered.

Greg Maxwell, co-founder of Blockstream and one of the most important developers of Bitcoin said:

“I, and I assume others, haven’t put a big priority into fixing this vulnerability because it requires a majority [of mining] hashrate and could easily be blocked if someone started using it. In the case where one group of miners were to collect most of the hashrate, a timewarp attack would be the least of bitcoin’s worries“.