Skip to content

Commit 846cd6b

Browse files
committed
Add anti-probing penalty to ProbabilisticScorer
Currently, channel balances may be rather easily discovered through probing. This however poses a privacy risk, since the analysis of balance changes over adjacent channels could in the worst case empower an adversary to mount an end-to-end deanonymization attack, i.e., track who payed whom. The penalty added here is applied so we prefer nodes with a smaller `htlc_maximum_msat`, which makes balance discovery attacks harder to execute. As this improves privacy network-wide, we treat such nodes preferentially and hence create an incentive to restrict `htlc_maximum_msat`.
1 parent 16115cd commit 846cd6b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lightning/src/routing/scoring.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,19 @@ pub struct ProbabilisticScoringParameters {
361361
///
362362
/// Default value: 256 msat
363363
pub amount_penalty_multiplier_msat: u64,
364+
365+
/// A multiplier that is used in conjunction with the negative `log10` of the ratio of
366+
/// `htlc_maximum_msat` to channel capacity in order to calculate an anti-probing penalty:
367+
///
368+
/// `-log10(htlc_maximum_msat/capacity) * anti_probing_penalty_multiplier_msat`
369+
///
370+
/// This penalty is applied so we prefer nodes with a smaller `htlc_maximum_msat`, which makes
371+
/// balance discovery attacks harder to execute. As this improves privacy network-wide, we
372+
/// treat such nodes preferentially and hence create an incentive to restrict
373+
/// `htlc_maximum_msat`.
374+
///
375+
/// Default value: 10000 msat
376+
pub anti_probing_penalty_multiplier_msat: u64,
364377
}
365378

366379
/// Accounting for channel liquidity balance uncertainty.
@@ -461,6 +474,7 @@ impl ProbabilisticScoringParameters {
461474
liquidity_penalty_multiplier_msat: 0,
462475
liquidity_offset_half_life: Duration::from_secs(3600),
463476
amount_penalty_multiplier_msat: 0,
477+
anti_probing_penalty_multiplier_msat: 0,
464478
}
465479
}
466480
}
@@ -472,6 +486,7 @@ impl Default for ProbabilisticScoringParameters {
472486
liquidity_penalty_multiplier_msat: 40_000,
473487
liquidity_offset_half_life: Duration::from_secs(3600),
474488
amount_penalty_multiplier_msat: 256,
489+
anti_probing_penalty_multiplier_msat: 10_000,
475490
}
476491
}
477492
}
@@ -672,11 +687,24 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
672687
fn channel_penalty_msat(
673688
&self, short_channel_id: u64, source: &NodeId, target: &NodeId, usage: ChannelUsage
674689
) -> u64 {
690+
691+
let network_graph = self.network_graph.read_only();
692+
let mut anti_probing_penalty_msat = 0;
693+
if let Some(chan) = network_graph.channels().get(&short_channel_id) {
694+
if let Some((directed_info, _source)) = chan.as_directed_to(target) {
695+
if let Some(capacity_msat) = chan.capacity_sats.map(|capacity_sats| capacity_sats * 1000) {
696+
let htlc_maximum_msat = directed_info.htlc_maximum_msat();
697+
let log_distance_ratio = approx::negative_log10_times_2048(capacity_msat-htlc_maximum_msat, capacity_msat);
698+
anti_probing_penalty_msat = self.params.anti_probing_penalty_multiplier_msat * log_distance_ratio / 2048;
699+
}
700+
}
701+
}
702+
675703
if let EffectiveCapacity::ExactLiquidity { liquidity_msat } = usage.effective_capacity {
676704
if usage.amount_msat > liquidity_msat {
677705
return u64::max_value();
678706
} else {
679-
return self.params.base_penalty_msat;
707+
return self.params.base_penalty_msat.saturating_add(anti_probing_penalty_msat);
680708
};
681709
}
682710

@@ -689,6 +717,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> Score for Probabilis
689717
.unwrap_or(&ChannelLiquidity::new())
690718
.as_directed(source, target, capacity_msat, liquidity_offset_half_life)
691719
.penalty_msat(amount_msat, self.params)
720+
.saturating_add(anti_probing_penalty_msat)
692721
}
693722

694723
fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) {

0 commit comments

Comments
 (0)