<p>A brief back history on the proposal:</p>
<p>Covenants were -- as far as I'm aware -- first discussed online in 2013, here <a href="https://bitcointalk.org/index.php?topic=278122.0" rel="nofollow noreferrer">https://bitcointalk.org/index.php?topic=278122.0</a></p>
<p>MES presented in 2016 OP_COV <a href="https://fc16.ifca.ai/bitcoin/papers/MES16.pdf" rel="nofollow noreferrer">https://fc16.ifca.ai/bitcoin/papers/MES16.pdf</a> which was essentially a basic covenant system based on pattern matching.</p>
<p>In 2017 I gave a talk at Stanford's BPASE on multi transaction merkelized covenants <a href="https://www.youtube.com/watch?v=r7xN7K0OqaA&amp;list=PLxiUDysqkJ9x6VsYjjphSA79pEHiMwdI_&amp;index=19" rel="nofollow noreferrer">video</a> <a href="https://rubin.io/talks/2017/01/26/multi-txn-contracts/" rel="nofollow noreferrer">slides</a> which introduces some of the motivations and design space for covenants. This is where the concept of congestion control was originally presented.</p>
<p>Following feedback from to conference,in 2018 I put together a system for emulating covenants using multiparty ECDSA pre-signing called <a href="https://github.com/JeremyRubin/lazuli" rel="nofollow noreferrer">lazuli</a> and presented it in Tokyo at the bitcoin developer workshop. The feedback I received was that the core community was disinterested in looking at any ECDSA based designs since schnorr was imminent.</p>
<p>Modern History:</p>
<p>The Lazuli concept (as you can see from the whitepaper) formed the basis for what CTV/BIP-119 became. Rather than doing ECDSA multi-party, maybe developers would find it acceptable to just directly commit to the pre-signed transaction hash. The difficulty here was making a comitted covenant that would not permit recursive covenants -- at least not unintentionally.</p>
<p>In May 2019 I presented the initial draft of this covenant idea under the name CHECKOUTPUTSHASHVERIFY to SF BitDevs. <a href="https://docs.google.com/presentation/d/1BuIJj8KkGFM8uOCXuQDgnwTLOHyUM72j6ofrkxwj_qg" rel="nofollow noreferrer">Slides</a>. I focused on the congestion control use case in particular as a clear cut motivation, although the presentation makes brief mention of other applications. Notably I included &quot;spawning channels&quot; as one of the intended use cases. This design also used a new pattern for a &quot;multi byte opcode&quot;, a &quot;forward argument&quot; where the verify semantics apply to the <em>next</em> argument ensuring that the data could not come from any computation but had to be statically known at address generation time. This was to make it trivial to prove no recursive covenants were possible.</p>
<p>I received feedback from online and in person:</p>
<ol>
<li>Russel O'Connor made a <a href="https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2019-June/017043.html" rel="nofollow noreferrer">strong argument</a> to <em>not</em> do a forward peeking argument, since the regular argument order (checking the thing on the stack not the script) was also safe &amp; preserved some script composition rules.</li>
<li>Greg Maxwell pointed out in <a href="https://freenode.irclog.whitequark.org/bitcoin-wizards/2019-05-24#24662080;" rel="nofollow noreferrer">IRC</a> that I needed to commit to more fields to prevent malleability.</li>
<li>The name was universally hated because it was so boring</li>
</ol>
<p>In response:</p>
<ol>
<li>I kept the forward peeking argument design (ignoring Russel's request) as I felt that the principal was already violated by OP_IF</li>
<li>More fields were comitted to to eliminate unintentional malleability and make it possible to predict the TXIDs in trees of transactions perfectly (for, e.g., channels).</li>
<li>It was renamed OP_SECURETHEBAG</li>
</ol>
<p>Over the next several months, I gathered more feedback &amp; made more tweaks on the design:</p>
<ol>
<li>In more conversations with Russell, we reached agreement to drop the forward peeking argument design in favor of normal reading from the stack (creating an upgrade path for using CTV more generally with things like OP_CAT).</li>
<li>The input_index was added to the digest to preclude the &quot;half spend problem&quot; where 2 identical covenants could unintentionally be satisfied in a single transaction.</li>
<li>The name OP_SECURETHEBAG was both more loved and hated than COSHV. COSHV was no longer technically accurate, so the name was changed to CheckTemplateVerify.</li>
</ol>
<p>At this juncture (roughly January 2020) I felt that the BIP was conceptually mature enough &amp; code wise stable enough to introduce a BIP.</p>
<p>In February 2020 I held the <a href="https://utxos.org/workshops/" rel="nofollow noreferrer">utxos.org workshop</a> to discuss the design of CTV (in it's current form).</p>
<p>Around April 2020, I also broke ground on Sapio (originally mentioned at Scaling Bitcoin '19 Tel Aviv as a possibility) to generalize the tooling for the smart contracts I was developing for CTV but hand rolling the code for.</p>
<p>Around February 2021, I released the first open source version of Sapio which had undergone many iterations (i.e., re-implemented from python to rust, custom scripts to miniscript).</p>
<p>Overall I don't find your assessment is quite correct as recursive covenants were never a part of CTV's design (always an anti-goal). Most of the changes made were not around flexibility, but around safety &amp; upholding the intended properties required to allow implementing something similar to Lazuli without requiring a multiparty (ECDSA or Schnorr) trust assumption. CTV's design process was inherently targetted at carving out a safe chunk of covenants to &quot;move the overton window&quot; on what would be possible/safe in Core. That there's now a growing wider desire for more general covenants is fantastic.</p>
<p>With the removal of the forward-peeking argument, CTV could be used in combination with future changes (e.g., OP_CAT/SHASTREAM) to build covenant descriptions on the stack. Effort has gone into ensuring that the transaction digest used in CTV is easy to manipulate on the stack by ordering fields in the order of least to most likely to change (&quot;static prefix assumption&quot;).</p>

CC BY-SA 4.0
2021-08-04T14:48:25.227Z
2021-08-04T14:48:25.227Z
Jeremy Rubin
<p><a href="https://github.com/bitcoin/bips/blob/master/bip-0119.mediawiki" rel="nofollow noreferrer">OP_CHECKTEMPLATEVERIFY (BIP 119)</a> has gone through various iterations. I don't particularly find the renames at all interesting (e.g. OP_CHECKOUTPUTSHASHVERIFY, OP_SECURETHEBAG) but I am interested in how the design of the opcode has changed and the trade-offs for these changes. My understanding is that the changes have mainly been motivated by how flexible or how generic the opcode should be i.e. whether it should support multiple use cases or be focused on one particular use case. I also understand that recursive covenants were initially supported but are not supported by OP_CHECKTEMPLATEVERIFY.</p>
<p>The current code for OP_CHECKTEMPLATEVERIFY is <a href="https://github.com/bitcoin/bitcoin/pull/21702" rel="nofollow noreferrer">here</a> but this isn't the best place for documenting why certain design decisions were made. The <a href="https://github.com/bitcoin/bips/blob/master/bip-0119.mediawiki" rel="nofollow noreferrer">BIP</a> doesn't seem to cover the evolution of the opcode either though there is some rationale for the current design.</p>

<soft-fork><bip119-checktemplateverify><covenants>
How has the design of the opcode OP_CHECKTEMPLATEVERIFY evolved over its various renames?
Michael Folkson
# How has the design of the opcode OP_CHECKTEMPLATEVERIFY evolved over its various renames?

(Asked by: username_0 on 2021-08-03)

[OP\_CHECKTEMPLATEVERIFY (BIP 119)](https://github.com/bitcoin/bips/blob/master/bip-0119.mediawiki) has gone through various iterations. I don't particularly find the renames at all interesting (e.g. OP\_CHECKOUTPUTSHASHVERIFY, OP\_SECURETHEBAG) but I am interested in how the design of the opcode has changed and the trade-offs for these changes. My understanding is that the changes have mainly been motivated by how flexible or how generic the opcode should be i.e. whether it should support multiple use cases or be focused on one particular use case. I also understand that recursive covenants were initially supported but are not supported by OP\_CHECKTEMPLATEVERIFY.

The current code for OP\_CHECKTEMPLATEVERIFY is [here](https://github.com/bitcoin/bitcoin/pull/21702) but this isn't the best place for documenting why certain design decisions were made. The [BIP](https://github.com/bitcoin/bips/blob/master/bip-0119.mediawiki) doesn't seem to cover the evolution of the opcode either though there is some rationale for the current design.

**Tags:** soft-fork, bip119-checktemplateverify, covenants


---

## 1 answers

### Answer by username_1 on 2021-08-04. Score: 2 | Accepted answer

A brief back history on the proposal:

Covenants were -- as far as I'm aware -- first discussed online in 2013, here <https://bitcointalk.org/index.php?topic=278122.0>

MES presented in 2016 OP\_COV <https://fc16.ifca.ai/bitcoin/papers/MES16.pdf> which was essentially a basic covenant system based on pattern matching.

In 2017 I gave a talk at Stanford's BPASE on multi transaction merkelized covenants [video](https://www.youtube.com/watch?v=r7xN7K0OqaA&list=PLxiUDysqkJ9x6VsYjjphSA79pEHiMwdI_&index=19) [slides](https://username_1.io/talks/2017/01/26/multi-txn-contracts/) which introduces some of the motivations and design space for covenants. This is where the concept of congestion control was originally presented.

Following feedback from to conference,in 2018 I put together a system for emulating covenants using multiparty ECDSA pre-signing called [lazuli](https://github.com/username_1/lazuli) and presented it in Tokyo at the bitcoin developer workshop. The feedback I received was that the core community was disinterested in looking at any ECDSA based designs since schnorr was imminent.

Modern History:

The Lazuli concept (as you can see from the whitepaper) formed the basis for what CTV/BIP-119 became. Rather than doing ECDSA multi-party, maybe developers would find it acceptable to just directly commit to the pre-signed transaction hash. The difficulty here was making a comitted covenant that would not permit recursive covenants -- at least not unintentionally.

In May 2019 I presented the initial draft of this covenant idea under the name CHECKOUTPUTSHASHVERIFY to SF BitDevs. [Slides](https://docs.google.com/presentation/d/1BuIJj8KkGFM8uOCXuQDgnwTLOHyUM72j6ofrkxwj_qg). I focused on the congestion control use case in particular as a clear cut motivation, although the presentation makes brief mention of other applications. Notably I included "spawning channels" as one of the intended use cases. This design also used a new pattern for a "multi byte opcode", a "forward argument" where the verify semantics apply to the *next* argument ensuring that the data could not come from any computation but had to be statically known at address generation time. This was to make it trivial to prove no recursive covenants were possible.

I received feedback from online and in person:

1. Russel O'Connor made a [strong argument](https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2019-June/017043.html) to *not* do a forward peeking argument, since the regular argument order (checking the thing on the stack not the script) was also safe & preserved some script composition rules.
2. Greg Maxwell pointed out in [IRC](https://freenode.irclog.whitequark.org/bitcoin-wizards/2019-05-24#24662080;) that I needed to commit to more fields to prevent malleability.
3. The name was universally hated because it was so boring

In response:

1. I kept the forward peeking argument design (ignoring Russel's request) as I felt that the principal was already violated by OP\_IF
2. More fields were comitted to to eliminate unintentional malleability and make it possible to predict the TXIDs in trees of transactions perfectly (for, e.g., channels).
3. It was renamed OP\_SECURETHEBAG

Over the next several months, I gathered more feedback & made more tweaks on the design:

1. In more conversations with Russell, we reached agreement to drop the forward peeking argument design in favor of normal reading from the stack (creating an upgrade path for using CTV more generally with things like OP\_CAT).
2. The input\_index was added to the digest to preclude the "half spend problem" where 2 identical covenants could unintentionally be satisfied in a single transaction.
3. The name OP\_SECURETHEBAG was both more loved and hated than COSHV. COSHV was no longer technically accurate, so the name was changed to CheckTemplateVerify.

At this juncture (roughly January 2020) I felt that the BIP was conceptually mature enough & code wise stable enough to introduce a BIP.

In February 2020 I held the [utxos.org workshop](https://utxos.org/workshops/) to discuss the design of CTV (in it's current form).

Around April 2020, I also broke ground on Sapio (originally mentioned at Scaling Bitcoin '19 Tel Aviv as a possibility) to generalize the tooling for the smart contracts I was developing for CTV but hand rolling the code for.

Around February 2021, I released the first open source version of Sapio which had undergone many iterations (i.e., re-implemented from python to rust, custom scripts to miniscript).

Overall I don't find your assessment is quite correct as recursive covenants were never a part of CTV's design (always an anti-goal). Most of the changes made were not around flexibility, but around safety & upholding the intended properties required to allow implementing something similar to Lazuli without requiring a multiparty (ECDSA or Schnorr) trust assumption. CTV's design process was inherently targetted at carving out a safe chunk of covenants to "move the overton window" on what would be possible/safe in Core. That there's now a growing wider desire for more general covenants is fantastic.

With the removal of the forward-peeking argument, CTV could be used in combination with future changes (e.g., OP\_CAT/SHASTREAM) to build covenant descriptions on the stack. Effort has gone into ensuring that the transaction digest used in CTV is easy to manipulate on the stack by ordering fields in the order of least to most likely to change ("static prefix assumption").


---

