-
Notifications
You must be signed in to change notification settings - Fork 420
Validate amount_msats against invreq amount
#3535
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
Validate amount_msats against invreq amount
#3535
Conversation
| ) | ||
| )?; | ||
|
|
||
| if let Some(requested_amount_msats) = invoice_request.amount_msats() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
bdf5dcb to
2ad61a0
Compare
amount_msats against invoice and refund amountsamount_msats against invreq amount
|
LGTM, feel free to squash. |
|
CI is sad, I think it looks related to the PR |
Ah, right. I guess I need to rebase on |
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 <[email protected]> Co-authored-by: Jeffrey Czyz <[email protected]>
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.
2ad61a0 to
c2360be
Compare
|
Backported in #3536. |
| $(, $self_mut: tt)? | ||
| ) => { | ||
| #[cfg_attr(c_bindings, allow(dead_code))] | ||
| pub(crate) fn amount_msats_unchecked( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grr, yea, please.
Add a check to ensure that the
amount_msatsin an invoice matches theamount_msatsspecified in theinvoice_requestoroffer(orrefund). 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.