Skip to content

BIPs 455–457: SwiftSync Specification - #2152

Open
rustaceanrob wants to merge 3 commits into
bitcoin:masterfrom
rustaceanrob:swiftsync-bips
Open

rustaceanrob wants to merge 3 commits into
bitcoin:masterfrom
rustaceanrob:swiftsync-bips

Conversation

@rustaceanrob

Copy link
Copy Markdown
Member

SwiftSync is a protocol for clients to parallelize initial block download, based on the original writeup.

@murchandamus murchandamus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick first glance, but could you please break your text into shorter lines? That makes it easier to leave review and track what changed between commits. Either 100 or 120 characters per line seems to work well enough.

Comment thread bip-0457.md Resolved
Comment thread bip-xxxx-swiftsync.md Resolved
@murchandamus murchandamus added New BIP PR Author action required Needs updates, has unaddressed review comments, or is otherwise waiting for PR author labels May 6, 2026
@jonatack jonatack changed the title SwiftSync Specification BIP drafts: SwiftSync Specification May 6, 2026
@jonatack

jonatack commented May 6, 2026 •

Copy link
Copy Markdown
Member

FWIW, I don't mind the unbroken lines and even prefer them. Avoids rejigging line lengths to keep them consistent when updating or having lines with very different lengths.

@danielabrozzoni danielabrozzoni left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did an initial pass and left some comments. I read the BIPs in the commit order (block undo -> histfile -> swiftsync) and it was pretty easy to follow.

Comment thread bip-xxxx-block-undo.md Resolved
Comment thread bip-xxxx-block-undo.md Resolved
Comment thread bip-xxxx-block-undo.md Resolved
Comment thread bip-xxxx-block-undo.md Resolved
Comment thread bip-xxxx-block-undo.md Resolved
Comment thread bip-xxxx-block-undo.md Resolved
Comment thread bip-xxxx-block-undo.md Resolved
Comment thread bip-xxxx-block-undo.md Resolved
Comment thread bip-xxxx-block-undo.md Resolved

@jurraca jurraca left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some writing nits but overall the concept is clear enough.

Comment thread bip-xxxx-block-undo.md Resolved
Comment thread bip-xxxx-block-undo.md Resolved
Comment thread bip-xxxx-block-undo.md Resolved
@rustaceanrob
rustaceanrob force-pushed the swiftsync-bips branch 2 times, most recently from 92093e1 to f4cd99a Compare May 10, 2026 09:31
@murchandamus

Copy link
Copy Markdown
Member

Thanks for the review, @danielabrozzoni and @jurraca, as well as the quick turnaround @rustaceanrob. I notice that this pull request is still marked as a Draft PR. Are you still planning significant changes? If your submission is ready for another BIP Editor review, please mark the PR as "ready for review".

@rustaceanrob

Copy link
Copy Markdown
Member Author

I will keep these as a draft as the hintsfile format is subject to change.

Comment thread bip-0455.md Resolved
Comment thread bip-xxxx-block-undo.md Resolved
Comment thread bip-xxxx-block-undo.md Resolved
Comment thread bip-0455.md
| Amount | 64 bit unsigned integer | Defined above | Satoshi denominated value |
### Messages

#### MSG_GET_SPENT_COINS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that a peer would issue this request for every block in the chain? If we assume mainnet at height, and a 150 ms round trip time, then a peer would spend nearly 80 hours just downloading this undo data.

You may want to consider a batched variant, similar to the way messages like getheaders works.

@rustaceanrob rustaceanrob Jun 22, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've found that bandwidth throughput is the limiting factor when downloading blocks in parallel. Not all spent coins have to be downloaded if a client keeps a cache, as this document describes. In the batched variant, the cache is not possible and the bandwidth requirement increases significantly.

Comment thread bip-xxxx-block-undo.md Outdated

| Field | Value |
| :----------------- | :---------- |
| `NODE_BLOCK_UNDO` | `1 << ???` |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rationale should be added for the choice of a new node version over the more common place (as of the past few years) exchange of a sendX message during the version handshake.

IMO a version makes sense here, as it can be used to filter out peers upfront that support sending this undo data over the network.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted for a BIP-434 feature message, which has a similar mechanism for the sendX

Comment thread bip-0455.md

#### MSG_SPENT_COINS

