<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>output-types on Murch ado about nothing</title>
    <link>http://murch.one/tags/output-types/</link>
    <description>Recent content in output-types on Murch ado about nothing</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 23 Dec 2021 00:00:00 +0000</lastBuildDate>
    <atom:link href="http://murch.one/tags/output-types/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>A breakdown of different output types and their address formats</title>
      <link>http://murch.one/posts/single-sig-output-types/</link>
      <pubDate>Thu, 23 Dec 2021 00:00:00 +0000</pubDate>
      <guid>http://murch.one/posts/single-sig-output-types/</guid>
      <description>&lt;p&gt;I was inspired by a recent &lt;a href=&#34;https://www.reddit.com/r/Bitcoin/comments/rjdao2/people_keep_asking_me_about_the_different_types/&#34;&gt;reddit post&lt;/a&gt; to write my own description of the various single-sig output formats in Bitcoin. I’ll be covering only output types that make use of a single signature.&lt;/p&gt;
&lt;h2 id=&#34;legacy-outputs-aka-p2pkh&#34;&gt;“Legacy Outputs” aka P2PKH&lt;/h2&gt;
&lt;p&gt;Pay to Public Key Hash was the first output type that got an address standard. Addresses for P2PKH outputs start with “1” and use the &lt;em&gt;Base58Check&lt;/em&gt; encoding. The address encoding provides a checksum and represents a shorthand to communicate recipient information—which improved the UX over the prior situation which required the sender to handle the recipient’s full public key or non-standard output script to send a transaction.&lt;/p&gt;
&lt;p&gt;Example: &lt;code&gt;1MDPuAy9WCbNQin71j9S3MKAAe9mGBRNVx&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Issues:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;High transaction weight&lt;/li&gt;
&lt;li&gt;Case-sensitive addresses&lt;/li&gt;
&lt;li&gt;Bigger data footprint than Pay to Public Key&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;wrapped-segwit-outputs-aka-p2sh-p2wpkh&#34;&gt;“Wrapped Segwit Outputs” aka P2SH-P2WPKH&lt;/h2&gt;
&lt;p&gt;Segwit aimed to introduce &lt;a href=&#34;https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki&#34;&gt;a new family of output types&lt;/a&gt; which we refer to as &lt;em&gt;native segwit&lt;/em&gt;, but the authors realized that adoption of a new address format would take time. The segwit softfork additionally introduced &lt;em&gt;wrapped segwit&lt;/em&gt; outputs as a transitional solution, to be forward-compatible to wallets that could send to P2SH addresses. Since P2SH was rolled out in March 2012 and already widely used for multisig, most wallet software supported sending to P2SH when segwit was activated in 2017.&lt;/p&gt;
&lt;p&gt;P2SH-wrapped Pay to Witness Public Key outputs are indistinguishable from other P2SH-uses until spent. All P2SH addresses start with the prefix “3” and use the &lt;em&gt;Base58Check&lt;/em&gt; encoding like P2PKH addresses.&lt;/p&gt;
&lt;p&gt;Wrapped segwit outputs lock funds to a &lt;em&gt;P2SH Program&lt;/em&gt;, but their input script contains a &lt;em&gt;Witness Program&lt;/em&gt; that redirects the script validation to the &lt;em&gt;Witness Stack&lt;/em&gt;. While this achieved forward-compatibility, the redirection requires additional data that needs to be relayed on the network and stored in the blockchain. Since witness data is discounted by 75% when assessing transaction weight, wrapped segwit inputs are cheaper to create, even while their data footprint is larger than P2PKH.&lt;/p&gt;
&lt;p&gt;All P2SH addresses start with “3”.&lt;/p&gt;
&lt;p&gt;Example: &lt;code&gt;3Mwz6cg8Fz81B7ukexK8u8EVAW2yymgWNd&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Issues:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Case-sensitive addresses&lt;/li&gt;
&lt;li&gt;Redirection to the witness stack for evaluation adds extra data&lt;/li&gt;
&lt;li&gt;Even bigger data footprint than P2PKH&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;native-segwit-outputs&#34;&gt;Native Segwit Outputs&lt;/h2&gt;
&lt;p&gt;Instead of locking funds to a &lt;em&gt;P2SH Program&lt;/em&gt;, the output script for native segwit outputs directly contains the &lt;em&gt;Witness Program&lt;/em&gt;. This way, native segwit inputs only need a witness stack, and make do without the redirection data needed in the wrapped segwit construction, leaving only a zero-length stub for the input script. Native segwit outputs are represented with &lt;em&gt;bech32&lt;/em&gt; addresses for version 0, and &lt;em&gt;bech32m&lt;/em&gt; for version 1–16. The bech32 encoding is single-case, making it easier to note down and dictate as well as more efficient to encode in QR codes. The bech32 encoding is engineered to provide error-detection guarantees. Bech32 and bech32m addresses start with “bc1”.&lt;/p&gt;
&lt;h3 id=&#34;0-p2wpkh-aka-native-segwit-v0&#34;&gt;0) P2WPKH aka Native Segwit v0&lt;/h3&gt;
&lt;p&gt;Often simply referred to as “native segwit”, Pay to Witness Public Key Hash outputs lock funds to a public key hash similar to how P2PKH works. However, P2WPKH inputs provide the public key and signature in the Witness Stack instead of the input script, thus benefiting from the witness discount. Bech32 addresses encoding version 0 native segwit outputs start with “bc1q”, because “q” encodes 0 in bech32.&lt;/p&gt;
&lt;p&gt;Example: &lt;code&gt;bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Issues:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bech32 addresses are still not supported by some wallets and services&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;1-p2tr-aka-taproot-aka-native-segwit-v1&#34;&gt;1) P2TR aka Taproot aka Native Segwit v1&lt;/h3&gt;
&lt;p&gt;With the recent activation of Taproot, we add native segwit v1 outputs to our portfolio. Pay to Taproot outputs lock funds directly to a public key in the output’s witness program, which means (for single-sig uses) that the input only needs a single script argument, a signature, instead of needing to provide both a public key and signature like P2WPKH. P2TR uses Schnorr signatures, which are more compactly encoded than ECDSA signatures, reducing the signature size from 71-72 B to 64 B. This means that P2TR has the smallest data footprint even while the overall weight of input and output is slightly bigger than for P2WPKH. In addition, more complex spending conditions can be encoded in the leaves of the taptree that’s tweaked into the public key contained in the witness program. Bech32m addresses encoding P2TR outputs are longer than the bech32 addresses encoding P2WPKH outputs, since public keys are longer than the 20-byte hash used in P2WPKH. Addresses for P2TR outputs start with “bc1p”, because “p” encodes 1.&lt;/p&gt;
&lt;p&gt;Example: &lt;code&gt;bc1pay2tapr00tajnawrkf897ccgsmk4e0x8ng5g3rv3qzd7jzfy2zxspy50gj&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Issues:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bech32m addresses are brand-new and not yet supported by many wallets and services&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;cost-considerations&#34;&gt;Cost Considerations&lt;/h2&gt;

