<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aaron Recompile on Medium]]></title>
        <description><![CDATA[Stories by Aaron Recompile on Medium]]></description>
        <link>https://medium.com/@aaron.recompile?source=rss-9580f025ce6d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EYz89g1McDjSt8aZbCBNSg.png</url>
            <title>Stories by Aaron Recompile on Medium</title>
            <link>https://medium.com/@aaron.recompile?source=rss-9580f025ce6d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 18:50:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aaron.recompile/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[SIGHASH_ANYPREVOUT on Signet: When Signatures Stop Binding to UTXOs]]></title>
            <link>https://medium.com/@aaron.recompile/sighash-anyprevout-on-signet-when-signatures-stop-binding-to-utxos-eed4fc475668?source=rss-9580f025ce6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/eed4fc475668</guid>
            <category><![CDATA[lightning-network]]></category>
            <category><![CDATA[bitcoin-development]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[cryptography]]></category>
            <dc:creator><![CDATA[Aaron Recompile]]></dc:creator>
            <pubDate>Sat, 11 Apr 2026 23:02:44 GMT</pubDate>
            <atom:updated>2026-04-11T23:02:44.929Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>Standard CHECKSIG asks: did you sign for </em><strong><em>this UTXO</em></strong><em>?</em></blockquote><blockquote><em>ANYPREVOUT asks: did you sign for </em><strong><em>this kind of UTXO</em></strong><em>?</em></blockquote><blockquote>A signature normally says: “I authorize spending this exact coin.”<br>ANYPREVOUT says: “I authorize spending any coin that looks like this.”</blockquote><blockquote>Same Schnorr math. Different preimage.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDJqPG1-pS7G7dliFPGCRg.png" /></figure><pre>Bitcoin is not designed top-down.  <br>It is discovered through execution.<br><br>&quot;Run the Future&quot; — starts here.</pre><p><strong>TL;DR</strong> — Same private key, same tapscript leaf (&lt;0x01||xonly&gt; OP_CHECKSIG, 35 bytes), two different UTXOs. Sign once, copy the witness verbatim onto the second transaction — no re-signing. Both pass Inquisition consensus validation and confirm in the same block. The mechanism: BIP 118’s sighash preimage omits sha_prevouts, so the outpoint vanishes from the digest. The signature binds not to “which UTXO” but to “what shape of UTXO.”</p><h3>1. What Signatures Actually Are, and How Bitcoin Uses Them</h3><p>Schnorr signatures (BIP 340) have nothing inherently to do with Bitcoin. They simply sign a message:</p><pre>sig = Sign(privkey, message)<br>Verify(pubkey, message, sig) → true / false</pre><p>message can be anything — a text string, a file hash, a chat message. A signature proves: <strong>the holder of this private key endorsed this message.</strong> No relation to transactions whatsoever.</p><p>Bitcoin took this general-purpose tool and did something specific: <strong>it dictated what the message must be.</strong></p><p>When a script executes OP_CHECKSIG, the node does not let you pass in your own message. It automatically assembles a byte string from the current transaction’s fields — input sources, output destinations, amounts, timelocks — called the <strong>sighash preimage</strong>, then hashes it to produce a 32-byte <strong>digest</strong>. This digest is the message being signed.</p><pre>General signing:  you choose the message → sign → verify<br>CHECKSIG:         consensus rules choose the message → you just sign → node rebuilds the message to verify</pre><p><strong>So CHECKSIG is not just “verify a signature” — it turns signatures from general authorization into transaction authorization.</strong> You are not signing “I agree.” You are signing “I agree to spend this money, from here, to there.” The strength of the signature depends on which fields are stuffed into the sighash preimage.</p><h3>Where sighash comes from</h3><p>The sighash mechanism has evolved through several generations:</p><ul><li><strong>Legacy (pre-SegWit)</strong>: Serializes the entire transaction, strips different parts depending on sighash type, double SHA256. The infamous O(n²) problem originated here.</li><li><strong>BIP 143 (SegWit v0)</strong>: Redesigned the preimage format — SHA256 prevouts, sequences, and outputs once each, then plug those 32-byte hashes into the preimage. Solved O(n²).</li><li><strong>BIP 341 / 342 (Taproot / Tapscript)</strong>: Built on BIP 143 with TaggedHash(&quot;TapSighash&quot;, ...) for domain separation, added spend_type, tapleaf_hash, key_version, and other fields.</li></ul><p>Every generation adjusts the same question: <strong>which fields go into the sighash preimage?</strong> More fields means tighter binding; fewer fields means more flexibility.</p><h3>Sighash type: choosing how much to bind</h3><p>Even within the same sighash generation, the signer can choose which fields to bind via <strong>sighash type</strong>. The standard options:</p><p>sighash typeBinds all inputsBinds all outputsSIGHASH_ALL (0x01)YesYesSIGHASH_NONE (0x02)Yes<strong>No</strong>SIGHASH_SINGLE (0x03)YesSame-index output onlySIGHASH_ANYONECANPAY (0x80, combinable)<strong>Current input only</strong>Depends on the above three</p><p>These all operate on the <strong>output side</strong> — relaxing “where the money goes.” But they share one invariant: <strong>the input side never relaxes.</strong> The input you sign is permanently bound to a specific txid:vout. Once signed, that signature can only spend that one UTXO. Swap it, and the signature fails.</p><p><strong>This is exactly what BIP 118 changes.</strong></p><h3>What problem BIP 118 solves</h3><p>Scenario: you and a counterparty opened a Lightning channel and went through 100 state updates. The counterparty cheats by broadcasting the old state from round 50. You need your round-100 update transaction to override it.</p><p>But your round-100 update transaction was signed during round 100 — at that time you had no idea whether the counterparty would broadcast round 50, let alone what txid round 50 would have on-chain. Under standard CHECKSIG, the signature is bound to the prevout’s txid:vout. You cannot pre-sign a “spend any future old state” transaction.</p><p>BIP 118 (SIGHASH_ANYPREVOUT) solves this: <strong>remove </strong><strong>sha_prevouts from the sighash preimage.</strong> The signature no longer binds to a specific outpoint. As long as the UTXO’s amount and script match, the same signature works. You can pre-sign at round 100 a transaction that spends “any shape-matching old state” — whether the counterparty broadcasts round 50 or round 73.</p><p>This is the foundation of Eltoo / LN-Symmetry.</p><h3>2. SigMsg vs Msg118: What Exactly Was Removed</h3><p>Standard Tapscript (BIP 342) SigMsg assembles these fields:</p><pre>SigMsg = hash_type<br>       || nVersion || nLocktime<br>       || sha_prevouts          ← SHA256(txid₁||vout₁ || txid₂||vout₂ || ...)<br>       || sha_amounts           ← SHA256(amount₁ || amount₂ || ...)<br>       || sha_scriptpubkeys     ← SHA256(spk₁ || spk₂ || ...)<br>       || sha_sequences         ← SHA256(seq₁ || seq₂ || ...)<br>       || sha_outputs           ← SHA256(all outputs)<br>       || spend_type<br>       || input_amount          ← current input&#39;s amount<br>       || input_scriptpubkey    ← current input&#39;s scriptPubKey<br>       || input_index<br>       || ...</pre><p>sha_prevouts hashes every input’s txid:vout into the digest. Change one prevout, the hash changes, the digest changes, signature verification fails. <strong>This is the “bind to UTXO” mechanism — not some abstract design, but a line of bytes in the preimage.</strong></p><p>BIP 118’s Msg118 removes these fields:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*MaVo6dlHQr7aejXKH65ymA.png" /></figure><p>Note the subtlety: BIP 342 includes both the global sha_amounts (hash of all input amounts) and the per-input input_amount. BIP 118 keeps only the latter — if the global were retained, you would still indirectly bind to other inputs’ information.</p><p><strong>Result</strong>: the digest contains no information about which outpoint is being spent. As long as the new UTXO has the same amount and same scriptPubKey, Msg118 produces the identical byte string, the identical digest, and signature verification passes.</p><h3>3. Three Tiers of Sighash: Package Pickup</h3><p>BIP 118 defines two new sighash flags. Together with standard BIP 342, there are three tiers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*06PVfHcG7YmjcrXUxNfhrA.png" /></figure><p>Package pickup analogy:</p><ul><li><strong>Standard CHECKSIG (0x01)</strong>: The pickup slip says “collect package YT1234567890.” Only that one package — the signature is valid only for that tracking number.</li><li><strong>ANYPREVOUT (0x41)</strong>: The pickup slip says “collect any 5 kg package addressed to Zhang San.” Three qualifying packages at the station — this slip works for any of them. But it must be 5 kg, addressed to Zhang San.</li><li><strong>ANYPREVOUTANYSCRIPT (0xC1)</strong>: The pickup slip just says “Zhang San is here to pick up.” Any package will do, regardless of weight or sender, as long as the station accepts Zhang San’s ID.</li></ul><p>This experiment uses 0x41 (the middle tier), which is also the tier Eltoo / LN-Symmetry actually needs.</p><h3>4. How the Node Switches: the 0x01 Public Key Prefix</h3><p>Standard tapscript uses 32-byte x-only public keys. BIP 118 stipulates: <strong>if the public key in a tapscript is 33 bytes and the first byte is </strong><strong>0x01</strong>, the node uses BIP 118’s Msg118 + Ext118 to compute the digest when executing OP_CHECKSIG, instead of standard BIP 342’s SigMsg.</p><pre>Standard tapscript:  &lt;32-byte xonly pubkey&gt; OP_CHECKSIG   → uses BIP 342 SigMsg<br>BIP 118:             &lt;0x01 || 32-byte xonly pubkey&gt; OP_CHECKSIG → uses Msg118 + Ext118</pre><p>This is an opt-in mechanism — it does not affect any existing tapscript. Only when you explicitly use a 0x01-prefixed public key does BIP 118 sighash logic activate.</p><p>Additionally, key_version = 0x01 in Ext118 (BIP 342 uses 0x00) isolates the sighash domain: even if the public key bytes are identical, a BIP 118 signature cannot replay on a standard BIP 342 key. The two worlds do not interfere.</p><h3>5. Commit Phase: Building an APO-only P2TR Address with btcaaron</h3><pre>key = Key.from_wif(DEMO_KEY_WIF)<br><br>program = (<br>    TapTree(internal_key=key, network=&quot;signet&quot;)<br>    .bip118_checksig(key, label=&quot;apo_rebind&quot;)<br>    .build()<br>)<br>addr = program.address</pre><h3>btcaaron API Walkthrough</h3><p><strong>.bip118_checksig(key, label=&quot;apo_rebind&quot;)</strong> is a convenience wrapper around .custom(). It is equivalent to:</p><pre>apo_pk = apo_pubkey_bytes(key.xonly_bytes)   # 0x01 || xonly (33 bytes)<br>leaf_script = RawScript(build_script(push_bytes(apo_pk), OP_CHECKSIG))<br><br>program = (<br>    TapTree(internal_key=key, network=&quot;signet&quot;)<br>    .custom(script=leaf_script, label=&quot;apo_rebind&quot;)<br>).build()</pre><p>The leaf script is:</p><pre>&lt;0x01 || xonly_pubkey&gt; OP_CHECKSIG</pre><p>35 bytes (OP_PUSHBYTES_33 1 byte + 0x01||xonly 33 bytes + OP_CHECKSIG 1 byte). The 0x01 prefix tells the Inquisition node to use BIP 118 sighash. apo_pubkey_bytes() prepends the 0x01 byte to the x-only public key. The subsequent .build() → .spend() → .sign() / .unlock_with() flow is identical to all prior experiments.</p><p>Tapscript bytecode:</p><pre>21                                                                &lt;- OP_PUSHBYTES_33<br>01ff1f9fa326a9438227e6aa25030ccf89bcb8ce53db4f78dbce6146499d9986b8  &lt;- 0x01 || xonly pubkey<br>ac                                                                &lt;- OP_CHECKSIG</pre><h3>Funding Two Identical UTXOs</h3><pre>txid1 = wallet_send_sats(rpc_wallet, addr, 50_000)<br>txid2 = wallet_send_sats(rpc_wallet, addr, 50_000)</pre><p>Two independent wallet transfers, 50,000 sats each, sent to the same P2TR address. Two UTXOs with the same amount and scriptPubKey, but different txids.</p><h3>6. Reveal Phase: Sign Once, Spend Twice</h3><pre># Sign the first UTXO normally<br>tx1 = (<br>    program.spend(&quot;apo_rebind&quot;)<br>    .from_utxo(u1_txid, u1_vout, sats=50_000)<br>    .to(change_addr, 47_000)<br>    .sign(key)          # ← internally calls key.sign_taproot_script_bip118()<br>    .build()<br>)<br><br># Extract the witness stack<br>stack = tx1._tx.witnesses[0].stack   # [sig, leaf_script, control_block]<br># Attach the same witness to the second transaction - no re-signing<br>tx2 = (<br>    program.spend(&quot;apo_rebind&quot;)<br>    .from_utxo(u2_txid, u2_vout, sats=50_000)<br>    .to(change_addr, 47_000)<br>    .unlock_with([stack[0].hex(), stack[1].hex(), stack[2].hex()])<br>    .build()<br>)<br>out1 = broadcast_or_raise(tx1.hex)<br>out2 = broadcast_or_raise(tx2.hex)</pre><h3>btcaaron Signing API Walkthrough</h3><p><strong>.sign(key)</strong>, upon detecting that the current leaf uses a BIP 118 public key, internally calls:</p><pre>key.sign_taproot_script_bip118(<br>    tx, txin_index=0,<br>    utxo_scripts=[scriptPubKey],<br>    amounts=[50_000],<br>    tapleaf_script=leaf,<br>    hash_type=0x41,      # SIGHASH_ALL | SIGHASH_ANYPREVOUT<br>)</pre><p>This method calls bip118_sighash() to construct Msg118 || Ext118, computes TaggedHash(&quot;TapSighash&quot;, 0x00 || msg || ext) to get a 32-byte digest, then produces a BIP 340 Schnorr signature, appends sighash byte 0x41, returning 65 bytes (130 hex chars).</p><p><strong>.unlock_with([sig, leaf, cb])</strong> does not sign — it directly uses the three provided hex strings as the witness stack. Because Msg118 does not contain the outpoint, the witness from the first spend is equally valid on the second.</p><h3>7. Transaction Structure and On-chain Evidence</h3><h3>Funding: Two Independent Wallet Transfers</h3><p>TxIDAmountFunding A<a href="https://mempool.space/signet/tx/4b6451082fe4349fdb2acad6bf0964c6cfd8c9cbf5161806fc342b051dee344a?showDetails=true">4b64…344a</a>50,000 satsFunding B<a href="https://mempool.space/signet/tx/543c97f777ea04624392f6a1547146d6e98996b38aec0794f6b79e3275f6a5eb?showDetails=true">543c…a5eb</a>50,000 sats</p><p>Both pay to: tb1prpa4a7wc0v5ghesn8pqhz7uw6lccd5u52rgzcfdqv3kwd3ptapcqnt93g2</p><h3>Reveal: The Rebinding Pair</h3><p>TxIDPrevoutOutputSpend A (signed)<a href="https://mempool.space/signet/tx/03c0577c1d47da32804d098187644d0eee18b448aded2f427cd02193c070f3a4?showDetails=true">03c0…f3a4</a>4b64…344a:047,000 satsSpend B (reused witness)<a href="https://mempool.space/signet/tx/46091190c74d8fd4b39be67a2e945a19b021850e7f8d9e378f5eb11722ae1a43?showDetails=true">4609…1a43</a>543c…a5eb:047,000 sats</p><p>Both confirmed in Inquisition signet block 298,280. 3,000 sats fee.</p><h3>Witness Comparison</h3><p>Decoding both spend transactions on mempool.space, the witness stacks are byte-for-byte identical:</p><pre>Witness[0] = 902004a5...b5fa04064bdc41   &lt;- Schnorr signature + sighash byte 0x41 (65 bytes)<br>Witness[1] = 2101ff1f...9986b8ac         &lt;- tapscript (35 bytes)<br>Witness[2] = c1ff1f9fa3...9986b8         &lt;- control block (33 bytes)</pre><p><strong>Witness[0]</strong>: 64-byte Schnorr signature with 0x41 (SIGHASH_ALL | SIGHASH_ANYPREVOUT) appended, totaling 65 bytes.</p><p><strong>Witness[1]</strong>: 21 (OP_PUSHBYTES_33) + 01||xonly_pubkey (33 bytes) + ac (OP_CHECKSIG) = 35 bytes. The BIP 118 leaf script.</p><p><strong>Witness[2]</strong>: Control block starts with c1. c1 = leaf version 0xc0 + parity bit 1. The parity bit is determined by the Y-coordinate parity of the output key Q after TapTweak computation — c0 for even, c1 for odd; it cannot be chosen in advance. Followed by 32-byte internal public key, totaling 33 bytes.</p><p>Different inputs, same witness, both confirmed. <strong>This is rebinding.</strong></p><h3>Negative Test</h3><p>Modifying Spend B’s output address or amount causes script verification failure. sha_outputs remains in Msg118 (SIGHASH_ALL mode) — the signature commits to where the money goes. <strong>Rebinding lets you swap the input, not the destination.</strong></p><h3>8. Rebuilding the Address with RootScope</h3><p>The tapscript is 35 bytes: OP_PUSHBYTES_33 (0x21) + 0x01||xonly_pubkey (33 bytes) + OP_CHECKSIG (0xac). The derivation chain is identical to the single-leaf TapTree used in all prior experiments.</p><h3>Derivation Chain</h3><pre>TapLeaf hash = tagged_hash(&quot;TapLeaf&quot;,  0xc0 || compact_size(35) || script_bytes)<br>               (leaf version 0xc0, script length 35, script = 21 01||xonly ac)<br>Merkle root  = TapLeaf hash<br>Tweak t      = tagged_hash(&quot;TapTweak&quot;,  internal_pubkey || Merkle root)<br>Output key Q = internal_pubkey + t*G<br>P2TR address = Bech32m(&quot;tb&quot;, Q.x_only)</pre><h3>Verification Code</h3><pre>internal_pubkey = bytes.fromhex(<br>    &quot;ff1f9fa326a9438227e6aa25030ccf89bcb8ce53db4f78dbce6146499d9986b8&quot;<br>)<br>script_bytes = bytes.fromhex(<br>    &quot;2101ff1f9fa326a9438227e6aa25030ccf89bcb8ce53db4f78dbce6146499d9986b8ac&quot;<br>)<br><br>tapleaf_hash = tagged_hash(<br>    &quot;TapLeaf&quot;,<br>    # compact_size(35) = 0x23, single byte since 35 &lt; 253<br>    bytes([0xc0]) + bytes([len(script_bytes)]) + script_bytes,<br>)<br>merkle_root = tapleaf_hash<br>tweak = tagged_hash(&quot;TapTweak&quot;, internal_pubkey + merkle_root)<br>Q    = Key.from_x_only(internal_pubkey).tweak_add(tweak)<br>addr = Q.to_p2tr_address(network=&quot;signet&quot;)<br># Expected: tb1prpa4a7wc0v5ghesn8pqhz7uw6lccd5u52rgzcfdqv3kwd3ptapcqnt93g2  [OK]</pre><h3>RootScope Visualization</h3><pre>Internal key<br>  ff1f9fa3...9986b8<br>        |<br>    TapLeaf (0xc0)<br>    Script: 2101&lt;01||xonly&gt;ac  (35 bytes)<br>                 ^--- 0x01 prefix triggers BIP 118 sighash<br>        |<br>    TapLeaf hash<br>        |   (no sibling -&gt; single-leaf tree)<br>    Merkle root<br>        |<br>    TapTweak<br>        |<br>    Output key Q  (parity: odd -&gt; control block byte = c1)<br>        |<br>    P2TR address<br>    tb1prpa4a7wc0v5ghesn8pqhz7uw6lccd5u52rgzcfdqv3kwd3ptapcqnt93g2  [OK]</pre><p>The control block starts with c1 — the same odd-parity result as the IK+CSFS experiment, but for a different reason: this 35-byte BIP 118 script produces a different TapLeaf hash, and after tweaking, the output key Q’s Y-coordinate happens to be odd. Same internal_pubkey (ff1f9fa3...9986b8) as all prior experiments, different tapscript, different Merkle root, different TapTweak, different address.</p><h3>9. Cross-validation: Two Independent Implementations Agree on One Spec</h3><p>Two confirmed transactions mean two independent implementations agreed on the digest:</p><ul><li><strong>Signing side</strong> (Python, btcaaron/bip118.py): constructs Msg118 || Ext118, TaggedHash(&quot;TapSighash&quot;, ...), BIP 340 signature</li><li><strong>Validation side</strong> (C++, Bitcoin Inquisition): reconstructs the same digest from the transaction, verifies the Schnorr signature</li></ul><p>Bitcoin Core’s wallet and CLI do not support constructing BIP 118 signatures — there is no signrawtransaction --sighash=anyprevout. Signing must be done externally. btcaaron/bip118.py is a Python implementation independent of Core’s test framework, building Msg118 / Ext118 byte assembly from the <a href="https://github.com/bitcoin/bips/blob/master/bip-0118.mediawiki">BIP 118 specification</a>.</p><p>On-chain confirmation is the strictest test: if my implementation and Inquisition’s C++ disagree on any byte, the transaction gets rejected.</p><h3>10. Why This Matters for Eltoo</h3><p>ANYPREVOUT is the infrastructure for <a href="https://blockstream.com/eltoo.pdf">Eltoo (LN-Symmetry)</a>. In Eltoo, channel state update transactions need to be able to spend <strong>any prior state’s</strong> UTXO:</p><pre>Counterparty cheats by broadcasting old State v2 (txid: aaaa...)<br>You need your State v5 update transaction to override it<br>But State v5 was pre-signed during round 5 — you didn&#39;t know State v2 would ever go on-chain</pre><p>0x41 makes this possible: <strong>when pre-signing, you don’t need to know the txid — just that the amount and scriptPubKey match.</strong> Because all rounds’ state UTXOs share the same “lock” (same amount + same script), the signature you pre-signed works against any round.</p><p>Building on this signing code, I also ran a three-round Eltoo-style state chain (APO updates + CTV settlement), with all six transactions confirmed on the same signet — details at the <a href="https://delvingbitcoin.org/t/bip-118-signing-from-scratch-on-chain-rebinding-proof/">BIP 118 implementation post on Delving Bitcoin</a> and the <a href="https://delvingbitcoin.org/t/challenge-covenants-for-braidpool/1370/2">Braidpool covenant challenge reply</a>.</p><h3>Series Position</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QlprdkDv_zrQbU6evXWVzQ.png" /></figure><h3>What We Did</h3><p>We ran an on-chain BIP 118 SIGHASH_ANYPREVOUT experiment: a 35-byte tapscript (&lt;0x01||xonly&gt; OP_CHECKSIG), two UTXOs with the same amount and scriptPubKey. After signing the first UTXO, we copied the full witness — 65-byte Schnorr signature (sighash byte 0x41), 35-byte leaf script, 33-byte control block — verbatim onto the second transaction. No re-signing. Both broadcast, both confirmed in Inquisition signet block 298,280.</p><p>Signing was done with btcaaron’s Key.sign_taproot_script_bip118(), which internally calls the independently implemented Msg118 / Ext118 / TaggedHash(&quot;TapSighash&quot;, ...) construction in bip118.py. This is a Python implementation independent of Bitcoin Core’s test framework — on-chain confirmation means it agrees byte-for-byte with Inquisition’s C++ consensus engine on the BIP 118 specification.</p><p>Negative testing confirmed the boundary: modifying the second transaction’s output address or amount causes script verification failure. Under SIGHASH_ALL, sha_outputs remains in Msg118. Rebinding relaxes “which UTXO to spend,” not “where the money goes.”</p><h3>References</h3><ul><li>BIP 118 specification: <a href="https://github.com/bitcoin/bips/blob/master/bip-0118.mediawiki">github.com/bitcoin/bips/bip-0118</a></li><li>btcaaron toolkit: <a href="https://github.com/aaron-recompile/btcaaron">github.com/aaron-recompile/btcaaron</a></li><li>BIP 118 sighash implementation: <a href="https://github.com/aaron-recompile/btcaaron/blob/main/btcaaron/bip118.py">btcaaron/bip118.py</a></li><li>Rebinding demo script: <a href="https://github.com/aaron-recompile/btcaaron/blob/main/examples/braidpool/rca_taptree_smoke.py">examples/braidpool/rca_taptree_smoke.py</a></li><li>Bitcoin Inquisition: <a href="https://github.com/bitcoin-inquisition/">github.com/bitcoin-inquisition</a></li><li>RootScope visualization tool: <a href="https://github.com/aaron-recompile/rootscope">github.com/aaron-recompile/rootscope</a></li></ul><p><em>Signet | Bitcoin Inquisition 29.2 | Funding </em><a href="https://mempool.space/signet/tx/4b6451082fe4349fdb2acad6bf0964c6cfd8c9cbf5161806fc342b051dee344a?showDetails=true"><em>4b64…344a</em></a><em> </em><a href="https://mempool.space/signet/tx/543c97f777ea04624392f6a1547146d6e98996b38aec0794f6b79e3275f6a5eb?showDetails=true"><em>543c…a5eb</em></a><em> | Spend A </em><a href="https://mempool.space/signet/tx/03c0577c1d47da32804d098187644d0eee18b448aded2f427cd02193c070f3a4?showDetails=true"><em>03c0…f3a4</em></a><em> | Spend B </em><a href="https://mempool.space/signet/tx/46091190c74d8fd4b39be67a2e945a19b021850e7f8d9e378f5eb11722ae1a43?showDetails=true"><em>4609…1a43</em></a><em> | Confirmed in block 298,280</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eed4fc475668" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OP_CAT + OP_CHECKSIGFROMSTACK on Signet — Dynamic Message, Oracle Authorization]]></title>
            <link>https://medium.com/@aaron.recompile/op-cat-op-checksigfromstack-on-signet-dynamic-message-oracle-authorization-8c73e1ef5353?source=rss-9580f025ce6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c73e1ef5353</guid>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[opcodes]]></category>
            <category><![CDATA[taproot]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[schnorr-signature]]></category>
            <dc:creator><![CDATA[Aaron Recompile]]></dc:creator>
            <pubDate>Fri, 27 Mar 2026 18:51:00 GMT</pubDate>
            <atom:updated>2026-03-27T18:51:00.569Z</atom:updated>
            <content:encoded><![CDATA[<h3>OP_CAT + OP_CHECKSIGFROMSTACK on Signet — Dynamic Message, Oracle Authorization</h3><blockquote><em>IK + CSFS asks: did the owner sign this? CAT + CSFS asks: did the oracle sign what the stack assembled?</em></blockquote><blockquote>The interesting question is not what an opcode does.<br>It is what emerges when they compose.</blockquote><pre>The interesting question is not what an opcode does.<br>It is what emerges when they compose.<br><br>Bitcoin is not designed top-down.<br>It is discovered through execution.<br>&quot;Run the Future&quot; - continues here.</pre><p><strong>TL;DR</strong> — Four opcodes, 36 bytes (7ea820...cc). OP_CAT assembles the signed message on-chain from two witness fragments. OP_SHA256 fixes it to a 32-byte digest. An oracle pubkey hardcoded in the script authorizes exactly that digest via OP_CHECKSIGFROMSTACK. The signer never saw the transaction — they only signed a price quote. The witness carries the raw material; the script determines what counts as authorization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZtyuQZ2vm3Cb7UqleQxkIA.png" /></figure><h3>From Identity to Message</h3><p>The previous combo experiment established one axis of the binding surface: <em>who</em> is authorized. OP_INTERNALKEY pulls the UTXO’s internal key from the Taproot execution context; OP_CHECKSIGFROMSTACK verifies that this specific key holder signed the message. The pubkey moves from the witness into the structure of the UTXO itself.</p><p>This experiment shifts to a different axis: <em>what is being authorized</em>, and specifically, <em>how the authorized message is constructed</em>.</p><p>In every previous CSFS experiment — solo or combined — the witness hands the message in whole. It is a static 32-byte blob: SHA256(&quot;hello world&quot;), SHA256(&quot;authorized:group_combo_ik_csfs:v1&quot;). The signer commits to a pre-known string, and the verifier checks it. The message content is determined before the script runs.</p><p>OP_CAT changes that. Combined with OP_SHA256 and OP_CSFS, it makes the message a runtime product of execution. The witness provides raw fragments — two byte strings that the script assembles, hashes, and then checks a signature against. The oracle never sees the assembled form; they sign semantic components. The final authorization target is constructed on-chain.</p><p>This is the <strong>oracle-gate pattern</strong>: the script commits to an authorized signer (the oracle pubkey), but not to the authorized message. The message is determined by what the spender supplies. The oracle attests to a statement structure — “a price reading of the form ASSET=VALUE&quot; — and any spend that presents matching fragments with a valid oracle signature passes.</p><pre>Binding surface evolution:<br>  CSFS          pubkey: witness    message: witness (static whole)<br>  IK + CSFS     pubkey: context    message: witness (static whole)<br>  CAT + CSFS    pubkey: script     message: assembled on-chain from witness parts</pre><p>The pubkey is now in the script itself, hardcoded at UTXO creation time. The message is not pre-committed anywhere — it emerges from execution.</p><h3>The CAT+CSFS Contract</h3><p>The locking script is:</p><pre>OP_CAT<br>OP_SHA256<br>OP_PUSHBYTES_32 &lt;oracle_pubkey&gt;<br>OP_CHECKSIGFROMSTACK</pre><p>The oracle signs a message offline. The spender provides two fragments and the signature. The script assembles the fragments, hashes them, pushes the oracle pubkey, and verifies.</p><p>For this experiment: PART1 = &quot;BTC_USD=&quot;, PART2 = &quot;100000&quot;. The oracle attests to a price reading.</p><p>Compare the three CSFS variants:</p><pre>Standalone CSFS:<br>  witness  = [sig, message, pubkey]<br>  script   = OP_CHECKSIGFROMSTACK<br><br>IK + CSFS:<br>  witness  = [sig, message]<br>  script   = OP_INTERNALKEY OP_CHECKSIGFROMSTACK<br>CAT + CSFS:<br>  witness  = [sig, PART1, PART2]<br>  script   = OP_CAT OP_SHA256 &lt;oracle_pubkey&gt; OP_CHECKSIGFROMSTACK</pre><p>In the CAT+CSFS version, the message is absent from the witness as a unit. It does not exist until OP_CAT runs. The oracle pubkey is not in the witness at all — it is embedded in the script, committed at UTXO creation time.</p><h3>The Contract Design</h3><pre>Oracle offline:<br>  FULL_MESSAGE = PART1 || PART2 = &quot;BTC_USD=100000&quot;<br>  MESSAGE_HASH = SHA256(&quot;BTC_USD=100000&quot;)<br>               = d97200147349b678a5f38c5e5cf95181476b4961ef6566570f88c3ea9b4ccc73<br>  sig          = Schnorr.sign(oracle_key, MESSAGE_HASH)<br><br>At spend time, witness provides:<br>  Witness[0] = sig    (64 bytes)<br>  Witness[1] = PART1  &quot;BTC_USD=&quot; (8 bytes)<br>  Witness[2] = PART2  &quot;100000&quot;   (6 bytes)<br>Script constructs the message on-chain:<br>  CAT    -&gt; &quot;BTC_USD=100000&quot;<br>  SHA256 -&gt; d97200...ccc73   (same hash oracle signed)<br>  PUSH oracle_pk<br>  CSFS   -&gt; verify sig(MESSAGE_HASH, oracle_pk) -&gt; TRUE</pre><p>The tapscript bytecode:</p><pre>7e                                               &lt;- OP_CAT<br>a8                                               &lt;- OP_SHA256<br>20                                               &lt;- OP_PUSHBYTES_32<br>ff1f9fa326a9438227e6aa25030ccf89bcb8ce53db4f78dbce6146499d9986b8<br>cc                                               &lt;- OP_CHECKSIGFROMSTACK (OP_RETURN_204 on standard nodes)</pre><p>36 bytes. The oracle pubkey is the only constant embedded in the script — the message structure is implicit in the oracle’s signing convention, not enforced by the bytecode.</p><p><strong>A note on the demo key.</strong> In this experiment, ORACLE_PUBKEY is derived from the same WIF as the TapTree&#39;s internal key — the oracle and the UTXO creator are the same entity. This is a deliberate simplification to keep the experiment self-contained. In production the two would be distinct: the internal key held by whoever deploys the contract, the oracle pubkey belonging to an independent data provider. The script mechanism is identical either way. When the two keys are the same, the oracle gate reduces to self-authorization. When they differ, it becomes a genuine third-party attestation gate — which is the pattern worth building toward.</p><h3>Commit Phase: Building the Taproot Address with btcaaron</h3><pre>PART1 = b&quot;BTC_USD=&quot;<br>PART2 = b&quot;100000&quot;<br>FULL_MESSAGE = PART1 + PART2<br>MESSAGE_HASH = hashlib.sha256(FULL_MESSAGE).digest()<br><br>key = Key.from_wif(DEMO_KEY_WIF)<br>ORACLE_PUBKEY = bytes.fromhex(key.xonly)<br>leaf_script = RawScript(<br>    build_script(<br>        OP_CAT,<br>        OP_SHA256,<br>        push_bytes(ORACLE_PUBKEY),<br>        OP_CHECKSIGFROMSTACK,<br>    )<br>)<br>program = (<br>    TapTree(internal_key=key, network=&quot;signet&quot;)<br>    .custom(script=leaf_script, label=&quot;cat_csfs&quot;)<br>).build()<br>addr = program.address</pre><h3>btcaaron API Highlights</h3><p><strong>build_script(OP_CAT, OP_SHA256, push_bytes(ORACLE_PUBKEY), OP_CHECKSIGFROMSTACK)</strong> assembles the 36-byte tapscript. OP_CAT and OP_CHECKSIGFROMSTACK are imported from experiments.opcodes as raw bytes 0x7e and 0xcc — proposed opcodes defined in the experiment layer rather than btcaaron&#39;s standard primitives. push_bytes(ORACLE_PUBKEY) encodes the 32-byte oracle pubkey with the 0x20 length prefix.</p><p><strong>TapTree(...).custom(script, label).build()</strong> derives the P2TR address via the same TapLeaf → Merkle root → TapTweak → output key chain as all previous experiments. A 36-byte script produces the same derivation structure as any other single-leaf tree.</p><h3>Funding the Address</h3><pre>txid = fund_address(addr, FUND_TXID_FILE, fund_sats=50_000)</pre><h3>Reveal Phase: Spending with Sig and Fragments</h3><p>The witness is three items: the oracle signature, and the two fragments that the script will assemble on-chain. The assembled message never appears in the witness — it is a runtime product.</p><pre>def _make_witness():<br>    secret = wif_secret_bytes(DEMO_KEY_WIF)<br>    sk = PrivateKey(secret, raw=True)<br>    sig = sk.schnorr_sign(MESSAGE_HASH, &quot;&quot;, raw=True)<br>    return [sig.hex(), PART1.hex(), PART2.hex()]<br><br>tx = (<br>    program.spend(&quot;cat_csfs&quot;)<br>    .from_utxo(txid, vout, sats=sats)<br>    .to(change_addr, sats - fee_sats)<br>    .unlock_with(_make_witness())<br>    .build()<br>)<br>reveal_txid = broadcast_or_raise(tx.hex)</pre><h3>btcaaron Spend API</h3><p><strong>_make_witness()</strong> returns [sig, PART1, PART2]. Elements are pushed in list order, so sig lands at the bottom of the execution stack, PART1 in the middle, and PART2 at the top. This is what OP_CAT expects: it pops the top two elements and concatenates as bottom || top, producing PART1 || PART2.</p><p><strong>pk.schnorr_sign(MESSAGE_HASH, &quot;&quot;, raw=True)</strong> signs the 32-byte digest of the fully assembled message. The oracle signs a pre-computed hash — they never interact with the transaction or the fragments individually.</p><p>The final witness layout:</p><pre>Witness[0] = e3e78a8f...83cfde       &lt;- Schnorr sig (64 bytes)<br>Witness[1] = 4254435f5553443d        &lt;- PART1: &quot;BTC_USD=&quot; (8 bytes)<br>Witness[2] = 313030303030            &lt;- PART2: &quot;100000&quot; (6 bytes)<br>Witness[3] = 7ea820ff1f9f...9986b8cc &lt;- tapscript (36 bytes)<br>Witness[4] = c1ff1f9fa3...9986b8     &lt;- control block (33 bytes)</pre><h3>Transactions, OP_RETURN_204, and Stack Trace</h3><h3>Commit: what lands on-chain</h3><p><strong>TxID</strong>: <a href="https://mempool.space/signet/tx/926c40c1b72edb904a3bb7bf96795f351a6be597fc1aeab1390c15e0133b008f?showDetails=true">926c40c1...008f</a></p><pre>Timestamp     : 2026-03-21 12:24:18 UTC<br>Confirmed     : after 9 minutes<br>Fee           : 155 sats  (1.01 sat/vB)<br>Features      : SegWit | Taproot | RBF<br><br>INPUT<br>  tb1p2nmwxkf...psdvg7ky    0.00132441 sBTC<br>OUTPUTS<br>  tb1p7vd6g2a...nscrqdhy    0.00082286 sBTC  &lt;- change<br>  tb1peaj5tna...csd84jel    0.00050000 sBTC  &lt;- CAT+CSFS lock UTXO</pre><p>The output tb1peaj5tna...csd84jel is a standard P2TR address. No observer can tell from the outside that a 36-byte oracle-gate script is committed in the script path.</p><h3>Reveal: what mempool.space shows</h3><p><strong>TxID</strong>: <a href="https://mempool.space/signet/tx/75db54dea1f125174699710bd5b517ae13b6e09b3293a0b0f463ea5561a65ca2?showDetails=true">75db54de...65ca2</a></p><pre>Timestamp  : 2026-03-21 12:24:18 UTC<br>Fee        : 500 sats  (3.77 sat/vB)<br>Features   : SegWit | Taproot | RBF<br><br>INPUT<br>  tb1peaj5tna...csd84jel    0.00050000 sBTC<br>OUTPUT<br>  tb1p0tmlqak...xqcuvjzl    0.00049500 sBTC  (V1_P2TR)</pre><p>The witness as shown by mempool.space:</p><pre>Witness[0]  e3e78a8f93d0349a4c20694ed93a4593a0179615667d<br>            a0078658973ee8d939bf146c574398ed3af179b560306b<br>            2f8508aa33598b262d783b786c709dcd83cfde<br>            &lt;- Schnorr sig (64 bytes)<br><br>Witness[1]  4254435f5553443d<br>            &lt;- &quot;BTC_USD=&quot; (8 bytes)<br>Witness[2]  313030303030<br>            &lt;- &quot;100000&quot; (6 bytes)<br>Witness[3]  7ea820ff1f9fa326a9438227e6aa25030ccf89bcb8ce<br>            53db4f78dbce6146499d9986b8cc<br>            &lt;- tapscript: OP_CAT OP_SHA256 OP_PUSHBYTES_32 &lt;oracle_pk&gt; OP_RETURN_204<br>Witness[4]  c1ff1f9fa326a9438227e6aa25030ccf89bcb8ce53db<br>            4f78dbce6146499d9986b8<br>            &lt;- control block (leaf version 0xc0 + odd parity + internal pubkey)</pre><p>nSequence for this input is 0xfffffffd — RBF is enabled. This differs from the CTV experiment where 0xffffffff was required by the template hash commitment. Here the output template is unconstrained; the spender is free to replace the transaction to adjust fees.</p><h3>The OP_RETURN_204 label</h3><p>mempool.space decodes the tapscript and displays:</p><pre>P2TR tapscript   OP_CAT  OP_SHA256  OP_PUSHBYTES_32 ff1f9f...9986b8  OP_RETURN_204</pre><p>OP_RETURN_204 is the explorer&#39;s label for opcode 0xcc = 204 decimal. On standard nodes without BIP348 active, 204 falls in the OP_SUCCESS range (BIP342 opcodes 187–254), causing the tapscript to pass immediately without checking the signature. On Bitcoin Inquisition 29.2 with BIP348 active, the same byte is OP_CHECKSIGFROMSTACK — the node pops pubkey, message, and sig from the stack and runs BIP340 Schnorr verification.</p><p>Notably, OP_CAT and OP_SHA256 are shown correctly by mempool.space — they are recognized opcodes on standard nodes (CAT via BIP347, SHA256 via existing script support). Only the final 0xcc is unknown to the standard decoder. The word &quot;RETURN&quot; in OP_RETURN_204 is not OP_RETURN the data-embedding opcode; it is mempool.space&#39;s naming convention for unrecognized opcodes.</p><h3>Stack execution</h3><p><strong>Executing</strong>: OP_CAT OP_SHA256 OP_PUSHBYTES_32 &lt;oracle_pubkey&gt; OP_CHECKSIGFROMSTACK</p><p>The Taproot interpreter strips Witness[3] (script) and Witness[4] (control block), loading Witness[0..2] as the initial execution stack.</p><h4>Initial State: three witness items loaded</h4><pre>+--------------------------------------------+<br>| 313030303030                               |  &lt;- &quot;100000&quot;   (Witness[2], PART2, top)<br>| 4254435f5553443d                           |  &lt;- &quot;BTC_USD=&quot; (Witness[1], PART1)<br>| e3e78a8f...83cfde                          |  &lt;- Schnorr sig (Witness[0], bottom)<br>+--------------------------------------------+</pre><p>Two fragments and a signature. The assembled message does not exist yet. The oracle pubkey is not on the stack — it is waiting in the script.</p><h4>Step 1 — OP_CAT: pop top two, push concatenation</h4><pre>+--------------------------------------------+<br>| 4254435f5553443d313030303030               |  &lt;- &quot;BTC_USD=100000&quot; (14 bytes)<br>| e3e78a8f...83cfde                          |  &lt;- sig (still on stack)<br>+--------------------------------------------+</pre><p>OP_CAT pops &quot;100000&quot; (top), then &quot;BTC_USD=&quot; (next), and concatenates as bottom || top. The full price-reading string materializes on-chain for the first time. BIP347&#39;s 520-byte ceiling is nowhere near approached — 14 bytes is well within bounds.</p><h4>Step 2 — OP_SHA256: pop top, push its SHA256</h4><pre>+--------------------------------------------+<br>| d97200147349b678...b4ccc73                 |  &lt;- SHA256(&quot;BTC_USD=100000&quot;) (32 bytes)<br>| e3e78a8f...83cfde                          |  &lt;- sig<br>+--------------------------------------------+</pre><p>This is the exact 32-byte digest the oracle signed offline. The hash is deterministic — given the same PART1 and PART2, it always produces the same MESSAGE_HASH.</p><h4>Step 3 — OP_PUSHBYTES_32: push oracle pubkey from script</h4><pre>+--------------------------------------------+<br>| ff1f9fa3...9986b8                          |  &lt;- oracle_pubkey (from script)<br>| d97200147349b678...b4ccc73                 |  &lt;- MESSAGE_HASH<br>| e3e78a8f...83cfde                          |  &lt;- sig<br>+--------------------------------------------+</pre><p>The oracle pubkey arrives from the locking script, not the witness. It was committed at UTXO creation time. The spender cannot substitute a different key.</p><h4>Step 4 — OP_CHECKSIGFROMSTACK: pop pubkey, message, sig — verify — push result</h4><pre>+--------------------------------------------+<br>| 01                                         |  &lt;- TRUE<br>+--------------------------------------------+</pre><p>OP_CSFS pops all three items (top-first: pubkey → message → sig) and runs BIP340 Schnorr verification:</p><pre>verify: Schnorr(sig  = e3e78a8f...83cfde,<br>                msg  = d97200147349b678...b4ccc73,<br>                pub  = ff1f9fa3...9986b8)<br>result: VALID -&gt; push 01</pre><p>Script terminates with a single truthy value. The spend is valid.</p><h4>Why the sig doesn’t cover the transaction</h4><p>The oracle signed SHA256(&quot;BTC_USD=100000&quot;) — computed before the UTXO existed. The signature does not bind to input amounts, output addresses, or sequence numbers. Anyone who obtains this oracle signature can construct a spend with any output structure and pass the CSFS check, provided they also supply the matching fragments. This is not a flaw — it is the oracle pattern. The oracle attests to a fact about the world; what happens to funds after that attestation is a separate contract design question, typically addressed by combining CAT+CSFS with OP_CTV to lock the output destination alongside the oracle condition.</p><h3>A Structural Boundary: Replay</h3><p>In this experiment the oracle signs the string &quot;BTC_USD=100000&quot;. Once the reveal transaction is on-chain, the (sig, PART1, PART2) triple is permanently visible in the witness. If a second UTXO existed with the same 7ea820...cc script — same oracle pubkey — that triple could be replayed against it. The fragments match, the hash matches, the sig verifies — the spend passes.</p><p>This is an oracle-gate contract behaving exactly as designed. The oracle attested to a real-world fact at a point in time. The attestation is inherently transferable to any UTXO that accepts it. If you want each oracle signature to be valid for exactly one spend, include UTXO-specific data in the fragments:</p><pre>PART1 = b&quot;BTC_USD=100000|txid=&quot;<br>PART2 = bytes.fromhex(txid)   # 32 bytes of the input UTXO&#39;s txid</pre><p>Now SHA256(PART1 || PART2) commits to a specific UTXO. The oracle signs a UTXO-bound attestation. Replay is structurally closed.</p><p>IK+CSFS established <em>who</em> can authorize. CAT+CSFS establishes <em>what</em> the authorization covers and hands the message construction to the execution stack. Combining all three — IK to bind signer identity, CAT to build a spend-specific message, CSFS to verify — produces authorization with no replay surface at any layer.</p><h3>Address Reconstruction with RootScope</h3><p>The tapscript is 36 bytes: 7e (OP_CAT) + a8 (OP_SHA256) + 20 (OP_PUSHBYTES_32) + 32-byte oracle pubkey + cc (OP_CHECKSIGFROMSTACK).</p><h3>The Derivation Chain</h3><pre>TapLeaf hash = tagged_hash(&quot;TapLeaf&quot;,  0xc0 || 0x24 || script_bytes)<br>               (leaf version 0xc0, script length 36 = 0x24)<br>Merkle root  = TapLeaf hash<br>tweak t      = tagged_hash(&quot;TapTweak&quot;,  internal_pubkey || merkle_root)<br>output key Q = internal_pubkey + t*G<br>P2TR address = Bech32m(&quot;tb&quot;, Q.x_only)</pre><h3>Verification Code</h3><pre>ORACLE_PUBKEY = bytes.fromhex(<br>    &quot;ff1f9fa326a9438227e6aa25030ccf89bcb8ce53db4f78dbce6146499d9986b8&quot;<br>)<br>script_bytes = bytes([0x7e, 0xa8, 0x20]) + ORACLE_PUBKEY + bytes([0xcc])<br><br>tapleaf_hash = tagged_hash(<br>    &quot;TapLeaf&quot;,<br>    bytes([0xc0]) + bytes([len(script_bytes)]) + script_bytes,<br>)<br>merkle_root = tapleaf_hash<br>internal_pubkey = bytes.fromhex(<br>    &quot;ff1f9fa326a9438227e6aa25030ccf89bcb8ce53db4f78dbce6146499d9986b8&quot;<br>)<br>tweak = tagged_hash(&quot;TapTweak&quot;, internal_pubkey + merkle_root)<br>Q    = Key.from_x_only(internal_pubkey).tweak_add(tweak)<br>addr = Q.to_p2tr_address(network=&quot;signet&quot;)<br># Expected: tb1peaj5tna...csd84jel  [OK]</pre><p>Notice: the same internal_pubkey (ff1f9fa3...9986b8) appears as both the TapTree construction key and the oracle pubkey embedded in the script. In this demo, the oracle and the UTXO creator are the same entity. In production these would typically be distinct — the internal key held by the contract operator, the oracle pubkey by an independent data provider.</p><h3>RootScope Visual Output</h3><pre>Internal Key<br>  ff1f9fa3...9986b8<br>        |<br>    TapLeaf (0xc0)<br>    script: 7e a8 20 ff1f9fa3...9986b8 cc  (36 bytes)<br>                     ^--- oracle pubkey hardcoded in script<br>        |<br>    TapLeaf Hash<br>        |   (no siblings -&gt; single-leaf tree)<br>    Merkle Root<br>        |<br>    TapTweak<br>        |<br>    Output Key Q  (parity: odd -&gt; control block byte = c1)<br>        |<br>    P2TR Address<br>    tb1peaj5tna...csd84jel   [OK]</pre><p>The control block opens with c1, consistent with the IK+CSFS experiment and different from the CAT, CSFS, and CTV solo experiments which all produced c0. Same internal key, 36-byte script, different Merkle root, different TapTweak value, different parity outcome.</p><h3>Where CAT+CSFS Sits in the Series</h3><p>Opcode(s) Script Witness Pubkey source Message source What it proves OP_CAT 7ea820...87 [part1, part2] n/a assembled Preimage reassembly OP_CSFS cc [sig, msg, pubkey] witness witness (static whole) Someone with given key signed this OP_CTV 20...b3 [] n/a n/a Spending tx matches template OP_INTERNALKEY cb20...87 [] context n/a Internal key equals expected IK+CSFS cbcc [sig, msg] context (UTXO) witness (static whole) UTXO owner signed the message <strong>CAT+CSFS</strong> <strong>7ea820...cc</strong> <strong>[sig, part1, part2]</strong> <strong>script</strong> <strong>assembled on-chain</strong> <strong>Oracle signed what the stack built</strong></p><p>The series now spans two levels: solo experiments that characterize individual primitives, and combo experiments that explore how composition shifts the authorization surface. The next direction: combining all three axes — IK to bind signer identity, CAT to assemble a spend-specific message, CSFS to verify — producing authorization with no replay surface at any layer.</p><h3>What We Built</h3><p>We ran the second combo experiment: a 36-byte tapscript that pairs OP_CAT and OP_SHA256 with a hardcoded oracle pubkey and OP_CHECKSIGFROMSTACK. The oracle signed SHA256(&quot;BTC_USD=100000&quot;) offline — a price attestation with no knowledge of the transaction it would eventually authorize. At spend time, the witness supplied the signature and two fragments separately; the script assembled them on-chain, hashed the result, and verified the oracle&#39;s signature against the computed digest.</p><p>We built the TapTree with btcaaron&#39;s build_script(OP_CAT, OP_SHA256, push_bytes(ORACLE_PUBKEY), OP_CHECKSIGFROMSTACK), constructed the single-leaf TapTree, and derived the Signet address. The witness was [sig, PART1, PART2] — three items, no pre-assembled message, no pubkey. The spend used .unlock_with(_make_witness()).</p><p>Both transactions confirmed on Signet at 2026–03–21 12:24:18 UTC. RootScope verified the address derivation: the oracle pubkey appears in two roles — once as the TapTree’s internal key feeding the TapTweak derivation, once as a literal constant inside the 36-byte script. Same key, two roles, different derivation paths. Control block opens with c1: same odd-parity outcome as the IK+CSFS experiment, arising from a different Merkle root produced by the 36-byte script.</p><p>The replay boundary is real and deliberate: this oracle attestation is transferable to any UTXO that accepts the same oracle signature. Closing it requires encoding UTXO-specific data in the assembled fragments. That is the design space this experiment opens — not a limitation to apologize for, but a primitive boundary to build from.</p><p>One more boundary worth naming: in this demo the oracle pubkey and the TapTree’s internal key are the same key. The oracle is the contract creator. Separating them — an independent oracle pubkey embedded in the script, a different internal key controlling the key path — is the production design. The mechanism is identical; only the trust model changes.</p><h3>Resources</h3><ul><li>Bitcoin Inquisition: <a href="https://github.com/bitcoin-inquisition/">github.com/bitcoin-inquisition</a></li><li>btcaaron toolkit: <a href="https://github.com/aaron-recompile/btcaaron">github.com/aaron-recompile/btcaaron</a></li><li>RootScope visualizer: <a href="https://github.com/aaron-recompile/rootscope">github.com/aaron-recompile/rootscope</a></li></ul><p><em>Signet | Bitcoin Inquisition 29.2 | Commit </em><a href="https://mempool.space/signet/tx/926c40c1b72edb904a3bb7bf96795f351a6be597fc1aeab1390c15e0133b008f?showDetails=true"><em>926c40c1...008f</em></a><em> | Reveal </em><a href="https://mempool.space/signet/tx/75db54dea1f125174699710bd5b517ae13b6e09b3293a0b0f463ea5561a65ca2?showDetails=true"><em>75db54de...65ca2</em></a><em> | Confirmed 2026-03-21</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c73e1ef5353" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OP_INTERNALKEY + OP_CHECKSIGFROMSTACK on Signet — Identity-Bound Authorization]]></title>
            <link>https://medium.com/@aaron.recompile/op-internalkey-op-checksigfromstack-on-signet-identity-bound-authorization-04f0440557bc?source=rss-9580f025ce6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/04f0440557bc</guid>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Aaron Recompile]]></dc:creator>
            <pubDate>Sat, 21 Mar 2026 18:35:18 GMT</pubDate>
            <atom:updated>2026-03-21T18:35:18.575Z</atom:updated>
            <content:encoded><![CDATA[<pre>Bitcoin is not designed top-down.  <br>It is discovered through execution.<br><br>&quot;Run the Future&quot; — starts here.</pre><blockquote><em>Pure CSFS asks: did someone sign this? IK + CSFS asks: did the </em>owner<em> sign this?</em></blockquote><blockquote>Bitcoin does not enforce identity declarations. It enforces authorization structures.</blockquote><p><strong>TL;DR</strong> — Two opcodes, two bytes (cbcc), zero pubkey in the witness. OP_INTERNALKEY pushes the UTXO&#39;s internal key from Taproot execution context; OP_CHECKSIGFROMSTACK verifies that the key holder signed the message. Authorization is bound to UTXO identity at creation time, not declared at spend time. One structural consequence: a fixed message is replayable across UTXOs with the same internal key — the next experiment (CAT+CSFS) closes that window.</p><p>The distinction matters more than it looks.</p><p>In the standalone CSFS experiment, the witness supplies three items: signature, message, and pubkey. Any pubkey can walk in. If you have a key that matches the sig-message pair, you pass. The script has no opinion about who that key belongs to.</p><p>OP_INTERNALKEY changes the question. It is a single opcode that pushes the x-only internal pubkey of the current Taproot context onto the stack. The script no longer accepts a key from the witness — it reads the key from the UTXO itself. The authorized signer is whoever created this specific UTXO, not whoever happens to have a matching key.</p><p>Combined as OP_INTERNALKEY OP_CHECKSIGFROMSTACK, two bytes, this produces an authorization primitive that is bound to a specific Taproot identity: the internal key holder must have signed the message. The witness shrinks from three items to two — signature and message only. The pubkey never appears in the witness. It arrives at runtime from the execution context.</p><p>This post runs the first combo experiment: cbcc on Signet, with a commit-reveal cycle through Bitcoin Inquisition 29.2. The witness is two items. The stack execution is three steps. Both transactions are confirmed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*NSBxGHO3iz6DjLVqDWpzhA.png" /></figure><p>Same verification primitive. Different binding surface.</p><p>Bitcoin changes when the binding surface changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z-tdFHN-skpNd_nfq6Y_mg.png" /></figure><h3>The IK+CSFS Contract</h3><p>Compare pure CSFS to the combo:</p><pre>Pure CSFS (OP_CHECKSIGFROMSTACK):<br>  witness  = [sig, message, pubkey]<br>  script   = OP_CHECKSIGFROMSTACK<br>  pubkey source: witness (caller-supplied)<br><br><br>IK + CSFS (OP_INTERNALKEY OP_CHECKSIGFROMSTACK):<br>  witness  = [sig, message]<br>  script   = OP_INTERNALKEY OP_CHECKSIGFROMSTACK<br>  pubkey source: Taproot context (UTXO-bound)</pre><p>In the IK+CSFS version, the pubkey is never in the witness. It is pushed by OP_INTERNALKEY from the validated Taproot execution context — the internal key used to construct the TapTree the spender is revealing.</p><p>This matters because of how the Taproot verifier works. When a script-path spend occurs, the control block in the witness carries the candidate internal key P and a Merkle path. The verifier reconstructs the output key Q&#39; = P + tweak·G and checks Q&#39; == Q against the UTXO. Only after this consistency check passes does OP_INTERNALKEY expose the validated P to the execution stack. There is no way to inject a different key through the witness.</p><p>The result: the signer identity is bound to this UTXO’s creation. The same two-byte script can be used in any TapTree — but each instance enforces a different authorized signer, because each instance has a different internal key.</p><h3>The Contract Design</h3><pre>Signer offline:<br>  message = SHA256(&quot;authorized:group_combo_ik_csfs:v1&quot;)<br>           = c4820b82...313ebc<br>  sig     = Schnorr.sign(secret_key, message)<br>           = 5a5a5107...a1fdd37<br><br>At spend time, witness provides:<br>  Witness[0] = sig       (64 bytes)<br>  Witness[1] = message   (32 bytes)<br>Script (two bytes):<br>  0xcb = OP_INTERNALKEY           &lt;- push internal key from Taproot context<br>  0xcc = OP_CHECKSIGFROMSTACK     &lt;- verify sig(message, internal_key)</pre><p>The tapscript bytecode:</p><pre>cb   &lt;- OP_INTERNALKEY<br>cc   &lt;- OP_CHECKSIGFROMSTACK</pre><p>Two bytes. No key in the script, no key in the witness. The authorized identity is implicit in the UTXO’s Taproot construction.</p><h3>Commit Phase: Building the Taproot Address with btcaaron</h3><pre>MESSAGE = hashlib.sha256(b&quot;authorized:group_combo_ik_csfs:v1&quot;).digest()<br><br>key = Key.from_wif(DEMO_KEY_WIF)<br>leaf_script = RawScript(build_script(OP_INTERNALKEY, OP_CHECKSIGFROMSTACK))<br>program = (<br>    TapTree(internal_key=key, network=&quot;signet&quot;)<br>    .custom(script=leaf_script, label=&quot;ik_csfs&quot;)<br>).build()<br>addr = program.address</pre><h3>btcaaron API Highlights</h3><p><strong>build_script(OP_INTERNALKEY, OP_CHECKSIGFROMSTACK)</strong> assembles the two-byte tapscript cbcc. Both opcodes are imported from experiments.opcodes as raw bytes — they are proposed opcodes, not standard btcaaron primitives, so they live in the experiment layer rather than the library.</p><p><strong>TapTree(...).custom(script, label).build()</strong> derives the P2TR address via the same TapLeaf → Merkle root → TapTweak → output key chain as all previous experiments. Two-byte script, same derivation depth as any other single-leaf tree.</p><h3>Funding the Address</h3><pre>txid = fund_address(addr, FUND_TXID_FILE, fund_sats=50_000)</pre><h3>Reveal Phase: Spending with Sig and Message Only</h3><p>The witness is two items. No pubkey.</p><pre>def _make_witness():<br>    secret = wif_secret_bytes(DEMO_KEY_WIF)<br>    sk = PrivateKey(secret, raw=True)<br>    sig = sk.schnorr_sign(MESSAGE, &quot;&quot;, raw=True)<br>    return [sig.hex(), MESSAGE.hex()]<br><br>tx = (<br>    program.spend(&quot;ik_csfs&quot;)<br>    .from_utxo(txid, vout, sats=sats)<br>    .to(change_addr, sats - fee_sats)<br>    .unlock_with(_make_witness())<br>    .build()<br>)<br>reveal_txid = broadcast_or_raise(tx.hex)</pre><h3>btcaaron Spend API</h3><p><strong>_make_witness()</strong> returns [sig, message] in that order. sig is pushed first (lands at stack bottom), message is pushed second (lands at stack top). No pubkey item — OP_INTERNALKEY will supply it at runtime.</p><p><strong>pk.schnorr_sign(MESSAGE, &quot;&quot;, raw=True)</strong> signs the 32-byte digest using BIP340 Schnorr with a deterministic nonce.</p><p>The final witness layout:</p><pre>Witness[0] = 5a5a5107...a1fdd37    &lt;- Schnorr sig (64 bytes)<br>Witness[1] = c4820b82...313ebc     &lt;- message = SHA256(&quot;authorized:...&quot;) (32 bytes)<br>Witness[2] = cbcc                  &lt;- tapscript (OP_INTERNALKEY OP_CHECKSIGFROMSTACK, 2 bytes)<br>Witness[3] = c1ff1f9fa3...9986b8   &lt;- control block (33 bytes)</pre><h3>Transactions, OP_RETURN_203 + OP_RETURN_204, and Stack Trace</h3><h3>Commit: what lands on-chain</h3><p><strong>TxID</strong>: <a href="https://mempool.space/signet/tx/9930e922036a80d04a96a4b08f15838bcb880ce2a4be91da0b24af1484e10ea8?showDetails=true">9930e922...0ea8</a></p><pre>OUTPUTS (relevant)<br>  tb1p...    0.00050000 sBTC  &lt;- IK+CSFS lock UTXO</pre><p>Standard P2TR output. Nothing about the two-byte script is visible externally.</p><h3>Reveal: what lands on-chain</h3><p><strong>TxID</strong>: <a href="https://mempool.space/signet/tx/8d0b2156e9425afe64cabf3c906da255b6b86c51cb8968f828d5253fc261dd8f?showDetails=true">8d0b2156...dd8f</a></p><pre>Fee        : 500 sats<br>Features   : SegWit | Taproot | RBF<br><br>INPUT<br>  (IK+CSFS lock UTXO)    0.00050000 sBTC<br>OUTPUT<br>  (change address)       0.00049500 sBTC  (V1_P2TR)</pre><p>The witness as shown by mempool.space:</p><pre>Witness[0]  5a5a5107...a1fdd37<br>            &lt;- Schnorr sig (64 bytes)<br><br>Witness[1]  c4820b82...313ebc<br>            &lt;- SHA256(&quot;authorized:group_combo_ik_csfs:v1&quot;) (32 bytes)<br>Witness[2]  cbcc<br>            &lt;- tapscript<br>Witness[3]  c1 ff1f9fa3...9986b8<br>            &lt;- control block (leaf version 0xc0 + parity 1 + internal pubkey)</pre><p>P2TR tapscript decoded:</p><pre>OP_RETURN_203<br>OP_RETURN_204</pre><h3>The OP_RETURN_203 + OP_RETURN_204 labels — and what they actually mean</h3><p><em>(Readers familiar with the OP_SUCCESS soft fork upgrade pattern can skip this section.)</em></p><p>0xcb = 203 decimal. 0xcc = 204 decimal. Both fall in BIP342&#39;s OP_SUCCESS range (opcodes 187–254 are OP_SUCCESS in Tapscript). On standard nodes, any OP_SUCCESS opcode causes the tapscript to pass immediately without evaluating anything further. On Bitcoin Inquisition 29.2, 0xcb executes as OP_INTERNALKEY and 0xcc as OP_CHECKSIGFROMSTACK.</p><p>mempool.space, running standard software, labels both as OP_RETURN_203 and OP_RETURN_204 — its naming convention for unrecognized opcodes, not OP_RETURN the data-embedding opcode. When two OP_SUCCESS opcodes appear in the same script, a non-upgraded node passes on the first one without reaching the second. Inquisition nodes execute both sequentially in full.</p><p>This is the same soft fork upgrade mechanism as the standalone CSFS experiment. The new rules turn “always pass” opcodes into real constraints; old nodes see OP_SUCCESS and accept the block because they have no rule to reject it.</p><h3>Stack execution</h3><p><strong>Executing</strong>: OP_INTERNALKEY OP_CHECKSIGFROMSTACK</p><p>The Taproot interpreter strips Witness[2] (script) and Witness[3] (control block), loading Witness[0..1] as the initial execution stack.</p><h4>Initial State: two witness items loaded as execution stack</h4><pre>+--------------------------------------------+<br>| c4820b82...313ebc                          |  &lt;- message  (Witness[1], top)<br>| 5a5a5107...a1fdd37                         |  &lt;- sig      (Witness[0], bottom)<br>+--------------------------------------------+</pre><p>Two items. No pubkey anywhere on the stack yet.</p><h4>Step 1 — OP_INTERNALKEY: push internal key from Taproot context</h4><pre>+--------------------------------------------+<br>| ff1f9fa3...9986b8                          |  &lt;- internal key (32 bytes, from context)<br>| c4820b82...313ebc                          |  &lt;- message<br>| 5a5a5107...a1fdd37                         |  &lt;- sig<br>+--------------------------------------------+</pre><p>OP_INTERNALKEY reads the validated internal key from the Taproot execution context — the P that was checked against the UTXO&#39;s output key Q when the control block was processed. This value was never in the witness. It comes from the UTXO&#39;s construction history.</p><h4>Step 2 — OP_CHECKSIGFROMSTACK: pop pubkey, message, sig — verify — push result</h4><pre>+--------------------------------------------+<br>| 01                                         |  &lt;- TRUE<br>+--------------------------------------------+</pre><p>OP_CSFS pops top-first: internal key, then message, then sig. Executes BIP340 Schnorr verification:</p><pre>verify: Schnorr(sig=5a5a5107...a1fdd37,<br>                msg=c4820b82...313ebc,<br>                pub=ff1f9fa3...9986b8)<br>result: VALID -&gt; push 01</pre><p>Script terminates with a single truthy value. The spend is valid.</p><h4>Why the witness has two items instead of three</h4><p>In the standalone CSFS experiment, the spender supplies [sig, message, pubkey] — three explicit items. The pubkey is caller-supplied: whoever constructs the reveal transaction chooses which key to present. This works fine for verifying against an external key like an oracle or a co-signer, but it means the script has no binding to the UTXO&#39;s specific identity.</p><p>IK+CSFS replaces that third item with the execution context. The spender cannot choose a different pubkey. They cannot substitute a key that matches their own private key unless their private key happens to be the TapTree’s internal key. The authorization is not externally presented — it is structurally enforced by the UTXO’s Taproot construction.</p><p>The practical pattern: a cold key holder pre-signs authorization tickets (sig, message) offline. A hot-side executor broadcasts those tickets without ever holding the cold private key. The script enforces that only the internal key holder&#39;s signatures are valid — and the internal key is locked into the UTXO at creation time, not declared at spend time.</p><h3>Address Reconstruction with RootScope</h3><p>The tapscript is two bytes: cb (OP_INTERNALKEY) and cc (OP_CHECKSIGFROMSTACK). The derivation chain is identical to any other single-leaf TapTree.</p><h3>The Derivation Chain</h3><pre>TapLeaf hash = tagged_hash(&quot;TapLeaf&quot;,  0xc0 || 0x02 || 0xcb || 0xcc)<br>               (leaf version 0xc0, script length 2, script bytes)<br>Merkle root  = TapLeaf hash<br>tweak t      = tagged_hash(&quot;TapTweak&quot;,  internal_pubkey || merkle_root)<br>output key Q = internal_pubkey + t*G<br>P2TR address = Bech32m(&quot;tb&quot;, Q.x_only)</pre><h3>Verification Code</h3><pre>internal_pubkey = bytes.fromhex(<br>    &quot;ff1f9fa326a9438227e6aa25030ccf89bcb8ce53db4f78dbce6146499d9986b8&quot;<br>)<br>script_bytes = bytes([0xcb, 0xcc])<br><br>tapleaf_hash = tagged_hash(<br>    &quot;TapLeaf&quot;,<br>    bytes([0xc0]) + bytes([len(script_bytes)]) + script_bytes,<br>)<br>merkle_root = tapleaf_hash<br>tweak = tagged_hash(&quot;TapTweak&quot;, internal_pubkey + merkle_root)<br>Q    = Key.from_x_only(internal_pubkey).tweak_add(tweak)<br>addr = Q.to_p2tr_address(network=&quot;signet&quot;)<br># Expected: tb1p...  [OK]</pre><p>The same internal_pubkey (ff1f9fa3...9986b8) from all four solo experiments. Same key, two-byte tapscript, different Merkle root, different TapTweak, different address.</p><h3>RootScope Visual Output</h3><pre>Internal Key<br>  ff1f9fa3...9986b8  &lt;----- also the key OP_INTERNALKEY pushes at runtime<br>        |<br>    TapLeaf (0xc0)<br>    script: cb cc  (2 bytes)<br>               ^--- OP_INTERNALKEY pushes this key from context<br>        |<br>    TapLeaf Hash<br>        |   (no siblings -&gt; single-leaf tree)<br>    Merkle Root<br>        |<br>    TapTweak<br>        |<br>    Output Key Q  (parity: odd -&gt; control block byte = c1)<br>        |<br>    P2TR Address<br>    tb1p...  [OK]</pre><p>The control block opens with c1, not c0 as in the CAT, CSFS, and CTV experiments. The different parity reflects a different TapTweak value — this two-byte script produces a different Merkle root than any of the 34-byte or 1-byte scripts, and the tweak lands on an odd-parity point.</p><p>There is a deeper connection here worth making explicit. RootScope performs forward derivation: given P and the script, compute Q. The Taproot verifier during control block processing performs the same computation in reverse: given Q from the UTXO and candidate P from the control block, verify that P → Q holds under the same formula. The math is identical; only what is known and what is being verified differs.</p><p>This is why OP_INTERNALKEY can be trusted. It does not reach into the witness and grab a key — it surfaces a value that was already validated by the control block check before script execution began. RootScope’s derivation chain is not just an address verification tool; it is a visualization of the trust chain that makes OP_INTERNALKEY meaningful. The key it pushes onto the stack is the same key that satisfies Q = P + t·G for this specific UTXO. That relationship, computed forward by RootScope and verified backward by the node, is the foundation.</p><h3>Where IK+CSFS Sits in the Series</h3><p>The four solo experiments each isolated one opcode. The combo experiments start combining them. This is the first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*RLRN58bXPs68KJzH8J0QzA.png" /></figure><p>The progression from CSFS alone to IK+CSFS is the progression from “someone signed this” to “the owner signed this.” OP_INTERNALKEY does one thing: it replaces a witness-supplied public key with the UTXO-bound Taproot identity. That single substitution turns a generic signature check into an ownership-gated authorization.</p><p>Next combo: CAT + CSFS — building the signed message dynamically from stack components rather than pre-committing it at script creation time.</p><h3>A Boundary Condition: Signature Replay</h3><p>This experiment uses a fixed message constant:</p><pre>MESSAGE = hashlib.sha256(b&quot;authorized:group_combo_ik_csfs:v1&quot;).digest()</pre><p>Once a successful reveal transaction is on-chain, the (sig, message) pair is permanently visible. If a second UTXO existed with the same cbcc script and the same internal key, that pair could be replayed against it — no private key required. The control block would validate, OP_INTERNALKEY would push the same P, and OP_CSFS would verify the same signature against the same message. The spend would pass.</p><p>This is not a flaw in IK+CSFS as a primitive. It is a consequence of using a fixed message in a contract that does not bind the authorization to a specific UTXO. The fix is straightforward: include UTXO-specific data in the message — the txid, vout, amount, or destination — so each signature is only valid for one spend:</p><pre>MESSAGE = SHA256(txid || vout || amount || destination_scriptpubkey)</pre><p>This is precisely what the next experiment addresses. CAT + CSFS composes the message dynamically at execution time from stack components. Each signature becomes specific to the spend it authorizes. The replay window closes. IK+CSFS establishes <em>who</em> can authorize; CAT+CSFS establishes <em>what</em> is being authorized and binds the two together.</p><h3>What We Built</h3><p>We ran the first combo experiment: a two-byte tapscript that pairs OP_INTERNALKEY with OP_CHECKSIGFROMSTACK. The design is minimal — OP_INTERNALKEY pushes the UTXO’s internal key, then OP_CSFS verifies that the message SHA256(&quot;authorized:group_combo_ik_csfs:v1&quot;) was signed by that key. The witness supplies only the signature and the message. The pubkey never appears in the witness; it arrives from the Taproot execution context.</p><p>We built the TapTree with btcaaron&#39;s build_script(OP_INTERNALKEY, OP_CHECKSIGFROMSTACK), assembled the two-byte leaf, and derived the Signet address. The witness was constructed with _make_witness(), which signs the message offline using the same key that controls the TapTree&#39;s internal key path. The spend used .unlock_with([sig, message]) — two items, no pubkey.</p><p>Both transactions confirmed on Signet. The trace file records the exact witness bytes. The stack execution is three steps: load two witness items, push the internal key via OP_INTERNALKEY, verify and push TRUE via OP_CSFS.</p><p>RootScope confirmed the address derivation: same internal key as all prior experiments, two-byte tapscript, different Merkle root, different output key, different address. The control block opens with c1 rather than c0 — the odd-parity outcome of this specific tweak combination.</p><p>The real applications of this combination emerge in multi-leaf trees and vault constructions. A leaf that uses IK+CSFS alongside a CTV leaf can enforce both who authorized a spend and exactly where the funds go, with neither condition visible from the P2TR address alone.</p><p>Run the future. Execute first. Formalize later.</p><h3>Evidence Index</h3><p>Everything needed to reproduce this experiment end-to-end:</p><pre>Script hex        cbcc<br>                  (cb = OP_INTERNALKEY, cc = OP_CHECKSIGFROMSTACK)<br><br>Internal pubkey   ff1f9fa326a9438227e6aa25030ccf89bcb8ce53db4f78dbce6146499d9986b8<br>Message           c4820b82d8856e9d8df36a9138d20149a9cd2f5b83d2e33d1b7e026abc313ebc<br>                  (SHA256(&quot;authorized:group_combo_ik_csfs:v1&quot;))<br>Commit TxID       9930e922036a80d04a96a4b08f15838bcb880ce2a4be91da0b24af1484e10ea8<br>Reveal TxID       8d0b2156e9425afe64cabf3c906da255b6b86c51cb8968f828d5253fc261dd8f<br>Control block     c1ff1f9fa326a9438227e6aa25030ccf89bcb8ce53db4f78dbce6146499d9986b8<br>                  (c1 = leaf version 0xc0 + odd parity)<br>Experiment code   experiments/group_opcodes/code/combo_ik_csfs.py<br>Trace output      experiments/group_opcodes/outputs/combo_ik_csfs_trace.json<br>Network           Signet | Bitcoin Inquisition 29.2</pre><h3>Resources</h3><ul><li>Bitcoin Inquisition: <a href="https://github.com/bitcoin-inquisition/">github.com/bitcoin-inquisition</a></li><li>btcaaron toolkit: <a href="https://github.com/aaron-recompile/btcaaron">github.com/aaron-recompile/btcaaron</a></li><li>RootScope visualizer: <a href="https://github.com/aaron-recompile/rootscope">github.com/aaron-recompile/rootscope</a></li></ul><p><em>Signet | Bitcoin Inquisition 29.2 | Commit </em><a href="https://mempool.space/signet/tx/9930e922036a80d04a96a4b08f15838bcb880ce2a4be91da0b24af1484e10ea8?showDetails=true"><em>9930e922...0ea8</em></a><em> | Reveal </em><a href="https://mempool.space/signet/tx/8d0b2156e9425afe64cabf3c906da255b6b86c51cb8968f828d5253fc261dd8f?showDetails=true"><em>8d0b2156...dd8f</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=04f0440557bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OP_CHECKTEMPLATEVERIFY on Signet — Locking Outputs at UTXO Creation Time]]></title>
            <link>https://medium.com/@aaron.recompile/op-checktemplateverify-on-signet-locking-outputs-at-utxo-creation-time-1d623fbe3899?source=rss-9580f025ce6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d623fbe3899</guid>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[soft-fork]]></category>
            <category><![CDATA[opcodes]]></category>
            <dc:creator><![CDATA[Aaron Recompile]]></dc:creator>
            <pubDate>Thu, 19 Mar 2026 01:31:01 GMT</pubDate>
            <atom:updated>2026-04-11T22:26:47.765Z</atom:updated>
            <content:encoded><![CDATA[<p>With OP_CAT you assemble data. With OP_CSFS you authorize it. With OP_CTV you enforce it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NnakRDSLhbWr669BI57o3g.png" /></figure><pre>Bitcoin is not designed top-down.  <br>It is discovered through execution.<br><br>&quot;Run the Future&quot; — starts here.</pre><h3>Constraining the Future, Not the Present</h3><p>OP_CHECKSIG proves that the <em>current</em> key holder authorized <em>this</em> spend. OP_CSFS proves that <em>someone</em> authorized <em>some statement</em>. <strong>OP_CHECKTEMPLATEVERIFY (BIP119)</strong> does something different from both: it proves that the <em>spending transaction itself</em> matches a template committed at UTXO creation time.</p><p>The script does not look at a witness. It does not verify a signature. It computes a hash over the spending transaction’s structure — version, locktime, input count, sequences, output count, outputs — and checks whether that hash matches the one baked into the locking script. If the outputs deviate by a single satoshi or a single byte, the hash fails and the spend is rejected.</p><p>This is <strong>output covenant by pre-commitment</strong>. The creator of the UTXO decides, at funding time, exactly where and how much the money can go. The spender has no discretion over the outputs; they can only construct a transaction that reproduces the template exactly.</p><p><strong>BIP119</strong> assigns opcode 0xb3 to OP_CTV. On standard nodes 0xb3 is OP_NOP4 — it does nothing, so any spend passes. <strong>Bitcoin Inquisition 29.2</strong> activates BIP119 on Signet, turning OP_NOP4 into the real constraint. Same soft fork upgrade pattern as OP_CAT (BIP347, 0x7e) and OP_CSFS (BIP348, 0xcc).</p><p>This post runs a minimal CTV experiment on Signet: commit to a template that sends exactly 49,500 sats to a fixed address, then spend by providing an empty witness and a matching transaction. The spending transaction proves itself.</p><h3>The CTV Contract</h3><p>The locking script is:</p><pre>OP_PUSHBYTES_32 &lt;template_hash&gt;<br>OP_NOP4                          &lt;- OP_CTV on Inquisition (0xb3)</pre><p>The template hash commits to the spending transaction structure. At spend time, the script:</p><ol><li>Pushes &lt;template_hash&gt; onto the stack (from the script itself)</li><li>OP_CTV pops it, computes DefaultCheckTemplateVerifyHash(spending_tx, input_index)</li><li>Checks: computed_hash == template_hash</li><li>If equal, script succeeds</li></ol><p><strong>The witness is empty.</strong> The spender provides no data — no signature, no preimage, no pubkey. The spending transaction itself is the proof. This is the fundamental contrast with every other script we have seen in this series:</p><pre>OP_CAT experiment:<br>  witness  -&gt; [&quot;hello&quot;, &quot;world&quot;]     (data for stack computation)<br>  script   -&gt; OP_CAT OP_SHA256 &lt;hash&gt; OP_EQUAL<br><br>OP_CSFS experiment:<br>  witness  -&gt; [sig, message, pubkey] (authorization proof)<br>  script   -&gt; OP_CHECKSIGFROMSTACK<br><br>OP_CTV experiment:<br>  witness  -&gt; []                     (nothing)<br>  script   -&gt; &lt;template_hash&gt; OP_CTV (spending tx proves itself)</pre><h3>The Template Hash: What Gets Committed</h3><p>DefaultCheckTemplateVerifyHash is defined in BIP119 as:</p><pre>SHA256(<br>  nVersion          (4 bytes, little-endian)<br>  nLockTime         (4 bytes, little-endian)<br>  -- scriptSigs hash omitted for native segwit (all empty) --<br>  nInputs           (4 bytes, little-endian)<br>  SHA256(sequences) (32 bytes)<br>  nOutputs          (4 bytes, little-endian)<br>  SHA256(outputs)   (32 bytes)<br>  input_index       (4 bytes, little-endian)<br>)</pre><p>For our experiment, the committed values are:</p><pre>nVersion          = 2<br>nLockTime         = 0<br>nInputs           = 1<br>sequences         = [0xffffffff]<br>nOutputs          = 1<br>outputs           = [49500 sats -&gt; tb1p32g0c5...wsxlfd5s]<br>input_index       = 0</pre><p>Computed template hash: f4ceec28ec225e022e059355819726668dca411b9239ee4ef65379dc7bd2d8e08</p><p>Every field that could affect the spending transaction’s character is committed. The output address and amount cannot change. The sequence cannot change. The version and locktime cannot change. The only free variable is the input itself — which is implicitly determined by spending the committed UTXO.</p><h3>The Contract Design</h3><pre>At UTXO creation time:<br>  compute template_hash = SHA256(version=2 || locktime=0 ||<br>                                 nInputs=1 || SHA256(seq=0xffffffff) ||<br>                                 nOutputs=1 || SHA256(49500 sats to tb1p32g0c5...wsxlfd5s) ||<br>                                 input_index=0)<br>                        = f4ceec28...d8e08<br><br><br>Lock script:<br>  OP_PUSHBYTES_32 f4ceec28...d8e08<br>  OP_NOP4  (= OP_CTV on Inquisition)<br>At spend time:<br>  witness  = []   &lt;- empty<br>  spending tx must reproduce:<br>    version=2, locktime=0, sequence=0xffffffff,<br>    exactly one output: 49500 sats -&gt; tb1p32g0c5...wsxlfd5s</pre><p>The tapscript bytecode:</p><pre>20     &lt;- OP_PUSHBYTES_32<br>f4ceec28ec225e022e059355819726668dca411b9239ee4ef65379dc7bd2d8e08<br>b3     &lt;- OP_NOP4 / OP_CTV</pre><h3>Commit Phase: Building the Taproot Address with btcaaron</h3><p>btcaaron provides inq_ctv_program_for_output() which handles the template hash computation and TapTree construction in a single call. The caller provides the destination output; the function derives everything else.</p><pre>FUND_SATS   = 50_000<br>FEE_SATS    = 500<br>OUTPUT_SATS = FUND_SATS - FEE_SATS   # 49_500、<br><br>change_addr = default_change_address()<br>script_pubkey_hex = rpc_wallet(&quot;getaddressinfo&quot;, change_addr)[&quot;scriptPubKey&quot;]<br>program, template_hash = inq_ctv_program_for_output(<br>    internal_key=key,<br>    output_sats=OUTPUT_SATS,<br>    output_script_pubkey=script_pubkey_hex,<br>    network=&quot;signet&quot;,<br>    sequence=0xFFFFFFFF,<br>)<br>addr = program.address</pre><h3>btcaaron API Highlights</h3><p><strong>inq_ctv_program_for_output(internal_key, output_sats, output_script_pubkey, network, sequence)</strong> wraps the full CTV setup:</p><ul><li>Serializes the output: value (8 bytes LE) || compact_size(len(scriptpubkey)) || scriptpubkey</li><li>Computes DefaultCheckTemplateVerifyHash over the template fields above</li><li>Builds the tapscript: OP_PUSHBYTES_32 &lt;hash&gt; OP_NOP4</li><li>Constructs a single-leaf TapTree and derives the Bech32m address</li><li>Returns (program, template_hash) — the program carries the spend builder, the hash is for inspection</li></ul><p>The caller must save change_addr to disk — it is needed at spend time to reconstruct the exact same template hash. If change_addr changes, the template hash changes, and the spend fails.</p><h3>Funding the Address</h3><pre>txid = fund_address(addr, FUND_TXID_FILE, fund_sats=FUND_SATS)</pre><h3>Reveal Phase: Spending with an Empty Witness</h3><p>The spend is architecturally the simplest of the three experiments. The spender provides no data. They only need to reconstruct the identical template (same change_addr, same amounts) and submit a matching transaction.</p><pre>_, program, _ = _build_ctv_address(change_addr)<br><br>tx = (<br>    program.spend(&quot;ctv&quot;)<br>    .from_utxo(txid, vout, sats=sats)<br>    .to(change_addr, OUTPUT_SATS)<br>    .sequence(0xFFFFFFFF)<br>    .unlock_with([])          # &lt;- empty: no witness data<br>    .build()<br>)<br>reveal_txid = broadcast_or_raise(tx.hex)</pre><p><strong>.unlock_with([])</strong> passes an empty list. The final witness contains only two items: the tapscript and the control block. There is nothing before them.</p><p><strong>.sequence(0xFFFFFFFF)</strong> must be set explicitly to match the committed template. Any other sequence value produces a different hash and fails the CTV check.</p><p><strong>.to(change_addr, OUTPUT_SATS)</strong> must reproduce the exact scriptpubkey committed in the template. Amount and address must be identical.</p><p>The final witness layout:</p><pre>Witness[0] = 20 f4ceec28...d8e08 b3     &lt;- tapscript (34 bytes)<br>Witness[1] = c0 ff1f9fa3...9986b8       &lt;- control block (33 bytes)</pre><p>No Witness[2], no Witness[3]. Two items total.</p><h3>Transactions, OP_NOP4, and Stack Trace</h3><h3>Commit: what lands on-chain</h3><p><strong>TxID</strong>: <a href="https://mempool.space/signet/tx/d083e038393afb711a6f8c11499131e4f856bb3fae898b74e43aa3bb69b6681f?showDetails=true">d083e038...69b6681f</a></p><pre>INPUT<br>  tb1pqzxvhv...lsycut3t    1.99999816 sBTC  (key-path spend, 64-byte Schnorr sig)<br><br>OUTPUTS<br>  tb1pg5quycyy...yspzja7g  1.99949661 sBTC  &lt;- change<br>  tb1pvqhal44...5q6g6avk   0.00050000 sBTC  &lt;- CTV lock UTXO</pre><p>The CTV lock output tb1pvqhal44...5q6g6avk is a standard P2TR address. No observer can distinguish it from a key-path address. Its previous output script (visible in the reveal tx) confirms:</p><pre>Previous output script:<br>  OP_PUSHNUM_1<br>  OP_PUSHBYTES_32  602fdfd6...042728    &lt;- P2TR output key<br>Previous output type: V1_P2TR</pre><h3>Reveal: witness data and stack execution</h3><p><strong>TxID</strong>: <a href="https://mempool.space/signet/tx/2789983e7f01997ef1fa04a718ea83d388e813cd2ded3116a5acb1a986a244db?showDetails=true">2789983e...86a244db</a></p><pre>Timestamp  : 2026-03-15 23:47:15 UTC<br>Fee        : 500 sats  (4.46 sat/vB)<br>Features   : SegWit | Taproot  (no RBF -- see below)<br><br>INPUT<br>  tb1pvqhal44...5q6g6avk   0.00050000 sBTC<br>OUTPUT<br>  tb1p32g0c5...wsxlfd5s    0.00049500 sBTC  (V1_P2TR)</pre><p>The witness as shown by mempool.space:</p><pre>Witness[0]  20f4ceec28ec225e022e059355819726668dca411b9239ee4ef65379dc7bd2d8e08b3<br>            &lt;- tapscript: OP_PUSHBYTES_32 &lt;template_hash&gt; OP_NOP4<br><br>Witness[1]  c0ff1f9fa326a9438227e6aa25030ccf89bcb8ce53db4f78dbce6146499d9986b8<br>            &lt;- control block (leaf version 0xc0 + internal pubkey)</pre><p>Two witness items. Nothing else.</p><p>P2TR tapscript decoded:</p><pre>OP_PUSHBYTES_32  f4ceec28ec225e022e059355819726668dca411b9239ee4ef65379dc7bd2d8e08<br>OP_NOP4</pre><h3>The OP_NOP4 label — same pattern, different opcode</h3><p>mempool.space decodes 0xb3 and displays:</p><pre>P2TR tapscript   OP_PUSHBYTES_32 f4ceec28...d8e08  OP_NOP4</pre><p>0xb3 = 179 decimal. On standard nodes, opcode 179 is OP_NOP4 — a no-op that leaves the stack unchanged. Under BIP342, NOPs in Tapscript are treated differently from OP_SUCCESS: they do not cause immediate pass, but they also do not fail. A standard node executes OP_PUSHBYTES_32 &lt;hash&gt; (stack now has one item) and then OP_NOP4 (does nothing), leaving the hash on the stack. The script terminates with a non-empty stack — which in Tapscript counts as success. So old nodes accept this spend without ever checking the template.</p><p>On Bitcoin Inquisition 29.2 with BIP119 active, the same 0xb3 is OP_CTV. It pops the hash from the stack, computes DefaultCheckTemplateVerifyHash from the spending transaction, and checks equality. Only a transaction with the exact matching outputs passes.</p><p>This is subtly different from the CSFS case. OP_CSFS (0xcc) is an OP_SUCCESS opcode — old nodes immediately pass without executing anything. OP_NOP4 (0xb3) is a NOP — old nodes execute the full script but do nothing at the NOP step. The end result is the same (old nodes always accept), but the upgrade mechanism differs. BIP119 could have chosen OP_SUCCESS for a cleaner soft fork; instead it chose a NOP to preserve the property that old nodes still execute and validate the non-CTV parts of the script.</p><h3>Stack execution</h3><p><strong>Executing</strong>: OP_PUSHBYTES_32 &lt;template_hash&gt; OP_NOP4/OP_CTV</p><p>The Taproot interpreter strips Witness[0] (script) and Witness[1] (control block). The remaining witness items become the initial execution stack — and there are none.</p><h4>Initial State: empty stack</h4><pre>+--------------------------------------------+<br>|                  (empty)                   |<br>+--------------------------------------------+</pre><p>No witness data. The spending transaction is implicitly available to OP_CTV, but it is not on the stack.</p><h4>Step 1 — OP_PUSHBYTES_32: push template hash from script</h4><pre>+--------------------------------------------+<br>| f4ceec28...d8e08                           |  &lt;- template_hash (32 bytes)<br>+--------------------------------------------+</pre><p>The script itself supplies the committed hash. The spender provided nothing — this value came from the locking script, fixed at UTXO creation time.</p><h4>Step 2 — OP_CTV (0xb3): pop hash, verify spending tx, push result</h4><pre>+--------------------------------------------+<br>| 01                                         |  &lt;- TRUE<br>+--------------------------------------------+</pre><p>OP_CTV pops f4ceec28...d8e08 and computes:</p><pre>computed = DefaultCheckTemplateVerifyHash(spending_tx, input_index=0)<br>         = SHA256(<br>             version=2          nLockTime=0<br>             nInputs=1          SHA256(seq=0xffffffff)<br>             nOutputs=1         SHA256(49500 sats to tb1p32g0c5...wsxlfd5s)<br>             input_index=0<br>           )<br>         = f4ceec28...d8e08<br><br>check: computed == template_hash  -&gt; TRUE</pre><p>The spending transaction’s structure exactly reproduces the committed template. Script terminates with TRUE. Spend is valid.</p><h3>Why nSequence = 0xffffffff and no RBF</h3><p>The reveal transaction features show <strong>no RBF flag</strong>. This is not an accident.</p><p>nSequence = 0xffffffff is committed in the template hash. If you tried to replace the transaction (RBF) with a different fee by changing the fee rate, you would need to either reduce the output amount or add a second input. Reducing the output amount changes the outputs hash — the CTV check fails. Adding a second input changes nInputs — the CTV check fails. There is no fee-bumping path that leaves the template hash intact.</p><p><strong>CPFP is the practical solution.</strong> After the reveal transaction confirms and sends 49,500 sats to tb1p32g0c5...wsxlfd5s, that output can spend those sats with a high-fee child transaction. Miners who see the child&#39;s fee incentive will mine the parent (reveal) too. This is why the Delving Bitcoin post noted: <em>&quot;CTV: parent template constraints make direct replacement less flexible; CPFP is the practical accelerator.&quot;</em></p><p>In the experiment, we set the fee to 500 sats and waited for natural confirmation. At 4.46 sat/vB on Signet, this took hours — the EXPERIMENT_MATRIX records a reveal-to-confirm window of ~338,814 seconds (~3.9 days) for the earlier CTV run. For production CTV vaults, fee planning at template creation time is critical.</p><h3>Address Reconstruction with RootScope</h3><p>The tapscript is 34 bytes: one OP_PUSHBYTES_32 (0x20), the 32-byte template hash, and OP_NOP4 (0xb3).</p><h3>The Derivation Chain</h3><pre>TapLeaf hash = tagged_hash(&quot;TapLeaf&quot;,  0xc0 || 0x22 || 0x20 || template_hash || 0xb3)<br>               (leaf version, script length=34, OP_PUSHBYTES_32, hash, OP_NOP4)<br>Merkle root  = TapLeaf hash<br>tweak t      = tagged_hash(&quot;TapTweak&quot;,  internal_pubkey || merkle_root)<br>output key Q = internal_pubkey + t*G<br>P2TR address = Bech32m(&quot;tb&quot;, Q.x_only)</pre><h3>Verification Code</h3><pre>template_hash = bytes.fromhex(<br>    &quot;f4ceec28ec225e022e059355819726668dca411b9239ee4ef65379dc7bd2d8e08&quot;<br>)<br>script_bytes = bytes([0x20]) + template_hash + bytes([0xb3])<br><br>tapleaf_hash = tagged_hash(<br>    &quot;TapLeaf&quot;,<br>    bytes([0xc0]) + bytes([len(script_bytes)]) + script_bytes,<br>)<br>merkle_root = tapleaf_hash<br>internal_pubkey = bytes.fromhex(<br>    &quot;ff1f9fa326a9438227e6aa25030ccf89bcb8ce53db4f78dbce6146499d9986b8&quot;<br>)<br>tweak = tagged_hash(&quot;TapTweak&quot;, internal_pubkey + merkle_root)<br>Q    = Key.from_x_only(internal_pubkey).tweak_add(tweak)<br>addr = Q.to_p2tr_address(network=&quot;signet&quot;)<br># Expected: tb1pvqhal44...5q6g6avk  [OK]</pre><p>Notice: the same internal_pubkey (ff1f9fa3...9986b8) appears in all three experiments. It is the x-only pubkey of key = Key.from_wif(DEMO_KEY_WIF), the key that controls all three TapTree key paths. The three experiments share one key but embed completely different tapscripts.</p><h3>RootScope Visual Output</h3><pre>Internal Key<br>  ff1f9fa3...9986b8<br>        |<br>    TapLeaf (0xc0)<br>    script: 20 f4ceec28...d8e08 b3  (34 bytes)<br>        |<br>    TapLeaf Hash<br>        |   (no siblings -&gt; single-leaf tree)<br>    Merkle Root<br>        |<br>    TapTweak<br>        |<br>    Output Key Q<br>        |<br>    P2TR Address<br>    tb1pvqhal44...5q6g6avk   [OK]</pre><h3>The Series Complete: CAT, CSFS, CTV</h3><p>This is the third and final post in the series. All three opcodes are now confirmed on Signet.</p><p>Opcode BIP Legacy opcode What it constrains Witness Stack at start OP_CAT 347 OP_SUCCESS Stack composition [part1, part2] 2 items from witness OP_CSFS 348 OP_SUCCESS Signature scope [sig, message, pubkey] 3 items from witness OP_CTV 119 OP_NOP4 Output template [] empty</p><p>The three opcodes represent three different answers to the question “what should Bitcoin Script be able to prove?”:</p><p><strong>CAT</strong> says: the stack should be able to assemble arbitrary byte strings. It gives Script a serialization primitive. Without CAT, you cannot construct dynamic messages or concatenate transaction fields. With CAT, you can build any 32-byte value from components available on the stack.</p><p><strong>CSFS</strong> says: Script should be able to verify that a specific key holder pre-authorized a specific statement. It decouples authorization from the spending transaction. Without CSFS, a key can only authorize one transaction. With CSFS, a key can authorize any statement — an oracle reading, an output template, a channel state.</p><p><strong>CTV</strong> says: Script should be able to constrain the spending transaction to a fixed template, without requiring any runtime authorization. It is deterministic covenant enforcement. Without CTV, you need a signature to authorize every spend. With CTV, the UTXO is self-enforcing — anyone can spend it, but only to the committed destination.</p><p>The three together form a covenant design space. A vault that allows emergency recovery, time-locked inheritance, and fee optimization might use all three: CAT to serialize the output template at runtime, CSFS to verify the vault manager’s pre-authorization, and CTV to enforce the final destination unconditionally.</p><h3>What We Built</h3><p>We constructed a CTV output that commits exactly 49,500 sats to a fixed destination. The locking script is 34 bytes: a pushed template hash followed by OP_NOP4/OP_CTV. The spending witness is empty — the transaction structure is its own proof.</p><p>We used btcaaron&#39;s inq_ctv_program_for_output() to derive the template hash and build the TapTree in one call. The spend used .unlock_with([]) and .sequence(0xFFFFFFFF) — no data supplied, but the transaction structure must match exactly. RootScope verified the address reconstruction: same internal key as the CAT and CSFS experiments, different 34-byte tapscript, different output key, different address.</p><p>The OP_NOP4 label in mempool.space reflects a different soft fork path than CSFS’s OP_SUCCESS: old nodes execute the full script but treat the NOP as inert, leaving the hash on the stack and accepting. Inquisition nodes enforce the actual CTV semantics. Both paths lead to old-node acceptance — only upgraded miners can reject an invalid template spend.</p><p>The reveal transaction has no RBF flag and no viable fee-bumping path short of CPFP. This is not an implementation detail; it is a direct consequence of the template hash committing to nSequence and outputs. Fee planning belongs at UTXO creation time, not at spend time.</p><p>All three transactions — CAT, CSFS, CTV — are permanently confirmed on Signet and reproducible end-to-end using the tools below.</p><h3>Resources</h3><ul><li>Bitcoin Inquisition: <a href="https://github.com/bitcoin-inquisition/">github.com/bitcoin-inquisition</a></li><li>btcaaron toolkit: <a href="https://github.com/aaron-recompile/btcaaron">github.com/aaron-recompile/btcaaron</a></li><li>RootScope visualizer: <a href="https://github.com/aaron-recompile/rootscope">github.com/aaron-recompile/rootscope</a></li></ul><p><em>Signet | Bitcoin Inquisition 29.2 | Commit </em><a href="https://mempool.space/signet/tx/d083e038393afb711a6f8c11499131e4f856bb3fae898b74e43aa3bb69b6681f?showDetails=true"><em>d083e038...69b6681f</em></a><em> | Reveal </em><a href="https://mempool.space/signet/tx/2789983e7f01997ef1fa04a718ea83d388e813cd2ded3116a5acb1a986a244db?showDetails=true"><em>2789983e...86a244db</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d623fbe3899" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OP_CHECKSIGFROMSTACK on Signet — Sign Anything, Verify on Stack]]></title>
            <link>https://medium.com/@aaron.recompile/op-checksigfromstack-on-signet-sign-anything-verify-on-stack-9cf70ab07583?source=rss-9580f025ce6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9cf70ab07583</guid>
            <category><![CDATA[opcodes]]></category>
            <category><![CDATA[signet]]></category>
            <category><![CDATA[bitcoin-developers]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[taproot]]></category>
            <dc:creator><![CDATA[Aaron Recompile]]></dc:creator>
            <pubDate>Tue, 17 Mar 2026 21:21:00 GMT</pubDate>
            <atom:updated>2026-04-11T22:22:51.972Z</atom:updated>
            <content:encoded><![CDATA[<p>Satoshi disabled OP_CAT in 2010. OP_CSFS was never even enabled. We ran it on-chain in 2026.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ddg0hA7OdBj-DQHLntCjRg.png" /></figure><pre>Bitcoin is not designed top-down.  <br>It is discovered through execution.<br><br>&quot;Run the Future&quot; — starts here.</pre><h3>Decoupling the Signature from the Transaction</h3><p>Every Bitcoin signature you have ever seen signs the same thing: a hash of the current transaction. OP_CHECKSIG, OP_CHECKMULTISIG, Schnorr — they all implicitly bind the signature to the spending transaction. The message is not a parameter; it is fixed by consensus.</p><p><strong>OP_CHECKSIGFROMSTACK</strong> (BIP348) breaks that assumption. It takes three explicit stack items — a signature, a message, and a public key — and verifies the signature over that arbitrary message. The message can be anything: a SHA256 digest of a string, a serialized output template, a price oracle feed, a cross-input commitment. The transaction is irrelevant.</p><p>This changes what Bitcoin Script can express. OP_CHECKSIG can only attest that the signer authorized <em>this</em> spend. OP_CSFS can attest that the signer authorized <em>any statement</em>, and that statement can be checked against other stack values produced by introspection. Combined with OP_CAT (previous post), it becomes possible to serialize transaction fields, hash them, sign them in advance, and enforce the result as a covenant.</p><p><strong>BIP348</strong> assigns opcode 0xcc to OP_CHECKSIGFROMSTACK. <strong>Bitcoin Inquisition 29.2</strong> activates it on Signet alongside BIP347 (OP_CAT) and BIP119 (OP_CTV), making all three available for combined experimentation.</p><p>This post runs a minimal CSFS experiment on Signet: sign the digest of &quot;hello world&quot; offline, embed the pubkey in the tapscript, and let the script verify the signature at spend time. The message has nothing to do with the transaction.</p><p>One thing to note upfront: OP_CSFS reveal transactions are non-standard under legacy mempool policy. They will not appear in standard Signet mempools before confirmation. After Inquisition mines the block, the transaction becomes visible on public explorers. “Not in the mempool” is a policy observation, not a consensus rejection.</p><h3>The CSFS Contract</h3><p>OP_CHECKSIGFROMSTACK in its simplest form is a single opcode. The script is:</p><pre>OP_CHECKSIGFROMSTACK   (0xcc)</pre><p>That is the entire locking script. The spending witness must supply, in order:</p><pre>[sig]      &lt;- Schnorr signature over the committed message<br>[message]  &lt;- the 32-byte message that was signed<br>[pubkey]   &lt;- x-only public key of the signer</pre><p>The script pops all three and verifies. If the signature is valid over the message under the pubkey, the result is 1 (TRUE).</p><p>Compare this to OP_CHECKSIG:</p><pre>OP_CHECKSIG behavior:<br>  message  = implicit (current tx sighash)<br>  pubkey   = from script<br>  sig      = from witness<br>  -&gt; verifies sig(tx_hash, pubkey)<br><br>OP_CHECKSIGFROMSTACK behavior:<br>  message  = explicit (from witness stack)<br>  pubkey   = explicit (from witness stack)<br>  sig      = explicit (from witness stack)<br>  -&gt; verifies sig(message, pubkey)<br></pre><p>The transaction is not in scope. This is the core design shift.</p><h3>The Contract Design</h3><pre>Signer offline:<br>  message = SHA256(&quot;hello world&quot;)<br>           = b94d27b9...efcde9<br>  sig     = Schnorr.sign(secret_key, message)<br>           = ab69f346...76912<br><br>At spend time, witness provides:<br>  Witness[0] = sig       (64 bytes)<br>  Witness[1] = message   (32 bytes)<br>  Witness[2] = pubkey    (32 bytes)<br>Script (one byte):<br>  0xcc = OP_CHECKSIGFROMSTACK<br>       -&gt; pops pubkey, message, sig<br>       -&gt; verifies sig over message under pubkey<br>       -&gt; pushes TRUE</pre><p>The tapscript bytecode is exactly:</p><pre>cc   &lt;- OP_CHECKSIGFROMSTACK</pre><p>One byte. No hash commitment in the script itself — the pubkey alone identifies the authorized signer.</p><h3>Commit Phase: Building the Taproot Address with btcaaron</h3><p>btcaaron ships inq_csfs_script() which returns the single-byte 0xcc tapscript. The commit phase is identical in structure to the CAT experiment: build a single-leaf TapTree, derive the address, fund it.</p><pre>MESSAGE = hashlib.sha256(b&quot;hello world&quot;).digest()<br><br>leaf_script = inq_csfs_script()<br>key = Key.from_wif(DEMO_KEY_WIF)<br>tap_tree = (<br>    TapTree(internal_key=key, network=&quot;signet&quot;)<br>    .custom(script=leaf_script, label=&quot;csfs&quot;)<br>).build()<br>addr = tap_tree.address</pre><h3>btcaaron API Highlights</h3><p><strong>inq_csfs_script()</strong> returns a RawScript containing the single byte 0xcc. This is Inquisition&#39;s opcode assignment for OP_CHECKSIGFROMSTACK under BIP348. On a standard node the same byte is an OP_SUCCESS opcode — more on this below.</p><p><strong>TapTree(...).custom(script, label).build()</strong> derives the P2TR address via the same TapLeaf -&gt; Merkle root -&gt; TapTweak -&gt; output key chain described in the previous post. The script being one byte makes no difference to the derivation logic.</p><h3>Funding the Address</h3><pre>txid = rpc_wallet(&quot;sendtoaddress&quot;, tap_tree.address, FUND_SATS / 1e8)</pre><h3>Reveal Phase: Spending with an Offline Signature</h3><p>The reveal transaction constructs the witness by signing the message offline with the secp256k1 library, then submitting all three items — sig, message, pubkey — to the script.</p><pre>def _make_witness():<br>    secret = wif_secret_bytes(DEMO_KEY_WIF)<br>    pk = PrivateKey(secret, raw=True)<br>    sig = pk.schnorr_sign(MESSAGE, &quot;&quot;, raw=True)<br>    pub_x = pk.pubkey.serialize()[1:33]<br>    return [sig.hex(), MESSAGE.hex(), pub_x.hex()]<br><br>tx = (<br>    program.spend(&quot;csfs&quot;)<br>    .from_utxo(txid, vout, sats=sats)<br>    .to(change_addr, sats - fee_sats)<br>    .unlock_with(_make_witness())<br>    .build()<br>)<br><br>reveal_txid = broadcast_or_raise(tx.hex)</pre><h3>btcaaron Spend API</h3><p><strong>_make_witness()</strong> produces three items in the order CSFS expects: signature first (deepest on stack), then message, then pubkey (topmost). The Taproot interpreter will load these as the initial execution stack before running the tapscript.</p><p><strong>pk.schnorr_sign(MESSAGE, &quot;&quot;, raw=True)</strong> signs the 32-byte message digest directly using BIP340 Schnorr. The second argument (&quot;&quot;) is the auxiliary randomness string; passing empty uses a deterministic nonce.</p><p><strong>.unlock_with([...])</strong> injects all three items before the script and control block, exactly as in the CAT experiment. The final witness layout is:</p><pre>Witness[0] = ab69f346...76912      &lt;- Schnorr sig (64 bytes)<br>Witness[1] = b94d27b9...efcde9     &lt;- message = SHA256(&quot;hello world&quot;) (32 bytes)<br>Witness[2] = ff1f9fa3...9986b8     &lt;- x-only pubkey (32 bytes)<br>Witness[3] = cc                    &lt;- tapscript (OP_CHECKSIGFROMSTACK, 1 byte)<br>Witness[4] = c0ff1f9f...9986b8     &lt;- control block (33 bytes)</pre><h3>Transactions, OP_RETURN_204, and Stack Trace</h3><h3>Commit: what lands on-chain</h3><p><strong>TxID</strong>: <a href="https://mempool.space/signet/tx/2d68a0e621533c2f7391159f4c2e252f409c1cec0ec681ff9c6b11cb133803fe?showDetails=true">2d68a0e6...133803fe</a></p><pre>INPUT<br>  tb1p...                          0.00050000 sBTC  (funding source)<br><br>OUTPUTS<br>  tb1p822a0z...fqp6x5up            0.00050000 sBTC  &lt;- CSFS lock UTXO<br>  (change)</pre><p>The output tb1p822a0z...fqp6x5up is a standard P2TR address. No observer can tell that the script path is a single-byte OP_CSFS.</p><h3>Reveal: what mempool.space shows</h3><p><strong>TxID</strong>: <a href="https://mempool.space/signet/tx/cc1b6d352f75348b6a52c7f5c68fc5caea2512423e08011e8f69a9bb85195f97?showDetails=true">cc1b6d35...85195f97</a></p><pre>INPUT<br>  tb1p822a0z...fqp6x5up            0.00050000 sBTC<br><br>OUTPUT<br>  tb1pghctez...es5gqyqw            0.00049500 sBTC  (V1_P2TR)</pre><p>The witness data as shown by mempool.space:</p><pre>Witness[0]  ab69f3465e011994ae9d33650a75fa8b0d5f333d...76912<br>            &lt;- Schnorr sig (64 bytes)<br><br>Witness[1]  b94d27b9934d3e08a52e52d7da7dabfac484efe3...efcde9<br>            &lt;- SHA256(&quot;hello world&quot;) (32 bytes)<br>Witness[2]  ff1f9fa326a9438227e6aa25030ccf89bcb8ce53...9986b8<br>            &lt;- x-only pubkey (32 bytes)<br>Witness[3]  cc<br>            &lt;- tapscript<br>Witness[4]  c0 ff1f9fa3...9986b8<br>            &lt;- control block (leaf version 0xc0 + internal pubkey)</pre><h3>The OP_RETURN_204 label — and what it actually means</h3><p>mempool.space decodes the tapscript cc and displays it as:</p><pre>P2TR tapscript   OP_RETURN_204</pre><p>This label requires explanation. 0xcc = 204 decimal. On nodes that have <em>not</em> activated BIP348, opcode 204 falls in the OP_SUCCESS range defined by BIP342 (opcodes 187–254 are OP_SUCCESS in Tapscript). An OP_SUCCESS opcode causes the tapscript to pass immediately — no further evaluation. So a non-upgraded node reads cc, recognizes it as OP_SUCCESS, and marks the script valid without checking the signature at all.</p><p>On Bitcoin Inquisition 29.2, which has BIP348 activated, the same byte cc is interpreted as OP_CHECKSIGFROMSTACK. The node actually pops pubkey, message, and sig off the stack and performs the Schnorr verification.</p><p>This is the standard soft fork upgrade mechanism. The new rule turns an “always pass” opcode into a real constraint. Miners running Inquisition enforce the new semantics; legacy nodes see OP_SUCCESS and accept the block because they have no rule to reject it. mempool.space, running standard software, therefore labels it OP_RETURN_204 — their display name for &quot;opcode 204, meaning unknown.&quot; The word &quot;RETURN&quot; here is not OP_RETURN the opcode; it is a mempool.space naming convention for unrecognized opcodes.</p><h3>Stack execution</h3><p><strong>Executing</strong>: OP_CHECKSIGFROMSTACK (single opcode, 0xcc)</p><p>The Taproot interpreter strips Witness[3] (script) and Witness[4] (control block), leaving Witness[0..2] as the execution stack:</p><h4>Initial State: three witness items loaded</h4><pre>+--------------------------------------------+<br>| ff1f9fa3...9986b8                          |  &lt;- pubkey    (Witness[2], top)<br>| b94d27b9...efcde9                          |  &lt;- message   (Witness[1])<br>| ab69f346...76912                           |  &lt;- sig       (Witness[0], bottom)<br>+--------------------------------------------+</pre><p>Three explicit inputs. The transaction itself is not on the stack and plays no role in what follows.</p><h4>Step 1 — OP_CHECKSIGFROMSTACK: pop pubkey, message, sig — verify — push result</h4><pre>+--------------------------------------------+<br>| 01                                         |  &lt;- TRUE<br>+--------------------------------------------+</pre><p>OP_CSFS pops all three items (top-first: pubkey, then message, then sig) and runs BIP340 Schnorr verification:</p><pre>verify: Schnorr(sig=ab69f346...76912,<br>                msg=b94d27b9...efcde9,<br>                pub=ff1f9fa3...9986b8)<br><br>result: VALID -&gt; push 01</pre><p>Script terminates with a single truthy value. The spend is valid.</p><h4>Why does the sig not cover the transaction?</h4><p>With OP_CHECKSIG, the signer must know the transaction being spent — the signature is computed over the sighash, which commits to inputs, outputs, and amounts. If the outputs change, the signature breaks.</p><p>With OP_CSFS, the signer committed to SHA256(&quot;hello world&quot;) — a message that has nothing to do with the transaction. The signature was computed before the transaction existed. This is the delegation primitive: a key holder can pre-authorize an action by signing a statement, and anyone who obtains that signature can construct a transaction that passes the CSFS check, regardless of what the outputs look like. Combined with OP_CTV (next post), you can constrain both the authorization (CSFS) and the outputs (CTV) simultaneously.</p><h3>Address Reconstruction with RootScope</h3><p>The tapscript is a single byte: 0xcc. That makes the derivation maximally transparent.</p><h3>The Derivation Chain</h3><pre>TapLeaf hash = tagged_hash(&quot;TapLeaf&quot;,  0xc0 || 0x01 || 0xcc)<br>               (leaf version 0xc0, script length 1, script byte 0xcc)<br>Merkle root  = TapLeaf hash<br>tweak t      = tagged_hash(&quot;TapTweak&quot;,  internal_pubkey || merkle_root)<br>output key Q = internal_pubkey + t*G<br>P2TR address = Bech32m(&quot;tb&quot;, Q.x_only)</pre><h3>Verification Code</h3><pre>script_bytes = bytes([0xcc])   # OP_CHECKSIGFROMSTACK, 1 byte<br><br>tapleaf_hash = tagged_hash(<br>    &quot;TapLeaf&quot;,<br>    bytes([0xc0]) + bytes([len(script_bytes)]) + script_bytes,<br>)<br>merkle_root = tapleaf_hash<br>internal_pubkey = bytes.fromhex(<br>    &quot;ff1f9fa326a9438227e6aa25030ccf89bcb8ce53db4f78dbce6146499d9986b8&quot;<br>)<br>tweak = tagged_hash(&quot;TapTweak&quot;, internal_pubkey + merkle_root)<br>Q    = Key.from_x_only(internal_pubkey).tweak_add(tweak)<br>addr = Q.to_p2tr_address(network=&quot;signet&quot;)<br># Expected: tb1p822a0z...fqp6x5up  [OK]</pre><p>Notice: the internal pubkey in the control block (ff1f9fa3...9986b8) is the <strong>same</strong> key provided in the witness as the CSFS pubkey. This is intentional for the demo — the same key controls both the Taproot key path and the CSFS verification. In production designs these would typically be different keys.</p><h3>RootScope Visual Output</h3><pre>Internal Key<br>  ff1f9fa3...9986b8<br>        |<br>    TapLeaf (0xc0)<br>    script: cc  (1 byte)<br>        |<br>    TapLeaf Hash<br>        |   (no siblings -&gt; single-leaf tree)<br>    Merkle Root<br>        |<br>    TapTweak<br>        |<br>    Output Key Q<br>        |<br>    P2TR Address<br>    tb1p822a0z...fqp6x5up   [OK]</pre><p>The one-byte script produces the same derivation depth as any other single-leaf tree. The address gives no indication of the script’s size or content.</p><h3>Where CSFS Sits in the CAT / CSFS / CTV Series</h3><p>This is the second post in a three-part series. Each opcode in the series constrains a different layer of a transaction:</p><p>Opcode BIP What it constrains Mechanism Post OP_CAT 347 Stack composition Concatenate two elements; enables serialization [1] OP_CSFS 348 Signature scope Verify a signature over any message, not just tx [2] OP_CTV 119 Output template Commit the spend tx to a pre-defined hash [3]</p><p>OP_CAT operates purely on the stack and knows nothing about transactions. OP_CSFS understands signatures and keys, but deliberately decouples the message from the transaction. OP_CTV goes furthest — it commits the entire spending transaction to a hash baked into the locking script, requiring exact output reproduction.</p><p>The three together form a covenant toolkit. A realistic pattern: use CAT to serialize transaction output data onto the stack, use CSFS to verify that an authorized party signed that output template, and use CTV to enforce the template is reproduced exactly. Each opcode handles one layer; none of them alone is sufficient.</p><p>Next post: OP_CHECKTEMPLATEVERIFY on Signet — committing to outputs at UTXO creation time, and why CPFP is the practical fee-bumping strategy when the output template is fixed.</p><h3>What We Built</h3><p>We designed the simplest possible CSFS contract: a one-byte tapscript (0xcc) that verifies a Schnorr signature over an arbitrary 32-byte message. The message — SHA256(&quot;hello world&quot;) — was signed offline before the transaction existed. At spend time, the witness supplies the sig, message, and pubkey explicitly; OP_CSFS verifies without consulting the transaction sighash at all.</p><p>We used btcaaron&#39;s inq_csfs_script() to get the tapscript byte, built a single-leaf TapTree with TapTree(...).custom(...).build(), and constructed the witness with _make_witness() + .unlock_with(). RootScope verified the address reconstruction: internal key + one-byte script -&gt; TapLeaf hash -&gt; TapTweak -&gt; output key -&gt; tb1p822a0z...fqp6x5up.</p><p>The key thing mempool.space reveals: the decoded tapscript reads OP_RETURN_204, not OP_CHECKSIGFROMSTACK. That is not a bug in the explorer. It is the soft fork mechanism in action — non-upgraded nodes see OP_SUCCESS and pass the script unconditionally; Inquisition nodes see the actual CSFS semantics and enforce the signature check. The same upgrade pattern governs Taproot, SegWit, and every future Bitcoin soft fork.</p><p>Both transactions are permanently confirmed on Signet.</p><h3>Resources</h3><ul><li>Bitcoin Inquisition: <a href="https://github.com/bitcoin-inquisition/">github.com/bitcoin-inquisition</a></li><li>btcaaron toolkit: <a href="https://github.com/aaron-recompile/btcaaron">github.com/aaron-recompile/btcaaron</a></li><li>RootScope visualizer: <a href="https://github.com/aaron-recompile/rootscope">github.com/aaron-recompile/rootscope</a></li></ul><p><em>Signet | Bitcoin Inquisition 29.2 | Commit </em><a href="https://mempool.space/signet/tx/2d68a0e621533c2f7391159f4c2e252f409c1cec0ec681ff9c6b11cb133803fe?showDetails=true"><em>2d68a0e6...133803fe</em></a><em> | Reveal </em><a href="https://mempool.space/signet/tx/cc1b6d352f75348b6a52c7f5c68fc5caea2512423e08011e8f69a9bb85195f97?showDetails=true"><em>cc1b6d35...85195f97</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9cf70ab07583" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OP_CAT on Signet — Concatenation, Commitment, and Bitcoin Inquisition]]></title>
            <link>https://medium.com/@aaron.recompile/op-cat-on-signet-concatenation-commitment-and-bitcoin-inquisition-ed34a07866d6?source=rss-9580f025ce6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed34a07866d6</guid>
            <category><![CDATA[bitcoin-taproot]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[opcodes]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Aaron Recompile]]></dc:creator>
            <pubDate>Mon, 16 Mar 2026 16:59:08 GMT</pubDate>
            <atom:updated>2026-04-11T22:19:09.217Z</atom:updated>
            <content:encoded><![CDATA[<p>Satoshi disabled it in 2010. We ran it on-chain in 2026.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p3m_flh1egUfPTSlSPpY2w.png" /></figure><pre>Bitcoin is not designed top-down.  <br>It is discovered through execution.<br><br>&quot;Run the Future&quot; — starts here.</pre><h3>From Satoshi’s Disabling to Protocol Revival</h3><p>OP_CAT is one of Bitcoin’s most storied disabled opcodes. In 2010, Satoshi Nakamoto silently removed it along with a handful of others, citing concerns about unbounded memory growth — a concatenated loop could theoretically produce a stack element of arbitrary size, opening a vector for denial-of-service attacks against nodes.</p><p>The irony is that OP_CAT is perhaps <em>the</em> most expressive primitive in Bitcoin Script. A single opcode — pop two stack elements, push their concatenation — unlocks a surprising range of constructions: introspection, covenants, STARK proof verification, cross-input signature binding. For over a decade, it sat dormant while developers found increasingly exotic workarounds.</p><p><strong>BIP347</strong> (proposed 2024) formalizes OP_CAT’s return under Tapscript, with a strict 520-byte limit on concatenated outputs. <strong>Bitcoin Inquisition 29.2</strong> ships BIP347 as a soft fork active on Signet, making Signet the canonical testbed for OP_CAT experiments before any mainnet activation.</p><p>This post walks through a complete commit-reveal experiment conducted on Signet, implemented with the btcaaron toolkit and reconstructed visually with RootScope. The core contract is intentionally minimal: a <strong>split-preimage hash lock</strong> that proves OP_CAT&#39;s basic functionality while demonstrating the full Taproot script-path lifecycle.</p><p>One thing worth noting upfront: before block confirmation, reveal transactions may be absent from standard Signet mempools — not because of a network fork, but because of policy. Inquisition nodes accept the non-standard spend, mine it, and make it visible on public explorers post-confirmation. “Not seen yet” does not mean the network rejected it.</p><h3>The Split-Preimage Contract</h3><p>The classical hash-lock script commits to a preimage and requires the spender to reveal it:</p><pre>OP_SHA256 &lt;hash&gt; OP_EQUALVERIFY OP_TRUE</pre><p>The preimage is presented as a single stack element. OP_CAT introduces a twist: we can commit to a preimage that the spender must <em>reconstruct on the fly</em> by providing two separate pieces and concatenating them on-chain. This is the <strong>split-preimage</strong> pattern:</p><pre>OP_CAT<br>OP_SHA256<br>OP_PUSHBYTES_32 &lt;SHA256(part1 || part2)&gt;<br>OP_EQUAL</pre><p>In our experiment: part1 = &quot;hello&quot;, part2 = &quot;world&quot;, and the expected hash is SHA256(&quot;helloworld&quot;).</p><p><strong>Why this matters beyond the toy example.</strong> The split-preimage pattern is the embryo of more sophisticated constructions. When you control what gets concatenated — for instance, a transaction field extracted via introspection alongside a known constant — you can enforce covenant behavior. OP_CAT turns the stack into a serialization engine. But we walk before we run.</p><h3>The Contract Design</h3><pre>Secret split:  &quot;hello&quot; (0x68656c6c6f)  ||  &quot;world&quot; (0x776f726c64)<br>                                   |<br>                               OP_CAT<br>                                   |<br>                    &quot;helloworld&quot; (0x68656c6c6f776f726c64)<br>                                   |<br>                               OP_SHA256<br>                                   |<br>          936a185c...8f8f07af   (SHA256 of &quot;helloworld&quot;)<br>                                   |<br>                         compare with committed hash<br>                                   |<br>                               OP_EQUAL -&gt; TRUE</pre><p>The tapscript bytecode is exactly:</p><pre>7e                                               &lt;- OP_CAT<br>a8                                               &lt;- OP_SHA256<br>20                                               &lt;- OP_PUSHBYTES_32<br>936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb944412bb6f8f8f07af<br>87                                               &lt;- OP_EQUAL</pre><h3>Commit Phase: Building the Taproot Address with btcaaron</h3><p>The commit transaction funds a Taproot output whose script path encodes the OP_CAT hash lock. We construct it as a <strong>single-leaf TapTree</strong> with the internal key controlling the key path.</p><h3>Computing the Committed Hash</h3><pre>part1 = b&quot;hello&quot;<br>part2 = b&quot;world&quot;<br>committed_hash = hashlib.sha256(part1 + part2).digest()<br><br># 936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb944412bb6f8f8f07af</pre><h3>Constructing the OP_CAT Script</h3><p>OP_CAT is opcode 0x7e — disabled on mainnet, activated on Signet via BIP347. We define it explicitly and pass it to btcaaron&#39;s script builder:</p><pre>OP_CAT = bytes([0x7E])<br><br>script_hex = build_script(<br>    OP_CAT,<br>    OP_SHA256,<br>    push_bytes(committed_hash),<br>    OP_EQUAL,<br>)<br>cat_leaf = RawScript(script_hex)<br>tap_tree  = (<br>    TapTree(internal_key=key, network=&quot;signet&quot;)<br>    .custom(script=cat_leaf, label=&quot;cat&quot;)<br>).build()</pre><p><strong>btcaaron API Highlights</strong></p><p><strong>TapTree(internal_key, network)</strong> initialises a Taproot tree builder. The internal_key is used as the key-path spend key and as the basis for the P2TR address derivation tweak.</p><p><strong>.custom(script, label)</strong> attaches a raw script leaf to the tree under a human-readable label. The label is used later by .spend(label) to identify which leaf&#39;s control block to construct.</p><p><strong>.build()</strong> finalises the tree: computes TapLeaf hashes, assembles the Merkle root (for a single leaf, the Merkle root <em>is</em> the TapLeaf hash), applies the BIP341 tweak Q = P + t*G where t = tagged_hash(&quot;TapTweak&quot;, P || merkle_root), and derives the Bech32m Signet address.</p><h3>Funding the Address</h3><pre>txid = rpc_wallet(&quot;sendtoaddress&quot;, tap_tree.address, FUND_SATS / 1e8)</pre><h3>Reveal Phase: Spending with the Split Preimage</h3><p>The reveal transaction spends the UTXO by supplying &quot;hello&quot; and &quot;world&quot; as separate witness stack elements, letting OP_CAT reassemble them on-chain before the hash check.</p><pre>tx = (<br>    tap_tree.spend(&quot;cat&quot;)<br>    .from_utxo(fund_txid, vout, sats=FUND_SATS)<br>    .to(change_addr, OUTPUT_SATS)<br>    .sequence(0xFFFFFFFF)<br>    .unlock_with([<br>        part1.hex(),   # &quot;68656c6c6f&quot;  &lt;- pushed first -&gt; sits at stack bottom<br>        part2.hex(),   # &quot;776f726c64&quot;  &lt;- pushed second -&gt; sits at stack top<br>    ])<br>    .build()<br>)<br>reveal_txid = rpc(&quot;sendrawtransaction&quot;, tx.hex)</pre><h3>btcaaron Spend API</h3><p><strong>.spend(label)</strong> looks up the named leaf in the tree, constructs its control block (internal pubkey + optional Merkle path), and returns a transaction builder pre-configured for script-path spending.</p><p><strong>.unlock_with([...])</strong> injects raw witness stack elements <em>before</em> the script and control block. Order matters: elements are pushed in list order, so the <em>first</em> element ends up deepest on the execution stack. In our case, &quot;hello&quot; lands at the bottom and &quot;world&quot; sits on top — exactly what OP_CAT expects.</p><p>The final witness for our single input:</p><pre>Witness[0] = 68656c6c6f                  &lt;- &quot;hello&quot;<br>Witness[1] = 776f726c64                  &lt;- &quot;world&quot;<br>Witness[2] = 7ea820...8f8f07af87         &lt;- tapscript (OP_CAT script)<br>Witness[3] = c050be5f...126bb4d3         &lt;- control block</pre><h3>Transactions and Stack Trace</h3><h3>Commit: what lands on-chain</h3><p><strong>TxID</strong>: <a href="https://mempool.space/signet/tx/084d5a9c6a8c176c24edc0a8b7ce54ed65808a326367d8a9299b4460ecaada09?showDetails=true">084d5a9c...ecaada09</a></p><pre>Timestamp     : 2026-02-12 09:52:48 UTC<br>Fee           : 155 sats  (1.01 sat/vB)<br>Features      : SegWit | Taproot | RBF<br><br>INPUT<br>  tb1pvzghpa...sqkluxcm    0.00250812 sBTC<br>OUTPUTS<br>  tb1p7lcpdk...8snhqmnc    0.00050000 sBTC  &lt;- CAT lock UTXO<br>  tb1pmfwqkg...jsk55q8v    0.00200657 sBTC  &lt;- change</pre><p>The output tb1p7lcpdk...8snhqmnc is a standard P2TR address. An external observer sees nothing unusual — no hint that an OP_CAT script lurks in the script path. The commitment is invisible until revealed.</p><h3>Reveal: witness data and stack execution</h3><p><strong>TxID</strong>: <a href="https://mempool.space/signet/tx/00072d4aa354b5987eb8f2ffec440db7467b0581c5e845a6a0ef6999b2d05656?showDetails=true">00072d4a...b2d05656</a></p><p>The Taproot interpreter strips the last two witness items (script + control block) and uses the remaining items as the initial execution stack.</p><pre>Witness[0]  68656c6c6f<br>            &lt;- &quot;hello&quot;<br><br>Witness[1]  776f726c64<br>            &lt;- &quot;world&quot;<br>Witness[2]  7e a8 20 936a185c...8f8f07af 87<br>            &lt;- tapscript: OP_CAT OP_SHA256 OP_PUSHBYTES_32 &lt;hash&gt; OP_EQUAL<br>Witness[3]  c0 50be5fc4...126bb4d3<br>            &lt;- control block (leaf version 0xc0 + internal pubkey, no Merkle path)</pre><p>The 33-byte control block confirms a single-leaf TapTree: no sibling hash, because the TapLeaf hash <em>is</em> the Merkle root.</p><p><strong>Executing</strong>: OP_CAT OP_SHA256 OP_PUSHBYTES_32 &lt;committed_hash&gt; OP_EQUAL</p><h4>Initial State: Witness[0] and Witness[1] loaded as execution stack</h4><pre>+--------------------------------------------+<br>| 776f726c64                                 |  &lt;- &quot;world&quot;  (Witness[1], top)<br>| 68656c6c6f                                 |  &lt;- &quot;hello&quot;  (Witness[0], bottom)<br>+--------------------------------------------+</pre><p>Two separate byte strings. Neither alone matches the preimage hash; only their concatenation does.</p><h4>Step 1 — OP_CAT: pop top two, push concatenation</h4><pre>+--------------------------------------------+<br>| 68656c6c6f776f726c64                       |  &lt;- &quot;helloworld&quot; (10 bytes)<br>+--------------------------------------------+</pre><p>OP_CAT pops &quot;world&quot; then &quot;hello&quot; (top-first) and concatenates as bottom || top. BIP347 enforces a 520-byte ceiling on the result — our 10-byte string is well within bounds.</p><h4>Step 2 — OP_SHA256: pop top, push its SHA256</h4><pre>+--------------------------------------------+<br>| 936a185c...8f8f07af                        |  &lt;- SHA256(&quot;helloworld&quot;) (32 bytes)<br>+--------------------------------------------+</pre><p>The hash is deterministic. The spender cannot influence it without controlling the preimage composition.</p><h4>Step 3 — OP_PUSHBYTES_32: push the committed hash from script</h4><pre>+--------------------------------------------+<br>| 936a185c...8f8f07af                        |  &lt;- committed_hash (from script)<br>| 936a185c...8f8f07af                        |  &lt;- computed_hash  (from Step 2)<br>+--------------------------------------------+</pre><p>The script carries the expected hash as a 32-byte constant embedded at compile time.</p><h4>Step 4 — OP_EQUAL: compare, push result</h4><pre>+--------------------------------------------+<br>| 01                                         |  &lt;- TRUE<br>+--------------------------------------------+</pre><p>Both hashes match. Script terminates with a single truthy value — spend is valid. Output destination: tb1p4ug2v8...zqwnmkrp 0.00049500 sBTC (V1_P2TR).</p><h4>Why not OP_EQUALVERIFY + OP_TRUE?</h4><p>Both produce the same consensus result here. OP_EQUAL leaves the boolean on the stack, while OP_EQUALVERIFY consumes it and aborts on failure. For a single-path terminal opcode, OP_EQUAL is idiomatic — clearer intent, one fewer byte. The on-chain bytecode (87) confirms this choice.</p><h3>Address Reconstruction with RootScope</h3><p>The real payoff of understanding Taproot internals is being able to <strong>independently reconstruct the P2TR address</strong> from its constituent parts, without trusting any external source. RootScope walks through the full derivation and renders each step visually.</p><h3>The Derivation Chain</h3><pre>TapLeaf hash = tagged_hash(&quot;TapLeaf&quot;,  0xc0 || compact_size(len(script)) || script)<br>Merkle root  = TapLeaf hash              &lt;- single leaf: no TapBranch needed<br>tweak t      = tagged_hash(&quot;TapTweak&quot;,  internal_pubkey || merkle_root)<br>output key Q = internal_pubkey + t*G    &lt;- elliptic curve point addition<br>P2TR address = Bech32m(&quot;tb&quot;, Q.x_only)</pre><h3>Verification Code</h3><pre>tapleaf_hash = tagged_hash(<br>    &quot;TapLeaf&quot;,<br>    bytes([0xc0]) + bytes([len(script_bytes)]) + script_bytes,<br>)<br>merkle_root = tapleaf_hash<br><br>internal_pubkey = bytes.fromhex(<br>    &quot;50be5fc44ec580c387bf45df275aaa8b27e2d7716af31f10eeed357d126bb4d3&quot;<br>)<br>tweak = tagged_hash(&quot;TapTweak&quot;, internal_pubkey + merkle_root)<br>Q    = Key.from_x_only(internal_pubkey).tweak_add(tweak)<br>addr = Q.to_p2tr_address(network=&quot;signet&quot;)<br># Expected: tb1p7lcpdk...8snhqmnc  [OK]</pre><h3>RootScope Visual Output</h3><pre>Internal Key<br>  50be5fc4...126bb4d3<br>        |<br>    TapLeaf (0xc0)<br>    script: 7ea820...07af87<br>        |<br>    TapLeaf Hash<br>        |   (no siblings -&gt; single-leaf tree)<br>    Merkle Root<br>        |<br>    TapTweak<br>        |<br>    Output Key Q<br>        |<br>    P2TR Address<br>    tb1p7lcpdk...8snhqmnc   [OK]</pre><p>For multi-leaf trees, RootScope renders the full binary tree, highlights the Merkle proof path for any selected leaf, and shows where sibling hashes appear in the control block — indispensable for debugging spend failures caused by mismatched script indexes or incorrect tree ordering.</p><h3>What Comes Next: CAT, CSFS, and CTV</h3><p>This post is the first in a three-part series covering the opcode proposals currently co-activated on Signet via Bitcoin Inquisition. Each targets a different layer of the transaction:</p><p>Opcode BIP What it constrains Mechanism OP_CAT 347 Stack composition Concatenate two elements; enables serialization OP_CSFS 348 Signature scope Check a signature against an arbitrary message OP_CTV 119 Output template Commit the spend tx to a pre-defined hash</p><p>OP_CAT, as shown here, operates purely on the stack. It does not know what a transaction looks like — it just concatenates bytes. That is precisely why covenant designs need to combine it with introspection: CAT reassembles serialized transaction fields, and something else checks them.</p><p>OP_CSFS goes one step further: it decouples the message being signed from the transaction itself. A signature can be validated against any data on the stack, not just the current transaction hash. This opens the door to delegation schemes and cross-input commitments.</p><p>OP_CTV takes the opposite approach: instead of building up constraints from scratch, it commits the spending transaction to a pre-computed hash at UTXO creation time. The spender cannot deviate from the template — output addresses, amounts, and sequence numbers are all locked in. No introspection needed; the commitment is baked into the script.</p><p>The three opcodes are complementary. A covenant that validates a transaction’s output structure might use CTV for the simple fixed-template case, or CAT + CSFS for a more dynamic one where the template is computed at runtime. Next post: OP_CSFS on Signet — what it takes to sign something other than the current transaction.</p><h3>What We Built</h3><p>We designed a split-preimage hash lock under Taproot’s script path, implemented it with btcaaron&#39;s TapTree / RawScript / .custom() / .unlock_with() chain, and broadcast both the commit and reveal transactions on Signet. The reveal witness puts &quot;hello&quot; and &quot;world&quot; on the stack as two separate items; OP_CAT reassembles them before the SHA256 check fires.</p><p>We then used RootScope to walk the derivation in reverse: starting from the raw script bytes and the internal key, we recomputed the TapLeaf hash, the Merkle root, the TapTweak, and the output key — arriving at the same tb1p7lcpdk...8snhqmnc that received the commit funds. That chain of trust, from script to address, is what makes Taproot&#39;s script-path commitments verifiable and auditable without any external authority.</p><p>Both transactions are permanently confirmed on Signet. The experiment is reproducible end-to-end using the tools linked below.</p><h3>Resources</h3><ul><li>Bitcoin Inquisition: <a href="https://github.com/bitcoin-inquisition/">github.com/bitcoin-inquisition</a></li><li>btcaaron toolkit: <a href="https://github.com/aaron-recompile/btcaaron">github.com/aaron-recompile/btcaaron</a></li><li>RootScope visualizer: <a href="https://github.com/aaron-recompile/rootscope">github.com/aaron-recompile/rootscope</a></li></ul><p><em>Signet | Bitcoin Inquisition | Commit </em><a href="https://mempool.space/signet/tx/084d5a9c6a8c176c24edc0a8b7ce54ed65808a326367d8a9299b4460ecaada09?showDetails=true"><em>084d5a9c...ecaada09</em></a><em> | Reveal </em><a href="https://mempool.space/signet/tx/00072d4aa354b5987eb8f2ffec440db7467b0581c5e845a6a0ef6999b2d05656?showDetails=true"><em>00072d4a...b2d05656</em></a><em> | Confirmed 2026-02-12</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed34a07866d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Missing Developer Stack of Taproot]]></title>
            <link>https://medium.com/@aaron.recompile/the-missing-developer-stack-of-taproot-61352dad7f96?source=rss-9580f025ce6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/61352dad7f96</guid>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[developer-tools]]></category>
            <dc:creator><![CDATA[Aaron Recompile]]></dc:creator>
            <pubDate>Wed, 11 Mar 2026 21:11:00 GMT</pubDate>
            <atom:updated>2026-03-11T21:11:00.679Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Why Taproot still lacks the infrastructure developers need</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*90lD_gw7t7D1rO2yKgJ4TQ.png" /></figure><h3>Introduction — Taproot is deployed, but underused</h3><p>Taproot activated in 2021 and introduced one of the most powerful upgrades in Bitcoin’s scripting history.</p><p>It enabled Schnorr signatures, key aggregation, script trees, and meaningfully improved privacy for complex spending conditions. From a protocol perspective, Taproot is complete.</p><p>However, four years after activation, most Taproot outputs on chain are still spent via key-path spends, while script-path usage remains relatively rare.</p><p>This raises an obvious question: if Taproot is so powerful, why are complex script constructions still uncommon?</p><p>The answer is not a limitation of the protocol. It is a limitation of the developer infrastructure around it.</p><p>Taproot currently lacks a coherent developer stack.</p><h3>Layer 1 — Debugging and Measurement Tools</h3><p>One of the biggest obstacles developers face when working with Taproot is <em>visibility</em>.</p><p>A Taproot script-path spend contains multiple layers of cryptographic commitments:</p><pre>TapLeaf hash<br>  → Merkle path<br>    → Control block<br>      → TapTweak<br>        → Tweaked output key</pre><p>Understanding or verifying these steps manually is difficult. Today, most tools provide only basic transaction decoding. Bitcoin Core’s decoderawtransaction, for example, does not reconstruct TapLeaf hashes, Merkle path structure, control block interpretation, or tweak verification.</p><p>As a result, developers often fall back to ad-hoc scripts or manual calculations. This friction discourages experimentation.</p><p>What is missing are Taproot inspection tools: witness analyzers, control block inspectors, commitment reconstruction tools, and chain-level measurement frameworks for understanding how Taproot is being used in practice. Without these, debugging Taproot scripts is unnecessarily opaque — even for developers who understand the protocol.</p><h3>Layer 2 — Script Engineering Knowledge</h3><p>Even when developers understand the protocol rules, there is a second, more subtle gap: <em>engineering patterns</em>.</p><p>The Taproot BIPs define the system precisely:</p><ul><li><strong>BIP340</strong> — Schnorr signatures</li><li><strong>BIP341</strong> — Taproot construction</li><li><strong>BIP342</strong> — Tapscript</li></ul><p>But these documents do not answer the practical questions that arise when building real systems:</p><ul><li>How should a complex script tree be structured?</li><li>How should leaf ordering be chosen?</li><li>What privacy trade-offs emerge from different tree designs?</li><li>How should multiple spending conditions be composed efficiently?</li></ul><p>These are engineering questions, not protocol questions — and the gap is more concrete than it might sound.</p><p>Take leaf ordering as one example. In a Taproot tree with multiple spending conditions, placing the most likely-to-be-used leaf at a lower depth reduces the control block size required at spend time. But leaf position also has privacy implications: a shallow leaf reveals less of the tree than a deep one, and an analyst observing script-path spends over time can make probabilistic inferences about tree structure. How a developer balances these trade-offs is not specified anywhere in the BIPs.</p><p>Or take control block size itself. In a balanced binary tree of depth <em>d</em>, the control block grows by 32 bytes per level (one hash per Merkle path step). A tree with 8 leaves at depth 3 requires a 3-hash control block; a pathological linear tree of the same 8 leaves can require up to 7 hashes for the deepest leaf. The choice of tree topology is therefore an engineering decision with real on-chain cost and privacy consequences — but there is no reference material telling developers how to think about it.</p><p>In other ecosystems, these answers emerge as design patterns, reference implementations, and cookbook-style documentation. For Taproot, this material is still scarce. As a result, many developers treat Taproot scripts as theoretical capabilities rather than practical building blocks.</p><h3>Layer 3 — Playground Infrastructure</h3><p>The final missing piece is <em>experimentation infrastructure</em>.</p><p>Developers working in other scripting environments typically have access to purpose-built tooling: local deployment environments, transaction simulators, interactive debuggers. Bitcoin development is different by design — Bitcoin Script is not a general-purpose computation system, and the comparison has real limits. But the underlying need is similar: a low-friction way to construct, test, and iterate on script logic before committing to mainnet.</p><p>The typical Taproot development workflow today still looks like:</p><pre>bitcoind → regtest → RPC calls → manual transaction construction</pre><p>This workflow is fully capable, but it requires assembling many pieces by hand, and there is no dedicated tooling for Taproot-specific tasks. A focused Taproot development environment could provide script tree construction tools, transaction simulation with witness inspection, reproducible test cases, and interactive control block debugging. The goal is not to replicate Ethereum’s tooling philosophy — it is to give Bitcoin developers the same ability to move quickly and verify their understanding that regtest alone does not provide.</p><p>Such infrastructure would significantly lower the barrier to experimentation and reduce the time between “I have an idea” and “I have a working transaction.”</p><h3>Why This Matters</h3><p>Taproot was designed to enable a wide range of advanced protocols: vault constructions, DLCs, covenant-like structures, and future contract systems. But protocols do not emerge automatically. They require tools, examples, and experiments.</p><p>The current situation is not a failure of the protocol — it is a gap in the surrounding ecosystem. Developers who might otherwise explore Taproot’s capabilities are slowed down at each layer: they cannot see what is happening inside their transactions, they have no engineering patterns to reason from, and they have no low-friction environment in which to iterate.</p><p>Each of these is a solvable problem.</p><h3>Conclusion</h3><p>Taproot itself is not missing any functionality. What is missing is the developer stack around it.</p><p>Three layers remain underdeveloped:</p><ol><li><strong>Debugging and measurement tools</strong> — witness analyzers, control block inspectors, commitment reconstruction tools, and chain-level measurement frameworks</li><li><strong>Script engineering knowledge</strong> — concrete patterns for tree design, leaf ordering, privacy trade-offs, and spending condition composition</li><li><strong>Playground infrastructure</strong> — a focused environment for Taproot experimentation that reduces the gap between understanding the protocol and building with it</li></ol><p>Building this stack is likely one of the most important steps for unlocking the full potential of Taproot.</p><p>The protocol is already here. Now the ecosystem needs the tools that allow developers to truly use it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61352dad7f96" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RootScope: A Tool for Reconstructing Taproot Script Paths — Step by Step]]></title>
            <link>https://medium.com/@aaron.recompile/rootscope-a-tool-for-reconstructing-taproot-script-paths-step-by-step-106012af54b9?source=rss-9580f025ce6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/106012af54b9</guid>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[taproot]]></category>
            <dc:creator><![CDATA[Aaron Recompile]]></dc:creator>
            <pubDate>Mon, 09 Mar 2026 08:14:10 GMT</pubDate>
            <atom:updated>2026-03-09T08:14:10.409Z</atom:updated>
            <content:encoded><![CDATA[<h4>When you spend from a Taproot script path, the hash chain is deterministic. Reconstructing it by hand is a trap.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ybIhmVO2RbZquBOvK2TaDw.png" /></figure><p>Taproot is elegant on paper. Spend from a script path, and the witness contains everything needed to prove your script was committed: the script itself, the control block, and the Merkle path up to the root. The math is clean.</p><p>The problem is <em>inspection</em>.</p><p>Given a real transaction, try to manually verify that the reconstructed Merkle root matches the output key. You’ll need to:</p><ol><li>Parse the control block byte by byte</li><li>Compute TaggedHash(&quot;TapLeaf&quot;, version || compact_size(len) || script)</li><li>Walk the sibling hashes in the control block up to the root</li><li>Compute TaggedHash(&quot;TapTweak&quot;, internal_pubkey || root)</li><li>Do the elliptic curve point addition on secp256k1</li><li>Bech32m-encode the result</li><li>Check that it matches the output address</li></ol><p>Miss one step — wrong hash tag, wrong byte order, parity bit ignored — and you get a silent mismatch. No error message. Just a wrong address.</p><p>I built <strong>RootScope</strong> to do this deterministically and show every step.</p><h3>What RootScope Does</h3><p>Given a script and control block, RootScope computes the complete reconstruction chain:</p><pre>TapLeaf hash<br>  → TapBranch step 1<br>  → TapBranch step 2<br>  → ...<br>  → Merkle root<br>  → TapTweak<br>  → tweaked output key<br>  → bech32m address<br>  → ✓ matches expected address (optional check)</pre><p>Each intermediate value is shown. Nothing is hidden.</p><p>There’s also a fetch-witness helper: give it a txid + vin, and it resolves the witness from a block explorer and prefills the inputs. No manual hex-copying from a mempool explorer.</p><p>Repo: <a href="https://github.com/aaron-recompile/rootscope">github.com/aaron-recompile/rootscope</a></p><h3>The Hash Chain, Concretely</h3><p>BIP 341 defines three tagged hashes used in Taproot construction:</p><p><strong>TapLeaf:</strong></p><pre>TapLeaf_hash = TaggedHash(&quot;TapLeaf&quot;, leafVersion || compact_size(len) || script)</pre><p><strong>TapBranch</strong> (each step up the Merkle path):</p><pre>TapBranch_hash = TaggedHash(&quot;TapBranch&quot;, left || right)</pre><p>where left and right are the lexicographically-sorted pair — the control block provides sibling hashes in order, so sorting happens at construction time.</p><p><strong>TapTweak:</strong></p><pre>tweak = TaggedHash(&quot;TapTweak&quot;, internal_pubkey || merkle_root)<br>taproot_pubkey = lift_x(internal_pubkey) + tweak × G</pre><p>The final output key is the x-coordinate of that point. Parity check against the control block’s low bit completes the verification.</p><p>RootScope implements all of this in pure Python — hashlib only, no external crypto libraries. crypto.py re-implements tagged_hash, secp256k1 lift_x, point_add, point_mul, and bech32m_encode/decode from scratch. Every function is independently testable.</p><h3>Validation</h3><p>Before touching mainnet data, I ran the full BIP 341 test vectors.</p><p>wallet-test-vectors.json contains 6 test cases with 12 distinct script-path spending paths — including unbalanced trees (case 3) and mixed-depth paths (cases 5 and 6). All 12 pass:</p><pre>$ make bip341-vectors<br>Running BIP341 test vectors...<br> [PASS] Case 1 - path 0/0<br> [PASS] Case 1 - path 0/1<br> [PASS] Case 2 - path 0/0<br> ...<br> [PASS] Case 6 - path 0/1/0<br><br><br>12 / 12 PASS</pre><p>Additional vectors from <a href="https://github.com/aaron-recompile/mastering-taproot"><em>Mastering Taproot</em></a> cover single-leaf, dual-leaf (balanced), and the first documented 4-leaf Taproot tree — including the full unbalanced variant from Chapter 8.</p><p>Control block guard checks:</p><ul><li>(len - 33) % 32 == 0 — control block length must be valid</li><li>depth ≤ 128 — as specified in BIP 341</li><li>output-key parity check against the version &amp; 0x01 bit</li></ul><p>Quick repro:</p><pre>git clone https://github.com/aaron-recompile/rootscope<br>cd rootscope<br>python3 -m venv .venv &amp;&amp; ./.venv/bin/python -m pip install -r backend/requirements.txt<br><br>make bip341-vectors<br>./.venv/bin/python -m backend.cli tx \<br>  f1de8d3b3894a7cc0efffa7332bf7236ad089195b9d642121f4844f13e01f1e0 \<br>  --vin 0 --network mainnet</pre><h3>The Deeper the Tree, the More the Control Block Reveals</h3><p>Most mainnet script-path spends use single-leaf trees — 33-byte control blocks with no Merkle path at all. That’s the on-chain reality. But it’s not what Taproot was designed for. The interesting structures are in the <a href="https://github.com/aaron-recompile/mastering-taproot"><em>Mastering Taproot</em></a> book vectors and the BIP 341 test cases.</p><p><strong>Depth progression: single-leaf to 4-leaf</strong></p><p>The book’s three chapters correspond to three tree shapes. Control block length grows linearly with depth:</p><pre>Chapter 06 — single leaf (depth=0)<br>control block = 1 + 32 = 33 bytes<br><br>internal_key<br>       │<br>     leaf_A  ← script here, no sibling hashes in control block<br>Chapter 07 - dual-leaf balanced (depth=1)<br>control block = 1 + 32 + 32 = 65 bytes<br><br><br>  internal_key<br>       │<br>    Branch<br>   ┌───┴───┐<br> leaf_A  leaf_B  ← reveal A, control block carries hash of B<br>Chapter 08 - 4-leaf balanced (depth=2)<br>control block = 1 + 32 + 32 + 32 = 97 bytes<br><br><br>  internal_key<br>       │<br>      Root<br>   ┌───┴────┐<br>Branch0   Branch1<br>┌──┴──┐  ┌──┴──┐<br>S0   S1  S2   S3  ← reveal S1: control block carries [S0_hash, Branch1_hash]</pre><p>Each additional depth level adds 32 bytes. Verification complexity is O(depth).</p><p><strong>Unbalanced trees: two different proofs, same output address</strong></p><p>This is the most counterintuitive part of Taproot’s design: <strong>different leaves in the same tree can have different control block depths, but all resolve to the same output address.</strong></p><p>Unbalanced 3-leaf tree:</p><pre>      Root<br>    ┌──┴──┐<br>  Branch  leaf_C  ← depth=1, control block carries Branch_hash<br>  ┌─┴─┐<br>leaf_A leaf_B     ← depth=2, control block carries [leaf_B_hash, leaf_C_hash]</pre><p>Revealing leaf_A (depth=2):</p><pre>control_block = version | parity<br>              + internal_pubkey       (32 bytes)<br>              + leaf_B_hash           (32 bytes, sibling)<br>              + leaf_C_hash           (32 bytes, sibling one level up)<br>total = 97 bytes</pre><p>Revealing leaf_C (depth=1):</p><pre>control_block = version | parity<br>              + internal_pubkey       (32 bytes)<br>              + Branch_AB_hash        (32 bytes, entire left subtree)<br>total = 65 bytes</pre><p>Two paths, identical Merkle root, identical output address. RootScope reconstructs both correctly and produces consistent results.</p><p><strong>BIP 341 Case 3: non-standard leaf version</strong></p><p>Test case 3 in wallet-test-vectors.json includes a path with leaf version 0xfa — not the standard Tapscript 0xc0:</p><pre>control_block = &quot;faee4fe085983462a184015d1f782d6a5f8b9c2b...&quot;<br>#                ^^<br>#                0xfa = non-standard leaf version, low bit = parity</pre><p>The script for this path is the raw bytes 06424950333431 — ASCII &quot;BIP341&quot;. From the perspective of address verification, the leaf version only affects the TapLeaf hash computation. TapBranch and TapTweak are unaffected. RootScope handles this correctly.</p><h3>Open Questions</h3><ol><li><strong>Depth distribution at scale.</strong> Does depth &gt; 0 appear more often in protocol-specific spending — Lightning, RGB, covenant constructions? Are there real multi-leaf trees in the wild beyond ordinals infrastructure?</li><li><strong>Template labeling.</strong> The current pipeline identifies templates by script structure. Automatic classification is possible but risks false positives. Is conservative, opt-in labeling better for a tool like this?</li><li><strong>Dataset integration.</strong> Are there public datasets of script-path spends — academic datasets, mempool.space exports, or other tooling outputs — that would plug directly into the batch pipeline?</li></ol><p>Repo: <a href="https://github.com/aaron-recompile/rootscope">github.com/aaron-recompile/rootscope</a></p><p><em>Related: </em><a href="https://medium.com/@aaron.recompile/building-a-4-leaf-taproot-tree-in-python-the-first-complete-implementation-on-bitcoin-testnet-3a9b2c8e7f1d"><em>Building a 4-Leaf Taproot Tree in Python</em></a><em> · </em><a href="https://medium.com/@aaron.recompile/taproot-control-block-deep-analysis-stack-execution-visualization-5ff10f98032c"><em>Taproot Control Block Deep Analysis</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=106012af54b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Commit-Reveal vs Dual-Layer Scripts: The Real Architecture of Bitcoin Script]]></title>
            <link>https://medium.com/@aaron.recompile/commit-reveal-vs-dual-layer-scripts-the-real-architecture-of-bitcoin-script-665a79b0bd34?source=rss-9580f025ce6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/665a79b0bd34</guid>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[bitcoin-taproot]]></category>
            <category><![CDATA[bitcoin-programming]]></category>
            <dc:creator><![CDATA[Aaron Recompile]]></dc:creator>
            <pubDate>Tue, 02 Dec 2025 05:04:34 GMT</pubDate>
            <atom:updated>2025-12-02T05:04:34.485Z</atom:updated>
            <content:encoded><![CDATA[<p>Companion notes to my book <strong><em>Mastering Taproot</em></strong>.</p><pre>HODLing is the beginning.<br>But Bitcoin was meant to be programmed.<br><br>&quot;Not Just HODLing: Real Bitcoin Script Engineering&quot; starts here.<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8vWIEun7MLB7FhZi_Cvt0g.png" /></figure><h3>Bitcoin Script looks like a single program. It isn’t.</h3><p>Underneath, two different architectures coexist:</p><ul><li>a philosophical <strong>commit–reveal</strong> model shared by all address types</li><li>an engineering <strong>dual-layer</strong> structure introduced only in P2SH, P2WSH, and Taproot script-path</li></ul><p>Most confusion comes from mixing these two.</p><p>This essay separates them cleanly.</p><h3>1. The Universal Truth: Commit → Reveal</h3><p>Every Bitcoin output — P2PKH, SegWit, Taproot — follows one rule:</p><pre>Lock:   commit to a condition<br>Unlock: reveal a proof satisfying it</pre><ul><li>P2PKH commits to a pubkey hash</li><li>P2SH commits to a script hash</li><li>P2WSH commits to SHA256(script)</li><li>Taproot commits to a tweaked key (optionally hiding a Merkle tree)</li></ul><p>This is a conceptual model, not an execution structure.</p><p>Commit–reveal is the language. Opcodes are the grammar.</p><h3>2. Single-Layer vs Dual-Layer Scripts</h3><p>Commit–reveal is universal. Dual-layer execution is not.</p><p>Bitcoin has exactly two script architectures:</p><h3>Single-Layer Scripts</h3><p><strong>Used by:</strong></p><ul><li>P2PK / P2PKH</li><li>P2MS (bare multisig)</li><li>P2WPKH</li><li>Taproot key-path</li></ul><p><strong>Structure:</strong></p><pre>scriptSig / witness pushes data<br>            ↓<br>scriptPubKey (or implicit logic) executes directly</pre><p>No script hash. No script extraction. No inner vs outer.</p><p><strong>P2WPKH</strong></p><p>Witness only carries data. Nodes recognize OP_0 &lt;20 bytes&gt;, then execute an implicit P2PKH-equivalent program.</p><p>This is not dual-layer because there is no script hash and no revealed script.</p><p><strong>Taproot key-path</strong></p><p>Pure single-layer: a single Schnorr signature verifies the tweaked key. No script execution at all.</p><h3>Dual-Layer Scripts</h3><p><strong>Used only by:</strong></p><ul><li>P2SH</li><li>P2WSH</li><li>Taproot script-path</li></ul><p><strong>Architecture:</strong></p><pre>Outer layer:   verify a commitment (hash / tweaked key)<br>Inner layer:   execute the revealed script</pre><pre>┌─────────────────────────────┐<br>│        Outer Commit Layer   │<br>│   (scriptPubKey commitment) │<br>└───────────────┬─────────────┘<br>                │<br>                ▼<br>┌─────────────────────────────┐<br>│      Inner Execution Layer  │<br>│ (redeemScript / witnessScript / tapscript)<br>└─────────────────────────────┘</pre><p>Only these three structures follow: <strong>unlock → reveal → load script → execute script</strong>.</p><p>This is why P2SH has no OP_CHECKSIG in its locking script. All logic lives in the inner script.</p><h3>3. The Commitment Types</h3><h3>P2SH</h3><pre>scriptPubKey:  OP_HASH160 &lt;script_hash&gt; OP_EQUAL<br>redeemScript:  (actual logic, e.g. OP_CHECKSIG)</pre><h3>P2WSH</h3><pre>scriptPubKey:  OP_0 &lt;32-byte script_hash&gt;<br>witnessScript: (actual logic)</pre><h3>Taproot script-path</h3><pre>scriptPubKey:  OP_1 &lt;32-byte output_pubkey&gt;<br>witness:       &lt;stack&gt; &lt;tapscript&gt; &lt;control_block&gt;</pre><p>The control_block contains the internal key and Merkle path.</p><p><strong>The outer script never encodes logic — only a fingerprint of logic.</strong></p><h3>4. Why This Distinction Matters</h3><p>Failing to distinguish these two layers leads to confusion:</p><ul><li>Why P2SH’s scriptPubKey has no OP_CHECKSIG</li><li>Why SegWit moves scripts into the witness</li><li>Why P2WSH and Taproot require revealing full scripts</li><li>Why Taproot must reconstruct the tweaked key</li><li>Why key-path spend is “scriptless”</li></ul><p>With the correct architecture, everything clicks:</p><p><strong>Commit–reveal is the philosophy.Dual-layer is the mechanism.</strong></p><p>P2PKH only follows the philosophy. P2SH / P2WSH / Taproot script-path implement both.</p><h3>5. The Unified Evolution</h3><pre>P2PK     → commit(pubkey)<br>P2PKH    → commit(hash(pubkey))<br>P2SH     → commit(hash(script))<br>P2WSH    → commit(sha256(script))<br>Taproot  → commit(internal_key + tweak(merkle_root))</pre><p>Commitments grow more abstract. Privacy improves. Scripts expose less and less.</p><p>But the core remains unchanged:</p><pre>Commit → Reveal → Execute</pre><p>This is the true architecture of Bitcoin programmability.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=665a79b0bd34" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Anatomy of Bitcoin Scripts: From P2PKH to Taproot]]></title>
            <link>https://medium.com/@aaron.recompile/the-anatomy-of-bitcoin-scripts-from-p2pkh-to-taproot-4db16924232f?source=rss-9580f025ce6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4db16924232f</guid>
            <category><![CDATA[taproot]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[bitcoin-core]]></category>
            <category><![CDATA[bitcoin-script]]></category>
            <dc:creator><![CDATA[Aaron Recompile]]></dc:creator>
            <pubDate>Fri, 28 Nov 2025 00:40:24 GMT</pubDate>
            <atom:updated>2025-11-28T00:40:24.201Z</atom:updated>
            <content:encoded><![CDATA[<p>Companion notes to my book <strong><em>Mastering Taproot</em></strong>.</p><pre>HODLing is the beginning.<br>But Bitcoin was meant to be programmed.<br><br>&quot;Not Just HODLing: Real Bitcoin Script Engineering&quot; starts here.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1-nfC1obuIQItPMMYVsK5Q.jpeg" /></figure><h3>The Universal Truth</h3><p>Every Bitcoin address — from the genesis block to the latest Taproot output — follows one fundamental pattern:</p><pre>Lock:   Commit to a condition<br>Unlock: Reveal proof that you satisfy it</pre><p>This isn’t a feature of SegWit or Taproot. It’s the DNA of Bitcoin itself.</p><h3>Evolution of Commit-Reveal</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BttYEFyVYnRx0ocaAdwuKg.png" /></figure><p>The abstraction deepens. The privacy improves. The core logic remains unchanged.</p><h3>Locking Script Formats</h3><h3>P2PKH</h3><pre>OP_DUP OP_HASH160 &lt;20-byte pubkey_hash&gt; OP_EQUALVERIFY OP_CHECKSIG</pre><h3>P2SH</h3><pre>OP_HASH160 &lt;20-byte script_hash&gt; OP_EQUAL</pre><h3>P2WPKH</h3><pre>OP_0 &lt;20-byte pubkey_hash&gt;</pre><h3>P2WSH</h3><pre>OP_0 &lt;32-byte script_hash&gt;</pre><h3>P2TR</h3><pre>OP_1 &lt;32-byte output_pubkey&gt;</pre><p><strong>How nodes differentiate SegWit types:</strong></p><ul><li>OP_0 + 20 bytes → P2WPKH</li><li>OP_0 + 32 bytes → P2WSH</li><li>OP_1 + 32 bytes → P2TR</li></ul><h3>The Verification Flow</h3><h3>Universal Pattern</h3><pre>Step 1: Verify Commit — Does the revealed content match what was promised?<br>Step 2: Execute Script — Do the conditions evaluate to true?</pre><h3>P2SH Verification</h3><pre>HASH160(redeem_script) == hash in locking script?<br>Match → Execute redeem_script</pre><h3>P2WSH Verification</h3><pre>SHA256(witness_script) == hash in locking script?<br>Match → Execute witness_script</pre><h3>P2TR Script Path Verification</h3><pre>1. Extract internal_pubkey from control block<br>2. Compute tapleaf_hash from script<br>3. Calculate merkle_root using Merkle path<br>4. tweak = TaggedHash(&quot;TapTweak&quot;, internal_pubkey || merkle_root)<br>5. computed_pubkey = internal_pubkey + tweak × G<br>6. computed_pubkey == output_pubkey in locking script?<br>7. Match → Execute tapscript</pre><h3>Stack Execution Visualized</h3><h3>Example 1: P2PKH</h3><p><strong>Locking Script:</strong> OP_DUP OP_HASH160 &lt;pubkey_hash&gt; OP_EQUALVERIFY OP_CHECKSIG</p><p><strong>Unlock Data:</strong> &lt;signature&gt; &lt;pubkey&gt;</p><pre>Initial Stack      OP_DUP         OP_HASH160      PUSH hash<br>┌─────────┐       ┌─────────┐    ┌─────────┐     ┌─────────┐<br>│ pubkey  │       │ pubkey  │    │ pk_hash │     │ pk_hash │ ← expected<br>├─────────┤       ├─────────┤    ├─────────┤     ├─────────┤<br>│ sig     │       │ pubkey  │    │ pubkey  │     │ pk_hash │ ← computed<br>└─────────┘       ├─────────┤    ├─────────┤     ├─────────┤<br>                  │ sig     │    │ sig     │     │ pubkey  │<br>                  └─────────┘    └─────────┘     ├─────────┤<br>                                                 │ sig     │<br>                                                 └─────────┘<br><br>OP_EQUALVERIFY     OP_CHECKSIG      Final<br>┌─────────┐        ┌─────────┐      ┌─────────┐<br>│ pubkey  │        │ 1(true) │      │ 1(true) │ ✓<br>├─────────┤        └─────────┘      └─────────┘<br>│ sig     │<br>└─────────┘</pre><h3>Example 2: P2SH with Timelock</h3><p><strong>Redeem Script:</strong> OP_3 OP_CSV OP_DROP OP_DUP OP_HASH160 &lt;hash&gt; OP_EQUALVERIFY OP_CHECKSIG</p><p><strong>Unlock Data:</strong> &lt;signature&gt; &lt;pubkey&gt;</p><pre>Initial Stack      PUSH 3         OP_CSV          OP_DROP<br>┌─────────┐       ┌─────────┐    ┌─────────┐     ┌─────────┐<br>│ pubkey  │       │ 3       │    │ 3       │     │ pubkey  │<br>├─────────┤       ├─────────┤    ├─────────┤     ├─────────┤<br>│ sig     │       │ pubkey  │    │ pubkey  │     │ sig     │<br>└─────────┘       ├─────────┤    ├─────────┤     └─────────┘<br>                  │ sig     │    │ sig     │<br>                  └─────────┘    └─────────┘<br>                                 Check nSeq ≥ 3<br><br>Continues with standard P2PKH logic...</pre><h3>Example 3: P2WPKH</h3><p><strong>Locking Script:</strong> OP_0 &lt;20-byte pubkey_hash&gt;</p><p><strong>Witness:</strong> &lt;signature&gt; &lt;pubkey&gt;</p><p>Node sees OP_0 + 20 bytes, implicitly executes P2PKH logic:</p><pre>Verification: HASH160(pubkey) == hash in locking script? Match → Continue<br><br><br>Execution (implicit P2PKH logic):<br><br>Initial Stack      OP_DUP         OP_HASH160      PUSH hash<br>┌─────────┐       ┌─────────┐    ┌─────────┐     ┌─────────┐<br>│ pubkey  │       │ pubkey  │    │ pk_hash │     │ pk_hash │ ← expected<br>├─────────┤       ├─────────┤    ├─────────┤     ├─────────┤<br>│ sig     │       │ pubkey  │    │ pubkey  │     │ pk_hash │ ← computed<br>└─────────┘       ├─────────┤    ├─────────┤     ├─────────┤<br>                  │ sig     │    │ sig     │     │ pubkey  │<br>                  └─────────┘    └─────────┘     ├─────────┤<br>                                                 │ sig     │<br>                                                 └─────────┘<br>OP_EQUALVERIFY     OP_CHECKSIG      Final<br>┌─────────┐        ┌─────────┐      ┌─────────┐<br>│ pubkey  │        │ 1(true) │      │ 1(true) │ ✓<br>├─────────┤        └─────────┘      └─────────┘<br>│ sig     │<br>└─────────┘</pre><p><strong>Difference from P2PKH:</strong> Identical logic, unlock data moved from scriptSig to witness.</p><h3>Example 4: P2WSH (2-of-3 Multisig)</h3><p><strong>Locking Script:</strong> OP_0 &lt;32-byte script_hash&gt;</p><p><strong>Witness Script:</strong> OP_2 &lt;pubkey1&gt; &lt;pubkey2&gt; &lt;pubkey3&gt; OP_3 OP_CHECKMULTISIG</p><p><strong>Witness:</strong> OP_0 &lt;sig1&gt; &lt;sig2&gt; &lt;witness_script&gt;</p><pre>Verification: SHA256(witness_script) == hash? Match → Execute witness_script<br><br><br>Execution:<br>Initial Stack (witness data excluding witness_script)<br>┌─────────┐<br>│ sig2    │<br>├─────────┤<br>│ sig1    │<br>├─────────┤<br>│ 0       │ ← CHECKMULTISIG bug placeholder<br>└─────────┘<br>PUSH 2         PUSH pk1       PUSH pk2       PUSH pk3<br>┌─────────┐    ┌─────────┐    ┌─────────┐    ┌─────────┐<br>│ 2       │    │ pk1     │    │ pk2     │    │ pk3     │<br>├─────────┤    ├─────────┤    ├─────────┤    ├─────────┤<br>│ sig2    │    │ 2       │    │ pk1     │    │ pk2     │<br>├─────────┤    ├─────────┤    ├─────────┤    ├─────────┤<br>│ sig1    │    │ sig2    │    │ 2       │    │ pk1     │<br>├─────────┤    ├─────────┤    ├─────────┤    ├─────────┤<br>│ 0       │    │ sig1    │    │ sig2    │    │ 2       │<br>└─────────┘    ├─────────┤    ├─────────┤    ├─────────┤<br>               │ 0       │    │ sig1    │    │ sig2    │<br>               └─────────┘    ├─────────┤    ├─────────┤<br>                              │ 0       │    │ sig1    │<br>                              └─────────┘    ├─────────┤<br>                                             │ 0       │<br>                                             └─────────┘<br><br><br><br>PUSH 3                    OP_CHECKMULTISIG           Final<br>┌─────────┐               ┌─────────┐                ┌─────────┐<br>│ 3       │               │ 1(true) │                │ 1(true) │ ✓<br>├─────────┤               └─────────┘                └─────────┘<br>│ pk3     │<br>├─────────┤               Verify: at least 2 of 3<br>│ pk2     │               signatures are valid<br>├─────────┤<br>│ pk1     │<br>├─────────┤<br>│ 2       │<br>├─────────┤<br>│ sig2    │<br>├─────────┤<br>│ sig1    │<br>├─────────┤<br>│ 0       │ ← consumed (legacy bug)<br>└─────────┘</pre><p><strong>The CHECKMULTISIG bug:</strong> Due to an off-by-one error in the original implementation, an extra stack element is consumed. Hence the dummy OP_0 at the start of witness.</p><h3>Example 5: Taproot Script Path</h3><p><strong>Tapscript:</strong> OP_2 OP_CSV OP_DROP &lt;pubkey&gt; OP_CHECKSIG</p><p><strong>Witness:</strong> &lt;signature&gt; &lt;script&gt; &lt;control_block&gt;</p><pre>Verification: control_block + script → reconstruct output_pubkey → match locking script<br><br>Execution:<br>Initial Stack      PUSH 2         OP_CSV          OP_DROP<br>┌─────────┐       ┌─────────┐    ┌─────────┐     ┌─────────┐<br>│ sig     │       │ 2       │    │ 2       │     │ sig     │<br>└─────────┘       ├─────────┤    ├─────────┤     └─────────┘<br>                  │ sig     │    │ sig     │<br>                  └─────────┘    └─────────┘<br>                                 Check nSeq ≥ 2<br><br><br><br>PUSH pubkey        OP_CHECKSIG        Final<br>┌─────────┐        ┌─────────┐        ┌─────────┐<br>│ pubkey  │        │ 1(true) │        │ 1(true) │ ✓<br>├─────────┤        └─────────┘        └─────────┘<br>│ sig     │<br>└─────────┘</pre><h3>What SegWit Actually Changed</h3><p>SegWit wasn’t a revolution. It was a relocation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mKiJ-2uXgxgDFHN1Xi0HcQ.png" /></figure><h3>What Taproot Actually Changed</h3><p>Taproot optimized the commit-reveal paradigm:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eLHjPezLIyQSWDnKbx2Y9w.png" /></figure><p><strong>Control Block Structure:</strong></p><pre>[1 byte: leaf_version + parity] [32 bytes: internal_pubkey] [32 bytes × N: Merkle path]</pre><p><strong>Verification Formula:</strong></p><pre>output_pubkey = internal_pubkey + TaggedHash(&quot;TapTweak&quot;, internal_pubkey || merkle_root) × G</pre><h3>Key Takeaways</h3><ol><li><strong>Every address type is commit-reveal</strong> — Lock with a hash/pubkey commitment, unlock by revealing the preimage</li><li><strong>Locking scripts are routing labels</strong> — Nodes use the format to determine validation rules; they don’t execute on stack</li><li><strong>Verification precedes execution</strong> — First prove “you have the right to run this script”, then verify “does the script pass”</li><li><strong>Stack execution is universal</strong> — Regardless of address type, it’s all push, pop, verify signatures, check timelocks</li><li><strong>The trajectory is clear:</strong></li></ol><ul><li>Commitments grow more abstract (pubkey → hash → tweak)</li><li>Privacy improves (expose everything → expose only what’s used)</li><li>Efficiency increases (fee optimization, verification optimization)</li></ul><p><em>Understanding these primitives is the foundation for everything that follows — Lightning channels, covenant proposals, and whatever comes next.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4db16924232f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>