Skip to content

Commit b048708

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 0925e2c commit b048708

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
@@ -1339,11 +1339,23 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
13391339
let refund = RefundContents::try_from(
13401340
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
13411341
)?;
1342+
1343+
if amount_msats != refund.amount_msats() {
1344+
return Err(Bolt12SemanticError::InvalidAmount);
1345+
}
1346+
13421347
Ok(InvoiceContents::ForRefund { refund, fields })
13431348
} else {
13441349
let invoice_request = InvoiceRequestContents::try_from(
13451350
(payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
13461351
)?;
1352+
1353+
if let Some(requested_amount_msats) = invoice_request.amount_msats() {
1354+
if amount_msats != requested_amount_msats {
1355+
return Err(Bolt12SemanticError::InvalidAmount);
1356+
}
1357+
}
1358+
13471359
Ok(InvoiceContents::ForOffer { invoice_request, fields })
13481360
}
13491361
}

0 commit comments

Comments
 (0)