Skip to content

Commit dc8479a

Browse files
authored
Merge pull request #1454 from TheBlueMatt/2022-04-fuzz-underflow
Reject channels if the total reserves are larger than the funding
2 parents f53d13b + 92c87ba commit dc8479a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lightning/src/ln/channel.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1103,14 +1103,13 @@ impl<Signer: Sign> Channel<Signer> {
11031103
if msg.channel_reserve_satoshis > msg.funding_satoshis {
11041104
return Err(ChannelError::Close(format!("Bogus channel_reserve_satoshis ({}). Must be not greater than funding_satoshis: {}", msg.channel_reserve_satoshis, msg.funding_satoshis)));
11051105
}
1106-
let funding_value = (msg.funding_satoshis - msg.channel_reserve_satoshis) * 1000;
1107-
if msg.push_msat > funding_value {
1108-
return Err(ChannelError::Close(format!("push_msat {} was larger than funding value {}", msg.push_msat, funding_value)));
1106+
let full_channel_value_msat = (msg.funding_satoshis - msg.channel_reserve_satoshis) * 1000;
1107+
if msg.push_msat > full_channel_value_msat {
1108+
return Err(ChannelError::Close(format!("push_msat {} was larger than channel amount minus reserve ({})", msg.push_msat, full_channel_value_msat)));
11091109
}
11101110
if msg.dust_limit_satoshis > msg.funding_satoshis {
11111111
return Err(ChannelError::Close(format!("dust_limit_satoshis {} was larger than funding_satoshis {}. Peer never wants payout outputs?", msg.dust_limit_satoshis, msg.funding_satoshis)));
11121112
}
1113-
let full_channel_value_msat = (msg.funding_satoshis - msg.channel_reserve_satoshis) * 1000;
11141113
if msg.htlc_minimum_msat >= full_channel_value_msat {
11151114
return Err(ChannelError::Close(format!("Minimum htlc value ({}) was larger than full channel value ({})", msg.htlc_minimum_msat, full_channel_value_msat)));
11161115
}
@@ -1164,6 +1163,9 @@ impl<Signer: Sign> Channel<Signer> {
11641163
if holder_selected_channel_reserve_satoshis < MIN_CHAN_DUST_LIMIT_SATOSHIS {
11651164
return Err(ChannelError::Close(format!("Suitable channel reserve not found. remote_channel_reserve was ({}). dust_limit_satoshis is ({}).", holder_selected_channel_reserve_satoshis, MIN_CHAN_DUST_LIMIT_SATOSHIS)));
11661165
}
1166+
if holder_selected_channel_reserve_satoshis * 1000 >= full_channel_value_msat {
1167+
return Err(ChannelError::Close(format!("Suitable channel reserve not found. remote_channel_reserve was ({}). Channel value is ({} - {}).", holder_selected_channel_reserve_satoshis, full_channel_value_msat, msg.push_msat)));
1168+
}
11671169
if msg.channel_reserve_satoshis < MIN_CHAN_DUST_LIMIT_SATOSHIS {
11681170
log_debug!(logger, "channel_reserve_satoshis ({}) is smaller than our dust limit ({}). We can broadcast stale states without any risk, implying this channel is very insecure for our counterparty.",
11691171
msg.channel_reserve_satoshis, MIN_CHAN_DUST_LIMIT_SATOSHIS);

lightning/src/ln/functional_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn test_insane_channel_opens() {
103103

104104
insane_open_helper("Bogus channel_reserve_satoshis", |mut msg| { msg.channel_reserve_satoshis = msg.funding_satoshis + 1; msg });
105105

106-
insane_open_helper(r"push_msat \d+ was larger than funding value \d+", |mut msg| { msg.push_msat = (msg.funding_satoshis - msg.channel_reserve_satoshis) * 1000 + 1; msg });
106+
insane_open_helper(r"push_msat \d+ was larger than channel amount minus reserve \(\d+\)", |mut msg| { msg.push_msat = (msg.funding_satoshis - msg.channel_reserve_satoshis) * 1000 + 1; msg });
107107

108108
insane_open_helper("Peer never wants payout outputs?", |mut msg| { msg.dust_limit_satoshis = msg.funding_satoshis + 1 ; msg });
109109

0 commit comments

Comments
 (0)