Research/Bitcoin

OP_TXHASH: The Flexible Covenant Primitive That Could Unlock Bitcoin Programmability

OP_TXHASH lets scripts inspect parts of a transaction at runtime. How it works, what it enables, and where it sits in the covenant debate.

bcTanjiDec 5, 2026

Bitcoin scripts today are blind. They can verify signatures, check timelocks, and enforce multisig thresholds, but they cannot inspect the transaction that spends them. A script guarding a UTXO has no way to ask: where are these coins going? How much is being sent? What do the other outputs look like? This limitation is by design, but it also prevents an entire class of applications: covenants, spending conditions that constrain future transactions rather than just authorizing the current one.

OP_TXHASH, specified in BIP 346, proposes a way to give scripts that missing eyesight. Instead of hashing the entire transaction into a fixed template (as OP_CTV does) or requiring scripts to reconstruct data from raw bytes (as OP_CAT enables), OP_TXHASH lets the script choose exactly which transaction fields to hash. The result is a flexible transaction introspection primitive that generalizes simpler proposals while keeping resource costs bounded.

What Problem Does OP_TXHASH Solve

The covenant debate comes down to a question of granularity: how much of a spending transaction should a script be allowed to see? Too little, and you get rigid constructs that work for a narrow set of use cases. Too much, and you risk unbounded computation, unforeseen script interactions, and contentious upgrades that never reach consensus.

OP_TXHASH occupies a deliberate middle ground. It does not give scripts byte-level access to transaction data. Instead, it lets a script specify a selector that identifies which fields to include in a hash, then pushes the resulting 32-byte digest onto the stack. The script can then compare that digest against a precommitted value, combine it with other opcodes, or use it as input to OP_CHECKSIGFROMSTACK (BIP 348) to enforce custom signature commitments.

Key distinction: OP_TXHASH does not push raw transaction data onto the stack. It pushes a hash of selected fields. This means scripts can verify that specific fields match expected values without being able to read or manipulate the data directly, keeping the security model closer to signature-based verification than to general-purpose computation.

How the TxFieldSelector Works

The core mechanism in BIP 346 is the TxFieldSelector (TXFS): a variable-length byte string that the script places on the stack before calling OP_TXHASH. Each bit and byte in the selector determines which parts of the transaction get included in the hash. The opcode pops the selector, validates it, computes the hash over the specified fields for the current input index, and pushes the 32-byte result.

Global Fields

The selector can include transaction-wide properties that apply regardless of which input or output is being examined:

  • Transaction version number
  • Locktime
  • Input count and output count
  • Current input index (the index of the input being validated)

These global fields let a script enforce high-level transaction structure. For example, a script could require that the spending transaction has exactly two outputs without specifying what those outputs contain.

Per-Input and Per-Output Fields

The selector can also target specific inputs and outputs. For inputs, selectable fields include the previous outpoint (the TXID and index of the UTXO being spent), the sequence number, and the scriptPubKey and value of the UTXO being consumed. For outputs, scripts can commit to the scriptPubKey (destination address), the amount, or both.

The selection supports four modes for choosing which inputs or outputs to include:

  • All inputs or all outputs
  • Only the current input (the one being validated)
  • A leading range (the first N inputs or outputs)
  • Up to 32 individually specified indices

One-Byte Shorthand

For common patterns, a single-byte selector mirrors existing sighash flag behavior from BIP 341. This means the simplest OP_TXHASH invocations are compact: a one-byte selector that commits to all inputs and all outputs produces a hash semantically equivalent to what OP_CTV (BIP 119) computes. OP_TXHASH, in its most restricted mode, is CTV.

Selector ModeFields IncludedEquivalent To
Default (all inputs, all outputs)Version, locktime, all prevouts, all sequences, all output scripts and amountsOP_CTV (BIP 119)
Current input only, all outputsCurrent prevout, current sequence, all outputsSIGHASH_ANYONECANPAY | ALL
All inputs, current output onlyAll inputs, output at current indexSIGHASH_SINGLE
No inputs, no outputsVersion, locktime onlyNo existing equivalent
Custom individual indicesUp to 32 specific inputs/outputsNo existing equivalent

