Skip to content

Commit 35d1314

Browse files
committed
f: assert payload/key match
1 parent 93b9c5c commit 35d1314

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lightning/src/ln/onion_utils.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,12 @@ pub(super) fn construct_onion_keys<T: secp256k1::Signing>(
314314
) -> Result<Vec<OnionKeys>, secp256k1::Error> {
315315
let mut res = Vec::with_capacity(path.hops.len());
316316

317+
let blinded_tail =
318+
if path.trampoline_hops.len() == 0 { path.blinded_tail.as_ref() } else { None };
317319
construct_onion_keys_generic_callback(
318320
secp_ctx,
319321
&path.hops,
320-
path.blinded_tail.as_ref(),
322+
blinded_tail,
321323
session_priv,
322324
|shared_secret, _blinding_factor, ephemeral_pubkey, _, _| {
323325
let (rho, mu) = gen_rho_mu_from_shared_secret(shared_secret.as_ref());
@@ -648,6 +650,8 @@ pub(super) fn construct_onion_packet(
648650
let mut chacha = ChaCha20::new(&prng_seed, &[0; 8]);
649651
chacha.process(&[0; ONION_DATA_LEN], &mut packet_data);
650652

653+
debug_assert_eq!(payloads.len(), onion_keys.len(), "Payloads and keys must have equal lengths");
654+
651655
let packet = FixedSizeOnionPacket(packet_data);
652656
construct_onion_packet_with_init_noise::<_, _>(
653657
payloads,

0 commit comments

Comments
 (0)