This PR is on top of #22867 which adds test coverage relevant to this PR, and motivates it by highlighting some of the behavior this improves upon.
It aims to resolve issue #22209 as well as CVE-2021-31876
Bitcoin Core 0.12.0 through 0.21.1 does not properly implement the replacement policy specified in BIP125, which makes it easier for attackers to trigger a loss of funds, or a denial of service attack against downstream projects such as Lightning network nodes.
- As a followup to this PR I think some fuzz testing would be useful.
- Also an optimization followup can be done, putting some stricter bounds on
IsRBFOptIn
when it invokesCalculateMemPoolAncestors
. However, I don’t do that in this PR to keep it as simple as possible, and I don’t think it’s necessary. a) default mempool limits are much stricter than BIP125 Rule 5’sMAX_BIP125_REPLACEMENT_CANDIDATES{100}
, becauseDEFAULT_DESCENDANT_LIMIT == 25
. b) I don’t see a major performance tradeoff (please double check me). I think https://github.com/bitcoin/bitcoin/blob/master/test/functional/mempool_updatefromblock.py is a good worst-case scenario stress test for additional runtime required to check for inherited signaling, and this test seems to run in approx the same amount of time after this PR. Which seems acceptable to me, and not a risk for a DOS vector. But again, please be critical of this in the review. I also noticed #23621 when testing, and would like to see where that lands before I try any optimization.