Skip to content

Commit d99089e

Browse files
Fix blinded recipient fail on malformed HTLC
If a blinded recipient to a multihop blinded path needs to fail back a malformed HTLC, they should use error code INVALID_ONION_BLINDING and a zeroed out onion hash per BOLT 4.
1 parent a2b4813 commit d99089e

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,12 @@ fn failed_backwards_to_intro_node() {
281281

282282
let mut updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
283283
let mut update_malformed = &mut updates.update_fail_malformed_htlcs[0];
284-
// Ensure the final hop does not correctly blind their error.
284+
// Check that the final node encodes its failure correctly.
285+
assert_eq!(update_malformed.failure_code, INVALID_ONION_BLINDING);
286+
assert_eq!(update_malformed.sha256_of_onion, [0; 32]);
287+
288+
// Modify such the final hop does not correctly blind their error so we can ensure the intro node
289+
// converts it to the correct error.
285290
update_malformed.sha256_of_onion = [1; 32];
286291
nodes[1].node.handle_update_fail_malformed_htlc(&nodes[2].node.get_our_node_id(), update_malformed);
287292
do_commitment_signed_dance(&nodes[1], &nodes[2], &updates.commitment_signed, true, false);

lightning/src/ln/onion_payment.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,16 @@ where
319319
($msg: expr, $err_code: expr) => {
320320
{
321321
log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
322+
let (sha256_of_onion, failure_code) = if msg.blinding_point.is_some() {
323+
([0; 32], INVALID_ONION_BLINDING)
324+
} else {
325+
(Sha256::hash(&msg.onion_routing_packet.hop_data).to_byte_array(), $err_code)
326+
};
322327
return Err(HTLCFailureMsg::Malformed(msgs::UpdateFailMalformedHTLC {
323328
channel_id: msg.channel_id,
324329
htlc_id: msg.htlc_id,
325-
sha256_of_onion: Sha256::hash(&msg.onion_routing_packet.hop_data).to_byte_array(),
326-
failure_code: $err_code,
330+
sha256_of_onion,
331+
failure_code,
327332
}));
328333
}
329334
}

0 commit comments

Comments
 (0)