Relationship to Other Covenant Proposals

OP_TXHASH exists in a landscape of competing and complementary covenant proposals, each making different tradeoffs between simplicity, flexibility, and risk. Understanding where TXHASH sits requires comparing it to the other leading candidates.

OP_CTV: The Fixed Template

OP_CHECKTEMPLATEVERIFY (BIP 119) is the most conservative covenant proposal. It hashes a fixed set of transaction fields and verifies the result against a value on the stack. The script has no choice about which fields to include: it always commits to the same template. This rigidity is both its strength (smaller attack surface, easier to reason about) and its limitation (no partial commitments, no fee flexibility without workarounds like ephemeral anchors).

As of late 2026, CTV has an activation client using the Speedy Trial mechanism with a 90% miner signaling threshold. Its signaling window opened on March 30, 2026, with a minimum activation date around May 2027. Miner signaling has remained at zero percent through the first several months of the window.

OP_CAT: The Raw Concatenator

OP_CAT (BIP 347) takes a fundamentally different approach. Rather than hashing transaction fields directly, it re-enables byte concatenation on the stack, which was disabled in 2010 due to denial-of-service concerns. By itself, OP_CAT is not a covenant opcode, but combined with Schnorr signature verification and careful script construction, it enables scripts to reconstruct and verify transaction data at the byte level.

OP_CAT reached "Complete" specification status in March 2026 but has no mainnet activation parameters. Its flexibility is controversial: supporters see it as a general-purpose building block, while critics worry about recursive covenants and emergent complexity that is difficult to audit.

SIGHASH_ANYPREVOUT: The Signature Modifier

BIP 118 (APO) is not a covenant opcode in the traditional sense. It introduces new sighash modes for tapscript that allow signatures to skip committing to the input being spent. This enables rebindable transactions: the same pre-signed transaction can be attached to different inputs, which is the foundation of the eltoo (LN-Symmetry) protocol for Lightning channel state management.

Comparison Table

PropertyOP_CTV (BIP 119)OP_CAT (BIP 347)OP_TXHASH (BIP 346)APO (BIP 118)
MechanismFixed template hashByte concatenationSelectable field hashNew sighash modes
GranularityAll-or-nothingByte-level (indirect)Field-level (direct)Signature-level
Recursive covenantsNoYes (with tricks)No (by design)No
Fee flexibilityRequires workaroundsYesYes (omit fee-related fields)N/A
Script contextAll script typesTapscript onlyTapscript onlyTapscript only
Specification statusActivation client deployedComplete, no activationDraftDraft
Signet transactions~16~74,000Minimal~1,000
Can emulate othersNoTheoretically allCTV, APO (with CSFS)No

What OP_TXHASH Enables

The flexibility of the TxFieldSelector opens up applications that are either impossible or awkward with fixed-template approaches. Several concrete use cases illustrate the design space.

Vaults with Fee Flexibility

A vault is a spending policy that enforces a time delay before funds can move, giving the owner a window to claw back stolen coins. With OP_CTV, vault constructions must commit to exact fee amounts at setup time, which is problematic when fee markets are volatile. OP_TXHASH can commit to output destinations and amounts while leaving input selection flexible, allowing the spender to attach additional inputs for fees without breaking the covenant.

Congestion Control

During periods of high mempool congestion, a single on-chain transaction can commit to a tree of future payouts. The root transaction locks funds into a script that enforces a specific set of child transactions, each of which can be claimed later when fees drop. OP_CTV already enables this pattern, but OP_TXHASH allows more nuanced constructions: scripts can constrain outputs while leaving room for fee-bumping inputs, and partial expansions of the tree become possible without reconstructing the entire commitment chain.

Payment Pools

