<div>Hi Jeremy,<br></div><div><br></div><div>I think it would be nice to have and suggested something similar (enforce minimality) in the context of<br>Miniscript a few months ago [0].<br></div><div><br></div><div>However your code:<br></div><div><br></div><div>        const bool seq_is_reserved = (txin.nSequence < CTxIn::SEQUENCE_FINAL-2) && (<br></div><div>        // when sequence is set to disabled, it is reserved for future use<br></div><div>        ((txin.nSequence & CTxIn::SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0) ||<br></div><div>        // when sequence has bits set outside of the type flag and locktime mask,<br></div><div>        // it is reserved for future use.<br></div><div>        ((~(CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | CTxIn::SEQUENCE_LOCKTIME_MASK) &<br></div><div>                txin.nSequence) != 0)<br></div><div>        );<br></div><div><br></div><div>Would effectively prevent Lightning Network commitment transactions from relaying. The protocol uses<br>a hack encoding the commitment transaction numbering in the part of nSequence (and nLockTime)<br>without consensus meaning. This both sets the LOCKTIME_DISABLE_FLAG and uses bits outside of<br>the mask.<br></div><div><br></div><div>[0] <a href="https://github.com/rust-bitcoin/rust-miniscript/pull/246#issue-671512626">https://github.com/rust-bitcoin/rust-miniscript/pull/246#issue-671512626</a><br></div><div>[1] <a href="https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#commitment-transaction">https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#commitment-transaction</a><br></div><div class="protonmail_quote">
        ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐<br>
        Le lundi 6 septembre 2021 à 5:17 AM, Jeremy via bitcoin-dev <bitcoin-dev@lists.linuxfoundation.org> a écrit :<br>
        <blockquote class="protonmail_quote" type="cite">
            <div dir="ltr"><div><div style="font-family:arial,helvetica,sans-serif;font-size:small;color:rgb(0,0,0)">BIP 68 says >= 2:</div></div><i>This specification defines the meaning of sequence numbers for transactions with an nVersion greater than or equal to 2 for which the rest of this specification relies on.</i><div style="font-size:small"><font face="arial, helvetica, sans-serif" color="#000000"><span style="caret-color: rgb(0, 0, 0);">BIP-112 says not < 2</span></font></div><table style="box-sizing:border-box;border-spacing:0px;border-collapse:collapse;color:rgb(201,209,217);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI Variable","Segoe UI",system-ui,ui-sans-serif,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:14px"><tbody style="box-sizing:border-box"><tr style="box-sizing:border-box"><td style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;word-wrap:normal"><font color="#000000">// Fail if the transaction's version number is not set high<br>// enough to trigger BIP 68 rules.<br>if (static_cast<uint32_t>(txTo->nVersion) < 2) return false;</font></td></tr></tbody></table><div style="font-size:small"><font face="arial, helvetica, sans-serif" color="#000000"><span style="caret-color: rgb(0, 0, 0);"><br></span></font></div><div style="font-size:small"><font face="arial, helvetica, sans-serif" color="#000000"><span style="caret-color: rgb(0, 0, 0);">A further proof that this needs fix: the flawed upgradable semantic exists in script as well as in the transaction nSeqeunce. we can't really control the transaction version an output will be spent with in the future, so it would be weird/bad to change the semantic in transaction version 3.</span></font></div><div style="font-size:small"><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif"><br></span></div><div style="font-size:small"><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif">--</span><br></div><div><div data-smartmail="gmail_signature" dir="ltr"><div dir="ltr"><a target="_blank" href="https://twitter.com/JeremyRubin" rel="noreferrer nofollow noopener">@JeremyRubin</a><a target="_blank" href="https://twitter.com/JeremyRubin" rel="noreferrer nofollow noopener"></a></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Sep 5, 2021 at 7:36 PM David A. Harding <<a href="mailto:dave@dtrt.org" rel="noreferrer nofollow noopener">dave@dtrt.org</a>> wrote:<br></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex" class="gmail_quote">On Fri, Sep 03, 2021 at 08:32:19PM -0700, Jeremy via bitcoin-dev wrote:<br>
> Hi Bitcoin Devs,<br>
> <br>
> I recently noticed a flaw in the Sequence lock implementation with respect<br>
> to upgradability. It might be the case that this is protected against by<br>
> some transaction level policy (didn't see any in policy.cpp, but if not,<br>
> I've put up a blogpost explaining the defect and patching it<br>
> <a target="_blank" rel="noreferrer nofollow noopener" href="https://rubin.io/bitcoin/2021/09/03/upgradable-nops-flaw/">https://rubin.io/bitcoin/2021/09/03/upgradable-nops-flaw/</a><br>
<br>
Isn't this why BIP68 requires using tx.version=2?  Wouldn't we just<br>
deploy any new nSequence rules with tx.version>2?<br>
<br>
-Dave<br>
</blockquote></div>

        </blockquote><br>
    </div>