&lt;figure class=&#34;image center&#34;&gt;
&lt;img src=&#34;http://murch.one/images/output-types.png&#34; alt=&#34;Table with overview of raw length, weight, and vsize of output types&#34;&gt;
&lt;/figure&gt;

&lt;p&gt;All four described output types satisfy single-sig usage, although P2TR can do a lot more under the hood. Generally, the transaction cost is cheaper for newer output types: Legacy &amp;gt; Wrapped Segwit &amp;gt; Native Segwit. While the overall cost of P2TR input and output is slightly higher than that of P2WPKH, P2TR shifts a portion of the cost from the input to the output. When you don’t know at what feerate you’ll need to pay to spend your funds later, you should keep them in P2TR outputs, since they’ll have the smallest input cost. Likewise, you should prefer P2TR when others are paying you: the sender pays the output cost while the recipient pays the input cost. Although, you may still bump into some counter-parties that cannot send to bech32, and many that cannot send to bech32m, yet, the economic incentives are clear. If your preferred wallet or service doesn’t support bech32(m) yet, please do ask them to do so.&lt;/p&gt;
&lt;p&gt;If you’re considering your transactions’ data footprint on the blockchain, you should also strictly prefer P2TR as it get you the most bang for the byte (see column “raw [B]” in table above). The data footprint for the output types is P2SH-P2WPKH &amp;gt; P2PKH &amp;gt; P2WPKH &amp;gt; P2TR.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>2-of-3 inputs using Pay-to-Taproot</title>
      <link>http://murch.one/posts/2-of-3-using-p2tr/</link>
      <pubDate>Tue, 18 Aug 2020 00:00:00 +0000</pubDate>
      <guid>http://murch.one/posts/2-of-3-using-p2tr/</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was &lt;a href=&#34;https://murchandamus.medium.com/2-of-3-multisig-inputs-using-pay-to-taproot-d5faf2312ba3&#34;&gt;originally published&lt;/a&gt; on my medium page on 2020-08-18.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;This article was amended on 2020–12–20 to improve the description of the P2TR output scripts. Thanks to Matthew Zipkin, for pointing out the prior imprecision.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The Bitcoin community has been &lt;a href=&#34;https://medium.com/hackernoon/excited-for-schnorr-signatures-a00ee467fc5f&#34;&gt;abuzz for a few years&lt;/a&gt; about bringing Schnorr signatures to Bitcoin. Since then, the idea has evolved into three formal Bitcoin Improvement Proposals: ‘&lt;a href=&#34;https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki&#34;&gt;BIP340 — Schnorr Signatures for secp256k1&lt;/a&gt;’, ‘&lt;a href=&#34;https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki&#34;&gt;BIP341 — Taproot: SegWit version 1 spending rules&lt;/a&gt;’, and ‘&lt;a href=&#34;https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki&#34;&gt;BIP342 — Validation of Taproot Scripts&lt;/a&gt;’. Respectively, they define a standard for Schnorr signatures in Bitcoin, introduce the Taproot construction, and formalize the new Script v1 instruction set. Taproot also iterates on the previous proposal of Merklized Alternative Script Trees (MAST).&lt;/p&gt;
