<oembed><type>rich</type><version>1.0</version><title>matejcik [ARCHIVE] wrote</title><author_name>matejcik [ARCHIVE] (npub18g…sgac3)</author_name><author_url>https://yabu.me/npub18g04tf4qudcsna6qfcrm55s39axx3ymrunr65gxen4rctm0zv24sasgac3</author_url><provider_name>njump</provider_name><provider_url>https://yabu.me</provider_url><html>📅 Original date posted:2018-06-21&#xA;📝 Original message:On 19.6.2018 19:16, Pieter Wuille wrote:&#xA;&gt;&gt; 1) Why isn&#39;t the global type 0x03 (BIP-32 path) per-input? How do we&#xA;&gt;&gt; know, which BIP-32 path goes to which input? The only idea that comes to&#xA;&gt;&gt; my mind is that we should match the input&#39;s scriptPubKey&#39;s pubkey to&#xA;&gt;&gt; this 0x03&#39;s key (the public key).&#xA;&gt; &#xA;&gt;&gt; If our understanding is correct, the BIP-32 path is global to save space&#xA;&gt;&gt; in case two inputs share the same BIP-32 path? How often does that&#xA;&gt;&gt; happen? And in case it does, doesn&#39;t it mean an address reuse which is&#xA;&gt;&gt; discouraged?&#xA;&gt; &#xA;&gt; Yes, the reason is address reuse. It may be discouraged, but it still&#xA;&gt; happens in practice (and unfortunately it&#39;s very hard to prevent&#xA;&gt; people from sending to the same address twice).&#xA;&gt; &#xA;&gt; It&#39;s certainly possible to make them per-input (and even per-output as&#xA;&gt; suggested below), but I don&#39;t think it gains you much. At least when a&#xA;&gt; signer supports any kind of multisig, it needs to match up public keys&#xA;&gt; with derivation paths. If several can be provided, looking them up&#xA;&gt; from a global table or a per-input table shouldn&#39;t fundamentally&#xA;&gt; change anything.&#xA;&#xA;So here’s a thing I’m still confused about.&#xA;&#xA;Imagine two cases, for a naive Signer:&#xA;- either all data is global&#xA;- or most data is per input.&#xA;&#xA;Now, the general signing flow is this:&#xA;1. Pre-serialize the transaction&#xA;2. Prepare the current input - fill out scriptPubKey (or equivalent for&#xA;segwit)&#xA;3. find a secret key&#xA;4. output public key + signature&#xA;&#xA;Step (3) is the main issue here.&#xA;&#xA;In the case of everything per-input, the naive Signer can do this:&#xA;1. (in the global section) pre-serialize the transaction&#xA;2. (in each input) find and fill out scriptPubKey from the provided UTXO&#xA;3. (for a given BIP32 path) check if the master fingerprint matches&#xA;mine, if yes, derive secret key, output pubkey, signature&#xA;4. goto 3 (more keys per input), goto 2 (next input)&#xA;&#xA;Note that this flow works perfectly for multisig; it’s going to be the&#xA;job of a Finalizer to build the final scriptSig, but each input can have&#xA;multiple partial signatures -- and, interestingly, the naive Signer&#xA;doesn’t even need to know about multisig.&#xA;&#xA;A less naive Signer will want to check things, maybe derive a scriptSig&#xA;itself and check if it matches the given hash, etc., but it can do this&#xA;all in place. You go linearly through the signing flow and place a&#xA;couple strategic assertions along the way.&#xA;&#xA;However, if the data is global, as is now, it gets more complicated:&#xA;1. (in the global section) pre-serialize the transaction, prefill lookup&#xA;tables&#xA;2. (for a given BIP32 path) check if mine, then derive public key and&#xA;store in a dictionary&#xA;3. (for each input) find _and parse_ scriptPubKey, extract (PK or)&#xA;script hash&#xA;4. lookup redeem script based on script-hash; if not found, goto 2; if&#xA;found, parse out public key&#xA;5. lookup public key in the BIP32 dictionary; if not found, goto 2&#xA;6. output pubkey, signature&#xA;&#xA;In addition to being more steps and lookups, it requires the Signer to&#xA;understand the redeem script. A strict Signer will want that anyway, but&#xA;in the first case, the Signer can regenerate the scripts and compare&#xA;specificaly the ones it&#39;s working with; here, you need to parse them&#xA;even before you know what you&#39;re comparing to.&#xA;&#xA;Is there something I’m missing? Because as I see it, there is literally&#xA;no advantage to the more complicated flow; that’s why we assumed that&#xA;the format is space-saving, because saving space was the only reason we&#xA;could imagine.&#xA;&#xA;&gt; If we go down this route, if a field is marked as mandatory, can you&#xA;&gt; still act as a combiner for it? Future extensions should always&#xA;&gt; maintain the invariant that a simple combiner which just merges all&#xA;&gt; the fields and deduplicates should always be correct, I think. So such&#xA;&gt; a mandatory field should only apply to signers?&#xA;&#xA;(...)&#xA;&#xA;&gt; However, perhaps we do want to enforce at-most one UTXO per input. If&#xA;&gt; there are more potential extensions like this, perhaps a key-value&#xA;&gt; model is better, as it&#39;s much easier to enforce no duplicate keys than&#xA;&gt; it is to add field-specific logic to combiners (especially for&#xA;&gt; extensions they don&#39;t know about yet).&#xA;&#xA;In general, you seem to focus a lot on the role of Combiners, esp.&#xA;simple Combiners. To me, that doesn’t look like a significant role. As I&#xA;envision it, a Combiner really doesn’t need to do anything more&#xA;complicated than merge and deduplicate records, simply based on the&#xA;uniqueness of the whole record.&#xA;It’s the Finalizer’s job to reconstruct and validate the result. Also&#xA;ISTM if something messes up the PSBT (such as including multiple&#xA;conflicting fields anywhere), it’s OK to leave it to Finalizer to fail.&#xA;&#xA;Are the Combiners supposed to be separate from Finalizers? (Is there a&#xA;risk of a Combiner passing along a bad PSBT, Finalizer rejecting it, and&#xA;the other parties not finding out?)&#xA;&#xA;&#xA;&gt; If we go with the &#34;not put signatures/witnesses inside the transaction&#xA;&gt; until all of them are finalized&#34; suggestion, perhaps the number of&#xA;&gt; inputs field can be dropped. There would be always one exactly for&#xA;&gt; each input (but some may have the &#34;final script/witness&#34; field and&#xA;&gt; others won&#39;t).&#xA;&#xA;Strongly agree with this. A guarantee that number of inputs in the&#xA;transaction corresponds to number of input fields for PBST looks cleaner&#xA;than specifying it separately. This way we can also drop the &#34;input index&#34;.&#xA;&#xA;&#xA;&gt; Right now, the BIP32 fields are of the form &lt;master&#xA;&gt; fingerprint&gt;&lt;childidx&gt;&lt;childidx&gt;&lt;childidx&gt;...&#xA;&gt; &#xA;&gt; Instead, I suggest fields of the form &lt;master pubkey&gt;&lt;master&#xA;&gt; chaincode&gt;&lt;childidx&gt;&lt;childidx&gt;&lt;childidx&gt;...&#xA;&gt; &#xA;&gt; The fingerprint in this case is identical to the first 32 bit of the&#xA;&gt; Hash160 of &lt;master pubkey&gt;, so certainly no information is lost by&#xA;&gt; making this change.&#xA;&gt; &#xA;&gt; This may be advantageous for three reasons:&#xA;&gt; * It permits signers to have ~thousands of master keys (at which point&#xA;&gt; 32-bit fingerprints would start having reasonable chance for&#xA;&gt; collisions, meaning multiple derivation attempts would be needed to&#xA;&gt; figure out which one to use).&#xA;&gt; * It permits signers to index their master keys by whatever they like&#xA;&gt; (for example, SHA256 rather than Hash160 or prefix thereof)&gt; * It permits signers who don&#39;t store a chaincode at all, and just&#xA;&gt; protect a single private key.&#xA;&#xA;I like this last usecase a lot, but perhaps that&#39;s a role for a&#xA;&#34;sub-Creator&#34;? see below.&#xA;&#xA;Also, is there a reason to publish the chain code, wouldn&#39;t just the&#xA;public key be sufficient to accomplish all three usecases you list?&#xA;I sort of dislike the notion that you need to give all this information&#xA;to a possibly untrusted Creator.&#xA;&#xA;&#xA;An aside to this in particular, I’ve been thinking about the requirement&#xA;to share derivation paths and public keys with the Creator. The spec&#xA;assumes that this will happen; you’re talking about providing full&#xA;xpub+chaincode too. At least, the Creator must prefill BIP32 paths and&#xA;master key fingerprints. Possibly also prefill public keys in the redeem&#xA;scripts?&#xA;&#xA;This might not be an improvement proposal, but a point worth being&#xA;raised and maybe explained in the spec. Perhaps the original Creator&#xA;doesn’t have access to this data, and delegates this to some&#xA;“sub-Creators”  - I imagine a coordinator sending a PSBT to signing&#xA;parties, each of which acts as a sub-Creator (fills out derivation paths&#xA;and public keys) and a Signer (forwarding to a HWW). Some of the&#xA;discussion even suggests some sort of generic “key derivation field”&#xA;with arbitrary contents - fingerprint + bip32 path? xpub + chain code?&#xA;derivation points? encrypted xprv?&#xA;&#xA;thank you for your comments&#xA;&#xA;regards&#xA;m.&#xA;&#xA;-------------- next part --------------&#xA;A non-text attachment was scrubbed...&#xA;Name: signature.asc&#xA;Type: application/pgp-signature&#xA;Size: 819 bytes&#xA;Desc: OpenPGP digital signature&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/bitcoin-dev/attachments/20180621/92c941f5/attachment-0001.sig&gt;</html></oembed>