<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-19&#xA;📝 Original message:On Tue, Jun 19, 2018 at 7:20 AM, matejcik via bitcoin-dev&#xA;&lt;bitcoin-dev at lists.linuxfoundation.org&gt; wrote:&#xA;&#xA;Thanks for your comments so far. I&#39;m very happy to see people dig into&#xA;the details, and consider alternative approaches.&#xA;&#xA;&gt; 1) Why isn&#39;t the global type 0x03 (BIP-32 path) per-input? How do we&#xA;&gt; know, which BIP-32 path goes to which input? The only idea that comes to&#xA;&gt; my mind is that we should match the input&#39;s scriptPubKey&#39;s pubkey to&#xA;&gt; this 0x03&#39;s key (the public key).&#xA;&#xA;&gt; If our understanding is correct, the BIP-32 path is global to save space&#xA;&gt; in case two inputs share the same BIP-32 path? How often does that&#xA;&gt; happen? And in case it does, doesn&#39;t it mean an address reuse which is&#xA;&gt; discouraged?&#xA;&#xA;Yes, the reason is address reuse. It may be discouraged, but it still&#xA;happens in practice (and unfortunately it&#39;s very hard to prevent&#xA;people from sending to the same address twice).&#xA;&#xA;It&#39;s certainly possible to make them per-input (and even per-output as&#xA;suggested below), but I don&#39;t think it gains you much. At least when a&#xA;signer supports any kind of multisig, it needs to match up public keys&#xA;with derivation paths. If several can be provided, looking them up&#xA;from a global table or a per-input table shouldn&#39;t fundamentally&#xA;change anything.&#xA;&#xA;However, perhaps it makes sense to get rid of the global section&#xA;entirely, and make the whole format a transaction plus per-input and&#xA;per-output extra fields. This would result in duplication in case of&#xA;key reuse, but perhaps that&#39;s worth the complexity reduction.&#xA;&#xA;&gt; 2) The global items 0x01 (redeem script) and 0x02 (witness script) are&#xA;&gt; somewhat confusing. Let&#39;s consider only the redeem script (0x01) to make&#xA;&gt; it simple. The value description says: &#34;A redeem script that will be&#xA;&gt; needed to sign a Pay-To-Script-Hash input or is spent to by an output.&#34;.&#xA;&gt; Does this mean that the record includes both input&#39;s redeem script&#xA;&gt; (because we need to sign it), but also a redeem script for the output&#xA;&gt; (to verify we are sending to a correct P2SH)? To mix those two seems&#xA;&gt; really confusing.&#xA;&gt;&#xA;&gt; Yet again, adding a new output section would make this more readable. We&#xA;&gt; would include the input’s redeem script in the input section and the&#xA;&gt; output’s redeem script again in the output section, because they’ll most&#xA;&gt; likely differ anyway.&#xA;&#xA;I think here it makes sense because there can actually only be (up to)&#xA;one redeemscript and (up to) one witnessscript. So if we made those&#xA;per-input and per-output, it may simplify signers as they don&#39;t need a&#xA;table lookup to find the correct one. That would also mean we can drop&#xA;their hashes, even if we keep a key-value model.&#xA;&#xA;&gt; 3) The sighash type 0x03 says the sighash is only a recommendation. That&#xA;&gt; seems rather ambiguous. If the field is specified shouldn&#39;t it be binding?&#xA;&#xA;Perhaps, yes.&#xA;&#xA;&gt; 4) Is it a good idea to skip records which types we are unaware of? We&#xA;&gt; can&#39;t come up with a reasonable example, but intuitively this seems as a&#xA;&gt; potential security issue. We think we should consider  introducing a&#xA;&gt; flag, which would define if the record is &#34;optional&#34;. In case the signer&#xA;&gt; encounters a record it doesn&#39;t recognize and such flag is not set, it&#xA;&gt; aborts the procedure. If we assume the set model we could change the&#xA;&gt; structure to &lt;type&gt;&lt;optional flag&gt;&lt;length&gt;{data}. We are not keen on&#xA;&gt; this, but we wanted to include this idea to see what you think.&#xA;&#xA;Originally there was at least this intuition for why it shouldn&#39;t be&#xA;necessary: the resulting signature for an input is either valid or&#xA;invalid. Adding information to a PSBT (which is what signers do)&#xA;either helps with that or not. The worst case is that they simply&#xA;don&#39;t have enough information to produce a signature together. But an&#xA;ignored unknown field being present should never result in signing the&#xA;wrong thing (they can always see the transaction being signed), or&#xA;failing to sign if signing was possible in the first place. Another&#xA;way of looking at it, the operation of a signer is driven by queries:&#xA;it looks at the scriptPubKey of the output being spent, sees it is&#xA;P2SH, looks for the redeemscript, sees it is P2WSH, looks for the&#xA;witnessscript, sees it is multisig, looks for other signers&#39;&#xA;signatures, finds enough for the threshold, and proceeds to sign and&#xA;create a full transaction. If at any point one of those things is&#xA;missing or not comprehensible to the signer, he simply fails and&#xA;doesn&#39;t modify the PSBT.&#xA;&#xA;However, if the sighash request type becomes mandatory, perhaps this&#xA;is not the case anymore, as misinterpreting something like this could&#xA;indeed result in an incorrect signature.&#xA;&#xA;If we go down this route, if a field is marked as mandatory, can you&#xA;still act as a combiner for it? Future extensions should always&#xA;maintain the invariant that a simple combiner which just merges all&#xA;the fields and deduplicates should always be correct, I think. So such&#xA;a mandatory field should only apply to signers?&#xA;&#xA;&gt; In general, the standard is trying to be very space-conservative,&#xA;&gt; however is that really necessary? We would argue for clarity and ease of&#xA;&gt; use over space constraints. We think more straightforward approach is&#xA;&gt; desired, although more space demanding. What are the arguments to make&#xA;&gt; this as small as possible? If we understand correctly, this format is&#xA;&gt; not intended for blockchain nor for persistent storage, so size doesn’t&#xA;&gt; matter nearly as much.&#xA;&#xA;I wouldn&#39;t say it&#39;s trying very hard to be space-conservative. The&#xA;design train of thought started from &#34;what information does a signer&#xA;need&#34;, and found a signer would need information on the transaction to&#xA;sign, and on scripts to descend into, information on keys to derive,&#xA;and information on signatures provided by other participants. Given&#xA;that some of this information was global (at least the transaction),&#xA;and some of this information was per-input (at least the signatures),&#xA;separate scopes were needed for those. Once you have a global scope,&#xA;and you envision a signer which looks up scripts and keys in a map of&#xA;known ones (like the signing code in Bitcoin Core), there is basically&#xA;no downside to make the keys and scripts global - while giving space&#xA;savings for free to deduplication.&#xA;&#xA;However, perhaps that&#39;s not the right way to think about things, and&#xA;the result is simpler if we only keep the transaction itself global,&#xA;and everything else per-input (and per-output).&#xA;&#xA;I think there are good reasons to not be gratuitously large (I expect&#xA;that at least while experimenting, people will copy-paste these things&#xA;a lot and page-long copy pastes become unwieldy quickly), but maybe&#xA;not at the cost of structural complexity.&#xA;&#xA;On Tue, Jun 19, 2018 at 7:22 AM, matejcik via bitcoin-dev&#xA;&lt;bitcoin-dev at lists.linuxfoundation.org&gt; wrote:&#xA;&gt; hello,&#xA;&gt; this is our second e-mail with replies to Pieter&#39;s suggestions.&#xA;&gt;&#xA;&gt; On 16.6.2018 01:34, pieter.wuille at gmail.com (Pieter Wuille) wrote:&#xA;&gt;&gt; * Key-value map model or set model.&#xA;&#xA;&gt; Just to note, we should probably use varint for the &lt;type&gt; field - this&#xA;&gt; allows us, e.g., to create “namespaces” for future extensions by using&#xA;&gt; one byte as namespace identifier and one as field identifier.&#xA;&#xA;Agree, but this doesn&#39;t actually need to be specified right now. As&#xA;the key&#39;s (and or value&#39;s) interpretation (including the type) is&#xA;completely unspecified, an extension can just start using 2-byte keys&#xA;(as long as the first byte of those 2 isn&#39;t used by another field&#xA;already).&#xA;&#xA;&gt;&gt; One exception is the &#34;transaction&#34; record, which needs to be unique.&#xA;&gt;&gt; That can either be done by adding an exception (&#34;there can only be one&#xA;&gt;&gt; transaction record&#34;), or by encoding it separately outside the normal&#xA;&gt;&gt; records (that may also be useful to make it clear that it is always&#xA;&gt;&gt; required).&#xA;&gt;&#xA;&gt; This seems to be the case for some fields already - i.e., an input field&#xA;&gt; must have exactly one of Non-witness UTXO or Witness Output. So “adding&#xA;&gt; an exception” is probably just a matter of language?&#xA;&#xA;Hmm, I wouldn&#39;t say so. Perhaps the transaction&#39;s inputs and outputs&#xA;are chosen by one entity, and then sent to another entity which has&#xA;access to the UTXOs or previous transactions. So while the UTXOs must&#xA;be present before signing, I wouldn&#39;t say the file format itself must&#xA;enforce that the UTXOs are present.&#xA;&#xA;However, perhaps we do want to enforce at-most one UTXO per input. If&#xA;there are more potential extensions like this, perhaps a key-value&#xA;model is better, as it&#39;s much easier to enforce no duplicate keys than&#xA;it is to add field-specific logic to combiners (especially for&#xA;extensions they don&#39;t know about yet).&#xA;&#xA;&gt; We’d also like to note that the “number of inputs” field should be&#xA;&gt; mandatory - and as such, possibly also a candidate for outside-record field.&#xA;&#xA;If we go with the &#34;not put signatures/witnesses inside the transaction&#xA;until all of them are finalized&#34; suggestion, perhaps the number of&#xA;inputs field can be dropped. There would be always one exactly for&#xA;each input (but some may have the &#34;final script/witness&#34; field and&#xA;others won&#39;t).&#xA;&#xA;&gt;&gt; * Derivation from xpub or fingerprint&#xA;&gt;&gt;&#xA;&gt;&gt; For BIP32 derivation paths, the spec currently only encodes the 32-bit&#xA;&gt;&gt; fingerprint of the parent or master xpub. When the Signer only has a&#xA;&gt;&gt; single xprv from which everything is derived, this is obviously&#xA;&gt;&gt; sufficient. When there are many xprv, or when they&#39;re not available&#xA;&gt;&gt; indexed by fingerprint, this may be less convenient for the signer.&#xA;&gt;&gt; Furthermore, it violates the &#34;PSBT contains all information necessary&#xA;&gt;&gt; for signing, excluding private keys&#34; idea - at least if we don&#39;t treat&#xA;&gt;&gt; the chaincode as part of the private key.&#xA;&gt;&gt;&#xA;&gt;&gt; For that reason I would suggest that the derivation paths include the&#xA;&gt;&gt; full public key and chaincode of the parent or master things are&#xA;&gt;&gt; derived from. This does mean that the Creator needs to know the full&#xA;&gt;&gt; xpub which things are derived from, rather than just its fingerprint.&#xA;&gt;&#xA;&gt;&#xA;&gt; We don’t understand the rationale for this idea. Do you see a scenario&#xA;&gt; where an index on master fingerprint is not available but index by xpubs&#xA;&gt; is? In our envisioned use cases at least, indexing private keys by xpubs&#xA;&gt; (as opposed to deriving from a BIP32 path) makes no sense.&#xA;&#xA;Let me elaborate.&#xA;&#xA;Right now, the BIP32 fields are of the form &lt;master&#xA;fingerprint&gt;&lt;childidx&gt;&lt;childidx&gt;&lt;childidx&gt;...&#xA;&#xA;Instead, I suggest fields of the form &lt;master pubkey&gt;&lt;master&#xA;chaincode&gt;&lt;childidx&gt;&lt;childidx&gt;&lt;childidx&gt;...&#xA;&#xA;The fingerprint in this case is identical to the first 32 bit of the&#xA;Hash160 of &lt;master pubkey&gt;, so certainly no information is lost by&#xA;making this change.&#xA;&#xA;This may be advantageous for three reasons:&#xA;* It permits signers to have ~thousands of master keys (at which point&#xA;32-bit fingerprints would start having reasonable chance for&#xA;collisions, meaning multiple derivation attempts would be needed to&#xA;figure out which one to use).&#xA;* It permits signers to index their master keys by whatever they like&#xA;(for example, SHA256 rather than Hash160 or prefix thereof).&#xA;* It permits signers who don&#39;t store a chaincode at all, and just&#xA;protect a single private key.&#xA;&#xA;Cheers,&#xA;&#xA;-- &#xA;Pieter</html></oembed>