Skip to content

Update messages for Taproot types. #2005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

arik-so
Copy link
Contributor

@arik-so arik-so commented Feb 2, 2023

This PR creates Taproot-specific types, such as MuSig2 nonces as well as PartialSignatureWithNonce. It also updates the channel opening and regular channel operation mechanism related messages to support these types using TLVs.

This PR does not introduce Taproot type support for channel-close-related messages.

@codecov-commenter
Copy link

codecov-commenter commented Feb 2, 2023

Codecov Report

Patch coverage: 45.12% and project coverage change: -0.12 ⚠️

Comparison is base (0e28bcb) 91.38% compared to head (bc97b82) 91.27%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2005      +/-   ##
==========================================
- Coverage   91.38%   91.27%   -0.12%     
==========================================
  Files         102      102              
  Lines       49767    49976     +209     
  Branches    49767    49976     +209     
==========================================
+ Hits        45482    45618     +136     
- Misses       4285     4358      +73     
Impacted Files Coverage Δ
lightning/src/ln/msgs.rs 84.10% <17.64%> (-1.75%) ⬇️
lightning/src/util/ser.rs 90.54% <32.00%> (-2.81%) ⬇️
lightning/src/ln/channel.rs 90.09% <100.00%> (+0.04%) ⬆️
lightning/src/ln/functional_tests.rs 98.22% <100.00%> (+<0.01%) ⬆️

... and 14 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -49,6 +51,18 @@ use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
/// 21 million * 10^8 * 1000
pub(crate) const MAX_VALUE_MSAT: u64 = 21_000_000_0000_0000_000;

/// A public nonce used for Musig2, comprised of two ECPoints
Copy link

Choose a reason for hiding this comment

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

I don't know if the name should be labeled MuSig2BIPPublicNonce (ideally the bip number but no one yet to the best of my knowledge) or whatever to dissociate that's the two-point nonces variant of MuSig2 we're using (in case we introduce a variant on musig2 itself in the future for optimisations whatever)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's actually a point I brought up in the musig2 bip itself, but for now we have solved it here by not declaring the type here, and instead using my (hopefully ephemeral) musig2 crate, which exposes it simply as PublicNonce.

#[derive(Clone, Debug, PartialEq)]
pub struct Musig2SecretNonce(pub(crate) SecretKey, pub(crate) SecretKey);

/// A partial signature that also contains the Musig2 nonce its signer used
Copy link

Choose a reason for hiding this comment

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

I think "channel-level signer" just not confused with a nested signer as even a partial signature could be generated by multiple "same-channel-side" signers. Or any notation making it clear which signer we're referring to.

@@ -257,6 +273,10 @@ pub struct FundingCreated {
pub funding_output_index: u16,
/// The signature of the channel initiator (funder) on the initial commitment transaction
pub signature: Signature,
/// The partial signature of the channel initiator (funder)
pub partial_signature_with_nonce: Option<PartialSignatureWithNonce>,
Copy link

Choose a reason for hiding this comment

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

can be called initiator_partial_signature_with_nonce even if more verbose than spec

@@ -268,6 +288,8 @@ pub struct FundingSigned {
pub channel_id: [u8; 32],
/// The signature of the channel acceptor (fundee) on the initial commitment transaction
pub signature: Signature,
/// The partial signature of the channel acceptor (fundee)
pub partial_signature_with_nonce: Option<PartialSignatureWithNonce>,
Copy link

Choose a reason for hiding this comment

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

can be called fundee_partial_signature_with_nonce even if more verbose than spec

@@ -407,6 +429,8 @@ pub struct CommitmentSigned {
pub signature: Signature,
/// Signatures on the HTLC transactions
pub htlc_signatures: Vec<Signature>,
/// The partial Taproot signature on the commitment transaction
pub partial_signature_with_nonce: Option<PartialSignatureWithNonce>,
Copy link

Choose a reason for hiding this comment

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

can be called commitment_partial_signature_with_nonce even if more verbose than spec

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm, I disagree, because signature is not also called commitment_signature

@TheBlueMatt TheBlueMatt added the blocked on rust-bitcoin Blocked until we update rust-bitcoin/etc label Feb 9, 2023
@arik-so arik-so force-pushed the 2023-01-taproot-message-types branch 3 times, most recently from 62e40c9 to dbcdfbe Compare March 29, 2023 23:56
@TheBlueMatt
Copy link
Collaborator

Let's add a CI job for cfg(taproot) so we dont break it every 5th PR like we have anchors.

@arik-so arik-so force-pushed the 2023-01-taproot-message-types branch from dbcdfbe to 363a922 Compare March 30, 2023 17:09
/// A partial signature that also contains the Musig2 nonce its signer used
#[cfg(taproot)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PartialSignatureWithNonce(pub(crate) musig2::types::PartialSignature, pub(crate) musig2::types::PublicNonce);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do these need to be pub(crate) vs just pub?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm, perhaps at some point in the future we'll want to expose the inner details externally, but for now I'd leave it at pub(crate)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean it doesn't matter because its behind a cfg flag anyway, but in general I think we should/are move to making all messages public so that users can build their own complete custom messages.

@arik-so arik-so force-pushed the 2023-01-taproot-message-types branch from 363a922 to 2f6c321 Compare March 31, 2023 01:45
@wpaulino wpaulino self-requested a review March 31, 2023 01:49
@arik-so arik-so force-pushed the 2023-01-taproot-message-types branch 4 times, most recently from 922799e to 7633e04 Compare March 31, 2023 17:46
@arik-so arik-so marked this pull request as ready for review March 31, 2023 17:53
@arik-so arik-so force-pushed the 2023-01-taproot-message-types branch from 7633e04 to 3bd93db Compare March 31, 2023 19:49
@TheBlueMatt TheBlueMatt removed the blocked on rust-bitcoin Blocked until we update rust-bitcoin/etc label Mar 31, 2023
@arik-so arik-so force-pushed the 2023-01-taproot-message-types branch from 3bd93db to 8e800d1 Compare March 31, 2023 23:57
TheBlueMatt
TheBlueMatt previously approved these changes Apr 3, 2023
wpaulino
wpaulino previously approved these changes Apr 3, 2023
impl Readable for musig2::types::PublicNonce {
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
let buf: [u8; PUBLIC_KEY_SIZE * 2] = Readable::read(r)?;
let nonce = musig2::types::PublicNonce::from_slice(&buf).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oops, somehow I missed this - we can't unwrap during deserialization, you have a few of them. We have to map to an Err and return that.

@arik-so arik-so force-pushed the 2023-01-taproot-message-types branch from b6b7b91 to c6df720 Compare April 3, 2023 20:07
@arik-so arik-so force-pushed the 2023-01-taproot-message-types branch from c6df720 to bc97b82 Compare April 3, 2023 20:17
@TheBlueMatt TheBlueMatt merged commit 09f5e50 into lightningdevkit:main Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants