BIP-342 (Tapscript)

The script validation rules for Taproot's script path, with cleaned-up opcodes and signature behaviour.

Basically

Tapscript is the set of rules for spending Bitcoin through a Taproot script. It updates how scripts check signatures and leaves room for future upgrades.

Key Takeaways

  • BIP-342 defines Tapscript, the upgraded scripting language used inside Taproot script-path spends. It replaces legacy multisig opcodes with OP_CHECKSIGADD and enforces Schnorr signature validation for all signature checks.
  • OP_SUCCESS opcodes replace previously disabled opcodes. They provide a clean mechanism for introducing new Bitcoin Script features through future soft forks without the limitations of OP_NOP-based upgrades.
  • Tapscript removes the 10,000-byte script size limit and 201-opcode cap from legacy Script. This enables more complex contracts, while a per-script signature operations budget provides DoS protection.

What Is BIP-342 (Tapscript)?

BIP-342 is a Bitcoin Improvement Proposal authored by Pieter Wuille, Jonas Nick, and Anthony Towns. It specifies Tapscript, the set of script validation rules governing Taproot script-path spends. BIP-341 defines the Taproot output structure and its Merkle tree of scripts, while BIP-342 defines what happens when one of those scripts actually executes.

Tapscript activated alongside Taproot on November 14, 2021, at block height 709,632. It modernises Bitcoin Script by integrating Schnorr signatures, removing artificial resource limits, and adding upgrade hooks that make future soft forks easier to deploy. Leaf version 0xc0 identifies it within the BIP-341 framework.

BIP-340 (Schnorr signatures), BIP-341 (Taproot output structure), and BIP-342 (Tapscript validation rules) form a single integrated upgrade to Bitcoin's transaction capabilities. For a broader overview of this upgrade, see the research article on Taproot and Schnorr signatures.

How It Works

A Taproot output spent via the script path rather than the key path reveals a script leaf from the Merkle tree in the witness data. If that leaf has version 0xc0, the script executes under Tapscript rules. These rules modify several aspects of legacy Bitcoin Script.

OP_CHECKSIGADD Replaces OP_CHECKMULTISIG

Legacy Bitcoin Script uses OP_CHECKMULTISIG for multi-signature operations, but this opcode is incompatible with Schnorr batch verification. OP_CHECKMULTISIG does not associate specific signatures with specific public keys until runtime. The resulting combinatorial search prevents efficient batch validation.

Tapscript disables OP_CHECKMULTISIG and OP_CHECKMULTISIGVERIFY entirely, so they cause immediate script failure. In their place, BIP-342 introduces OP_CHECKSIGADD (opcode 0xba), which pops three elements from the stack: a public key, a counter, and a signature. If the signature is valid, it pushes the counter incremented by one; if the signature is empty, it pushes the counter unchanged.

A k-of-n multisig in Tapscript chains individual signature checks rather than bundling them. You check each signature separately.

Each public key pairs with exactly one signature or an empty value. This enables Schnorr batch verification across an entire block of transactions.

Schnorr Signature Validation

Tapscript modifies OP_CHECKSIG and OP_CHECKSIGVERIFY to verify Schnorr signatures per BIP-340 instead of ECDSA. The signature format is strict.

Public keys in Tapscript follow a versioning scheme. Keys of 32 bytes are validated as BIP-340 Schnorr keys, while keys of unknown sizes are treated as valid but unverified. This allows future soft forks to introduce new signature algorithms without modifying Tapscript itself.

The Signature Message

Tapscript extends the BIP-341 common signature message with three additional fields. These fields commit to the specific script being executed.

