-
Notifications
You must be signed in to change notification settings - Fork 12
Description
I’ve been working on a draft proposal for aggregating Lightning HTLCs in a single output on the commitment transaction. The idea is to avoid the commitment getting large when forwarding a lot of HTLCs, and making it cheaper to claim them after a force close.
To make this work I need some sort of covenant, and I’m wondering if someone has any opinion on which proposal would be best to pursue.
Let’s say the output script and amount encoding the active HTLCs is on the form [hash1 amt1 … hashn amtn] <script>:sum, where the <script> part can be static as long as you know the number n.
Simple example
Now we want to claim htlc1 on chain, and present the preimage for hash1. We must enforce that the new output script is on the form [hash2 amt2 … hashn amtn] <script>:sum-amt1. (Note that htlc1 and its amount has been removed, everything else stays the same. Since we presented a valid preimage we can do with the subtracted amount whatever we like).
Requirements
First, we need a check for the output amount. This has been discussed in other settings, and we most likely also need a way to do 64 bit math in the script.
Next, we need a way to verify that the new taproot output is based on the remaining hashes. One way to do this is to tweak the taproot internal key with all the hashes and amounts, and that way commit to them. This way we could keep this “dynamic commitment data” in the internal key, while the actual taproot tree can be mostly static (it just commits to the static script). This would need some way of inspecting the key (or verifying arbitrary data against it) when spending. OP_CHECK[INPUT/OUTPUT]COVENANTVERIFY from #25 could be a good candidate for this.
Note: I initially tried to commit to the remaining HTLCs in the taproot tree itself, but found it very hard to verify this from the script, since it required (AFAICT) re-deriving and inspecting the whole taproot tree.
Spending
Having these capabilities a spender would claim the HTLC by presenting the full list of HTLCs and amounts, as well as the preimages for the HTLCs to be claimed.
- Check that the internal key commits to the list of HTLCs and amounts presented.
- Verify the preimages and subtract their values from the input amount, as well as from the list of HTLCs.
- Verify that the output has an internal key committing to the remaining HTLCs, an amount equal to the remaining sum, and the static taproot.
Help wanted
The main question is whether this way of commiting to the HTLCs can be done elegantly with any of the covenant proposals.
Also, any ideas or pointers would be greatly appreciated, as well as any feedback or questions!