Skip to content

Commit b7d63a9

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

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lightning/src/ln/onion_utils.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,15 @@ 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 = if path.trampoline_hops.len() == 0 {
318+
path.blinded_tail.as_ref()
319+
} else {
320+
None
321+
};
317322
construct_onion_keys_generic_callback(
318323
secp_ctx,
319324
&path.hops,
320-
path.blinded_tail.as_ref(),
325+
blinded_tail,
321326
session_priv,
322327
|shared_secret, _blinding_factor, ephemeral_pubkey, _, _| {
323328
let (rho, mu) = gen_rho_mu_from_shared_secret(shared_secret.as_ref());
@@ -648,6 +653,8 @@ pub(super) fn construct_onion_packet(
648653
let mut chacha = ChaCha20::new(&prng_seed, &[0; 8]);
649654
chacha.process(&[0; ONION_DATA_LEN], &mut packet_data);
650655

656+
debug_assert_eq!(payloads.len(), onion_keys.len(), "Payloads and keys must have equal lengths");
657+
651658
let packet = FixedSizeOnionPacket(packet_data);
652659
construct_onion_packet_with_init_noise::<_, _>(
653660
payloads,

0 commit comments

Comments
 (0)