Skip to content

Commit 243f8d3

Browse files
committed
fuzzy exports
1 parent fe4bcd7 commit 243f8d3

File tree

6 files changed

+55
-40
lines changed

6 files changed

+55
-40
lines changed

fuzz/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
hfuzz_target
22
target
33
hfuzz_workspace
4+
corpus

fuzz/src/process_onion_failure.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
9292

9393
let mut hops = Vec::<RouteHop>::new();
9494
let hop_count = get_slice!(1)[0] as usize;
95-
for i in 0..hop_count {
95+
for _ in 0..hop_count {
9696
hops.push(RouteHop {
9797
pubkey: get_pubkey!(),
9898
node_features: NodeFeatures::empty(),
@@ -108,7 +108,7 @@ fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
108108
true => {
109109
let mut trampoline_hops = Vec::<TrampolineHop>::new();
110110
let trampoline_hop_count = get_slice!(1)[0] as usize;
111-
for i in 0..trampoline_hop_count {
111+
for _ in 0..trampoline_hop_count {
112112
trampoline_hops.push(TrampolineHop {
113113
pubkey: get_pubkey!(),
114114
node_features: NodeFeatures::empty(),
@@ -118,7 +118,7 @@ fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
118118
}
119119
let mut blinded_hops = Vec::<BlindedHop>::new();
120120
let blinded_hop_count = get_slice!(1)[0] as usize;
121-
for i in 0..blinded_hop_count {
121+
for _ in 0..blinded_hop_count {
122122
blinded_hops.push(BlindedHop {
123123
blinded_node_id: get_pubkey!(),
124124
encrypted_payload: get_slice!(get_u8!()).to_vec(),
@@ -147,12 +147,7 @@ fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
147147
let failure_len = u16::from_be_bytes(get_slice!(2).try_into().unwrap());
148148
let encrypted_packet = OnionErrorPacket { data: get_slice!(failure_len as u64).into() };
149149

150-
lightning::ln::onion_utils::process_onion_failure(
151-
&secp_ctx,
152-
&logger,
153-
&htlc_source,
154-
encrypted_packet,
155-
);
150+
lightning::ln::process_onion_failure(&secp_ctx, &logger, &htlc_source, encrypted_packet);
156151
}
157152

158153
/// Method that needs to be added manually, {name}_test

lightning/src/ln/channelmanager.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -674,21 +674,29 @@ impl_writeable_tlv_based_enum!(SentHTLCId,
674674
},
675675
);
676676

677-
678-
/// Tracks the inbound corresponding to an outbound HTLC
679-
#[allow(clippy::derive_hash_xor_eq)] // Our Hash is faithful to the data, we just don't have SecretKey::hash
680-
#[derive(Clone, Debug, PartialEq, Eq)]
681-
pub enum HTLCSource {
682-
PreviousHopData(HTLCPreviousHopData),
683-
OutboundRoute {
684-
path: Path,
685-
session_priv: SecretKey,
686-
/// Technically we can recalculate this from the route, but we cache it here to avoid
687-
/// doing a double-pass on route when we get a failure back
688-
first_hop_htlc_msat: u64,
689-
payment_id: PaymentId,
690-
},
677+
mod fuzzy_channelmanager {
678+
use super::*;
679+
680+
/// Tracks the inbound corresponding to an outbound HTLC
681+
#[allow(clippy::derive_hash_xor_eq)] // Our Hash is faithful to the data, we just don't have SecretKey::hash
682+
#[derive(Clone, Debug, PartialEq, Eq)]
683+
pub enum HTLCSource {
684+
PreviousHopData(HTLCPreviousHopData),
685+
OutboundRoute {
686+
path: Path,
687+
session_priv: SecretKey,
688+
/// Technically we can recalculate this from the route, but we cache it here to avoid
689+
/// doing a double-pass on route when we get a failure back
690+
first_hop_htlc_msat: u64,
691+
payment_id: PaymentId,
692+
},
693+
}
691694
}
695+
#[cfg(fuzzing)]
696+
pub use self::fuzzy_channelmanager::*;
697+
#[cfg(not(fuzzing))]
698+
pub(crate) use self::fuzzy_channelmanager::*;
699+
692700
#[allow(clippy::derive_hash_xor_eq)] // Our Hash is faithful to the data, we just don't have SecretKey::hash
693701
impl core::hash::Hash for HTLCSource {
694702
fn hash<H: core::hash::Hasher>(&self, hasher: &mut H) {

lightning/src/ln/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub mod channel;
3939
#[cfg(not(fuzzing))]
4040
pub(crate) mod channel;
4141

42-
pub mod onion_utils;
42+
pub(crate) mod onion_utils;
4343
mod outbound_payment;
4444
pub mod wire;
4545

@@ -51,6 +51,9 @@ pub use onion_utils::create_payment_onion;
5151
// without the node parameter being mut. This is incorrect, and thus newer rustcs will complain
5252
// about an unnecessary mut. Thus, we silence the unused_mut warning in two test modules below.
5353

54+
#[cfg(fuzzing)]
55+
pub use onion_utils::process_onion_failure;
56+
5457
#[cfg(test)]
5558
#[allow(unused_mut)]
5659
pub mod bolt11_payment_tests;

lightning/src/ln/msgs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,13 @@ mod fuzzy_internal_msgs {
22412241
pub(crate) failuremsg: Vec<u8>,
22422242
pub(crate) pad: Vec<u8>,
22432243
}
2244+
2245+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
2246+
pub struct OnionErrorPacket {
2247+
// This really should be a constant size slice, but the spec lets these things be up to 128KB?
2248+
// (TODO) We limit it in decode to much lower...
2249+
pub data: Vec<u8>,
2250+
}
22442251
}
22452252
#[cfg(fuzzing)]
22462253
pub use self::fuzzy_internal_msgs::*;
@@ -2349,13 +2356,6 @@ impl Debug for TrampolineOnionPacket {
23492356
}
23502357
}
23512358

2352-
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
2353-
pub struct OnionErrorPacket {
2354-
// This really should be a constant size slice, but the spec lets these things be up to 128KB?
2355-
// (TODO) We limit it in decode to much lower...
2356-
pub data: Vec<u8>,
2357-
}
2358-
23592359
impl From<UpdateFailHTLC> for OnionErrorPacket {
23602360
fn from(msg: UpdateFailHTLC) -> Self {
23612361
OnionErrorPacket {

lightning/src/ln/onion_utils.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -926,16 +926,24 @@ pub(super) fn build_failure_packet(
926926
onion_error_packet
927927
}
928928

929-
pub struct DecodedOnionFailure {
930-
pub(crate) network_update: Option<NetworkUpdate>,
931-
pub(crate) short_channel_id: Option<u64>,
932-
pub(crate) payment_failed_permanently: bool,
933-
pub(crate) failed_within_blinded_path: bool,
934-
#[cfg(any(test, feature = "_test_utils"))]
935-
pub(crate) onion_error_code: Option<u16>,
936-
#[cfg(any(test, feature = "_test_utils"))]
937-
pub(crate) onion_error_data: Option<Vec<u8>>,
929+
mod fuzzy_onion_utils {
930+
use super::*;
931+
932+
pub struct DecodedOnionFailure {
933+
pub(crate) network_update: Option<NetworkUpdate>,
934+
pub(crate) short_channel_id: Option<u64>,
935+
pub(crate) payment_failed_permanently: bool,
936+
pub(crate) failed_within_blinded_path: bool,
937+
#[cfg(any(test, feature = "_test_utils"))]
938+
pub(crate) onion_error_code: Option<u16>,
939+
#[cfg(any(test, feature = "_test_utils"))]
940+
pub(crate) onion_error_data: Option<Vec<u8>>,
941+
}
938942
}
943+
#[cfg(fuzzing)]
944+
pub use self::fuzzy_onion_utils::*;
945+
#[cfg(not(fuzzing))]
946+
pub(crate) use self::fuzzy_onion_utils::*;
939947

940948
pub fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
941949
secp_ctx: &Secp256k1<T>, logger: &L, htlc_source: &HTLCSource,

0 commit comments

Comments
 (0)