Skip to content

Commit 9ca59ac

Browse files
committed
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.
1 parent 2fe871d commit 9ca59ac

File tree

3 files changed

+193
-19
lines changed

3 files changed

+193
-19
lines changed

02-peer-protocol.md

+10
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,12 @@ is destined, is described in [BOLT #4](04-onion-routing.md).
927927
* [`u32`:`cltv_expiry`]
928928
* [`1366*byte`:`onion_routing_packet`]
929929

930+
1. `tlv_stream`: `update_add_htlc_tlvs`
931+
2. types:
932+
1. type: 0 (`blinding_point`)
933+
2. data:
934+
* [`point`:`blinding`]
935+
930936
#### Requirements
931937

932938
A sending node:
@@ -962,6 +968,8 @@ A sending node:
962968
- for the first HTLC it offers:
963969
- MUST set `id` to 0.
964970
- MUST increase the value of `id` by 1 for each successive offer.
971+
- if it is relaying a payment inside a blinded route:
972+
- MUST set `blinding_point` (see [Route Blinding](04-onion-routing.md#route-blinding))
965973

966974
`id` MUST NOT be reset to 0 after the update is complete (i.e. after `revoke_and_ack` has
967975
been received). It MUST continue incrementing instead.
@@ -986,6 +994,8 @@ A receiving node:
986994
- if other `id` violations occur:
987995
- MAY send a `warning` and close the connection, or send an
988996
`error` and fail the channel.
997+
- if `blinding_point` is provided:
998+
- MUST use the corresponding blinded private key to decrypt the `onion_routing_packet` (see [Route Blinding](04-onion-routing.md#route-blinding))
989999

9901000
The `onion_routing_packet` contains an obfuscated list of hops and instructions for each hop along the path.
9911001
It commits to the HTLC by setting the `payment_hash` as associated data, i.e. includes the `payment_hash` in the computation of HMACs.

04-onion-routing.md

+97-19
Original file line numberDiff line numberDiff line change
@@ -264,39 +264,78 @@ It is formatted according to the Type-Length-Value format defined in [BOLT #1](0
264264
2. data:
265265
* [`32*byte`:`payment_secret`]
266266
* [`tu64`:`total_msat`]
267+
1. type: 10 (`encrypted_recipient_data`)
268+
2. data:
269+
* [`...*byte`:`encrypted_data`]
270+
1. type: 12 (`blinding_point`)
271+
2. data:
272+
* [`point`:`blinding`]
267273
1. type: 16 (`payment_metadata`)
268274
2. data:
269275
* [`...*byte`:`payment_metadata`]
270276

271277
### Requirements
272278

273279
The writer:
280+
274281
- Unless `node_announcement`, `init` message or the [BOLT #11](11-payment-encoding.md#tagged-fields) offers feature `var_onion_optin`:
275282
- MUST use the legacy payload format instead.
276-
- For every node:
283+
- For every node inside a blinded route:
284+
- MUST include the `encrypted_data` provided by the recipient
285+
- For the first node in the blinded route:
286+
- MUST include the `blinding_point` provided by the recipient
287+
- If it is the final node:
288+
- MUST include `amt_to_forward` and `outgoing_cltv_value`.
289+
- Otherwise:
290+
- MUST NOT include `amt_to_forward` and `outgoing_cltv_value`.
291+
- For every node outside of a blinded route:
277292
- MUST include `amt_to_forward` and `outgoing_cltv_value`.
278-
- For every non-final node:
279-
- MUST include `short_channel_id`
280-
- MUST NOT include `payment_data`
281-
- For the final node:
282-
- MUST NOT include `short_channel_id`
283-
- if the recipient provided `payment_secret`:
284-
- MUST include `payment_data`
285-
- MUST set `payment_secret` to the one provided
286-
- MUST set `total_msat` to the total amount it will send
287-
- if the recipient provided `payment_metadata`:
288-
- MUST include `payment_metadata` with every HTLC
289-
- MUST not apply any limits to the size of payment_metadata except the limits implied by the fixed onion size
293+
- For every non-final node:
294+
- MUST include `short_channel_id`
295+
- MUST NOT include `payment_data`
296+
- For the final node:
297+
- MUST NOT include `short_channel_id`
298+
- if the recipient provided `payment_secret`:
299+
- MUST include `payment_data`
300+
- MUST set `payment_secret` to the one provided
301+
- MUST set `total_msat` to the total amount it will send
302+
- if the recipient provided `payment_metadata`:
303+
- MUST include `payment_metadata` with every HTLC
304+
- MUST not apply any limits to the size of `payment_metadata` except the limits implied by the fixed onion size
290305

291306
The reader:
292-
- MUST return an error if `amt_to_forward` or `outgoing_cltv_value` are not present.
293-
- if it is the final node:
294-
- MUST treat `total_msat` as if it were equal to `amt_to_forward` if it
295-
is not present.
307+
308+
- If `blinding_point` is set (either in the payload or the outer message):
309+
- MUST return an error if it is set in both the payload and the outer message
310+
- MUST return an error if `encrypted_recipient_data` is not present.
311+
- MUST return an error if the expiry is greater than `encrypted_recipient_data.payment_constraints.max_cltv_expiry`.
312+
- MUST return an error if the amount is below `encrypted_recipient_data.payment_constraints.htlc_minimum_msat`.
313+
- MUST return an error if the payment uses a feature not included in `encrypted_recipient_data.payment_constraints.allowed_features`.
314+
- If it not the final node:
315+
- MUST return an error if `encrypted_recipient_data` does not contain `short_channel_id` or `next_node_id`.
316+
- MUST return an error if `encrypted_recipient_data` does not contain `payment_relay`.
317+
- If `encrypted_recipient_data.payment_relay` does not satisfy its current settings:
318+
- MAY return an error.
319+
- Otherwise:
320+
- MUST use values from `encrypted_recipient_data.payment_relay` to relay the payment.
321+
- If it is the final node:
322+
- MUST return an error if the `path_id` in `encrypted_recipient_data` does not match the one it created.
323+
- MUST return an error if `amt_to_forward` or `outgoing_cltv_value` are not present.
324+
- MUST return an error if `amt_to_forward` is below what it expects for the payment.
325+
- SHOULD add a random delay before returning errors.
326+
- Otherwise (it is not part of a blinded route):
327+
- MUST return an error if `amt_to_forward` or `outgoing_cltv_value` are not present.
328+
- MUST return an error if `encrypted_recipient_data` is present.
329+
- If it is the final node:
330+
- MUST treat `total_msat` as if it were equal to `amt_to_forward` if it is not present.
296331

297332
The requirements for the contents of these fields are specified [above](#legacy-hop_data-payload-format)
298333
and [below](#basic-multi-part-payments).
299334

335+
The requirements for the fields related to route blinding
336+
(`encrypted_recipient_data` and `blinding_point`) are also specified
337+
[below](#route-blinding).
338+
300339
### Basic Multi-Part Payments
301340

302341
An HTLC may be part of a larger "multi-part" payment: such
@@ -413,6 +452,16 @@ may contain the following TLV fields:
413452
1. type: 8 (`next_blinding_override`)
414453
2. data:
415454
* [`point`:`blinding`]
455+
1. type: 10 (`payment_relay`)
456+
2. data:
457+
* [`u32`:`fee_base_msat`]
458+
* [`u32`:`fee_proportional_millionths`]
459+
* [`u16`:`cltv_expiry_delta`]
460+
1. type: 12 (`payment_constraints`)
461+
2. data:
462+
* [`u32`:`max_cltv_expiry`]
463+
* [`u64`:`htlc_minimum_msat`]
464+
* [`...*byte`:`allowed_features`]
416465

417466
#### Requirements
418467

@@ -436,6 +485,14 @@ A recipient N(r) creating a blinded route `N(0) -> N(1) -> ... -> N(r)` to itsel
436485
- MUST communicate the blinded node IDs `B(i)` and `encrypted_data(i)` to the sender
437486
- MUST communicate the real node ID of the introduction point `N(0)` to the sender
438487
- MUST communicate the first blinding ephemeral key `E(0)` to the sender
488+
- If the blinded route will be used for payments:
489+
- MUST set `short_channel_id` and `payment_relay` in the `encrypted_data` for intermediate nodes
490+
- MUST NOT set `path_id` in the `encrypted_data` for intermediate nodes
491+
- MUST compute the total fees and cltv delta of the route and communicate them to the sender
492+
- If the blinded route will be used for messages:
493+
- MUST set `next_node_id` in the `encrypted_data` for intermediate nodes
494+
- MUST NOT set `payment_relay` or `payment_constraints` in the `encrypted_data` payloads
495+
- MUST NOT set `path_id` in the `encrypted_data` for intermediate nodes
439496

440497
The sender:
441498

@@ -519,11 +576,28 @@ context information in the `path_id` field (e.g. the `payment_preimage`) and
519576
verify that when receiving the onion. Note that it's important to use private
520577
information in that case, that senders cannot have access to.
521578

579+
Whenever the final recipient receives an invalid message from a blinded route,
580+
it should add a random delay before returning an error (if it returns one).
581+
Invalid messages are likely to be probing attempts and message timing may help
582+
the attacker infer its distance to the final recipient.
583+
522584
The `padding` field can be used to ensure that all `encrypted_data` have the
523585
same length. It's particularly useful when adding dummy hops at the end of a
524586
blinded route, to prevent the sender from figuring out which node is the final
525587
recipient.
526588

589+
When route blinding is used for payments, the recipient specifies the fees and
590+
expiry that blinded nodes should apply to the payment instead of letting the
591+
sender configure them. The recipient also adds additional constraints to the
592+
payments that can go through that route to protect against probing attacks that
593+
would let malicious nodes unblind the identity of the blinded nodes.
594+
595+
When route blinding is used for payments, nodes inside the blinded route must
596+
not return standard onion errors, because they would provide information to the
597+
sender that could help them unblind the identity of the blinded nodes. Also,
598+
instead of forwarding errors, nodes should replace them with garbage, in case
599+
a downstream node was buggy and returned a valid onion error.
600+
527601
# Accepting and Forwarding a Payment
528602

529603
Once a node has decoded the payload it either accepts the payment locally, or forwards it to the peer indicated as the next hop in the payload.
@@ -971,11 +1045,15 @@ channel.
9711045
### Requirements
9721046

9731047
The _erring node_:
1048+
9741049
- SHOULD set `pad` such that the `failure_len` plus `pad_len` is equal to 256.
975-
- Note: this value is 118 bytes longer than the longest currently-defined
976-
message.
1050+
- Note: this value is 118 bytes longer than the longest currently-defined message.
1051+
- If it is part of a blinded route:
1052+
- MUST return random bytes instead of a valid onion error.
1053+
- SHOULD replace downstream errors by random bytes before forwarding them upstream.
9771054

9781055
The _origin node_:
1056+
9791057
- once the return message has been decrypted:
9801058
- SHOULD store a copy of the message.
9811059
- SHOULD continue decrypting, until the loop has been repeated 20 times.

0 commit comments

Comments
 (0)