Skip to content

Commit 6b0b8df

Browse files
committed
Add Trampoline error test vector
1 parent d7df50f commit 6b0b8df

File tree

1 file changed

+91
-2
lines changed

1 file changed

+91
-2
lines changed

lightning/src/ln/onion_utils.rs

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,11 +2039,11 @@ mod tests {
20392039
use crate::prelude::*;
20402040
use crate::util::test_utils::TestLogger;
20412041

2042+
use super::*;
20422043
use bitcoin::hex::FromHex;
20432044
use bitcoin::secp256k1::Secp256k1;
20442045
use bitcoin::secp256k1::{PublicKey, SecretKey};
2045-
2046-
use super::*;
2046+
use types::features::Features;
20472047

20482048
fn get_test_session_key() -> SecretKey {
20492049
let hex = "4141414141414141414141414141414141414141414141414141414141414141";
@@ -2404,6 +2404,95 @@ mod tests {
24042404
assert_eq!(decrypted_failure.onion_error_code, Some(0x2002));
24052405
}
24062406

2407+
#[test]
2408+
fn test_trampoline_onion_error_vectors() {
2409+
// as per https://github.com/lightning/bolts/blob/079f761bf68caa48544bd6bf0a29591d43425b0b/bolt04/trampoline-onion-error-test.json
2410+
// TODO(arik): check intermediate hops' perspectives once we have implemented forwarding
2411+
2412+
let dummy_amt_msat = 150_000_000;
2413+
let path = Path {
2414+
hops: vec![
2415+
// Bob
2416+
RouteHop {
2417+
pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()).unwrap(),
2418+
node_features: NodeFeatures::empty(),
2419+
short_channel_id: 0,
2420+
channel_features: ChannelFeatures::empty(),
2421+
fee_msat: 3_000,
2422+
cltv_expiry_delta: 24,
2423+
maybe_announced_channel: false,
2424+
},
2425+
2426+
// Carol
2427+
RouteHop {
2428+
pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()).unwrap(),
2429+
node_features: NodeFeatures::empty(),
2430+
short_channel_id: (572330 << 40) + (42 << 16) + 2821,
2431+
channel_features: ChannelFeatures::empty(),
2432+
fee_msat: 153_000,
2433+
cltv_expiry_delta: 0,
2434+
maybe_announced_channel: false,
2435+
},
2436+
],
2437+
blinded_tail: Some(BlindedTail {
2438+
trampoline_hops: vec![
2439+
// Carol's pubkey
2440+
TrampolineHop {
2441+
pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()).unwrap(),
2442+
node_features: Features::empty(),
2443+
fee_msat: 2_500,
2444+
cltv_expiry_delta: 24,
2445+
},
2446+
2447+
// Eve's pubkey
2448+
TrampolineHop {
2449+
pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("02edabbd16b41c8371b92ef2f04c1185b4f03b6dcd52ba9b78d9d7c89c8f221145").unwrap()).unwrap(),
2450+
node_features: Features::empty(),
2451+
fee_msat: 2_500,
2452+
cltv_expiry_delta: 24,
2453+
},
2454+
],
2455+
2456+
// Dummy blinded hop (because LDK doesn't allow unblinded Trampoline receives)
2457+
hops: vec![
2458+
// Eve's dummy blinded node id
2459+
BlindedHop {
2460+
blinded_node_id: PublicKey::from_slice(&<Vec<u8>>::from_hex("0295d40514096a8be54859e7dfe947b376eaafea8afe5cb4eb2c13ff857ed0b4be").unwrap()).unwrap(),
2461+
encrypted_payload: vec![],
2462+
}
2463+
],
2464+
blinding_point: PublicKey::from_slice(&<Vec<u8>>::from_hex("02988face71e92c345a068f740191fd8e53be14f0bb957ef730d3c5f76087b960e").unwrap()).unwrap(),
2465+
excess_final_cltv_expiry_delta: 0,
2466+
final_value_msat: dummy_amt_msat
2467+
}),
2468+
};
2469+
2470+
// all dummy values
2471+
let secp_ctx = Secp256k1::new();
2472+
let trampoline_session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
2473+
let outer_session_priv = SecretKey::from_slice(&[4; 32]).unwrap();
2474+
2475+
let logger: Arc<TestLogger> = Arc::new(TestLogger::new());
2476+
let htlc_source = HTLCSource::OutboundRoute {
2477+
path,
2478+
session_priv: trampoline_session_priv,
2479+
first_hop_htlc_msat: dummy_amt_msat,
2480+
payment_id: PaymentId([1; 32]),
2481+
};
2482+
2483+
let error_packet_hex = "f8941a320b8fde4ad7b9b920c69cbf334114737497d93059d77e591eaa78d6334d3e2aeefcb0cc83402eaaf91d07d695cd895d9cad1018abdaf7d2a49d7657b1612729db7f393f0bb62b25afaaaa326d72a9214666025385033f2ec4605dcf1507467b5726d806da180ea224a7d8631cd31b0bdd08eead8bfe14fc8c7475e17768b1321b54dd4294aecc96da391efe0ca5bd267a45ee085c85a60cf9a9ac152fa4795fff8700a3ea4f848817f5e6943e855ab2e86f6929c9e885d8b20c49b14d2512c59ed21f10bd38691110b0d82c00d9fa48a20f10c7550358724c6e8e2b966e56a0aadf458695b273768062fa7c6e60eb72d4cdc67bf525c194e4a17fdcaa0e9d80480b586bf113f14eea530b6728a1c53fe5cee092e24a90f21f4b764015e7ed5e23";
2484+
let error_packet =
2485+
OnionErrorPacket { data: <Vec<u8>>::from_hex(error_packet_hex).unwrap() };
2486+
let decrypted_failure = process_onion_failure(
2487+
&secp_ctx,
2488+
&logger,
2489+
&htlc_source,
2490+
error_packet,
2491+
Some(outer_session_priv),
2492+
);
2493+
assert_eq!(decrypted_failure.onion_error_code, Some(0x400f));
2494+
}
2495+
24072496
#[test]
24082497
fn test_non_attributable_failure_packet_onion() {
24092498
// Create a failure packet with bogus data.

0 commit comments

Comments
 (0)