`MSG_SPENT_COINS` defines the data structure for inputs of a block.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not really y'all's intended use case, but if you optionally make it possible to include merkle proofs for the set of coins, then this message can be used to obtain a proof that an output was spent in a given block.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would actually also be useful for BIP 157+158 peers, as the final version that shipped includes the script spent (instead of the outpoint), which means that if you're using the filters to find a block where a given script has been spent, you need to make some assumptions about what the prev script is for a given transaction.

@rustaceanrob rustaceanrob Jun 23, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most recent response on this mailing list post mentions commitment to the UTXO set as part of the block header. There are additional ways to do this outside of a soft fork as well, i.e. utreexo proofs. For now I think it best to leave this unspecified in this version of the message while the community shares ideas, but I do think this is interesting.

Comment thread bip-xxxx-swiftsync.md Resolved
@rustaceanrob

Copy link
Copy Markdown
Member Author

Wrapped text and standardized formatting with mdformat, will address outstanding feedback soon.

@murchandamus

Copy link
Copy Markdown
Member

Great, thanks! I’ll give it a read when you’re done with that.

melvincarvalho added a commit to bitcoin-kernel/kernel that referenced this pull request Jun 20, 2026
hintsfile.js implements the SwiftSync hintsfile (bitcoin/bips#2152 'Hints for
unspent coins'): per-block unspent output indices encoded with Elias-Fano
(CompactSize(n) || CompactSize(m) || L || H; low bits LSB-first, unary gap high
bits), plus the 'UTXO' magic/version/height/vector container.

This is the ONE cross-compatibility artifact (per Somsen), so it's validated
byte-for-byte against the BIP's own elias_fano.json vectors — all three match,
plus round-trips, edge cases, and a container round-trip. Exported from index +
package exports (./hintsfile).
melvincarvalho added a commit to bitcoin-kernel/kernel that referenced this pull request Jun 20, 2026
…matches BIP vectors

undo.js implements the full-validation spent-coin data (bitcoin/bips#2152 'Peer
sharing of block spent coins'): Core's CompressAmount/DecompressAmount, the
reconstructable-script prefix table (P2PKH/P2SH/P2PK/P2WPKH/P2WSH/P2TR/raw), the
height code (height<<1|coinbase), and a spent-coin record. Amount + script
compression validated byte-for-byte against the BIP's compressed_amount.json and
reconstructable_script.json vectors (+ round-trips).

Also factored CompactSize/concat into varint.js, shared by hintsfile + undo.
Full suite: 21 pass / 0 fail.
@rustaceanrob rustaceanrob changed the title BIP drafts: SwiftSync Specification BIPs: SwiftSync Specification Jun 22, 2026
@rustaceanrob
rustaceanrob marked this pull request as ready for review June 22, 2026 08:54
@rustaceanrob

Copy link
Copy Markdown
Member Author

Given there are a few clients that have started implementations of SwiftSync, and new hintsfile encodings may simply increment the file version, I am moving these out of draft. Some outstanding comments addressed, others require some additional thought.

@rustaceanrob
rustaceanrob force-pushed the swiftsync-bips branch 5 times, most recently from 24ae4e7 to ecbda2a Compare June 23, 2026 09:00
@jonatack jonatack removed the PR Author action required Needs updates, has unaddressed review comments, or is otherwise waiting for PR author label Jun 23, 2026

@edilmedeiros edilmedeiros left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for documenting the protocol in this draft.

Did a deep dive together with the guys from @vinteumorg and left many comments concerning conceptual aspects of the BIPs. I have many editing suggestions, but left them for a second round after the higher-level aspects are more mature.

Comment thread bip-xxxx-hintsfile.md Resolved
Comment thread bip-xxxx-hintsfile.md Resolved
Comment thread bip-xxxx-hintsfile.md Outdated
in Bitcoin Core, and reasonable for most clients to hold directly in memory. This encoding represents elements in $2n +
n \\lceil \\log_2(m/n) \\rceil$ bits, which is within a reasonable bound of the theoretical optimum.

Partitioning the hints by block is an intuitive choice, and allows for efficient random access of hints. Groupings of

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partitioning the hints by block is an intuitive choice, and allows for efficient random access of hints.

I don't see how this can be true: the bistream has a header (magic, version, height) followed by a sequence of EliasFano items, each of which are composed by N, M (fixed size info), L, H (variable size info).

So, imagine I have a hintsfile. To find data for block k, one do need to (minimally) process data for block 1 to discover the size of the first EliasFano item (because of the variable size parts). Then, block 2 and so forth, until the intended block target. This would be true if the EliasFano items were fixed size among all blocks to allow for offset arithmetic, but the amount of padding would be prohibitively high.

Thus, the hints payload works more like a List<EliasFano> (requires sequential access) than a vector<EliasFano> (allows random access). Of course, the decoder could create an index of offsets, but this is not only an implementation detail, but also something that will add to the required resources to process the hintsfile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, the original version had a header section, but was removed as it could be reconstructed as you described. I will remove that note.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if having more blocks taken together will not improve compression sensibly (I'll experiment with it). We can add a counter in the bitstream to allow the encoder to choose it freely (at the cost of having more bytes in the bitstream) but we potentially gain:

  1. Less H, L pairs in the bitstream.
  2. More data to feed to the Elias-fano process (tends to push it closer to the theoretical entropy).

Comment thread bip-xxxx-hintsfile.md Resolved
Comment thread bip-xxxx-hintsfile.md Resolved
Comment thread bip-xxxx-swiftsync.md Resolved
Comment thread bip-xxxx-swiftsync.md Resolved
Comment thread bip-xxxx-swiftsync.md Resolved
Comment thread bip-xxxx-swiftsync.md Resolved
Comment thread bip-xxxx-swiftsync.md Resolved
@rustaceanrob
rustaceanrob force-pushed the swiftsync-bips branch 5 times, most recently from 3631bcb to 0776320 Compare July 15, 2026 13:11
@rustaceanrob

Copy link
Copy Markdown
Member Author

Updated bip-0457 with feedback. For bip-0456 I will let @edilmedeiros take a pass. Thanks for the review @murchandamus

@murchandamus

Copy link
Copy Markdown
Member

Thanks, looks great

@edilmedeiros

Copy link
Copy Markdown
Contributor

Going though a round of review now. Sorry for being lagging behind this days.

@edilmedeiros
edilmedeiros force-pushed the swiftsync-bips branch 2 times, most recently from aa09bb0 to 35d283a Compare July 28, 2026 03:42
@edilmedeiros

edilmedeiros commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

@murchandamus about bip 456, I reworked the document to address your comments:

  1. abstract now only specifies what this bip specifies
  2. motivation now focuses on why the hintsfile is useful. It was conflating with the rationale, so I moved/edited parts of it to that section.
  3. tried to tighten the specification part: hintsfile serialization, then ellias-fano serialization, then how the elias-fano encoding should be performed (top-down, or external to internal objects, approach).
  4. tried to make the elias-fano encoding process more operational, I hope it's easier to follow now.

You didn't mentioned specifically, but I also made the variables names more consistent among the mathematical notation and code (fixed-width).

Added this to a separate commit to make the review (and rollback, if needed) easier. Can squash before merging.

@murchandamus

Copy link
Copy Markdown
Member

Thanks @edilmedeiros sounds great. I’m going to take another look soon.

@murchandamus murchandamus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave BIP455 another read. I did not compare in detail to the previous feedback, but it was a smooth read and looks great. I just have a few nits.

Comment thread bip-0455.md Resolved
Comment thread bip-0455.md Resolved
Comment thread bip-0455.md Resolved
Comment thread bip-0455.md Resolved
Comment thread bip-0455.md Resolved
Comment thread bip-0455.md Resolved
Comment thread bip-0455.md Resolved
Comment thread bip-0455.md Resolved
Comment thread bip-0455.md Resolved
Comment thread bip-0455.md Resolved
@edilmedeiros

Copy link
Copy Markdown
Contributor

I just have a few nits.

Fixed those, thanks.

@edilmedeiros edilmedeiros left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed we are lacking BIP324 message type definitions in these two spots. I prefer to let @rustaceanrob pick them. Happy to do the rebase stuff if you just want to put them in this chat.

Comment thread bip-0455.md Resolved
Comment thread bip-0455.md Resolved
@rustaceanrob

Copy link
Copy Markdown
Member Author

I think it makes sense to just use the next in the sequence, so 38 and 39 for MSG_GET_SPENT_COINS and MSG_SPENT_COINS respectively.

@murchandamus murchandamus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave BIP456 and BIP457 another full read. Well done, I don’t have any additional remarks beyond noticing that the todos that @edilmedeiros raised still seem to be unaddressed and there being a merge conflict on the README.mediawiki.

Comment thread bip-0455.md Resolved
Comment thread bip-0455.md Resolved
@murchandamus murchandamus added the PR Author action required Needs updates, has unaddressed review comments, or is otherwise waiting for PR author label Nov 18, 2026
Comment thread bip-0455.md

Inputs of a Bitcoin block are referenced by the outpoint data structure. This commonly poses a limitation during initial
block download (IBD), such that a client must process blocks sequentially to validate the chain history. The SwiftSync
protocol allows blocks to be evaluated in arbitrary order, however additional data is required that must be served over

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be mentioned that there is more than "additional data" required to reap the aforementioned benefit of this proposal. Namely, that this enhancement requires the transmission of a new file (a hints file) from an un-trusted source. As the Abstract, Motivation and Specification and remainder of document read, you may be lead to believe that no such hints file is needed, which makes the entire spec incomprehensible from a high-level without at least mention of this detail.

@rustaceanrob

Copy link
Copy Markdown
Member Author

Going to rebase and squash with after addressing some todos next week. Thanks for the re-read @murchandamus!

rustaceanrob and others added 2 commits December 1, 2026 13:02

@murchandamus murchandamus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This jumped out at me, looking at the diff from the prior version. Will take another look when I get back to a computer.

Comment thread bip-0456.md
Comment on lines +126 to +128
Bitstrings are serialized to bytes by packing bits least-significant-bit first: bit $j$ of a bitstring is stored at bit
position $j \bmod 8$ of byte $\lfloor j / 8 \rfloor$, where bit position 0 is the least significant bit of a byte. Any
unused bits in the final byte are set to `0`.

@murchandamus murchandamus Dec 2, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s probably mostly a me-issue, but I had to read lines 126–128 five times to grok what you mean with the first sentence.

My first attempt at feedback was “Huh, bitststrings don’t have ‘least-significant-bits’ because they are not numbers?!”.
I thought that least-significant-bits was referring to the “last bit of the bitstring” and figured that if I were to put the last bit of the bitstring as the first bit of a byte, for a bitstring 111100 the byte would start with 001111…. If that were zero padded, 111100 would become 0x3C (the last bit 0 becomes the first bit of the byte, followed by another 0, then the four ones, and then two zeros padding are added).

The more formal explanation that follows is clearer, but it’s not obvious to me whether byte 0 would refer to the left-most or right-most byte. Presumably, the right most?

After several reads, and comparing to the examples in lines 171–172, I now interpret the first sentence as:

Bitstrings are serialized to bytes by putting the first bit of the bitstring into the the least-significant-bit of the last byte, the second bit into the next-least-significant-bit, etc.

I was unable to clarify the byte order, because all example bitstrings are fewer than 8 bits.

Do I understand right, that right-padding the bitstring with zeroes to the next multiple of 8, and then populating the bytes with the reverse would be equivalent to what you are specifying?

Given what a mess Bitcoin is regarding endianness, perhaps the phrasing here could be clarified?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To say it more concisely, this bit seems ambiguous to me regarding byte-order and serialization. How would a bitstring 11010010001 be serialized as bytes? 0x084b, 0x4b08, or something else again?

@rustaceanrob rustaceanrob Dec 3, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this example, here's what I have in mind:

  • Split 11010010001 into 8 bit portions 11010010 001
  • Pad 001 to 00100000
  • Iterate those chunks, staring with 11010010
  • Pack the bits in LSB order into the byte, which gives 0x4B
  • Do it again for 00100000, which I get 0x04 (one power of two different than 0x08 in your outcomes)

I decided to add this because I was packing MSB for no particular reason in the reference implementation, which of course leads to a different encoding. I thought it best to be thorough here. How does this sound?

L and H are bitstrings. Throughout this document, a bitstring is serialized to bytes least significant bit first:
bit $j$ of a bitstring is stored at bit position $j \bmod 8$ of byte $\lfloor j / 8 \rfloor$, where bit position 0 is
the least significant bit of a byte, bytes are serialized in ascending order, and unused bits of the final byte are
set to 0. For example, the bitstring 11010010001 is serialized as the two bytes 0x4B 0x04.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New BIP PR Author action required Needs updates, has unaddressed review comments, or is otherwise waiting for PR author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants