bitcoin-dev
Multi-byte opcodes
Posted on: November 18, 2024 17:15 UTC
The recent discussion on the Bitcoin Development Mailing List highlighted innovative approaches to opcode behavior in Bitcoin script development.
A notable suggestion involves utilizing opcode families where arguments are augmented with flags to influence their behavior, a method already implemented in opcodes like OP_CHECKSIG*. This strategy allows for flexibility in specifying the behavior of the hashing portion of the opcode. Similarly, both OP_CHECKTEMPLATEVERIFY (CTV) and OP_CHECKSIGFROMSTACKVERIFY (CSFSV), as proposed in the current PR, adopt this design philosophy. These opcodes specifically limit the first argument to 32 bytes but do not restrict extensions using different lengths. This opens up possibilities for leveraging varying lengths of either opcode as OP_OP, or creating variants on CTV and CSFSV. The advantage of this approach is its efficient use of the length byte. It serves not only to define the opcode's behavior but also to indicate the total length of the first argument, encompassing both flags and data, thereby optimizing opcode functionality without wasting resources.