aboutsummaryrefslogtreecommitdiff
path: root/src/pow.h
diff options
context:
space:
mode:
authorSuhas Daftuar <sdaftuar@gmail.com>2022-05-25 10:16:56 -0400
committerSuhas Daftuar <sdaftuar@gmail.com>2022-08-23 11:34:10 -0400
commit1d4cfa4272cf2c8b980cc8762c1ff2220d3e8d51 (patch)
tree4d1338b17702e4ed0998ece0f00f2d4b8b9ba062 /src/pow.h
parent2bd9aa5a44b88c866c4d98f8a7bf7154049cba31 (diff)
downloadbitcoin-1d4cfa4272cf2c8b980cc8762c1ff2220d3e8d51.tar.xz
Add function to validate difficulty changes
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. Includes fuzz test by Martin Zumsande.
Diffstat (limited to 'src/pow.h')
-rw-r--r--src/pow.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/pow.h b/src/pow.h
index 1d802cd01e..44b9d673ef 100644
--- a/src/pow.h
+++ b/src/pow.h
@@ -20,4 +20,18 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&);
+/**
+ * Return false if the proof-of-work requirement specified by new_nbits at a
+ * given height is not possible, given the proof-of-work on the prior block as
+ * specified by old_nbits.
+ *
+ * This function only checks that the new value is within a factor of 4 of the
+ * old value for blocks at the difficulty adjustment interval, and otherwise
+ * requires the values to be the same.
+ *
+ * Always returns true on networks where min difficulty blocks are allowed,
+ * such as regtest/testnet.
+ */
+bool PermittedDifficultyTransition(const Consensus::Params& params, int64_t height, uint32_t old_nbits, uint32_t new_nbits);
+
#endif // BITCOIN_POW_H