Skip to content

Commit 1a7254c

Browse files
Parse blinded forward-as-intro onion payloads
Previously, we only parsed blinded receive payloads.
1 parent 50c850f commit 1a7254c

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParame
5353
use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundOnionErr, NextPacketDetails};
5454
use crate::ln::msgs;
5555
use crate::ln::onion_utils;
56-
use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING};
56+
use crate::ln::onion_utils::HTLCFailReason;
5757
use crate::ln::msgs::{ChannelMessageHandler, DecodeError, LightningError};
5858
#[cfg(test)]
5959
use crate::ln::outbound_payment;

lightning/src/ln/msgs.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use bitcoin::{secp256k1, Witness};
3131
use bitcoin::blockdata::script::ScriptBuf;
3232
use bitcoin::hash_types::Txid;
3333

34-
use crate::blinded_path::payment::ReceiveTlvs;
34+
use crate::blinded_path::payment::{BlindedPaymentTlvs, ForwardTlvs, ReceiveTlvs};
3535
use crate::ln::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
3636
use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
3737
use crate::ln::onion_utils;
@@ -1666,9 +1666,10 @@ pub trait OnionMessageHandler {
16661666

16671667
mod fuzzy_internal_msgs {
16681668
use bitcoin::secp256k1::PublicKey;
1669-
use crate::blinded_path::payment::PaymentConstraints;
1669+
use crate::blinded_path::payment::{PaymentConstraints, PaymentRelay};
16701670
use crate::prelude::*;
16711671
use crate::ln::{PaymentPreimage, PaymentSecret};
1672+
use crate::ln::features::BlindedHopFeatures;
16721673

16731674
// These types aren't intended to be pub, but are exposed for direct fuzzing (as we deserialize
16741675
// them from untrusted input):
@@ -1695,6 +1696,13 @@ mod fuzzy_internal_msgs {
16951696
amt_msat: u64,
16961697
outgoing_cltv_value: u32,
16971698
},
1699+
BlindedForward {
1700+
short_channel_id: u64,
1701+
payment_relay: PaymentRelay,
1702+
payment_constraints: PaymentConstraints,
1703+
features: BlindedHopFeatures,
1704+
intro_node_blinding_point: PublicKey,
1705+
},
16981706
BlindedReceive {
16991707
amt_msat: u64,
17001708
total_msat: u64,
@@ -2354,7 +2362,23 @@ impl<NS: Deref> ReadableArgs<&NS> for InboundOnionPayload where NS::Target: Node
23542362
let mut s = Cursor::new(&enc_tlvs);
23552363
let mut reader = FixedLengthReader::new(&mut s, enc_tlvs.len() as u64);
23562364
match ChaChaPolyReadAdapter::read(&mut reader, rho)? {
2357-
ChaChaPolyReadAdapter { readable: ReceiveTlvs { payment_secret, payment_constraints }} => {
2365+
ChaChaPolyReadAdapter { readable: BlindedPaymentTlvs::Forward(ForwardTlvs {
2366+
short_channel_id, payment_relay, payment_constraints, features
2367+
})} => {
2368+
if amt.is_some() || cltv_value.is_some() || total_msat.is_some() {
2369+
return Err(DecodeError::InvalidValue)
2370+
}
2371+
Ok(Self::BlindedForward {
2372+
short_channel_id,
2373+
payment_relay,
2374+
payment_constraints,
2375+
features,
2376+
intro_node_blinding_point: blinding_point,
2377+
})
2378+
},
2379+
ChaChaPolyReadAdapter { readable: BlindedPaymentTlvs::Receive(ReceiveTlvs {
2380+
payment_secret, payment_constraints
2381+
})} => {
23582382
if total_msat.unwrap_or(0) > MAX_VALUE_MSAT { return Err(DecodeError::InvalidValue) }
23592383
Ok(Self::BlindedReceive {
23602384
amt_msat: amt.ok_or(DecodeError::InvalidValue)?,

lightning/src/ln/onion_payment.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::ln::PaymentHash;
1111
use crate::ln::channelmanager::{CLTV_FAR_FAR_AWAY, HTLCFailureMsg, MIN_CLTV_EXPIRY_DELTA, PendingHTLCInfo, PendingHTLCRouting};
1212
use crate::ln::msgs;
1313
use crate::ln::onion_utils;
14-
use crate::ln::onion_utils::HTLCFailReason;
14+
use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING};
1515
use crate::sign::{NodeSigner, Recipient};
1616
use crate::util::logger::Logger;
1717

@@ -44,6 +44,7 @@ pub(super) fn create_fwd_pending_htlc_info(
4444
let (short_channel_id, amt_to_forward, outgoing_cltv_value) = match hop_data {
4545
msgs::InboundOnionPayload::Forward { short_channel_id, amt_to_forward, outgoing_cltv_value } =>
4646
(short_channel_id, amt_to_forward, outgoing_cltv_value),
47+
msgs::InboundOnionPayload::BlindedForward { .. } => todo!(),
4748
msgs::InboundOnionPayload::Receive { .. } | msgs::InboundOnionPayload::BlindedReceive { .. } =>
4849
return Err(InboundOnionErr {
4950
msg: "Final Node OnionHopData provided for us as an intermediary node",
@@ -90,6 +91,13 @@ pub(super) fn create_recv_pending_htlc_info(
9091
msg: "Got non final data with an HMAC of 0",
9192
})
9293
},
94+
msgs::InboundOnionPayload::BlindedForward { .. } => {
95+
return Err(InboundOnionErr {
96+
err_code: INVALID_ONION_BLINDING,
97+
err_data: vec![0; 32],
98+
msg: "Got blinded non final data with an HMAC of 0",
99+
})
100+
}
93101
};
94102
// final_incorrect_cltv_expiry
95103
if outgoing_cltv_value > cltv_expiry {
@@ -327,6 +335,11 @@ where
327335
outgoing_amt_msat: amt_to_forward, outgoing_cltv_value
328336
}
329337
},
338+
onion_utils::Hop::Forward {
339+
next_hop_data: msgs::InboundOnionPayload::BlindedForward { .. }, ..
340+
} => {
341+
todo!()
342+
},
330343
onion_utils::Hop::Receive { .. } => return Ok((next_hop, shared_secret, None)),
331344
onion_utils::Hop::Forward { next_hop_data: msgs::InboundOnionPayload::Receive { .. }, .. } |
332345
onion_utils::Hop::Forward { next_hop_data: msgs::InboundOnionPayload::BlindedReceive { .. }, .. } =>

0 commit comments

Comments
 (0)