<oembed><type>rich</type><version>1.0</version><author_name>npub1qp30q8l5nqgsxyw4nxrt8gyge6qjvm4syfg8zpmrc2pg8265s52sw9lsqv</author_name><author_url>https://nostr.ae/npub1qp30q8l5nqgsxyw4nxrt8gyge6qjvm4syfg8zpmrc2pg8265s52sw9lsqv</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2015-01-09&#xA;📝 Original message:A limitation on most existing micropayment channel ideas is that payments&#xA;can only flow in one direction. This is because the payment receiver can&#xA;sign -any- transaction you send them, not just the most recent one, and so&#xA;it&#39;s possible to just sign the transaction transferring the largest amount&#xA;into their control. This is easily remedied by opening a second payment&#xA;channel in the opposite direction, but now both parties have to deposit&#xA;funds over the lifetime of the two channels. If one party doesn&#39;t know&#xA;ahead of time whether or not the other party will go into credit, having&#xA;only one channel may save the use of a deposit.&#xA;&#xA;I propose a way of using CHECKLOCKTIMEVERIFY to allow a reversible payment&#xA;channel, introducing at most one additional broadcast transaction, with a&#xA;waiting period before the payment receiver can access deposited funds. The&#xA;extra transaction and waiting period apply only when the depositor doesn&#39;t&#xA;co-operate with the receiver.&#xA;&#xA;In this protocol, the setup is identical, with a deposit made to a P2SH&#xA;address matching a script allowing either single-party+CHECKLOCKTIME or&#xA;2-of-2. In this case, however, payments made by the depositor occur in the&#xA;form of unbroadcast transactions to special -holding addresses-.&#xA;&#xA;These holding addresses are themselves P2SH addresses, with scripts known&#xA;to both parties. Each script may be redeemed in one of two ways:&#xA;by the payment receiver, using their signature with a CHECKLOCKTIME&#xA;restriction that expires some period of time after the restriction on the&#xA;depositor&#39;s refund transaction, or&#xA;by the depositor, using their own signature, together with a hashlock.&#xA;&#xA;In the second case, we actually use a double hashlock, i.e. the depositor&#xA;must provide a value which when SHA256-hashed twice produces the value in&#xA;the script.&#xA;&#xA;The receiver generates these values according to the following algorithm:&#xA;Beginning with a secret S_0, they double hash S_0 to make the hashlock&#xA;value for the first payment, D_0 =H(H(S_0)). Then to make S_i+1 given S_i,&#xA;they create a public nonce, N_i, and let S_i+1 = H(N_i | H(S_i)), where a|b&#xA;denotes the string a followed by the string b. The hashlock values D_i are&#xA;not secret, and can be disclosed in advance or as part of the process of&#xA;receiving the associated payment.&#xA;&#xA;When the receiver wants to refund some amount to the depositor, the&#xA;receiver finds the last payment which left the depositor with a balance&#xA;-greater- than the desired balance, and negotiates a rewind of the payment&#xA;sequence to that point, with an additional payment of the remainder by the&#xA;depositor. Suppose the last payment that will remain valid was the i-th&#xA;payment, counting from zero. The receiver creates a new nonce, N&#39;_i,&#xA;creates the associated new secret value S&#39;_i+1 by S&#39;_i+1 = H(N&#39;_i |&#xA;H(S_i)), and sends D&#39;_i+1 to the depositor with a request for payment of&#xA;the right amount. This amount will be greater than that associated to D_i,&#xA;but less than that associated to D_i+1, so the depositor does not need to&#xA;trust the receiver in order to honour the request. The payment chain is now&#xA;forked at D_i, with a branch D_i+1, D_i+2... and a branch that only has&#xA;D&#39;_i+1. The receiver now unwinds the old branch, back to D_i, by revealing&#xA;S_i+1 to the depositor. The depositor can now generate - and check - the&#xA;secrets S_i+1, S_i+2..., and so knows that if the receiver attempts to sign&#xA;and broadcast a transaction to an address using one of those secrets, the&#xA;depositor can take back all their funds before the receiver is able to put&#xA;their own (CHECKLOCKTIME restricted) transaction from that address on the&#xA;blockchain. Now the best usable payment to the receiver is the one&#xA;associated to D&#39;_i+1.&#xA;&#xA;When the two parties want to close the payment channel, one party signs a&#xA;transaction from the deposit address to whatever addresses are desired, and&#xA;sends the transaction to the other party to add their own signature and&#xA;publish. This avoids either party having to wait for CHECKLOCKTIME&#xA;restrictions to expire. If either party abandons the protocol at this&#xA;point, the other can use the CHECKLOCKTIME restrictions to ensure they get&#xA;at least as much as they would if both cooperated. Note that the holding&#xA;addresses are only used on the blockchain when the protocol is abandoned.&#xA;&#xA;This protocol does not deal with the case of malicious attacks on a party&#39;s&#xA;network connection, which could keep them offline until CHECKLOCKTIME has&#xA;expired. This is something that each party should consider when choosing&#xA;how long the restrictions should be in place for. The protocol improves on&#xA;blueadept&#39;s use of a new nLockTime for each reverse payment[1], by keeping&#xA;the wait time independent of the number of payments, and not requiring&#xA;either party to predict ahead of time how many payments will occur.&#xA;&#xA;A note on generating hashlock secrets: the protocol works perfectly well&#xA;without generating them deterministically. Using an HMAC-style derivation&#xA;is more of a convenience than anything else - it saves storing and&#xA;transmitting all the secrets when a chain needs to be invalidated - but it&#xA;does encode the fact that the addresses form a chain into the addresses&#39;&#xA;scripts, which is a nice property to have.&#xA;&#xA;[1] https://bitcointalk.org/index.php?topic=814770.msg9185225#msg9185225&#xA;&#xA;I first posted this at https://bitcointalk.org/index.php?topic=918018.0 and&#xA;have edited it slightly for posting on this list. Thanks to Peter Todd for&#xA;the suggestion to submit it here for review.&#xA;&#xA;Nathan Cook&#xA;-------------- next part --------------&#xA;An HTML attachment was scrubbed...&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/bitcoin-dev/attachments/20150109/dc18ce68/attachment.html&gt;</html></oembed>