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
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
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
foobar foo IsSubStr
is equivalent to:
foobar foo bar Cat Equal
--
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+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/bitcoindev/678d40e3-3e22-4d55-82c0-b25ccafb87ecn%40googlegroups.com.
Hi Rijndael,
Thanks for your example
[witness: foobar foo] bar CAT EQ
Yes, the unfixed string can be checked against a target substring in your example. However, if the target substring is located in the middle of the unfixed string, how to check it? In other words, how to have the same function as “foobar ob ISSUBSTR” with CAT if “foobar” is unfixed?
For example, suppose that a lucky draw game has the rule: if anyone has a publicKey which includes a special substring "goodluck", he/she will be awarded.
This game can be easily implemented with OP_ISSUBSTR as follow.
- LockScript: OP_DUP goodluck OP_ISSUBSTR...
- UnlockScript: signature publicKey
How to implement it with OP_CAT?
Regards
Weichu deng
The solution of splitting the string and using OP_CAT only works if the exact position of the substring is known. How would a case be handled where the substring could be in any position
--
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+...@googlegroups.com.