@@ -32,12 +32,6 @@ fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
32
32
} } ;
33
33
}
34
34
35
- macro_rules! get_u8 {
36
- ( ) => {
37
- get_slice!( 1 ) [ 0 ]
38
- } ;
39
- }
40
-
41
35
macro_rules! get_u16 {
42
36
( ) => {
43
37
match get_slice!( 2 ) . try_into( ) {
@@ -47,105 +41,82 @@ fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
47
41
} ;
48
42
}
49
43
50
- macro_rules! get_u32 {
44
+ macro_rules! get_bool {
51
45
( ) => {
52
- match get_slice!( 4 ) . try_into( ) {
53
- Ok ( val) => u32 :: from_be_bytes( val) ,
54
- Err ( _) => return ,
55
- }
46
+ get_slice!( 1 ) [ 0 ] & 1 != 0
56
47
} ;
57
48
}
58
49
59
- macro_rules! get_u64 {
60
- ( ) => {
61
- match get_slice!( 8 ) . try_into( ) {
62
- Ok ( val) => u64 :: from_be_bytes( val) ,
63
- Err ( _) => return ,
64
- }
65
- } ;
50
+ fn usize_to_32_bytes ( input : usize ) -> [ u8 ; 32 ] {
51
+ let mut bytes = [ 0u8 ; 32 ] ;
52
+ let input_bytes = input. to_be_bytes ( ) ;
53
+ bytes[ ..input_bytes. len ( ) ] . copy_from_slice ( & input_bytes) ;
54
+ bytes
66
55
}
67
56
68
- macro_rules! get_bool {
69
- ( ) => {
70
- get_slice!( 1 ) [ 0 ] != 0
71
- } ;
72
- }
57
+ fn usize_to_pubkey ( input : usize ) -> PublicKey {
58
+ let bytes = usize_to_32_bytes ( 1 + input) ;
73
59
74
- macro_rules! get_pubkey {
75
- ( ) => {
76
- match PublicKey :: from_slice( get_slice!( 33 ) ) {
77
- Ok ( val) => val,
78
- Err ( _) => return ,
79
- }
80
- } ;
60
+ let secp_ctx = Secp256k1 :: new ( ) ;
61
+ let secret_key = SecretKey :: from_slice ( & bytes) . unwrap ( ) ;
62
+ secret_key. public_key ( & secp_ctx)
81
63
}
82
64
83
65
let secp_ctx = Secp256k1 :: new ( ) ;
84
66
let logger: Arc < dyn Logger > = Arc :: new ( test_logger:: TestLogger :: new ( "" . to_owned ( ) , out) ) ;
85
67
86
- let session_priv = match SecretKey :: from_slice ( get_slice ! ( 32 ) ) {
87
- Ok ( val) => val,
88
- Err ( _) => return ,
89
- } ;
90
-
91
- let payment_id = match get_slice ! ( 32 ) . try_into ( ) {
92
- Ok ( val) => PaymentId ( val) ,
93
- Err ( _) => return ,
94
- } ;
68
+ let session_priv = SecretKey :: from_slice ( & usize_to_32_bytes ( 213127 ) ) . unwrap ( ) ;
69
+ let payment_id = PaymentId ( usize_to_32_bytes ( 232299 ) ) ;
95
70
96
71
let mut hops = Vec :: < RouteHop > :: new ( ) ;
97
- let hop_count = get_slice ! ( 1 ) [ 0 ] as usize ;
98
- for _ in 0 ..hop_count {
72
+ let hop_count = get_slice ! ( 1 ) [ 0 ] as usize % 30 ;
73
+ for i in 0 ..hop_count {
99
74
hops. push ( RouteHop {
100
- pubkey : get_pubkey ! ( ) ,
75
+ pubkey : usize_to_pubkey ( i ) ,
101
76
node_features : NodeFeatures :: empty ( ) ,
102
- short_channel_id : get_u64 ! ( ) ,
77
+ short_channel_id : i as u64 ,
103
78
channel_features : ChannelFeatures :: empty ( ) ,
104
- fee_msat : get_u64 ! ( ) ,
105
- cltv_expiry_delta : get_u32 ! ( ) ,
106
- maybe_announced_channel : get_bool ! ( ) ,
79
+ fee_msat : 0 ,
80
+ cltv_expiry_delta : 0 ,
81
+ maybe_announced_channel : false ,
107
82
} ) ;
108
83
}
109
84
110
85
let blinded_tail = match get_bool ! ( ) {
111
86
true => {
112
87
let mut trampoline_hops = Vec :: < TrampolineHop > :: new ( ) ;
113
- let trampoline_hop_count = get_slice ! ( 1 ) [ 0 ] as usize ;
114
- for _ in 0 ..trampoline_hop_count {
88
+ let trampoline_hop_count = get_slice ! ( 1 ) [ 0 ] as usize % 30 ;
89
+ for i in 0 ..trampoline_hop_count {
115
90
trampoline_hops. push ( TrampolineHop {
116
- pubkey : get_pubkey ! ( ) ,
91
+ pubkey : usize_to_pubkey ( 1000 + i ) ,
117
92
node_features : NodeFeatures :: empty ( ) ,
118
- fee_msat : get_u64 ! ( ) ,
119
- cltv_expiry_delta : get_u32 ! ( ) ,
93
+ fee_msat : 0 ,
94
+ cltv_expiry_delta : 0 ,
120
95
} ) ;
121
96
}
122
97
let mut blinded_hops = Vec :: < BlindedHop > :: new ( ) ;
123
- let blinded_hop_count = get_slice ! ( 1 ) [ 0 ] as usize ;
124
- for _ in 0 ..blinded_hop_count {
98
+ let blinded_hop_count = get_slice ! ( 1 ) [ 0 ] as usize % 30 ;
99
+ for i in 0 ..blinded_hop_count {
125
100
blinded_hops. push ( BlindedHop {
126
- blinded_node_id : get_pubkey ! ( ) ,
127
- encrypted_payload : get_slice ! ( get_u8 !( ) ) . to_vec ( ) ,
101
+ blinded_node_id : usize_to_pubkey ( 2000 + i ) ,
102
+ encrypted_payload : get_slice ! ( get_u16 !( ) ) . to_vec ( ) ,
128
103
} ) ;
129
104
}
130
105
Some ( BlindedTail {
131
106
trampoline_hops,
132
107
hops : blinded_hops,
133
- blinding_point : get_pubkey ! ( ) ,
134
- excess_final_cltv_expiry_delta : get_u32 ! ( ) ,
135
- final_value_msat : get_u64 ! ( ) ,
108
+ blinding_point : usize_to_pubkey ( 64354334 ) ,
109
+ excess_final_cltv_expiry_delta : 0 ,
110
+ final_value_msat : 0 ,
136
111
} )
137
112
} ,
138
113
false => None ,
139
114
} ;
140
115
141
116
let path = Path { hops, blinded_tail } ;
142
117
143
- let htlc_source = HTLCSource :: OutboundRoute {
144
- path,
145
- session_priv,
146
- first_hop_htlc_msat : get_u64 ! ( ) ,
147
- payment_id,
148
- } ;
118
+ let htlc_source =
119
+ HTLCSource :: OutboundRoute { path, session_priv, first_hop_htlc_msat : 0 , payment_id } ;
149
120
150
121
let failure_len = get_u16 ! ( ) ;
151
122
let encrypted_packet = OnionErrorPacket { data : get_slice ! ( failure_len) . into ( ) } ;
0 commit comments