A payment pool lets multiple users share a single UTXO, with each participant able to exit unilaterally. The pool needs scripts that enforce output constraints (each participant gets their balance) while allowing flexible input composition. OP_TXHASH's ability to commit to specific output indices without committing to all inputs makes pool constructions more natural than with CTV, where every participant's exit transaction must be fully templated at pool creation time.

In-Band Fee Adjustment

One of the most practical advantages of selective field hashing is fee management. A covenant script can commit to outputs (enforcing where coins go and how much) while explicitly excluding inputs from the hash. This means anyone can add inputs to cover fees without invalidating the covenant, eliminating the need for pay-to-anchor outputs or CPFP workarounds.

Custom Sighash Emulation

When paired with OP_CHECKSIGFROMSTACK (BIP 348), OP_TXHASH can emulate arbitrary sighash flag combinations, including those proposed in BIP 118 (SIGHASH_ANYPREVOUT). The script hashes the desired fields with OP_TXHASH, then verifies a signature over that hash using CSFS. This combination provides fully generalized signature covenant functionality without requiring a new sighash type to be added to the consensus rules.

Subsumption argument: OP_TXHASH with OP_CHECKSIGFROMSTACK can replicate both CTV (by using the default selector) and APO (by omitting the prevout from the hash). This has led some developers to argue that TXHASH+CSFS is a more future-proof activation target than any individual proposal, though critics counter that subsumption is not the same as simplicity, and a more complex opcode carries higher review costs.

Technical Tradeoffs and Concerns

OP_TXHASH is not without risks. Its flexibility introduces concerns that simpler proposals avoid, and these tradeoffs are central to the activation debate.

Quadratic Hashing

If a script calls OP_TXHASH multiple times with overlapping field selections, the same transaction data could be hashed repeatedly, potentially leading to quadratic computation costs. BIP 346 addresses this with several mitigations: individual field selection is capped at 64 items, selecting all inputs or outputs reuses existing sighash caches, and for leading-range selections, the implementation can store intermediate SHA-256 states at regular intervals so that repeated calls only hash a bounded number of additional items.

The BIP also proposes reducing the tapscript validation budget by 10 units for every OP_TXHASH invocation, putting an upper bound on the number of hash computations per script execution. This approach mirrors how signature operations are already budgeted in tapscript.

Complexity vs. Simplicity

CTV's advocates argue that its fixed template is a feature, not a limitation. A reviewer can reason about CTV's behavior exhaustively: given the same template hash, the spending transaction is fully determined. OP_TXHASH introduces a combinatorial explosion of possible selector values, each producing different security properties. While any individual selector is straightforward to analyze, the space of possible selectors is large, and interactions between different selector choices in multi-input transactions are harder to reason about.

Non-Recursive by Design

Unlike OP_CAT-based constructions, OP_TXHASH cannot create recursive covenants: coins that are permanently restricted to a specific spending pattern across all future transactions. This is a deliberate design choice. OP_TXHASH hashes field data but does not allow scripts to read the raw bytes and re-encode them into output scripts. Some developers view this as a critical safety property (coins should always be "freeable"), while others see it as an unnecessary limitation that will eventually need to be lifted.

Specification Maturity

As of December 2026, BIP 346 remains in Draft status with no activation client, no mainnet signaling parameters, and limited signet testing compared to both CTV and OP_CAT. The specification has evolved since Steven Roose's initial September 2023 mailing-list proposal, with Brandon Black joining as co-author and several design changes reflected in the current draft. Open questions remain around whether the selector itself should be included in the hash (to prevent malleability) and whether the caching strategy is sufficient for adversarial workloads.

Where OP_TXHASH Fits in the Activation Landscape

The Bitcoin covenant debate has fractured into competing bundles, each packaging different combinations of opcodes. Understanding TXHASH's position requires mapping these proposals.

LNHANCE

