<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vlad Stan on Medium]]></title>
        <description><![CDATA[Stories by Vlad Stan on Medium]]></description>
        <link>https://medium.com/@motorina0?source=rss-3236004e48e7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*MjysLlrbjC11Z12X.</url>
            <title>Stories by Vlad Stan on Medium</title>
            <link>https://medium.com/@motorina0?source=rss-3236004e48e7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 21:18:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@motorina0/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Which is the lightest Lightning Network node setup?]]></title>
            <link>https://motorina0.medium.com/which-is-the-lightest-lightning-network-node-setup-624532ab187b?source=rss-3236004e48e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/624532ab187b</guid>
            <category><![CDATA[lightning-network]]></category>
            <dc:creator><![CDATA[Vlad Stan]]></dc:creator>
            <pubDate>Mon, 05 Apr 2021 07:43:18 GMT</pubDate>
            <atom:updated>2021-04-05T09:03:53.888Z</atom:updated>
            <content:encoded><![CDATA[<p>Lightning Network is a Layer 2 solution on top Bitcoin (Layer 1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*nKVNHnWT8HwEYMqA72C3cw.png" /><figcaption>Layers</figcaption></figure><p>Under normal conditions we should run our own Bitcoin Full Node and point the Lightning Network Node to it. This way we make sure that we are independent of any third parties to notify us about events related to our channel(s) state.</p><p>However, many people do not want/can/care to run a Bitcoin Full Node, what they would like is a quick and simple way to test some Lightning Network applications (LApps).</p><p>For the cases when the Lightning Network node has just one or two channels with little funds on them (~10 USD), then we can just connect to some third party <a href="https://github.com/lightninglabs/neutrino">Neutrino</a> nodes instead of using our own full node.</p><p><strong>DO NOT FOLLOW THIS APPROACH IF YOU HAVE MANY CHANNELS AND/OR SIGNIFICANT FUNDS!</strong></p><h3>Start the Lightning Network Node</h3><h4>Steps:</h4><ul><li>Install docker and docker-compose(there are plenty of online resource on how to do this for every major OS)</li><li>Save the below file and name it docker-compose.yaml</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e7eb8e5c59a0c8c4e7702c009cb8c33/href">https://medium.com/media/2e7eb8e5c59a0c8c4e7702c009cb8c33/href</a></iframe><ul><li>Open a command line and go to the folder where the docker-compose.yaml was downloaded</li><li>Run docker-compose up -d to start your Lightning Network Node</li><li>To see the logs run docker-compose logs -f</li></ul><p>We have to wait for a few minutes (~5–10) until the Lightning Network Node synchronizes.<br>A volumes folder will be created next to the the docker-compose.yaml file. The <strong>TLS Certificate</strong> and the <strong>macaroon</strong> files will be located under this folder.</p><h3>Lightning Network Client</h3><p>Depending on the LApp that we are testing, we might need to run some command line instructions (create wallet, open channel, etc). We will run the commands using docker exec.</p><h4>Steps:</h4><ul><li>Get the <strong>Container ID</strong> by running docker ps. Choose the Container ID corresponding to the lnd-prod name.</li></ul><pre>CONTAINER ID   IMAGE                                  NAMES<br>83fbf550a52b   lightninglabs/lnd:v0.12.0-beta.rc6     lnd-prod</pre><ul><li>Use docker to execute lncli commands. For example:<br> docker exec -t 83fbf550a52b /bin/lncli create<br>Of course, replace 83fbf550a52b with your own Container ID</li><li>Check the Lightning Network Node state by running:<br>docker exec -t 83fbf550a52b /bin/lncli getinfo</li></ul><pre>{<br>    &quot;version&quot;: &quot;0.12.0-beta.rc6 commit=v0.12.0-beta.rc6&quot;,<br>    ...<br>    &quot;synced_to_chain&quot;: true,<br>    &quot;synced_to_graph&quot;: true,<br>    &quot;testnet&quot;: false,<br>    &quot;chains&quot;: [<br>        {<br>            &quot;chain&quot;: &quot;bitcoin&quot;,<br>            &quot;network&quot;: &quot;mainnet&quot;<br>        }<br>    ],<br>    ...<br>}</pre><p>Both synced_to_chain and synced_to_graph must be true in order to consider the Node ready to use.</p><h3>Neutrino</h3><p>More details about Neutrino can be found here:<br> <a href="https://github.com/lightninglabs/neutrino">https://github.com/lightninglabs/neutrino</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=624532ab187b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Updating the balance of a Payment Channel]]></title>
            <link>https://motorina0.medium.com/updating-the-balance-of-a-payment-channel-944a713a8408?source=rss-3236004e48e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/944a713a8408</guid>
            <category><![CDATA[commitment-transaction]]></category>
            <category><![CDATA[lightning-network]]></category>
            <category><![CDATA[payment-channels]]></category>
            <category><![CDATA[bitcoin]]></category>
            <dc:creator><![CDATA[Vlad Stan]]></dc:creator>
            <pubDate>Fri, 19 Feb 2021 12:55:11 GMT</pubDate>
            <atom:updated>2021-03-23T08:28:14.303Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article we will look in detail at how the balance of a Lighting Network channel gets updated without any of the participants risking their funds.</p><p>Lightning Network is an adversarial network, participants do not trust the other side. In fact they <em>expect</em> that the “others” will try to cheat them. <br>A participant signs <strong>only</strong> what it knows to be safe. At <strong>any moment</strong> it must have the option to take out the money and leave the agreement (close the channel).</p><p>For this article we assume that the <strong>payment channel has already been open</strong> and it has a balance of 0.10 BTC for Alice and 0.0 BTC for Bob.</p><h3>Commitment Transactions</h3><p>After the payment channel has been open, Alice wants to pay Bob 0.02 BTC. The payments between the two parties are executed using a special type of transaction called a <strong>Commitment Transaction</strong>.<br>These transactions are special because they:</p><ul><li>can be revoked (canceled) if both parties agree to do so</li><li>always spend from the 2-of-2 multisig Output of the Funding Transaction</li></ul><p>The Commitment Transactions are intended to be used inside the payment channel, without hitting the main-chain. However, they are fully valid Bitcoin transactions and can be broadcast to the main-chain if one of the parties decides to do so.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*ANBUn70eAzsTHIjGsV00ow.gif" /><figcaption>Multiple Commitment Transactions inside a Payment Channel</figcaption></figure><p>In order to pay Bob, Alice must create two transactions, <strong>both of which</strong> will pay 0.02 BTC to Bob, but the outputs have different conditions for spending.</p><p>We will refer to these transactions as the <strong>Pay-Me-First</strong> transaction and the <strong>Pay-Other-First</strong> transaction. Remember that <strong>both transactions are created by Alice</strong> without any direct input from Bob. Alice got all the information she needed when Bob sent the accept_channel message.</p><h4>Pay-Me-First Transaction</h4><p>In the Pay-Me-First transaction Alice can spend her output immediately, while Bob has to comply with the <a href="https://motorina0.medium.com/rsm-contracts-f690cfdf04e8"><strong>RSM Contrac</strong></a><strong>t</strong>. A Revocable Sequence Maturity Contract puts several restrictions on spending the Output:</p><ul><li>the beneficiary of the funds can only spend them after a “maturation” period has passed (is delayed)</li><li>the contract can be revoked (by the beneficiary)</li><li>if the contract was revoked and the beneficiary still tries to spend the funds then it risks penalty (loosing all the funds)</li></ul><p>More details about Revocable Sequence Maturity Contracts <a href="https://motorina0.medium.com/rsm-contracts-f690cfdf04e8">here</a>.</p><p>This transaction is more advantageous for Alice. You can view a sample of this transaction <a href="https://bitcoincore.tech/apps/bitcoinjs-ui/index.html?&amp;tx_note=Sample%20of%20a%20Commitment%20Transaction%20used%20in%20Lightning%20Network.&amp;tx_input_0_note=Spend%20from%20the%20Funding%20Transaction&amp;tx_input_0_script_note=This%20script%20unlocks%20a%20P2WSH.%20Click%20the%20%27Edit%27%20button%20and%20manually%20set%20the%20type%20to%20P2WSH%20in%20order%20to%20view%20the%202-of-2%20multisig%20script.&amp;tx_output_0_note=%5BTo%20Local%5D%20Output%20sends%20funds%20back%20to%20the%20owner%20(Alice)%20of%20this%20commitment%20transaction%20and%20thus%20must%20be%20timelocked%20using%20%60OP_CHECKSEQUENCEVERIFY%60.%20It%20can%20be%20claimed,%20without%20delay,%20by%20the%20other%20party%20if%20they%20know%20the%20revocation%20private%20key.&amp;tx_output_0_script_note=This%20is%20the%20%22naked%22%20unwrapped%20Revocable%20Sequence%20Maturity%20Contract%20(RSMC).%20In%20order%20to%20see%20the%20final%20form,%20click%20the%20%27Edit%27%20button%20and%20%27Wrap%20in%20P2WSH%27.&amp;tx_output_1_note=%5BTo%20Remote%5D%20Output%20sends%20funds%20to%20the%20other%20party.%20If%20%60option_anchor_outputs%60%20applies%20to%20the%20commitment%20transaction,%20the%20%60to_remote%60%20output%20is%20encumbered%20by%20a%20one%20block%20csv%20lock.%20Otherwise,%20this%20output%20is%20a%20simple%20P2WPKH%20to%20remotepubkey.&amp;tx_output_1_script_note=This%20is%20the%20%22naked%22%20unwrapped%20Contract%20that%20pays%20Bob%20with%20no%20restrictions.%20In%20order%20to%20see%20the%20final%20form,%20click%20the%20%27Edit%27%20button%20and%20%27Wrap%20in%20P2WSH%27.&amp;tx_output_2_note=%5BLocal%20Anchor%5D%20Output%20can%20be%20spent%20by%20the%20local%20node%20to%20provide%20incentive%20to%20mine%20the%20transaction,%20using%20child-pays-for-parent.&amp;tx_output_3_note=%5BRemote%20Anchor%5D%20Output%20can%20be%20spent%20by%20the%20remote%20node%20to%20provide%20incentive%20to%20mine%20the%20transaction,%20using%20child-pays-for-parent.&amp;tx_hex=02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a4884890000000000ffffffff04e48d6a00000000004d63210212a140cd0c6539d07cd08dfe09984dec3251ea808b892efeac3ede9402bf2b1967029000b2752103fd5960528dc152014952efdb702a88f71e3c1653b2314431701ec77e57fde83c68acc0c62d00000000002521032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991ad51b24a010000000000002200202b1b5854183c12d3316565972c4668929d314d81c5dcdbb21cb45fe8a9a8114f4a01000000000000220020e9e86e4823faa62e222ebc858a226636856158f07e69898da3b0d1af0ddb39940340ca3e2b815f7bf548fa59a79002d8093ee786b38803704130a589f749c33552145a36440a0d7d407dee948c85c2f20e4892479075cf2f166e94c2e6309907971440f89034eba16b2be0e5581f750a0a6309192b75cce0f202f0ee2b4ec0cc39485076c65dc507fe42276152b7a3d90e961e678adbe966e916ecfe85e64d430e75f3475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae00000000">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*O9F0Ggmmn8vsU0AkwZ2zpg.png" /><figcaption>The <strong>Pay-Me-First</strong> transaction created by Alice</figcaption></figure><h4>Pay-Other-First Transaction</h4><p>In the Pay-Other-First transaction Bob can spend his output immediately, while Alice has to comply with the <a href="https://motorina0.medium.com/rsm-contracts-f690cfdf04e8"><strong>RSM Contract</strong></a>. This transaction is more advantageous for Bob. You can view a sample of this transaction <a href="https://bitcoincore.tech/apps/bitcoinjs-ui/index.html?&amp;tx_note=Sample%20of%20a%20Commitment%20Transaction%20used%20in%20Lightning%20Network.&amp;tx_input_0_note=Spend%20from%20the%20Funding%20Transaction&amp;tx_input_0_script_note=This%20script%20unlocks%20a%20P2WSH.%20Click%20the%20%27Edit%27%20button%20and%20manually%20set%20the%20type%20to%20P2WSH%20in%20order%20to%20view%20the%202-of-2%20multisig%20script.&amp;tx_output_0_note=%5BTo%20Local%5D%20Output%20sends%20funds%20back%20to%20the%20owner%20(Bob)%20of%20this%20commitment%20transaction%20and%20thus%20must%20be%20timelocked%20using%20%60OP_CHECKSEQUENCEVERIFY%60.%20It%20can%20be%20claimed,%20without%20delay,%20by%20the%20other%20party%20if%20they%20know%20the%20revocation%20private%20key.&amp;tx_output_0_script_note=This%20is%20the%20%22naked%22%20unwrapped%20Revocable%20Sequence%20Maturity%20Contract%20(RSMC).%20In%20order%20to%20see%20the%20final%20form,%20click%20the%20%27Edit%27%20button%20and%20%27Wrap%20in%20P2WSH%27.&amp;tx_output_1_note=%5BTo%20Remote%5D%20Output%20sends%20funds%20to%20the%20other%20party.%20If%20%60option_anchor_outputs%60%20applies%20to%20the%20commitment%20transaction,%20the%20%60to_remote%60%20output%20is%20encumbered%20by%20a%20one%20block%20csv%20lock.%20Otherwise,%20this%20output%20is%20a%20simple%20P2WPKH%20to%20remotepubkey.&amp;tx_output_1_script_note=This%20is%20the%20%22naked%22%20unwrapped%20Contract%20that%20pays%20Bob%20with%20no%20restrictions.%20In%20order%20to%20see%20the%20final%20form,%20click%20the%20%27Edit%27%20button%20and%20%27Wrap%20in%20P2WSH%27.&amp;tx_output_2_note=%5BLocal%20Anchor%5D%20Output%20can%20be%20spent%20by%20the%20local%20node%20to%20provide%20incentive%20to%20mine%20the%20transaction,%20using%20child-pays-for-parent.&amp;tx_output_3_note=%5BRemote%20Anchor%5D%20Output%20can%20be%20spent%20by%20the%20remote%20node%20to%20provide%20incentive%20to%20mine%20the%20transaction,%20using%20child-pays-for-parent.&amp;tx_hex=02000000000101bef67e4e2fb9ddeeb3461973cd4c62abb35050b1add772995b820b584a4884890000000000ffffffff04e48d6a00000000004d632103f9b004476ef731bac15887882b99c8756d2451800674e4b9f42d2effde4bebc567029000b27521034e0ec6dc63301141448af127eb2d8eba26e8c2bb24d4bfdf8e29afa7bb02657b68acc0c62d00000000002521034f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aaad51b24a010000000000002200202b1b5854183c12d3316565972c4668929d314d81c5dcdbb21cb45fe8a9a8114f4a01000000000000220020e9e86e4823faa62e222ebc858a226636856158f07e69898da3b0d1af0ddb39940340ca3e2b815f7bf548fa59a79002d8093ee786b38803704130a589f749c33552145a36440a0d7d407dee948c85c2f20e4892479075cf2f166e94c2e6309907971440f89034eba16b2be0e5581f750a0a6309192b75cce0f202f0ee2b4ec0cc39485076c65dc507fe42276152b7a3d90e961e678adbe966e916ecfe85e64d430e75f3475221023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb21030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c152ae00000000">here</a>.</p><figure><img alt="The Pay-Other-First transaction created by Alice" src="https://cdn-images-1.medium.com/max/722/1*VCFKJzFqiUNcrC_FTV5tcQ.png" /><figcaption>The <strong>Pay-Other-First</strong> transaction created by Alice</figcaption></figure><p><strong>Note</strong>: Transaction outputs are <a href="https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki">sorted in ascending order</a> by amount.</p><p>Alice will <strong>only send </strong>signatures to Bob for the Pay-Me-First transaction (me=Alice). She will <strong>never</strong><em> </em><strong>send</strong> signatures directly to Bob for the Pay-Other-First transaction (other=Bob).</p><p>The <strong>only time</strong> Alice will sign the Pay-Other-First transaction is if she intends to broadcast that transaction to the Bitcoin network (without sending it to Bob).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*EdYugowRmYkVMoQnGsZsrw.gif" /></figure><p>The outputs of the Pay-Other-First transaction are called <a href="https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#to_local-output"><strong>to_local</strong></a> (the one that pays Alice) and <a href="https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#to_remote-output"><strong>to_remote</strong></a> (the one that pays Bob).</p><p>In a similar manner, Bob will create a Pay-Me-First transaction and a Pay-Other-First transaction.</p><h4>Channel State Update — Step By Step</h4><p>Next we will take a look in detail at what happens when Alice pays Bob 0.02 BTC using a Lightning Network payment channel.</p><p>Below are the steps taken by Alice and Bob to update the balance from Alice 0.10 BTC and Bob 0.0 BTC (<strong>State01</strong>) to Alice 0.08 BTC and Bob 0.02 BTC (<strong>State02</strong>).</p><p>The party making the payment initiates the flow, in this case Alice.</p><h4>Alice Builds and Signs</h4><figure><img alt="Alice builds and signs her Pay-Me-First transaction" src="https://cdn-images-1.medium.com/max/682/1*6iE3Kp-5h8bbc13ZREN9PA.png" /><figcaption>Alice builds and signs her Pay-Me-First transaction</figcaption></figure><ol><li>BuildPayMeFirstTx( alice) — Alice builds the transaction that pays her 0.08 BTC <strong>with no restrictions</strong> and 0.02 BTC to Bob <strong>under the </strong><a href="https://motorina0.medium.com/rsm-contracts-f690cfdf04e8"><strong>RSM Contract</strong></a>. We name this transaction payAliceFirstTx.</li><li>Sign(payAliceFirstTx) — Alice signs payAliceFirstTx transaction and creates a signature named payAliceFirstSignature.</li><li>Send(payAliceFirstSignature) — Alice sends the payAliceFirstSignature to Bob. There is no risk for her sending this signature. The worst case scenario is that Bob will close the channel and will broadcast payAliceFirstTx, which is fine for Alice since she can spend her output right away, while Bob has to wait. <br>By broadcasting payAliceFirstTx, Bob also discloses that he received the 0.02 BTC from Alice. If instead of closing the channel Bob becomes unresponsive then Alice can safely broadcast the previous transaction where she has a larger amount (<strong>State01</strong>) since she has not revoked the current commitment transaction yet.</li></ol><h4>Bob checks and revokes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*TJ1anRzIMJ1L5AKBto2IRQ.png" /></figure><figure><img alt="Bob checks the signature from Alice and revokes the previous state" src="https://cdn-images-1.medium.com/max/682/1*_Ii2NIDDxY3CDStToHsj1w.png" /><figcaption>Bob checks the signature from Alice and revokes the previous state</figcaption></figure><p>4. Receive(payAliceFirstSignature) — Bob receives the payAliceFirstSignature message. Note that Alice sends only the signature and not the full transaction. Bob can reconstruct the exact same transaction.</p><p>5. BuildPayOtherFirstTx(alice) — Bob builds the transaction that pays him 0.02 BTC under the <a href="https://motorina0.medium.com/rsm-contracts-f690cfdf04e8">RSM Contract</a> and 0.08 BTC to Alice with no restrictions. We name this transaction payOtherFirstTx. It is <strong>identical</strong> with the payAliceFirstTx (that Alice built).</p><p>6. CheckSignature(payOtherFirstTx, payAliceFirstSignature) — Bob checks if the signature received from Alice (payAliceFirstSignature) is valid for the transaction that he just built (payAliceFirstTx). If the signature from Alice is valid then Bob has a valid new commitment transaction (<strong>State02</strong>). He can continue to use the channel or he can sign and broadcast the transaction, thus closing the channel. However, if Bob broadcasts the transaction he will be restricted in spending it by the <a href="https://motorina0.medium.com/rsm-contracts-f690cfdf04e8">RSM Contract</a>, while Alice will be able to spend her funds immediately.</p><p>7. Store(payAliceFirstSignature) — Bob persists the signature together with the data that allows him to reconstruct payAliceFirstTx. He might need this data if Alice becomes unresponsive.</p><p>8. BuildRevokeCommitmentMsg() — Bob does not need the older state (where he had less money) so he wants to make <strong>State02</strong> (payAliceFirstTx) the current state and revoke (invalidate) the old one (<strong>State01</strong>). He builds the revokeMessage message that invalidates <strong>State01</strong>.</p><p>9. Send(revokeMessage) — Bob sends the revokeMessage to Alice. There is no risk for him to send this message which revokes the previous state (<strong>State01</strong>). The worst case scenario is that Alice becomes unresponsive and Bob has to broadcast the payAliceFirstTx transaction.<br>By revoking the previous state (<strong>State01</strong>), Bob assures Alice that it is OK for her to take the next steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*TJ1anRzIMJ1L5AKBto2IRQ.png" /></figure><figure><img alt="Alice receives the revocation message for State01" src="https://cdn-images-1.medium.com/max/682/1*ipXIw4Sa8HW4Pvz4jLEywQ.png" /><figcaption>Alice receives the revocation message for State01</figcaption></figure><p>10. ReceiveRevokeMsg(revokeMessage) — Alice receives the revocation message from Bob. Alice now has the possibility to penalize Bob if he broadcasts the revoked commitment transaction (<strong>State01</strong>).<br>She will not revoke her current state yet since she has not received a signature from Bob for <strong>State02</strong>.</p><h4>Bob builds and signs</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*TJ1anRzIMJ1L5AKBto2IRQ.png" /></figure><figure><img alt="Bob builds and signs the Pay-Me-First transaction" src="https://cdn-images-1.medium.com/max/682/1*1lQ9yezVm3UE7pzcidRAdQ.png" /><figcaption>Bob builds and signs the Pay-Me-First transaction</figcaption></figure><p>11. BuildPayMeFirstTx(bob) — Bob <strong>does not simply sign</strong> the payAliceFirstTx transaction and sends it to Alice. This transaction is <strong>unfavorable to him</strong> since he has to comply with the <a href="https://motorina0.medium.com/rsm-contracts-f690cfdf04e8">RSM Contract</a> while Alice is free to spend her funds immediately. But most importantly, he will have <strong>no power to penalize</strong> Alice if she decides to broadcast the payAliceFirstTx transaction sometime in the future when this old transaction becomes favorable to her (more money).<br>Bob builds a transaction that pays him <strong>with no restrictions</strong>, but pays Alice under the <a href="https://motorina0.medium.com/rsm-contracts-f690cfdf04e8">RSM Contract</a> restrictions. This is the payBobFirstTx transaction.</p><p>12. Sign(payBobFirstTx) — Bob creates the payBobFirstSignature by signing the payBobFirstTx transaction.</p><p>13. Send(payBobFirstSignature) — Bob sends the payBobFirstSignature message to Alice.</p><h4>Alice checks and revokes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*TJ1anRzIMJ1L5AKBto2IRQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*zeE8oYVicXRBG236gy0eFQ.png" /></figure><p>14. Receive(signatureBob) — Alice receives the payBobFirstSignature message. Note that Bob sends only the signature and not the full transaction. Alice can reconstruct the exact same transaction.</p><p>15. BuildPayOtherFirstTx(bob) — Alice builds the transaction that pays her 0.08 BTC under the <a href="https://motorina0.medium.com/rsm-contracts-f690cfdf04e8">RSM Contract</a> and pays Bob 0.02 with no restrictions. We name this transaction payOtherFirstTx. It must be identical with the payBobFirstTx (built by Bob).</p><p>16. CheckSignature(payOtherFirstTx, signatureBob) — Alice checks if the signature received from Bob (payBobFirstSignature) is valid for the transaction that she just built (payBobFirstTx). If the signature from Bob is valid then Alice has a valid new commitment transaction (<strong>State02</strong>). She can continue to use the channel or she can sign and broadcast the transaction therefore closing the channel. If Alice chooses to broadcast this transaction, Bob will be able to spend his funds immediately while she has to comply with the <a href="https://motorina0.medium.com/rsm-contracts-f690cfdf04e8">RSM Contract</a>.</p><p>17. Store(signatureBob) — Alice persists the signatureBob message together with the data that allows her to reconstruct payBobFirstTx. She can use this data if Bob becomes unresponsive.</p><p>18. BuildRevokeCommitmentMsg() — Alice builds the revokeMessage, that will penalize her if she tries to broadcast the old state (<strong>State01</strong>) where she had 0.10 BTC.</p><p>19. Send(revokeMessage) — Alice sends the revokeMessage to Bob. She can now consider the payment complete. The payment channel has moved to <strong>State02</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*TJ1anRzIMJ1L5AKBto2IRQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*2Pdmt12_XlgGzmH8kezLyA.png" /></figure><p>20. Receive(revokeMessage) — Bob receives the revocationMessage from Alice. He now can consider the payment complete. The payment channel has moved to <strong>State02</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=944a713a8408" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RSM Contracts]]></title>
            <link>https://motorina0.medium.com/rsm-contracts-f690cfdf04e8?source=rss-3236004e48e7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f690cfdf04e8</guid>
            <dc:creator><![CDATA[Vlad Stan]]></dc:creator>
            <pubDate>Thu, 18 Feb 2021 13:04:14 GMT</pubDate>
            <atom:updated>2021-02-19T15:11:59.480Z</atom:updated>
            <content:encoded><![CDATA[<p>Bitcoin has contracts, it always did. A contract is just a small script (program) that gets executed when an output is being spent. <br>The spender must provide an input for the script (contract), then the script is executed, if it returns TRUE, then the UTXO can be spent, otherwise it cannot.</p><p>A contract is usually (but not always) agreed between two parties. The party that spends the funds (Alice) and the party that receives the funds (Bob).</p><p>A <strong>Revocable Sequence Maturity Contract</strong> (RSMC) has two main characteristics:</p><ol><li>it can be spent by the owner (Alice) <strong>only after it has reached maturity</strong> (some time has passed)</li><li>it can be spent immediately by the other party (Bob) <strong>if he previously obtained from Alice a Revocation Key</strong></li></ol><p>The reason for a<strong> Contract (C1)</strong> to be <em>revocable</em> is that the two parties negotiate and agree on a new <strong>Contract (C2)</strong>. As part of the negotiation they want to cancel the effects of the old contract. Bob <em>cannot simply trust</em> that Alice will <em>delete</em> the old transaction (where she has more funds) and that she will never broadcast it. Instead Bob asks for a <strong>Revocation Key</strong> that will allow him to penalize Alice if she breaks the deal and tries to enforce the deprecated contract (<strong>C1</strong>) on the main-chain.</p><h4>Commitment Transactions</h4><p>RSM Contracts are useful for the construction of payment channels in Lightning Network. In a payment channel, the two parties make bidirectional payments and update the balance multiple times using what is called <strong>Commitment Transactions</strong>. Each time the balance is updated, the old state (old Commitment Transaction) must be revoked. Commitment Transactions are intended for off-chain use (second layer), but they can be broadcast to the main-chain if one of the parties desires so.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*ANBUn70eAzsTHIjGsV00ow.gif" /><figcaption>When a new Commitment Transaction is agreed then the old Commitment Transaction must be Revoked</figcaption></figure><p>A Commitment Transaction:</p><ul><li>spends from a 2–of-2 multisig (wrapped in a P2WSH), therefore it requires signatures from <strong>both parties</strong> (Alice and Bob) in order to unlock the funds</li><li>sends funds to both participants (except when the amount is below the dust limit)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*fOnjxPfkIX1f3dnyWMulxw.png" /><figcaption>Commitment Transaction</figcaption></figure><p>This is from the BOLT 03 specification for <a href="https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#commitment-transaction-outputs">Commitment Transaction Outputs</a>:</p><blockquote>To allow an opportunity for penalty transactions, in case of a revoked commitment transaction, all outputs that return funds to the owner of the commitment transaction (a.k.a. the “local node”) must be delayed for to_self_delay blocks.</blockquote><p>A RSM Contract is what allows the “<em>opportunity for penalty transactions, in case of a revoked commitment transaction</em>”. The flow for a RSM Contract is of this form:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*s2CXB6G5ycZKQ82sw1VR4g.png" /><figcaption>Alice (the owner) is delayed in getting the funds, giving Bob time to penalize her if he has a Revocation Key</figcaption></figure><h4>Alice is the Owner</h4><p>What exactly does it mean that “Alice is the owner” and why isn’t Bob also the owner since he is part of this transaction too?</p><p>Alice can call herself the owner of the Commitment Transaction if <strong>she has received from Bob a signature that allows her to spend the Input(s) of this transaction</strong>. Remember that the Commitment Transactions spend from a 2-of-2 multisig (wrapped in a P2WSH). The party that is able to broadcast the Commitment Transaction is considered the owner.</p><p>Bob<strong> is not able to spend the Inputs</strong><em> </em>for the Commitment Transaction since he does not have Alice’s signature. He is not the owner.</p><h4>But Bob has the Revocation Key</h4><p>What does it mean that “Bob has the Revocation Key” and how comes he can use it, but Alice cannot? The code inside “Pay Bob” box is (<a href="https://bitcoin.stackexchange.com/questions/102654/lightning-network-revocation-format?noredirect=1#comment116545_102654">was</a>):</p><pre>2 &lt;AlicePublicKey01&gt; &lt;BobPublicKey01&gt; 2 OP_CHECKMULTISIG</pre><p>For details on OP_CHECKMULTISIG you can read more <a href="https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch07.asciidoc#multisignature">here</a> and <a href="https://en.bitcoin.it/wiki/Script">here</a>.</p><p>Alice has the <em>Alice</em><strong><em>PrivateKey</em></strong><em>01</em> that corresponds to <em>Alice</em><strong><em>PublicKey</em></strong><em>01.<br></em>Bob has the <em>Bob</em><strong><em>PrivateKey</em></strong><em>01</em> that corresponds to <em>Bob</em><strong><em>PublicKey</em></strong><em>01</em>.<br>Signatures from <em>both</em> Private Keys are required in order to pass the multisig check.</p><p>When the two parties agree to <em>revoke the current Commitment Transaction</em>, <strong>Alice gives Bob</strong> the Private Key (<em>Alice</em><strong><em>PrivateKey</em></strong><em>01</em>) that corresponds to <em>Alice</em><strong><em>PublicKey</em></strong><em>01</em>. Now we can say that “Bob has the Revocation Key”. Alice cannot spend the funds using the “Pay Bob” box since she does not know Bob’s Private Key (<em>Bob</em><strong><em>PrivateKey</em></strong><em>01).</em></p><h4>Long Story Short</h4><p>Alice <strong>can</strong> broadcast, but Bob <strong>can</strong> revoke.<br>Alice <strong>cannot</strong> revoke and Bob <strong>cannot</strong> broadcast.</p><h4>Revocation Improvements</h4><p>The initial Lighting Network Paper specified a 2-of-2 multisig as the revocation mechanism. However, it was later replaced with a more efficient technique that uses <a href="https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication">elliptic curve point multiplication</a>. The updated version is of the form:</p><pre>&lt;revocationpubkey&gt; OP_CHECKSIG</pre><p>where</p><pre>revocationpubkey = Alice<strong>PublicKey</strong>01 + Bob<strong>PublicKey</strong>01</pre><p>You can find more details <a href="https://medium.com/@yyforyongyu/till-its-lightning-fast-uncover-the-lightning-network-transactions-f3180e467857">here</a> on the <a href="https://medium.com/@yyforyongyu/till-its-lightning-fast-uncover-the-lightning-network-transactions-f3180e467857">Revocation — Keys and More Keys</a> section.</p><h3>Script</h3><p>The Bitcoin Script for the RSM Contract is quite simple, and it is easy to observe the two possible paths:</p><pre>OP_IF<br>    &lt;revocationpubkey&gt;<br>OP_ELSE<br>    `to_self_delay` OP_CHECKSEQUENCEVERIFY OP_DROP<br>    &lt;local_delayedpubkey&gt;<br>OP_ENDIF<br>OP_CHECKSIG</pre><p>The <em>revoke</em> path has just a public key (revocationpubkey).<br>The <em>maturity</em> path uses the OP_CHECK<strong>SEQUENCE</strong>VERIFY operator to check if sufficient time has passed, hence the “Sequence Maturity” part of the RSMC name.</p><p>At the end, an OP_CHECKSIG is performed either against &lt;revocationpubkey&gt; or against &lt;local_delayedpubkey&gt; depending on the taken path. The updated diagram looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*MlIqkgSDmSZhQKlIEugGAA.png" /></figure><p>For details on OP_CHECKSEQUENCEVERIFY you can read more <a href="https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch07.asciidoc#relative-timelocks">here</a> and <a href="https://en.bitcoin.it/wiki/Script">here</a>.</p><h3>Spending the Output</h3><p>As specified in the <a href="https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#to_local-output">BOLT 03</a> spec:</p><blockquote>The output is spent by an input with nSequence field set to to_self_delay (which can only be valid after that duration has passed) and witness:</blockquote><pre>&lt;local_delayedsig&gt; &lt;&gt;</pre><blockquote>If a revoked commitment transaction is published, the other party can spend this output immediately with the following witness:</blockquote><pre>&lt;revocation_sig&gt; 1</pre><h3>Final Note</h3><p>When we say that an <strong>Output that pays Alice</strong> is restricted by a<strong> RSM Contract</strong> it means that:</p><ul><li>Alice is the owner of the Commitment Transaction and she can broadcast it</li><li>Alice can only spend the funds after a certain period (maturity)</li><li>Alice can revoke the Commitment Transaction by offering Bob a Revocation Key</li><li>Alice can be penalized (lose the funds) if she tries to spend a revoked transaction</li></ul><h3>Notes and References</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f690cfdf04e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>