<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-26&#xA;📝 Original message:hello,&#xA;&#xA;in general, I agree with my colleague Tomas, the proposed changes are&#xA;good and achieve the most important things that we wanted. We&#39;ll review&#xA;the proposal in more detail later.&#xA;&#xA;For now a couple minor things I have run into:&#xA;&#xA;- valid test vector 2 (&#34;one P2PKH input and one P2SH-P2WPKH input&#34;)&#xA;seems broken, at least its hex version; a delimiter seems to be missing,&#xA;misplaced or corrupted&#xA;- at least the first signing vector is not updated, but you probably&#xA;know that&#xA;- BIP32 derivation fields don&#39;t specify size of the &#34;master public key&#34;,&#xA;which would make it un-parsable :)&#xA;- &#34;Transaction format is specified as follows&#34; and its table need to be&#xA;updated.&#xA;&#xA;&#xA;I&#39;m still going to argue against the key-value model though.&#xA;&#xA;It&#39;s true that this is not significant in terms of space. But I&#39;m more&#xA;concerned about human readability, i.e., confusing future implementers.&#xA;At this point, the key-value model is there &#34;for historical reasons&#34;,&#xA;except these aren&#39;t valid even before finalizing the format. The&#xA;original rationale for using key-values seems to be gone (no key-based&#xA;lookups are necessary). As for combining and deduplication, whether key&#xA;data is present or not is now purely a stand-in for a &#34;repeatable&#34; flag.&#xA;We could just as easily say, e.g., that the high bit of &#34;type&#34; specifies&#xA;whether this record can be repeated.&#xA;&#xA;(Moreover, as I wrote previously, the Combiner seems like a weirdly&#xA;placed role. I still don&#39;t see its significance and why is it important&#xA;to correctly combine PSBTs by agents that don&#39;t understand them. If you&#xA;have a usecase in mind, please explain.&#xA;ISTM a Combiner could just as well combine based on whole-record&#xA;uniqueness, and leave the duplicate detection to the Finalizer. In case&#xA;the incoming PSBTs have incompatible unique fields, the Combiner would&#xA;have to fail anyway, so the Finalizer might as well do it. Perhaps it&#xA;would be good to leave out the Combiner role entirely?)&#xA;&#xA;There&#39;s two remaining types where key data is used: BIP32 derivations&#xA;and partial signatures. In case of BIP32 derivation, the key data is&#xA;redundant ( pubkey = derive(value) ), so I&#39;d argue we should leave that&#xA;out and save space. In case of partial signatures, it&#39;s simple enough to&#xA;make the pubkey part of the value.&#xA;&#xA;Re breaking change, we are proposing breaking changes anyway, existing&#xA;code *will* need to be touched, and given that this is a hand-parsed&#xA;format, changing `parse_keyvalue` to `parse_record` seems like a small&#xA;matter?&#xA;&#xA;---&#xA;&#xA;At this point I&#39;m obliged to again argue for using protobuf.&#xA;&#xA;Thing is: BIP174 *is basically protobuf* (v2) as it stands. If I&#39;m&#xA;succesful in convincing you to switch to a record set model, it&#39;s going&#xA;to be &#34;protobuf with different varint&#34;.&#xA;&#xA;I mean this very seriously: (the relevant subset of) protobuf is a set&#xA;of records in the following format:&#xA;&lt;record type&gt;&lt;varint field length&gt;&lt;field data&gt;&#xA;Record types can repeat, the schema specifies whether a field is&#xA;repeatable or not - if it&#39;s not, the last parsed value is used.&#xA;&#xA;BIP174 is a ad-hoc format, simple to parse by hand; but that results in&#xA;_having to_ parse it by hand. In contrast, protobuf has a huge&#xA;collection of implementations that will do the job of sorting record&#xA;types into relevant struct fields, proper delimiting of records, etc.&#xA;...while at the same time, implementing &#34;protobuf-based-BIP174&#34; by hand&#xA;is roughly equally difficult as implementing the current BIP174.&#xA;&#xA;N.B., it&#39;s possible to write a parser for protobuf-BIP174 without&#xA;needing a general protobuf library. Protobuf formats are designed with&#xA;forwards- and backwards- compatibility in mind, so having a hand-written&#xA;implementation should not lead to incompatibilities.&#xA;&#xA;I did an experiment with this and other variants of the BIP174 format.&#xA;You can see them here:&#xA;[1] https://github.com/matejcik/bip174-playground&#xA;see in particular:&#xA;[2] https://github.com/matejcik/bip174-playground/blob/master/bip174.proto&#xA;&#xA;The tool at [1] does size comparisons. On the test vectors, protobuf is&#xA;slightly smaller than key-value, and roughly equal to record-set, losing&#xA;out a little when BIP32 fields are used.&#xA;(I&#39;m also leaving out key-data for BIP32 fields.)&#xA;&#xA;There&#39;s some technical points to consider about protobuf, too:&#xA;&#xA;- I decided to structure the message as a single &#34;PSBT&#34; type, where&#xA;&#34;InputType&#34; and &#34;OutputType&#34; are repeatable embedded fields. This seemed&#xA;better in terms of extensibility - we could add more sections in the&#xA;future. But the drawback is that you need to know the size of&#xA;Input/OutputType record in advance.&#xA;The other option is sending the messages separated by NUL bytes, same as&#xA;now, in which case you don&#39;t need to specify size.&#xA;&#xA;- in InputType, i&#39;m using &#34;uint32&#34; for sighash. This type is not&#xA;length-delimited, so non-protobuf consumers would have to understand it&#xA;specially. We could also declare that all fields must be&#xA;length-delimited[1] and implement sighash as a separate message type&#xA;with one field.&#xA;&#xA;- non-protobuf consumers will also need to understand both protobuf&#xA;varint and bitcoin compact uint, which is a little ugly&#xA;&#xA;best regards&#xA;matejcik&#xA;&#xA;&#xA;[1] https://developers.google.com/protocol-buffers/docs/encoding#structure&#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/20180626/a1c4e6e5/attachment.sig&gt;</html></oembed>