1
0
Fork 0
mirror of https://github.com/lightning/bolts.git synced 2025-03-13 19:37:31 +01:00
Commit graph

1106 commits

Author SHA1 Message Date
Rusty Russell
a09564a8b7 tools/extract-formats: suppress modern Python warnings.
It complains about escapes unless we tell it it's a regex:

```
/home/rusty/devel/cvs/bolts/./tools/extract-formats.py:27: SyntaxWarning: invalid escape sequence '\.'
  '(1\.|\*) type: (?P<value>[-0-9A-Za-z_|]+) \(`(?P<name>[A-Za-z0-9_]+)`\)( \(`?(?P<option>[^)`]*)`\))?')
/home/rusty/devel/cvs/bolts/./tools/extract-formats.py:29: SyntaxWarning: invalid escape sequence '\.'
  '(1\.|\*) `tlv_stream`: `(?P<name>[A-Za-z0-9_]+)`')
/home/rusty/devel/cvs/bolts/./tools/extract-formats.py:31: SyntaxWarning: invalid escape sequence '\.'
  '(1\.|\*) subtype: `(?P<name>[A-Za-z0-9_]+)`')
/home/rusty/devel/cvs/bolts/./tools/extract-formats.py:33: SyntaxWarning: invalid escape sequence '\s'
  '\s+([0-9]+\.|\*) \[`(?P<typefield>[-._a-zA-Z0-9*+]+)`:`(?P<name>[_a-z0-9]+)`\]')
/home/rusty/devel/cvs/bolts/./tools/extract-formats.py:35: SyntaxWarning: invalid escape sequence '\.'
  '(2\.|\*) data:')
/home/rusty/devel/cvs/bolts/./tools/extract-formats.py:37: SyntaxWarning: invalid escape sequence '\.'
  '(2\.|\*) types:')
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-03-05 17:56:33 +01:00
Rusty Russell
79101063c3 BOLT 1: typo fix in definition.
Extra space after : breaks extract-formats.py.  Here's the before/after:

