[0/4] A Bitcoin Scripting Proposal BIP Quartet

Posted by Rusty Russell

Sep 27, 2025/11:29 UTC

This BIP introduces a new opcode, OP_TX, for tapscript v2, enhancing the Bitcoin scripting system by enabling explicit and efficient introspection of the current transaction. This feature allows scripts to directly access and perform operations on various parts of the transaction data, facilitating a wide range of conditional spending scenarios without relying on external oracles or pre-signed transactions. The design of OP_TX is grounded in the original vision of Bitcoin that emphasizes eliminating dependence on trusted third parties, ensuring that the network can enforce spending conditions autonomously.

The functionality of OP_TX extends beyond simple data retrieval; it supports extracting multiple values simultaneously into a single stack element, optimizing for common use cases where specific transaction fields must meet exact criteria. This approach contrasts with less efficient methods that would require accessing each piece of data individually. The opcode operates by taking a selection vector from the stack, which specifies the parts of the transaction to extract based on predefined selector bits for inputs, outputs, and other transaction metadata. Depending on these selections, OP_TX can output a variety of information, including transaction version, input and output counts, specific input and output details, and more, all while adhering to certain constraints to prevent excessive resource usage.

A notable aspect of OP_TX is its runtime success semantics for undefined bits in the selection vector, enhancing script upgradability. This forward-thinking feature allows future expansions of the opcode's capabilities without breaking compatibility with existing scripts. The decision-making process behind selecting which parts of a transaction to access reflects a balance between flexibility and efficiency, offering four distinct modes for both input and output selection to cover most practical needs.

The implementation of OP_TX also considers the computational cost associated with accessing transaction data. The "varops cost" is introduced as a measure to ensure the opcode's use remains within reasonable limits, preventing potential abuse that could lead to performance issues. This cost calculation takes into account the total bytes extracted and imposes restrictions on the maximum allowable size and number of stack elements, maintaining the integrity and efficiency of script execution.

Despite its comprehensive design, the BIP acknowledges areas for further optimization, particularly regarding the ordering of bits in the selection vector. This openness to future improvements underscores the proposal's commitment to fostering a collaborative development environment, inviting contributions from the wider Bitcoin developer community to refine and enhance the opcode's functionality.

In summary, OP_TX represents a significant advancement in Bitcoin scripting, offering a robust mechanism for transaction introspection that aligns with the decentralized ethos of Bitcoin. Its introduction promises to expand the possibilities for creating complex, condition-based spending scripts, further solidifying Bitcoin's position as a versatile and secure digital currency platform.

Link to Raw Post
Bitcoin Logo

TLDR

Join Our Newsletter

We’ll email you summaries of the latest discussions from high signal bitcoin sources, like bitcoin-dev, lightning-dev, and Delving Bitcoin.

Explore all Products

ChatBTC imageBitcoin searchBitcoin TranscriptsSaving SatoshiDecoding BitcoinWarnet
Built with 🧡 by the Bitcoin Dev Project
View our public visitor count

We'd love to hear your feedback on this project.

Give Feedback