Repository navigation
sv2: use a one-byte length for STR0_255, B0_255 and SEQ0_255 - #166
Merged
Merged
Conversation
The spec encodes STR0_255 with a one-byte length, but SetupConnection was read with Bitcoin's CompactSize length. The two agree up to 252 bytes, so a valid 253-255 byte vendor, firmware or other string made sv2-tp reject the message and disconnect the client.
xyephy
marked this pull request as draft
November 12, 2026 11:25
Collaborator
|
Nice catch! Why is it draft? |
xyephy
marked this pull request as ready for review
November 12, 2026 12:20
Contributor
Author
was waiting on some tests, now its good to go. |
Sjors
reviewed
Nov 12, 2026
Comment on lines
-380
to
-381
| // Technically using VARINT is a problem for a merkle path longer | ||
| // than 127 elements, but a block can't have enough transactions to |
Collaborator
There was a problem hiding this comment.
My original comment here was wrong, as I was confusing VARINT with CompactSize.
Error codes, the coinbase prefix and the merkle path were also written with a CompactSize length. The bytes are the same for every value sv2-tp sends today, so this only aligns the code with the spec. Values over 255 now throw instead of producing an invalid message.
xyephy
force-pushed
the
2026/11/sv2-short-lengths
branch
from
November 12, 2026 13:27
b5ed334 to
6512db0
Compare
Collaborator
|
ACK 6512db0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The spec encodes
STR0_255andB0_255as a one-byte length followed by the bytes, andSEQ0_255as a one-byte count. sv2-tp used Bitcoin's default serialization, which writes a CompactSize length. The two agree up to 252 and differ from 253 up.The first commit fixes the receive side. A
SetupConnectionwith a valid 253-255 byte string (vendor, firmware, etc.) failed to parse, and sv2-tp disconnected the client with "Received invalid SetupConnection message". It adds a message test for 252-255 byte strings and a connman test that sends a 255-byte vendor and expectsSetupConnection.Success. Thesv2_setup_connectionfuzz target wrote its input with CompactSize too, so it couldn't catch this; it now uses the spec encoding.The second commit does the same for the fields sv2-tp sends: the
SetupConnection.ErrorandRequestTransactionData.Errorerror codes, the coinbase prefix, and the merkle path. The output bytes don't change for any value sv2-tp sends today. Values over 255 now throw instead of producing an invalid message. It also drops the merkle path comment, which wrongly described the encoding as VARINT.