<div dir="ltr"><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><font color="#24292e" style="font-family:arial,helvetica,sans-serif">Discussing the possibility of a new opcode (</font><font color="#24292e" face="monospace, monospace">OP_CHECKTXOUTSCRIPTHASHVERIFY</font><font color="#24292e" style="font-family:arial,helvetica,sans-serif">) for the Bitcoin scripting system that allows a transaction output to be only spendable in a predefined manner.<br></font><br><b><font size="4">Brief Description</font></b><br><br><font color="#24292e" style="font-family:arial,helvetica,sans-serif">Bitcoin transactions have a </font><font color="#24292e" face="monospace, monospace">txoutScript</font><font color="#24292e" style="font-family:arial,helvetica,sans-serif"> (</font><font color="#24292e" face="monospace, monospace">scriptPubKey</font><font color="#24292e"><font face="arial, helvetica, sans-serif">) field for each output.<br></font><font face="monospace, monospace">txoutScriptHash=</font></font><span style="background-color:rgb(248,249,250);font-family:monospace,monospace">Hash160(txoutScript)</span><font face="arial, helvetica, sans-serif"><br></font></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><span style="font-family:arial,helvetica,sans-serif;background-color:rgb(248,249,250)"><b>Word</b>: </span><span style="background-color:rgb(248,249,250)"><font face="monospace, monospace">OP_CHECKTXOUTSCRIPTHASHVERIFY</font><br><font face="arial, helvetica, sans-serif"><b>Opcode</b>: </font><font face="monospace, monospace">184 (OP_NOP9)</font><br></span><span style="background-color:rgb(248,249,250)"><font face="arial, helvetica, sans-serif"><b>Input</b>: </font><font face="monospace, monospace">x</font></span><span style="font-family:arial,helvetica,sans-serif;background-color:rgb(248,249,250)"><br><b>Output</b>:</span><span style="font-family:arial,helvetica,sans-serif;background-color:rgb(248,249,250)"> </span><span style="background-color:rgb(248,249,250)"><font face="monospace, monospace">x / fail*</font><br></span><span style="font-family:arial,helvetica,sans-serif;background-color:rgb(248,249,250)"><b>Description</b>:<br>Marks transaction as invalid if </span><span style="background-color:rgb(248,249,250)"><font face="monospace, monospace">txoutScriptHash</font></span><span style="font-family:arial,helvetica,sans-serif;background-color:rgb(248,249,250)"> is not equal to top stack item and value of </span><span style="background-color:rgb(248,249,250)"><font face="monospace, monospace">txoutScript</font></span><span style="font-family:arial,helvetica,sans-serif;background-color:rgb(248,249,250)"> is not equal to </span><span style="color:rgb(26,26,26)"><font face="monospace, monospace">OP_HASH160 ThisRedeemScriptHash OP_EQUAL</font></span><span style="font-family:arial,helvetica,sans-serif;color:rgb(26,26,26)">*.</span></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><font face="arial, helvetica, sans-serif" size="1"><i><span style="background-color:rgb(248,249,250)">* Not entirely certain here, always have this impression new opcode has to &quot;</span><span style="background-color:rgb(248,249,250)">NOP or fail&quot; to ensure it can be implemented</span><span style="background-color:rgb(248,249,250)">. As a result, </span><span style="background-color:rgb(248,249,250)">t</span><span style="background-color:rgb(248,249,250)">he item may also has to be dropped explicitly</span><span style="background-color:rgb(248,249,250)">.<br></span></i><i>* So that change can be sent back to the this redeem script. There are challenges to generalize this as a script hash cause of some cyclic reference. Not sure if cyclic is the correct term, ie: A = hash (B&#39;s hash) and B = hash (A&#39;s hash) is impossible.</i></font></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><span style="color:rgb(36,41,46)"><b><font size="4">Sample use case</font></b></span></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><span style="color:rgb(36,41,46)">Acme has an ordinary key pair and a secure key pair. </span><span style="color:rgb(36,41,46)">The ordinary key pair is assumed to be in a less secure environment.  </span><span style="color:rgb(36,41,46)">The private key of the secure key pair will never ever expose itself until the moment it needs to revoke transaction of the ordinary key pair.<br></span></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><span style="font-family:monospace,monospace;color:rgb(26,26,26)">redeemScript:<br>  </span><span style="color:rgb(36,41,46);font-family:monospace,monospace">IF<br></span><span style="font-family:monospace,monospace;color:rgb(36,41,46)">    2 </span><span style="font-family:monospace,monospace;color:rgb(26,26,26)">&lt;Acme&#39;s pubkey&gt; </span><span style="font-family:monospace,monospace;color:rgb(26,26,26)">&lt;securePubkey&gt; 2</span><span style="font-family:monospace,monospace;color:rgb(26,26,26)"> </span><span style="font-family:monospace,monospace;color:rgb(26,26,26)">CHECKMULTISIG<br></span><span style="font-family:monospace,monospace;color:rgb(26,26,26)">  ELSE<br>    &lt;txoutScriptHash&gt; </span><span style="font-family:monospace,monospace;background-color:rgb(248,249,250)">CHECKTXOUTSCRIPTHASHVERIFY </span><font color="#000000" style="font-family:monospace,monospace"><span style="white-space:pre-wrap;background-color:rgb(248,249,250)">DROP </span></font><span style="color:rgb(26,26,26);font-family:monospace,monospace">&lt;Acme&#39;s pubkey&gt; </span><span style="color:rgb(26,26,26);font-family:monospace,monospace">CHECKSIG<br>  ENDIF</span><br></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><span style="color:rgb(36,41,46)">The only ways to spend its outputs from this <font face="monospace, monospace">ThisRedeemScript</font> is to forward it to <font face="monospace, monospace">NextRedeemScript</font>. </span><span style="color:rgb(36,41,46)">Even if the original key pair is</span><span style="color:rgb(36,41,46)"> compromised, the attacker can only spend it this way and has to publish the transaction.</span></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><font face="monospace, monospace">tx1:<br><span style="background-color:rgb(248,249,250)">  scriptSig: &lt;sig&gt; &lt;pubKey&gt; 0<br></span></font><font color="#1a1a1a"><font face="monospace, monospace">  scriptPubKey: </font></font><span style="color:rgb(26,26,26)"><font face="monospace, monospace">HASH160 &lt;Hash160(NextRedeemScript)&gt; EQUAL<br><br></font></span><font face="monospace, monospace">tx2: //if there is change<br><span style="background-color:rgb(248,249,250)">  scriptSig: &lt;sig&gt; &lt;Acme&#39;s pubKey&gt;<br></span></font><font color="#1a1a1a"><font face="monospace, monospace">  scriptPubKey: </font></font><span style="color:rgb(26,26,26)"><font face="monospace, monospace">HASH160 </font></span><span style="color:rgb(26,26,26);font-family:monospace,monospace">ThisRedeemScriptHash</span><span style="color:rgb(26,26,26)"><font face="monospace, monospace"> EQUAL<br></font></span><span style="color:rgb(26,26,26)"><font face="monospace, monospace"><br></font></span><font face="monospace, monospace" style="color:rgb(36,41,46)">NextRedeemScript</font><span style="color:rgb(36,41,46)"> is time locked. Acme is able to monitor for </span><span style="color:rgb(36,41,46)">unauthorized transactions</span><span style="color:rgb(36,41,46)"> and react within the sequence-defined duration. The combination of 2 key pair as one multisig can spend the output immediately regardless of the timelock.</span></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><span style="font-family:monospace,monospace;color:rgb(26,26,26)">NextRedeemScript</span><span style="font-family:monospace,monospace"><font color="#1a1a1a">:<br></font></span><span style="color:rgb(36,41,46);font-family:monospace,monospace">  IF<br></span><span style="font-family:monospace,monospace;color:rgb(36,41,46)">    2 </span><span style="font-family:monospace,monospace;color:rgb(26,26,26)">&lt;Acme&#39;s pubkey&gt; </span><span style="font-family:monospace,monospace;color:rgb(26,26,26)">&lt;securePubkey&gt; 2</span><span style="font-family:monospace,monospace;color:rgb(26,26,26)"> </span><span style="font-family:monospace,monospace;color:rgb(26,26,26)">CHECKMULTISIG<br></span><span style="color:rgb(26,26,26);font-family:monospace,monospace">  ELSE<br></span><span style="font-family:monospace,monospace;color:rgb(26,26,26)">    </span><font color="#1a1a1a" style="font-family:monospace,monospace">&quot;12h&quot; CHECKSEQUENCEVERIFY DROP </font><span style="font-family:monospace,monospace;color:rgb(26,26,26)">&lt;Acme&#39;s pubkey&gt; </span><span style="font-family:monospace,monospace;color:rgb(26,26,26)">CHECKSIG<br></span><span style="color:rgb(26,26,26);font-family:monospace,monospace">  ENDIF</span></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><span style="color:rgb(36,41,46)">After 12 hours, Acme is can spend the output as normal.</span><br></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><font face="monospace, monospace">tx:<br><span style="background-color:rgb(248,249,250)">  scriptSig: &lt;sig&gt; &lt;pubkey&gt; 0<br></span></font><font color="#1a1a1a"><font face="monospace, monospace">  scriptPubKey: </font></font><span style="background-color:rgb(248,249,250);color:rgb(0,0,0);font-family:monospace,courier;font-size:14px;white-space:pre-wrap">DUP HASH160 &lt;recipient&#39;s pubkeyHash&gt; EQUALVERIFY CHECKSIG</span></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px"><b style="color:rgb(36,41,46);font-size:large;font-family:arial,helvetica,sans-serif">Description</b></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46)"><span style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif">CSV and CTLV already laid the groundwork for r</span><span style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif">etroactive invalidation, showcased in innovative protocols such as HTLC of lightning network.<br><br>As illustrated from the sample use case, t</span><span style="font-family:arial,helvetica,sans-serif;color:rgb(34,34,34)">here are other classes of problems that may requires retroactive invalidation in different</span><span style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif"> and less-interactive way from channels. Most of those problems require a primitive opcode to influence how the output can be spent.</span></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46)">If the use case works as expected, attacks will be <i>less</i> rewarding. There are still other attack vectors if Acme&#39;s original key pair is compromised, i.e;<br><br>&gt; The attacker can drain the output as transaction fees.<br>There could be ways to reduce that risk, but do not intent to add complexity to a request. This additional depth of defense is an improvement to deter attacks especially if an attack is costly to pull.<br><br>&gt; After 12 hours, it may be still possible for attacker to submit transactions in concurrent or ahead of Acme.<br>Acme should submit the transaction before the 12 hours and leave it <span style="color:rgb(36,39,41);font-family:Arial,&quot;Helvetica Neue&quot;,Helvetica,sans-serif">in mempool, waiting for nSequence to elapse.</span> Attacker&#39;s transaction submitted after it <i>should be(?)</i><span style="color:rgb(36,39,41);font-family:Arial,&quot;Helvetica Neue&quot;,Helvetica,sans-serif"> rejected by the network. Attacker&#39;s transaction submitted before it will be caught by the monitoring function. Even if the above assumption is misguided, the use-case is still useful if transactions have value smaller quantity than total, that limits loss to only the transaction&#39;s value. At the same time, that reveals the fact that the key pair is compromised and the further preventive actions can be carried out using the secure key pair.</span></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46)">Possible privacy concern: The use case demonstrated change to be sent back to self (there may be related concern such as wrongly configured digital signature). The use case assumed P2SH is exceptional case, kind of like multisignature wallets, for custodians like e-commerce merchants, exchanges.</p></div>