<div dir="ltr">Hi<br><br>Following earlier posts on Proof of Payment I&#39;m now proposing the following BIP (To read it formatted instead, go to <a href="https://github.com/kallerosenbaum/poppoc/wiki/Proof-of-Payment-BIP">https://github.com/kallerosenbaum/poppoc/wiki/Proof-of-Payment-BIP</a>).<br><br>Regards,<br>Kalle Rosenbaum<br><br>&lt;pre&gt;<br>  BIP: &lt;BIP number&gt;<br>  Title: Proof of Payment<br>  Author: Kalle Rosenbaum &lt;<a href="mailto:kalle@rosenbaum.se">kalle@rosenbaum.se</a>&gt;<br>  Status: Draft<br>  Type: Standards Track<br>  Created: &lt;date created on, in ISO 8601 (yyyy-mm-dd) format&gt;<br>&lt;/pre&gt;<br><br>== Abstract ==<br><br>This BIP describes how a wallet can prove to a server that it has the ability to sign a certain transaction.<br><br>== Motivation ==<br><br>There are several scenarios in which it would be useful to prove that you have paid for something. For example:<br><br>* A pre-paid hotel room where your PoP functions as a key to the door.<br>* An online video rental service where you pay for a video and watch it on any device.<br>* An ad-sign where you pay in advance for e.g. 2 weeks exclusivity. During this period you can upload new content to the sign whenever you like using PoP.<br>* Log in to a pay site using a PoP.<br>* A parking lot you pay for monthly and the car authenticates itself using PoP.<br>* A lottery where all participants pay to the same address, and the winner is selected among the transactions to that address. You exchange the prize for a PoP for the winning transaction.<br><br>With Proof of Payment, these use cases can be achieved without any personal information (user name, password, e-mail address, etc) being involved.<br><br>== Rationale ==<br><br>Desirable properties:<br><br># A PoP should be generated on demand.<br># It should only be usable once to avoid issues due to theft.<br># It should be able to create a PoP for any payment, regardless of script type (P2SH, P2PKH, etc.).<br># It should prove that you have enough credentials to unlock all the inputs of the proven transaction.<br># It should be easy to implement by wallets and servers to ease adoption.<br><br>Current methods of proving a payment:<br><br>* In BIP0070, the PaymentRequest together with the transactions fulfilling the request makes some sort of proof. However, it does not meet 1, 2 or 4 and it obviously only meets 3 if the payment is made through BIP0070. Also, there&#39;s no standard way to request/provide the proof. If standardized it would probably meet 5.<br>* Signing messages, chosen by the server, with the private keys used to sign the transaction. This could meet 1 and 2 but probably not 3. This is not standardized either. 4 Could be met if designed so.<br><br>If the script type is P2SH, any satisfying script should do, just like for a payment. For M-of-N multisig scripts, that would mean that any set of M keys should be sufficient, not neccesarily the same set of M keys that signed the transaction. This is important because strictly demanding the same set of M keys would undermine the purpose of a multisig address.<br><br>== Specification ==<br><br>=== Data structure ===<br><br>A proof of payment for a transaction T, here called PoP(T), is used to prove that one has ownership of the credentials needed to unlock all the inputs of T. It has the exact same structure as a bitcoin transaction with the same inputs and outputs as T and in the same order as in T. There is also one OP_RETURN output inserted at index 0, here called the pop output. This output must have the following format:<br><br> OP_RETURN &lt;version&gt; &lt;txid&gt; &lt;nonce&gt;<br><br>{|        <br>! Field        !! Size [B] !! Description<br>|-<br>| &amp;lt;version&gt; || 2        || Version, little endian, currently 0x01 0x00<br>|-<br>| &amp;lt;txid&gt;    || 32       || The transaction to prove<br>|-<br>| &amp;lt;nonce&gt;   || 6        || Random data<br>|}<br><br>The value of the pop output is set to the same value as the transaction fee of T. Also, if the outputs of T contains an OP_RETURN output, that output must not be included in the PoP because there can only be one OP_RETURN output in a transaction. The value of that OP_RETURN output is instead added to the value of the pop output.<br><br>An illustration of the PoP data structure and its original payment is shown below.<br><br>&lt;pre&gt;<br>  T<br> +----------------------------------------------+<br> |inputs       | outputs                        |<br> |       Value | Value   Script                 |<br> +----------------------------------------------+<br> |input0 1     |     0   pay to A               |<br> |input1 3     |     2   OP_RETURN &lt;some data&gt;  |<br> |input2 4     |     1   pay to B               |<br> |             |     4   pay to C               |<br> +----------------------------------------------+<br> <br>  PoP(T)<br> +----------------------------------------------------------+<br> |inputs       | outputs                                    |<br> |       Value | Value   Script                             |<br> +----------------------------------------------------------+<br> |input0 1     |     3   OP_RETURN &lt;version&gt; &lt;txid&gt; &lt;nonce&gt; |<br> |input1 3     |     0   pay to A                           |<br> |input2 4     |     1   pay to B                           |<br> |             |     4   pay to C                           |<br> +----------------------------------------------------------+<br>&lt;/pre&gt;<br><br>The PoP is signed using the same signing process that is used for bitcoin transactions.<br><br>The purpose of the nonce is to make it harder to use a stolen PoP; Once the PoP has reached the server, that PoP is useless since the server will generate a new nonce for every PoP request.<br><br>Since a PoP is indistinguishable from a bitcoin transaction, there is a risk that it, accidently or maliciously, enters the bitcoin p2p network. If T is still unconfirmed, or if a reorg takes place, chances are that PoP(T) ends up in a block, invalidating T. Therefore it is important that the outputs of the PoP are the same as in T. The zero transaction fee in PoP(T) is to minimize the incentives for miners to select PoP(T) for inclusion.<br><br>=== Process ===<br><br># A proof of payment request is sent from the server to the wallet. The PoP request contains:<br>## a random nonce<br>## a destination where to send the PoP, for example a https URL<br>## data hinting the wallet which transaction to create a proof for. For example:<br>##* txid, if known by the server<br>##* PaymentRequest.PaymentDetails.merchant_data (in case of a BIP0070 payment)<br>##* amount, label, message or other information from a BIP0021 URL<br># The wallet identifies a transaction T, if possible. Otherwise it asks the user to select among the ones that match the hints in 1.iii.<br># The wallet creates an unsigned PoP (UPoP) for T, and asks the user to sign it.<br># The user confirms<br># The UPoP(T) is signed by the wallet, creating PoP(T).<br># The PoP is sent to the destination in 1.ii.<br># The server receiving the PoP validates it and responds with “valid” or “invalid”.<br># The wallet displays the response in some way to the user.<br><br>&#39;&#39;&#39;Remarks:&#39;&#39;&#39;<br><br>* The method of transferring the PoP request at step 1 is not specified here. Instead that is specified in separate specifications. See [btcpop scheme BIP](btcpop scheme BIP).<br>* The nonce must be randomly generated by the server for every new PoP request.<br><br>=== Validating a PoP ===<br><br>The server needs to validate the PoP and reply with &quot;valid&quot; or &quot;invalid&quot;. That process is outlined below. If any step fails, the validation is aborted and &quot;invalid&quot; is returned:<br><br># Check the format of the PoP. It must pass normal transaction checks, except that the inputs may already be spent.<br># Check the PoP output at index 0. It must conform to the OP_RETURN output format outlined above.<br># Check that the rest of the outputs exactly corresponds to the outputs of T and that they appear in the same order as in T. An exception to this is that any OP_RETURN outputs of T must not be included in the PoP. All output value from the OP_RETURN must instead be included in the PoP output.<br># Check that the nonce is the same as the one you requested.<br># Check that the inputs of the PoP are exactly the same as in transaction T, and in the same order.<br># Check the scripts of all the inputs, as would be done on a normal transaction.<br># Check that the txid in the PoP output is the transaction you actually want proof for. If you don’t know exactly what transaction you want proof for, check that the transaction actually pays for the product/service you deliver.<br># Return &quot;valid&quot;.<br><br>== Security considerations ==<br><br>* Someone can intercept the PoP-request and change the PoP destination so that the user sends the PoP to the bad actor.<br>* Someone can intercept the PoP-request and change for example the txid to trick the user to sign a PoP for another transaction than the intended. This can of course be avoided if the user is actually looking at the UPoP before signing it. The bad actor could also set hints for a transaction, existing or not, that the user didn’t make, resulting in a broken service.<br>* Someone can steal a PoP and try to use the service hoping to get a matching nonce. Probability per try: 1/(2^48). The server should have a mechanism for detecting a brute force attack of this kind, or at least slow down the process by delaying the PoP request by some 100 ms or so.<br>* Even if a wallet has no funds it might still be valuable as a generator for PoPs. This makes it important to keep the security of the wallet after it has been emptied.<br>* Transaction malleability may cause the server to have another transaction id than the wallet for the payment. In that case the wallet will not be able to prove the transaction for the server. Wallets should not rely on the transaction id of the outgoing transaction. Instead it should listen for the transaction on the network and put that in its list of transactions.<br><br>The first two issues are the same attack vector as for traditional, ie BIP0021, bitcoin payments. They could be mitigated by using secure connections.<br><br>== Reference implementation ==<br><br>[<a href="https://github.com/kallerosenbaum/poppoc">https://github.com/kallerosenbaum/poppoc</a> poppoc on GitHub]<br><br>[<a href="https://github.com/kallerosenbaum/wallet">https://github.com/kallerosenbaum/wallet</a> Mycelium fork on GitHub]<br><br>== References ==<br><br>[<a href="https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki">https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki</a> BIP0021]: URI Scheme<br><br>[<a href="https://github.com/bitcoin/bips/blob/master/bip-0070.mediawiki">https://github.com/bitcoin/bips/blob/master/bip-0070.mediawiki</a> BIP0070]: Payment Protocol<br><br>[[btcpop scheme BIP]]<br><br></div>