SwiftSync is a protocol to accelerate initial block download (IBD) using existing cryptographic primitives and minimal state. The protocol is compromised of hash aggregate for a set of elements and a "hintsfile" to indicate the spent-ness of outputs in the chain history. Using these hints, clients may perform IBD in parallel, which maximizes the use of existing system resources and shifts the performance limitations to internet quality.
Initial block download is the first user experience when using Bitcoin software, and, moreover, is a bootstrapping cost for second layer protocols. Improvements to this process benefit end-users and scaling protocols alike. IBD faces two limitations. First, although the lifetime of coins demonstrates an empirical distribution, cache misses occur for coins that are deleted. This creates unnecessary disk I/O and database compaction. Secondly, given the structure of a block, coins that are spent are indexed by their outpoint. This creates a requirement for clients to maintain a cache to fetch coin metadata associated with an outpoint. SwiftSync alleviates both of these limitations, allowing for IBD with assume-valid assumptions in as fast as 66 minutes.
-
$H_{salt}$ : The SHA-256 hashing function with client generated salt -
$Hintsfile_{n}$ : Defined in BIP ??? -
$UTXO_{n}$ : Unspent outputs at block height$n$
SwiftSync builds on a common observation in cryptography, that verification is often orders of magnitude more performant than computation. What a client seeks to verify when performing SwiftSync is that a unspent transaction output (UTXO) set indeed corresponds to the chain history downloaded from peers.
A key invariant is that a UTXO set state at height
Given this relationship between the two sets, a client uses hints to
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
A client must compare
To add an element to an aggregate, a client computes the
When computing the aggregate, a client MUST use a random, client-side generated salt.
Block validation when performing SwiftSync is nearly the same, only with a few additional steps. First, a client requires a
When downloading blocks, SwiftSync clients will do the following:
- Download the required block undo data defined in BIP ???
- Using the undo data, validate the block. A non-exhaustive but explicit list of steps include:
- Check the coinbase does not over-claim the block subsidy
- Check the number of signature operations
- Validate all script executions succeed
- Validate non-contextual checks like merkle roots and timestamps
- If the block is invalid, disconnect the peer. If the block is valid, continue
- For all inputs, except the coinbase, add them to
$Agg_{inputs}$ - For all outputs:
- If the output is unspendable, continue
- Add the output to
$UTXO_{n}$ if the output is in$Hintsfile_{n}$ and continue - Otherwise, add the output to
$Agg_{outputs}$
Notice here that a client does not have to download blocks in any particular order, and may download blocks from multiple peers at a time. A client then verifies
While there are hash functions, such as siphash, that may offer a performance improvement compared to SHA-256, consensus is already dependent on the cryptographic assumptions of SHA. Thus, SHA-256 was selected to circumvent adding new cryptographic assumptions to IBD. For the aggregate construction, one may observe that, rather than using two aggregates, adding
On griefing, a malicious peer may construct undo data that is valid for the given block, yet it is not spending the correct coins in the history for the chain of most work. Take, for example, a trivially spendable output. The malicious peer may use any script when serving the block inputs, which will alter the output of
During the period between BIP-30 activation and BIP-34 activation, a SwiftSync client must check for duplicate coinbase outputs. A cache of these outputs is modest in memory footprint, and may be easily added and queried for the fixed block range.
The protocol may be easily extended, and rather simplified, with similar assumptions to assume valid. Rather than hashing the entirety of coin data, a client may take
This does introduce an additional check, however, that inflation has not been introduced. At the end of the protocol, the client must also check the total value introduced in the system is less than the expected value for the height
swiftsyncRust implementation
Kudos to my colleague Ruben Somsen for creating the protocol described in this specification