<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.5">Jekyll</generator><link href="https://yakshaver.org/feed.xml" rel="self" type="application/atom+xml" /><link href="https://yakshaver.org/" rel="alternate" type="text/html" /><updated>2024-03-02T10:19:01+00:00</updated><id>https://yakshaver.org/feed.xml</id><title type="html">Yakshaver.org</title><subtitle>Personal web site for links to open source Bitcoin work.
</subtitle><author><name>Richard Myers</name></author><entry><title type="html">PeerSwap</title><link href="https://yakshaver.org/2022/08/01/peerswap.html" rel="alternate" type="text/html" title="PeerSwap" /><published>2022-08-01T00:00:00+00:00</published><updated>2022-08-01T00:00:00+00:00</updated><id>https://yakshaver.org/2022/08/01/peerswap</id><content type="html" xml:base="https://yakshaver.org/2022/08/01/peerswap.html"><![CDATA[<p>Thanks <a href="https://bitdevsla.org/socratic-seminar-30/">BitDevs LA</a> for giving me the chance to <a href="https://www.youtube.com/watch?v=0L_ylLNw5wc">talk</a> (<a href="https://yakshaver.org/assets/presentations/BitDevsLA_PeerSwap_v1.pdf">slides</a>) about <a href="https://www.peerswap.dev">PeerSwap</a>.</p>

<p>A big thanks also to <a href="https://acinq.co/">ACINQ</a> for supporting this work; you can track our PeerSwap progress on <a href="https://github.com/ACINQ/eclair/pull/2342">github</a>.</p>]]></content><author><name>Richard Myers</name></author><summary type="html"><![CDATA[Thanks BitDevs LA for giving me the chance to talk (slides) about PeerSwap.]]></summary></entry><entry><title type="html">APO Vault</title><link href="https://yakshaver.org/2021/11/18/covenants.html" rel="alternate" type="text/html" title="APO Vault" /><published>2021-11-18T00:00:00+00:00</published><updated>2021-11-18T00:00:00+00:00</updated><id>https://yakshaver.org/2021/11/18/covenants</id><content type="html" xml:base="https://yakshaver.org/2021/11/18/covenants.html"><![CDATA[<p>It has been <a href="https://www.mail-archive.com/bitcoin-dev@lists.linuxfoundation.org/msg08075.html">suggested</a> that a form of <a href="https://bitcoinops.org/en/topics/covenants/">covenants</a> could be possible using the proposed ANYPREVOUT sighash described in <a href="https://github.com/bitcoin/bips/blob/master/bip-0118.mediawiki">BIP-118</a>.</p>

<p>I’ve created a brief <a href="https://yakshaver.org/assets/presentations/APO_Vault_Covenants_v1.pdf">presentation</a> of how I think it would work, and begun to create some simple <a href="https://github.com/remyers/bitcoin/blob/covenant-anyprevout/test/functional/feature_apocovenant.py">tests</a> using AJ Town’s anyprevout branch of Bitcon to see if this might work.</p>

<p>I’d love to get feedback from the covenant / vault experts out there. Is this covenant scheme useful? How does it compare to existing covenant proposals like the CHECKTEMPLATEVERIFY <a href="https://github.com/bitcoin/bips/blob/master/bip-0119.mediawiki#feature-redundancy">BIP-119</a>?</p>

<p>Kanzure’s <a href="https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2019-August/017229.html">2019 mailing list post</a> describes vaults that do not require, but would benefit from, SIGHASH_NOINPUT. The Revault team <a href="https://github.com/revault/practical-revault/blob/master/revault.pdf">describes</a> describes a similar scheme. To investigate the use of covenants with APO I built a vault system loosly based on the Kanzure/Revault vaults, but using the current APO branch from AJ Towns to implement them with covenants.</p>

<p>You can read more about covenants in the paper, <a href="https://arxiv.org/pdf/2006.16714.pdf">Bitcoin Covenants: Three Ways to Control the
Future</a>.</p>]]></content><author><name>Richard Myers</name></author><summary type="html"><![CDATA[It has been suggested that a form of covenants could be possible using the proposed ANYPREVOUT sighash described in BIP-118.]]></summary></entry><entry><title type="html">Adventures in Adaptor Signatures</title><link href="https://yakshaver.org/2021/10/04/adaptor_sig.html" rel="alternate" type="text/html" title="Adventures in Adaptor Signatures" /><published>2021-10-04T00:00:00+00:00</published><updated>2021-10-04T00:00:00+00:00</updated><id>https://yakshaver.org/2021/10/04/adaptor_sig</id><content type="html" xml:base="https://yakshaver.org/2021/10/04/adaptor_sig.html"><![CDATA[<h2 id="motivation">Motivation</h2>

<p>The next update of the scripts for my eltoo simulation will replace the HTLCs with <a href="https://suredbits.com/payment-points-part-1/">PTLCs</a>. To implement PTLCs I need support for <a href="https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#Adaptor_Signatures">Adaptor Signatures</a>. Although you can implement adaptor signatures using ECDSA today, eltoo will rely on Taproot which uses Schnorr signatures. For my simulation I needed an adaptor signature implementation that satisfied three criteria:</p>
<ul>
  <li>Python (using SECP256K1 functions)</li>
  <li>Schnorr based</li>
  <li>Support for x-only pubkeys</li>
</ul>

<p>I do not need something fast, secure or robustly tested because this is just a prototyping experiment and ease of understanding was most important.</p>

<h2 id="implementations">Implementations</h2>

<p>The first useful example implementation I found was from <a href="https://twitter.com/LeoComandini">@LeoComandini</a>. His <a href="https://github.com/LeoComandini/adaptor-py">adaptor-py</a> Python scripts were written to go along with a <a href="https://satoshispritz.com">Satoshi Spritz</a> presentation he gave, <a href="https://satoshispritz.com/presentazioni/210318-how_dlc-bets_work.pdf">“How DLC-Bets Work?”</a>. If you want to learn about adaptor signatures, this (toy) pure python implementation for ECDSA and Schnorr is a great place to start. Unfortunately it relied on it’s own eliptical curve functions and did not take into account x-only public keys. I wanted to use something that added a minimal amount of code to the functional test framework and also would be compatible with the x-only pubkeys used for tapscript.</p>

