* [bitcoindev] New Proposal:String Substring Search in Bitcoin Script - OP_ISSUBSTR
@ 2025-03-17 16:14 weichu deng
2025-03-17 16:54 ` Peter Todd
0 siblings, 1 reply; 2+ messages in thread
From: weichu deng @ 2025-03-17 16:14 UTC (permalink / raw)
To: Bitcoin Development Mailing List
[-- Attachment #1.1: Type: text/plain, Size: 4263 bytes --]
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.
[-- Attachment #1.2: Type: text/html, Size: 6308 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [bitcoindev] New Proposal:String Substring Search in Bitcoin Script - OP_ISSUBSTR
2025-03-17 16:14 [bitcoindev] New Proposal:String Substring Search in Bitcoin Script - OP_ISSUBSTR weichu deng
@ 2025-03-17 16:54 ` Peter Todd
0 siblings, 0 replies; 2+ messages in thread
From: Peter Todd @ 2025-03-17 16:54 UTC (permalink / raw)
To: weichu deng; +Cc: Bitcoin Development Mailing List
[-- Attachment #1: Type: text/plain, Size: 1405 bytes --]
On Mon, Mar 17, 2025 at 09:14:05AM -0700, weichu deng wrote:
>
>
> 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.
Bitcoin scripts are about validation. Not computation.
This means that substring search and concatenation are equivalent. For
every script that validates a substring search, you can instead
concatenate the substring with the rest of the string, and validate
equality instead.
Basically speaking:
foobar foo IsSubStr
is equivalent to:
foobar foo bar Cat Equal
A real-world example would be more complex. But I hope that illustrates
my point sufficiently.
--
https://petertodd.org 'peter'[:-1]@petertodd.org
--
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/Z9hTu2TjMlLr5-Eg%40petertodd.org.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-17 17:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-17 16:14 [bitcoindev] New Proposal:String Substring Search in Bitcoin Script - OP_ISSUBSTR weichu deng
2025-03-17 16:54 ` Peter Todd
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox