Subject: Re: [bitcoindev] New Proposal：String Substring Search in Bitcoin Script - OP_ISSUBSTR

From: weichu deng <[email-masked]>
Date: Wed, 19 Mar 2025 02:07:56 -0700 (PDT)

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

[email-masked]

在2025年3月19日星期三 UTC+8 10:28:25<Rijndael> 写道：

> Stack elements in Taproot are limited to 520 bytes. The current proposal 
> for re-activating OP_CAT includes this restriction: creating a string 
> longer than 520 bytes with CAT will cause the script to fail.
>
> With either CAT or ISSUBSTR, you can either commit to the substrings or 
> provide them at spend-time as witness data (and allow them to be unfixed in 
> the script).
>
> Fixed: FOOBAR BAR ISSUBSTR == FOOBAR FOO BAR CAT EQ
> Variable: [witness: FOOBAR] BAR ISSUBSTR == [witness: FOOBAR FOO] BAR CAT 
> EQ
>
>
> rijndael 
>
>
> On Mar 18, 2025, at 11:32 AM, weichu deng <[email-masked]> 
> wrote:
>
> Hi, Peter Todd
> Thanks for your feedback. I agree that "Bitcoin scripts are about 
> validation. Not computation."
> String search and concatenation are equivalent in some cases, such as in 
> the example you provided.
> However, it is still necessary to introduce the OP_ISSUBSTR operation 
> separately.
> One example is converting a non-deterministic signature to a deterministic 
> one.
> Another case is when the substring in question is located in the middle of 
> the checked string.
> CAT cannot replace ISSUBSTR for the following reasons:
>
>    1. The security of CAT is still controversial. It can easily generate 
>    overly long strings, potentially causing a stack overflow. Additionally, 
>    whether OP_CAT will be restored is still under discussion.
>    2. The other substring (bar) must be known in advance.
>    
>
> With respect,
>
> Weichu Deng
>
> [email-masked]
> 在2025年3月18日星期二 UTC+8 01:01:16<Peter Todd> 写道：
>
> 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 [email-masked].
> To view this discussion visit 
> https://groups.google.com/d/msgid/bitcoindev/678d40e3-3e22-4d55-82c0-b25ccafb87ecn%40googlegroups.com 
> <https://groups.google.com/d/msgid/bitcoindev/678d40e3-3e22-4d55-82c0-b25ccafb87ecn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
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 [email-masked].
To view this discussion visit https://groups.google.com/d/msgid/bitcoindev/8c823e50-197e-479c-8651-9e0407a4168en%40googlegroups.com.