{"type":"rich","version":"1.0","author_name":"npub19helcfnqgk2jrwzjex2aflq6jwfc8zd9uzzkwlgwhve7lykv23mq5zkvn4","author_url":"https://nostr.ae/npub19helcfnqgk2jrwzjex2aflq6jwfc8zd9uzzkwlgwhve7lykv23mq5zkvn4","provider_name":"njump","provider_url":"https://nostr.ae","html":"📅 Original date posted:2020-04-22\n📝 Original message:\nHi z,\n\nActually, the current anchors proposal already does this, since it enforces\na\nCSV of 1 block before the HTLCs can be spent (the block after\nconfirmation). So\nI think we already do this, meaning the malicious node is already forced to\nuse\nan RBF-replaceable transaction.\n\n-- Laolu\n\n\nOn Wed, Apr 22, 2020 at 4:05 PM Olaoluwa Osuntokun \u003claolu32 at gmail.com\u003e\nwrote:\n\n\u003e Hi Z,\n\u003e\n\u003e \u003e It seems to me that, if my cached understanding that `\u003c0\u003e\n\u003e \u003e OP_CHECKSEQUENCEVERIFY` is sufficient to require RBF-flagging, then\n\u003e adding\n\u003e \u003e that to the hashlock branch (2 witness bytes, 0.5 weight) would be a\n\u003e pretty\n\u003e \u003e low-weight mitigation against this attack.\n\u003e\n\u003e I think this works...so they're forced to spend the output with a non-final\n\u003e sequence number, meaning it *must* signal RBF. In this case, now it's the\n\u003e timeout-er vs the success-er racing based on fee rate. If the honest party\n\u003e (the\n\u003e one trying to time out the HTLC) bids a fee rate higher (need to also\n\u003e account\n\u003e for the whole absolute fee replacement thing), then things should generally\n\u003e work out in their favor.\n\u003e\n\u003e -- Laolu\n\u003e\n\u003e\n\u003e On Tue, Apr 21, 2020 at 11:08 PM ZmnSCPxj \u003cZmnSCPxj at protonmail.com\u003e wrote:\n\u003e\n\u003e\u003e Good morning Laolu, Matt, and list,\n\u003e\u003e\n\u003e\u003e\n\u003e\u003e \u003e \u003e  * With `SIGHASH_NOINPUT` we can make the C-side signature\n\u003e\u003e \u003e \u003e  `SIGHASH_NOINPUT|SIGHASH_SINGLE` and allow B to re-sign the B-side\n\u003e\u003e \u003e \u003e  signature for a higher-fee version of HTLC-Timeout (assuming my\n\u003e\u003e cached\n\u003e\u003e \u003e \u003e  understanding of `SIGHASH_NOINPUT` still holds).\n\u003e\u003e \u003e\n\u003e\u003e \u003e no_input isn't needed. With simply single+anyone can pay, then B can\n\u003e\u003e attach\n\u003e\u003e \u003e a new input+output pair to increase the fees on their HTLC redemption\n\u003e\u003e \u003e transaction. As you mention, they now enter into a race against this\n\u003e\u003e \u003e malicious ndoe to bump up their fees in order to win over the other\n\u003e\u003e party.\n\u003e\u003e\n\u003e\u003e Right, right, that works as well.\n\u003e\u003e\n\u003e\u003e \u003e\n\u003e\u003e \u003e If the malicious node uses a non-RBF signalled transaction to sweep\n\u003e\u003e their\n\u003e\u003e \u003e HTLC, then we enter into another level of race, but this time on the\n\u003e\u003e mempool\n\u003e\u003e \u003e propagation level. However, if there exists a relay path to a miner\n\u003e\u003e running\n\u003e\u003e \u003e full RBF, then B's higher fee rate spend will win over.\n\u003e\u003e\n\u003e\u003e Hmm.\n\u003e\u003e\n\u003e\u003e So basically:\n\u003e\u003e\n\u003e\u003e * B has no mempool, because it wants to reduce its costs and etc.\n\u003e\u003e * C broadcasts a non-RBF claim tx with low fee before A-\u003eB locktime (L+1).\n\u003e\u003e * B does not notice this tx because:\n\u003e\u003e   1.  The tx is too low fee to be put in a block.\n\u003e\u003e   2.  B has no mempool so it cannot see the tx being propagated over the\n\u003e\u003e P2P network.\n\u003e\u003e * B tries to broadcast higher-fee HTLC-timeout, but fails because it\n\u003e\u003e cannot replace a non-RBF tx.\n\u003e\u003e * After L+1, C contacts the miners off-band and offers fee payment by\n\u003e\u003e other means.\n\u003e\u003e\n\u003e\u003e It seems to me that, if my cached understanding that `\u003c0\u003e\n\u003e\u003e OP_CHECKSEQUENCEVERIFY` is sufficient to require RBF-flagging, then adding\n\u003e\u003e that to the hashlock branch (2 witness bytes, 0.5 weight) would be a pretty\n\u003e\u003e low-weight mitigation against this attack.\n\u003e\u003e\n\u003e\u003e So I think the combination below gives us good size:\n\u003e\u003e\n\u003e\u003e * The HTLC-Timeout signature from C is flagged with\n\u003e\u003e `OP_SINGLE|OP_ANYONECANPAY`.\n\u003e\u003e   * Normally, the HTLC-Timeout still deducts the fee from the value of\n\u003e\u003e the UTXO being spent.\n\u003e\u003e   * However, if B notices that the L+1 timeout is approaching, it can\n\u003e\u003e fee-bump HTLC-Timeout with some onchain funds, recreating its own signature\n\u003e\u003e but reusing the (still valid) C signature.\n\u003e\u003e * The hashlock branch in this case includes `\u003c0\u003e OP_CHECKSEQUENCEVERIFY`,\n\u003e\u003e preventing C from broadcasting a low-fee claim tx.\n\u003e\u003e\n\u003e\u003e This has the advantages:\n\u003e\u003e\n\u003e\u003e * B does not need a mempool still and can run in `blocksonly`.\n\u003e\u003e * The normal path is still the same as current behavior, we \"only\" add a\n\u003e\u003e new path where if the L+1 timeout is approaching we fee-bump the\n\u003e\u003e HTLC-Timeout.\n\u003e\u003e * Costs are pretty low:\n\u003e\u003e   * No need for extra RBF carve-out txo.\n\u003e\u003e   * Just two additional witness bytes in the hashlock branch.\n\u003e\u003e * No mempool rule changes needed, can be done with the P2P network of\n\u003e\u003e today.\n\u003e\u003e   * Probably still resilient even with future changes in mempool rules,\n\u003e\u003e as long as typical RBF behaviors still remain.\n\u003e\u003e\n\u003e\u003e Is my understanding correct?\n\u003e\u003e\n\u003e\u003e Regards,\n\u003e\u003e ZmnSCPxj\n\u003e\u003e\n\u003e\u003e \u003e\n\u003e\u003e \u003e -- Laolu\n\u003e\u003e \u003e\n\u003e\u003e \u003e On Tue, Apr 21, 2020 at 9:13 PM ZmnSCPxj via bitcoin-dev \u003c\n\u003e\u003e bitcoin-dev at lists.linuxfoundation.org\u003e wrote:\n\u003e\u003e \u003e\n\u003e\u003e \u003e \u003e Good morning Matt, and list,\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e \u003e     RBF Pinning HTLC Transactions (aka \"Oh, wait, I can steal\n\u003e\u003e funds, how, now?\")\n\u003e\u003e \u003e \u003e \u003e     =============================\n\u003e\u003e \u003e \u003e \u003e\n\u003e\u003e \u003e \u003e \u003e     You'll note that in the discussion of RBF pinning we were\n\u003e\u003e pretty broad, and that that discussion seems to in fact cover\n\u003e\u003e \u003e \u003e \u003e     our HTLC outputs, at least when spent via (3) or (4). It does,\n\u003e\u003e and in fact this is a pretty severe issue in today's\n\u003e\u003e \u003e \u003e \u003e     lightning protocol [2]. A lightning counterparty (C, who\n\u003e\u003e received the HTLC from B, who received it from A) today could,\n\u003e\u003e \u003e \u003e \u003e     if B broadcasts the commitment transaction, spend an HTLC using\n\u003e\u003e the preimage with a low-fee, RBF-disabled transaction.\n\u003e\u003e \u003e \u003e \u003e     After a few blocks, A could claim the HTLC from B via the\n\u003e\u003e timeout mechanism, and then after a few days, C could get the\n\u003e\u003e \u003e \u003e \u003e     HTLC-claiming transaction mined via some out-of-band agreement\n\u003e\u003e with a small miner. This leaves B short the HTLC value.\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e My (cached) understanding is that, since RBF is signalled using\n\u003e\u003e `nSequence`, any `OP_CHECKSEQUENCEVERIFY` also automatically imposes the\n\u003e\u003e requirement \"must be RBF-enabled\", including `\u003c0\u003e OP_CHECKSEQUENCEVERIFY`.\n\u003e\u003e \u003e \u003e Adding that clause (2 bytes in witness if my math is correct) to the\n\u003e\u003e hashlock branch may be sufficient to prevent C from making an RBF-disabled\n\u003e\u003e transaction.\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e But then you mention out-of-band agreements with miners, which\n\u003e\u003e basically means the transaction might not be in the mempool at all, in\n\u003e\u003e which case the vulnerability is not really about RBF or relay, but sheer\n\u003e\u003e economics.\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e The payment is A-\u003eB-\u003eC, and the HTLC A-\u003eB must have a larger timeout\n\u003e\u003e (L + 1) than the HTLC B-\u003eC (L), in abstract non-block units.\n\u003e\u003e \u003e \u003e The vulnerability you are describing means that the current time must\n\u003e\u003e now be L + 1 or greater (\"A could claim the HTLC from B via the timeout\n\u003e\u003e mechanism\", meaning the A-\u003eB HTLC has timed out already).\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e If so, then the B-\u003eC transaction has already timed out in the past\n\u003e\u003e and can be claimed in two ways, either via B timeout branch or C hashlock\n\u003e\u003e branch.\n\u003e\u003e \u003e \u003e This sets up a game where B and C bid to miners to get their version\n\u003e\u003e of reality committed onchain.\n\u003e\u003e \u003e \u003e (We can neglect out-of-band agreements here; miners have the\n\u003e\u003e incentive to publicly leak such agreements so that other potential bidders\n\u003e\u003e can offer even higher fees for their versions of that transaction.)\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e Before L+1, C has no incentive to bid, since placing any bid at all\n\u003e\u003e will leak the preimage, which B can then turn around and use to spend from\n\u003e\u003e A, and A and C cannot steal from B.\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e Thus, B should ensure that *before* L+1, the HTLC-Timeout has been\n\u003e\u003e committed onchain, which outright prevents this bidding war from even\n\u003e\u003e starting.\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e The issue then is that B is using a pre-signed HTLC-timeout, which is\n\u003e\u003e needed since it is its commitment tx that was broadcast.\n\u003e\u003e \u003e \u003e This prevents B from RBF-ing the HTLC-Timeout transaction.\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e So what is needed is to allow B to add fees to HTLC-Timeout:\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e * We can add an RBF carve-out output to HTLC-Timeout, at the cost of\n\u003e\u003e more blockspace.\n\u003e\u003e \u003e \u003e * With `SIGHASH_NOINPUT` we can make the C-side signature\n\u003e\u003e `SIGHASH_NOINPUT|SIGHASH_SINGLE` and allow B to re-sign the B-side\n\u003e\u003e signature for a higher-fee version of HTLC-Timeout (assuming my cached\n\u003e\u003e understanding of `SIGHASH_NOINPUT` still holds).\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e With this, B can exponentially increase the fee as L+1 approaches.\n\u003e\u003e \u003e \u003e If B can get HTLC-Timeout confirmed before L+1, then C cannot steal\n\u003e\u003e the HTLC value at all, since the UTXO it could steal from has already been\n\u003e\u003e spent.\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e In particular, it does not seem to me that it is necessary to change\n\u003e\u003e the hashlock-branch transaction of C at all, since this mechanism is enough\n\u003e\u003e to sidestep the issue (as I understand it).\n\u003e\u003e \u003e \u003e But it does point to a need to make HTLC-Timeout (and possibly\n\u003e\u003e symmetrically, HTLC-Success) also fee-bumpable.\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e Note as well that this does not require a mempool: B can run in\n\u003e\u003e `blocksonly` mode and as each block comes in from L to L+1, if HTLC-Timeout\n\u003e\u003e is not confirmed, feebump HTLC-Timeout.\n\u003e\u003e \u003e \u003e In particular, HTLC-Timeout comes into play only if B broadcast its\n\u003e\u003e own commitment transaction, and B *should* be aware that it did so ---\n\u003e\u003e there is still no need for mempool monitoring here.\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e Now, of course this only delays the war.\n\u003e\u003e \u003e \u003e Let us now consider what C can do to ensure that the bidding war will\n\u003e\u003e happen eventually.\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e * C can bribe a miner to prevent HTLC-Timeout from confirming between\n\u003e\u003e L and L+1.\n\u003e\u003e \u003e \u003e   * Or in other words, this is a censorship attack.\n\u003e\u003e \u003e \u003e     * The Bitcoin censorship-resistance model is that censored\n\u003e\u003e transactions can be fee-bumped, which attracts non-censoring miners to try\n\u003e\u003e their luck at mining and evict the censoring miner.\n\u003e\u003e \u003e \u003e       * Thus, letting B bump the fee on HTLC-Timeout is precisely the\n\u003e\u003e mechanism we need.\n\u003e\u003e \u003e \u003e       * This sets up a bidding war between C requesting miners to\n\u003e\u003e censor, vs. B requesting miners to confirm, but that only sets the stage\n\u003e\u003e for a second bidding war later between C and B, thus C is at a\n\u003e\u003e disadvantage: it has to bribe miners to censor continuously from L to L+1\n\u003e\u003e *and* additional bribe miners to confirm its transaction after L+1, whereas\n\u003e\u003e B can offer its bribe as being something that miners can claim now without\n\u003e\u003e waiting after L+1.\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e The issue of course is the additional output that bloats the UTXO set\n\u003e\u003e and requires another transaction to claim later.\n\u003e\u003e \u003e \u003e And if we have `SIGHASH_NOINPUT`, it seems to me that\n\u003e\u003e Decker-Russell-Osuntokun sidesteps this issue as well, as any timed-out\n\u003e\u003e HTLC can be claimed with a fee-bumpable transaction directly without\n\u003e\u003e RBF-carve-out.\n\u003e\u003e \u003e \u003e (As well, it seems to me that, if both nodes support doing so, a\n\u003e\u003e Poon-Dryja channel can be upgraded, without onchain activity, to a\n\u003e\u003e Decker-Russell-Osuntokun channel: sign a transaction spending the funding\n\u003e\u003e tx to a txo that has been set up as Decker-Russell-Osuntokun, do not\n\u003e\u003e broadcast that transaction, then revoke the latest Poon-Dryja commitment\n\u003e\u003e transactions, then switch the mechanism over to Decker-Russell-Osuntokun;\n\u003e\u003e you still need to monitor for previous Poon-Dryja commitment transactions,\n\u003e\u003e but HTLCs now sidestep the issue under discussion here.)\n\u003e\u003e \u003e \u003e\n\u003e\u003e \u003e \u003e Regards,\n\u003e\u003e \u003e \u003e ZmnSCPxj\n\u003e\u003e \u003e \u003e _______________________________________________\n\u003e\u003e \u003e \u003e bitcoin-dev mailing list\n\u003e\u003e \u003e \u003e bitcoin-dev at lists.linuxfoundation.org\n\u003e\u003e \u003e \u003e https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev\n\u003e\u003e\n\u003e\u003e\n\u003e\u003e\n-------------- next part --------------\nAn HTML attachment was scrubbed...\nURL: \u003chttp://lists.linuxfoundation.org/pipermail/lightning-dev/attachments/20200422/b51b1fe1/attachment.html\u003e"}
