HomePhabricator

Add function to validate difficulty changes

Description

Add function to validate difficulty changes

Summary:
The rule against difficulty adjustments changing by more than a factor of 4 can
be helpful for anti-DoS measures in contexts where we lack a full headers
chain, so expose this functionality separately and in the narrow case where we
only know the height, new value, and old value.

The function was adjusted to account for the changes in difficulty algorithms after the 2017 BCH fork. The EDA algorithm no longer limits the difficulty change interval to 2016 blocks but still keeps the rule that the difficulty cannot change by more than a factor 4. The DAA (CW-144) and ASERTI3D algorithms no longer have hard rules for difficulty transitions, so the function always returns true after the november 15 2017 hard fork block height.

This is a backport of core#25717
https://github.com/bitcoin/bitcoin/pull/25717/commits/1d4cfa4272cf2c8b980cc8762c1ff2220d3e8d51

Test Plan: ninja && ninja check

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D15123

Details

Provenance
Suhas Daftuar <sdaftuar@gmail.com>Authored on May 25 2022, 14:16
PiRKCommitted on Jan 12 2024, 07:40
PiRKPushed on Jan 12 2024, 07:40
Reviewer
Restricted Project
Differential Revision
D15123: Add function to validate difficulty changes
Parents
rABCf57103ac9621: [Cashtab] Additional mitigation for legacy wallet addresses
Branches
Unknown
Tags
Unknown