Skip to content

Commit

Permalink
Validate amount_msats against invoice and refund amounts
Browse files Browse the repository at this point in the history
Add a check to ensure that the amount_msats in an invoice
matches the amount_msats specified in the invoice_request
or refund. Reject the invoice as invalid if there is a
mismatch between these amounts. This validation ensures
consistency in invoice handling.
  • Loading branch information
slanesuke committed Oct 10, 2024
1 parent 7b465f9 commit f15db05
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lightning/src/offers/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1381,11 +1381,23 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
let refund = RefundContents::try_from(
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
)?;

if amount_msats != refund.amount_msats() {
return Err(Bolt12SemanticError::InvalidAmount);
}

Ok(InvoiceContents::ForRefund { refund, fields })
} else {
let invoice_request = InvoiceRequestContents::try_from(
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
)?;

if let Some(requested_amount_msats) = invoice_request.amount_msats() {
if amount_msats != requested_amount_msats {
return Err(Bolt12SemanticError::InvalidAmount);
}
}

Ok(InvoiceContents::ForOffer { invoice_request, fields })
}
}
Expand Down

0 comments on commit f15db05

Please sign in to comment.