1
0
mirror of https://github.com/lightning/bolts.git synced 2024-11-19 01:50:03 +01:00
Commit Graph

261 Commits

Author SHA1 Message Date
niftynei
11dea59504 tx-abort: port over meaning of the data field from warning
`tx_abort`'s structure comes from the `warning`/`error` messages,
but we failed to port over the rationale/rules for the `data` field.

Suggested-By: @morehouse
2024-02-13 11:55:23 -06:00
Dustin Dettmer
71e67e6d46 Bolt 2: Make interactive-tx explicitly use SIGHASH_ALL
This was previously assumed but adding it to the spec makes it explicit, should we ever want to change it in the future.

Suggested-By: @morehouse
2024-02-13 11:55:23 -06:00
niftynei
c51ef43fee interactive-tx: highlight MUST of serial_id sorting
Suggested-By: @dunxen
2024-02-13 11:55:23 -06:00
Duncan Dean
2ddddbd7c2 Use bitcoin wire encoding for witnesses 2024-02-13 11:55:23 -06:00
t-bast
c7af874f3d Store state when sending commitment_signed
If we only store state when sending `tx_signatures`, there are cases where
we cannot reconcile states if a disconnection occurs during the signing
steps: one side will have sent `tx_signatures` and thus must wait for the
transaction to be spent or double-spent, while the other side has already
forgotten that channel because they haven't sent `tx_signatures`.

This is fixed by storing state when sending `commitment_signed`, and
adding a `next_funding_txid` field to `channel_reestablish` to ask our
peer to retransmit signatures that we haven't received.
2024-02-13 11:55:23 -06:00
t-bast
1e48543ff1 Add section about liquidity griefing
This issue is non-trivial and worth mentioning, otherwise implementations
may forget to handle this which would result in an easy way of attacking
node's on-chain liquidity, creating a large opportunity cost.
2024-02-13 11:55:23 -06:00
t-bast
03a0eab139 Add require_confirmed_inputs TLV
This lets any side of the protocol require the other side to use confirmed
inputs, to avoid paying the fees of a low feerate unconfirmed ancestor.
2024-02-13 11:55:23 -06:00
niftynei
0bc22790ea v2 opens: proposal to get rid of the minimum estimated fee
Prior versions of the v2 dual-funding protocol assumed a 'minimum fee'
payment for any witness stack of any input, as a way to simplify fee
checks.

The suggested min feerate didn't make sense for taproot spend paths etc;
instead we remove this check entirely.
2024-02-13 11:55:23 -06:00
niftynei
cf9a5fcfe5 peer-protocol: send first+second commit point in openchanv2 + accept
Repeat the second commit point in the initial openchannel2 +
acceptchannel2 messages.

Suggested-By: @pm47
2024-02-13 11:55:23 -06:00
t-bast
811e55cd9e Use signed amounts in RBF messages
While dual funding only needs unsigned funding amounts, other protocols
that leverage interactive-tx may use signed funding amounts, for example
to take funds out of an existing channel (splice-out).

It is thus more future-proof to use signed amounts in `tx_init_rbf` and
`tx_ack_rbf`.
2024-02-13 11:55:23 -06:00
t-bast
180e4764ce Clarify RBF funding requirements 2024-02-13 11:55:23 -06:00
niftynei
3f1d142471 v2 opens: add a tx_abort message
Requested-by: @t-bast
2024-02-13 11:55:23 -06:00
niftynei
c00c0dd7bc interactive-tx: Add dual-funding flow, using the interactive tx protocol
This commit adds the interactive transaction construction protcol, as
well as the first practical example of using it, v2 of channel
establishment.

Note that for v2 we also update the channel_id, which now uses the hash
of the revocation_basepoints. We move away from using the funding
transaction id, as the introduction of RBF* makes it such that a single
channel may have many funding transaction id's over the course of
its lifetime.

