Skip to content

Commit 81571aa

Browse files
Fix blinded recipient fail on receive reqs violation
If a blinded HTLC does not satisfy the receiver's requirements, e.g. bad CLTV or amount, they should malformed-fail backwards with error code INVALID_ONION_BLINDING and a zeroed out onion hash per BOLt 4.
1 parent 640e915 commit 81571aa

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,16 @@ enum ReceiveCheckFail {
464464
RecipientFail,
465465
// Failure to decode the recipient's onion payload.
466466
OnionDecodeFail,
467+
// The incoming HTLC did not satisfy our requirements; in this case it underpaid us according to
468+
// the expected receive amount in the onion.
469+
ReceiveRequirements,
467470
}
468471

469472
#[test]
470473
fn multi_hop_receiver_fail() {
471474
do_multi_hop_receiver_fail(ReceiveCheckFail::RecipientFail);
472475
do_multi_hop_receiver_fail(ReceiveCheckFail::OnionDecodeFail);
476+
do_multi_hop_receiver_fail(ReceiveCheckFail::ReceiveRequirements);
473477
}
474478

475479
fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
@@ -554,7 +558,14 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
554558
nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), update_add);
555559
check_added_monitors!(nodes[2], 0);
556560
do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true);
557-
}
561+
},
562+
ReceiveCheckFail::ReceiveRequirements => {
563+
let update_add = &mut payment_event_1_2.msgs[0];
564+
update_add.amount_msat -= 1;
565+
nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), update_add);
566+
check_added_monitors!(nodes[2], 0);
567+
do_commitment_signed_dance(&nodes[2], &nodes[1], &payment_event_1_2.commitment_msg, true, true);
568+
},
558569
}
559570

560571
let updates_2_1 = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());

lightning/src/ln/channelmanager.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,6 +3192,16 @@ where
31923192
{
31933193
let logger = WithContext::from(&self.logger, Some(*counterparty_node_id), Some(msg.channel_id));
31943194
log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
3195+
if msg.blinding_point.is_some() {
3196+
return PendingHTLCStatus::Fail(HTLCFailureMsg::Malformed(
3197+
msgs::UpdateFailMalformedHTLC {
3198+
channel_id: msg.channel_id,
3199+
htlc_id: msg.htlc_id,
3200+
sha256_of_onion: [0; 32],
3201+
failure_code: INVALID_ONION_BLINDING,
3202+
}
3203+
))
3204+
}
31953205
return PendingHTLCStatus::Fail(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
31963206
channel_id: msg.channel_id,
31973207
htlc_id: msg.htlc_id,

0 commit comments

Comments
 (0)