All hash computations use tagged hashes for domain separation, following the pattern: SHA256(SHA256(tag) // SHA256(tag) // message). The Tapscript signature hash uses the tag "TapSighash".

OP_SUCCESS: A Soft Fork Upgrade Mechanism

BIP-342 redefines a set of previously disabled opcodes (80, 98, 126-129, 131-134, 137-138, 141-142, 149-153, 187-254) as OP_SUCCESSx. When any of these opcodes appears in a Tapscript, the entire script succeeds unconditionally during the decoding phase. This happens before any execution begins.

OP_SUCCESS offers a significant improvement over legacy OP_NOP-based upgrades. OP_NOP opcodes can only add new validation conditions because they cannot modify the stack, while OP_SUCCESS opcodes bypass all validation and allow a future soft fork to redefine them with full stack read and write access. The redefinition simply makes a previously-always-succeeding opcode sometimes fail, which is a valid soft fork because it tightens the rules.

Removed Resource Limits

Tapscript lifts two constraints that limited legacy Bitcoin Script. These are the 10,000-byte script size limit and the 201-opcode cap.

The script size limit was safe to remove because the Tapscript signature hash commits to scripts indirectly through a precomputable tapleaf_hash. This eliminates the O(n²) hashing concern that justified the original limit. For DoS protection, Tapscript uses a per-script signature operations budget calculated as 50 plus the total serialised size of the input witness in bytes, with each successful signature check costing 50 units from this budget.

MINIMALIF Consensus Enforcement

In legacy Script, the MINIMALIF rule requires OP_IF and OP_NOTIF arguments to be exactly empty or exactly the byte 0x01, but it is only a relay policy. Tapscript promotes this to a consensus rule. This closes a script malleability vector where third parties could alter transaction witnesses without invalidating them.

Efficient Multi-Signature Schemes

OP_CHECKSIGADD enables clean k-of-n multisig scripts where each signer provides exactly one signature or an empty value. This pairs naturally with threshold signature schemes. Simple cases use the Taproot key path with aggregated keys, while complex fallback conditions live in Tapscript leaves.

Advanced Smart Contracts

The removal of script size and opcode limits opens the door for more sophisticated Bitcoin contracts. Miniscript policies that previously bumped against the 201-opcode ceiling can now express richer spending conditions. Combined with Taproot's Merkle tree of scripts, developers can encode dozens of spending paths without bloating on-chain data, as explored in the research article on Bitcoin Script programmability.

Future Protocol Upgrades

OP_SUCCESS opcodes provide a clean path for introducing new functionality via soft fork. Proposals like covenants (OP_CHECKTEMPLATEVERIFY, OP_VAULT) and other advanced opcodes can be deployed by redefining an OP_SUCCESS opcode. The public key versioning mechanism similarly allows future signature schemes to coexist with Schnorr without modifying Tapscript's core logic.

Layer 2 Protocols

Tapscript improvements benefit Layer 2 protocols that rely on complex on-chain scripts for dispute resolution and exit mechanisms. Protocols like Spark, Lightning, and Ark can use more expressive Tapscript leaves for their on-chain components. They can keep the common cooperative case in the efficient key path.

Complexity for Wallet Developers

Tapscript introduces new signature hashing, opcode behaviour, and resource limit rules that wallet and library developers must implement correctly. The interaction between leaf versions, public key versions, and OP_SUCCESS semantics requires careful handling. Wallets that support Taproot script-path spending must fully implement BIP-342 validation to avoid accepting invalid transactions or producing invalid signatures.

Script Size and Witness Costs

Tapscript removes the script size limit, but larger scripts still cost more in witness data weight. The per-script sigops budget also ties signature capacity to witness size, so complex multi-signature arrangements require proportionally larger witnesses. Developers must balance contract expressiveness against on-chain cost.

OP_SUCCESS and Validation Risks

Any Tapscript containing an OP_SUCCESS opcode is unconditionally valid today. If a wallet or application accidentally includes an OP_SUCCESS opcode in a script, anyone can spend the output. This is by design for upgradability, but developers must avoid using undefined opcodes in production scripts until they are redefined by a future soft fork.

Adoption and Compatibility

Tapscript is only available within Taproot (SegWit v1) outputs, while legacy and SegWit v0 scripts continue using the old rules. Applications that want Tapscript benefits must migrate to P2TR output types, which requires updates across the wallet stack: key generation, address encoding, signing, and transaction construction. The research article on Bitcoin address types covers this migration path in detail.

This glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.

0

← All 1876 glossary terms