Skip to content

BOLT2: Check we don't send and accept 0-msat HTLC #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 11, 2020

Conversation

ariard
Copy link

@ariard ariard commented Feb 21, 2020

Failing this requirement at sending means a strict receiver would
fail our channel while processing at HTLC routed from a third-party.

Fix by enforcing check on both sender and receiver side.

BOLT2:

A sending node MUST offer amount_msat greater than 0.

A receiving node receiving an amount_msat equal to 0, OR less than its own htlc_minimum_msat SHOULD fail the channel.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for tackling this. Should pass travis if you rebase on master with #514.

@@ -1597,6 +1597,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
if msg.amount_msat > self.channel_value_satoshis * 1000 {
return Err(ChannelError::Close("Remote side tried to send more than the total value of the channel"));
}
if msg.amount_msat == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to test this line as well. Another way to do it that would be easier to test would be to just set our_htlc_minimum_msat to at least 1 always.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a commit for this, without modifying default config

@codecov
Copy link

codecov bot commented Feb 26, 2020

Codecov Report

Merging #513 into master will increase coverage by 0.16%.
The diff coverage is 98.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #513      +/-   ##
==========================================
+ Coverage   90.07%   90.24%   +0.16%     
==========================================
  Files          34       34              
  Lines       19053    19197     +144     
==========================================
+ Hits        17162    17324     +162     
+ Misses       1891     1873      -18     
Impacted Files Coverage Δ
lightning/src/ln/functional_tests.rs 96.35% <97.87%> (+0.05%) ⬆️
lightning/src/ln/channel.rs 86.95% <100.00%> (+0.04%) ⬆️
lightning/src/ln/functional_test_utils.rs 94.59% <100.00%> (+<0.01%) ⬆️
lightning/src/util/config.rs 69.04% <100.00%> (+0.75%) ⬆️
lightning/src/ln/features.rs 96.87% <0.00%> (+0.25%) ⬆️
lightning/src/ln/msgs.rs 89.72% <0.00%> (+1.61%) ⬆️
lightning/src/ln/wire.rs 65.85% <0.00%> (+11.30%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 83c9eb4...dd9c476. Read the comment docs.

@ariard ariard force-pushed the 2020-02-fix-zero-msat-htlc branch from b1cd4fc to 91a9321 Compare February 26, 2020 21:06
@ariard
Copy link
Author

ariard commented Feb 26, 2020

Rebased 91a9321

@TheBlueMatt
Copy link
Collaborator

Looks like this needs a further rebase on top of #509.

@ariard ariard force-pushed the 2020-02-fix-zero-msat-htlc branch from 91a9321 to 3d6b2d9 Compare February 28, 2020 17:02
@ariard
Copy link
Author

ariard commented Feb 28, 2020

Rebased 3d6b2d9

@@ -1652,6 +1652,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
if msg.amount_msat > self.channel_value_satoshis * 1000 {
return Err(ChannelError::Close("Remote side tried to send more than the total value of the channel"));
}
if msg.amount_msat == 0 {
return Err(ChannelError::Ignore("Remote side tried to send a 0-msat HTLC"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think this is right? We should either ::Close() or we should add the HTLC and fail it backwards as soon as they commit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You right, should fail the channel IIRC the spec, will update

@ariard ariard force-pushed the 2020-02-fix-zero-msat-htlc branch from 3d6b2d9 to cf2918f Compare March 3, 2020 20:04
@ariard
Copy link
Author

ariard commented Mar 3, 2020

Updated at cf2918f with rebase errors fixed, ::Ignore() switched for a ::Close() and receiver-test updated to check for channel closing.

@TheBlueMatt
Copy link
Collaborator

I believe this needs further updates (and a rebase onto master to make travis pass).

Antoine Riard added 2 commits March 10, 2020 13:05
Failing this requirement at sending means a strict receiver would
fail our channel while processing a HTLC routed from a third-party.

Fix by enforcing check on both sender and receiver side.
@ariard ariard force-pushed the 2020-02-fix-zero-msat-htlc branch from cf2918f to 16edc6d Compare March 10, 2020 17:21
@ariard
Copy link
Author

ariard commented Mar 10, 2020

Rebased 16edc6d

@TheBlueMatt
Copy link
Collaborator

Doesn't build.

@ariard ariard force-pushed the 2020-02-fix-zero-msat-htlc branch from 16edc6d to 43d7ceb Compare March 10, 2020 20:42
@TheBlueMatt
Copy link
Collaborator

As discussed, we should never be sending an htlc_minimum_msat of < 1 to any of our peers, so this needs an update to check for that.

@ariard ariard force-pushed the 2020-02-fix-zero-msat-htlc branch from 43d7ceb to fe5200d Compare March 10, 2020 23:31
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One doc change suggestion but looks good.

Comment on lines 56 to 57
/// Announced in `open_channel`/`accept_channel` according if it's an inbound/outbound
/// channel. Enforced at `update_add_htlc` reception with other HTLC sanitization checks.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Announced in `open_channel`/`accept_channel` according if it's an inbound/outbound
/// channel. Enforced at `update_add_htlc` reception with other HTLC sanitization checks.
/// This value is sent to our counterparty on channel-open and we close the channel any time
/// our counterparty misbehaves by sending us an HTLC with a value smaller than this.
///
/// If the value is less than 1, it is ignored and set to 1, as is required by the protocol.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, took your suggestion

Antoine Riard added 2 commits March 11, 2020 14:28
Enforce a minimum htlc_minimum_msat of 1.

Instead of computing dynamically htlc_minimum_msat based on feerate,
relies on user-provided configuration value. This let user compute
an economical-driven channel parameter according to network dynamics.
@ariard ariard force-pushed the 2020-02-fix-zero-msat-htlc branch from fe5200d to dd9c476 Compare March 11, 2020 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants