mirror of
https://github.com/bitcoin/bips.git
synced 2026-10-19 19:29:18 +00:00
bip138: clarify that 0x00 ends payload parsing
Specify that parsing stops immediately. Add a vector with an item followed by a terminator and ignored bytes. Clarify that TYPE 0x00 also doesn't require TYPE_LENGTH.
This commit is contained in:
13
bip-0138.md
13
bip-0138.md
@@ -408,7 +408,7 @@ remaining bytes are `PADDING`. A `PAYLOAD` MUST contain at least one item (see
|
||||
|
||||
`TYPE_LENGTH`: variable-length integer representing the length of `TYPE_PARAMS` in bytes.
|
||||
|
||||
For all `TYPE` values except `0x01`, `TYPE_LENGTH` MUST be present.[^length-required]
|
||||
For all `TYPE` values except `0x00` and `0x01`, `TYPE_LENGTH` MUST be present.[^length-required]
|
||||
|
||||
[^length-required]: **Why is `TYPE_LENGTH` mandatory?**
|
||||
`TYPE_LENGTH` is what lets a parser skip a content type it does not implement and still
|
||||
@@ -417,20 +417,19 @@ For all `TYPE` values except `0x01`, `TYPE_LENGTH` MUST be present.[^length-requ
|
||||
implementation that only handles descriptors from recovering that descriptor. A
|
||||
type whose `TYPE_PARAMS` is always empty still carries a zero `TYPE_LENGTH` for this reason.
|
||||
`0x01` is exempt because every implementation handles it, so it is never skipped
|
||||
blindly.
|
||||
blindly. `0x00` is a terminator rather than a content item.
|
||||
|
||||
`TYPE_PARAMS`: variable-length field whose encoding depends on `TYPE`.
|
||||
|
||||
For `TYPE` values defined above:
|
||||
- 0x00: parsers MUST stop reading content items and treat the remaining bytes as
|
||||
padding.
|
||||
- 0x00: parsers MUST stop immediately and treat the remaining bytes as padding.
|
||||
- 0x01: `TYPE_LENGTH` MUST be omitted and `TYPE_PARAMS` is a 2-byte big-endian unsigned integer
|
||||
representing the BIP number that defines it.
|
||||
- 0x02: `TYPE_PARAMS` MUST be `TYPE_LENGTH` bytes of opaque, vendor-specific data.
|
||||
- 0x03: `TYPE_PARAMS` MUST be empty, and the following `CONTENT` is the string itself,
|
||||
which MUST be valid UTF-8.
|
||||
|
||||
For all `TYPE` values except `0x01`, parsers MUST reject `CONTENT_TYPE` if `TYPE_LENGTH` exceeds
|
||||
For all `TYPE` values except `0x00` and `0x01`, parsers MUST reject `CONTENT_TYPE` if `TYPE_LENGTH` exceeds
|
||||
the remaining payload bytes.
|
||||
|
||||
For an unknown `TYPE` less than `0x80`, parsers MUST consume its `TYPE_LENGTH` bytes of
|
||||
@@ -595,6 +594,10 @@ The version field enables possible future enhancements:
|
||||
vectors for key serialisations.
|
||||
[content_type.json](./bip-0138/test_vectors/content_type.json) contains test
|
||||
vectors for content types serialisations.
|
||||
[payload.json](./bip-0138/test_vectors/payload.json) contains test vectors for payload parsing.
|
||||
`payload` and each item's `content` are hexadecimal bytes; `type` is the numeric
|
||||
type byte, and `items` lists the content items before the terminator.
|
||||
|
||||
[derivation_path.json](./bip-0138/test_vectors/derivation_path.json) contains
|
||||
test vectors for derivation paths serialisations.
|
||||
[individual_secrets.json](./bip-0138/test_vectors/individual_secrets.json)
|
||||
|
||||
13
bip-0138/test_vectors/payload.json
Normal file
13
bip-0138/test_vectors/payload.json
Normal file
@@ -0,0 +1,13 @@
|
||||
[
|
||||
{
|
||||
"description": "Bytes after terminator are ignored",
|
||||
"valid": true,
|
||||
"payload": "030001610080ff",
|
||||
"items": [
|
||||
{
|
||||
"type": 3,
|
||||
"content": "61"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user