Skip to content

Commit fb9ad56

Browse files
Document and test 0-len channel update onion error case
1 parent cd2ebb7 commit fb9ad56

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lightning/src/ln/onion_route_tests.rs

+24
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,30 @@ fn test_onion_failure() {
645645
}, || nodes[2].node.fail_htlc_backwards(&payment_hash), false, None,
646646
Some(NetworkUpdate::NodeFailure { node_id: route.paths[0].hops[1].pubkey, is_permanent: true }),
647647
Some(channels[1].0.contents.short_channel_id));
648+
run_onion_failure_test_with_fail_intercept("0-length channel update in UPDATE onion failure", 200, &nodes,
649+
&route, &payment_hash, &payment_secret, |_msg| {}, |msg| {
650+
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
651+
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
652+
let mut decoded_err_packet = msgs::DecodedOnionErrorPacket {
653+
failuremsg: vec![
654+
0x10, 0x7, // UPDATE|7
655+
0x0, 0x0 // 0-len channel update
656+
],
657+
pad: vec![0; 255 - 4 /* 4-byte error message */],
658+
hmac: [0; 32],
659+
};
660+
let um = onion_utils::gen_um_from_shared_secret(&onion_keys[1].shared_secret.as_ref());
661+
let mut hmac = HmacEngine::<Sha256>::new(&um);
662+
hmac.input(&decoded_err_packet.encode()[32..]);
663+
decoded_err_packet.hmac = Hmac::from_engine(hmac).into_inner();
664+
msg.reason = onion_utils::encrypt_failure_packet(
665+
&onion_keys[1].shared_secret.as_ref(), &decoded_err_packet.encode()[..])
666+
}, || nodes[2].node.fail_htlc_backwards(&payment_hash), true, Some(0x1000|7),
667+
Some(NetworkUpdate::ChannelFailure {
668+
short_channel_id: channels[1].0.contents.short_channel_id,
669+
is_permanent: false,
670+
}),
671+
Some(channels[1].0.contents.short_channel_id));
648672
}
649673

650674
#[test]

lightning/src/ln/onion_utils.rs

+2
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ where L::Target: Logger {
579579
msg: chan_update,
580580
})
581581
} else {
582+
// The node in question intentionally encoded a 0-length channel update. This is
583+
// likely due to https://github.com/ElementsProject/lightning/issues/6200.
582584
network_update = Some(NetworkUpdate::ChannelFailure {
583585
short_channel_id: route_hop.short_channel_id,
584586
is_permanent: false,

0 commit comments

Comments
 (0)