&lt;p&gt;There are two ways of spending a pay-to-taproot (P2TR) output. The first way is called &lt;em&gt;keypath spending&lt;/em&gt;. P2TR funds are locked to a single public key similarly to &lt;em&gt;pay-to-public-key&lt;/em&gt; (P2PK) outputs. The output script appears in the transaction as &lt;code&gt;OP_1 &amp;lt;pubkey&amp;gt;&lt;/code&gt;. This script can be satisfied by providing an empty input script and a Schnorr signature of the corresponding private key in the witness program. The keypath is the default spending path. It is used in single-sig and collaborative multi-party spending.&lt;/p&gt;
&lt;p&gt;Under the hood, the public key is a composition of an &lt;em&gt;inner key&lt;/em&gt; and the Merkle root of a Taproot tree (the inner key is tweaked with the Merkle root). The inner key can optionally be a composite itself, for example multiple public keys aggregated via the &lt;a href=&#34;https://blockstream.com/2019/02/18/en-musig-a-new-multisignature-standard/&#34;&gt;MuSig&lt;/a&gt; scheme. These compositions are possible due to Schnorr signatures being linear.&lt;/p&gt;
&lt;p&gt;The second way of spending a P2TR output uses one of the Taproot leaves. We call this &lt;em&gt;scriptpath spending&lt;/em&gt;. First, the existence of the leaf needs to be proven which is done by revealing the inner key, the Merkle path to the Taproot leaf, and the script encoded in the leaf. Then, the spending conditions of the leaf’s script are fulfilled.&lt;/p&gt;
&lt;p&gt;The remainder of this article explores the input costs of 2-of-3 multisig Taproot constructions. Some familiarity with the details of the proposals is helpful. Check out the &lt;a href=&#34;https://bitcoinops.org/en/topics/taproot/&#34;&gt;Taproot overview&lt;/a&gt; and the excellent &lt;a href=&#34;https://bitcoinops.org/en/newsletters/2019/05/14/#overview-of-the-taproot--tapscript-proposed-bips&#34;&gt;summary of the three BIPs&lt;/a&gt; by the Bitcoin Optech Group if you are looking to refresh the details.&lt;/p&gt;
&lt;h2 id=&#34;the-multisig-user-story&#34;&gt;The multisig user story&lt;/h2&gt;
&lt;p&gt;We are looking at a wallet construction using three keys held by two or three parties. The first key is held by the user, the second key is held by the service provider, and the third key is a backup key either held by the user or a key recovery service. We are assuming that the first two keys are hot and can be used in an interactive signing scheme as employed by MuSig. The backup key may be held cold e.g. on an air-gapped system in which case interactive signing should be avoided.&lt;/p&gt;

