Skip to content

Commit a35b92c

Browse files
Fuzz test blinded payment pathfinding
1 parent 9bf4b6e commit a35b92c

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

fuzz/src/router.rs

+44-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ use bitcoin::blockdata::script::Builder;
1111
use bitcoin::blockdata::transaction::TxOut;
1212
use bitcoin::hash_types::BlockHash;
1313

14+
use lightning::blinded_path::{BlindedHop, BlindedPath};
1415
use lightning::chain::transaction::OutPoint;
1516
use lightning::ln::channelmanager::{self, ChannelDetails, ChannelCounterparty};
17+
use lightning::ln::features::{BlindedHopFeatures, Bolt12InvoiceFeatures};
1618
use lightning::ln::msgs;
19+
use lightning::offers::invoice::BlindedPayInfo;
1720
use lightning::routing::gossip::{NetworkGraph, RoutingFees};
1821
use lightning::routing::utxo::{UtxoFuture, UtxoLookup, UtxoLookupError, UtxoResult};
1922
use lightning::routing::router::{find_route, PaymentParameters, RouteHint, RouteHintHop, RouteParameters};
@@ -315,7 +318,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
315318
net_graph.channel_failed_permanent(short_channel_id);
316319
},
317320
_ if node_pks.is_empty() => {},
318-
_ => {
321+
x if x < 250 => {
319322
let mut first_hops_vec = Vec::new();
320323
// Use macros here and in the blinded match arm to ensure values are fetched from the fuzz
321324
// input in the same order, for better coverage.
@@ -330,6 +333,46 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
330333
}
331334
});
332335
},
336+
x => {
337+
let mut first_hops_vec = Vec::new();
338+
let first_hops = first_hops!(first_hops_vec);
339+
let mut last_hops_unblinded = Vec::new();
340+
last_hops!(last_hops_unblinded);
341+
let dummy_pk = PublicKey::from_slice(&[2; 33]).unwrap();
342+
let last_hops: Vec<(BlindedPayInfo, BlindedPath)> = last_hops_unblinded.into_iter().map(|hint| {
343+
let hop = &hint.0[0];
344+
let payinfo = BlindedPayInfo {
345+
fee_base_msat: hop.fees.base_msat,
346+
fee_proportional_millionths: hop.fees.proportional_millionths,
347+
htlc_minimum_msat: hop.htlc_minimum_msat.unwrap(),
348+
htlc_maximum_msat: hop.htlc_minimum_msat.unwrap().saturating_mul(100),
349+
cltv_expiry_delta: hop.cltv_expiry_delta,
350+
features: BlindedHopFeatures::empty(),
351+
};
352+
let num_blinded_hops = x % 250;
353+
let mut blinded_hops = Vec::new();
354+
for _ in 0..num_blinded_hops {
355+
blinded_hops.push(BlindedHop {
356+
blinded_node_id: dummy_pk,
357+
encrypted_payload: Vec::new()
358+
});
359+
}
360+
(payinfo, BlindedPath {
361+
introduction_node_id: hop.src_node_id,
362+
blinding_point: dummy_pk,
363+
blinded_hops,
364+
})
365+
}).collect();
366+
let mut features = Bolt12InvoiceFeatures::empty();
367+
features.set_basic_mpp_optional();
368+
find_routes!(first_hops, vec![dummy_pk].iter(), |final_amt, _, _| {
369+
RouteParameters {
370+
payment_params: PaymentParameters::blinded(last_hops.clone())
371+
.with_bolt12_features(features.clone()).unwrap(),
372+
final_value_msat: final_amt,
373+
}
374+
});
375+
}
333376
}
334377
}
335378
}

lightning/src/blinded_path/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,26 @@ pub struct BlindedPath {
3636
/// message or payment's next hop and forward it along.
3737
///
3838
/// [`encrypted_payload`]: BlindedHop::encrypted_payload
39-
pub(crate) introduction_node_id: PublicKey,
39+
pub introduction_node_id: PublicKey,
4040
/// Used by the introduction node to decrypt its [`encrypted_payload`] to forward the onion
4141
/// message or payment.
4242
///
4343
/// [`encrypted_payload`]: BlindedHop::encrypted_payload
44-
pub(crate) blinding_point: PublicKey,
44+
pub blinding_point: PublicKey,
4545
/// The hops composing the blinded path.
46-
pub(crate) blinded_hops: Vec<BlindedHop>,
46+
pub blinded_hops: Vec<BlindedHop>,
4747
}
4848

4949
/// Used to construct the blinded hops portion of a blinded path. These hops cannot be identified
5050
/// by outside observers and thus can be used to hide the identity of the recipient.
5151
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
5252
pub struct BlindedHop {
5353
/// The blinded node id of this hop in a blinded path.
54-
pub(crate) blinded_node_id: PublicKey,
54+
pub blinded_node_id: PublicKey,
5555
/// The encrypted payload intended for this hop in a blinded path.
5656
// The node sending to this blinded path will later encode this payload into the onion packet for
5757
// this hop.
58-
pub(crate) encrypted_payload: Vec<u8>,
58+
pub encrypted_payload: Vec<u8>,
5959
}
6060

6161
impl BlindedPath {

lightning/src/routing/router.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,8 @@ impl PaymentParameters {
656656
.with_expiry_time(invoice.created_at().as_secs().saturating_add(invoice.relative_expiry().as_secs()))
657657
}
658658

659-
fn blinded(blinded_route_hints: Vec<(BlindedPayInfo, BlindedPath)>) -> Self {
659+
/// Creates parameters for paying to a blinded payee from the provided blinded route hints.
660+
pub fn blinded(blinded_route_hints: Vec<(BlindedPayInfo, BlindedPath)>) -> Self {
660661
Self {
661662
payee: Payee::Blinded { route_hints: blinded_route_hints, features: None },
662663
expiry_time: None,

0 commit comments

Comments
 (0)