Skip to content

Commit 80d09ed

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 810fd52 commit 80d09ed

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
@@ -3400,6 +3400,16 @@ where
34003400
($msg: expr, $err_code: expr, $data: expr) => {
34013401
{
34023402
log_info!(self.logger, "Failed to accept/forward incoming HTLC: {}", $msg);
3403+
if msg.blinding_point.is_some() {
3404+
return PendingHTLCStatus::Fail(HTLCFailureMsg::Malformed(
3405+
msgs::UpdateFailMalformedHTLC {
3406+
channel_id: msg.channel_id,
3407+
htlc_id: msg.htlc_id,
3408+
sha256_of_onion: [0; 32],
3409+
failure_code: INVALID_ONION_BLINDING,
3410+
}
3411+
))
3412+
}
34033413
return PendingHTLCStatus::Fail(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
34043414
channel_id: msg.channel_id,
34053415
htlc_id: msg.htlc_id,

0 commit comments

Comments
 (0)