Bitcoin Covenants Part 2: OP_CHECKTEMPLATEVERIFY
This is Part 2 in the technical article series about Bitcoin covenants by Cointelegraph Research. To read the previous article click here.
OP_CHECKTEMPLATEVERIFY (OP_CTV) was proposed by Jeremy Rubin in BIP 119. It defines spending conditions in a simple template structure that can include the outputs, version, and locktime of the next transaction. The opcode takes a commitment hash as an argument and requires that any transaction executing the opcode include only outputs that match this commitment.
Upon execution, OP_CTV expects this 32-byte commitment hash on top of the stack. The opcode then computes a fresh StandardTemplateHash from the current spending transaction to compare with this commitment hash. The serialized fields that go into the StandardTemplateHash include the transaction version and locktime, the counts of inputs and outputs, and a hash of all outputs, which commits to both their values and their locking scripts (scriptPubKeys). If the transaction matches the template, OP_CTV pushes a 1 on the stack to signal success; otherwise, it pushes a 0 to signal failure.
A basic locking script with OP_CTV would take the form <Commitment Hash> OP_CTV <PubKey> OP_CHECKSIG. This enforces both the transaction details and the authorization of the key holder. To introduce branching logic, where two or more possible transaction types are allowed, CTV can be combined with conditionals such as OP_IF and OP_ELSE. A script structured OP_IF <Hash_X> OP_CTV OP_ELSE <Hash_Y> OP_CTV OP_ENDIF gives the spender the option of two possible transaction templates, each enforced by a distinct commitment hash. The spender selects a branch, and OP_CTV verifies that the spending transaction matches the corresponding template. The hash for each path is computed from the full set of outputs and other fixed parameters defined for that transaction.
To illustrate a more advanced application of OP_CTV, suppose Alice wants to create a vault, i.e., a Bitcoin UTXO spending policy that constrains how funds can be spent, by requiring it to go through possible withdrawal paths. To spend her funds, they first need to be moved to an intermediary address from which they can either go to her hot wallet after a 100 block delay, or immediately be sent back to secure cold storage in case a compromise has taken place. This construction requires that three transaction templates and two OP_CTV ScriptPubKeys be created.
To deposit funds into this vault, she creates a vault output encumbered by OP_CTV that commits only to a single transaction template, Tx_Unvault. This template spends the vault UTXO to a second OP_CTV address, which creates the intermediate unvaulting output. The intermediate output, in turn, has two possible spending templates. The first template, Tx_Hot, defines the normal withdrawal path and spends the unvaulting output to her hot wallet after a 100-block relative timelock enforced by OP_CHECKSEQUENCEVERIFY (OP_CSV) via the previous transaction’s nSequence. The second template, Tx_Cold, defines the emergency recovery path that can be triggered in case her keys are compromised. It spends the attempted unvault directly back to cold storage without delay.
Alice computes a CTV commitment hash for each template. She then constructs the vault’s locking script as a P2WSH output, committing to the redeem script shown in Figure 1.
Figure 1: Hot Branch Spend of Alice’s P2WSH Transaction
OP_0 <sha256(
OP_IF
<100> OP_CHECKSEQUENCEVERIFY
OP_DROP
<Hash_Hot> OP_CHECKTEMPLATEVERIFY
<Hot_PubKey> OP_CHECKSIG
OP_ELSE
<Hash_Cold> OP_CHECKTEMPLATEVERIFY
<Cold_PubKey> OP_CHECKSIG
OP_ENDIF
)>
If Alice takes the normal withdrawal path, she waits 100 blocks, builds Tx_Hot exactly as precommitted, and provides her hot key signature with OP_1 to select the first branch. The relative time-lock countdown does not begin until an attempt is made to unvault the funds. In either case, the spending transaction must match one of the pre-committed templates exactly.
The constraints expressible through OP_CTV are similar to those that can already be achieved through pre-signed transactions. However, OP_CTV avoids having to generate and later dispose of ephemeral keys. Because OP_CTV does not commit to txids, an OP_CTV address can also be reused, as long as it is funded with the exact amount required by the output template. If the UTXO sent to an OP_CTV is too small, it can become unspendable. If it is too large, the excess can become a compulsory miner tip. OP_CTV results in a more trust-minimized mechanism for constructing vaults, congestion-control schemes, and other smart contract primitives, but some of the rigidity of pre-signed transactions remains.
In our next article we will commence our discussion of SIGHASH_ANYPREVOUT (APO), which is another well discussed proposal for opcodes that fully implement covenant functionality.
Disclaimer: The content of this article solely reflects the author's opinion and does not represent the platform in any capacity. This article is not intended to serve as a reference for making investment decisions.
You may also like
The AI boom may follow the path of the 19th-century railway bubble, and builders may not be the ultimate winners
Goldman Sachs analyst Bobby Molavi compared the current situation to the 19th-century British railway mania: 500 companies spent more than the nation's annual income building 8,000 miles of railway, with most early investors losing out, while the real beneficiaries were the later "passengers." He pointed out that the current AI craze is driven by both debt and momentum, and that the S&P 500’s forward P/E ratio of 18x is only "a bit cheaper." Whether the builders can retain value is uncertain, and history does not offer an optimistic answer.

If Anthropic's IPO goes smoothly and the stock price rises next week, then everything remains the same for AI. Otherwise, some companies will go bankrupt.
The shrinking valuations of two major giants have triggered a chain reaction—investors are adopting more conservative revenue multiples for AI startups and are directly halting high-valuation financing for companies with zero revenue. Multiple venture capital firms have advised their portfolio companies to lower valuation expectations and to quickly build up cash reserves. Market participants warn that the outcome of Anthropic’s IPO will be a barometer for the industry: if successful, the boom will continue; if it fails, some companies may face elimination.
After the Brazilian election, political discount deepens; Morgan Stanley remains bullish on Petrobras (PBR.US), focusing on fuel pricing and dividends
Morgan Stanley still maintains its most optimistic "Overweight" rating, but has lowered its year-end 2027 target price from $31 to $25.

Corning (GLW.US) receives initial "Buy" rating from Jefferies! AI factories driving a fiber optic rush, with a potential global supply gap of up to 30%
For Corning, the recent profit growth mainly comes from the expansion of AI clusters. As the number of optical links crossing cabinets and campuses increases, customers need to deploy more optical fibers within limited conduit and cabinet space, thus driving demand for high-density optical cables and connection systems.

