The BTG blockchain uses an LWMA (a Linearly Weighted Moving Average of the last 45 blocktimes) for our DAA (Difficulty Adjustment Algorithm) after every block. This means difficult is adjusted quickly to compensate for recent block speed changes due to fluctuating amounts of hashpower.
I had been running simulations lately, and realized I had the tools to answer a curiosity question I’ve had in the past: if an attacking miner has more hashpower than the honest miners, how far ahead can they get, in terms of block count?
Obivously, with double the hashpower, they’ll produce blocks at double speed - every five minutes, instead of every ten. But the DAA will raise the difficulty, which will slow the attacker down, and they won’t get infinitely far ahead. How far ahead WILL they get?
In 1000 minutes, our normal blockchain would mine about 100 blocks. With double that hashpower, we won’t get 200 blocks… but will we get 160 blocks, to be ahead of mainchain by 60 blocks? Or will it be only 130 blocks, to be ahead by 30? I didn’t have a solid guess, but some back-of-the-envelope math suggested it would be even smaller. But how much smaller?
And if I kept running for several thousand minutes, just how far ahead would it get before the lead stopped growing?
So I simulated 100,000 runs with 2x, 4x, 8x, 16x, and 32x the mainchain’s hashpower… and, just for fun, x/2 as well. Here’s the resulting chart:
As you can see, the red line - Mainchain - averages at 1 block per 10 minutes, as expected (so, 100 blocks are reached at 1000 minutes, etc.) With more hashpower, more blocks are found, but it’s obvious that the gain happens quite quickly, in the initial few hundred minutes, and that after that, all the blockchains proceed at the same pace.
Here’s that same data, but instead of block counts, I’m presenting how far ahead of (or behind) mainchain we are for each hashpower multiple:
Remarkably, with double the mainchain’s hashpower, an attacker doesn’t even get 15 blocks ahead, on average! (it tops out at 14.9), and most of that lead is gained in the first few hours before it stops growing. Even with 32 times the mainchain’s hashpower, an attacker gets ahead by less than 60 blocks before they stop making any progress on their “lead.”
Let’s zoom in on the first 500 minutes to see more detail.
This is the same data, but you can more clearly see how quickly the DAA is adjusting to the change in hashpower.
Note: these are the AVERAGES of 100,000 runs. The variance from run to run can be quite high.
Inspection of the numbers shows that most of the speed advantage is lost in the first 45 blocks, and it’s nearly all gone in the first 90 blocks - which makes sense. That’s twice the 45-block averaging window. After 135 blocks, an advantage is difficult to detect at all.
But, of course, the time it take to get to 45 blocks is different at every power multiple! Here, the dots show where each multiple reached rouhgly 45 blocks:
(The 1/2 power chain would have gotten there at around 620 or 630 minutes.)
I suppose the 45-block point is more obvious on the other chart, where we can just draw a straight line across the chart at 45 blocks:
I thought some people might find this interesting, like I did.