Skip to content
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

Create Taproot feature and introduce signer type enum #2289

Closed
wants to merge 3 commits into from

Conversation

arik-so
Copy link
Contributor

@arik-so arik-so commented May 11, 2023

No description provided.

@arik-so arik-so changed the title Create Taproot signer and feature Create Taproot feature and define signer trait May 11, 2023
use crate::ln::PaymentPreimage;
use crate::sign::ChannelSigner;

pub trait TaprootSigner: ChannelSigner {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should add an implementation in the same pr, no? There's a bunch of TODOs here related to the new code - even if it's behind a feature flag let's commit complete code.

use crate::sign::ChannelSigner;

pub trait TaprootSigner: ChannelSigner {
fn generate_local_nonce_pair(&self, secp_ctx: &Secp256k1<secp256k1::All>) -> PublicNonce;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we have some kind of id here so that later references to the Dane nonce pair can use the same id for derivation? Also this needs docs.

@@ -53,6 +53,9 @@ use crate::util::atomic_counter::AtomicCounter;
use crate::util::chacha20::ChaCha20;
use crate::util::invoice::construct_invoice_preimage;

#[cfg(all(anchors, taproot))]
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should add a CI test of the new flag.

/// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
/// not allow the spending of any funds by itself (you need our holder `revocation_secret` to do
/// so).
fn sign_justice_revoked_output(&self, justice_tx: &Transaction, input: usize, amount: u64,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know the existing signer doesn't but can we specify in these docs exactly when we call all these methods?

@@ -384,6 +384,9 @@ mod sealed {
define_feature!(27, ShutdownAnySegwit, [InitContext, NodeContext],
"Feature flags for `opt_shutdown_anysegwit`.", set_shutdown_any_segwit_optional,
set_shutdown_any_segwit_required, supports_shutdown_anysegwit, requires_shutdown_anysegwit);
define_feature!(31, Taproot, [InitContext, NodeContext, ChannelTypeContext],
Copy link

Choose a reason for hiding this comment

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

/// Note that all the relevant preimages will be provided, but there may also be additional
/// irrelevant or duplicate preimages.
//
// TODO: Document the things someone using this interface should enforce before signing.
Copy link

Choose a reason for hiding this comment

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

The signer should verify we’re spending a P2TR.

// TODO: Document the things someone using this interface should enforce before signing.
fn partially_sign_counterparty_commitment(&self, commitment_tx: &CommitmentTransaction,
preimages: Vec<PaymentPreimage>, secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<(PartialSignature, Vec<Signature>), ()>;
Copy link

Choose a reason for hiding this comment

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

Do we expect this method to return Signature for each, if yes also the inclusion_proof for the script path as we expect this method to be use internally by LDK for on-chain claims?

/// It may be called multiple times for same output(s) if a fee-bump is needed with regards
/// to an upcoming timelock expiration.
///
/// Amount is value of the output spent by this input, committed to in the BIP 143 signature.
Copy link

Choose a reason for hiding this comment

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

BIP341 signature if we’re talking about PT2R outputs no ?

@TheBlueMatt
Copy link
Collaborator

CC @devrandom any idea what y'all need on the signing API side for VLS?

@TheBlueMatt
Copy link
Collaborator

Or @ksedgwic

@arik-so
Copy link
Contributor Author

arik-so commented May 12, 2023

FYI, everyone, slow down a bit. This PR is a draft for a reason. I'm gonna have tons of revisions to the signer trait. In fact, I think I'll move it to a separate PR.

@wpaulino wpaulino self-requested a review May 16, 2023 17:46
@arik-so arik-so force-pushed the 2023-05-taproot-signer branch 3 times, most recently from 5abe515 to fcd0322 Compare May 17, 2023 07:31
@codecov-commenter
Copy link

codecov-commenter commented May 17, 2023

Codecov Report

Patch coverage: 97.56% and project coverage change: +0.46 🎉

Comparison is base (818dbdf) 91.50% compared to head (b8ee6bd) 91.96%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2289      +/-   ##
==========================================
+ Coverage   91.50%   91.96%   +0.46%     
==========================================
  Files         104      105       +1     
  Lines       52087    69041   +16954     
  Branches    52087    69041   +16954     
==========================================
+ Hits        47660    63491   +15831     
- Misses       4427     5550    +1123     
Impacted Files Coverage Δ
lightning/src/ln/features.rs 97.40% <ø> (-1.06%) ⬇️
lightning/src/sign/mod.rs 91.53% <ø> (+2.71%) ⬆️
lightning/src/ln/channel.rs 92.72% <96.77%> (+2.91%) ⬆️
lightning/src/sign/type_resolver.rs 100.00% <100.00%> (ø)

... and 58 files with indirect coverage changes

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

@arik-so arik-so changed the title Create Taproot feature and define signer trait Create Taproot feature and introduce signer type enum May 17, 2023
@arik-so arik-so marked this pull request as ready for review May 17, 2023 17:22
@arik-so
Copy link
Contributor Author

arik-so commented May 17, 2023

Ok, I decided to move the Taproot trait definition into a separate PR, which will also add a variant to the signer type enum introduced here.

lightning/src/sign/type_resolver.rs Show resolved Hide resolved
}

/// Helper trait for accessing common channel signer methods between different implementations
pub trait AsChannelSigner {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this needs to be public, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I guess it doesn't matter since we make the module pub(crate).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It actually does, unfortunately. Rust is complaining that ChannelSigner (public) inherits from a trait that would otherwise have a lower visibility, which is a no-no. Thankfully, the compiler doesn't yet detect that that's meaningless. So 🤫

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this means a downstream crate is unable to implement ChannelSigner (you've sealed it). Instead, you can impl<C: ChannelSigner> AsChannelSigner for C and not inherit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not inheriting will break the functionality, unfortunately. It's a crucial aspect. But I have a different idea.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is the inheritance critical here? Maybe we don't land this PR until we get a few more commits so that reviewers can better understand where its going?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Huh, TIL, but you can take that sample and simply remove the extension and it still compiles?

trait Base {
    fn a(&self) -> ();
}

trait AsBase {
    fn as_base(&self) -> &dyn Base;
}

impl<T: Base> AsBase for T {
    fn as_base(&self) -> &dyn Base {
        self
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Here's a more self-contained example of what we're trying to achieve: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4d9d295a47d6da11e2fd58c27ffc3fda

Copy link
Collaborator

Choose a reason for hiding this comment

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

The issue is the Bar(Box<dyn Bar>), which seems like it should be fixed instead of adding a new public trait. ISTM we should just include additional commits here so that the whole context can be reviewed, rather than reviewing something in part that doesn't make sense on its own.

lightning/src/ln/features.rs Outdated Show resolved Hide resolved
lightning/src/ln/features.rs Show resolved Hide resolved
wpaulino
wpaulino previously approved these changes May 18, 2023
@22388o 22388o mentioned this pull request May 20, 2023
13 tasks
lightning/src/sign/type_resolver.rs Outdated Show resolved Hide resolved
}

/// Helper trait for accessing common channel signer methods between different implementations
pub trait AsChannelSigner {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this means a downstream crate is unable to implement ChannelSigner (you've sealed it). Instead, you can impl<C: ChannelSigner> AsChannelSigner for C and not inherit.

@@ -4196,7 +4197,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {

let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.cur_holder_commitment_transaction_number == 1 {
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
let next_per_commitment_point = self.holder_signer.get_per_commitment_point(self.cur_holder_commitment_transaction_number, &self.secp_ctx);
let next_per_commitment_point = self.holder_signer.as_ref().get_per_commitment_point(self.cur_holder_commitment_transaction_number, &self.secp_ctx);
Copy link
Collaborator

Choose a reason for hiding this comment

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

While you're at it can we clean up a lot of the long lines in this file (that are now worse).

@@ -384,6 +384,9 @@ mod sealed {
define_feature!(27, ShutdownAnySegwit, [InitContext, NodeContext],
"Feature flags for `opt_shutdown_anysegwit`.", set_shutdown_any_segwit_optional,
set_shutdown_any_segwit_required, supports_shutdown_anysegwit, requires_shutdown_anysegwit);
define_feature!(31, Taproot, [InitContext, NodeContext, ChannelTypeContext],
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a TODO(taproot) to the module docs above to remember to document support for simple taproot channels when the time comes?

@arik-so
Copy link
Contributor Author

arik-so commented Jan 10, 2024

Implemented in another PR.

@arik-so arik-so closed this Jan 10, 2024
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.

None yet

6 participants