Difference between revisions of "Simplified Payment Verification"

Line 1: Line 1:
Simplified Payment Verification (SPV) is described in section 8 of the [[Bitcoin whitepaper]]. It allows a user to prove or verify that a transaction is in the [[Block chain]] without downloading the full chain.
+
Simplified Payment Verification (SPV) is described in section 8 of the [[Bitcoin whitepaper]]. It allows a user to prove or verify a payment to them without downloading the full [[Block chain]], by utilising the properties of Merkle proofs. An SPV client "only needs to keep a copy of the block headers of the longest proof-of-work chain, which he can get by querying network nodes until he's convinced he has the longest chain, and obtain the Merkle branchlinking the transaction to the block it's timestamped in." (link to bitcoin whitepaper) This block header chain is many orders of mangitude smaller than the entire blockchain (with all transactions in it) since it only grows by a fixed amount over time regardless of how big the blockchain grows. "A block header with no transactions would be about 80 bytes. If we suppose blocks aregenerated every 10 minutes, 80 bytes * 6 * 24 * 365 = 4.2MB per year." (link to bitcoin whitepaper)
  
To '''create''' a Merkle proof, a user or (or their wallet) simply needs the '''[[Block_hashing_algorithm#Block_Header|block header]]''' for a given block (80 bytes) and the '''Merkle path''' within that block of the transaction they need to validate. Together, these two items will be sufficient to prove that a given transaction exists in the chain at a given block height.
 
 
To '''validate''' a proof, a user (or their wallet) only needs the 80 byte header for the block where the transaction appeared.  They don't need all of the transactions within block (which could be very large).  By computing the hash of the transaction and the Merkle root, the user can compare it with the Merkle root in the block header. If it matches, then the validation is successful.
 
  
 
===Advantages===
 
===Advantages===
 
The advantages of using SPV are clear in terms of the volume of data required:
 
The advantages of using SPV are clear in terms of the volume of data required:
  
* a wallet can store '''all necessary block headers in around 50MB - this covers  the entire block chain''' (as at January 2020, with 80 bytes per block and around 620,000 blocks in the chain). The total '''grows linearly''' at around 4MB per year (i.e. it increases by 80 bytes with each block mined, regardless of the size of that block).
+
* a wallet can store '''all necessary block headers in around 50MB - this covers  the entire block chain''' (as of January 2020, with 80 bytes per block and around 620,000 blocks in the chain). The total '''grows linearly''' at around 4MB per year (i.e. it increases by 80 bytes with each block mined, regardless of the size of that block).
  
 
* contrast this with the '''hundreds of gigabytes''' which would be required to store the entire chain, if SPV were not being used.
 
* contrast this with the '''hundreds of gigabytes''' which would be required to store the entire chain, if SPV were not being used.
  
 
* The size of the data required for the '''merkle paths''' is of maximum <math>64log_{2}{n}</math> bytes, where <math>n</math> is the total number of transaction in one block.  
 
* The size of the data required for the '''merkle paths''' is of maximum <math>64log_{2}{n}</math> bytes, where <math>n</math> is the total number of transaction in one block.  
 +
 +
SPV allows users to securely transact with each other, peer-to-peer, while nodes act to form the settlement layer.
 +
  
 
===Approach===
 