```
 msgdata,pong,byteslen,u16,
 msgdata,pong,ignored,byte,byteslen
 msgtype,peer_storage,7
+msgdata,peer_storage,length,u16,
+msgdata,peer_storage,blob,byte,length
 msgtype,peer_storage_retrieval,9
+msgdata,peer_storage_retrieval,length,u16,
+msgdata,peer_storage_retrieval,blob,byte,length
 tlvtype,n1,tlv1,1
 tlvdata,n1,tlv1,amount_msat,tu64,
 tlvtype,n1,tlv2,2
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-03-05 17:56:33 +01:00
t-bast
ccfa38ed4f Explicitly mention which output to set to 0 2025-02-12 09:46:08 +01:00
t-bast
90662b1323 Clarify a few requirements
As suggested by @yyforyongyu.
2025-02-12 09:46:08 +01:00
t-bast
7b635f0f2d Clarify OP_RETURN requirements
As suggested by @roasbeef.
2025-02-12 09:46:08 +01:00
t-bast
7eff1485a5 Simplify state machine by removing shutdown exchange
As pointed out by @TheBlueMatt, we can greatly simplify the protocol
by removing the `shutdown` exchange entirely. The only piece of data
nodes must remember is the last script their peer sent. This can be
found in the last received `closing_complete`, or in `shutdown` if
`closing_complete` was never received. This doesn't even need to be
persisted, because on reconnection nodes will exchange `shutdown`
again with the last script they want to use for their output.

By doing that, the protocol becomes a trivial request/response protocol
where nodes send `closing_complete` and expect `closing_sig` back. This
creates a race condition when both nodes update their script at the same
time, but this will be extremely rare so we can simply resolve it by
reconnecting.

This protocol is compatible with taproot channels, with the following
additions:

- when sending `shutdown`, nodes will include two random nonces:
  - `closer_nonce` that will be used in their `closing_complete`
  - `closee_nonce` that will be used in their `closing_sig`
- when sending `closing_complete`, nodes will include a new random nonce
  for their next `closing_complete` (`next_closer_nonce`)
- when sending `closing_sig`, nodes will include a new random nonce for
  their next `closing_sig` (`next_closee_nonce`)

This ensures that nodes always have a pair of random nonces for their
next signing round.
2025-02-12 09:46:08 +01:00
t-bast
7f8520079e Fix @tnull's comments
Clarify strict `shutdown` exchange requirements and fix typos.
2025-02-12 09:46:08 +01:00
t-bast
37fa862a82 Add strict shutdown exchange for taproot channels
It was previously unclear whether a node could send `shutdown` and
`closing_complete` immediately after that whenever RBF-ing their
previous closing transaction. While this worked for non-taproot
channels, it doesn't allow a clean exchange of fresh musig2 nonces
for taproot channels. We now require that whenever a node wants to
start a new signing round, `shutdown` must be sent *and* received
before sending `closing_complete`.
2025-02-12 09:46:08 +01:00
t-bast
8efb63eb61 Address pending PR comments
- add more detailed protocol flow diagram
- rename sigs TLVs as suggested by @morehouse
- mention `upfront_shutdown_script` as suggested by @Crypt-iQ
- fix typos
- reformat
2025-02-12 09:46:08 +01:00
t-bast
039f8ce99a Allow setting nLockTime, not nSequence
We always set `nSequence` to `0xFFFFFFFD`, but each node can choose the
`nLockTime` they want to use for the transactions for which they are
paying the fees.
2025-02-12 09:46:08 +01:00
t-bast
3d9f0b8fad Set output amount to 0 when using OP_RETURN
Bitcoin Core version 25+ will not broadcast transactions containing
`OP_RETURN` outputs if their amount is greater than 0, because this
amount would then be unspendable. We thus require that the output
amount is set to 0 when using `OP_RETURN`.
2025-02-12 09:46:08 +01:00
Rusty Russell
9981a0a9f2 BOLT 2: specify nSequence explicitly.
We don't care, as long as it's RBF-able.  This will be nicer for
Taproot when mutual closes are otherwise indistinguishable from normal
spends.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-12 09:46:08 +01:00
Rusty Russell
e8eced6795 Feedback from Bastien
- Make it clear why the OP_RETURN restrictions have two forms.
- Cross-reference existing dust threshold
- Lots of typo fixes
- Don't set closer_and_closee if we're larger/equal, and closee is dust.
- Remove Rationale on delete zero-output tx hack.
2025-02-12 09:46:08 +01:00
Rusty Russell
b2ef4b48ea BOLT 2: allow standard OP_RETURN as an output type.
This gets around "but both our outputs are dust!" problems, as
recommended by Anthony Towns.

I hope I interpreted the standardness rules correctly (technically,
you can have multiple pushes in an OP_RETURN as long as the total is
under 83 bytes, but let's keep it simple).

Add an explicit note that "OP_RETURN" is never considered "uneconomic".

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-12 09:46:08 +01:00
Rusty Russell
8490ccc5d1 BOLT 2: Rewrite to use TLV, and only allow the lesser-amount to drop output.
If both are dust, you should lowball fees.  The next patch adds OP_RETURN
as a valid shutdown scriptpubkey though if you really want to do this.

This also addresses the case where people send a new `shutdown` with a *different* scriptpubkey.  This could previously cause a race where you receive a bad signature (because it hasn't received the updated shutdown), so we ignore these cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-12 09:46:08 +01:00
Rusty Russell
167a7354fb Require non-dust output for closer.
You have to give them something which will propagate.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-12 09:46:08 +01:00
Rusty Russell
a1ae46ddc3 BOLT 2: fix battling requirements for shutdown
The shutdown section says:

```
  - MUST NOT send multiple `shutdown` messages.
```

But the reconnection section says:

```
  - upon reconnection:
    - if it has sent a previous `shutdown`:
      - MUST retransmit `shutdown`.
