Skip to content

Commit 3fffab3

Browse files
t-bastrustyrussell
authored andcommitted
Clean-up nits
This commit doesn't change the logic at all, it simply: - removes `realm` from onion test vector - cleans-up markdown formatting and indents - fixes typos and missing parenthesis - consistently uses `_` instead of `-` for field names - fixes math formatting (including changes from #1169 and #1158)
1 parent 5e9ea22 commit 3fffab3

6 files changed

+57
-58
lines changed

02-peer-protocol.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2130,14 +2130,14 @@ A node:
21302130
- MUST NOT send an `update_fulfill_htlc`, `update_fail_htlc`, or
21312131
`update_fail_malformed_htlc`.
21322132
- When failing an incoming HTLC:
2133-
- If `current_path_key_point` is set in the onion payload and it is not the
2133+
- If `current_path_key` is set in the onion payload and it is not the
21342134
final node:
21352135
- MUST send an `update_fail_htlc` error using the `invalid_onion_blinding`
21362136
failure code for any local or downstream errors.
21372137
- SHOULD use the `sha256_of_onion` of the onion it received.
21382138
- MAY use an all zero `sha256_of_onion`.
21392139
- SHOULD add a random delay before sending `update_fail_htlc`.
2140-
- If `path_key_point` is set in the incoming `update_add_htlc`:
2140+
- If `path_key` is set in the incoming `update_add_htlc`:
21412141
- MUST send an `update_fail_malformed_htlc` error using the
21422142
`invalid_onion_blinding` failure code for any local or downstream errors.
21432143
- SHOULD use the `sha256_of_onion` of the onion it received.

04-onion-routing.md

+29-30
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ The reader:
324324
- MUST return an error if incoming `cltv_expiry` < `outgoing_cltv_value`.
325325
- MUST return an error if incoming `cltv_expiry` < `current_block_height` + `min_final_cltv_expiry_delta`.
326326
- Otherwise (it is not part of a blinded route):
327-
- MUST return an error if `path_key` is set in the incoming `update_add_htlc` or `current_pass` is present.
327+
- MUST return an error if `path_key` is set in the incoming `update_add_htlc` or `current_path_key` is present.
328328
- MUST return an error if `amt_to_forward` or `outgoing_cltv_value` are not present.
329329
- if it is not the final node:
330330
- MUST return an error if:
@@ -498,20 +498,20 @@ may contain the following TLV fields:
498498
A recipient $`N_r`$ creating a blinded route $`N_0 \rightarrow N_1 \rightarrow ... \rightarrow N_r`$ to itself:
499499