<p>The next solution that was recommended to me was to look at <a href="https://twitter.com/LLFOURN">@LLFourn</a>’s <a href="https://docs.rs/schnorr_fun/0.6.2/schnorr_fun/">Schnorr-fun</a> Rust implementation of BIP-340 compatible <a href="https://docs.rs/schnorr_fun/0.6.2/schnorr_fun/adaptor/index.html">adaptor signatures</a>. This was exactly what I needed, but in the wrong language to use for my eltoo simulation.</p>

<p>I decided that I should try to port the schnorr_fun adaptor signature scheme to Python, but quickly got lost in how to translate the all important eliptical curve computations from the elegant Rust <a href="https://docs.rs/secp256kfun/0.6.2/secp256kfun/">secp256k1-fun</a> system to the Python based <a href="https://github.com/bitcoin/bitcoin/blob/cdb4dfcbf1c82ef4c4eb7bb982b35219d5dbf827/test/functional/test_framework/key.py#L215">SECP256K1</a> eliptical curve functions used in bitcoin-core’s functional test framework. I reached out to my friend <a href="https://twitter.com/Elichai2">@Elichai2</a> for help. Elichai is very smart about all things Bitcoin and elipitcal curves and authored the <a href="https://bitcoinops.org/">Bitcoin Optech</a> <a href="https://youtu.be/wybiVFdknhg">Schnorr signature tuturoial</a>. Elichai whipped up an example Python <a href="https://github.com/elichai/bitcoin/blob/b8252af349143346b5881ddb4c627e460557c3ae/test/functional/test_framework/key.py#L636">adaptor signature scheme</a> in a couple of hours (!) that demonstrated how to use SECP256K1 for what I wanted to do in the functional test framework. Thanks again Elichai!</p>

<p>I spent the next couple of weeks debugging my translation of Lloyd’s Rust adaptor functions to Python, using Elichai’s implementation and tips to guide me along the way. I won’t go into all of the things I did wrong, but will mention the final break-through was that I was using an x-only pubkey for the <a href="https://github.com/remyers/bitcoin/blob/c7e68f209105d91583ef1ed4c8968a7a09b0e351/test/functional/feature_adaptorsig.py#L44">encryption_key</a> parameter. This caused my adaptor signatures functions to work perfectly, BUT the recovered schnorr signatures did not verify as valid Schnorr signatures about half the time. More closely looking at the schnorr-fun version revealed my error and then everything magically worked.</p>

<h2 id="testing">Testing</h2>

