Dear fellow Bitcoin developers,

 

I am pleased to present a new BIP proposal. This proposal introduces a new opcode for Bitcoin scripts: OP_ISSUBSTR.


Abstract

This BIP introduces two string opcodes, OP_ISSUBSTR and OP_ISSUBSTRVERIFY (similar to the relationship between OP_EQUAL and OP_EQUALVERIFY), to determine whether one string is a substring of another. As these opcodes do not alter any blockchain state, they are secure.

 

Specification

These opcodes check if the second string on the stack is a substring of the first string. If the opcode is OP_ISSUBSTRVERIFY, it verifies the condition and throws an error if false, without retaining the result.

 

Execution Process

  1. Take the two strings at the top of the stack.
  2. Use standard library functions to compare the two strings.
  3. Pop the two strings from the stack and push the result onto the stack.
  4. If the opcode is OP_ISSUBSTRVERIFY, do not push the result.

Motivation

The absence of string operations in Bitcoin scripts restricts its applicability. When developers need string operations for applications, they must simulate these functions through off-chain preprocessing or complex scripts, increasing development difficulty and potentially introducing centralized dependencies.

 

Early Bitcoin versions supported some string operations, such as OP_SUBSTR, which extracted a substring of specified position and length from a string, replacing the original string. For security reasons, OP_SUBSTR was disabled in Bitcoin v0.3.10 and later versions due to a vulnerability (CVE-2010-5137) caused by OP_LSHIFT. To prevent similar overflow vulnerabilities, Bitcoin disabled several opcodes, including OP_SUBSTR. As Bitcoin adoption grows, the limitations of lacking string operations have become more evident. Our proposed OP_ISSUBSTR adds string search functionality to Bitcoin scripts without changing any state, making it safe.

 

Advantages

  1. Enhanced Script Functionality and Flexibility Developers can process string logic on-chain without off-chain reliance. For example, in multi-signature wallets, developers can verify specific signer information or remarks directly in scripts using OP_ISSUBSTR to check transaction comments or signature fields for particular substrings.
  2. Support for String Searching In some scenarios, developers need to verify if parts of a string match a format or contain specific data. For example, checking if a payment transaction's payee name matches a preset value.
  3. Conversion of Non-deterministic Algorithms to Deterministic Ones Some signature algorithms or hash functions produce non-deterministic outputs. OP_ISSUBSTR allows developers to check if these outputs contain known substrings in scripts, converting non-deterministic results to deterministic ones. For example, verifying if a hash value contains a specific hexadecimal sequence (like "0000") to trigger contract logic.
  4. Simplified Address Verification Logic Bitcoin addresses typically start with specific prefixes or suffixes. OP_ISSUBSTR enables direct address format verification in scripts. For example, checking if a transaction target address starts with "bc1" to ensure validity or detect "address pollution" attacks.
  5. Integration with Modern Programming Languages Modern languages widely support string operations. OP_ISSUBSTR makes Bitcoin scripts more aligned with these languages, lowering the barrier for developers.

 

We have provided detailed documentation and a reference implementation in the BIP draft. You can read the full proposal here: https://github.com/Weichu-Deng/bips/blob/OP_ISSUBSTR/bip-yongdong%20wu-OP_ISSUBSTR.md


Thank you for your feedback! 

With respect,

Weichu Deng

 weichudeng@stu2024.jnu.edu.cn

 

--
You received this message because you are subscribed to the Google Groups "Bitcoin Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bitcoindev+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/bitcoindev/f844a85e-8be8-4429-8687-bc19dd4b96ffn%40googlegroups.com.