Skip to content

Validate amount_msats against invreq amount - #3535

Merged
TheBlueMatt merged 2 commits into
lightningdevkit:mainfrom
jkczyz:2025-01-invoice-amount
Jan 15, 2025
Merged

Validate amount_msats against invreq amount#3535
TheBlueMatt merged 2 commits into
lightningdevkit:mainfrom
jkczyz:2025-01-invoice-amount

Conversation

@jkczyz

@jkczyzjkczyz commented Jan 14, 2025

Copy link
Copy Markdown
Contributor

Add a check to ensure that the amount_msats in an invoice matches the amount_msats specified in the invoice_request or offer (or refund). Reject the invoice as invalid if there is a mismatch between these amounts. Otherwise, an invoice may be paid with an amount greater than the requested amount.

valentinewallace
valentinewallace previously approved these changes Jan 14, 2025
)
)?;

if let Some(requested_amount_msats) = invoice_request.amount_msats() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we check this against the offer's set amount as well?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah, fixed this and added tests as discussed offline. Now InvoiceRequest::amount_msats will infer the amount from the Offer::amount and InvoiceRequest::quantity, is possible. Added a new InvoiceRequest::has_amount_msats method as otherwise we can't determine whether the amount was explicitly set.

@TheBlueMattTheBlueMatt mentioned this pull request Jan 15, 2025
@jkczyz
jkczyzforce-pushed the 2025-01-invoice-amount branch from bdf5dcb to 2ad61a0CompareJanuary 15, 2025 16:00
@jkczyzjkczyz changed the title Validate amount_msats against invoice and refund amountsValidate amount_msats against invreq amountJan 15, 2025
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

LGTM, feel free to squash.

@valentinewallace

Copy link
Copy Markdown
Contributor

CI is sad, I think it looks related to the PR

@jkczyz

Copy link
Copy Markdown
ContributorAuthor

CI is sad, I think it looks related to the PR

Ah, right. I guess I need to rebase on main and fix it.

slanesukeand others added 2 commits January 15, 2025 11:23
Add a check to ensure that the amount_msats in an invoice matches the
amount_msats specified in the invoice_request or offer (or refund).
Reject the invoice as invalid if there is a mismatch between these
amounts. Otherwise, an invoice may be paid with an amount greater than
the requested amount.
Co-authored-by: Ian Slane <slaneian@gmail.com>
Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
When InvoiceRequest::amount_msats returns Some, it may have been
inferred from the Offer::amount and InvoiceRequest::quantity. Add a
method to InvoiceRequest for determining if the amount was explicitly
set.
@jkczyz
jkczyzforce-pushed the 2025-01-invoice-amount branch from 2ad61a0 to c2360beCompareJanuary 15, 2025 17:23
@TheBlueMatt
TheBlueMatt merged commit 6d604c5 into lightningdevkit:mainJan 15, 2025
@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Backported in #3536.

$(, $self_mut: tt)?
) => {
#[cfg_attr(c_bindings, allow(dead_code))]
pub(crate) fn amount_msats_unchecked(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, just realized this breaks CI because it doesn't work for --cfg=async_payments unfortunately. Happy to look into a fix if that helps

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Grr, yea, please.

Sign up for freeto 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.

4 participants

@jkczyz@TheBlueMatt@valentinewallace@slanesuke