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

Avoid unwrap'ing channel_parameters in to_counterparty signing #2634

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

Previously, StaticPaymentOutputDescriptors did not include channel_parameters for the signer. As a result, when going to spend old StaticPaymentOutputDescriptors,
InMemorySigner::sign_counterparty_payment_input may be called with channel_parameters set to None. This should be fine, but in fa2a2ef we started relying on it (indirectly via channel_features) for signing. This caused an unwrap when spending old output descriptors.

This is fixed here by simply avoiding the unwrap and assuming old StaticPaymentOutputDescriptors represent non-anchor channels.

Previously, `StaticPaymentOutputDescriptor`s did not include
`channel_parameters` for the signer. As a result, when going to
spend old `StaticPaymentOutputDescriptor`s,
`InMemorySigner::sign_counterparty_payment_input` may be called
with `channel_parameters` set to `None`. This should be fine, but
in fa2a2ef we started relying on
it (indirectly via `channel_features`) for signing. This caused an
`unwrap` when spending old output descriptors.

This is fixed here by simply avoiding the unwrap and assuming old
`StaticPaymentOutputDescriptor`s represent non-anchor channels.
@TheBlueMatt TheBlueMatt added this to the 0.0.117 milestone Oct 1, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (20f287f) 89.10% compared to head (60567da) 89.51%.
Report is 19 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2634      +/-   ##
==========================================
+ Coverage   89.10%   89.51%   +0.40%     
==========================================
  Files         112      112              
  Lines       86932    90838    +3906     
  Branches    86932    90838    +3906     
==========================================
+ Hits        77465    81316    +3851     
- Misses       7239     7293      +54     
- Partials     2228     2229       +1     
Files Coverage Δ
lightning/src/util/test_channel_signer.rs 86.07% <100.00%> (+0.17%) ⬆️
lightning/src/sign/mod.rs 79.86% <94.11%> (+5.80%) ⬆️

... and 17 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@G8XSU G8XSU left a comment

Choose a reason for hiding this comment

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

Overall lgtm!

lightning/src/sign/mod.rs Show resolved Hide resolved
Comment on lines 952 to 954
let supports_anchors_zero_fee_htlc_tx = self.channel_parameters.as_ref()
.map(|params| params.channel_type_features.supports_anchors_zero_fee_htlc_tx())
.unwrap_or(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth adding a helper. We do this in create_spendable_outputs_psbt, too, and it looks like we have an unchecked use in sign_counterparty_commitment. Though maybe that is never reached in practice?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah sign_counterparty_commitment shouldn't happen, we always provide the parameters there before signing commitment transactions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Turns out the one in create_spendable_outputs_psbt is not on self but rather on StaticPaymentOutputDescriptor. While we could DRY up that usage and StaticPaymentOutputDescriptor::max_witness_length, it's probably not worth it because we may refactor the former as per #2605 (comment).

In the previous commit we fixed a bug where we were spuriously
(indirectly) `unwrap`ing the `channel_parameters` in
`InMemorySigner`. Here we make such bugs much less likely in the
future by having the utilities which do the `unwrap`ing internally
return `Option`s instead.

This makes the `unwrap`s clear at the callsite.
This further documents the parameter-fetching utilities in
`InMemorySigner` to hopefully make them more robust against future
spurious `unwrap`s.
@TheBlueMatt TheBlueMatt merged commit 0ce1c5a into lightningdevkit:main Oct 3, 2023
15 checks passed
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