<oembed><type>rich</type><version>1.0</version><title>Pieter Wuille [ARCHIVE] wrote</title><author_name>Pieter Wuille [ARCHIVE] (npub1tj…jtl6r)</author_name><author_url>https://yabu.me/npub1tjephawh7fdf6358jufuh5eyxwauzrjqa7qn50pglee4tayc2ntqcjtl6r</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 Thu, Jun 21, 2018 at 4:29 AM, matejcik &lt;jan.matejek at satoshilabs.com&gt; wrote:&#xA;&gt; In the case of everything per-input, the naive Signer can do this:&#xA;&gt; 1. (in the global section) pre-serialize the transaction&#xA;&gt; 2. (in each input) find and fill out scriptPubKey from the provided UTXO&#xA;&gt; 3. (for a given BIP32 path) check if the master fingerprint matches&#xA;&gt; mine, if yes, derive secret key, output pubkey, signature&#xA;&gt; 4. goto 3 (more keys per input), goto 2 (next input)&#xA;&gt;&#xA;&gt; Note that this flow works perfectly for multisig; it’s going to be the&#xA;&gt; job of a Finalizer to build the final scriptSig, but each input can have&#xA;&gt; multiple partial signatures -- and, interestingly, the naive Signer&#xA;&gt; doesn’t even need to know about multisig.&#xA;&#xA;Ah, you&#39;re thinking of an even simpler signer than I was imagining. I&#xA;don&#39;t think this works in general, because the hash being signed&#xA;depends on the structure of the script. For example, if it is P2SH, it&#xA;is the redeemscript that goes into the scriptCode serialization rather&#xA;than the scriptPubKey. If it is segwit, BIP143 serialization needs to&#xA;be used, etc. It may work if your signing is restricted to just one of&#xA;those structures, though.&#xA;&#xA;&gt; A less naive Signer will want to check things, maybe derive a scriptSig&#xA;&gt; itself and check if it matches the given hash, etc., but it can do this&#xA;&gt; all in place. You go linearly through the signing flow and place a&#xA;&gt; couple strategic assertions along the way.&#xA;&#xA;Right - but I think anything but the simplest signer must do this,&#xA;just to be able to distinguish between different kinds of signature&#xA;hashing.&#xA;&#xA;But you&#39;re right, having per-input redeemscript/witnessscript&#xA;simplifies things still - instead of needing to look a script hash in&#xA;a map, you can just compare it with *the* redeemscript/witnessscript.&#xA;&#xA;&gt; However, if the data is global, as is now, it gets more complicated:&#xA;&gt; 1. (in the global section) pre-serialize the transaction, prefill lookup&#xA;&gt; tables&#xA;&gt; 2. (for a given BIP32 path) check if mine, then derive public key and&#xA;&gt; store in a dictionary&#xA;&gt; 3. (for each input) find _and parse_ scriptPubKey, extract (PK or)&#xA;&gt; script hash&#xA;&gt; 4. lookup redeem script based on script-hash; if not found, goto 2; if&#xA;&gt; found, parse out public key&#xA;&gt; 5. lookup public key in the BIP32 dictionary; if not found, goto 2&#xA;&gt; 6. output pubkey, signature&#xA;&#xA;I understand your point now. I hadn&#39;t considered the possibility of&#xA;just signing with all BIP32 derivation paths given for which the&#xA;master matches, instead of extracting pubkeys/pkhs from the script.&#xA;That&#39;s a major simplification for signers indeed. I do think you need&#xA;some conditions before to determine the script structure (see above),&#xA;but this is a good point in favour of making the derivation paths&#xA;per-input.&#xA;&#xA;&gt; In general, you seem to focus a lot on the role of Combiners, esp.&#xA;&gt; simple Combiners. To me, that doesn’t look like a significant role. As I&#xA;&gt; envision it, a Combiner really doesn’t need to do anything more&#xA;&gt; complicated than merge and deduplicate records, simply based on the&#xA;&gt; uniqueness of the whole record.&#xA;&#xA;It&#39;s more a side-effect of focusing on forward compatibility. I expect&#xA;that we will have transactions with inputs spending different kinds of&#xA;outputs, and some signers may not be able to understand all of them.&#xA;However, as long as the design goal of having Combiners function&#xA;correctly for things they don&#39;t understand, everything should be able&#xA;to work together fine.&#xA;&#xA;&gt; It’s the Finalizer’s job to reconstruct and validate the result. Also&#xA;&gt; ISTM if something messes up the PSBT (such as including multiple&#xA;&gt; conflicting fields anywhere), it’s OK to leave it to Finalizer to fail.&#xA;&#xA;Agree.&#xA;&#xA;&gt; An aside to this in particular, I’ve been thinking about the requirement&#xA;&gt; to share derivation paths and public keys with the Creator. The spec&#xA;&gt; assumes that this will happen; you’re talking about providing full&#xA;&gt; xpub+chaincode too. At least, the Creator must prefill BIP32 paths and&#xA;&gt; master key fingerprints. Possibly also prefill public keys in the redeem&#xA;&gt; scripts?&#xA;&gt;&#xA;&gt; This might not be an improvement proposal, but a point worth being&#xA;&gt; raised and maybe explained in the spec. Perhaps the original Creator&#xA;&gt; doesn’t have access to this data, and delegates this to some&#xA;&gt; “sub-Creators”  - I imagine a coordinator sending a PSBT to signing&#xA;&gt; parties, each of which acts as a sub-Creator (fills out derivation paths&#xA;&gt; and public keys) and a Signer (forwarding to a HWW). Some of the&#xA;&gt; discussion even suggests some sort of generic “key derivation field”&#xA;&gt; with arbitrary contents - fingerprint + bip32 path? xpub + chain code?&#xA;&gt; derivation points? encrypted xprv?&#xA;&#xA;That makes sense - I think we&#39;ve already touched this when discussing&#xA;the requirement for UTXOs to be added. Perhaps those aren&#39;t added by&#xA;the Creator, but by some index server. The same could be true for the&#xA;scripts or derivations paths.&#xA;&#xA;And indeed, most of the information in the derivation paths is&#xA;effectively opaque to the Creator - it&#39;s just some data given out by&#xA;the Signer about its keys that gets passed back to it so it can&#xA;identify the key. There is benefit in keeping it in a fixed structure&#xA;(like xpub/chaincode, or fingerprint + derivation indexes), to&#xA;guarantee compatibility between multiple signer implementations with&#xA;access to the same key.&#xA;&#xA;On Tue, Jun 19, 2018 at 5:39 PM, Jason Les via bitcoin-dev&#xA;&lt;bitcoin-dev at lists.linuxfoundation.org&gt; wrote:&#xA;&gt;&gt;Hex encoding?&#xA;&gt;&#xA;&gt; I was hoping for some standard here was well and I agree using something&#xA;&gt; more compact than hex is important. My understanding is Z85 is better for&#xA;&gt; use with JSON than Base64, which is probably a good benefit to have here.&#xA;&#xA;Both Base64 and Z85 can be stored in JSON strings without quoting&#xA;(neither uses quotation characters or backslashes), but Z85 is&#xA;slightly more compact (Z85 is 5 characters for 4 bytes, Base64 is 4&#xA;characters for 3 bytes). Both use non-alphanumeric characters, so I&#xA;don&#39;t think there is much difference w.r.t. copy-pastability either.&#xA;Z85 is far less common though.&#xA;&#xA;On Thu, Jun 21, 2018 at 4:44 AM, Tomas Susanka via bitcoin-dev&#xA;&lt;bitcoin-dev at lists.linuxfoundation.org&gt; wrote:&#xA;&gt;&gt; I think here it makes sense because there can actually only be (up to)&#xA;&gt;&gt; one redeemscript and (up to) one witnessscript. So if we made those&#xA;&gt;&gt; per-input and per-output, it may simplify signers as they don&#39;t need a&#xA;&gt;&gt; table lookup to find the correct one. That would also mean we can drop&#xA;&gt;&gt; their hashes, even if we keep a key-value model.&#xA;&gt; Yes, indeed. Just to clarify: in the first sentence you mean &#34;per&#xA;&gt; output&#34;, right? There can actually only be (up to) one redeemscript and&#xA;&gt; (up to) one witnessscript *per output*.&#xA;&#xA;Up to one per output, and up to one per input - indeed.&#xA;&#xA;On Thu, Jun 21, 2018 at 7:32 AM, Tomas Susanka via bitcoin-dev&#xA;&lt;bitcoin-dev at lists.linuxfoundation.org&gt; wrote:&#xA;&gt;&gt;&gt; A question to consider is,&#xA;&gt;&gt;&gt; will there be more per-output data? If yes, it might make sense to have&#xA;&gt;&gt;&gt; an output section.&#xA;&gt;&gt; I think it is unlikely that there would be anymore per-output data.&#xA;&gt;&#xA;&gt; Hmm, upon further reflection, maybe it&#39;s not even worth including *any*&#xA;&gt; per-output data, aside from what the original transaction contains.&#xA;&gt;&#xA;&gt; The output redeem script is either:&#xA;&gt; - unknown, because we have received only an address from the receiver&#xA;&gt; - or it is known, because it is ours and in that case it doesn’t make&#xA;&gt; sense to include it in PSBT&#xA;&gt;&#xA;&gt; We got stuck on the idea of the Creator providing future (output)&#xA;&gt; redeem/witness scripts. But that seems to be a minority use case and can&#xA;&gt; be solved efficiently via the same channels that coordinate the PSBT&#xA;&gt; creation. Sorry to change opinions so quickly on this one.&#xA;&#xA;Perhaps you&#39;re missing the reason for having output scripts? It is so&#xA;that signers that wish to known the amounts transferred can be told&#xA;which outputs of the to-be transaction are change, and thus shouldn&#39;t&#xA;be counted towards the balance. By providing the scripts and&#xA;derivation paths in a PSBT, the Creator can prove to the Signer that&#xA;certain outputs do not actually move funds to some other entity.&#xA;&#xA;&#xA;Based on the points before, my preference is having everything&#xA;per-input and per-output except the transaction (with empty&#xA;scriptSig/witness) itself, and having exactly one set/map per input&#xA;and output (which may include a &#34;finalized scriptSig/witness field&#34;&#xA;for finalized inputs). The overhead of having at least one separator&#xA;byte for every input and output in the transaction is at most a few&#xA;percent compared to the data in the transaction itself. If size is&#xA;really an issue (but I think we&#39;ve already established that small size&#xA;gains aren&#39;t worth much extra complexity), we could also serialize the&#xA;transaction without scriptSigs/witnesses (which are at least one byte&#xA;each, and guaranteed to be empty).&#xA;&#xA;I&#39;m unsure about typed record vs. key-value model. If we&#39;d go with a&#xA;per-input script approach, the key would just be a single byte (&#34;the&#xA;redeemscript&#34; and &#34;the witnessscript&#34;), so the advantage of being able&#xA;to drop the script hashes applies equally to both models. After that,&#xA;it seems the only difference seems to be that a well-defined prefix of&#xA;the records is enforced to be unique as opposed to the entire record&#xA;being enforced to be unique. I don&#39;t think there is much difference in&#xA;complexity, as Combiners and Signers still need to enforce some kind&#xA;of uniqueness even in a typed records model.&#xA;&#xA;Cheers,&#xA;&#xA;-- &#xA;Pieter</html></oembed>