Skip to content

multi: make payment address mandatory #9702

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

erickcestari
Copy link

@erickcestari erickcestari commented Apr 10, 2025

Make the payment secret field ('s') mandatory for BOLT11 payment requests, implementing the requirement specified in BOLT11 spec PR lightning/bolts#1242.

Change Description

  • Adds validation in zpay32 to fail decoding if the 's' field is missing when no blinded path is provided.
  • Adds a test vector for an invoice missing the 's' field.

Closes #9700

Copy link
Contributor

coderabbitai bot commented Apr 10, 2025

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@saubyk saubyk added this to the v0.20.0 milestone Apr 11, 2025
@erickcestari erickcestari force-pushed the require-payment-secret branch 5 times, most recently from 28c722d to 18545d8 Compare April 11, 2025 20:04
Copy link
Contributor

@MPins MPins left a comment

Choose a reason for hiding this comment

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

Well done 👍

Left some comments. Missing doc-release commit also.

@@ -381,6 +381,12 @@ func validateInvoice(invoice *Invoice) error {
return fmt.Errorf("no payment hash found")
}

// The invoice must contain a payment address (payment secret)
// if it does not contain blinded paths.
if len(invoice.BlindedPaymentPaths) == 0 && invoice.PaymentAddr.IsNone() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please wrap this line to stay within the 80-character limit?

Copy link
Member

Choose a reason for hiding this comment

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

@erickcestari what do you think about the two phase approach I proposed in #9718?

If we reject the invoices in the decoding phase, then we won't be able to decode the invoices at all.

IMO, the pertinent change in user behavior is that we'll no longer pay to invoices that don't have the addr/secret.

Copy link
Member

Choose a reason for hiding this comment

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

This would also serve to decouple the feature bit layer from invoice parsing. We should always be able to decode a well structured invoice. At a later step, we then apply our feature bit requirements, which may lead to rejected payment attempts.

Copy link
Author

Choose a reason for hiding this comment

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

Could you please wrap this line to stay within the 80-character limit?

Done

@MPins
Copy link
Contributor

MPins commented Apr 14, 2025

@saubyk the workflow is awaiting approval from a maintainer.

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.

This should also modify the feature bits that we advertise (payment secret/addr required in all relevant places).

Also we should consider a two phase approach. See my comment for more details.

@@ -381,6 +381,12 @@ func validateInvoice(invoice *Invoice) error {
return fmt.Errorf("no payment hash found")
}

// The invoice must contain a payment address (payment secret)
// if it does not contain blinded paths.
if len(invoice.BlindedPaymentPaths) == 0 && invoice.PaymentAddr.IsNone() {
Copy link
Member

Choose a reason for hiding this comment

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

@erickcestari what do you think about the two phase approach I proposed in #9718?

If we reject the invoices in the decoding phase, then we won't be able to decode the invoices at all.

IMO, the pertinent change in user behavior is that we'll no longer pay to invoices that don't have the addr/secret.

@erickcestari
Copy link
Author

This should also modify the feature bits that we advertise (payment secret/addr required in all relevant places).

Also we should consider a two phase approach. See my comment for more details.

This would also serve to decouple the feature bit layer from invoice parsing. We should always be able to decode a well structured invoice. At a later step, we then apply our feature bit requirements, which may lead to rejected payment attempts.

Why would we decode an invoice that we can't pay? The idea behind making the payment address (payment secret) a required field is to fail early, during invoice validation, if it's not present. That way, we avoid decoding something that's already invalid.

Wouldn't an invoice missing a required field be considered structurally invalid?

I was thinking of following the approach used by LDK, where they enforce the presence of the payment secret during the validation phase:
https://github.com/lightningdevkit/rust-lightning/blob/main/lightning-invoice/src/lib.rs#L1343

But let me know if I'm missing something.

@erickcestari erickcestari force-pushed the require-payment-secret branch 2 times, most recently from 122a84a to 7848e6a Compare April 15, 2025 13:44
Make the payment secret field ('s') mandatory for BOLT11 payment requests,
implementing the requirement specified in BOLT11 spec PR lightning/bolts#1242.

This enhances privacy by preventing intermediate nodes from probing the
destination using payment onions.

This commit implements the following changes:
- Adds validation in `zpay32` to fail decoding if the 's' field is
  missing when no blinded path is provided.
- Adds a test vector for an invoice missing the 's' field.
- Updates existing tests to accommodate the mandatory payment address requirement.
@erickcestari erickcestari force-pushed the require-payment-secret branch from 7848e6a to 811aac3 Compare April 15, 2025 14:05
@erickcestari erickcestari requested review from Roasbeef and MPins April 15, 2025 17:07
@Roasbeef
Copy link
Member

Roasbeef commented Apr 16, 2025

Why would we decode an invoice that we can't pay? The idea behind making the payment address (payment secret) a required field is to fail early, during invoice validation, if it's not present. That way, we avoid decoding something that's already invalid.

Sometimes you just want to decode an invoice. Many node management UIs support just decoding an invoice. Invoice validity (BOLT 11) is distinct from the feature bits and fields we deem mandatory.

The goal here is to make a distinction between a valid invoice (parses w/o errors), from one that may not meet the stricter requirements based on our current feature bits.

@Roasbeef
Copy link
Member

If you look at the spec PR itself, it adds this section:

  • if a valid s field is not provided:
    • MUST fail the payment.

This matches my suggestion: allow the invoice to parse, but fail when we go to pay it.

@MPins
Copy link
Contributor

MPins commented Apr 16, 2025

IMO, the two-phase approach proposed by @Roasbeef brings flexibility, leaving room for improved node management UI development.

@erickcestari
Copy link
Author

Thanks for the clarification! I'll go ahead and implement the first phase for now. I think I was a bit too focused on just the decoding check, but this approach makes sense and should be fine.

@erickcestari
Copy link
Author

For now, I’ll mark this PR as a draft since it’s still far from completing the first phase. I’ll open a separate PR to handle that.

@erickcestari erickcestari marked this pull request as draft April 17, 2025 12:40
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.

[feature]: Make payment address mandatory
4 participants