Closed Roasbeef closed 4 months ago
The one interaction to point out here is that for commitment transactions today we sort all the outputs after constructing the commitment transaction. However for TAP, we use a split commitment mapping which indexes into all the output indicies. As a result, if we sort after we make all the split commitments, then the split proofs will be broken.
I started work on this part today. Luckily it's not as bad as I though, since the actual split commitment doesn't go into the Taproot Asset commitment (so it doesn't have a direct impact on the pk script itself, otherwise this would've become a recursive algorithm). So worst case, we have to create the output commitments twice.
This is related to: https://github.com/lightninglabs/taproot-assets/issues/863.
Given the ability to encode/decode our book keeping data in TLV blobs, we now need a way to map that blob, and some additional channel information into the set of tapscript leaves that'll commit to the asset information in all the commitment outputs.
Primary Abstraction Definition
As is, the primary interface resembles something like:
Primary Abstraction Overview
The first three methods are used to obtain the set of commit leaves (or nothing) for a given state. The last method is used to map the blob of a previous commitment, and a new commitment into the next blob we'll store for that commitment.
Correlation w/ the bLIP & Sorting Edge Case
This interface is meant to abstract away from this section of the channels bLIP. Given a description of a channel commitment (includes the blob, and all HTLC information), and the key ring (the keys we'll use for all the scripts), we'll need to derive all the relevant tap leaves for a given state.
All the tapleaves for now will just use the exact same set of scripts that we use for taproot channels which live here. The
AuxTapLeaf
returned will simply be the top level asset commitment for that given output.The one interaction to point out here is that for commitment transactions today we sort all the outputs after constructing the commitment transaction. However for TAP, we use a split commitment mapping which indexes into all the output indicies. As a result, if we sort after we make all the split commitments, then the split proofs will be broken.
To handle this properly, we'll need to note some details about the sorting algorithm. It sorts first by output amount, then the pkscript. For all the HTLCs that are TAP related, they'll be right above dust, so they'll have the same amount. For the local+remote outputs, this means that we know they'll be somewhere at "top" of the commitment transactions. Therefore, we know the placement of the anchor output (the initiator's commitment balance), so we can do the sorting routine within one of the methods above to derive a final stable sorting order.