Kyuupichan’s Difficulty Algorithm Explained

Goals

The goals of Kyuupichan’s design are:

  1. Have an algorithm that is simple to understand, and easy to implement for SPV clients.
  2. Retain a long-term mean block interval of about 600 seconds.
  3. Adjust difficulty each block if necessary, but only by small fraction, using a 6-block window to avoid oscillations. Adjustments can happen in either direction.
  4. Be resilient to attacks such a timestamp manipulation and speeding up the coin emission schedule.

Design Approach

Kyuupichan’s algorithm takes a different approach than Deadalnix’s. Instead of calculating an estimated hash rate, and then using that as the basis of calculating a target, this algorithm starts with the difficulty target of the last block, and then “nudges” it up or down, depending on the observed timestamps of past blocks. In this way it acts as a “feedback” mechanism.

Specification

This algorithm bases some calculations on Median Time Past (MTP), which returns the median timestamp of the last 11 blocks (ending with the block under consideration). This is believed to be resilient to timestamp manipulation, and always increases monotonically due to consensus rules.

  1. Set an initial value for next-target (nTarget) to the target of the last block.
  2. Find the difference between the timestamp of the last block, and the one 2016 blocks previous. If this value is less than 95% of the target block spacing (10 min) multiplied by 2016, the reduce next-target by next-target with bitwise shift 8 bits to the right (about 0.4% reduction).
  3. Find the difference between the MTP of the last block, and the one 6 blocks before.
  4. If the difference in MTP is less than 30 minutes, next-target is decreased by itself with bitwise shift 8 bits to the right (about a further 0.4%).
  5. If this difference is greater than 128 minutes, nTarget is increased by nTarget with bitwise shift 6 bits to the right (about 1.6%).
  6. Return next-target as the difficulty target of the block.

Next Steps

Both Deadalnix’s and Kyuupichan’s proposals have undergone some testing through simulation. Python code for simulating Kyuupican’s algorithm is available on Github [5], and simulation results for Deadalnix’ algorithm were posted to the mailing list [6].

References

[1] Kyuupichan initial proposal to bitcoin-ml: https://lists.linuxfoundation.org/pipermail/bitcoin-ml/2017-October/000305.html

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store