===Approach===
An article in March entitled [https://craigwright.net/blog/bitcoin-blockchain-tech/merkle-trees-and-spv Merkle Trees and SPV] (Craig Wright, 2019) clarified some previous misunderstandings around SPV and transaction verification. Previously, the custom had been for the person receiving a payment to poll the block chain repeatedly, to confirm that their transaction had reached a certain depth (say 6 blocks deep). Dr Wright stated that this was unnecessary:
+
There have been a lot of previous misunderstandings around SPV and peer-to-peer transacting. Previously, the custom had been for the sender of the payment to just broadcast the payment to the bitcoin network nodes. The receiver of the payment would then need to somehow filter through all of the transactions coming onto the blockchain for specific tranasactions relating to them (an extremely diffficult task in of itself). Even if the sender sent the transaction to the receiver as well as the network nodes, the custom had been for the receiver to always wait for the transaction to be burried into the blockchain at least 6 blocks deep whatever the transaction type or amount or situation.
  
{{quote|
+
Transactions between SPV clients are negotiated peer-to-peer and settled on the blockchain through the network nodes. An analogy for this is a transaction done using checks at a much faster speed. The customer hands the the signed check (transaction) to the merchant who then cashes the check (settles the transaction). When/if the merchant is satisfied according to the situtational risk of the transaction, then they can hand over the goods or services. There is no such thing as absolute security, there is always a risk against the cost of being defrauded (which increases exponentially as time goes by). If the transaction is only for a cup of coffee, then the merchant might incur more risk than if the transaction was for a car for example.
In contrast, the present invention requires that the necessary SPV check be performed on a transaction’s inputs '''prior to its broadcast''' [emphasis added]. The shift in emphasis greatly reduces the burden and traffic on the network in dealing with invalid transactions.
 
  
A second important paradigm in the existing [i.e. the prior] SPV system is that an SPV client must '''query full nodes''' [emphasis added] on the network to obtain the Merkle path required for the SPV check ...  SPV checks that '''remove such burden on the network''' [emphasis added], by stipulating the lightweight Bitcoin client where users keep, maintain, or at least have access to their own copies of Merkle paths pertinent to the unspent transaction outputs owned by them, '''allow Bitcoin to scale'''. [emphasis added]
+
An article in March entitled [https://craigwright.net/blog/bitcoin-blockchain-tech/merkle-trees-and-spv Merkle Trees and SPV] (Craig Wright, 2019) clarified some previous misunderstandings around SPV and transaction verification. The article included the following diagram which shows how transaction hashes can be related to the Merkle root in a block header:
}}
 
 
 
The article referenced above included the following diagram which shows how transaction hashes can be related to the Merkle root in a block header:
 
  
 
[[File: Merkle_tree2.png|frameless|1000px|alt=Three transactions and the Merkle paths which can be used to relate them to blocks]]
 
[[File: Merkle_tree2.png|frameless|1000px|alt=Three transactions and the Merkle paths which can be used to relate them to blocks]]
  
 
===Merkle Trees and Merkle Paths===
 
===Merkle Trees and Merkle Paths===
A Merkle Tree is a structure used in computer science to validate data - see [https://en.wikipedia.org/wiki/Merkle_tree https://en.wikipedia.org/wiki/Merkle_tree] for more information
+
A Merkle Tree is a structure used in computer science to validate data - see [https://en.wikipedia.org/wiki/Merkle_tree https://en.wikipedia.org/wiki/Merkle_tree] for more information.
 +
 
 +
To '''create''' a Merkle proof which proves the existence of a specific transaction in a specific block, a user or (or their wallet) simply needs the Merkle path of the transaction as well as the '''[[Block_hashing_algorithm#Block_Header|block header]]''' for a given block (80 bytes).
 +
 
 +
To '''validate''' a proof, a user (or their wallet) only needs the chain of block headers (as opposed to the whole blockchain). Using the block header chain, the transaction (or its hash/id), as well as its Merkle proof (also sometimes referred to as an inclusion proof), one does not need any additional information to prove that the specific transaction existed in the specific block.
 +
 
  
 
===SPV Wallet===
 
===SPV Wallet===

Revision as of 14:38, 22 January 2020

Simplified Payment Verification (SPV) is described in section 8 of the Bitcoin whitepaper. It allows a user to prove or verify a payment to them without downloading the full Block chain, by utilising the properties of Merkle proofs. An SPV client "only needs to keep a copy of the block headers of the longest proof-of-work chain, which he can get by querying network nodes until he's convinced he has the longest chain, and obtain the Merkle branchlinking the transaction to the block it's timestamped in." (link to bitcoin whitepaper) This block header chain is many orders of mangitude smaller than the entire blockchain (with all transactions in it) since it only grows by a fixed amount over time regardless of how big the blockchain grows. "A block header with no transactions would be about 80 bytes. If we suppose blocks aregenerated every 10 minutes, 80 bytes * 6 * 24 * 365 = 4.2MB per year." (link to bitcoin whitepaper)


Advantages

The advantages of using SPV are clear in terms of the volume of data required:

  • a wallet can store all necessary block headers in around 50MB - this covers the entire block chain (as of January 2020, with 80 bytes per block and around 620,000 blocks in the chain). The total grows linearly at around 4MB per year (i.e. it increases by 80 bytes with each block mined, regardless of the size of that block).
  • contrast this with the hundreds of gigabytes which would be required to store the entire chain, if SPV were not being used.
  • The size of the data required for the merkle paths is of maximum bytes, where is the total number of transaction in one block.

SPV allows users to securely transact with each other, peer-to-peer, while nodes act to form the settlement layer.


Approach

There have been a lot of previous misunderstandings around SPV and peer-to-peer transacting. Previously, the custom had been for the sender of the payment to just broadcast the payment to the bitcoin network nodes. The receiver of the payment would then need to somehow filter through all of the transactions coming onto the blockchain for specific tranasactions relating to them (an extremely diffficult task in of itself). Even if the sender sent the transaction to the receiver as well as the network nodes, the custom had been for the receiver to always wait for the transaction to be burried into the blockchain at least 6 blocks deep whatever the transaction type or amount or situation.

Transactions between SPV clients are negotiated peer-to-peer and settled on the blockchain through the network nodes. An analogy for this is a transaction done using checks at a much faster speed. The customer hands the the signed check (transaction) to the merchant who then cashes the check (settles the transaction). When/if the merchant is satisfied according to the situtational risk of the transaction, then they can hand over the goods or services. There is no such thing as absolute security, there is always a risk against the cost of being defrauded (which increases exponentially as time goes by). If the transaction is only for a cup of coffee, then the merchant might incur more risk than if the transaction was for a car for example.

An article in March entitled Merkle Trees and SPV (Craig Wright, 2019) clarified some previous misunderstandings around SPV and transaction verification. The article included the following diagram which shows how transaction hashes can be related to the Merkle root in a block header:

Three transactions and the Merkle paths which can be used to relate them to blocks

Merkle Trees and Merkle Paths

A Merkle Tree is a structure used in computer science to validate data - see https://en.wikipedia.org/wiki/Merkle_tree for more information.

To create a Merkle proof which proves the existence of a specific transaction in a specific block, a user or (or their wallet) simply needs the Merkle path of the transaction as well as the block header for a given block (80 bytes).

To validate a proof, a user (or their wallet) only needs the chain of block headers (as opposed to the whole blockchain). Using the block header chain, the transaction (or its hash/id), as well as its Merkle proof (also sometimes referred to as an inclusion proof), one does not need any additional information to prove that the specific transaction existed in the specific block.


SPV Wallet

An SPV wallet is a lightweight wallet that uses the mechanism of SPV to construct bitcoin transactions and payments.

To spend a UTXO, a user of a SPV wallet will pass on the following information to the receiver:

  1. - the transaction that contains the UTXO as an output,
  2. The Merkle path of
  3. The block header that contains the Merkle root derived from the Merkle path (or its identifier, e.g., block height)
  4. - the transaction that spends the UTXO

To validate the information, a user computes the Merkle root from the Merkle path of . The user then compares it with the Merkle root specified in the block header. If they are the same, the user accepts that is in the chain.

Offline Payment

Note that by storing locally, a user will be able to sign offline, as any signature on requires the scriptPubKey (locking script) part from .