<p>The file test/functional/feature_adaptorsig.py contains a simple test (translated from schnorr-fun) that demonstrates how to use the adaptor signature functions:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code>        <span class="c1"># Alice knows: signing_key
</span>        <span class="c1"># Bob knows: decryption_key
</span>        <span class="c1"># Both know: verification_key, encryption_key
</span>        <span class="n">signing_key</span> <span class="o">=</span> <span class="n">generate_privkey</span><span class="p">()</span> <span class="c1"># x
</span>        <span class="n">verification_key</span> <span class="o">=</span> <span class="n">compute_xonly_pubkey</span><span class="p">(</span><span class="n">signing_key</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span> <span class="c1"># X
</span>        <span class="n">decryption_key</span> <span class="o">=</span> <span class="n">generate_privkey</span><span class="p">()</span> <span class="c1"># y
</span>        <span class="n">encryption_key</span> <span class="o">=</span> <span class="n">encryption_key_for</span><span class="p">(</span><span class="nb">int</span><span class="p">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">decryption_key</span><span class="p">,</span> <span class="s">'big'</span><span class="p">))</span> <span class="c1"># Y
</span>        <span class="n">msg</span> <span class="o">=</span> <span class="n">hashlib</span><span class="p">.</span><span class="n">sha256</span><span class="p">(</span><span class="sa">b</span><span class="s">"give 100 coins to Bob"</span><span class="p">).</span><span class="n">digest</span><span class="p">()</span>

        <span class="c1"># Alice creates an encrypted signature for msg and sends it to Bob
</span>        <span class="n">encrypted_signature</span><span class="p">,</span> <span class="n">needs_negation</span> <span class="o">=</span> <span class="n">schnorr_adaptor_encrypt</span><span class="p">(</span><span class="n">signing_key</span><span class="p">,</span> <span class="n">verification_key</span><span class="p">,</span> <span class="n">encryption_key</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span>

        <span class="c1"># Bob verifies the encrypted signature and decrypts it
</span>        <span class="k">assert</span> <span class="n">schnorr_adaptor_verify</span><span class="p">(</span><span class="n">verification_key</span><span class="p">,</span> <span class="n">encryption_key</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">encrypted_signature</span><span class="p">,</span> <span class="n">needs_negation</span><span class="p">)</span>
        <span class="n">signature</span> <span class="o">=</span> <span class="n">schnorr_adaptor_decrypt</span><span class="p">(</span><span class="n">decryption_key</span><span class="p">,</span> <span class="n">encrypted_signature</span><span class="p">,</span> <span class="n">needs_negation</span><span class="p">)</span>

        <span class="c1"># Verify schnorr signature using standard method
</span>        <span class="k">assert</span> <span class="n">verify_schnorr</span><span class="p">(</span><span class="n">verification_key</span><span class="p">,</span> <span class="n">signature</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span>

        <span class="c1"># Bob then broadcasts the signature to the public.
</span>        <span class="c1"># Once Alice sees it she can recover Bob's secret decryption key
</span>        <span class="n">recovered_decryption_key</span> <span class="o">=</span> <span class="n">schnorr_adaptor_recover</span><span class="p">(</span><span class="n">encryption_key</span><span class="p">,</span> <span class="n">encrypted_signature</span><span class="p">,</span> <span class="n">signature</span><span class="p">,</span> <span class="n">needs_negation</span><span class="p">)</span>
        <span class="k">assert</span> <span class="n">recovered_decryption_key</span> <span class="o">!=</span> <span class="bp">None</span>

        <span class="c1"># Alice got the decryption key, otherwise the signature is not the decryption of our original encrypted signature
</span>        <span class="k">assert</span> <span class="n">recovered_decryption_key</span> <span class="o">==</span> <span class="nb">int</span><span class="p">.</span><span class="n">from_bytes</span><span class="p">(</span><span class="n">decryption_key</span><span class="p">,</span><span class="s">'big'</span><span class="p">)</span>
</code></pre></div></div>

<p>Ideally we would loop over different random and edge case key combinations to test this code, but for now the goal is more education than correctness.</p>

<h2 id="next-steps">Next Steps</h2>

<p>I should also take adantage of the fact that this adaptor signature implementation works in the functional test framework to test bitcoin transactions signed with Schnorr signatures recovered from adaptor signatures. I can then modify my eltoo <code class="language-plaintext highlighter-rouge">claim</code> transactions to use a key-path spend, and the <code class="language-plaintext highlighter-rouge">refund</code> transactions be script-path spends. I would also like to help AJ Towns test his <a href="https://twitter.com/ajtowns/status/1442737473142943747">new scheme</a> for poon-drya LN PTLCs.</p>]]></content><author><name>Richard Myers</name></author><summary type="html"><![CDATA[Motivation]]></summary></entry><entry><title type="html">eltoo with Anyprevout and Taproot</title><link href="https://yakshaver.org/2021/07/26/first.html" rel="alternate" type="text/html" title="eltoo with Anyprevout and Taproot" /><published>2021-07-26T00:00:00+00:00</published><updated>2021-07-26T00:00:00+00:00</updated><id>https://yakshaver.org/2021/07/26/first</id><content type="html" xml:base="https://yakshaver.org/2021/07/26/first.html"><![CDATA[<h2 id="motivation">Motivation</h2>

<p>With Taproot activation coming soon, now is a good time to look at <a href="https://github.com/bitcoin/bips/blob/master/bip-0118.mediawiki">BIP-118</a>, now known as Sighash Anyprevout and previously as Sighash Noinput. This soft fork enables a powerful new mechanism for replacing presigned transactions in off-chain protocols. The new Lightning Network state update protocol <a href="https://blockstream.com/eltoo.pdf">Eltoo</a>, for example, was designed around the existence of this transaction replacement mechanism.</p>

<p>In this blog post I will describe how to use the Bitcoin Core <a href="http://diyhpl.us/wiki/transcripts/scalingbitcoin/tel-aviv-2019/edgedevplusplus/bitcoin-core-functional-test-framework/">functional test framework</a> to test a set of Bitcoin Taproot transactions required by the eltoo protocol. These tests use a <a href="https://github.com/ajtowns/bitcoin/tree/202101-anyprevout">fork</a> of Bitcoin Core with an initial implementation of BIP-118 that builds on Taproot. In the <a href="#addendum">Addendum</a> I also summarize the relevant motivations and features of Anyprevout, eltoo and Taproot to give context for understanding these eltoo transactions, as well as the detailed Bitcoin scripts and transactions themselves.</p>

<p>The target audience for this write-up is anyone who wants to understand BIP-118, eltoo and Taproot better at the transaction and script level. You should be able to build Bitcoin Core from source and understand Python scripts. Following the steps below you will be able to see eltoo transactions confirmed on a local regtest network. My hope is that this will help people understand how these technologies work and give context for reviewing BIP-118. More people understanding and creating transaction tests for BIP-118 and eltoo will help find problems and improvements for both. More review and testing is critical before BIP-118 can be adopted by the Bitcoin network and eltoo by the Lightning network.</p>

<h2 id="tests">Tests</h2>

<p>I recommend that you confirm your system is setup to build Bitcoin Core and run the functional tests. If you have never done this before, then <a href="https://twitter.com/jonatack">Jon Atack</a> has a good summary of <a href="https://jonatack.github.io/articles/how-to-compile-bitcoin-core-and-run-the-tests">how to compile bitcoin core and run the tests</a>. Confirm your ability to run the functional tests (Step 8. in Jon’s summary) before proceeding.</p>

<p>You can now follow the steps again, but from my fork of the Bitcoin Core repository and using the <code class="language-plaintext highlighter-rouge">eltoo-anyprevout</code> branch:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone --single-branch --branch eltoo-anyprevout https://github.com/remyers/bitcoin.git bitcoin-eltoo-anyprevout
cd bitcoin-eltoo-anyprevout
git checkout eltoo-anyprevout
</code></pre></div></div>

<p>Now rebuild bitcoind patched with BIP-118 and run the new eltoo functional tests via the python script, for example:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>./autogen.sh 
... follow any other steps required to build for your system
make
test/functional/simulate-eltoo.py
</code></pre></div></div>

<p>The resulting output should end by showing that all tests passed:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Success!
2021-07-27T10:08:10.249000Z TestFramework (INFO): Stopping nodes
2021-07-27T10:08:10.505000Z TestFramework (INFO): Cleaning up /tmp/bitcoin_func_test_yjbnqj84 on exit
2021-07-27T10:08:10.505000Z TestFramework (INFO): Tests successful
</code></pre></div></div>

<h3 id="tests-explained">Tests Explained</h3>

<h4 id="taproot-tests">Taproot tests</h4>

<p>The file <code class="language-plaintext highlighter-rouge">/test/functional/simulate-eltoo.py</code> runs two tests. The first is <a href="https://github.com/remyers/bitcoin/blob/37a7490dc3b2128c0f7e34a463531f1123682d42/test/functional/simulate_eltoo.py#L1526">test_bitcoinops_workshop_tapscript</a> which goes through a short Taproot test based on the <a href="https://bitcoinops.org/en/schorr-taproot-workshop/#taproot">Schnorr Taproot Workshop</a> created by <a href="https://bitcoinops.org/">Bitcoin Optech</a>. I highly recommend these tutorials, but note that some changes in the Taproot BIP occurred after the workshop - specifically the change to <a href="https://medium.com/blockstream/reducing-bitcoin-transaction-sizes-with-x-only-pubkeys-f86476af05d7">“x-only” public keys</a> which reduce the size of keys by one byte. You can also check out their recent <a href="https://bitcoinops.org/en/preparing-for-taproot/">Preparing for Taproot</a> series.</p>

<h4 id="eltoo-tests">eltoo tests</h4>

<p>You should read both the <a href="https://github.com/bitcoin/bips/blob/master/bip-0118.mediawiki">BIP-118</a> specificaton and the <a href="https://blockstream.com/eltoo.pdf">eltoo</a> paper to understand these tests at a high level. The <a href="#apo">Anyprevout</a>, <a href="#l2">eltoo</a> and <a href="#tr">Taproot</a> sections below also summarize details relevant to understanding these eltoo transaction tests.</p>

<p>The second test, <a href="https://github.com/remyers/bitcoin/blob/37a7490dc3b2128c0f7e34a463531f1123682d42/test/functional/simulate_eltoo.py#L1623">test_tapscript_eltoo</a> performs the following tests after initializing some addresses, generating some coinbase outputs on the regtest network and funding the first eltoo state output.</p>

<p>All of the other transactions before the <a href="https://github.com/remyers/bitcoin/blob/37a7490dc3b2128c0f7e34a463531f1123682d42/test/functional/simulate_eltoo.py#L1694">divider line</a> are presigned transactions that in eltoo would occur without being immediately confirmed. Note that these tests use a normal Schnorr key and <strong>not</strong> a 2 of 2 multisig key created with something like <a href="https://medium.com/blockstream/musig2-simple-two-round-schnorr-multisignatures-bf9582e99295">MuSig2</a> for the internal Taproot key called <code class="language-plaintext highlighter-rouge">pubkey_AB</code>; except for how the public key and signatures are generated there should be no functional difference in how it is used in the test scripts.</p>

<ol>
  <li>
    <p>The first set of tests uses the function <code class="language-plaintext highlighter-rouge">test_transaction</code> to test if a transaction is valid <strong>without</strong> actually submitting it to the mempool. The first test checks if the <code class="language-plaintext highlighter-rouge">update1_tx</code> transaction is valid. We also confirm that <code class="language-plaintext highlighter-rouge">settle1_tx</code> when signed with <a href="#apo">APO</a> can not be rebound to <code class="language-plaintext highlighter-rouge">update0_tx</code> but that it can be rebound to a different state if incorrectly signed with <a href="#apo">APOAS</a>. Because APOAS does not commit to the exact script of the output this would allow any of the presigned Settle transactions to be bound to any of the Update transactions. The script then commits <code class="language-plaintext highlighter-rouge">update1_tx</code> into a block and generates <code class="language-plaintext highlighter-rouge">CSV_DELAY</code> number of blocks so that <code class="language-plaintext highlighter-rouge">settle1_tx</code> will be valid.</p>
  </li>
  <li>
    <p>The next section starts by modifying <code class="language-plaintext highlighter-rouge">settle1_tx</code> and <code class="language-plaintext highlighter-rouge">update2_tx</code> to rebind them to the specific <code class="language-plaintext highlighter-rouge">update1_tx</code> transaction that has now been confirmed on the blockchain. Because these transactions were signed with the APOAS and APO sighashes they do not commit to the transaction ID of a specific transaction. After these transactions are tested with <code class="language-plaintext highlighter-rouge">test_transaction</code>, the script commits to <code class="language-plaintext highlighter-rouge">update2_tx</code> to advance the channel to state 2.</p>
  </li>
  <li>
    <p>We then create the <code class="language-plaintext highlighter-rouge">update1b_tx</code> transaction which attempts to spend the <code class="language-plaintext highlighter-rouge">update2_tx</code> output back to channel state 1. This transaction uses the same pregenerated signature used by <code class="language-plaintext highlighter-rouge">update_1</code> but rebinds it to <code class="language-plaintext highlighter-rouge">update2_tx</code> instead of <code class="language-plaintext highlighter-rouge">update0_tx</code>. When <code class="language-plaintext highlighter-rouge">update1b_tx</code> is tested, it fails with the error message, <code class="language-plaintext highlighter-rouge">'non-mandatory-script-verify-flag (Locktime requirement not satisfied)'</code> because the signature commits to a transaction with a locktime of 1, which is less than the locktime encoded in the spending script of <code class="language-plaintext highlighter-rouge">update2_tx</code> and so the script fails.</p>
  </li>
  <li>
    <p>The next set of tests request we commit <code class="language-plaintext highlighter-rouge">settle2_tx</code> which can only spend from <code class="language-plaintext highlighter-rouge">update_2</code> because it uses the APO, and not APOAS, sighash. The APO sighash must be used because although the <code class="language-plaintext highlighter-rouge">update_2</code> script and amount are known, the exact transaction id of <code class="language-plaintext highlighter-rouge">update_2</code> was not known when it was signed and can change based on if <code class="language-plaintext highlighter-rouge">update_2</code> was bound to <code class="language-plaintext highlighter-rouge">update_0</code> or <code class="language-plaintext highlighter-rouge">update_1</code>.</p>
  </li>
  <li>
    <p>The final tests demonstrate how to spend the HTLCs outputs of <code class="language-plaintext highlighter-rouge">settle2_tx</code> using either a timeout via <code class="language-plaintext highlighter-rouge">htlc_refund_tx</code> or a hash preimage via <code class="language-plaintext highlighter-rouge">htlc_claim_tx</code>.</p>
  </li>
</ol>

<h4 id="fees">Fees</h4>
<p>Off-chain protocols must presigned transactions well in advance of when they are committed to a block. This means signers may not know the amount of fees to add for a transaction to be accepted into a block before a timeout critical to the protocol expires. The ability to select transactions fees at the time a transaction is committed reduces the risk a pre-signed transaction has too low a fee.</p>

<p>In these eltoo tests, HTLC refund and claim transactions are only signed by the channel partner collecting the HTLC and can include an additional fee input and change output. They also do not need to use an Anyprevout sighash. Update transactions also have a single input and output, so by using SIGHASH_SINGLE can add a fee input and change output just before commiting to the blockchain. Only the Settle transactions needs to allocate part of the channel balance in advance as transaction fees. The <a href="#challenges">Challenges</a> section discusses how this might be solved for eltoo and other off-chain protocols.</p>

<h4 id="bip-118-unit-tests">BIP-118 Unit tests</h4>

<p>In addition to high level functional tests for eltoo, there are also low-level tests added to <code class="language-plaintext highlighter-rouge">src/tests/sighash_tests.cpp</code> to exercise the new BIP-118 sighashes. They are implemented by the tests <a href="https://github.com/remyers/bitcoin/blob/5c1b157c2fd646305757e44cb6daea6b79bca75c/src/test/sighash_tests.cpp#L248">sighash_anyprevout_legacy</a> and <a href="https://github.com/remyers/bitcoin/blob/5c1b157c2fd646305757e44cb6daea6b79bca75c/src/test/sighash_tests.cpp#L404">sighash_anyprevout_taproot</a>. Review and expansion of theses tests would be very helpful.</p>

<h2 id="next-steps">Next Steps</h2>

<p>These transaction tests are only a very initial attempt at implementing eltoo so as to better understand how it works with BIP-118 and Taproot. Adding additional features will bring them closer to an actual working implementation.</p>

<h3 id="ptlcs">PTLCs</h3>

<p>Tapscript uses Schnorr signatures which allow us to replace <a href="https://bitcoinops.org/en/topics/htlc/">Hash Time Locked Contracts</a> with <a href="https://bitcoinops.org/en/topics/ptlc/">Point Time Lock Contracts</a> via adapter signatures. This will require modifying our <code class="language-plaintext highlighter-rouge">htlc_claim_tx</code> transaction to take a modified signature only and not a preimage.</p>

<p>PTLCs have three main advantages: they enhance privacy by removing the common preimage hash from transactions, transactions get smaller (which saves on transaction fees) and it also allow for “<a href="https://suredbits.com/payment-points-part-2-stuckless-payments/">stuckless payments</a>” as well as other more advanced features like escrowed payments.</p>

<h3 id="layered-commitments">Layered Commitments</h3>

<p>AJ Towns has proposed a modification of the eltoo protocol called <a href="https://lists.linuxfoundation.org/pipermail/lightning-dev/2020-January/002448.html">Layered Commitments</a> as a way to reduce the <a href="https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md#cltv_expiry_delta-selection">CLTV expiry delta</a> of eltoo which currently must include the CSV expiry time of its Update transaction which occurs before the Settle transaction becomes valid. Layered Commitments offer a way for each HTLC (or PTLC) to commit to either the Claim or Refund path before the CSV expiry time has expired and thus remove it from the CLTV expiry delta.</p>

<h3 id="multiparty-channels">Multiparty Channels</h3>

<p>A key feature of eltoo is the ability to support multiparty channels which can be used to create <a href="https://bitcoinops.org/en/topics/channel-factories/">Channel Factories</a> as originally described by Burchert, Decker and Wattenhofer in <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6124062/">Scalable funding of Bitcoin micropayment channel networks</a>. The current Poon-Dryja Lightning update scheme requires each channel partner to hold a different transaction, but using eltoo allows all channel partners to hold the same set of transactions for each update. This works because in eltoo newer state updates can spend from older ones, but Poon-Dryja channel updates assign a penalty to one side or the other if an old update is used. Assigning a penalty to enforce increasing state updates is difficult if you have more than two parties in each channel.</p>

<p>Extending these tests to explore channels with multiple parties will help confirm implementation details of this channel type. We would like to identify any problems or possible optimizations needed to make Channel Factories, and off-chain transactions generally, practical using multiparty channels.</p>

<h3 id="musig">Musig</h3>

<p>To refine message passing in our future eltoo simulation we should replace the single party Taproot internal key used by our eltoo transactions with a 2 of 2 multisignature Schnorr key using something like the <a href="https://medium.com/blockstream/musig2-simple-two-round-schnorr-multisignatures-bf9582e99295">MuSig2</a> protocol. This will also include exploring how the PTLC signing protocol can be combined with the Schnorr multisignature protocol. This step should also include a thorough examination of how to use a multisignature signing protocol with the least communication overhead while preserving its safety.</p>

<h3 id="simulation">Simulation</h3>

<p>Once we have finalized the eltoo transactions we can update the simulation code originally developed for the segwit (SIGHASH_NOINPUT) version of eltoo. A higher level simulation will help when creating more complicated tests and evolve to include mock message passing and other logic to more closely emulate the full Lightning protocol.</p>

<h2 id="challenges"><a name="challenges"></a>Challenges</h2>

<p>There are currently two main challenges identified for an eltoo implementation using BIP-118. The first is how to avoid long CLTV expiry delta values; it is hoped that the Layered Commitments scheme points the way to a solution. A potential downside of Layered Commitments though is that it removes the ability to use SIGHASH_SINGLE to defer adding transaction fee inputs and outputs to an eltoo Update transaction until it is committed to the blockchain.</p>

<p>The second challenge is how to generally have the ability to add transaction fee inputs and change outputs to eltoo transactions when they are commited to the blockchain instead of negotiating these values in advance to be paid from the channel balance. Current methods like RBF and CPFP could possibly help. Another suggested mechanism would be to replace SIGHASH_SINGLE with a mechanism to commit to a subset of outputs. Some ideas around this have recently been discussed in the “<a href="https://www.mail-archive.com/bitcoin-dev@lists.linuxfoundation.org/msg10280.html">A Stroll through Fee-Bumping Techniques : Input-Based vs Child-Pay-For-Parent</a>” thread on the bitcoin-dev mailing list. In particular the SIGHASH_GROUP proposal uses the new Taproot annex to specify a range of outputs committed to by a particular input.</p>

<h2 id="summary">Summary</h2>

<p>Implementing basic tests of the transactions required to implement eltoo using BIP-118 has been helpful for understanding both the BIP-118 and eltoo proposals and for being able to give useful feedback and review. Help is needed to implement the next steps outlined above; in the process we will likely uncover new challenges in addition to those already identified so far. BIP-118 requires a relatively small amount of code changes, but unlocks a huge design space for off-chain protocols of which eltoo is just one example. More people running and extending these tests will increase the amount of feedback and review and lead to faster consensus for adopting BIP-118.</p>

<h2 id="acknowledgements">Acknowledgements</h2>

<p>I’d like to thank <a href="https://twitter.com/Snyke">Christian Decker</a> for his patient mentorship on all things eltoo related and <a href="https://twitter.com/ajtowns">AJ Towns</a> for his help understanding the intricacies of the taproot versions of BIP-118 and eltoo. Thanks also to <a href="https://gotennamesh.com/products/mesh">goTenna</a> for their support of my <a href="https://globalmeshlabs.org/files/Lot49%20Protocol%20Whitepaper%20-%20DRAFT%200.8.5_20190611.pdf">Lot49</a> related Lightning development efforts and to the <a href="https://residency.chaincode.com/">Chaincode Labs Summer Residency</a> which allowed me to dedicate an entire summer to learning about Bitcoin and implementing my first eltoo simulation. Finally, my recent Bitcoin work was also made possible by a generous gift from the <a href="https://hrf.org/hrf-announces-new-recipients-of-gemini-backed-bitcoin-development-fund/">Human Rights Foundation Bitcoin Dev Fund</a>.</p>

<hr />

<h2 id="addendum">Addendum</h2>

<h3 id="anyprevout"><a name="apo"></a>Anyprevout</h3>

<p>BIP-118 proposes a soft fork that allows transactions to not just spend a specific previous transaction output, but instead any transactions output that uses the same signing key, in the case of SIGHASH_ANYPREVOUTANYSCRIPT (APOAS), or that spends an output with a specific amount and script in the case of SIGHASH_ANYPREVOUT (APO). Use of these two sighashes are enabled only for taproot script path spends of taproot transactions that reference a public key prepended with a <a href="https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki#cite_note-6">new public key type</a>. Some key features of BIP-118 are summarized below.</p>

<h4 id="taproot-key-type">Taproot Key Type</h4>

<p>To spend an output using a signature signed with APO or APOAS the tapscript must include a 32-byte schnorr public key prepended with the new ANYPREVOUT key type or alternately the single Anyprevout key type byte without a following 32 byte schnorr public key. If only the key type byte is used, then it will be substituted with the taproot internal public key. This removes the largest piece of data from the tapscript for the most common spending condition and yields a significant transaction fee saving. The example eltoo transactions below make use of this feature.</p>

<h4 id="transaction-hash">Transaction Hash</h4>
<p>The core changes of BIP-118 are to how transaction hashes are generated in the <a href="(https://github.com/remyers/bitcoin/blob/15a9df070615e7e8f29c17a92b889f19218f25ac/src/script/interpreter.cpp#L1492)">SignatureHashSchnorr</a> method of <code class="language-plaintext highlighter-rouge">bitcoin/src/interpreter.cpp</code> . This table summarizes which fields are hashed differently for the two new sighashes:</p>

<table>
  <thead>
    <tr>
      <th> </th>
      <th>SIGHASH_ANYPREVOUT (APO)</th>
      <th>SIGHASH_ANYPREVOUTANYSCRIPT (APOAS)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Prevout</td>
      <td><code class="language-plaintext highlighter-rouge">Excluded</code></td>
      <td><code class="language-plaintext highlighter-rouge">Excluded</code></td>
    </tr>
    <tr>
      <td>Amount</td>
      <td>Included</td>
      <td><code class="language-plaintext highlighter-rouge">Excluded</code></td>
    </tr>
    <tr>
      <td>ScriptPubkey</td>
      <td>Included</td>
      <td><code class="language-plaintext highlighter-rouge">Excluded</code></td>
    </tr>
    <tr>
      <td>Sequence</td>
      <td>Included</td>
      <td>Included</td>
    </tr>
    <tr>
      <td>Tapleaf Hash</td>
      <td>Included</td>
      <td><code class="language-plaintext highlighter-rouge">Excluded</code></td>
    </tr>
  </tbody>
</table>

<ul>
  <li>see also the <a href="https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2021-July/019257.html">sighash spreadsheet</a> made by Jeremy Rubin.</li>
</ul>

<h5 id="sighash-anyonecanpay">Sighash Anyonecanpay</h5>

<p>If either sighash APO or APOAS are used, then the signature behaves as if <a href="https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_ANYONECANPAY">SIGHASH_ANYONECANPAY</a> is used and allows additional inputs to be added to the transaction without invalidating the signature used for the input signed with these new sighashes. This feature is used by the eltoo transactions to add an additional input for transaction fees.</p>

<h5 id="sighash-single-or-all">Sighash Single or All</h5>
<p>Sighash APO or APOAS must be combined with either <a href="https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_SINGLE">SIGHASH_SINGLE</a> or <a href="https://en.bitcoin.it/wiki/OP_CHECKSIG#Hashtype_SIGHASH_ALL_.28default.29">SIGHASH_ALL</a> to indicate whether the signature commits to only a single output at the same index as the input, or all outputs in the transaction.  The eltoo <a href="#update_script">Update</a> transaction is signed with both SIGHASH_ANYPREVOUT and SIGHASH_SINGLE which allows for the addition of both a transaction fee input and change output.</p>

<h5 id="prevout">Prevout</h5>
<p>Both APO and APOAS ignore the prevout field of the output being spent. This enables the creation of pre-signed transactions that do not spend only a specific transaction that has already been confirmed on the blockchain.</p>

<h5 id="amount">Amount</h5>
<p>A transaction signed with APO, but not APOAS, commits to the specific amount of the output being spent. This creates a way to restrict which outputs can be spent from when the APO sighash is used. An input signed with APOAS has more flexibility to allow protocols that “consolidate a group of UTXOs with the same spending condition into a single UTXO” (see <a href="https://github.com/bitcoin/bips/blob/master/bip-0118.mediawiki#cite_note-3">BIP-118 ref 3</a>) and it also enables <a href="https://lists.linuxfoundation.org/pipermail/lightning-dev/2020-January/002448.html">Layered Commitments</a>.</p>

<h5 id="scriptpubkey">ScriptPubkey</h5>
<p>Only an input signed with APO commits to the exact script of the output being spent. An input signed with APOAS can spend any input that has matching spending conditions, even if the hash of the exact script is not the same. For example, the script for an <a href="https://github.com/remyers/bitcoin/blob/37a7490dc3b2128c0f7e34a463531f1123682d42/test/functional/eltoo_scripts.py#L43">eltoo state update</a> transaction includes the number of the state. This means that the hash of the script will be different for each state. Spending conditions, such as the key used to sign, can be used to constrain which output can be spent when APOAS is used to create the signature.</p>

<h5 id="sequence">Sequence</h5>
<p>Both APO and APOAS commit to the sequence number of the specific input being spent. This allows a way to restrict which transactions can be spent when these sighashes are used.</p>

<h5 id="tapleaf-hash">Tapleaf Hash</h5>
<p>APOAS does not commit to the root script of a transaction, defined by the ScriptPubkey of the output it spends, or the leaf script defined by the tapleaf hash of the spending transaction. APO does commit to a specific leaf script so must commit to a matching tapleaf hash.</p>

<h5 id="unchanged-fields">Unchanged Fields</h5>

<p>These fields are committed to in the same way both with or without BIP-118:</p>
<ul>
  <li>hash type: bit field used to sign,  eg. SIGHASH_ANYPREVOUT | SIGHASH_ALL</li>
  <li>version: of the spending transaction</li>
  <li>locktime: of the spending transaction</li>
  <li>spend type:  bit field that indicates key vs. script spend and whether an annex is present</li>
  <li>annex hash: hash of the annex, but only if an annex is present for the transaction</li>
  <li>key type: indicates the transaction is signed with a normal Taproot, Anyprevout or undefined key type.</li>
  <li>outputs hash: a hash of either all (SIGHASH_ALL) outputs in the spending transaction or just the output at the same index as the input of the spending transaction being signed (SIGHASH_SINGLE).</li>
  <li>code separator position: included for all script path spends</li>
</ul>

<p>See <a href="https://anyprevout.xyz/">anyprevout.xyz</a> and <a href="https://bitcoinops.org/en/topics/sighash_noinput/">Bitcoin Optech</a> for more discussion about the advantages and other uses of BIP-118.</p>

<h3 id="eltoo"><a name="l2"></a>eltoo</h3>

<p>The eltoo channel update protocol uses floating transactions that can spend from any older channel state, but not a newer one, using the anyprevout sighash. The eltoo protocol has three primary improvements over the current channel update mechanism used by Lightning:</p>
<ol>
  <li>no penalty for publishing an old channel state</li>
  <li>no need to store old state information</li>
  <li>compatible with multiparty channels</li>
</ol>

<p>It may also be possible to reduce the need to preselect transaction fees for uncooperative close transactions.</p>

<p>I have based my tests on the taproot <a href="https://lists.linuxfoundation.org/pipermail/lightning-dev/2019-May/001996.html">eltoo sketch</a> from AJ Towns, but without <a href="https://lists.linuxfoundation.org/pipermail/lightning-dev/2019-September/002176.html">chaperone signatures</a> (ie. the ‘X CHECKSIGVERIFY’ in his sketch).</p>

<h4 id="overview">Overview</h4>

<p>The Taproot eltoo scripts and transactions are pre-signed but not broadcast to the network except in the case of a non-cooperative close of the channel. Everytime the payment channel is updated, two new transactions are generated and pre-signed by both parties: one to immediately update the state of the channel and another to settle the value after a delay that gives time for a newer state to override it. When an update transaction is confirmed by the Bitcoin network, it can be spent, and effectively replaced, by a newer update, but not an older one, within a window of time after it was broadcast. After the relative timelock of an update transaction has expired, the corresponding settlement transaction can then spend its value and create outputs for settled value spendable by each of the two parties and inflight value as HTLC outputs that can be claimed by one party if they have a hash preimage, or refunded to the other after a timeout.</p>

<p>An update transaction uses the APOAS sighash to allow it to spend from any previous update transaction. A settlement transaction uses the APO sighash to bind it to a specific update transaction based on its script, which contains the state number, but not a specific transaction because the update transaction’s id can not be known when signing. A transaction to claim or refund an HTLC and collect the settled value only requires one party to sign so these can be signed after the settlement transaction has been confirmed in a block and does not need the APO or APOAS sighash.</p>

<p><img src="/assets/APO_APOAS_eltoo_transaction_diagram.png" alt="APO, APOAS eltoo transaction diagram" /></p>

<h4 id="scripts">Scripts</h4>

<p>Scripts for the update, settle, claim and refund transactions are described below. The update transaction is used to immediately spend an earlier update transaction with a lower state number. The settle transaction spends from a corresponding update transaction after a relative timelock has expired. A claim transaction immediately spends from the HTLC output of a specific settle transaction if presented with the correct hash preimage. A refund transaction can spend from the HTLC output of a specific settle transaction after a certain absolute clock time.</p>

<h5 id="update"><a name="update_script"></a>Update</h5>

<p>The first two lines of this script check that the corresponding transaction has been signed by a Schnorr key used as the Taproot internal key. This internal key should be a 2 of 2 multisig (eg. using <a href="https://medium.com/blockstream/musig2-simple-two-round-schnorr-multisignatures-bf9582e99295">MuSig2</a>) key and the signature should be generated by both channel parties. In these tests though we use a Schnorr key and signatures generated in the standard way for simplicity. OP_1 is used for a single byte anyprevout key that is replaced by the internal Taproot public key. The ctlv_start_time + state value represents the state number of the channel and is increased every time the channel is updated. As per <a href="https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki">BIP-65</a>, OP_CHECKLOCKTIMEVERIFY fails if the spending transaction has a nLocktime field with a value from an earlier state.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>OP_1	 
OP_CHECKSIGVERIFY
&lt;cltv_start_time + state&gt;
OP_CHECKLOCKTIMEVERIFY
</code></pre></div></div>

<p>Note that OP_CHECKLOCKTIMEVERIFY leaves the state constant on the stack, but because it is the last opcode there is no need to add an OP_DROP.</p>

<h5 id="settle"><a name="settle_script"></a>Settle</h5>

<p>The first two lines of this script check that the corresponding transaction has been signed by both parties in the same way as the update script. The csv_delay constant represents a relative block delay before which this transaction will not be valid. As per <a href="https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki">BIP-112</a>, OP_CHECKSEQUENCEVERIFY fails if the spending transaction has an nSequence field value not greater than the csv_delay and so can only be included in a block after that delay.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>OP_1
OP_CHECKSIGVERIFY
&lt;csv_delay&gt;
OP_CHECKSEQUENCEVERIFY
</code></pre></div></div>
<p>Note that OP_CHECKSEQUENCEVERIFY leaves the delay constant on the stack, but because it is the last opcode there is no need to add an OP_DROP.</p>

<h5 id="claim"><a name="claim_script"></a>Claim</h5>

<p>The input to this script is both a signature and a preimage value that when hashed matches the preimage_hash value encoded in the script. The OP_EQUALVERIFY opcode fails if they do not match. The pubkey constant is provided by the payee of the HTLC to ensure they can generate the signature to claim the HTLC output immediately if they learn the preimage by forwarding the payment successfully.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>OP_HASH160
&lt;preimage_hash&gt;
OP_EQUALVERIFY
&lt;pubkey&gt;
OP_CHECKSIG
</code></pre></div></div>

<h5 id="refund"><a name="refund_script"></a>Refund</h5>

<p>The pubkey constant is provided by the payer of the HTLC to ensure only they can generate the signature to claim the HTLC output if the payee has not forwarded the payment successfully. The expiry constant defines the time after which the payer can reclaim the HTLC balance. The OP_CHECKLOCKTIMEVERIFY opcode fails if the nLocktime value of the spending transaction does not exceed the expiry constant. The transaction can not be mined into a block until the median time past of the last 10 blocks exceeds the nLocktime of the transaction as per BIP-65 and <a href="https://github.com/bitcoin/bips/blob/master/bip-0113.mediawiki">BIP-113</a>.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;pubkey&gt;
OP_CHECKSIGVERIFY
&lt;expiry&gt;
OP_CHECKLOCKTIMEVERIFY
</code></pre></div></div>

<h4 id="transactions">Transactions</h4>

<h5 id="update-1"><a name="update_tx"></a>Update</h5>

<p>An Update transaction spends an old payment state to a new state. The transaction has the following field settings:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  nLocktime: &lt;cltv_start_time + state&gt;
  nVersion = 2
  Input nSequence: 0
  sighash = SINGLE | ANYPREVOUTANYSCRIPT
  Output 0: scriptPubkey = &lt;state_address&gt;
</code></pre></div></div>

<p>The nLocktime value is checked by the script to ensure it can only spend earlier states. The state_address is a Taproot address that encodes an Update script at the new state that can only be spent by specific Settle transaction for that state. A signature created by both channel partners in advance needs to be provided to spend an Update transaction to the output of a newer Update transaction. An Update transaction can spend any Update transaction with a lower state immediately. These transactions are signed with APOAS which allows the spending of an Update output from any transaction that is signed with the internal Taproot key for the channel and satisfies the script condition of a larger nLocktime.</p>

<h5 id="settle-1"><a name="settle_tx"></a>Settle</h5>

<p>A Settle transaction spends from a specific Update transaction with a matching scriptPubkey and amount. The transaction has the following field settings:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nLocktime: &lt;cltv_start_time + state + 1&gt;
nVersion = 2
Input nSequence: CSV_DELAY
sighash = ALL | ANYPREVOUT
Output 0: scriptPubkey = &lt;settled_amount_address_A&gt;
Output 1: scriptPubkey = &lt;settled_amount_address_B&gt;
Output 2...n: scriptPubkey = &lt;HTLC_addresses&gt;
</code></pre></div></div>

<p>The nSequence value of the field is checked by the script to ensure it can only spend from an Update output after <code class="language-plaintext highlighter-rouge">CSV_DELAY</code> blocks have been mined. This gives time for the other party to spend from the current Update output with an Update with a later state. This transaction is signed in advance by both parties with APO which means the Update output it spends from must have a matching scriptPubkey and amount. Because the scriptPubkey of the Update transaction is hashed from the script, and the script contains the state number, that ties a Settle transaction to a specific Update transaction. Once the Settle transaction is confirmed, then the settled amounts can be claimed immediately by each channel participant. The HTLC outputs can only be claimed by the payee (or refunded to the payer) based on the HTLC conditions.</p>

<h5 id="claim-1"><a name="claim_tx"></a>Claim</h5>

<p>A Claim transaction spends from an HTLC output of a confirmed Settle transaction. Because it only requires one party to sign it and spends from a settled transaction we do not need to use APO or APOAS to sign it.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nLocktime: 0
nVersion = 2
Input nSequence: DEFAULT_NSEQUENCE
sighash = SINGLE | ANYONECANPAY
Output 0: scriptPubkey = &lt;settled_amount_address_payee&gt;
</code></pre></div></div>

<p>To spend an HTLC output with this transaction requires a signature from the HTLC payee and also the preimage for the HTLC. There is no time lock and this output can be spent immediately. The settled amount they control and any HTLC outputs they can collect can be combined into a single transaction with fees deducted from the output.</p>

<h5 id="refund-1"><a name="refund_tx"></a>Refund</h5>

<p>A Refund transaction spends from an HTLC output of a confirmed Settle transaction. Because it only requires one party to sign it and spends from a settled transaction we do not need to use APO or APOAS to sign it.</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nLocktime: &lt;htlc_expiry&gt;
nVersion = 2
Input nSequence: DEFAULT_NSEQUENCE
sighash = SINGLE | ANYONECANPAY
Output 0: scriptPubkey = &lt;settled_amount_address_payer&gt;
</code></pre></div></div>

<p>To spend an HTLC output with this transaction requires a signature from the HTLC payer. The median time stamp of the last 11 blocks must also must be past <code class="language-plaintext highlighter-rouge">htlc_expiry</code> time. A transaction that spends the settled amount they control and any HTLC outputs they can collect can be combined into a single transaction with fees deducted from the output.</p>

<h3 id="taproot"><a name="tr"></a>Taproot</h3>

<p>The Update and Settle tapscripts are encoded as different leaves of a taptree computed for each eltoo state. The Update tapscript is presented to spend from an eltoo transaction to a newer eltoo state transaction. The Settle tapscript is presented to spend to the corresponding settle transaction for that state. The address of each HTLC output of the settle transaction encodes a Claim and Refund script as different leaves of a taptree. Presenting the Claim script and correct preimage is required to spend the output, or presenting the Refund script after the <code class="language-plaintext highlighter-rouge">htlc_expiry</code> time.</p>]]></content><author><name>Richard Myers</name></author><summary type="html"><![CDATA[Motivation]]></summary></entry></feed>