TeachMeBitcoin

OP_LEFT and OP_RIGHT - Disabled Slice Opcodes

From TeachMeBitcoin, the free encyclopedia Reading time: 4 min

6. OP_LEFT and OP_RIGHT — Disabled Slice Opcodes

Overview

OP_LEFT (0x80) and OP_RIGHT (0x81) are companion slice opcodes that extract a prefix or suffix of a byte string, respectively. Both were disabled in August 2010 along with the rest of the string manipulation family.

OP_LEFT opcode value: 0x80 | Current status: Disabled
OP_RIGHT opcode value: 0x81 | Current status: Disabled

OP_LEFT — Extract Prefix

OP_LEFT takes a byte string and an integer n, and returns the first n bytes of the string.

Stack before: [ <string> <n> ]
                          ↑ top

OP_LEFT:
  Pops <n>      (number of bytes to take from left)
  Pops <string>
  Returns: string[0 : n]  (first n bytes)
  Pushes result

Stack after: [ <first_n_bytes_of_string> ]

Example:
  string = 0xDEADBEEFCAFE  (6 bytes)
  n      = 3
  Result = 0xDEADBE         (first 3 bytes)

Edge cases:
  n = 0              → returns 0x (empty byte array)
  n = len(string)    → returns entire string (copy)
  n > len(string)    → would be error/undefined

OP_RIGHT — Extract Suffix

OP_RIGHT mirrors OP_LEFT, taking the last n bytes instead:

Stack before: [ <string> <n> ]
                          ↑ top

OP_RIGHT:
  Pops <n>
  Pops <string>
  Returns: string[len(string)-n : len(string)]  (last n bytes)
  Pushes result

Stack after: [ <last_n_bytes_of_string> ]

Example:
  string = 0xDEADBEEFCAFE  (6 bytes)
  n      = 3
  Result = 0xEFCAFE         (last 3 bytes)

Edge cases:
  n = 0              → returns 0x (empty byte array)
  n = len(string)    → returns entire string
  n > len(string)    → error

Use Cases

While OP_SUBSTR provides general slicing, OP_LEFT and OP_RIGHT handle two extremely common patterns more concisely. Common use cases would have included:

1. Address/hash extraction from compound encodings:

Suppose a 33-byte compressed public key is on the stack.
Extract the 32-byte x-coordinate (drop the first prefix byte):

  <33-byte-pubkey> OP_1 OP_RIGHT ... wait, RIGHT gives suffix
  Actually: 32 OP_RIGHT → last 32 bytes (x-coordinate without prefix byte)

  Or to get the prefix byte only:
  <33-byte-pubkey> OP_1 OP_LEFT → 0x02 or 0x03 (the parity prefix)

2. Version byte extraction:

Many Bitcoin data formats begin with a version byte.
OP_1 OP_LEFT would extract just that version byte for comparison.

  <versioned_data> OP_1 OP_LEFT <expected_version> OP_EQUAL

3. Combining with OP_CAT for byte manipulation:

Swap the first byte of a 4-byte string with a new value:
  <string> OP_1 OP_RIGHT → <last_3_bytes>
  <new_first_byte> SWAP OP_CAT → <new_first_byte || last_3_bytes>

Interaction and Completeness

OP_LEFT, OP_RIGHT, and OP_SUBSTR form a complete set of string slicing primitives:

Left prefix:  OP_LEFT(s, n)        = s[0..n]
Right suffix: OP_RIGHT(s, n)       = s[len(s)-n..len(s)]
Middle range: OP_SUBSTR(s, b, n)   = s[b..b+n]

Together with OP_CAT (concatenation) and OP_SIZE (length measurement),
these would form a complete string manipulation toolkit for Bitcoin Script.

The combination of all five opcodes (OP_CAT, OP_SUBSTR, OP_LEFT, OP_RIGHT, OP_SIZE) would enable:


- Data serialization/deserialization

- On-chain parsing of Bitcoin transaction components

- Merkle proof verification

- Covenant constructions that inspect spending transactions

- Cross-chain atomic swap verification without trusted oracles

Current Status and Alternatives

Both opcodes produce script_ERR_DISABLED_OPCODE when encountered. There are no current BIPs proposing their individual re-enablement — most discussions focus on OP_CAT first, treating it as the highest-value single opcode to restore.

Without these opcodes, Bitcoin Script developers must pre-compute all string slicing off-chain and pass pre-sliced values as witness data. This works but requires trusting that the off-chain computation was done correctly — something that script-level slicing would have allowed the script itself to verify.

Summary

OP_LEFT and OP_RIGHT are two sides of the same coin — simple, focused slice operations for the first and last N bytes of a stack item. Individually they seem minor, but in combination with OP_CAT and OP_SUBSTR, they complete a string manipulation system that would dramatically expand what Bitcoin Script can express and verify natively.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!