<oembed><type>rich</type><version>1.0</version><title>Tomas Susanka [ARCHIVE] wrote</title><author_name>Tomas Susanka [ARCHIVE] (npub1pz…xnfhv)</author_name><author_url>https://yabu.me/npub1pzhqhlvhvdg3ygr8keypprax6gg0qmsrtypmez67few4uzsvhqaqkxnfhv</author_url><provider_name>njump</provider_name><provider_url>https://yabu.me</provider_url><html>📅 Original date posted:2018-06-21&#xA;📝 Original message:Hi,&#xA;&#xA;On 19.6.2018 19:16, Pieter Wuille via bitcoin-dev wrote:&#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;&gt;&#xA;&gt; However, perhaps it makes sense to get rid of the global section&#xA;&gt; entirely, and make the whole format a transaction plus per-input and&#xA;&gt; per-output extra fields. This would result in duplication in case of&#xA;&gt; key reuse, but perhaps that&#39;s worth the complexity reduction.&#xA;I think having a global section with just one record (the transaction)&#xA;is just fine, in case we come up with some other fields later on which&#xA;would fit the global section. Otherwise I totally agree.&#xA;&gt;&gt; 2) The global items 0x01 (redeem script) and 0x02 (witness script) are&#xA;&gt;&gt; somewhat confusing. Let&#39;s consider only the redeem script (0x01) to make&#xA;&gt;&gt; it simple. The value description says: &#34;A redeem script that will be&#xA;&gt;&gt; needed to sign a Pay-To-Script-Hash input or is spent to by an output.&#34;.&#xA;&gt;&gt; Does this mean that the record includes both input&#39;s redeem script&#xA;&gt;&gt; (because we need to sign it), but also a redeem script for the output&#xA;&gt;&gt; (to verify we are sending to a correct P2SH)? To mix those two seems&#xA;&gt;&gt; really confusing.&#xA;&gt;&gt;&#xA;&gt;&gt; Yet again, adding a new output section would make this more readable. We&#xA;&gt;&gt; would include the input’s redeem script in the input section and the&#xA;&gt;&gt; output’s redeem script again in the output section, because they’ll most&#xA;&gt;&gt; likely differ anyway.&#xA;&gt; I think here it makes sense because there can actually only be (up to)&#xA;&gt; one redeemscript and (up to) one witnessscript. So if we made those&#xA;&gt; per-input and per-output, it may simplify signers as they don&#39;t need a&#xA;&gt; table lookup to find the correct one. That would also mean we can drop&#xA;&gt; their hashes, even if we keep a key-value model.&#xA;Yes, indeed. Just to clarify: in the first sentence you mean &#34;per&#xA;output&#34;, right? There can actually only be (up to) one redeemscript and&#xA;(up to) one witnessscript *per output*.&#xA;&gt;&gt; 4) Is it a good idea to skip records which types we are unaware of? We&#xA;&gt;&gt; can&#39;t come up with a reasonable example, but intuitively this seems as a&#xA;&gt;&gt; potential security issue. We think we should consider  introducing a&#xA;&gt;&gt; flag, which would define if the record is &#34;optional&#34;. In case the signer&#xA;&gt;&gt; encounters a record it doesn&#39;t recognize and such flag is not set, it&#xA;&gt;&gt; aborts the procedure. If we assume the set model we could change the&#xA;&gt;&gt; structure to &lt;type&gt;&lt;optional flag&gt;&lt;length&gt;{data}. We are not keen on&#xA;&gt;&gt; this, but we wanted to include this idea to see what you think.&#xA;&gt; Originally there was at least this intuition for why it shouldn&#39;t be&#xA;&gt; necessary: the resulting signature for an input is either valid or&#xA;&gt; invalid. Adding information to a PSBT (which is what signers do)&#xA;&gt; either helps with that or not. The worst case is that they simply&#xA;&gt; don&#39;t have enough information to produce a signature together. But an&#xA;&gt; ignored unknown field being present should never result in signing the&#xA;&gt; wrong thing (they can always see the transaction being signed), or&#xA;&gt; failing to sign if signing was possible in the first place. Another&#xA;&gt; way of looking at it, the operation of a signer is driven by queries:&#xA;&gt; it looks at the scriptPubKey of the output being spent, sees it is&#xA;&gt; P2SH, looks for the redeemscript, sees it is P2WSH, looks for the&#xA;&gt; witnessscript, sees it is multisig, looks for other signers&#39;&#xA;&gt; signatures, finds enough for the threshold, and proceeds to sign and&#xA;&gt; create a full transaction. If at any point one of those things is&#xA;&gt; missing or not comprehensible to the signer, he simply fails and&#xA;&gt; doesn&#39;t modify the PSBT.&#xA;The rationale behind this was, what if at some point we come up with a&#xA;PSBT record, which forbids some kind of operation or alters some&#xA;behaviour. In another words, by omitting such record the signer would&#xA;create a signature, which is valid, but actually signed something&#xA;different than the Creator intended.&#xA;&#xA;&gt; However, if the sighash request type becomes mandatory, perhaps this&#xA;&gt; is not the case anymore, as misinterpreting something like this could&#xA;&gt; indeed result in an incorrect signature.&#xA;I believe this use case illustrates it quite well. Let’s suppose the&#xA;sighash record is binding and the Signer does not know it. The Creator&#xA;creates a PSBT with sighash set SIGHASH_SINGLE. The Signer sings the&#xA;transaction with SIGHASH_ALL, because they are not aware of such field.&#xA;This results in a valid signature, however not what the Creator intended&#xA;it to be.&#xA;&#xA;&gt;&gt; We’d also like to note that the “number of inputs” field should be&#xA;&gt;&gt; mandatory - and as such, possibly also a candidate for outside-record field.&#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;Agree. I&#39;m be fine with dropping the field completely in that case.&#xA;&#xA;&#xA;Thanks,&#xA;Tomas</html></oembed>