Skip to content

Commit 3cba5f6

Browse files
committed
Clean up error handling on onion keys construction
Onion keys construction can only fail if we have a key which is the inverse of a hash containing a public key which we generated (even indirectly). Because we prefer to panic if our RNG creates an insecure key (as it indicates operating is incredibly unsafe), we thus don't actually need to return an error from `construct_onion_keys_generic_callback`, which we clean up here.
1 parent b16b362 commit 3cba5f6

File tree

5 files changed

+44
-53
lines changed

5 files changed

+44
-53
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ fn do_forward_checks_failure(check: ForwardCheckFail, intro_fails: bool) {
385385
ForwardCheckFail::ForwardPayloadEncodedAsReceive => {
386386
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
387387
let session_priv = SecretKey::from_slice(&[3; 32]).unwrap();
388-
let mut onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
388+
let mut onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv);
389389
let cur_height = nodes[0].best_block_info().1;
390390
let (mut onion_payloads, ..) = onion_utils::build_onion_payloads(
391391
&route.paths[0], amt_msat, &recipient_onion_fields, cur_height, &None, None, None).unwrap();
@@ -966,7 +966,7 @@ fn do_multi_hop_receiver_fail(check: ReceiveCheckFail) {
966966
},
967967
ReceiveCheckFail::OnionDecodeFail => {
968968
let session_priv = SecretKey::from_slice(&session_priv).unwrap();
969-
let mut onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
969+
let mut onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv);
970970
let cur_height = nodes[0].best_block_info().1;
971971
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
972972
let (mut onion_payloads, ..) = onion_utils::build_onion_payloads(

lightning/src/ln/functional_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ pub fn test_fee_spike_violation_fails_htlc() {
15001500

15011501
let cur_height = nodes[1].node.best_block.read().unwrap().height + 1;
15021502

1503-
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route.paths[0], &session_priv).unwrap();
1503+
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route.paths[0], &session_priv);
15041504
let recipient_onion_fields = RecipientOnionFields::secret_only(payment_secret);
15051505
let (onion_payloads, htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(&route.paths[0],
15061506
3460001, &recipient_onion_fields, cur_height, &None, None, None).unwrap();
@@ -1686,7 +1686,7 @@ pub fn test_chan_reserve_violation_inbound_htlc_outbound_channel() {
16861686
let secp_ctx = Secp256k1::new();
16871687
let session_priv = SecretKey::from_slice(&[42; 32]).unwrap();
16881688
let cur_height = nodes[1].node.best_block.read().unwrap().height + 1;
1689-
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route.paths[0], &session_priv).unwrap();
1689+
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route.paths[0], &session_priv);
16901690
let recipient_onion_fields = RecipientOnionFields::secret_only(payment_secret);
16911691
let (onion_payloads, htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(&route.paths[0],
16921692
700_000, &recipient_onion_fields, cur_height, &None, None, None).unwrap();
@@ -1866,7 +1866,7 @@ pub fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
18661866
let secp_ctx = Secp256k1::new();
18671867
let session_priv = SecretKey::from_slice(&[42; 32]).unwrap();
18681868
let cur_height = nodes[0].node.best_block.read().unwrap().height + 1;
1869-
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route_2.paths[0], &session_priv).unwrap();
1869+
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route_2.paths[0], &session_priv);
18701870
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
18711871
let (onion_payloads, htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(
18721872
&route_2.paths[0], recv_value_2, &recipient_onion_fields, cur_height, &None, None, None).unwrap();
@@ -3918,7 +3918,7 @@ pub fn fail_backward_pending_htlc_upon_channel_failure() {
39183918
let recipient_onion_fields = RecipientOnionFields::secret_only(payment_secret);
39193919
let (onion_payloads, _amount_msat, cltv_expiry) = onion_utils::build_onion_payloads(
39203920
&route.paths[0], 50_000, &recipient_onion_fields, current_height, &None, None, None).unwrap();
3921-
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route.paths[0], &session_priv).unwrap();
3921+
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route.paths[0], &session_priv);
39223922
let onion_routing_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &payment_hash).unwrap();
39233923

39243924
// Send a 0-msat update_add_htlc to fail the channel.
@@ -6930,7 +6930,7 @@ pub fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
69306930
route.paths[0].hops[0].fee_msat = send_amt;
69316931
let session_priv = SecretKey::from_slice(&[42; 32]).unwrap();
69326932
let cur_height = nodes[0].node.best_block.read().unwrap().height + 1;
6933-
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::signing_only(), &route.paths[0], &session_priv).unwrap();
6933+
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::signing_only(), &route.paths[0], &session_priv);
69346934
let recipient_onion_fields = RecipientOnionFields::secret_only(our_payment_secret);
69356935
let (onion_payloads, _htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(
69366936
&route.paths[0], send_amt, &recipient_onion_fields, cur_height, &None, None, None).unwrap();
@@ -8745,7 +8745,7 @@ pub fn test_onion_value_mpp_set_calculation() {
87458745
let session_priv = [3; 32];
87468746
let height = nodes[0].best_block_info().1;
87478747
let session_priv = SecretKey::from_slice(&session_priv).unwrap();
8748-
let mut onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
8748+
let mut onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv);
87498749
let recipient_onion_fields = RecipientOnionFields::secret_only(our_payment_secret);
87508750
let (mut onion_payloads, _, _) = onion_utils::build_onion_payloads(&route.paths[0], 100_000,
87518751
&recipient_onion_fields, height + 1, &None, None, None).unwrap();

lightning/src/ln/onion_payment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ mod tests {
662662
recipient_onion.custom_tlvs.push((13377331, vec![0; 1156]));
663663

664664
let path = Path { hops, blinded_tail: None, };
665-
let onion_keys = super::onion_utils::construct_onion_keys(&secp_ctx, &path, &session_priv).unwrap();
665+
let onion_keys = super::onion_utils::construct_onion_keys(&secp_ctx, &path, &session_priv);
666666
let (onion_payloads, ..) = super::onion_utils::build_onion_payloads(
667667
&path, total_amt_msat, &recipient_onion, cur_height + 1, &Some(keysend_preimage), None, None
668668
).unwrap();

0 commit comments

Comments
 (0)