Skip to content

Commit c7e97d6

Browse files
committed
Add Trampoline error test vector
1 parent c305459 commit c7e97d6

File tree

1 file changed

+90
-2
lines changed

1 file changed

+90
-2
lines changed

lightning/src/ln/onion_utils.rs

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,11 +2036,11 @@ mod tests {
20362036
use crate::prelude::*;
20372037
use crate::util::test_utils::TestLogger;
20382038

2039+
use super::*;
20392040
use bitcoin::hex::FromHex;
20402041
use bitcoin::secp256k1::Secp256k1;
20412042
use bitcoin::secp256k1::{PublicKey, SecretKey};
2042-
2043-
use super::*;
2043+
use types::features::Features;
20442044

20452045
fn get_test_session_key() -> SecretKey {
20462046
let hex = "4141414141414141414141414141414141414141414141414141414141414141";
@@ -2413,6 +2413,94 @@ mod tests {
24132413
assert_eq!(decrypted_failure.onion_error_code, Some(0x2002));
24142414
}
24152415

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

0 commit comments

Comments
 (0)