Skip to content

Commit dad077d

Browse files
committed
Don't include HMAC in Refund paths
Refunds are typically communicated via QR code, where a smaller size is desirable. Make the HMAC in OutboundPayment data optional such that it is elided from blinded paths used in refunds. This prevents abandoning refunds if the reader sends an invoice_error instead of an invoice message. However, this use case isn't necessary as the corresponding outbound payment will either timeout when the refund expires or can be explicitly abandoned by the creator.
1 parent 1cdec04 commit dad077d

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lightning/src/blinded_path/message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub enum OffersContext {
153153
/// used with an [`InvoiceError`].
154154
///
155155
/// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
156-
hmac: Hmac<Sha256>,
156+
hmac: Option<Hmac<Sha256>>,
157157
},
158158
/// Context used by a [`BlindedPath`] as a reply path for a [`Bolt12Invoice`].
159159
///
@@ -181,7 +181,7 @@ impl_writeable_tlv_based_enum!(OffersContext,
181181
(1, OutboundPayment) => {
182182
(0, payment_id, required),
183183
(1, nonce, required),
184-
(2, hmac, required),
184+
(2, hmac, option),
185185
},
186186
(2, InboundPayment) => {
187187
(0, payment_hash, required),

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8883,8 +8883,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
88838883
let secp_ctx = &$self.secp_ctx;
88848884

88858885
let nonce = Nonce::from_entropy_source(entropy);
8886-
let hmac = signer::hmac_for_payment_id(payment_id, nonce, expanded_key);
8887-
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac };
8886+
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: None };
88888887
let path = $self.create_blinded_paths_using_absolute_expiry(context, Some(absolute_expiry))
88898888
.and_then(|paths| paths.into_iter().next().ok_or(()))
88908889
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
@@ -9020,7 +9019,7 @@ where
90209019
let invoice_request = builder.build_and_sign()?;
90219020

90229021
let hmac = signer::hmac_for_payment_id(payment_id, nonce, expanded_key);
9023-
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac };
9022+
let context = OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) };
90249023
let reply_paths = self.create_blinded_paths(context)
90259024
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
90269025

@@ -10908,7 +10907,7 @@ where
1090810907
log_trace!(logger, "Received invoice_error: {}", invoice_error);
1090910908

1091010909
match context {
10911-
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac }) => {
10910+
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
1091210911
if signer::verify_payment_id(payment_id, hmac, nonce, expanded_key) {
1091310912
self.abandon_payment_with_reason(
1091410913
payment_id, PaymentFailureReason::RecipientRejected,

0 commit comments

Comments
 (0)