Skip to content

Check Bolt 2 spec #240

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

Closed
11 of 26 tasks
SWvheerden opened this issue Nov 1, 2018 · 13 comments
Closed
11 of 26 tasks

Check Bolt 2 spec #240

SWvheerden opened this issue Nov 1, 2018 · 13 comments

Comments

@SWvheerden
Copy link
Contributor

SWvheerden commented Nov 1, 2018

  • Open_channel Message
  • Accept_channel Message
  • Funding_created Message
  • Funding_signed Message
  • Funding_locked Message
  • Closing Initiation: shutdown
  • Closing Negotiation: closing_signed
  • Adding an HTLC: update_add_htlc
  • Removing an HTLC: update_fulfill_htlc, update_fail_htlc, and update_fail_malformed_htlc
  • Committing Updates So Far: commitment_signed
  • Completing the Transition to the Updated State: revoke_and_ack
  • Updating Fees: update_fee
  • Message Retransmission

Audited

  • Open_channel Message
  • Accept_channel Message
  • Funding_created Message
  • Funding_signed Message
  • Funding_locked Message
  • Closing Initiation: shutdown
  • Closing Negotiation: closing_signed
  • Adding an HTLC: update_add_htlc
  • Removing an HTLC: update_fulfill_htlc, update_fail_htlc, and update_fail_malformed_htlc
  • Committing Updates So Far: commitment_signed
  • Completing the Transition to the Updated State: revoke_and_ack
  • Updating Fees: update_fee
  • Message Retransmission
@SWvheerden
Copy link
Contributor Author

#129

@TheBlueMatt TheBlueMatt added this to the 0.1 milestone Nov 1, 2018
@SWvheerden
Copy link
Contributor Author

Bolt 2 spec says this on open channel:
if the connection has been re-established after receiving a previous open_channel, BUT before receiving a funding_created message:
- accept a new open_channel message.
- discard the previous open_channel message.

Currently we store and accept channel message's on channel_id's and not on node_id's
This mean we conform to spec, but it also allows as to have more than one channel per node?
https://github.com/rust-bitcoin/rust-lightning/blob/d9d8ea3f65500c59e06f7f291c034d35bb08b502/src/ln/channelmanager.rs#L1692

@TheBlueMatt
Copy link
Collaborator

The spec is kinda inconsistent - originally it was written assuming one-channel-per-node but that was thrown out, so looks like a spec bug to me, but we do comply with that text as we'll drop the channel on disconnection if we never received the funding_created.

@SWvheerden SWvheerden changed the title Check Bolt 2 spec error conditions Check Bolt 2 spec Nov 1, 2018
@TheBlueMatt
Copy link
Collaborator

Unchecked funding_signed - it still has some HandleError::action: None's in there. I've got a pending patchset to finish it off, though. Also as things get marked completed we should move from HandleError directly to ChannelError.

@SWvheerden
Copy link
Contributor Author

Update fee is missing spec
#231

@SWvheerden
Copy link
Contributor Author

SWvheerden commented Nov 6, 2018

message retransmission is missing
#238

@TheBlueMatt
Copy link
Collaborator

TheBlueMatt commented Nov 6, 2018 via email

@SWvheerden
Copy link
Contributor Author

Pretty much all the message retransmission should work, though isn't sufficiently tested at this point.

On November 6, 2018 9:35:08 AM UTC, SW van Heerden @.***> wrote: message retransmission is missing #239 and #238 -- You are receiving this because you commented. Reply to this email directly or view it on GitHub: #240 (comment)

It looks fine, thats why I ticket it off. Those two are optional, although they are good ideas

@SWvheerden
Copy link
Contributor Author

SWvheerden commented Nov 6, 2018

Removing an HTLC: update_fulfill_htlc, update_fail_htlc, and update_fail_malformed_htlc
Is missing: #215
#244

@neonknight64
Copy link

neonknight64 commented Nov 15, 2018

Audit of Bolt 2 spec for Closing Negotiation - closing_signed

  • Message structure correct - ClosingSigned
  • Check shutdown is complete before fee negotiation
  • Check channel is empty of HTLCs before fee negotiation
  • Funding node should send closing_signed message after receiving shutdown and no HTLCs remain
  • Sending node must set fee less than or equal to the base fee of the final commitment transaction
  • Sending node should set initial fee according to its estimate of cost of inclusion in a block
  • Sending node must set signature to the signature of the close transaction
  • Receiving node must fail connection when signature of close transactions invalid
  • Receiving node should broadcast final closing transaction when current and previous fee are the same
  • Receiving node must fail connection when fee is greater than the base fee of the final commitment transaction
    Comment: Implemented check with error but not failing connection
  • Receiving node should fail connection when fee not between previous sent and received fee, except when reconnected
    Comment: Implemented check with error but not failing connection
  • Receiving node should send closing_signed with same fee when agreement is reached
  • Receiving node can propose new fee between previous received and sent fee

@TheBlueMatt
Copy link
Collaborator

TheBlueMatt commented Nov 15, 2018

Note that the closing_signed dropped-output stuff is pretty clearly broken, and we currently incorrectly fail channels when the remote node sends commitment_signeds with HTLC removes after shutdown messages. I saw a number of other bugs I dont recall anymore when looking at it last week but as noted in #250 I kinda gave up until that part of the spec gets rewritten. WIthout good test coverage of individual things I dont think we can consider anything properly "audited".

@philipr-za
Copy link
Contributor

Tests have been written for the requirements for update_add_htlc message and was merged in as #291 / #296

@TheBlueMatt
Copy link
Collaborator

Closing as completed - most of the messages were audited as a part of this (thanks folks!) and the remaining ones have had plenty of eyeballs on them since (plus we'll be rewriting update_fee soon for update_fee v3 anyway!).

@github-project-automation github-project-automation bot moved this from In Progress to Done in LDK Roadmap May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

4 participants