Skip to content

Commit f15db05

Browse files
committed
Validate amount_msats against invoice and refund amounts
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.
1 parent 7b465f9 commit f15db05

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lightning/src/offers/invoice.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,11 +1381,23 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
13811381
let refund = RefundContents::try_from(
13821382
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
13831383
)?;
1384+
1385+
if amount_msats != refund.amount_msats() {
1386+
return Err(Bolt12SemanticError::InvalidAmount);
1387+
}
1388+
13841389
Ok(InvoiceContents::ForRefund { refund, fields })
13851390
} else {
13861391
let invoice_request = InvoiceRequestContents::try_from(
13871392
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
13881393
)?;
1394+
1395+
if let Some(requested_amount_msats) = invoice_request.amount_msats() {
1396+
if amount_msats != requested_amount_msats {
1397+
return Err(Bolt12SemanticError::InvalidAmount);
1398+
}
1399+
}
1400+
13891401
Ok(InvoiceContents::ForOffer { invoice_request, fields })
13901402
}
13911403
}

0 commit comments

Comments
 (0)