&lt;figure class=&#34;image center&#34;&gt;
&lt;img src=&#34;http://murch.one/images/2-of-3-keys.png&#34;&gt;
&lt;figcaption&gt;
2-of-3 multisig with two hot keys and one (optionally) cold key&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Classically, a 2-of-3 multisig address is constructed in the form of a &lt;em&gt;pay-to-scripthash&lt;/em&gt; (P2SH) output of the form &lt;code&gt;2 &amp;lt;pubkey1&amp;gt; &amp;lt;pubkey2&amp;gt; &amp;lt;pubkey3&amp;gt; 3 OP_CHECKMULTISIG&lt;/code&gt;. This construction can logically be expressed as ‘(A ∧ B) ∨(A ∧ C) ∨(B ∧ C)’ which could also be thought of as “one of three 2-of-2 multisig scripts”. The latter translates nicely to Taproot: we can encode the preferred condition of spending with the user and the service key (the two hot keys) in an aggregated pubkey for the keypath, and put the two spending conditions using the backup key in leaves of the Taproot tree. Two variants are explored: one where the backup key is capable of participating in the interactive MuSig signing scheme, another that falls back to a simpler multisig scheme where signing is non-interactive e.g. because the backup key is air-gapped and the multiple roundtrips required for MuSig are inconvenient.&lt;/p&gt;

