Skip to content

Commit 8192204

Browse files
committed
wip
1 parent 358a5f3 commit 8192204

13 files changed

+194
-10
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
������������������������������������������������������������������������������������������������������������������������������j�
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
����������������������#��������������������������������������������������������������������������������������j�
Binary file not shown.
Binary file not shown.
Binary file not shown.

fuzz/src/process_onion_failure.rs

Lines changed: 122 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,129 @@
1-
// Imports that need to be added manually
2-
use lightning_rapid_gossip_sync::RapidGossipSync;
1+
use std::sync::Arc;
2+
3+
use bitcoin::{key::Secp256k1, secp256k1::{PublicKey, SecretKey}};
4+
use lightning::{blinded_path::BlindedHop, ln::{channelmanager::{HTLCSource, PaymentId}, msgs::OnionErrorPacket}, routing::router::{BlindedTail, Path, RouteHop, TrampolineHop}, types::features::{ChannelFeatures, Features, NodeFeatures}, util::test_utils::TestLogger};
35

4-
use crate::utils::test_logger;
6+
// Imports that need to be added manually
7+
use crate::{utils::test_logger::{self}};
58

69
/// Actual fuzz test, method signature and name are fixed
710
fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
8-
println!("data -> {:?}", data);
11+
let mut read_pos = 0;
12+
macro_rules! get_slice {
13+
($len: expr) => {{
14+
let slice_len = $len as usize;
15+
if data.len() < read_pos + slice_len {
16+
return;
17+
}
18+
read_pos += slice_len;
19+
&data[read_pos - slice_len..read_pos]
20+
}};
21+
}
22+
23+
let secp_ctx = Secp256k1::new();
24+
let logger: Arc<TestLogger> = Arc::new(TestLogger::new());
25+
26+
let first_hop_htlc_msat_bytes = match get_slice!(8).try_into() {
27+
Ok(val) => val,
28+
Err(_) => return,
29+
};
30+
31+
let session_priv = match SecretKey::from_slice(get_slice!(32)) {
32+
Ok(val) => val,
33+
Err(_) => return,
34+
};
35+
36+
let payment_id = match get_slice!(32).try_into() {
37+
Ok(val) => PaymentId(val),
38+
Err(_) => return,
39+
};
40+
41+
macro_rules! get_pubkey {
42+
() => {
43+
match PublicKey::from_slice(get_slice!(32)) {
44+
Ok(val) => val,
45+
Err(_) => return,
46+
}
47+
};
48+
}
49+
50+
let path = Path {
51+
hops: vec![
52+
// Bob
53+
RouteHop {
54+
pubkey: get_pubkey!(),
55+
node_features: NodeFeatures::empty(),
56+
short_channel_id: 0,
57+
channel_features: ChannelFeatures::empty(),
58+
fee_msat: 3_000,
59+
cltv_expiry_delta: 24,
60+
maybe_announced_channel: false,
61+
},
62+
63+
// Carol
64+
RouteHop {
65+
pubkey: get_pubkey!(),
66+
node_features: NodeFeatures::empty(),
67+
short_channel_id: (572330 << 40) + (42 << 16) + 2821,
68+
channel_features: ChannelFeatures::empty(),
69+
fee_msat: 153_000,
70+
cltv_expiry_delta: 0,
71+
maybe_announced_channel: false,
72+
},
73+
],
74+
blinded_tail: Some(BlindedTail {
75+
trampoline_hops: vec![
76+
// Carol's pubkey
77+
TrampolineHop {
78+
pubkey: get_pubkey!(),
79+
node_features: Features::empty(),
80+
fee_msat: 2_500,
81+
cltv_expiry_delta: 24,
82+
},
83+
84+
// Dave's pubkey
85+
TrampolineHop {
86+
pubkey: get_pubkey!(),
87+
node_features: Features::empty(),
88+
fee_msat: 2_500,
89+
cltv_expiry_delta: 24,
90+
},
91+
92+
// Emily's pubkey
93+
TrampolineHop {
94+
pubkey: get_pubkey!(),
95+
node_features: Features::empty(),
96+
fee_msat: 150_500,
97+
cltv_expiry_delta: 36,
98+
},
99+
],
100+
101+
// Dummy blinded hop (because LDK doesn't allow unblinded Trampoline receives)
102+
hops: vec![
103+
// Emily's dummy blinded node id
104+
BlindedHop {
105+
blinded_node_id: get_pubkey!(),
106+
encrypted_payload: vec![],
107+
}
108+
],
109+
blinding_point: get_pubkey!(),
110+
excess_final_cltv_expiry_delta: 0,
111+
final_value_msat: 150_000_000,
112+
})};
113+
114+
let htlc_source = HTLCSource::OutboundRoute {
115+
path,
116+
session_priv,
117+
first_hop_htlc_msat: u64::from_be_bytes(first_hop_htlc_msat_bytes),
118+
payment_id,
119+
};
120+
121+
let failure_len = u16::from_be_bytes(get_slice!(2).try_into().unwrap());
122+
let encrypted_packet = OnionErrorPacket { data:
123+
get_slice!(failure_len as u64).into(),
124+
};
125+
126+
lightning::ln::onion_utils::process_onion_failure(&secp_ctx, &logger, &htlc_source, encrypted_packet);
9127
}
10128

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

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ impl_writeable_tlv_based_enum!(SentHTLCId,
678678
/// Tracks the inbound corresponding to an outbound HTLC
679679
#[allow(clippy::derive_hash_xor_eq)] // Our Hash is faithful to the data, we just don't have SecretKey::hash
680680
#[derive(Clone, Debug, PartialEq, Eq)]
681-
pub(crate) enum HTLCSource {
681+
pub enum HTLCSource {
682682
PreviousHopData(HTLCPreviousHopData),
683683
OutboundRoute {
684684
path: Path,

0 commit comments

Comments
 (0)