From: Jeffrey Czyz Date: Thu, 11 Jan 2024 19:13:12 +0000 (-0600) Subject: Use consistent cltv_expiry_delta in ForwardTlvs X-Git-Tag: v0.0.120~3^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=8053aa3df43e548561709a7453f410f85c353e01;p=rust-lightning Use consistent cltv_expiry_delta in ForwardTlvs When converting from CounterpartyForwardingInfo to PaymentRelay, the cltv_expiry_delta is copied. Then, when forming a blinded payment path, the value is mutated so that esoteric values don't reveal information about the path. However, the value was only used in computing PaymentConstraints and wasn't actually updated in PaymentRelay. Move the logic for modifying the cltv_expiry_delta to the conversion code to avoid this inconsistency. --- diff --git a/lightning/src/blinded_path/payment.rs b/lightning/src/blinded_path/payment.rs index f4df1e379..5d332a76f 100644 --- a/lightning/src/blinded_path/payment.rs +++ b/lightning/src/blinded_path/payment.rs @@ -97,12 +97,24 @@ pub struct PaymentConstraints { pub htlc_minimum_msat: u64, } -impl From for PaymentRelay { - fn from(info: CounterpartyForwardingInfo) -> Self { +impl TryFrom for PaymentRelay { + type Error = (); + + fn try_from(info: CounterpartyForwardingInfo) -> Result { let CounterpartyForwardingInfo { fee_base_msat, fee_proportional_millionths, cltv_expiry_delta } = info; - Self { cltv_expiry_delta, fee_proportional_millionths, fee_base_msat } + + // Avoid exposing esoteric CLTV expiry deltas + let cltv_expiry_delta = match cltv_expiry_delta { + 0..=40 => 40, + 41..=80 => 80, + 81..=144 => 144, + 145..=216 => 216, + _ => return Err(()), + }; + + Ok(Self { cltv_expiry_delta, fee_proportional_millionths, fee_base_msat }) } } diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 485fd2391..524bb1bc4 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -114,19 +114,14 @@ impl> + Clone, L: Deref, S: Deref, SP: Sized, None => return None, }; let payment_relay: PaymentRelay = match details.counterparty.forwarding_info { - Some(forwarding_info) => forwarding_info.into(), + Some(forwarding_info) => match forwarding_info.try_into() { + Ok(payment_relay) => payment_relay, + Err(()) => return None, + }, None => return None, }; - // Avoid exposing esoteric CLTV expiry deltas - let cltv_expiry_delta = match payment_relay.cltv_expiry_delta { - 0..=40 => 40u32, - 41..=80 => 80u32, - 81..=144 => 144u32, - 145..=216 => 216u32, - _ => return None, - }; - + let cltv_expiry_delta = payment_relay.cltv_expiry_delta as u32; let payment_constraints = PaymentConstraints { max_cltv_expiry: tlvs.payment_constraints.max_cltv_expiry + cltv_expiry_delta, htlc_minimum_msat: details.inbound_htlc_minimum_msat.unwrap_or(0),