*Later, also splicing
2024-02-13 11:55:23 -06:00
Keagan McClelland
4dcc377209 Clarify the semantics of max_htlc_value_in_flight_msat
Prior wording of the description of this parameter left room for
ambiguity around whether it capped the total value offered by both
channel peers combined or if it was solely capping the total value
of HTLCs offered by the remote.
2023-09-26 05:50:01 +09:30
ProofOfKeags
6e85df448b
BOLT2: change "reject" to "fail" in channel opening requirements (#1104)
Since "reject" isn't defined anywhere in the spec and "fail" does
have a definition laid out in BOLT1 that includes special
provisions for channels that have not yet been established, BOLT2
is amended to clarify the requirements for the receiver of
`accept_channel`
2023-08-28 14:13:59 +02:00
Antoine Riard
a1870e136e
Add a max_dust_htlc_exposure_msat (#919)
* Bound exposure to trimmed in-flight HTLCs
* Reject update_fee beyond max_dust_htlc_exposure_msat

Co-authored-by: t-bast <bastuc@hotmail.fr>
2023-08-14 23:08:10 +02:00
Bastien Teinturier
7d3ef5a6b2
Allow unset onion_hash in invalid_onion_blinding (#1093)
In most cases the `onion_hash` isn't actionable in the case of blinded
payments and it's wasteful to keep track of the incoming onion, so we
allow setting it to an all zero value.
2023-07-27 11:31:40 +02:00
t-bast
c4c5a8e5fb Bolt 4: add blinded payments
Add specification requirements for using route blinding to make payments
while preserving recipient anonymity. Implementers must ensure they
understand all those requirements, there are subtle attacks that could let
malicious senders deanonymize the route if incompletely implemented.
2023-03-28 08:44:14 +02:00
Bastien Teinturier
b38156b951
Allow nodes to overshoot final htlc amount and expiry (#1032)
When nodes receive HTLCs, they verify that the contents of those HTLCs
match the intructions that the sender provided in the onion. It is
important to ensure that intermediate nodes and final nodes have similar
requirements, otherwise a malicious intermediate node could easily probe
whether the next node is the final recipient or not.

Unfortunately, the requirements for intermediate nodes were more lenient
than the requirements for final nodes. Intermediate nodes allowed overpaying
and increasing the CLTV expiry, whereas final nodes required a perfect
equality between the HTLC values and the onion values.

This provided a trivial way of probing: when relaying an HTLC, nodes could
relay 1 msat more than what the onion instructed (or increase the outgoing
expiry by 1). If the next node was an intermediate node, they would accept
this HTLC, but if the next node was the recipient, they would reject it.

We update those requirements to fix this probing attack vector.

We also clarify `min_final_cltv_expiry`: this is actually a cltv_expiry_delta,
not an absolute cltv_expiry, so the field name should reflect that.

Recipients require incoming HTLC expiry to comply with that expiry delta.
2022-11-08 08:38:36 +01:00
eugene
341ec844f1 BOLT#02: clarify coop close requirements
This commit ensures closing_signed can only begin if there are
no dangling commitments. It also clarifies update_fee requirements
if it is sent after shutdown.
2022-07-18 15:35:08 -05:00
Bastien Teinturier
c6c672aa15
Zero-conf typos and clarifications (#998)
A typo wasn't fixed before merging, and there was a confusion between
public and private channels in the rationale for `alias`.
2022-06-20 21:32:00 +02:00
Matt Corallo
bc86304b4b
Merge pull request #910 from rustyrussell/zeroconf-as-alias
Explicitly allow funding_locked early, and support alias scids (feat 46/47/50/51)
2022-05-30 13:50:25 -07:00
Rusty Russell
34e9cd99db Rename funding_locked to channel_ready.
And `next_per_commitment_point` to explictly `second_per_commitment_point`;
this is particularly important since `channel_ready` can be retransmitted
after the channel has been in use, for example.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-05-30 20:47:49 +00:00
Rusty Russell
7a812cf077 Make zeroconf a channel type, and acceptance indicates trust.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-05-30 20:47:49 +00:00
Rusty Russell
7aa76b67b2 BOLT 2: add channel_type for option_scid_alias
Allows upgrade in future.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-05-30 20:47:49 +00:00
Rusty Russell
faa6c413b9 BOLT 2: Restore minimum_depth requirement, but explicitly allow 0.
And weaken it: the opener doesn't need to respect it.

Note also that the `funding_locked`-can-change-alias refers to the same peer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-05-30 20:47:49 +00:00
Rusty Russell
d41cc1ec12 Explicitly allow funding_locked early, and support alias scids.
This lets you add your brand new channel to routehints, and also
means you can use a routehinted channel even if you (later?) have a
real channel.

This supports both trusted and untrusted zero-conf channels: in the
trusted case you can use it immediately like any other channel,
and for the untrusted case you simply use any push_msat they gave you
for outgoing payments, but fail incoming.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-05-30 20:47:49 +00:00
Vincenzo Palazzo
e7017173d6
bolt2: disallow sending multiple shutdown msg (#977)
The rationale for this is to avoid bad cases like the following one
which was previously allowed:

* sender -> shutdown(script_one) -> receiver
* sender -> shutdown(script_two) -> receiver
* sender <- shutdown(script_one) <- receiver

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-05-18 15:51:37 +02:00
t-bast
32a76e80c7 Echo channel_type in accept_channel
One argument for adding a feature bit for channel types was to make things
more explicit and remove ambiguity.

When sending `open_channel`, we require funders to include a `channel_type`,
so it would make sense to require fundees to echo that `channel_type`
back to explicitly confirm that they're ok with this `channel_type`.
2022-03-14 14:58:34 -05:00
Rusty Russell
e60d594abf
Fix typo and aspell list. (#963)
Since Travis died, we don't get CI to check these any more :(

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2022-02-25 12:17:18 +01:00
Bastien Teinturier
5fa6ff3360
Warn on quick close fee mismatch instead of disconnecting (#904)
When peers disagree on the closing fee range, disconnecting
doesn't make sense: upon reconnection they will just send the
same `closing_signed` again.

A warning should instead be sent and logged, so that node
operators can decide to update their fee range if they want
this channel close to make progress.
2022-02-15 08:47:53 +01:00
lightning-developer
29db92f334
Removed requirement to broadcast an outdated commitment transaction (#942)
If a node has to fail a channel but knows that its latest commitment transaction is outdated it should not be required to send it but rather wait for the peer to unilaterally close the channel. 

The proposed solution is not so clean because it might produce a deadlock in which two peers assume they have outdated state and send `error` back and forth without actually force closing. Maybe in such a scenario we could create a protocol that mutually closes with split balance? 

Also replaced the word use with broadcast as it seems more accurate.

Co-authored-by: t-bast <bastuc@hotmail.fr>
2022-01-17 20:09:28 +01:00
Olaoluwa Osuntokun
ea37941537
anchors: follow up changes after initial zero fee anchors merge (#903)
We can remove references to anchors in a few places, and you need
static key in order to support it, so that reference is redundant.
2022-01-04 09:26:43 +01:00
Rusty Russell
c36c14d6da BOLT 2: Error instead of warning on shutdown on unopened channel.
Abandoning channel is kinda what they want here.

Reported-by: Matt Corallo
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-14 10:32:24 +10:30
Rusty Russell
eb6f3084c5 Make it explicit when to send warnings, errors, fail channel and close connection.
And make most places warn or error.  Places where we're operating
on a channel tend to be "warn and close connection" since we want to
forget the mistake they just sent, and closing the connection does that.

We now use the same words everywhere:
1. "fail channel" means to go onchain (if necessary).
2. "send `error`" means to send an error message.
3. "send `warning`" means to send a warning message.
4. "close connection" means close the connection.

These are all spelled out explicitly, rather than having "fail channel"
imply sending an error packet, for example.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-12-14 10:32:22 +10:30
Olaoluwa Osuntokun
630bf989db
BOLT-02+09: introduce feature bit to gate new channel_type feature (#906)
In this commit, we add a new feature bit to gate the new explicit
channel type funding via the new `channel_type` TLV. The addition of
this new bit allows peers to seek out other peers that understand the
new explicit channel negotiation. This is useful in practice, as it
allows peers to avoid needing to "downgrade" the feature bits advertised
at the connection level due to one peer not understanding a new
required feature bit while it has a channel with a connecting peer.

Such a workaround is already deployed on the network between lnd peers
and certain eclair peers, as the `lnd` peers require static key, but the
feature bit is unknown to eclair peers. This situation (forced
downgrade) is undesirable, as until the connected peer updates (or the
channel is closed) and "worst" feature bit set must always be advertised
in order to maintain connectivity.

The other benefit of adding this feature bit is that it allows
implementations to simplify their code by ensuring that the new feature
will be used before sending any messages that include or reference that
feature. Without a feature bit, peers are instead forced to essentially
guess if a peer understands that feature, with logic to be able to "bail
out" of an invalid state.

The addition of this feature bit matches the prior precedent of adding
feature bits when new fields in the channel negotiation message (last
one was upfront shutdown) are added.
2021-12-05 16:35:35 -08:00
Bastien Teinturier
8f2104e3b6
Peers need to check each other's dust limit (#894)
Since HTLCs below this amount will not appear in the commitment tx, they
are effectively converted to miner fees. The peer could use this to grief
you by broadcasting its commitment once it contains a lot of dust HTLCs.

Add network dust thresholds computation details, as implemented in Bitcoin
Core's default relay policy.

Drop non-segwit support in shutdown: this allows dust limit to go as low
as 354 sats without creating relay issues with default node policies.

We add a requirement that dust limit cannot be lower than 354 sats.
This ensures implementers don't have to figure this subtlety on their own.

Fixes #696 and #905
2021-10-06 09:40:22 +02:00
Bastien Teinturier
498f104fd3
Update closing_signed fee requirement (#847)
With anchor outputs, we can keep the commit tx feerate lower than the real
on-chain feerate. That means that when closing the channel, the resulting
fee will not necessarily be lower than the current commit tx fee, this
requirement doesn't make sense to be strict.

Both sides can optionally include a preferred fee range in their
`closing_signed`. This lets their peer know what fees they find acceptable
and simplifies the closing negotiation.
2021-08-31 09:08:07 +02:00
Rusty Russell
4372f9d538 BOLT 2: define channel_type, make negotiation explicit.
This is extracted from channel_upgrade (#868), but used for opening
negotiation as suggested by @roasbeef on the last spec meeting.

It's a trivial change, fully backwards compatible, but now each channel
has a channel_type, which defines its behavior, rather than an ad-hoc
set of "sticky" feature bits.  It also means both peers can *support* a
feature without endorsing it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-08-31 10:02:20 +09:30
Johan T. Halseth
fdc078f845
feature: define option_zero_htlc_tx_fee (feature 22/23) (#824)
This PR adds a new feature bit to define the new and improved anchor outputs commitment format.
2021-08-30 13:50:25 -07:00
Bastien Teinturier
84213f45c0
Remove HTLC amount restriction (#877)
We previously had a restriction on HTLC amounts to avoid big losses during
the early phases of the network, but it shouldn't be necessary anymore.

As long as we honor `max_htlc_value_in_flight_msat` and implementations
provide safe defaults for that parameter, we don't need that additional
restriction.
2021-06-21 22:41:46 +02:00
Rusty Russell
3508e4e85d BOLT 2: option_shutdown_anysegwit
In bitcoin 0.19.0, standardness rules are going to be relaxed to allow
future witness versions.  Once this is widely deployed, it will be safe
to accept them, smoothing use of future segwit versions.

See: https://github.com/bitcoin/bitcoin/pull/15846

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-05-25 06:46:27 +09:30
Lloyd Fournier
55ee3f406d
per_commitment_secret must be a valid secret key
See #832
2021-03-31 14:28:36 +11:00
Bastien Teinturier
ba00bf8f4c
Add 2016 blocks channel funding timeout (#839)
Routing nodes have an incentive to use low fees when opening channels to
ensure their activity is economically viable.

However, when a funding transaction takes too long to confirm, the fundee
may have forgotten the channel. In that case the funder is forced to
broadcast the first commit tx to get his funds back and then open a new
channel, which is costly.

We can avoid this issue by simply knowing how long the fundee will wait,
and ensuring the funding tx confirms before that period ends. We set this
timeout to 2016 blocks (2 weeks).
2021-03-02 09:16:07 +01:00
benthecarman
90468030d5 Correct hint for P2WPKH 2021-02-18 16:03:15 +10:30
Pierre-Marie Padiou
a5d4f33467
Minor indentation fix (#846) 2021-02-15 16:33:53 +01:00
Bastien Teinturier
920e51986d
Clarify relative order of some messages after reestablish (#810)
The existing requirements were not specifying the case where both a
`commitment_signed` and `revoke_and_ack` need to be retransmitted.

This is an important case to specify because if the relative order is not
preserved, the channel will close.

Fixes #794
2020-11-23 20:14:43 +01:00
Corné Plooy
13520a0e36 tlvs -> tlv_stream subsitution everywhere 2020-11-09 13:10:22 -06:00
Antoine Riard
01f29bf9fe
Fail channel in case of high-S remote signature reception (#807)
See CVE-2020-26895 for context.
2020-11-03 09:24:42 +01:00
t-bast
c5693d336d Update Bolt 11 default recommendation 2020-08-20 14:57:34 +09:30