Skip to content

Commit 23b4c80

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 313f344 commit 23b4c80

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

lightning/src/ln/onion_payment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ where
466466
{
467467
let encode_malformed_error = |message: &str, err_code: u16| {
468468
log_info!(logger, "Failed to accept/forward incoming HTLC: {}", message);
469-
let (sha256_of_onion, failure_code) = if msg.blinding_point.is_some() {
469+
let (sha256_of_onion, failure_code) = if msg.blinding_point.is_some() || err_code == INVALID_ONION_BLINDING {
470470
([0; 32], INVALID_ONION_BLINDING)
471471
} else {
472472
(Sha256::hash(&msg.onion_routing_packet.hop_data).to_byte_array(), err_code)

lightning/src/ln/onion_utils.rs

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,16 +1821,60 @@ where
18211821
trampoline_shared_secret,
18221822
),
18231823
}),
1824-
Ok((_, None)) => Err(OnionDecodeErr::Malformed {
1825-
err_msg: "Non-final Trampoline onion data provided to us as last hop",
1826-
// todo: find more suitable error code
1827-
err_code: 0x4000 | 22,
1828-
}),
1829-
Ok((_, Some(_))) => Err(OnionDecodeErr::Malformed {
1830-
err_msg: "Final Trampoline onion data provided to us as intermediate hop",
1831-
// todo: find more suitable error code
1832-
err_code: 0x4000 | 22,
1833-
}),
1824+
Ok((msgs::InboundTrampolinePayload::BlindedForward(hop_data), None)) => {
1825+
if hop_data.intro_node_blinding_point.is_some() {
1826+
return Err(OnionDecodeErr::Relay {
1827+
err_msg: "Non-final intro node Trampoline onion data provided to us as last hop",
1828+
err_code: INVALID_ONION_BLINDING,
1829+
shared_secret,
1830+
trampoline_shared_secret: Some(SharedSecret::from_bytes(
1831+
trampoline_shared_secret,
1832+
)),
1833+
});
1834+
}
1835+
Err(OnionDecodeErr::Malformed {
1836+
err_msg: "Non-final Trampoline onion data provided to us as last hop",
1837+
err_code: INVALID_ONION_BLINDING,
1838+
})
1839+
},
1840+
Ok((msgs::InboundTrampolinePayload::BlindedReceive(hop_data), Some(_))) => {
1841+
if hop_data.intro_node_blinding_point.is_some() {
1842+
return Err(OnionDecodeErr::Relay {
1843+
err_msg: "Final Trampoline intro node onion data provided to us as intermediate hop",
1844+
err_code: 0x4000 | 22,
1845+
shared_secret,
1846+
trampoline_shared_secret: Some(SharedSecret::from_bytes(
1847+
trampoline_shared_secret,
1848+
)),
1849+
});
1850+
}
1851+
Err(OnionDecodeErr::Malformed {
1852+
err_msg:
1853+
"Final Trampoline onion data provided to us as intermediate hop",
1854+
err_code: INVALID_ONION_BLINDING,
1855+
})
1856+
},
1857+
Ok((msgs::InboundTrampolinePayload::Forward(_), None)) => {
1858+
Err(OnionDecodeErr::Relay {
1859+
err_msg: "Non-final Trampoline onion data provided to us as last hop",
1860+
err_code: 0x4000 | 22,
1861+
shared_secret,
1862+
trampoline_shared_secret: Some(SharedSecret::from_bytes(
1863+
trampoline_shared_secret,
1864+
)),
1865+
})
1866+
},
1867+
Ok((msgs::InboundTrampolinePayload::Receive(_), Some(_))) => {
1868+
Err(OnionDecodeErr::Relay {
1869+
err_msg:
1870+
"Final Trampoline onion data provided to us as intermediate hop",
1871+
err_code: 0x4000 | 22,
1872+
shared_secret,
1873+
trampoline_shared_secret: Some(SharedSecret::from_bytes(
1874+
trampoline_shared_secret,
1875+
)),
1876+
})
1877+
},
18341878
Err(e) => Err(e),
18351879
}
18361880
},

0 commit comments

Comments
 (0)