Opcodes · splice · enabled

OP_SIZE (0x82)

Pushes the byte length of the top item without removing it.

Verified
Stack in → out
x → x len
Since
Original Bitcoin script
Cost
Base instruction cost 100 plus the byte length of the pushed result (2025 VM limits).
Bitcoin status
Same in Bitcoin (BTC)

Example

<0x112233> OP_SIZE OP_3 OP_EQUALVERIFY
Step Stack after (top on the right) What happens
<0x112233> 112233
OP_SIZE 112233 3 Pushes the length. The item itself stays.
OP_3 112233 3 3
OP_EQUALVERIFY 112233 The length was 3, so the script goes on with the item.

Step through it opcode by opcode in Bitauth IDE, the in-browser BCH VM debugger.

Where OP_SIZE is used

  • Contracts CashScript .length : bytes.length compiles to OP_SIZE OP_NIP: measure, then drop the item. Contracts use it to check a preimage or an NFT commitment has the expected size.
  • CHIP VM Limits: Targeted Virtual Machine Limits : Raised the largest stack item from 520 to 10,000 bytes, so OP_SIZE can now return up to 10,000.

Sources

  1. Libauth BCH_2023_05 opcodes (bch-2023-opcodes.ts)