Fast(er) Difficulty Adjustment for
Secure Sidechains

Mark Friedenbach<mark@friedenbach.org>
work in collaboration withan anonymous contributor

Fast Difficulty Adjustment

1The problem●●●

Bitcoin protocol adjusts difficulty every 2016 blocks, which
nominally happens every 2 weeks.
Bitcoin hash rate is relatively stable. A “slow” adjustment
algorithm works fine, so far.
But what about low probability events, or attacks not previously
seen on mainnet? We must plan for the future!

Fast Difficulty Adjustment

2The problem●●●

Alternative networks experience rapid hashrate fluctuation: 10x
flux on short (<1 day!) timescales is not unheard of, when there
exists hardware capable of being re-purposed for other networks(e.g. CPUs, GPUs, sha256 and scrypt chains).
Merged mined sidechains or extension blocks are expected toexperience large shocks in hashrate in current ecosystem as
mining pools add or remove support, or during active attacks.
Bitcoin may experience a large shock event in some unlikely, but
possible scenarios e.g. of Internet access to China being shut off(war?). While unlikely, this would be a situation where Bitcoin isneeded most...
Fast Difficulty Adjustment

3The problem
What would happen if the hashrate experienced a 10x reduction?
●●●Transaction throughput reduced to 10% of normal: 0.3tps.
Up to 4½ months until relief from the first difficulty adjustment
downward, almost 6 months until normalcy.
Reduction of throughput and lack of response leads to drop in
price, dropping price leads to dropping profitability forremaining miners, and a viscous “hash crash” cycle of further
hashrate reductions ensues.

This exact scenario has been the common experience of many
alternative networks. It could happen to Bitcoin too.
Fast Difficulty Adjustment

4The solutions●Adjust more frequently.
●●Decouple sliding window from adjustment frequency.
●●

Why not adjust every block? Or at least every N, for N << 2016.
Early adjustment has compounding effects, allowing quick response to a shock.

Size of sliding window affects how quickly the controller responds to a hashrate shock.
Note that how frequently the adjustment is performed, and how large of a sliding window is usedare mostly-independent knobs to tweak, even if in Bitcoin they are almost the same (2016 and2015, respectfully).

Change the control algorithm.
●Bitcoin uses an extremely simple, naïve control algorithm.
Control theory literature is full of better alternatives...

Fast Difficulty Adjustment

5

Adjust more frequently?

Fast Difficulty Adjustment

6

Adjust more frequently?

Fast Difficulty Adjustment

7

Adjust more frequently?

Fast Difficulty Adjustment

8Adversarial aside…
Bitcoin has an incentive problem encouraging miners to lie about
timestamps of blocks before and just after a difficulty adjustment.
Doing so results in a easier (~1%) difficulty than 10 minute blocks
with actual hashrate would require, resulting in higher revenue perunit time.
Shortening the adjustment interval makes this worse.
However this instance of the problem is mostly solved by making
sure that the sliding window is equal to or larger than theadjustment interval, which is not the case for bitcoin.
We will revisit this issue shortly...
Fast Difficulty Adjustment

9Decouple frequency and interval

Fast Difficulty Adjustment

10

The problem, revisitedThere is a variable, “hashrate” which we sample once per block.
The samples are subject to significant random noise.
We wish to ignore the high-frequency noise to isolate and respondto the long-term trend: by how much is the variable being sampledgenerally going up or down.
This is generally known as a low-pass filter.
Thankfully there are methods for generating provably optimal filter
designs… e.g. the Parks–McClellan filter design algorithm:
scipy.signal.remez(36, [0, 0.05, 0.1, 0.5], [1, 0])
Fast Difficulty Adjustment

11Low-pass filter design

Fast Difficulty Adjustment

12

Low-pass filter, continued
Adds two more tweakable parameters: gain and limiter. Optimal
selections for both based on the shown 36-tap linear filter,
validated by simulation:
Gain: increase or decrease is modulated by this factor.
gain = 0.125

Limiter: maximum increase or decrease allowed per adjustment.
limiter = 1.375

Fast Difficulty Adjustment

13

Questions

mark@friedenbach.org

Fast Difficulty Adjustment

14