<oembed><type>rich</type><version>1.0</version><title>Antoine Riard [ARCHIVE] wrote</title><author_name>Antoine Riard [ARCHIVE] (npub1vj…4x8dd)</author_name><author_url>https://yabu.me/npub1vjzmc45k8dgujppapp2ue20h3l9apnsntgv4c0ukncvv549q64gsz4x8dd</author_url><provider_name>njump</provider_name><provider_url>https://yabu.me</provider_url><html>📅 Original date posted:2021-05-06&#xA;📝 Original message:Hi,&#xA;&#xA;I&#39;m writing to report a defect in Bitcoin Core bip125 logic with minor&#xA;security and operational implications for downstream projects. Though this&#xA;defect grieves Bitcoin Core nodes 0.12.0 and above, base layer safety isn&#39;t&#xA;impacted.&#xA;&#xA;# Problem&#xA;&#xA;Bip 125 specification describes the following signalling mechanism :&#xA;&#xA;&#34;&#xA;This policy specifies two ways a transaction can signal that it is&#xA;replaceable.&#xA;&#xA;* Explicit signaling: A transaction is considered to have opted in to&#xA;allowing replacement of itself if any of its inputs have an nSequence&#xA;number less than (0xffffffff - 1).&#xA;&#xA;* Inherited signaling: Transactions that don&#39;t explicitly signal&#xA;replaceability are replaceable under this policy for as long as any one of&#xA;their ancestors signals replaceability and remains unconfirmed.&#xA;&#xA;One or more transactions currently in the mempool (original transactions)&#xA;will be replaced by a new transaction (replacement transaction) that spends&#xA;one or more of the same inputs if,&#xA;&#xA;# The original transactions signal replaceability explicitly or through&#xA;inheritance as described in the above Summary section.&#xA;&#34;&#xA;&#xA;An unconfirmed child transaction with nSequence = 0xff_ff_ff_ff spending an&#xA;unconfirmed parent with nSequence &lt;= 0xff_ff_ff_fd should be replaceable as&#xA;the child transaction signals &#34;through inheritance&#34;. However, the&#xA;replacement code as implemented in Core&#39;s `PreChecks()` shows that this&#xA;behavior isn&#39;t  enforced and Core&#39;s mempool rejects replacement attempts of&#xA;an unconfirmed child transaction.&#xA;&#xA;Branch asserting the behavior is here :&#xA;https://github.com/ariard/bitcoin/commits/2021-03-test-rbf&#xA;&#xA;# Solution&#xA;&#xA;The defect has not been patched.&#xA;&#xA;# Downstream Projects Affected&#xA;&#xA;* LN : State-of-the-art pinning attacks against second-stage HTLCs&#xA;transactions were thought to be only possible by exploiting RBF rule 3 on&#xA;the necessity of a higher absolute fee [0]. However, this replacement&#xA;defect opens the way for an attacker to only pin with an opt-out child&#xA;without a higher fee than the honest competing transaction. This lowers the&#xA;cost of attack as the malicious pinning transaction only has to be above&#xA;mempools&#39;min feerate. This also increases odds of attack success for a&#xA;reduced feerate diminishes odds of confirmation ending the pinning.&#xA;&#xA;A functional test demo illustrating cases is available on this branch:&#xA;https://github.com/ariard/bitcoin/commits/2021-05-htlc-preimage-pinnings&#xA;&#xA;LN nodes operators concerned by this defect might favor anchor outputs&#xA;channels, fully mitigating this specific pinning vector.&#xA;&#xA;* Onchain DLC/Coinswap/Vault : Those contract protocols have also multiple&#xA;stages of execution with time-sensitive transactions opening the way to&#xA;pinning attacks. Those protocols being non-deployed or in early phase, I&#xA;would recommend that any in-protocol competing transactions explicitly&#xA;signal RBF.&#xA;&#xA;* Coinjoin/Cut-Through : if CPFP is employed as a fee-bumping strategy, if&#xA;the coinjoin transaction is still laying in network mempools, if a&#xA;fee-bumping output is spendable by any protocol participant, this&#xA;fee-bumping mechanism might be halted by a malicious protocol participant&#xA;broadcasting an low-feerate opt-out child. According to bip125, if the&#xA;coinjoin parent tx signals replaceability, the child transaction should be&#xA;replaceable, whatever its signaling. However Core doesn&#39;t apply this&#xA;policy. RBF of the coinjoin transaction itself should be used as a&#xA;fallback. I&#39;m not aware of any deployed coinjoin using such&#xA;&#34;anyone-can-bump&#34; fee-bumping strategy.&#xA;&#xA;* Simple wallets : RBF engines&#39; behaviors might be altered in ways not&#xA;matching the intent of their developers. I invite RBF engines dev to verify&#xA;what those components are doing in the light of disclosed information.&#xA;&#xA;# Discovery&#xA;&#xA;While reviewing the LN dual-funding flow, I inquired on potential new DoS&#xA;vectors introduced by relying on counterparty utxos in this following&#xA;analysis [1]. The second DoS issue &#34;RBF opt-out by a Counterparty&#xA;Double-Spend&#34; is relying on a malicious chain of transactions where the&#xA;parent is signaling RBF opt-in through nSequence&lt;=0xff_ff_ff_ff-1 but the&#xA;child, servicing as a pinning transaction, opt-out from the RBF policy.&#xA;This pinning trick conception was matching my understanding of Core code&#xA;but while reading again the specification, I observed that it was&#xA;inconsistent from the inherited signaling mechanism as described in the&#xA;bip&#39;s &#34;Summary&#34; section.&#xA;&#xA;After exercising the logic, I did submit the defect to Dave Harding, asking&#xA;confirmation of divergence between Bitcoin Core and BIP 125. Soon after, he&#xA;did confirm it and pointed that the defect has been there since the 2015&#39;s&#xA;PR introducing the opt-in RBF, advicing to to consider security&#xA;implications for deployed second-layer protocols. After noticing the minor&#xA;implications for pinning attacks on second-stage LN transactions while&#xA;talking with Matt Corallo, I did disclose to the Bitcoin Core security list.&#xA;&#xA;My initial report was recommending avoiding a covert patch in the mempool&#xA;as risks of introducing DoS in this part of the codebase seemed to outweigh&#xA;security of deployed LN channels. This direction was agreed by the opinions&#xA;expressed on the security list. Beyond, there was a lack of agreement on&#xA;how to proceed with the disclosure as so far in the history project,&#xA;transaction relay policy have not been considered as strongly reliable.&#xA;Though from now on, L2 protocols like Lightning are making assumptions on&#xA;subset of this policy for their safety, such as the highlighted RBF one.&#xA;&#xA;Defect was disclosed to the LN projects maintainers, informing them that&#xA;currently in deployment anchor outputs protocol upgrade was mitigating&#xA;against this defect though old channels will stay vulnerable. To the best&#xA;of my knowledge, I didn&#39;t identify other deployed protocols of which coins&#xA;safety are impacted by this defect.&#xA;&#xA;# Ecosystem Observations&#xA;&#xA;This long-standing defect with benign security implications provided an&#xA;opportunity to exercise coordinated security disclosure across layers and&#xA;development teams.&#xA;&#xA;IMO, it underlies few interesting points:&#xA;* the lack of an established policy for coordinated security disclosures&#xA;between a base layer implementation and its downstream projects&#xA;* the lack of a clear methodology to identify downstream projects affected&#xA;by a transaction relay policy wreckage&#xA;* the lack of minimally-disruptive, emergency upgrade mechanisms&#xA;implemented by downstream projects [2]&#xA;&#xA;Finally, security implications for downstream projects provoked by base&#xA;layer issues shouldn&#39;t be minimized as they do have a risk of windblow on&#xA;base layer operations. I believe we should minimize risks of disaster&#xA;scenarios such as thousands of LN channels manually closed by worried&#xA;operators due to a non-concerted security disclosure, provoking mempool&#xA;cloaks and disrupting regular transactions for a while.&#xA;&#xA;# Timeline&#xA;&#xA;2021-03-18 : Defect discovered, report to Dave Harding original author of&#xA;bip125, confirmation of the defect&#xA;2021-03-19 : Disclosure to the Bitcoin Core security list, Dave Harding,&#xA;Matt Corallo, acknowledgment of the issue&#xA;2021-04-05 : Disclosure to the LN projects maintainers (c-lightning, lnd,&#xA;eclair, electrum, rust-lightning)&#xA;2021-04-28 : CVE-2021-31876 assigned&#xA;2021-05-06 : Full disclosure to the bitcoin-dev mailing list&#xA;&#xA;I believe the information reported is correct and reflects the best of my&#xA;knowledge, please point any shortcoming.&#xA;&#xA;Cheers,&#xA;Antoine&#xA;&#xA;[0]&#xA;https://lists.linuxfoundation.org/pipermail/lightning-dev/2020-April/002639.html&#xA;[1] See &#34;On Mempool Funny Games against Multi-Party Funded Transactions&#34;,&#xA;published 2021-05-06&#xA;[2] Such as&#xA;https://lists.linuxfoundation.org/pipermail/lightning-dev/2020-July/002763.html&#xA;-------------- next part --------------&#xA;An HTML attachment was scrubbed...&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/bitcoin-dev/attachments/20210506/80fed090/attachment-0001.html&gt;</html></oembed>