Skip to content

Commit 3fa0041

Browse files
committed
Add test for dummy hop insertion
Introduces a test to verify correct handling of dummy hops in constructed blinded paths. Ensures that the added dummy hops are properly included and do not interfere with the real path.
1 parent 2c5d4ab commit 3fa0041

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lightning/src/blinded_path/utils.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ pub fn is_padded(hops: &[BlindedHop], padding_round_off: usize) -> bool {
281281
let first_hop = hops.first().expect("BlindedPath must have at least one hop");
282282
let first_payload_size = first_hop.encrypted_payload.len();
283283

284+
// If the hops are padded correctly, the first payload size must be at least
285+
// the padding round off size.
286+
if first_payload_size < padding_round_off {
287+
return false;
288+
}
289+
284290
// The unencrypted payload data is padded before getting encrypted.
285291
// Assuming the first payload is padded properly, get the extra data length.
286292
let extra_length = first_payload_size % padding_round_off;

lightning/src/onion_message/functional_tests.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,34 @@ fn one_blinded_hop() {
443443
pass_along_path(&nodes);
444444
}
445445

446+
#[test]
447+
fn blinded_path_with_dummy() {
448+
let nodes = create_nodes(2);
449+
let test_msg = TestCustomMessage::Pong;
450+
451+
let secp_ctx = Secp256k1::new();
452+
let context = MessageContext::Custom(Vec::new());
453+
let entropy = &*nodes[1].entropy_source;
454+
let receive_key = nodes[1].messenger.node_signer.get_receive_auth_key();
455+
let blinded_path = BlindedMessagePath::new_with_dummy_hops(
456+
&[],
457+
nodes[1].node_id,
458+
5,
459+
receive_key,
460+
context,
461+
entropy,
462+
&secp_ctx,
463+
)
464+
.unwrap();
465+
// Ensure that dummy hops are added to the blinded path.
466+
assert_eq!(blinded_path.blinded_hops().len(), 6);
467+
let destination = Destination::BlindedPath(blinded_path);
468+
let instructions = MessageSendInstructions::WithoutReplyPath { destination };
469+
nodes[0].messenger.send_onion_message(test_msg, instructions).unwrap();
470+
nodes[1].custom_message_handler.expect_message(TestCustomMessage::Pong);
471+
pass_along_path(&nodes);
472+
}
473+
446474
#[test]
447475
fn two_unblinded_two_blinded() {
448476
let nodes = create_nodes(5);
@@ -658,9 +686,10 @@ fn test_blinded_path_padding_for_full_length_path() {
658686
let context = MessageContext::Custom(vec![0u8; 42]);
659687
let entropy = &*nodes[3].entropy_source;
660688
let receive_key = nodes[3].messenger.node_signer.get_receive_auth_key();
661-
let blinded_path = BlindedMessagePath::new(
689+
let blinded_path = BlindedMessagePath::new_with_dummy_hops(
662690
&intermediate_nodes,
663691
nodes[3].node_id,
692+
5,
664693
receive_key,
665694
context,
666695
entropy,
@@ -694,9 +723,10 @@ fn test_blinded_path_no_padding_for_compact_path() {
694723
let context = MessageContext::Custom(vec![0u8; 42]);
695724
let entropy = &*nodes[3].entropy_source;
696725
let receive_key = nodes[3].messenger.node_signer.get_receive_auth_key();
697-
let blinded_path = BlindedMessagePath::new(
726+
let blinded_path = BlindedMessagePath::new_with_dummy_hops(
698727
&intermediate_nodes,
699728
nodes[3].node_id,
729+
5,
700730
receive_key,
701731
context,
702732
entropy,

0 commit comments

Comments
 (0)