```

So clearly, remove the former.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-12 09:46:08 +01:00
Rusty Russell
dc376ca241 BOLT 2, 3, 9: option_simple_close.
Pay your own fees, so the peer will sign without caring.  Even if it doesn't relay.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-02-12 09:46:08 +01:00
finaltrip
c3c628b79d
chore: fix typo in tools/bolt3-bitcoind-test.sh (#1226)
Signed-off-by: finaltrip <finaltrip@qq.com>
2025-02-11 18:16:41 -08:00
ghost43
d8f5b4a680
BOLT 4: (trivial) rm duplicate line (#1227)
- rm duplicate requirement (already mentioned 3 lines above)
- fix broken link
2025-02-11 17:21:14 +01:00
Bastien Teinturier
acd383145d
More clarifications around channel_announcement handling (#1220)
This is a follow-up of #1215, where we keep reworking the announcement
requirements.

We remove the rationale around deferring after `channel_ready` since
that has been changed years ago and shouldn't be an issue anymore.

We slightly rework the wording to minimize future conflicts with the
splicing PR.

While nodes are free to send `announcement_signatures` whenever they
feel that the channel is safe from reorg, we disallow broadcasting the
`channel_announcement` before at least 6 confirmations: this gives nodes
a simple heuristic to ignore `channel_announcement`s for remote channels
that aren't spec-compliant, without having to deal with the extra cost
of managing reorgs.
2025-02-11 09:37:13 +01:00
Mattia Careddu
e96c3c59bb
fix code typo in 04 onion routing (#1225) 2025-02-10 09:14:36 +01:00
Vincenzo Palazzo
6bbcf5f892
meta: update the link to the ML (#1170)
This commit is adding a link to the ML archive and redirecting
users to the delvingbitcoin forum instead of the obsolete ML.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
2025-02-07 16:53:44 +01:00
Elias Rohrer
5f31faa0b6
Add test vector for (invalid) mixed-case offer encoding (#1217)
The spec requires the bech32 offer encodings to be all upper- or
lowercase, but disallows mixed-case encodings.

Here, we add a test vector for this.
2025-02-04 15:31:46 +01:00
Rusty Russell
e92a7fae44 12: Rename the title line to be clearer.
Suggested-by: Roasbeef
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-01-28 06:39:32 +10:30
Vincenzo Palazzo
6feb3aa91e meta: indexing the bolt12
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2025-01-28 06:39:32 +10:30
Aditya Sharma
e2e99ce7a3 Peer storage for nodes to distribute small encrypted blobs. 2025-01-28 06:38:36 +10:30
Matt Corallo
ecf792d873
Merge pull request #1222 from rustyrussell/bip353-fixes
BOLT 12: fix BIP 353 spec typos
2025-01-24 02:40:08 +00:00
Rusty Russell
b13990b03c BOLT 12: fix BIP 353 spec.
It's inserted weirdly (splits a paragraph, so otherwise clause is wrong), and all invreq fields
are mirrored in the invoice.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-01-24 09:44:39 +10:30
Bastien Teinturier
8707471dbc
Remove explicit 6-blocks delay for announcements (#1215)
We previously required waiting for 6 confirmations before sending
`announcement_signatures`, but the real criteria is that it should only
be sent once you are confident that a reorg will not invalidate it.
2025-01-14 10:22:19 +01:00
t-bast
c41536829c Leftover renaming of path_key in blinded paths
We renamed `blinding` to `path_key` in #1181, but forgot to update the
description in test vectors and the proposal document.
2024-12-03 12:21:43 +10:30
Matt Corallo
29c6e47955
Merge pull request #1180 from TheBlueMatt/2024-07-bolt12-hrn
Include BIP 353 name info in `invoice_request`s
2024-12-02 19:27:47 +00:00
Matt Corallo
aa5207aeaa
Merge pull request #1207 from TheBlueMatt/2024-10-ugh
Add a generic Code of Conduct
2024-11-08 15:27:35 +00:00
Matt Corallo
bd8f45c3ce Add the folks who signed up as CoC members 2024-11-04 21:48:13 +00:00
Matt Corallo
f23f55c12b Add a generic Code of Conduct
No need to be too prescriptive, but examples are good. This is a
pretty generic Code of Conduct that just says if you disrupt
people's ability to contribute or harass someone, you will be shown
the door.

It describes a Code of Conduct committee, which we'll need to
define.
2024-10-21 20:07:03 +00:00
Matt Corallo
89b99a578f Include BIP 353 name info in invoice_requests
BIP 353 defines a method for resolving Human Readable Names (in the
form ₿`name`@`domain`) into bitcoin: URIs. In order to use them with
BOLT 12 with a wildcard DNS entry which resolves to a single
BOLT 12 offer for all `name`s in a domain, we need a way to
disambiguate the `name` being paid in an `invoice_request` which we
provide here by simply copying the HRN into the `invoice_request`.
2024-10-21 19:28:22 +00:00
Rusty Russell
247e83d528 BOLT 12: the test vectors.
Three vectors:

1. Raw string decoding tests.  (Start here!)
2. Offer decoding tests.
3. TLV signature tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-09-24 19:40:59 +09:00
Rusty Russell
ca06224cf6 BOLT 4: add bolt12 payloads to onion message payloads.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-09-24 19:40:59 +09:00
Rusty Russell
aed3d28d5a BOLT 12: offers, sixth draft
A BOLT11 "invoice" has proven too low-level for human use in many
scenarios.  Efforts like lnurl have covered the gap, but integrating
some of such higher layers into the lightning protocol itself has many
advantages.

This draft defines three new things:

1. A new invoice format.  I know, this is painful, but it maps almost
   1:1 to the current format (though signatures are very different),
   is easier to implement, and easier to send via the lightning
   network itself.

2. Formats for an "offer", which for all intents and purposes serves
   as the new, persistent invoice for users.

3. Format for an "invoice_request": this is a message sent via the
   lightning network itself to receive the real invoice, or can
   be used directly in a send-money scenario (e.g. ATM).

The offer (for accepting payments) or invoice_request (for sending
payments) are usually presented via a QR code or similar, the replies
are sent using onion messages.  Each copies fields from the prior so
it stands alone, to allow statelessness.

Features which have been deliberately omitted for the initial version:
- Recurrence.
- Invoice replacement ("don't accept that old payment!")
- Payer proof for refunds.

This effort has been EPIC, and there is absolutely no way I could have
done this without the often thankless task of implementing,
re-implementing, revising and re-reading this text.

In particular I have been delighted to receive the mental boost from
the following people:

1. Thomas H of ACINQ (https://github.com/thomash-acinq)
2. Jeffrey Czyz of Square Crypto (https://github.com/jkczyz)
3. Joost Jager (https://github.com/joostjager)
4. Aditya Sharma (https://github.com/adi2011)
5. Rene Pickhardt (https://github.com/renepickhardt)
6. Bastien Teinturier of ACINQ (https://github.com/t-bast)
7. Valentine Wallace of LDK (https://github.com/valentinewallace)
8. Matt Corallo of LDK (https://github.com/BlueMatt)

Also @bjarnemagnussen, @ellemouton, @animatedbarber, @617a7a,
@instagibbs, @evansmj, @eupn and @yyforyongyu.

(And no doubt others over the years, who I've accidentally omitted!)

Yes, of course, thanks to my family for their patience with me.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-09-24 19:40:59 +09:00
Jeffrey Czyz
df4af02eb1 Add a sciddir_or_pubkey fundamental type
Offers may contain blinded paths to allow for greater recipient privacy.
However, they come at a cost of increased QR code size as the
introduction node requires a 33-byte `point`.

Define a new `sciddir_or_pubkey` fundamental type such that either a point or a
reference to one in a `channel_announcement` can be used. This is
backwards compatible with `point`.

Use this new type for the `blinded_path` subtype's `first_node_id`.
2024-09-24 19:40:59 +09:00
Jeffrey Czyz
86ba089de7 Allow using short_channel_id in onion messages
Offers may contain blinded paths to allow for greater recipient privacy.
However, they come at a cost of increased QR code size as each hop
requires a 33-byte `point` for the `next_node_id`. Allow using
`short_channel_id` instead, which only requires 8 bytes.

Still allow for use of `next_node_id` for cases where the blinded path
may not involve channel counterparties or for long-lived offers, which
may outlive the given channels.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-09-24 19:40:59 +09:00
Rusty Russell
b26da74abf tools/spellcheck.sh: more generally ignore things inside ``.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-09-24 19:40:59 +09:00
Rusty Russell
4e0e38459b BOLT 1: Add utf8 type.
It's far easier to validate these on parsing than to hand-validate them
elsewhere.

I didn't turn `alias` or `error` into this, though they're similar
(`alias` can have a nul terminator).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-09-24 19:40:59 +09:00
Rusty Russell
0277f4276e BOLT 1: add bip340sig type.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-09-24 19:40:59 +09:00
ziggieXXX
0809f77c7b
BOlT07: clarify dont_forward bit use cases. (#1198) 2024-09-18 13:37:56 +02:00
Antoni Spaanderman
e6ee5f8b95
Fix broken links to anchor section (#1000) 2024-09-18 13:32:39 +02:00
Hugo
e0b1200ffa
Bolt 11: add example SHA256 hash of description (#994)
Clarify test vector.
2024-09-18 11:09:49 +02:00
Matt Morehouse
0463bdb51b
Replace "logical OR" with "bitwise OR" (#991)
This makes more sense given the context of combining bitmaps.
2024-09-18 11:08:53 +02:00
Yong
fd83d7cee0
trivial: fix wording and links in bolt03 (#1192)
* bolt03: fix link to `bitcoind`'s `policy.cpp` file

The original link is broken, we now replace it with a permalink.

* bolt03: remove 0 `txout` count in closing tx

Txns cannot have zero outputs.

* bolt03: remove wrong ref to `remotepubkey` and fix format

`remotepubkey` has been placed at the wrong place, also fixes the format
so it's easier to read.
2024-08-27 09:29:19 +02:00
Rusty Russell
5dec5eb849 BOLT 3: Fix example keys in test vectors.
All the test vectors use static keys now, which are listed above
already as the local_payment_basepoint and remote_payment_basepoint.
The keys listed here are the pre-static rotated ones: if you use
these, the vectors don't work!

We actually use the same basepoint for the HTLCs, but never spelled it
out.  So do that now, and these are the local/remote htlc keys.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2024-08-16 10:16:05 +09:30