CHIPs · CHIP-2021-02 · activated
Native Introspection Opcodes
Added 14 opcodes that let contracts read the current transaction directly: input and output values, bytecode, counts, locktime and more.
Summary
This CHIP adds virtual machine operations that let a contract read details of the transaction spending it: output values, recipients, input bytecode and more. It does this “without increasing transaction validation costs,” because nodes already hold all of that data while validating.
Motivation
Covenants (contracts that check how their coins are spent) became possible on BCH with
OP_CHECKDATASIG in 2018. But they used a workaround: check the same signature with both
OP_CHECKSIG and OP_CHECKDATASIG, then parse a copy of the transaction’s signing data pushed by the spender.
The CHIP says this “doubles or triples the size of even the simplest covenant transactions,” and advanced covenants hit the 1,650-byte standard unlocking script limit. Native opcodes remove the duplication.
What it specifies
Fourteen opcodes at codepoints 0xc0–0xcd:
| Opcode | Pushes |
|---|---|
OP_INPUTINDEX |
index of the input being evaluated |
OP_ACTIVEBYTECODE |
bytecode currently being evaluated |
OP_TXVERSION |
transaction version |
OP_TXINPUTCOUNT |
number of inputs |
OP_TXOUTPUTCOUNT |
number of outputs |
OP_TXLOCKTIME |
transaction locktime |
OP_UTXOVALUE |
value of the coin spent by input N |
OP_UTXOBYTECODE |
locking bytecode of that coin |
OP_OUTPOINTTXHASH |
txid referenced by input N |
OP_OUTPOINTINDEX |
output index referenced by input N |
OP_INPUTBYTECODE |
unlocking bytecode of input N |
OP_INPUTSEQUENCENUMBER |
sequence number of input N |
OP_OUTPUTVALUE |
value of output N |
OP_OUTPUTBYTECODE |
locking bytecode of output N |
The CHIP recommended deploying it with Bigger Script Integers, since values can exceed 32-bit range.
Current status
Activated on 15 May 2022. The CHIP records acceptance by Bitcoin Unlimited, Bitcoin Cash Node, Knuth, Bitcoin Verde and Bitauth. Its statements section includes support from Flowee’s founder Tom Zander and from Rosco Kalis, who committed to supporting all the opcodes in CashScript. General Protocols’ early statement said the CHIP needed more analysis before it could take a strong position, while committing resources to support it.
Stakeholder positions
Only public statements we could link to. Silence is not listed as a position.