The LNHANCE soft-fork bundle, proposed in January 2024, packages CTV (BIP 119), CSFS (BIP 348), OP_INTERNALKEY, and OP_PAIRCOMMIT. OP_TXHASH is not included. LNHANCE's proponents argue that CTV+CSFS provides sufficient covenant functionality for near-term applications like vaults, timeout trees, and LN-Symmetry, and that adding TXHASH increases the review burden without enabling qualitatively new use cases.

TXHASH as a CTV Replacement

Others argue that if the community is going to activate a template-hashing opcode, it should be the generalized version from the start. Under this view, activating CTV first creates technical debt: once TXHASH is available, CTV becomes redundant, and scripts that used CTV cannot benefit from TXHASH's flexibility without being rewritten. The counterargument is that CTV's simplicity makes it easier to review, test, and reach consensus on, and that "perfect is the enemy of shipped."

The Competing Bundles

As of 2026, three overlapping proposals target similar capabilities:

  • CTV + CSFS (the minimal toolkit for vaults and channel protocols)
  • LNHANCE (CTV + CSFS + INTERNALKEY + PAIRCOMMIT)
  • TXHASH + CSFS (the generalized alternative that subsumes CTV and APO)

A June 2026 open letter signed by 66 Bitcoin developers endorsed CTV and CSFS together as a pragmatic first step. Meanwhile, the activation debate continues to grapple with whether incremental upgrades or comprehensive packages are the safer path for Bitcoin's consensus layer.

Implications for Bitcoin Layer 2 Protocols

Covenant opcodes matter most at the edges: the points where Layer 2 protocols touch the base chain. Every L2 system needs a mechanism for users to exit back to Layer 1 when something goes wrong. Today, those exit mechanisms rely on pre-signed transactions and cooperative signing, which works but introduces trust assumptions.

With OP_TXHASH, exit scripts could enforce constraints directly in Bitcoin Script. A statechain-based system like Spark currently relies on the Spark Entity cooperating during transfers and generating pre-signed exit transactions for unilateral withdrawal. Covenants could allow users to encode exit conditions (output destinations, amounts, timelock sequences) directly into the UTXO's spending script, reducing the trust surface from "the operator must cooperate or you use a pre-signed transaction" to "the Bitcoin script enforces the exit rules regardless of operator behavior."

OP_TXHASH's selective field commitment is particularly relevant here. Exit transactions need to lock destination addresses and amounts but should leave inputs flexible for fee adjustment at the time of broadcast, which could be weeks or months after the exit transaction was constructed. The ability to commit to outputs while omitting inputs maps cleanly to this requirement.

For developers building on Spark, the Spark SDK and documentation provide the current integration path. The existing statechain architecture with FROST threshold signatures already delivers instant, self-custodial transfers. Covenant opcodes like OP_TXHASH would not replace this architecture but rather strengthen its exit guarantees at the base layer.

What Happens Next

OP_TXHASH's path forward depends on several factors that are still unresolved.

If CTV activates successfully, TXHASH's value proposition narrows: it becomes a generalization of an already-deployed primitive, useful but less urgent. If CTV's activation stalls (as the current zero-percent signaling rate suggests it might), TXHASH could emerge as an alternative that appeals to developers who want CTV's functionality plus the flexibility that CTV lacks.

The specification needs more review. The quadratic hashing mitigations are plausible but unproven under adversarial conditions. The TxFieldSelector encoding is complex enough that implementation bugs are a real risk. And the broader ossification debate looms over all covenant proposals: a significant fraction of the Bitcoin community believes the protocol should stop changing, period.

What is clear is that the demand for covenant functionality is not going away. Vaults, payment pools, congestion control, and trust-minimized L2 exits all require some form of transaction introspection. Whether that introspection arrives via CTV's fixed templates, TXHASH's selectable fields, CAT's raw byte manipulation, or some combination remains Bitcoin's most consequential open design question.

For a side-by-side breakdown of how each proposal handles specific use cases, see the covenant proposals comparison tool.

This article is for educational purposes only. It does not constitute financial or investment advice. Bitcoin and Layer 2 protocols involve technical and financial risk. Always do your own research and understand the tradeoffs before using any protocol.