500500
- MUST create a blinded node ID $`B_i`$ for each node using the following algorithm:
501-
- $`e_0 /leftarrow {0;1}^256`$ ($`e_0`$ SHOULD be obtained via CSPRG)
501+
- $`e_0 \leftarrow \{0;1\}^{256}`$ ($`e_0`$ SHOULD be obtained via CSPRNG)
502502
- $`E_0 = e_0 \cdot G`$
503503
- For every node in the route:
504504
- let $`N_i = k_i * G`$ be the `node_id` ($`k_i`$ is $`N_i`$'s private key)
505-
- $`ss_i = SHA256(e_i * N_i) = SHA256(k_i * E_i)$` (ECDH shared secret known only by $`N_r`$ and $`N_i`$)
505+
- $`ss_i = SHA256(e_i * N_i) = SHA256(k_i * E_i)`$ (ECDH shared secret known only by $`N_r`$ and $`N_i`$)
506506
- $`B_i = HMAC256(\text{"blinded\_node\_id"}, ss_i) * N_i`$ (blinded `node_id` for $`N_i`$, private key known only by $`N_i`$)
507507
- $`rho_i = HMAC256(\text{"rho"}, ss_i)`$ (key used to encrypt the payload for $`N_i`$ by $`N_r`$)
508508
- $`e_{i+1} = SHA256(E_i || ss_i) * e_i`$ (ephemeral private path key, only known by $`N_r`$)
509509
- $`E_{i+1} = SHA256(E_i || ss_i) * E_i`$ (`path_key`. NB: $`N_i`$ MUST NOT learn $`e_i`$)
510510
- MAY replace $`E_{i+1}`$ with a different value, but if it does:
511-
- MUST set `encrypted_data_tlv[i].next_path_key_override` to `$E_{i+1}$`
511+
- MUST set `encrypted_data_tlv[i].next_path_key_override` to $`E_{i+1}`$
512512
- MAY store private data in `encrypted_data_tlv[r].path_id` to verify that the route is used in the right context and was created by them
513513
- SHOULD add padding data to ensure all `encrypted_data_tlv[i]` have the same length
514-
- MUST encrypt each `encrypted_data_tlv[i]` with ChaCha20-Poly1305 using the corresponding `rho_i` key and an all-zero nonce to produce `encrypted_recipient_data[i]`
514+
- MUST encrypt each `encrypted_data_tlv[i]` with ChaCha20-Poly1305 using the corresponding $`rho_i`$ key and an all-zero nonce to produce `encrypted_recipient_data[i]`
515515
- MUST communicate the blinded node IDs $`B_i`$ and `encrypted_recipient_data[i]` to the sender
516516
- MUST communicate the real node ID of the introduction point $`N_0`$ to the sender
517517
- MUST communicate the first `path_key` $`E_0`$ to the sender
@@ -521,7 +521,7 @@ A reader:
521521
- If it receives `path_key` ($`E_i`$) from the prior peer:
522522
- MUST use $`b_i`$ instead of its private key $`k_i`$ to decrypt the onion.
523523
Note that the node may instead tweak the onion ephemeral key with
524-
$`HMAC256(\text{"blinded\_node\_id}", ss_i)`$ which achieves the same result.
524+
$`HMAC256(\text{"blinded\_node\_id"}, ss_i)`$ which achieves the same result.
525525
- Otherwise:
526526
- MUST use $`k_i`$ to decrypt the onion, to extract `current_path_key` ($`E_i`$).
527527
- MUST compute:
@@ -560,7 +560,7 @@ keys of the nodes in the route with random public keys while letting senders
560560
choose what data they put in the onion for each hop. Blinded routes are also
561561
reusable in some cases (e.g. onion messages).
562562

563-
Each node in the blinded route needs to receive `E_i` to be able to decrypt
563+
Each node in the blinded route needs to receive $`E_i`$ to be able to decrypt
564564
the onion and the `encrypted_data` payload. Protocols that use route blinding
565565
must specify how this value is propagated between nodes.
566566

@@ -573,7 +573,7 @@ The final recipient must verify that the blinded route is used in the right
573573
context (e.g. for a specific payment) and was created by them. Otherwise a
574574
malicious sender could create different blinded routes to all the nodes that
575575
they suspect could be the real recipient and try them until one accepts the
576-
message. The recipient can protect against that by storing `E_r` and the
576+
message. The recipient can protect against that by storing $`E_r`$ and the
577577
context (e.g. a `payment_hash`), and verifying that they match when receiving
578578
the onion. Otherwise, to avoid additional storage cost, it can put some private
579579
context information in the `path_id` field (e.g. the `payment_preimage`) and
@@ -620,7 +620,7 @@ sent across.
620620

621621
Nodes implementing non-strict forwarding are able to make real-time assessments
622622
of channel bandwidths with a particular peer, and use the channel that is
623-
locally-optimal.
623+
locally-optimal.
624624

625625
For example, if the channel specified by `short_channel_id` connecting A and B
626626
does not have enough bandwidth at forwarding time, then A is able use a
@@ -860,9 +860,10 @@ func NewOnionPacket(paymentPath []*btcec.PublicKey, sessionKey *btcec.PrivateKey
860860

861861
# Onion Decryption
862862

863-
There are two kinds of `onion_packet` we use:
863+
There are two kinds of `onion_packet` we use:
864+
864865
1. `onion_routing_packet` in `update_add_htlc` for payments, which contains a `payload` TLV (see [Adding an HTLC](02-peer-protocol.md#adding-an-htlc-update_add_htlc))
865-
2. `onion_message_packet` on `onion_message` for messages, which contains a `onionmsg_tlv` TLV (see [Onion Messages](#onion-messages)
866+
2. `onion_message_packet` in `onion_message` for messages, which contains an `onionmsg_tlv` TLV (see [Onion Messages](#onion-messages))
866867

867868
Those sections specify the `associated_data` to use, the `path_key` (if any), the extracted payload format and handling (including how to determine the next peer, if any), and how to handle errors. The processing itself is identical.
868869

@@ -874,26 +875,26 @@ A reader:
874875
- if `public_key` is not a valid pubkey:
875876
- MUST abort processing the packet and fail.
876877
- if the onion is for a payment:
877-
- if `hmac` has previously been received:
878-
- if the preimage is known:
879-
- MAY immediately redeem the HTLC using the preimage.
880-
- otherwise:
881-
- MUST abort processing the packet and fail.
878+
- if `hmac` has previously been received:
879+
- if the preimage is known:
880+
- MAY immediately redeem the HTLC using the preimage.
881+
- otherwise:
882+
- MUST abort processing the packet and fail.
882883
- if `path_key` is specified:
883-
- Calculate the `blinding_ss` as ECDH(`path_key`, `node-privkey`)
884+
- Calculate the `blinding_ss` as ECDH(`path_key`, `node_privkey`).
884885
- Either:
885-
- Tweak `public_key` by multiplying by $`HMAC256(\text{"blinded\_node\_id"}, blinding\_ss)`$
886+
- Tweak `public_key` by multiplying by $`HMAC256(\text{"blinded\_node\_id"}, blinding\_ss)`$.
886887
- or (equivalently):
887-
- Tweak its own `node-privkey` below by multiplying by $`HMAC256(\text{"blinded\_node\_id"}, blinding\_ss)`$
888-
- Derive the shared secret `ss` as ECDH(`public_key`, `node-privkey`) (see [Shared Secret](#shared-secret))
888+
- Tweak its own `node_privkey` below by multiplying by $`HMAC256(\text{"blinded\_node\_id"}, blinding\_ss)`$.
889+
- Derive the shared secret `ss` as ECDH(`public_key`, `node_privkey`) (see [Shared Secret](#shared-secret)).
889890
- Derive `mu` as $`HMAC256(\text{"mu"}, ss)`$ (see [Key Generation](#key-generation)).
890-
- Derive the HMAC as $`HMAC256(mu, hop_payloads || associated_data)`$
891+
- Derive the HMAC as $`HMAC256(mu, hop\_payloads || associated\_data)`$.
891892
- MUST use a constant time comparison of the computed HMAC and `hmac`.
892893
- If the computed HMAC and `hmac` differ:
893894
- MUST abort processing the packet and fail.
894895
- Derive `rho` as $`HMAC256(\text{"rho"}, ss)`$ (see [Key Generation](#key-generation)).
895896
- Derive `bytestream` of twice the length of `hop_payloads` using `rho` (see [Pseudo Random Byte Stream](pseudo-random-byte-stream)).
896-
- Set `unwrapped_payloads` to the XOR of `hop_payloads` and `bytestream`
897+
- Set `unwrapped_payloads` to the XOR of `hop_payloads` and `bytestream`.
897898
- Remove a `bigsize` from the front of `unwrapped_payloads` as `payload_length`. If that is malformed:
898899
- MUST abort processing the packet and fail.
899900
- If the `payload_length` is less than two:
@@ -907,22 +908,20 @@ A reader:
907908
- If `unwrapped_payloads` is smaller than `hop_payloads`:
908909
- MUST abort processing the packet and fail.
909910
- If `next_hmac` is not all-zero (not the final node):
910-
- Derive `blinding_tweak` as $`SHA256(public_key || ss)`$ (see [Blinding Ephemeral Onion Keys](#blinding-ephemeral-onion-keys))
911+
- Derive `blinding_tweak` as $`SHA256(public\_key || ss)`$ (see [Blinding Ephemeral Onion Keys](#blinding-ephemeral-onion-keys)).
911912
- SHOULD forward an onion to the next peer with:
912-
- `version` set to 0
913-
- `public_key` set to the incoming `public_key` multiplied by `blinding_tweak`
914-
- `hop_payloads` set to the `unwrapped_payloads`, truncated to the incoming `hop_payloads` size
915-
- `hmac` set to `next_hmac`
913+
- `version` set to 0.
914+
- `public_key` set to the incoming `public_key` multiplied by `blinding_tweak`.
915+
- `hop_payloads` set to the `unwrapped_payloads`, truncated to the incoming `hop_payloads` size.
916+
- `hmac` set to `next_hmac`.
916917
- If it cannot forward:
917918
- MUST fail.
918919
- Otherwise (all-zero `next_hmac`):
919920
- This is the final destination of the onion.
920921

921-
922922
## Rationale
923923

924-
In the case where blinded paths are used, the sender did not actually encrypt this onion for our node_id, but for a tweaked version: we can derive the tweak used from `path_key` which is given alongside the onion. Then we either tweak our node private key the same way to decrypt the onion, or tweak to the onion ephemeral key which is mathematically equivalent.
925-
924+
In the case where blinded paths are used, the sender did not actually encrypt this onion for our `node_id`, but for a tweaked version: we can derive the tweak used from `path_key` which is given alongside the onion. Then we either tweak our node private key the same way to decrypt the onion, or tweak to the onion ephemeral key which is mathematically equivalent.
926925

927926
# Filler Generation
928927

bolt04/blinded-onion-message-onion-test.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"hops": [
77
{
88
"alias": "Alice",
9-
"comment": "Alice->Bob: note next_blinding_override to match that give by Dave for Bob",
10-
"blinding_secret": "6363636363636363636363636363636363636363636363636363636363636363",
9+
"comment": "Alice->Bob: note next_path_key_override to match that give by Dave for Bob",
10+
"path_key_secret": "6363636363636363636363636363636363636363636363636363636363636363",
1111
"tlvs": {
1212
"next_node_id": "0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c",
13-
"next_blinding_override": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
14-
"blinding_override_secret": "0101010101010101010101010101010101010101010101010101010101010101"
13+
"next_path_key_override": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
14+
"path_key_override_secret": "0101010101010101010101010101010101010101010101010101010101010101"
1515
},
1616
"encrypted_data_tlv": "04210324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c0821031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
1717
"ss": "c04d2a4c518241cb49f2800eea92554cb543f268b4c73f85693541e86d649205",
@@ -26,7 +26,7 @@
2626
{
2727
"alias": "Bob",
2828
"comment": "Bob->Carol",
29-
"blinding_secret": "0101010101010101010101010101010101010101010101010101010101010101",
29+
"path_key_secret": "0101010101010101010101010101010101010101010101010101010101010101",
3030
"tlvs": {
3131
"next_node_id": "027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007",
3232
"unknown_tag_561": "123456"
@@ -44,7 +44,7 @@
4444
{
4545
"alias": "Carol",
4646
"comment": "Carol->Dave",
47-
"blinding_secret": "f7ab6dca6152f7b6b0c9d7c82d716af063d72d8eef8816dfc51a8ae828fa7dce",
47+
"path_key_secret": "f7ab6dca6152f7b6b0c9d7c82d716af063d72d8eef8816dfc51a8ae828fa7dce",
4848
"tlvs": {
4949
"padding": "0000000000",
5050
"next_node_id": "032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991"
@@ -62,7 +62,7 @@
6262
{
6363
"alias": "Dave",
6464
"comment": "Dave is final node, hence path_id",
65-
"blinding_secret": "5de52bb427cc148bf23e509fdc18012004202517e80abcfde21612ae408e6cea",
65+
"path_key_secret": "5de52bb427cc148bf23e509fdc18012004202517e80abcfde21612ae408e6cea",
6666
"tlvs": {
6767
"padding": "",
6868
"path_id": "deadbeefbadc0ffeedeadbeefbadc0ffeedeadbeefbadc0ffeedeadbeefbadc0",
@@ -82,8 +82,8 @@
8282
},
8383
"route": {
8484
"comment": "The resulting blinded route Alice to Dave.",
85-
"introduction_node_id": "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619",
86-
"blinding": "031195a8046dcbb8e17034bca630065e7a0982e4e36f6f7e5a8d4554e4846fcd99",
85+
"first_node_id": "02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619",
86+
"first_path_key": "031195a8046dcbb8e17034bca630065e7a0982e4e36f6f7e5a8d4554e4846fcd99",
8787
"hops": [
8888
{
8989
"blinded_node_id": "02d1c3d73f8cac67e7c5b6ec517282d5ba0a52b06a29ec92ff01e12decf76003c1",

0 commit comments

Comments
 (0)