Skip to content

Conversation

@bhandras
Copy link
Member

@bhandras bhandras commented Apr 3, 2022

This PR adds a few changes to the already existing taproot HTLC code to make it simpler to integrate.

  • Refactor locking conditions.
  • Derive the shared internal public key when creating the HTLC and export the root hash.

@bhandras bhandras changed the title multi: upgrade to P2TR htlcs without keyspend path [wip] multi: upgrade to P2TR htlcs without keyspend path Apr 3, 2022
@arshbot arshbot mentioned this pull request Apr 13, 2022
9 tasks
@bhandras bhandras force-pushed the taproot-htlc branch 7 times, most recently from 274ec4c to 36da078 Compare April 25, 2022 12:55
@bhandras bhandras force-pushed the taproot-htlc branch 3 times, most recently from b332b53 to 61f729c Compare May 6, 2022 15:44
@bhandras bhandras force-pushed the taproot-htlc branch 7 times, most recently from b947b1c to fe94c3b Compare May 16, 2022 18:03
@bhandras bhandras changed the title [wip] multi: upgrade to P2TR htlcs without keyspend path [wip] multi: upgrade to P2TR htlcs and attempt musig2 loopout sweep May 18, 2022
@bhandras bhandras force-pushed the taproot-htlc branch 3 times, most recently from 3583191 to f4b2395 Compare May 19, 2022 21:13
@bhandras bhandras changed the title [wip] multi: upgrade to P2TR htlcs and attempt musig2 loopout sweep multi: changes to the taproot HTLC required for both client and server May 20, 2022
@bhandras bhandras requested review from arshbot and guggero May 20, 2022 09:37
@lightninglabs-deploy
Copy link

@guggero: review reminder
@arshbot: review reminder

Copy link
Contributor

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great cleanup and refactors! Only a few minor comments, nothing major.

@bhandras bhandras force-pushed the taproot-htlc branch 2 times, most recently from 872f647 to b406ff9 Compare June 7, 2022 20:59
@bhandras bhandras requested a review from guggero June 7, 2022 21:05
Copy link
Contributor

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, LGTM 🎉

@bhandras
Copy link
Member Author

bhandras commented Jun 8, 2022

@arshbot ping

Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor!

var schnorrSenderKey, schnorrReceiverKey [32]byte
copy(schnorrSenderKey[:], schnorr.SerializePubKey(senderPubKey))
copy(schnorrReceiverKey[:], schnorr.SerializePubKey(receiverPubKey))
aggregateKey, _, _, err := musig2.AggregateKeys(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, much cleaner than passing it all the way through everywhere 🤦‍♀️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keys.. Keys everywhere...

sweep/sweeper.go Outdated
}

// We need our previous outputs for taproot spends, and there's no
// harm including them for segwit v0, so we always inlucde our prevOut.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/inlucde/include

This is definitely my typo, I can feel it :')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

carlaKC and others added 3 commits June 9, 2022 10:20
Use of the Script() function is problematic when we introduce taproot
because our script will vary depending whether we use keyspend or a
tapleaf spend path (and on the tapleaf spent). This has not previously
been a problem for segwitv0 scripts, because they contain all of the
logical branches for each of our spend conditions in a single script.

This commit prepares for removal of the Script() function by moving
our address/pkScript/sigScript generation (which need Script()) into
each script's implementation of the HtlcScript interface so that
they have access to the script directly.
Taproot spends require a different sighash, so we update our HtlcScript
interface to provide the appropriate sighash when sweeping. We also add
distinct Timeout/Success Script functions to allow for tapleaf spends
which have different locking scripts for different paths. Note that the
timeout and success paths will be the same for segwit v0 htlcs, because
it has a single branched script containing all spend paths.

In future iterations, this differentiation of claim scripts can also
be used to use musig2 to collaboratively keyspend P2TR htlcs with the
server. This script can be expressed as PriorityScript (because we'll
try to keyspend as a priority, and then fall back to a tap leaf spend).
As we've done here, segwit v0 spends would just return their single
script for PriorityScript, and the claim would be no different from
our other claims.
@bhandras
Copy link
Member Author

bhandras commented Jun 9, 2022

Nice refactor!

Thanks for the review, welcome back :)

@carlaKC
Copy link
Contributor

carlaKC commented Jun 9, 2022

Thanks for the review, welcome back :)

Came for the nits, stayed for the musig2 😜

@levmi levmi requested review from yyforyongyu and removed request for arshbot June 9, 2022 14:06
Copy link
Contributor

@arshbot arshbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I really like this approach of abstracting away the output type logic so each type can figure out how to come up with the needed assets. Gives the right amount of flexibility because each htlc type conforms to lockingConditions, but doesn't commit to a path

}

// Script is not implemented, but necessary to conform to interface.
func (h *HtlcScriptV3) Script() []byte {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is certainly a much cleaner way of going about it

@bhandras bhandras merged commit 8f23c67 into lightninglabs:master Jun 9, 2022
@bhandras bhandras deleted the taproot-htlc branch September 12, 2023 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants