Skip to content

Commit 72a8397

Browse files
committed
mutation test for attr errs
1 parent 8d735fc commit 72a8397

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

lightning/src/ln/onion_utils.rs

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ where
10141014
return;
10151015
}
10161016

1017-
log_info!(logger, "Processing index {} of {}", route_hop_idx, path.hops.len());
1017+
// log_info!(logger, "Processing index {} of {}", route_hop_idx, path.hops.len());
10181018

10191019
let route_hop = match route_hop_opt {
10201020
Some(hop) => hop,
@@ -1106,11 +1106,11 @@ where
11061106
failed_within_blinded_path: false,
11071107
});
11081108

1109-
log_debug!(logger, "Invalid HMAC in onion failure packet at pos {}", route_hop_idx);
1109+
// log_debug!(logger, "Invalid HMAC in onion failure packet at pos {}", route_hop_idx);
11101110

11111111
return;
11121112
} else {
1113-
log_debug!(logger, "Valid HMAC in onion failure packet at pos {}", route_hop_idx);
1113+
// log_debug!(logger, "Valid HMAC in onion failure packet at pos {}", route_hop_idx);
11141114
}
11151115

11161116
// Shift payloads left.
@@ -2006,22 +2006,22 @@ use crate::util::test_utils::TestLogger;
20062006
RouteHop {
20072007
pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap(),
20082008
channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
2009-
short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
2009+
short_channel_id: 1, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
20102010
},
20112011
RouteHop {
20122012
pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()[..]).unwrap(),
20132013
channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
2014-
short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
2014+
short_channel_id: 2, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
20152015
},
20162016
RouteHop {
20172017
pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]).unwrap(),
20182018
channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
2019-
short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
2019+
short_channel_id: 3, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
20202020
},
20212021
RouteHop {
20222022
pubkey: PublicKey::from_slice(&<Vec<u8>>::from_hex("02edabbd16b41c8371b92ef2f04c1185b4f03b6dcd52ba9b78d9d7c89c8f221145").unwrap()[..]).unwrap(),
20232023
channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
2024-
short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
2024+
short_channel_id: 4, fee_msat: 0, cltv_expiry_delta: 0, maybe_announced_channel: true, // We fill in the payloads manually instead of generating them from RouteHops.
20252025
},
20262026
], blinded_tail: None }
20272027
}
@@ -2327,28 +2327,20 @@ use crate::util::test_utils::TestLogger;
23272327
set_max_path_length(&mut route_params, &recipient_onion, None, None, 42).unwrap();
23282328
}
23292329

2330-
// #[test]
2331-
// fn test_attributable_failure_packet_onion() {
2332-
// const EXPECT_FAILURE: &str = "400f0000000000000064000c3500fd84d1fd012c808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080";
2333-
2334-
// for mutating_node in 0..5 {
2335-
// for mutated_index in 0..1968 {
2336-
// println!("Testing mutation {} on node {}", mutated_index, mutating_node);
2337-
2338-
// let decrypted_failure = test_attributable_failure_packet_onion_with_mutation(mutating_node, mutated_index);
2339-
2340-
// match decrypted_failure.result {
2341-
// AttributableFailureResult::Success(success) => {
2342-
// assert_eq!(success.message.to_lower_hex_string(), EXPECT_FAILURE);
2343-
// assert_eq!(decrypted_failure.failure_index, 4);
2344-
// }
2345-
// AttributableFailureResult::InvalidPayload | AttributableFailureResult::InvalidHmac => {
2346-
// assert_eq!(decrypted_failure.failure_index, 4-mutating_node);
2347-
// }
2348-
// }
2349-
// }
2350-
// }
2351-
// }
2330+
#[test]
2331+
fn test_attributable_failure_packet_onion_mutations() {
2332+
for mutating_node in 0..5 {
2333+
for mutated_index in 0..1060+920 {
2334+
let decrypted_failure = test_attributable_failure_packet_onion_with_mutation(mutating_node, mutated_index);
2335+
2336+
// if let Some(chan_id) = decrypted_failure.short_channel_id {
2337+
// println!("Testing mutation {} on node {}: chan failure at {}", mutated_index, mutating_node, chan_id);
2338+
// }
2339+
2340+
assert!(decrypted_failure.onion_error_code == Some(16399) || decrypted_failure.short_channel_id.is_some());
2341+
}
2342+
}
2343+
}
23522344

23532345
#[test]
23542346
fn test_attributable_failure_packet_onion_happy() {
@@ -2388,13 +2380,22 @@ use crate::util::test_utils::TestLogger;
23882380

23892381
let logger: Arc<TestLogger> = Arc::new(TestLogger::new());
23902382

2391-
// if mutating_node == 0 {
2392-
// packet_slice[mutated_index] ^= 1;
2393-
// }
2394-
23952383
let mut encrypted_packet = super::encrypt_failure_packet(onion_keys[4].shared_secret.as_ref(), &onion_error);
23962384
// assert_eq!(encrypted_packet.data.to_lower_hex_string(), EXPECTED_MESSAGES[0]);
23972385

2386+
let mutate_packet = |packet: &mut OnionErrorPacket, mutated_index| {
2387+
let data_len = packet.data.len();
2388+
if mutated_index < data_len {
2389+
packet.data[mutated_index] ^= 1;
2390+
} else {
2391+
packet.attribution_data[mutated_index - data_len] ^= 1;
2392+
}
2393+
};
2394+
2395+
if mutating_node == 0 {
2396+
mutate_packet(&mut encrypted_packet, mutated_index);
2397+
}
2398+
23982399
for idx in 1..5 {
23992400

24002401
let shared_secret = onion_keys[4 - idx].shared_secret.as_ref();
@@ -2403,9 +2404,10 @@ use crate::util::test_utils::TestLogger;
24032404
process_failure_packet(&mut encrypted_packet, shared_secret, &payload);
24042405
encrypted_packet = super::encrypt_failure_packet(shared_secret, &encrypted_packet);
24052406

2406-
// if idx == mutating_node {
2407-
// encrypted_packet.data[mutated_index] ^= 1;
2408-
// }
2407+
if mutating_node == idx {
2408+
mutate_packet(&mut encrypted_packet, mutated_index);
2409+
}
2410+
24092411
// assert_eq!(encrypted_packet.data.to_lower_hex_string(), EXPECTED_MESSAGES[idx]);
24102412
}
24112413

0 commit comments

Comments
 (0)