You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Rename all the 'varint' to 'bigsize'.
Having both is confusing; we chose the name bigsize, so use it
explicitly.
Signed-off-by: Rusty Russell <[email protected]>
* BOLT 7: use `byte` instead of `u8`.
`u8` isn't a type; see BOLT #1 "Fundamental Types".
Signed-off-by: Rusty Russell <[email protected]>
* BOLT 1: promote bigsize to a Fundamental Type.
Signed-off-by: Rusty Russell <[email protected]>
Copy file name to clipboardExpand all lines: 01-messaging.md
+14-18Lines changed: 14 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -110,28 +110,23 @@ the backwards-compatible addition of new fields to existing message types.
110
110
111
111
A `tlv_record` represents a single field, encoded in the form:
112
112
113
-
*[`varint`: `type`]
114
-
*[`varint`: `length`]
113
+
*[`bigsize`: `type`]
114
+
*[`bigsize`: `length`]
115
115
*[`length`: `value`]
116
116
117
-
A `varint` is a variable-length, unsigned integer encoding using the
118
-
[BigSize](#appendix-a-bigsize-test-vectors) format, which resembles the bitcoin
119
-
CompactSize encoding but uses big-endian for multi-byte values rather than
120
-
little-endian.
121
-
122
117
A `tlv_stream` is a series of (possibly zero) `tlv_record`s, represented as the
123
118
concatenation of the encoded `tlv_record`s. When used to extend existing
124
119
messages, a `tlv_stream` is typically placed after all currently defined fields.
125
120
126
-
The `type` is a varint encoded using the BigSize format. It functions as a
121
+
The `type` is encoded using the BigSize format. It functions as a
127
122
message-specific, 64-bit identifier for the `tlv_record` determining how the
128
123
contents of `value` should be decoded. `type` identifiers below 2^16 are
129
124
reserved for use in this specification. `type` identifiers greater than or equal
130
125
to 2^16 are available for custom records. Any record not defined in this
131
126
specification is considered a custom record. This includes experimental and
132
127
application-specific messages.
133
128
134
-
The `length` is a varint encoded using the BigSize format signaling the size of
129
+
The `length` is encoded using the BigSize format signaling the size of
135
130
`value` in bytes.
136
131
137
132
The `value` depends entirely on the `type`, and should be encoded or decoded
@@ -192,7 +187,7 @@ things, enables the following optimizations:
192
187
- variable-size fields can reserve their expected size up front, rather than
193
188
appending elements sequentially and incurring double-and-copy overhead.
194
189
195
-
The use of a varint for `type` and `length` permits a space savings for small
190
+
The use of a bigsize for `type` and `length` permits a space savings for small
196
191
`type`s or short `value`s. This potentially leaves more space for application
197
192
data over the wire or in an onion payload.
198
193
@@ -236,6 +231,7 @@ The following convenience types are also defined:
236
231
*`signature`: a 64-byte bitcoin Elliptic Curve signature
237
232
*`point`: a 33-byte Elliptic Curve point (compressed encoding as per [SEC 1 standard](http://www.secg.org/sec1-v2.pdf#subsubsection.2.3.3))
238
233
*`short_channel_id`: an 8 byte value identifying a channel (see [BOLT #7](07-routing-gossip.md#definition-of-short-channel-id))
234
+
*`bigsize`: a variable-length, unsigned integer similar to Bitcoin's CompactSize encoding, but big-endian. Described in [BigSize](#appendix-a-bigsize-test-vectors).
239
235
240
236
## Setup Messages
241
237
@@ -474,10 +470,10 @@ decoded with BigSize should be checked to ensure they are minimally encoded.
474
470
475
471
The following is an example of how to execute the BigSize decoding tests.
Copy file name to clipboardExpand all lines: 04-onion-routing.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,7 +95,7 @@ There are a number of conventions adhered to throughout this document:
95
95
- Each hop in the route has a variable length `hop_payload`, or a fixed-size
96
96
legacy `hop_data` payload.
97
97
- The legacy `hop_data` is identified by a single `0x00`-byte prefix
98
-
- The variable length `hop_payload` is prefixed with a `varint` encoding
98
+
- The variable length `hop_payload` is prefixed with a `bigsize` encoding
99
99
the length in bytes, excluding the prefix and the trailing HMAC.
100
100
101
101
# Key Generation
@@ -163,7 +163,7 @@ It is 1300 bytes long and has the following structure:
163
163
164
164
1. type: `hop_payloads`
165
165
2. data:
166
-
*[`varint`:`length`]
166
+
*[`bigsize`:`length`]
167
167
*[`hop_payload_length`:`hop_payload`]
168
168
*[`32*byte`:`hmac`]
169
169
* ...
@@ -523,10 +523,10 @@ For each hop in the route, in reverse order, the sender applies the
523
523
following operations:
524
524
525
525
- The _rho_-key and _mu_-key are generated using the hop's shared secret.
526
-
-`shift_size` is defined as the length of the `hop_payload` plus the varint encoding of the length and the length of that HMAC. Thus if the payload length is `l` then the `shift_size` is `1 + l + 32` for `l < 253`, otherwise `3 + l + 32` due to the varint encoding of `l`.
526
+
-`shift_size` is defined as the length of the `hop_payload` plus the bigsize encoding of the length and the length of that HMAC. Thus if the payload length is `l` then the `shift_size` is `1 + l + 32` for `l < 253`, otherwise `3 + l + 32` due to the bigsize encoding of `l`.
527
527
- The `hop_payload` field is right-shifted by `shift_size` bytes, discarding the last `shift_size`
528
528
bytes that exceed its 1300-byte size.
529
-
- The varint-serialized length, serialized `hop_payload` and `hmac` are copied into the following `shift_size` bytes.
529
+
- The bigsize-serialized length, serialized `hop_payload` and `hmac` are copied into the following `shift_size` bytes.
530
530
- The _rho_-key is used to generate 1300 bytes of pseudo-random byte stream
531
531
which is then applied, with `XOR`, to the `hop_payloads` field.
532
532
- If this is the last hop, i.e. the first iteration, then the tail of the
@@ -662,7 +662,7 @@ The routing information is then deobfuscated, and the information about the
662
662
next hop is extracted.
663
663
To do so, the processing node copies the `hop_payloads` field, appends 1300 `0x00`-bytes,
664
664
generates `2*1300` pseudo-random bytes (using the _rho_-key), and applies the result, using `XOR`, to the copy of the `hop_payloads`.
665
-
The first few bytes correspond to the varint-encoded length `l` of the `hop_payload`, followed by `l` bytes of the resulting routing information become the `hop_payload`, and the 32 byte HMAC.
665
+
The first few bytes correspond to the bigsize-encoded length `l` of the `hop_payload`, followed by `l` bytes of the resulting routing information become the `hop_payload`, and the 32 byte HMAC.
666
666
The next 1300 bytes are the `hop_payloads` for the outgoing packet.
667
667
668
668
A special `hmac` value of 32 `0x00`-bytes indicates that the currently processing hop is the intended recipient and that the packet should not be forwarded.
@@ -1000,7 +1000,7 @@ The CLTV expiry in the HTLC is too far in the future.
1000
1000
1001
1001
1. type: PERM|22 (`invalid_onion_payload`)
1002
1002
2. data:
1003
-
*[`varint`:`type`]
1003
+
*[`bigsize`:`type`]
1004
1004
*[`u16`:`offset`]
1005
1005
1006
1006
The decrypted onion per-hop payload was not understood by the processing node
0 commit comments