Bounds on chain length with BIP-54 timewarp fixes

If we define:

  • P = (n-1)/2016, periods in the chain
  • T = t / (3600 \cdot 24 \cdot 14), intended periods for amount of time
  • D = w / (2^{32} + 2^{16}), total summed difficulty

Then the following holds:

D \;\geq\; \begin{cases} A\left[\left(\dfrac{T}{P}+C\right)^{\!-P}-1\right]+1, & \dfrac{T}{P}\;\geq\;\dfrac{\mathrm{e}}{4}-C\\[4ex] A\left[\left(\dfrac{1}{4}\,\mathrm{e}^{\frac{4}{\mathrm{e}}\left(\frac{T}{P}+C\right)}\right)^{\!-P}-1\right]+1, & \dfrac{T}{P}\;<\;\dfrac{\mathrm{e}}{4}-C \end{cases}

where A=672.9794928 = 1+\dfrac{N_\text{period}}{R_\text{max}-1} and C = \dfrac{1}{168} = \dfrac{T_\text{grace}}{T_\text{period}}

If you ignore the C correction from the grace time, and the fast-increase regime \frac{T}{P} < \frac{\mathrm{e}}{4}, then that matches your formula very closely, though it has an additional factor A. You can set A=1 of course, and still get a correct but less tight bound. With the A factor, you account for not just the last block in the chain, but the amount of work in the blocks before it too.