You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let max_length = get_control_tlv_length!(true,true);
214
+
215
+
let dummy_next_node_id = PublicKey::from_slice(&hex::decode("030101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap();
216
+
let dummy_blinding_override = PublicKey::from_slice(&hex::decode("030202020202020202020202020202020202020202020202020202020202020202").unwrap()[..]).unwrap();
// As `serialized_no_padding_tlv` is the longest tlv, no padding is expected.
245
+
// Expected data tlv is:
246
+
// 1. 4 (type) for `next_node_id`
247
+
// 2. 33 (length) for the length of a point/public key
248
+
// 3. 33 bytes of the `dummy_next_node_id`
249
+
// 4. 8 (type) for `next_blinding_override`
250
+
// 5. 33 (length) for the length of a point/public key
251
+
// 6. 33 bytes of the `dummy_blinding_override`
252
+
let expected_serialized_no_padding_tlv_payload = &hex::decode("04210301010101010101010101010101010101010101010101010101010101010101010821030202020202020202020202020202020202020202020202020202020202020202").unwrap()[..];
let serialized_blinding_override_padding_tlv = w.0;
259
+
// As `serialized_blinding_override_padding_tlv` has no `next_blinding_override`, 35 bytes
260
+
// of padding is expected (the serialized length of `next_blinding_override`).
261
+
// Expected data tlv is:
262
+
// 1. 1 (type) for padding
263
+
// 2. 33 (length) given the length of a the missing `next_blinding_override`
264
+
// 3. 33 0 bytes of padding
265
+
// 4. 4 (type) for `next_node_id`
266
+
// 5. 33 (length) for the length of a point/public key
267
+
// 6. 33 bytes of the `dummy_next_node_id`
268
+
let expected_serialized_blinding_override_padding_tlv = &hex::decode("01210000000000000000000000000000000000000000000000000000000000000000000421030101010101010101010101010101010101010101010101010101010101010101").unwrap()[..];
// As `recieve_tlv_padding_tlv` is a `ReceiveTlv` and has a `path_id`, 36 bytes of padding
276
+
// is expected, ie. 70 (value of `max_length`) - 34 (the serialized length of `path_id`).
277
+
// Expected data tlv is:
278
+
// 1. 1 (type) for padding
279
+
// 2. 34 (length) given 70 - 34
280
+
// 3. 34 0 bytes of padding
281
+
// 4. 6 (type) for `path_id`
282
+
// 5. 32 (length) for the length of a `path_id`
283
+
// 6. 32 bytes of the `path_id`
284
+
let expected_serialized_recieve_tlv_padding_tlv_payload = &hex::decode("01220000000000000000000000000000000000000000000000000000000000000000000006200101010101010101010101010101010101010101010101010101010101010101").unwrap()[..];
// As `serialized_full_padding_tlv` is a `ReceiveTlv` with no data at alll, 70 bytes of
292
+
// padding is expected (value of `max_length`).
293
+
// Expected data tlv is:
294
+
// 1. 1 (type) for padding
295
+
// 2. 68 (length) the length of the padding minus the prefix
296
+
// 3. 68 0 bytes of padding
297
+
let expected_serialized_full_padding_tlv_payload = &hex::decode("01440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap()[..];
let first_node_id = PublicKey::from_secret_key(&secp_ctx,&SecretKey::from_slice(&hex::decode(format!("{:02}",41).repeat(32)).unwrap()[..]).unwrap());
306
+
let middle_node_id = PublicKey::from_secret_key(&secp_ctx,&SecretKey::from_slice(&hex::decode(format!("{:02}",42).repeat(32)).unwrap()[..]).unwrap());
307
+
let recieve_node_id = PublicKey::from_secret_key(&secp_ctx,&SecretKey::from_slice(&hex::decode(format!("{:02}",43).repeat(32)).unwrap()[..]).unwrap());
308
+
let session_priv = SecretKey::from_slice(&hex::decode(format!("{:02}",3).repeat(32)).unwrap()[..]).unwrap();
309
+
310
+
let blinded_hops = blinded_hops(&secp_ctx,&[first_node_id, middle_node_id, recieve_node_id],&session_priv,false).unwrap();
311
+
312
+
// Verify that the blinded hops returned from `blinded_hops` have the same
313
+
// `encrypted_payload` length, regardless of which type of payload it is.
let two_blinded_hops = BlindedRoute::new(&[nodes[2].get_node_pk(), nodes[3].get_node_pk()],&*nodes[3].keys_manager,&secp_ctx,true).unwrap();
191
+
let three_blinded_hops = BlindedRoute::new(&[nodes[1].get_node_pk(), nodes[2].get_node_pk(), nodes[3].get_node_pk()],&*nodes[3].keys_manager,&secp_ctx,true).unwrap();
192
+
let session_priv = SecretKey::from_slice(&hex::decode(format!("{:02}",3).repeat(32)).unwrap()[..]).unwrap();
193
+
194
+
let only_unblinded_payloads = packet_payloads_and_keys(&secp_ctx,&[nodes[0].get_node_pk(), nodes[1].get_node_pk()],Destination::Node(nodes[2].get_node_pk()),None,&session_priv).unwrap().0;
195
+
let one_unblinded_and_three_blinded_payloads = packet_payloads_and_keys(&secp_ctx,&[nodes[1].get_node_pk()],Destination::BlindedRoute(three_blinded_hops),None,&session_priv).unwrap().0;
196
+
// When more that one unblinded payload exists, the blinded payloads should be the same length
197
+
// as the largest unblinded payload.
198
+
let multiple_unblinded_and_blinded_payloads = packet_payloads_and_keys(&secp_ctx,&[nodes[0].get_node_pk(), nodes[1].get_node_pk()],Destination::BlindedRoute(two_blinded_hops),None,&session_priv).unwrap().0;
199
+
200
+
// Verify that the blinded contol tlv payloads returned from `packet_payloads_and_keys` have
201
+
// the same length, and that the payload for every blinded payload matches the length of the
202
+
// largest unblinded payload length.
203
+
for payloads in[only_unblinded_payloads, one_unblinded_and_three_blinded_payloads, multiple_unblinded_and_blinded_payloads]{
204
+
letmut longest_tlv_length = None;
205
+
206
+
macro_rules! assign_longest_tlv_length {
207
+
($unblinded_tlv_length: expr) => {
208
+
if longest_tlv_length.map(|current_len| $unblinded_tlv_length > current_len).unwrap_or(true){
209
+
longest_tlv_length = Some($unblinded_tlv_length);
210
+
}
211
+
};
212
+
}
213
+
214
+
macro_rules! assert_correct_tlv_length {
215
+
($tlv_length: expr) => {
216
+
match longest_tlv_length {
217
+
None => {
218
+
longest_tlv_length = Some($tlv_length);
219
+
},
220
+
Some(expected_len) => {
221
+
assert_eq!($tlv_length, expected_len);
222
+
}
223
+
}
224
+
};
225
+
}
226
+
227
+
for payload in payloads {
228
+
match payload.0{
229
+
Payload::Forward(control_tlvs) => {
230
+
match control_tlvs {
231
+
ForwardControlTlvs::Blinded(bytes) => {
232
+
// 16 deducted to account for the 16 byte tag of the ChaCha encryption
0 commit comments