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

Large final onion payload fixes #2752

Conversation

valentinewallace
Copy link
Contributor

@valentinewallace valentinewallace commented Nov 28, 2023

See the last two commit messages. We had a debug assertion and packet construction code that are no longer valid now that final payloads may be large due to custom TLVs/metadata. H/t to @Evanfeenstra for pointing out the latter, which helped uncover the former.

Based on #2739.

@codecov-commenter
Copy link

codecov-commenter commented Nov 28, 2023

Codecov Report

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

Comparison is base (ec8e0fe) 88.53% compared to head (80ba9ac) 88.54%.

Files Patch % Lines
lightning/src/ln/onion_payment.rs 96.77% 1 Missing ⚠️
lightning/src/ln/payment_tests.rs 98.00% 1 Missing ⚠️

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2752   +/-   ##
=======================================
  Coverage   88.53%   88.54%           
=======================================
  Files         115      115           
  Lines       91011    91094   +83     
  Branches    91011    91094   +83     
=======================================
+ Hits        80580    80659   +79     
- Misses       8004     8013    +9     
+ Partials     2427     2422    -5     

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

lightning/src/ln/onion_utils.rs Outdated Show resolved Hide resolved
lightning/src/ln/onion_utils.rs Outdated Show resolved Hide resolved
@TheBlueMatt TheBlueMatt added this to the 0.0.119 milestone Nov 30, 2023
@valentinewallace valentinewallace force-pushed the 2023-11-large-final-onion-payload-fixes branch 2 times, most recently from 610e876 to 5494ddd Compare December 5, 2023 18:31
@valentinewallace
Copy link
Contributor Author

Rebased to fix CI.

@@ -322,7 +322,15 @@ fn construct_onion_packet_with_init_noise<HD: Writeable, P: Packet>(
let mut res = Vec::with_capacity(ONION_HOP_DATA_LEN * (payloads.len() - 1));

let mut pos = 0;
let mut packet_len_without_filler = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This variable can be elided entirely, just use (or rename) pos.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the extra var. It means we'll unnecessarily seek in chacha on the final payload, though.

@valentinewallace valentinewallace force-pushed the 2023-11-large-final-onion-payload-fixes branch from 5494ddd to ca25ca6 Compare December 8, 2023 22:25
We previously assumed that the final node's payload would be ~93 bytes, and had
code to ensure that the filler encoded after that payload is not all 0s. Now
with custom TLVs and metadata supported, the final node's payload may take up
the entire onion packet, so we can't assume that there are 64 bytes of filler
to check.
Ensure that if we call construct_onion_packet and friends where payloads are
too large for the allotted packet length, we'll fail to construct. Previously,
senders would happily construct invalid packets by array-shifting the final
node's HMAC out of the packet when adding an intermediate onion layer, causing
the receiver to error with "final payload provided for us as an intermediate
node."
@valentinewallace valentinewallace force-pushed the 2023-11-large-final-onion-payload-fixes branch from ca25ca6 to 80ba9ac Compare December 8, 2023 22:33
@valentinewallace
Copy link
Contributor Author

Rebased to fix CI.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Both fixes are exceedingly simple, and both feature a test which fails if the fix is reverted. Gonna go ahead and land this.

@TheBlueMatt TheBlueMatt merged commit 0c67753 into lightningdevkit:main Dec 8, 2023
14 of 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.

None yet

3 participants