&lt;figure class=&#34;image center&#34;&gt;
&lt;img src=&#34;http://murch.one/images/tweak.png&#34;&gt;
&lt;figcaption&gt;
The most likely spending option with the two hot keys is encoded as an aggregated key in the keypath. The two backup spending options are put into leaves of the script tree.&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id=&#34;keypath-spending-costs&#34;&gt;Keypath spending costs&lt;/h2&gt;
&lt;p&gt;In the general case, all parties agree on a course of action and collaborate to use the keypath. This is the most cost-effective way to spend a P2TR output and allows multiparty spenders (and other complex spending conditions) to be indistinguishable from single-sig spenders.&lt;/p&gt;
&lt;h3 id=&#34;costs-of-keypath-input&#34;&gt;Costs of keypath input&lt;/h3&gt;
&lt;p&gt;An input commits to a specific &lt;em&gt;unspent transaction output&lt;/em&gt; (UTXO) which is defined by the transaction that created it and the position in that transaction’s output list. The UTXO entry provides the spending conditions to be satisfied by the spender. An &lt;em&gt;nSequence&lt;/em&gt; field allows encoding replaceability, and the witness provides the spender’s authentication. In the case of the keypath this is a single Schnorr signature which in some cases may actually consist of multiple aggregated signatures.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;outpoint (txid:vout): 32 vB+4 vB&lt;/li&gt;
&lt;li&gt;scriptSig size: 1 vB&lt;/li&gt;
&lt;li&gt;nSequence: 4 vB&lt;/li&gt;
&lt;li&gt;count witness items: 1 WU&lt;/li&gt;
&lt;li&gt;witness item size: 1 WU&lt;/li&gt;
&lt;li&gt;signature: 64 WU&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;32+4+1+4+(1+1+64)/4 = 57.5 vB&lt;/p&gt;
&lt;h2 id=&#34;control-blocks&#34;&gt;Control Blocks&lt;/h2&gt;
&lt;p&gt;When a fallback to the backup key is necessary, the existence of the Taproot tree must be revealed. If there is only a single leaf, the spender provides only the inner key. Tweaking the inner key with the hashed leaf results in the public key. In sum, the data necessary to prove the existence of a scriptpath is called the &lt;em&gt;control block&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id=&#34;depth-0-control-block&#34;&gt;Depth 0 control block&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Length of control block: 1 WU&lt;/li&gt;
&lt;li&gt;Header byte (script version, sign of output key): 1 WU&lt;/li&gt;
&lt;li&gt;Inner key: 32 WU&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;1+1+32 = 34 WU&lt;/p&gt;
&lt;p&gt;In case of two leaves, additionally the first hashing partner for the Merkle path must be revealed:&lt;/p&gt;
&lt;h3 id=&#34;depth-1-control-block&#34;&gt;Depth 1 control block&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Length of control block: 1 WU&lt;/li&gt;
&lt;li&gt;Header byte: 1 WU&lt;/li&gt;
&lt;li&gt;Inner key of root key: 32 WU&lt;/li&gt;
&lt;li&gt;Hashing partner in tree: 32 WU&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;1+ 1+ 32 + 32 = 66 WU&lt;/p&gt;
&lt;h2 id=&#34;scriptpath-spending-cost&#34;&gt;Scriptpath spending cost&lt;/h2&gt;
&lt;p&gt;The below costs are in addition to the above costs of spending via the keypath.&lt;/p&gt;
&lt;h3 id=&#34;scriptpath-spend-assuming-2-of-2-musig-leaf-hot-backup-key&#34;&gt;Scriptpath spend assuming 2-of-2 MuSig leaf (hot backup key)&lt;/h3&gt;
&lt;p&gt;When the backup key is on a networked system, e.g. an HSM, and can participate in a multi-roundtrip signing process, we can make use of MuSig to aggregate the two public keys.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;script size: 1 WU&lt;/li&gt;
&lt;li&gt;script &lt;code&gt;&amp;lt;pk&amp;gt; OP_CHECKSIG&lt;/code&gt;: 33 WU+1 WU&lt;/li&gt;
&lt;li&gt;Depth 1 Control block: 66 WU&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;57.5+(1+34+66)/4 = 82.75 vB&lt;/p&gt;
&lt;h3 id=&#34;construction-with-2-of-2-op_checksig-cold-backup-key-no-musig&#34;&gt;Construction with 2-of-2 OP_CHECKSIG (cold backup key, no MuSig)&lt;/h3&gt;
&lt;p&gt;In the case that the backup key is offline and a human would have to make multiple trips employing USB sticks or QR codes, saving roundtrips may take precedence over saving a few bytes. Instead of an aggregated public key, we use a non-interactive multisig construction.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;second signature: 1 WU+64 WU&lt;/li&gt;
&lt;li&gt;script size: 1 WU&lt;/li&gt;
&lt;li&gt;script &lt;code&gt;&amp;lt;pk1&amp;gt; OP_CHECKSIGVERIFY &amp;lt;pk2&amp;gt; OP_CHECKSIG&lt;/code&gt;: 33+1+33+1=68 WU&lt;/li&gt;
&lt;li&gt;Depth 1 Control block: 66 WU&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;57.5+(1+64+1+68+66)/4 = 107.5 vB&lt;/p&gt;
&lt;h3 id=&#34;discarded-approach-single-leaf-with-2-of-3-script&#34;&gt;Discarded approach: single leaf with 2-of-3 script&lt;/h3&gt;
&lt;p&gt;It turns out that a single 2-of-3 leaf in lieu of the two 2-of-2 leaves is both more costly and less private.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;+2nd sig: 1+64 WU&lt;/li&gt;
&lt;li&gt;+1 empty witness item: 2 WU&lt;/li&gt;
&lt;li&gt;Length of script: 1 WU&lt;/li&gt;
&lt;li&gt;Script &lt;code&gt;&amp;lt;pk1&amp;gt; OP_CHECKSIG &amp;lt;pk2&amp;gt; OP_CHECKSIGADD &amp;lt;pk3&amp;gt; OP_CHECKSIGADD 2 OP_EQUAL&lt;/code&gt;: 33+1+33+1+33+1+2=104 WU&lt;/li&gt;
&lt;li&gt;Depth 0 Control block: 34 WU&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;57.5+(1+64+2+1+104+34)/4 = 109 vB&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;

&lt;figure class=&#34;image center&#34;&gt;
&lt;img src=&#34;http://murch.one/images/2-of-3-costs.png&#34;&gt;
&lt;figcaption&gt;
Upper bound of input and output sizes for single-sig and 2-of-3 multisig&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;The described 2-of-3 multisig scheme achieves input sizes of 57.5 vbytes for a keypath spend, 82.75 vbytes for the leaves using a hot backup key, and 107.5 vbytes for non-interactive backup spends. This results in a fee reduction by 45% for 2-of-3 inputs when switching from P2WSH to P2TR spending. In the uncommon case of a recovery transaction, the cost is negligibly increased for cold keys. Single-sig users are also incentivized to switch to P2TR as they save 11 vbytes on each input — the output cost is externalized on the sender.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
