Skip to content

Commit fd51e59

Browse files
committed
Propagate Trampoline blinding errors
When a blinded hop fails to decode, we send a special malformed error. However, we previously simply checked the presence of a blinding point within the `UpdateAddHTLC` message, which is not necessarily applicable to Trampoline, so now we additionally return a flag if the error stemmed from an inner onion's blinded hop decoding failure.
1 parent 5959009 commit fd51e59

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

lightning/src/ln/onion_payment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ where
475475
{
476476
let encode_malformed_error = |message: &str, err_code: u16| {
477477
log_info!(logger, "Failed to accept/forward incoming HTLC: {}", message);
478-
let (sha256_of_onion, failure_code) = if msg.blinding_point.is_some() {
478+
let (sha256_of_onion, failure_code) = if msg.blinding_point.is_some() || err_code == INVALID_ONION_BLINDING {
479479
([0; 32], INVALID_ONION_BLINDING)
480480
} else {
481481
(Sha256::hash(&msg.onion_routing_packet.hop_data).to_byte_array(), err_code)

lightning/src/ln/onion_utils.rs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,15 +1828,54 @@ where
18281828
trampoline_shared_secret,
18291829
),
18301830
}),
1831-
Ok((_, None)) => Err(OnionDecodeErr::Malformed {
1831+
Ok((msgs::InboundTrampolinePayload::BlindedForward(hop_data), None)) => {
1832+
if hop_data.intro_node_blinding_point.is_some() {
1833+
return Err(OnionDecodeErr::Relay {
1834+
err_msg: "Non-final intro node Trampoline onion data provided to us as last hop",
1835+
err_code: 0x4000 | 22,
1836+
shared_secret,
1837+
trampoline_shared_secret: Some(SharedSecret::from_bytes(
1838+
trampoline_shared_secret,
1839+
)),
1840+
});
1841+
}
1842+
Err(OnionDecodeErr::Malformed {
1843+
err_msg: "Non-final Trampoline onion data provided to us as last hop",
1844+
err_code: INVALID_ONION_BLINDING,
1845+
})
1846+
},
1847+
Ok((msgs::InboundTrampolinePayload::BlindedReceive(hop_data), Some(_))) => {
1848+
if hop_data.intro_node_blinding_point.is_some() {
1849+
return Err(OnionDecodeErr::Relay {
1850+
err_msg: "Final Trampoline intro node onion data provided to us as intermediate hop",
1851+
err_code: 0x4000 | 22,
1852+
shared_secret,
1853+
trampoline_shared_secret: Some(SharedSecret::from_bytes(
1854+
trampoline_shared_secret,
1855+
)),
1856+
});
1857+
}
1858+
Err(OnionDecodeErr::Malformed {
1859+
err_msg:
1860+
"Final Trampoline onion data provided to us as intermediate hop",
1861+
err_code: INVALID_ONION_BLINDING,
1862+
})
1863+
},
1864+
Ok((_, None)) => Err(OnionDecodeErr::Relay {
18321865
err_msg: "Non-final Trampoline onion data provided to us as last hop",
1833-
// todo: find more suitable error code
18341866
err_code: 0x4000 | 22,
1867+
shared_secret,
1868+
trampoline_shared_secret: Some(SharedSecret::from_bytes(
1869+
trampoline_shared_secret,
1870+
)),
18351871
}),
1836-
Ok((_, Some(_))) => Err(OnionDecodeErr::Malformed {
1872+
Ok((_, Some(_))) => Err(OnionDecodeErr::Relay {
18371873
err_msg: "Final Trampoline onion data provided to us as intermediate hop",
1838-
// todo: find more suitable error code
18391874
err_code: 0x4000 | 22,
1875+
shared_secret,
1876+
trampoline_shared_secret: Some(SharedSecret::from_bytes(
1877+
trampoline_shared_secret,
1878+
)),
18401879
}),
18411880
Err(e) => Err(e),
18421881
}

0 commit comments

Comments
 (0)