I try to understand a SPV implementation.

I read the wiki pages on Protocol Specification and Thin Client Security as well as the white-paper's chapter 8 .

What I don't understand:
Assume user A has Bitcoin address X.
User A can do getheaders and load all block headers and then have all block hashes and timestamps.

So: how does a SPV client then find possible transactions to the user's Bitcoin address X without loading all blocks (and all transactions)?

up vote 16 down vote accepted

You are right that SPV as described in the Bitcoin paper does not explain how to discover payments to yourself, without downloading full blocks. My guess is that Satoshi either planned to develop this later, or that he assumed you'd just be told about payments to yourself (pay-to-IP, as existed next to pay-to-pubkeyhash as is used now).

Practical implementations of SPV nodes today however use a protocol extension called bloom filters, described in BIP 37. They use getheaders to fetch block information prior to their wallet's birth timestamp, and request filtered blocks afterwards. To do so, they submit a bloom filter that describes the addresses and transactions they are interested in to the peer. The peer then only includes the relevant transactions in blocks it submits, together with their Merkle paths to prove that these transactions were indeed part of said block.

If it helps https://gist.github.com/TOMOAKI12345/7e0aa1c6b8ace4a70ca6

Breadwallet source code is really good source to learn about the network protocol of SPV wallet.

Just found something in bitcoinj sourcecode:

/**
 * The "getheaders" command is structurally identical to "getblocks", but has different meaning. On receiving this
 * message a Bitcoin node returns matching blocks up to the limit, but without the bodies. It is useful as an
 * optimization: when your wallet does not contain any keys created before a particular time, you don't have to download
 * the bodies for those blocks because you know there are no relevant transactions.
 */

In addition to above answers, You could refer to this diagram if it helps from this link.

enter image description here

I think SPV is only meant to verify transactions, not calculate a balance or list of all transactions to a certain address.

  • 1
    But how does Multibit (a SPV thin-client) check for incomming payments so fast? – Jonas Schnelli May 20 '13 at 6:48
  • @Jonas, Multibit uses bloom filters, that why it can check for incomming payments that fast. – rdymac May 20 '13 at 20:53
  • 2
    I downvoted. Verifying transaction is exactly the thing SPV does not do: it only verifies the block chain, not the transactions in it. – Pieter Wuille Jun 19 '13 at 9:36
  • SPV clients can calculate balances and can list transactions to certain addresses by requesting filtered blocks. SPV clients also verify transaction validity by verifying the signatures; what SPV does not verify is inclusion of outputs in the utxo, so double spending is possible. – dionyziz Jan 25 '16 at 0:02
  • @dionyziz SPV clients cannot verify signatures, as they don't have the UTXO entries to know what to verify against. – Pieter Wuille Sep 5 '16 at 17:17

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.