@@ -339,6 +339,13 @@ fn pass_along_path(path: &Vec<MessengerNode>) {
339
339
}
340
340
}
341
341
342
+ /// Checks if all the packets in the blinded path are properly padded, ensuring they are of equal size.
343
+ fn is_properly_padded ( path : & BlindedPath ) -> bool {
344
+ let first_hop = path. blinded_hops . first ( ) . expect ( "BlindedPath must have at least one hop" ) ;
345
+ let first_payload_size = first_hop. encrypted_payload . len ( ) ;
346
+ path. blinded_hops . iter ( ) . all ( |hop| hop. encrypted_payload . len ( ) == first_payload_size)
347
+ }
348
+
342
349
#[ test]
343
350
fn one_unblinded_hop ( ) {
344
351
let nodes = create_nodes ( 2 ) ;
@@ -539,6 +546,29 @@ fn too_big_packet_error() {
539
546
assert_eq ! ( err, SendError :: TooBigPacket ) ;
540
547
}
541
548
549
+ #[ test]
550
+ fn blinded_path_padding ( ) {
551
+ // Make sure that for a blinded path, all encrypted payloads are padded to equal lengths.
552
+ let nodes = create_nodes ( 4 ) ;
553
+ let test_msg = TestCustomMessage :: Pong ;
554
+
555
+ let secp_ctx = Secp256k1 :: new ( ) ;
556
+ let intermediate_nodes = [
557
+ ForwardNode { node_id : nodes[ 1 ] . node_id , short_channel_id : None } ,
558
+ ForwardNode { node_id : nodes[ 2 ] . node_id , short_channel_id : None } ,
559
+ ] ;
560
+ let context = MessageContext :: Custom ( Vec :: new ( ) ) ;
561
+ let blinded_path = BlindedPath :: new_for_message ( & intermediate_nodes, nodes[ 3 ] . node_id , context, & * nodes[ 3 ] . entropy_source , & secp_ctx) . unwrap ( ) ;
562
+
563
+ assert ! ( is_properly_padded( & blinded_path) ) ;
564
+
565
+ let destination = Destination :: BlindedPath ( blinded_path) ;
566
+
567
+ nodes[ 0 ] . messenger . send_onion_message ( test_msg, destination, None ) . unwrap ( ) ;
568
+ nodes[ 3 ] . custom_message_handler . expect_message ( TestCustomMessage :: Pong ) ;
569
+ pass_along_path ( & nodes) ;
570
+ }
571
+
542
572
#[ test]
543
573
fn we_are_intro_node ( ) {
544
574
// If we are sending straight to a blinded path and we are the introduction node, we need to
0 commit comments