[RFC] Canonical input and output ordering in transactions



Summary:

Mark Friedenbach suggests a special exemption for compact commitments via mid-state compression. The use case involves an OP_RETURN output sorted last, with the last N bytes serving as a commitment, and a proof of the commitment using mid-state compression to elide the beginning of the transaction. However, it is challenging to create a clean exemption without requiring an advertisement of sort-order exemptions. Despite this challenge, outputs can be sorted by the first byte minus 107 (or 0 if script is zero length) and the remainder of the script in lexicographical order. This method would place OP_RETURN outputs last. Peter Todd's more general best-effort language could also be used, as OP_RETURN transactions cannot be hidden to look like something else, so non-canonical ordering will not be an issue.


Updated on: 2023-06-09T22:18:10.230562+00:00