Skip to content

Conversation

guggero
Copy link
Collaborator

@guggero guggero commented Nov 17, 2022

Fixes #6974.

This PR upgrades the experimental MuSig2 RPC in the signrpc package to the BIP draft version v1.0.0rc2.
To remain backward compatible with applications that have on-chain funds on
keys that were created with the previous version of the MuSig2 BIP draft
v0.4.0 (such as Pool accounts) a version flag was added to the
MuSig2CombineKeys and MuSig2CreateSession RPC calls. That version flag is
mandatory, which means software using MuSig2 (such as Pool or Loop) must
update in order to use the new versioned RPC and upgrade any on-chain outputs
to the new version.

Upgrade/compatibility matrix

  • lnd v0.15.x
    • client software compatible with lnd v0.15.x (e.g. Pool v0.6.1): Full compatibility ✔️
    • client software compatible with lnd v0.16.x (e.g. future Pool version): Use lnd version to determine what RPC to use ✔️
  • lnd v0.16.x
    • client software compatible with lnd v0.15.x (e.g. Pool v0.6.1): lnd will throw error with hint to upgrade client version 🔼
    • client software compatible with lnd v0.16.x (e.g. future Pool version): Use lnd version to determine what RPC to use ✔️

@guggero guggero added rpc Related to the RPC interface signrpc musig2 labels Nov 17, 2022
@guggero guggero added this to the v0.16.0 milestone Nov 17, 2022
@guggero guggero requested review from Roasbeef and sputn1ck November 17, 2022 22:41
@guggero guggero force-pushed the musig2-versioned-rpc branch 2 times, most recently from d378ccf to a9a4d1e Compare November 17, 2022 22:44
Copy link
Collaborator

@sputn1ck sputn1ck left a comment

Choose a reason for hiding this comment

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

Changes lgtm!

While I wasn't a big fan of multiple api versions, it totally makes sense as in the future we might have more breaking version updates.

However now it becomes crucial for application developers to keep track of their musig version. Maybe docs/musig2.md could have a hint at that.

@guggero guggero force-pushed the musig2-versioned-rpc branch from a9a4d1e to d71ae53 Compare November 21, 2022 12:51
@guggero
Copy link
Collaborator Author

guggero commented Nov 21, 2022

Maybe docs/musig2.md could have a hint at that.

Good idea, added the section to the docs.

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🦜

One small comment re if some of the other related calls need the version or not. Also do we need to hold off on merging this until a release for loop/pool? Or will they already detect (strict versioning?) that a newer lnd version is being run so they can't continue forward?

// don't specify the version. Since this API is still declared to be
// experimental this should be the approach that leads to the least
// amount of unexpected behavior.
version, err := UnmarshalMuSig2Version(in.Version)
Copy link
Member

Choose a reason for hiding this comment

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

What about the Sign call? The main breaking change in musig2 1.0 was that the challenge hash ends up being changed, so the signing call should be versioned as well afaict.

Or is the idea that the context itself will now implicitly specify the version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because you pass in the session ID to the Sign call, it calls it on the session struct in memory, which is of the correct type. So you only need to specify the version when creating the session (or when combining keys outside of a session).

@lightninglabs-deploy
Copy link

@guggero, remember to re-request review from reviewers when ready

Before we change anything in the MuSig2 API, we first add an integration
test that makes sure the current version of the API combines keys
according to the v0.4.0 test vectors.
@guggero guggero force-pushed the musig2-versioned-rpc branch from 7585e61 to c5e54cd Compare February 3, 2023 17:27
@guggero
Copy link
Collaborator Author

guggero commented Feb 3, 2023

Rebased.

Also, I was able to verify that these RPCs work in Pool to upgrade existing Taproot accounts to use this updated MuSig2 v1.0.0-rc2 protocol. @bhandras are you confident as well that Loop can work with these RPCs as they are? If yes, I think we can merge this PR.

With this commit we copy the exact code of the MuSig2 code as found in
github.com/btcsuite/btcec/v2/schnorr/musig2 at the tag btcec/v2.2.2.
This corresponds to the MuSig2 BIP specification version of v0.4.0.
Since we explicitly keep an old version of a library in lnd for backward
compatibility we want to make sure the purpose and version of it is
clear and not misleading.
As a preparation for making it possible to version switch calls to the
MuSig2 API, we move some of the calls to the input package where in a
future commit we'll call the corresponding code in the correct package.
To allow us to properly test all test vectors, we can't default to true
on key sorting. Instead we add a parameter to the input package and move
the default value to the RPC server.
We put the calls that don't use musig2 package specific types as
parameters or return values behind an interface so we can easily call
those directly in the RPC without needing to know the underlying
implementation version. Some calls can't be used in the interface
because they use the specific package version's types. These calls are
implemented in helper functions in the input package instead that do the
necessary type switches.
With this commit we bump the github.com/btcd/btcec/v2 library to v2.3.2
which implements the MuSig2 BIP version v1.0.0rc2. With this the
github.com/btcsuite/btcd/btcec/v2/schnorr/musig2 package becomes
v1.0.0rc2 and the github.com/lightningnetwork/lnd/internal/musig2v040
stays at the old v0.4.0 version.
@guggero guggero force-pushed the musig2-versioned-rpc branch from c5e54cd to ad3e77c Compare February 3, 2023 17:30
@guggero guggero force-pushed the musig2-versioned-rpc branch from ad3e77c to 1e13bb8 Compare February 6, 2023 09:50
@guggero guggero merged commit 75a39da into lightningnetwork:master Feb 6, 2023
@guggero guggero deleted the musig2-versioned-rpc branch February 6, 2023 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
musig2 rpc Related to the RPC interface signrpc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

signrpc: switch to version v1.0 of musig2
4 participants