<div dir="ltr"><div>Update: BIP 79 has been implemented in the latest release of Electrum, v2.3.2: <br><br><a href="https://github.com/spesmilo/electrum/blob/master/RELEASE-NOTES">https://github.com/spesmilo/electrum/blob/master/RELEASE-NOTES</a><br><br></div>-Kristov<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 12, 2015 at 5:36 PM, Kristov Atlas <span dir="ltr">&lt;<a href="mailto:kristovatlas.lists@gmail.com" target="_blank">kristovatlas.lists@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Since everyone&#39;s busy, I went ahead and made a pull request to add this as an informational BIP 79 to the bips directory.<br><br><a href="https://github.com/bitcoin/bips/pull/157" target="_blank">https://github.com/bitcoin/bips/pull/157</a><br><br></div>Regards,<br></div>Kristov<br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 9, 2015 at 4:14 PM, Peter Todd <span dir="ltr">&lt;<a href="mailto:pete@petertodd.org" target="_blank">pete@petertodd.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Jun 08, 2015 at 06:53:54PM -0400, Kristov Atlas wrote:<br>
<br>
Two other things:<br>
<div><div><br>
<br>
<br>
&gt; On Sat, Jun 6, 2015 at 10:35 PM, Peter Todd &lt;<a href="mailto:pete@petertodd.org" target="_blank">pete@petertodd.org</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; Why mention SIGHASH_SINGLE at all? Its use-case is highly specialized<br>
&gt; &gt; protocols; you haven&#39;t taken into account the needs of those protocols.<br>
&gt; &gt; For BIP&#39;s it&#39;s better to stick to the use-cases where the need is clear<br>
&gt; &gt; and there exists running code that to speculate too much on future uses.<br>
&gt; &gt; With signature hashing in particular it&#39;s not yet clear at all what<br>
&gt; &gt; future OP_CHECKSIG&#39;s will look like, let alone the various ways people<br>
&gt; &gt; will use sighash for smart contract type stuff.<br>
&gt; &gt;<br>
&gt; &gt; You&#39;d be better off presenting the BIP in terms of a generic statement<br>
&gt; &gt; that &quot;except when otherwise prevented by advanced signature hashing<br>
&gt; &gt; requirements, wallet software must emit transactions sorted according to<br>
&gt; &gt; the following&quot; You can then specify the two common cases in detail:<br>
&gt; &gt;<br>
&gt; &gt; 1) SIGHASH_ALL: input and output order signed, so sort appropriately<br>
&gt; &gt;<br>
&gt; &gt; 2) SIGHASH_ANYONECANPAY: input order not signed, so software should emit<br>
&gt; &gt;    transactions sorted, recognising that the actual mined order may be<br>
&gt; &gt;    changed.<br>
&gt; &gt;<br>
&gt;<br>
&gt; That makes sense. I updated the language as follows -- your thoughts? Keep<br>
&gt; in mind this BIP is informational, and so people are free to ignore it.<br>
&gt;<br>
&gt; &quot;Applicability: This BIP applies to all transactions of signature hash type<br>
&gt; SIGHASH_ALL. Additionally,  software compliant with this BIP that allows<br>
&gt; later parties to update the transaction (e.g. using signature hash types<br>
&gt; SIGHASH_NONE or a variant of SIGHASH_ANYONECANPAY) should emit<br>
&gt; lexicographically sorted inputs and outputs, although they may later be<br>
&gt; modified. Transactions that have index dependencies between transactions or<br>
&gt; within the same transaction are covered under the section of this BIP<br>
&gt; entitled “Handling Input/Output Dependencies.”&quot;<br>
<br>
</div></div>I&#39;d keep it even simpler than that, and just say for now that such<br>
use-cases are out of the scope of this BIP, however those standards<br>
should come up with some kind of deterministic standard that meets the<br>
needs of the protocol. Again, there&#39;s a bunch of possible use-cases here<br>
and we just can&#39;t predict them; focus on the fact that the *spirit* of<br>
what this BIP is about is applicable and future standards should be<br>
developed.<br>
<br>
So I&#39;d change the &quot;Applicability&quot; section to:<br>
<br>
This BIP applies to all transactions where the order of inputs and<br>
outputs does not matter. This is true for the vast majority of<br>
transactions as they simply move funds from one place to another.<br>
<br>
Currently this generally refers to transactions where SIGHASH_ALL is<br>
used, in which case the signatures commit to the exact order of input<br>
and outputs. In the case where SIGHASH_ANYONECANPAY and/or SIGHASH_NONE<br>
has been used (e.g. crowdfunds) the order of inputs and/or outputs may<br>
not be signed, however compliant software should still emit transactions<br>
with sorted inputs and outputs, even though they may later be modified<br>
by others.<br>
<br>
In the event that future protocol upgrades introduce new signature hash<br>
types, compliant software should apply the lexographic ordering<br>
principle analogously.<br>
<br>
While out of scope of this BIP, protocols that do require a specified<br>
order of inputs/outputs (e.g. due to use of SIGHASH_SINGLE) should<br>
consider the goals of this BIP and how best to adapt them to the<br>
specifics needs of those protocols.<br>
<br>
<br>
Then remove the &quot;handling input/output deps&quot; section.<br>
<span><br>
&gt; &gt; Do you have a patch implementing deterministic tx ordering for Bitcoin<br>
&gt; &gt; Core yet?<br>
&gt; &gt;<br>
&gt;<br>
&gt; I&#39;m not a frequent C programmer, so I&#39;d prefer to let someone else take<br>
&gt; care of it, as a frequent committer of code would do a faster and more<br>
&gt; stylistically consistent job of it. If no one else will, however, I will.<br>
<br>
<br>
<br>
</span>re: the actual ordering algorithm, having txids be sorted by with the<br>
hex-based algorithm is odd. I&#39;d simply say they&#39;re sorted as<br>
little-endian byte arrays, or in other words, with the bytearr_cmp()<br>
function, but with the order of bytes reversed. You also should say that<br>
we&#39;re doing that to make the user see them in visually sorted order to<br>
match expectations because txids are displayed as little-endian.<br>
<br>
For outputs, don&#39;t say &quot;locking script&quot;, say &quot;scriptPubKey&quot;. Secondly,<br>
scriptPubKeys are not in little-endian representation - they have no<br>
endianness to them. With output amount, there&#39;s no need to say that<br>
they&#39;re unsigned or little-endian satoshies, just say they&#39;re sorted<br>
largest/smallest amount first.<br>
<br>
&quot;For the sake of efficiency, amounts will be considered first for<br>
sorting, since they contain fewer bytes of information (7 bytes)<br>
compared to a standard P2PKH locking script (800 bytes).&quot; &lt;- where the<br>
heck did you get these numbers from? Amounts are 8 bytes, and P2PKH<br>
scriptPubKeys are 25 bytes.<br>
<br>
<br>
&quot;Backwards Compatibility&quot; &lt;- I&#39;d just remove this whole section; we&#39;re<br>
unlikely to make this an IsStandard() rule anytime soon.<br>
<span><font color="#888888"><br>
--<br>
&#39;peter&#39;[:-1]@<a href="http://petertodd.org" rel="noreferrer" target="_blank">petertodd.org</a><br>
0000000000000000127ab1d576dc851f374424f1269c4700ccaba2c42d97e778<br>
</font></span></blockquote></div><br></div>
</div></div></blockquote></div><br></div>