Kills 4 live mutants on pow.cpp found with https://github.com/ViniciusCestarii/mutant-harness. The first 2 affect consensus. The third affect header sync and could stall IBD. The forth cover header sync hardening against DoS. They are:
<details> <summary>pow.cpp (killed by 1811735255b98257e7bf385325599c8d9bb69ad0): <code>GetNextWorkRequired</code>: <code>pindexFirst->GetBlockTime()</code> -> <code>GetMedianTimePast()</code></summary>
diff --git a/src/pow.cpp b/src/pow.cpp
index 9a9f4e5..9872b2c 100644
--- a/src/pow.cpp
+++ b/src/pow.cpp
@@ -44,7 +44,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst);
assert(pindexFirst);
- return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime(), params);
+ return CalculateNextWorkRequired(pindexLast, pindexFirst->GetMedianTimePast(), params);
}
unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params)
</details>
<details> <summary>pow.cpp (killed by 7834db23914a3faa3660cb609144cd1c345a1ef3): <code>CalculateNextWorkRequired</code>: <code>int64_t nActualTimespan</code> -> <code>uint32_t</code>.</summary>
diff --git a/src/pow.cpp b/src/pow.cpp
index 9a9f4e5..1917b7b 100644
--- a/src/pow.cpp
+++ b/src/pow.cpp
@@ -53,7 +53,7 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
return pindexLast->nBits;
// Limit adjustment step
- int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime;
+ uint32_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime;
if (nActualTimespan < params.nPowTargetTimespan/4)
nActualTimespan = params.nPowTargetTimespan/4;
if (nActualTimespan > params.nPowTargetTimespan*4)
</details>
<details> <summary>pow.cpp (killed by a9873943e259b23884fb4295591a82168c831026): <code>PermittedDifficultyTransition</code>: compares <code>smallest_difficulty_target</code> directly instead of round-tripping it through <code>SetCompact(GetCompact())</code></summary>
diff --git a/src/pow.cpp b/src/pow.cpp
index 9a9f4e5..028fa9f 100644
--- a/src/pow.cpp
+++ b/src/pow.cpp
@@ -124,11 +124,8 @@ bool PermittedDifficultyTransition(const Consensus::Params& params, int64_t heig
smallest_difficulty_target = pow_limit;
}
- // Round and then compare this new calculated value to what is
- // observed.
- arith_uint256 minimum_new_target;
- minimum_new_target.SetCompact(smallest_difficulty_target.GetCompact());
- if (minimum_new_target > observed_new_target) return false;
+ // Compare this new calculated value to what is observed.
+ if (smallest_difficulty_target > observed_new_target) return false;
} else if (old_nbits != new_nbits) {
return false;
}
</details>
<details> <summary>pow.cpp (killed by e6975adf58c354dbd167b419ad7aadc7b8053af6): <code>PermittedDifficultyTransition</code>: drops the non-retarget height check that requires <code>old_nbits == new_nbits</code></summary>
diff --git a/src/pow.cpp b/src/pow.cpp
index 9a9f4e5..ef2e788 100644
--- a/src/pow.cpp
+++ b/src/pow.cpp
@@ -129,8 +129,6 @@ bool PermittedDifficultyTransition(const Consensus::Params& params, int64_t heig
arith_uint256 minimum_new_target;
minimum_new_target.SetCompact(smallest_difficulty_target.GetCompact());
if (minimum_new_target > observed_new_target) return false;
- } else if (old_nbits != new_nbits) {
- return false;
}
return true;
}
</details>
Recommend reviewing per commit.