<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-06-10&#xA;📝 Original message:Hi Lloyd,&#xA;&#xA;Thanks for this tx mutation proposal extending the scope of fee-bumping&#xA;techniques. IIUC, the &lt;output_index&gt; serves as a pointer to increase the&#xA;output amount by value to recover the recompute the transaction hash&#xA;against which the original signature is valid ?&#xA;&#xA;Let&#39;s do a quick analysis of this scheme.&#xA;* onchain footprint : one tapleaf per contract participant, with O(log n)&#xA;increase of witness size, also one output per contract participant&#xA;* tx-relay bandwidth rebroadcast : assuming aforementioned in-place mempool&#xA;substitution policy, the mutated transaction&#xA;* batching : fee-bumping value is extract from contract transaction itself,&#xA;so O(n) per contract&#xA;* mempool flexibility : the mutated transaction&#xA;* watchtower key management : to enable outsourcing, the mutating key must&#xA;be shared, in theory enabling contract value siphoning to miner fees ?&#xA;&#xA;Further, I think tx mutation scheme can be achieved in another way, with&#xA;SIGHASH_ANYAMOUNT. A contract participant tapscript will be the following :&#xA;&#xA;&lt;contract_key&gt; &lt;finalizing_alice_key&gt;&#xA;&#xA;Where &lt;contract_signature&gt; is committed with SIGHASH_ANYAMOUNT, blanking&#xA;nValue of one or more outputs. That way, the fee-to-contract-value&#xA;distribution can be unilaterally finalized at a later time through the&#xA;finalizing key [0].&#xA;&#xA;Note, I think that the tx mutation proposal relies on interactivity in the&#xA;worst-case scenario where a counterparty wants to increase its fee-bumping&#xA;output from the contract balance. This interactivity may lure a&#xA;counterparty to alway lock the worst-case fee-bumping reserve in the&#xA;output. I believe anchor output enables more &#34;real-time&#34; fee-bumping&#xA;reserve adjustment ?&#xA;&#xA;Cheers,&#xA;Antoine&#xA;&#xA;[0] Incautious sighash alleability is unsafe. Be careful, otherwise kitties&#xA;will perish by the thousands :&#xA;https://github.com/revault/practical-revault/pull/83&#xA;&#xA;Le dim. 6 juin 2021 à 22:28, Lloyd Fournier &lt;lloyd.fourn at gmail.com&gt; a&#xA;écrit :&#xA;&#xA;&gt; Hi Antione,&#xA;&gt;&#xA;&gt; Thanks for bringing up this important topic. I think there might be&#xA;&gt; another class of solutions over input based, CPFP and sponsorship. I&#39;ll&#xA;&gt; call them tx mutation schemes. The idea is that you can set a key that can&#xA;&gt; increase the fee by lowering a particular output after the tx is signed&#xA;&gt; without invalidating the signature. The premise is that anytime you need to&#xA;&gt; bump the fee of a transaction you must necessarily have funds in an output&#xA;&gt; that are going to you and therefore you can sacrifice some of them to&#xA;&gt; increase the fee. This is obviously destructive to txids so child presigned&#xA;&gt; transactions will have to use ANYPREVOUT as in your proposal. The advantage&#xA;&gt; is that it does not require keeping extra inputs around to bump the fee.&#xA;&gt;&#xA;&gt; So imagine a new opcode OP_CHECKSIG_MUTATED &lt;output index&gt; &lt;publickey&gt;&#xA;&gt; &lt;value&gt; &lt;signature&gt;.&#xA;&gt; This would check that &lt;signature&gt; is valid against &lt;publickey&gt; if the&#xA;&gt; current transaction had the output at &lt;output index&gt; reduced by &lt;value&gt;. To&#xA;&gt; make this more efficient, if the public key is one byte: 0x02 it references&#xA;&gt; the taproot *external key* (similar to how ANYPREVOUT uses 0x01 to refer to&#xA;&gt; internal key[1]).&#xA;&gt; Now for our protocol we want both parties (p1 and p2) to be able to fee&#xA;&gt; bump a commitment transaction. They use MuSig to sign the commitment tx&#xA;&gt; under the external key with a decent fee for the current conditions. But in&#xA;&gt; case it proves insufficient they have added the following two leaves to&#xA;&gt; their key in the funding output as a backup so that p1 and p2 can&#xA;&gt; unilaterally bump the fee of anything they sign spending from the funding&#xA;&gt; output:&#xA;&gt;&#xA;&gt; 1. OP_CHECKSIG_MUTATED(0, 0x02, &lt;fee-bump-value&gt;, &lt;original-signature&gt;)&#xA;&gt; OP_CHECKSIGADD(p1-fee-bump-key, &lt;p1-fee-bump-signature&gt;)  OP_2&#xA;&gt; OP_NUMEQUALVERIFY&#xA;&gt; 2. OP_CHECKSIG_MUTATED(1, 0x02, &lt;fee-bump-value&gt;, &lt;original-signature&gt;)&#xA;&gt; OP_CHECKSIGADD(p2-fee-bump-key, &lt;p2-fee-bump-signature&gt;) OP_2&#xA;&gt; OP_NUMEQUALVERIFY&#xA;&gt;&#xA;&gt; where &lt;...&gt; indicates the thing comes from the witness stack.&#xA;&gt; So to bump the fee of the commit tx after it has been signed either party&#xA;&gt; takes the &lt;original-signature&gt; and adds a signature under their&#xA;&gt; fee-bump-key for the new tx and reveals their fee bump leaf.&#xA;&gt; &lt;original-signature&gt; is checked against the old transaction while the fee&#xA;&gt; bumped transaction is checked against the fee bump key.&#xA;&gt;&#xA;&gt; I know I have left out how to change mempool eviction rules to accommodate&#xA;&gt; this kind of fee bumping without DoS or pinning attacks but hopefully I&#xA;&gt; have demonstrated that this class of solutions also exists.&#xA;&gt;&#xA;&gt; [1] https://github.com/ajtowns/bips/blob/bip-anyprevout/bip-0118.mediawiki&#xA;&gt;&#xA;&gt; Cheers,&#xA;&gt;&#xA;&gt; LL&#xA;&gt;&#xA;&gt;&#xA;&gt;&#xA;&gt; On Fri, 28 May 2021 at 07:13, Antoine Riard via bitcoin-dev &lt;&#xA;&gt; bitcoin-dev at lists.linuxfoundation.org&gt; wrote:&#xA;&gt;&#xA;&gt;&gt; Hi,&#xA;&gt;&gt;&#xA;&gt;&gt; This post is pursuing a wider discussion around better fee-bumping&#xA;&gt;&gt; strategies for second-layer protocols. It draws out a comparison between&#xA;&gt;&gt; input-based and CPFP fee-bumping techniques, and their apparent trade-offs&#xA;&gt;&gt; in terms of onchain footprint, tx-relay bandwidth rebroadcast, batching&#xA;&gt;&gt; opportunity and mempool flexibility.&#xA;&gt;&gt;&#xA;&gt;&gt; Thanks to Darosior for reviews, ideas and discussions.&#xA;&gt;&gt;&#xA;&gt;&gt; ## Child-Pay-For-Parent&#xA;&gt;&gt;&#xA;&gt;&gt; CPFP is a mature fee-bumping technique, known and used for a while in the&#xA;&gt;&gt; Bitcoin ecosystem. However, its usage in contract protocols with&#xA;&gt;&gt; distrusting counterparties raised some security issues. As mempool&#39;s chain&#xA;&gt;&gt; of unconfirmed transactions are limited in size, if any output is spendable&#xA;&gt;&gt; by any contract participant, it can be leveraged as a pinning vector to&#xA;&gt;&gt; downgrade odds of transaction confirmation [0].&#xA;&gt;&gt;&#xA;&gt;&gt; That said, contract transactions interested to be protected under the&#xA;&gt;&gt; carve-out logic require to add a new output for any contract participant,&#xA;&gt;&gt; even if ultimately only one of them serves as an anchor to attach a CPFP.&#xA;&gt;&gt;&#xA;&gt;&gt; ## Input-Based&#xA;&gt;&gt;&#xA;&gt;&gt; I think input-based fee-bumping has been less studied as fee-bumping&#xA;&gt;&gt; primitive for L2s [1]. One variant of input-based fee-bumping usable today&#xA;&gt;&gt; is the leverage of the SIGHASH_ANYONECANPAY/SIGHASH_SINGLE malleability&#xA;&gt;&gt; flags. If the transaction is the latest stage of the contract, a bumping&#xA;&gt;&gt; input can be attached just-in-time, thus increasing the feerate of the&#xA;&gt;&gt; whole package.&#xA;&gt;&gt;&#xA;&gt;&gt; However, as of today, input-based fee-bumping doesn&#39;t work to bump first&#xA;&gt;&gt; stages of contract transactions as it&#39;s destructive of the txid, and as&#xA;&gt;&gt; such breaks chain of pre-signed transactions. A first improvement would be&#xA;&gt;&gt; the deployment of the SIGHASH_ANYPREVOUT softfork proposal. This new&#xA;&gt;&gt; malleability flag allows a transaction to be signed without reference to&#xA;&gt;&gt; any specific previous output. That way,  spent transactions can be&#xA;&gt;&gt; fee-bumped without altering validity of the chain of transactions.&#xA;&gt;&gt;&#xA;&gt;&gt; Even assuming SIGHASH_ANYPREVOUT, if the first stage contract transaction&#xA;&gt;&gt; includes multiple outputs (e.g the LN&#39;s commitment tx has multiple HTLC&#xA;&gt;&gt; outputs), SIGHASH_SINGLE can&#39;t be used and the fee-bumping input value&#xA;&gt;&gt; might be wasted. This edge can be smoothed by broadcasting a preliminary&#xA;&gt;&gt; fan-out transaction with a set of outputs providing a range of feerate&#xA;&gt;&gt; points for the bumped transaction.&#xA;&gt;&gt;&#xA;&gt;&gt; This overhead could be smoothed even further in the future with more&#xA;&gt;&gt; advanced sighash malleability flags like SIGHASH_IOMAP, allowing&#xA;&gt;&gt; transaction signers to commit to a map of inputs/outputs [2]. In the&#xA;&gt;&gt; context of input-based, the overflowed fee value could be redirected to an&#xA;&gt;&gt; outgoing output.&#xA;&gt;&gt;&#xA;&gt;&gt; ## Onchain Footprint&#xA;&gt;&gt;&#xA;&gt;&gt; CPFP: One anchor output per participant must be included in the&#xA;&gt;&gt; commitment transaction. To this anchor must be attached a child transaction&#xA;&gt;&gt; with 2 inputs (one for the commitment, one for the bumping utxo) and 1&#xA;&gt;&gt; output. Onchain footprint: 2 inputs + 3 outputs.&#xA;&gt;&gt;&#xA;&gt;&gt; Input-based (today): If the bumping utxo is offering an adequate feerate&#xA;&gt;&gt; point in function of network mempools congestion at time of broadcast, only&#xA;&gt;&gt; 1 input. If a preliminary fan-out transaction to adjust feerate point must&#xA;&gt;&gt; be broadcasted first, 1 input and 2 outputs more must be accounted for.&#xA;&gt;&gt; Onchain footprint: 2 inputs + 3 outputs.&#xA;&gt;&gt;&#xA;&gt;&gt; Input-based (SIGHASH_ANYPREVOUT+SIGHASH_IOMAP): As long as the bumping&#xA;&gt;&gt; utxo&#39;s value is wide enough to cover the worst-case of mempools congestion,&#xA;&gt;&gt; the bumped transaction can be attached 1 input and 1 output. Onchain&#xA;&gt;&gt; footprint: 1 input + 1 output.&#xA;&gt;&gt;&#xA;&gt;&gt; ## Tx-Relay Bandwidth Rebroadcast&#xA;&gt;&gt;&#xA;&gt;&gt; CPFP: In the context of multi-party protocols, we should assume bounded&#xA;&gt;&gt; rationality of the participants w.r.t to an unconfirmed spend of the&#xA;&gt;&gt; contract utxo across network mempools. Under this assumption, the bumped&#xA;&gt;&gt; transaction might have been replaced by a concurrent state. To guarantee&#xA;&gt;&gt; efficiency of the CPFP the whole chain of transactions should be&#xA;&gt;&gt; rebroadcast, perhaps wasting bandwidth consumption for a still-identical&#xA;&gt;&gt; bumped transaction [3]. Rebroadcast footprint: the whole chain of&#xA;&gt;&gt; transactions.&#xA;&gt;&gt;&#xA;&gt;&gt; Input-based (today): In case of rebroadcast, the fee-bumping input is&#xA;&gt;&gt; attached to the root of the chain of transactions and as such breaks the&#xA;&gt;&gt; chain validity in itself. Beyond the rebroadcast of the updated root under&#xA;&gt;&gt; replacement policy, the remaining transactions must be updated and&#xA;&gt;&gt; rebroadcast. Rebroadcast footprint: the whole chain of transactions.&#xA;&gt;&gt;&#xA;&gt;&gt; Input-based(SIGHASH_ANYPREVOUT+SIGHASH_IOMAP): In case of rebroadcast,&#xA;&gt;&gt; the fee-bumping is attached to the root of the chain of transactions but it&#xA;&gt;&gt; doesn&#39;t break the chain validity in itself. Assuming a future mempool&#xA;&gt;&gt; acceptance logic to authorize in-place substitution, the rest of the chain&#xA;&gt;&gt; could be preserved. Rebroadcast footprint: the root of the chain of&#xA;&gt;&gt; transactions.&#xA;&gt;&gt;&#xA;&gt;&gt; ## Fee-Bumping Batching&#xA;&gt;&gt;&#xA;&gt;&gt; CPFP: In the context of multi-party protocols, in optimistic scenarios,&#xA;&gt;&gt; we can assume aggregation of multiple chains of transactions. For e.g, a LN&#xA;&gt;&gt; operator is desirous to non-cooperatively close multiple channels at the&#xA;&gt;&gt; same time and would like to combine their fee-bumping. With CPFP, one&#xA;&gt;&gt; anchor output and one bumping input must be consumed per aggregated chain,&#xA;&gt;&gt; even if the child transaction fields can be shared. Batching perf: 1&#xA;&gt;&gt; input/1 output per aggregated chain.&#xA;&gt;&gt;&#xA;&gt;&gt; Input-based (today): Unless the contract allows interactivity, multiple&#xA;&gt;&gt; chains of transactions cannot be aggregated. One bumping input must be&#xA;&gt;&gt; attached per chain, though if a preliminary fan-out transaction is relied&#xA;&gt;&gt; on to offer multiple feerate points, transaction fields can be shared.&#xA;&gt;&gt; Batching perf: 1 input/1 output per aggregated chain.&#xA;&gt;&gt;&#xA;&gt;&gt; Input-based (SIGHASH_ANYPREVOUT+SIGHASH_IOMAP): Multiple chains of&#xA;&gt;&gt; transactions might be aggregated together *non-interactively*. One bumping&#xA;&gt;&gt; input and outgoing output can be attached to the aggregated root. Batching&#xA;&gt;&gt; perf: 1 input/1 output per aggregation.&#xA;&gt;&gt;&#xA;&gt;&gt; ## Fee-Bumping Mempool Flexibility&#xA;&gt;&gt;&#xA;&gt;&gt; CPFP: In the context of multi-party protocols, one of your counterparties&#xA;&gt;&gt; might build a branch of transactions from one of the root outputs thus&#xA;&gt;&gt; saturating the in-mempool package limits. To avoid these shenanigans, LN&#xA;&gt;&gt; channels are relying on the carve-out mechanism. Though, the carve-out&#xA;&gt;&gt; mechanism includes its own limitation and doesn&#39;t scale beyond 2 contract&#xA;&gt;&gt; participants.&#xA;&gt;&gt;&#xA;&gt;&gt; Input-based: The root of the chain of transaction is the package&#39;s oldest&#xA;&gt;&gt; ancestor, so package limits don&#39;t restrain its acceptance and it works&#xA;&gt;&gt; whatever the number of contract participants.&#xA;&gt;&gt;&#xA;&gt;&gt; To conclude, this post scores 2 fee-bumping primitives for multi-party&#xA;&gt;&gt; protocols on a range of factors. It hopes to unravel the ground for a real&#xA;&gt;&gt; feerate performance framework of second-layers protocols .&#xA;&gt;&gt;&#xA;&gt;&gt; Beyond that, few points can be highlighted a) future soft forks allow&#xA;&gt;&gt; significant onchain footprint savings, especially in case of batching, b)&#xA;&gt;&gt; future package relay bandwidth efficiency should account for rebroadcast&#xA;&gt;&gt; frequency of CPFPing multi-party protocols. On this latter point one&#xA;&gt;&gt; follow-up might be to evaluate differing package relay *announcement*&#xA;&gt;&gt; schemes in function of odds of non-cooperative protocol broadcast/odds of&#xA;&gt;&gt; concurrent broadcast/rebroadcast frequencies.&#xA;&gt;&gt;&#xA;&gt;&gt; Thoughts ?&#xA;&gt;&gt;&#xA;&gt;&gt; Cheers,&#xA;&gt;&gt; Antoine&#xA;&gt;&gt;&#xA;&gt;&gt; [0]&#xA;&gt;&gt; https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-November/016518.html&#xA;&gt;&gt; [1] Beyond the revault architecture :&#xA;&gt;&gt; https://github.com/revault/practical-revault/blob/master/revault.pdf&#xA;&gt;&gt; [2] Already proposed a while back :&#xA;&gt;&gt; https://bitcointalk.org/index.php?topic=252960.0&#xA;&gt;&gt; [3] In theory, an already-relayed transaction shouldn&#39;t pass Core&#39;s&#xA;&gt;&gt; `filterInventoryKnown`. In practice, if the transaction is announced as&#xA;&gt;&gt; part of a package_id, the child might have changed, not the parent, leading&#xA;&gt;&gt; to a redundant relay of the latter.&#xA;&gt;&gt; _______________________________________________&#xA;&gt;&gt; bitcoin-dev mailing list&#xA;&gt;&gt; bitcoin-dev at lists.linuxfoundation.org&#xA;&gt;&gt; https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev&#xA;&gt;&gt;&#xA;&gt;&#xA;-------------- next part --------------&#xA;An HTML attachment was scrubbed...&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/bitcoin-dev/attachments/20210610/c3f2b445/attachment-0001.html&gt;</html></oembed>