Delivery-date: Tue, 01 Apr 2025 15:38:38 -0700 Received: from mail-oo1-f55.google.com ([209.85.161.55]) by mail.fairlystable.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tzkFh-0000nH-5D for bitcoindev@gnusha.org; Tue, 01 Apr 2025 15:38:38 -0700 Received: by mail-oo1-f55.google.com with SMTP id 006d021491bc7-603fd09171bsf321327eaf.1 for ; Tue, 01 Apr 2025 15:38:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1743547111; cv=pass; d=google.com; s=arc-20240605; b=ifLSYKyV+ZmQl/VTBFaFhkktYXDcL/VcMTQ8Thm5+MHAxx3tmk1lMZpDY+Tu6/cTgm TDL3frG7NYzDgM9/tl5kolxwKsA0UArv7QHVR0sVlFC4Rl/u5/VvXc3e5VYNANH8k1s+ PzoaB+OV9dJ/Tm7l7sNMQzAjl8od10n2A9XqYXChfT+8ALrdKap1fFwFUGDvFgWHwiJM mEJHp1Jk+/owYbRF71YY0wCFQbqBuEDucHk/Bh6nQ+2W9qXcqG6VqF8L3nLH8fHLedIx Cuij8TVHQQQskLDE1kDw6PiQyy7j16NC+MGmPQcZOD+XDovc0yasUrK8aneb+8yhMtrf uQpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:sender:dkim-signature :dkim-signature; bh=PFjfduBnjzsQkzi2DI5PY5AK3iMzVsUFQwg9ojp2GPA=; fh=WmXfssJedKHy9Vzrl/7g1B6T6W4WapF59YdUBaRh61k=; b=OH/yCEprhVOCD3SNFTWlYahUWbjJnAwqiTXEyz/QCBLl0xlfyQ4ByQJw83YJooSN7r oxNOClVaOeFy8bNAnOXd388CS/y945RN7BAnbmw4ppuqGyP4Nmes7kyBW94jl8U+lcyM +OzWoKIqB/4VmfQ6WJ+IvgA6aRAeC85ziJpC5P/iXUtH8tO3vtUjsUngBiXGaG7vBPoB nig3EHyvuVwawZLPLG84WA9kf4nePjWMTYAJRorkV9SZTeUbS4FKG/Y5RZnP0jfr+QMd GBB27ea3LMOJMJpvP/u5RXXOw7DrTcOV2Xx/psZgFsMYL8CRYJO/aUg9zjTULfPeobSu hNhQ==; darn=gnusha.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="fl5PD/ud"; spf=pass (google.com: domain of martin.habovstiak@gmail.com designates 2607:f8b0:4864:20::736 as permitted sender) smtp.mailfrom=martin.habovstiak@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=pass header.i=@googlegroups.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1743547111; x=1744151911; darn=gnusha.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:sender:from:to:cc:subject:date:message-id :reply-to; bh=PFjfduBnjzsQkzi2DI5PY5AK3iMzVsUFQwg9ojp2GPA=; b=f74r+UbNfw/kaXInHHKkM70b7mIEsBNbf0iIXRqM/RzrLgivstGCgbEIsgvIL33M2d 9m3Hb0jiKwTDCQzAHzRloKtdxMvLBgKN8TRERq0NcMmX7abOxxmvTL6komNiXgkFCoGN 6vVDU92MQNbiX81niYaj9I+AIl1U2XF2VXpNyPmxjAurxHH4qqa4GpYOC1hqVeMUCjzd td9p2I1I1R8rTz77dFdFmqU222SMEcsdaVExFexre8JS8EO4FBjZ1UpxOlvwUtB1kf7K CekZo0CxrYJawB8AulOv/OD4wOJaNsXuC3mvee8DCZWxqXDGXjYx+eaJ9zFolaSYTEmg KIGg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743547111; x=1744151911; darn=gnusha.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:from:to:cc:subject:date:message-id:reply-to; bh=PFjfduBnjzsQkzi2DI5PY5AK3iMzVsUFQwg9ojp2GPA=; b=h69kNIBP914h3Q/a4rs3KzbNiHGDCG4ryS5FOWVXRijBEjuAtug0H/ic1z+Jy72h2n 4nMZsiAIlq6DFVqa4ABQU3tIjkxrvjEquapbvRWZYT08rnzrcxeQx0SBwCDhdXqBIxhE 4qkYcz5Ji/GqpECfTk+8oBv22OdeeKTb17Vo1IGWAYkgcUPaEdq3ZTcjQKoGPqGVdnp7 qlTpfy50UEJ3TgaoRfOFjgbs9ZrN//ORTDIgYulOMiHP0HQ9QfJ9V3yJIJI33NS/PVRF hnx2Me6iZBBTNYSDGDkPZ9Vp1UPQPuyfI165Dypug3/msoe3WKQPG7aQRFNBZTzmm/iP c3dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743547111; x=1744151911; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:x-beenthere:x-gm-message-state:sender:from :to:cc:subject:date:message-id:reply-to; bh=PFjfduBnjzsQkzi2DI5PY5AK3iMzVsUFQwg9ojp2GPA=; b=oErK5kz6rCA26hRaYdH9/bSnEqPPlTDNAjd8X8b2pnOt3uYkvYjh7r/jT+aAr0pwjP CYPk6O1DSdRL1ecz5/JqFqQWo7Giyj91Yu0UVNPXJtcGTVBMk6XtoBtZYmwAd6nr49dM dXxvcUqJQp8W4iqVi4JlsimiyerJuAlLnoYTs8yJE5kA6Zh7BsKxRdAFY07N9oFpHrku 5nZTSpnT9rIOv8X25wkE4fSWCvjHuLHrdU2GXOIOhQWcK6ZchlZtT9APqhWX4iz8PiQA VqjqvmuFZzqq3dobS1mwrhzg2FfRYCUJQYdFgkib2XnTiA2lXAWWcZIaJ/pC78nA+IFA lFvw== Sender: bitcoindev@googlegroups.com X-Forwarded-Encrypted: i=2; AJvYcCWqrTP+XKcBgWnuAJH5Zw2azyLXk/QZOZOF1XrBhUjAHnMq0UmgkpolSnqT+lt4rkCXfytJNyoJxEJL@gnusha.org X-Gm-Message-State: AOJu0YyZekHJirUbadFCHYMHHacNgDtybI9hsNunsWZUQvyvTXqeQ2F2 9dU4kOuWFi4haOBVIK+VDMo7nM6YDA9IHxajSdWOJ0CUJuq7VrS6 X-Google-Smtp-Source: AGHT+IHYNI0EWh0lIAoM8JXTvRLg30APZrwgr8eDQT2Umej4wgik6dAGeUkssN39h8tk1451iORgyA== X-Received: by 2002:a05:6820:2107:b0:603:f777:9801 with SMTP id 006d021491bc7-603f7779c95mr2088125eaf.3.1743547111003; Tue, 01 Apr 2025 15:38:31 -0700 (PDT) X-BeenThere: bitcoindev@googlegroups.com; h=ARLLPALZ66IIHkeinGsjmtfFzN9sYIB1V1+5ulGR8BYyeJrZ9A== Received: by 2002:a4a:a641:0:b0:603:be8f:a31e with SMTP id 006d021491bc7-603be8fa5c8ls667467eaf.1.-pod-prod-08-us; Tue, 01 Apr 2025 15:38:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUKl9pHxZZYLZmu8hCKaayyYPITelChzTXj/IT4vUpA86/P2ARJXO6a+Az4BFnmUXxvmPWQRRS0J0ar@googlegroups.com X-Received: by 2002:a05:6808:2019:b0:3fe:ab15:5e93 with SMTP id 5614622812f47-3ff0f524c93mr9182358b6e.11.1743547107585; Tue, 01 Apr 2025 15:38:27 -0700 (PDT) Received: by 2002:a05:6808:985:b0:3fa:6f09:b173 with SMTP id 5614622812f47-3feefbac77emsb6e; Tue, 1 Apr 2025 08:36:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXjxoCibe7zW6VnL+ja4KgqTpbKCw7G82en5Ygdx8E5kwIoBoLaRiIxza+sidqGt52GML5u8AowSfh9@googlegroups.com X-Received: by 2002:a17:90b:2e07:b0:2ee:53b3:3f1c with SMTP id 98e67ed59e1d1-30531f7c07cmr19794566a91.5.1743521764783; Tue, 01 Apr 2025 08:36:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1743521764; cv=none; d=google.com; s=arc-20240605; b=NITLkxzZva/ZZNMPhpL7chQEXMhHFxc5gZJB2yS2KAFrq+5ALcsyO0CZs+5W3p+nb1 EnT0p8zV/Wwg6C8BEhcQa/9aQ3uZjQ4EM3xY10LnKqkd/ZcHVKyh3m46xL77Ty5fzrFy qMn6j/aQhK07E2nRfyxnsb9vyOC4akia/x/On4SPssEodjeN04uJ3g0d/6GRfbxUNS4A nJ6JnIQLz3M6ticGF/zlWqrP9MJrtLF4HHQypD9AQccK33snIZaje0daSW52JowFuHyS rcQsF9vb0jxWiONr95V5Wt2YD3v4npiQJimEoCGN83maoGb0CMm+3lQEk76H5QEY/sXo Z60w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=r2K2TgMkVJjTLkR4tG9GmvR/WYaTX9V++QzBCL7n0PM=; fh=UslS9DHPkWd0noc2pTWy5Ft6VFWJ5hH0DY6AiDFuLK8=; b=gQAflzQw50Gv1svmOUE3AAt6oWuXRwbcsmGYXQb/BEhKFHsZ+nkN8CdutqOvY7rwzg Qkr3QUR7ec59oPkV65WCXXleNWIbhec1RGvzYDAgTVYy5k44qWg3cKP7oYbsynJoZbHT eDLCzZydry0koPOc9tHSBt2Vh6/pB2Oe6YMXiiwfHoIw0jOHoVbfATHtv+H9OoLONUPC 1YprVF/dJzEIz7RSFUi05UsGlrrBQfojD6k0rQPWDfouE4AKFN0QlNGWO9r72YjAakBo k3nuXznLRe4rg9OBz3Y3gOa1YdHN9ZMUf7P0/s8XjI1LJJK5pJZlRY9jvFuaqMKu8IUV bF9Q==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="fl5PD/ud"; spf=pass (google.com: domain of martin.habovstiak@gmail.com designates 2607:f8b0:4864:20::736 as permitted sender) smtp.mailfrom=martin.habovstiak@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=pass header.i=@googlegroups.com Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com. [2607:f8b0:4864:20::736]) by gmr-mx.google.com with ESMTPS id d9443c01a7336-2291eed881fsi5283895ad.1.2025.04.01.08.36.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Apr 2025 08:36:04 -0700 (PDT) Received-SPF: pass (google.com: domain of martin.habovstiak@gmail.com designates 2607:f8b0:4864:20::736 as permitted sender) client-ip=2607:f8b0:4864:20::736; Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-7c559b3eb0bso328406785a.1 for ; Tue, 01 Apr 2025 08:36:04 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCX+QOTXsEHXmJerV8H+y4MBW28nlYkf1GjsBKNx3+ld0sRQX5g/vNnGWELurtxNY+6XIwHqOnykQZ7+@googlegroups.com X-Gm-Gg: ASbGncsWq/6CPiIRIdS0+BrKDal09fQIiShz+NaHw0YUSZ+d+Nz+MQlwxUYaD3HWz2B pPIeeeuA9qlbUWOBih0smV4K+jGlwRQMJB6FwyxOVovh8IovT/wY0ghrWcKsxAteQB2Xs1QNMjA Tao1vyR0SWUY1zd+vddJ3t9PMhiQ== X-Received: by 2002:a05:620a:4544:b0:7c0:9f12:2b7e with SMTP id af79cd13be357-7c6862ebcdemr1758761285a.11.1743521764058; Tue, 01 Apr 2025 08:36:04 -0700 (PDT) MIME-Version: 1.0 References: <678d40e3-3e22-4d55-82c0-b25ccafb87ecn@googlegroups.com> <8c823e50-197e-479c-8651-9e0407a4168en@googlegroups.com> In-Reply-To: From: =?UTF-8?Q?Martin_Habov=C5=A1tiak?= Date: Tue, 1 Apr 2025 17:35:53 +0200 X-Gm-Features: AQ5f1Jonb64K8xwBCp_kuJq8yZNRre_fWTfTsBymB-tWsSBmqhpWzVEB--Uz7xU Message-ID: Subject: =?UTF-8?Q?Re=3A_=5Bbitcoindev=5D_New_Proposal=EF=BC=9AString_Substring_Sea?= =?UTF-8?Q?rch_in_Bitcoin_Script_=2D_OP=5FISSUBSTR?= To: Pieter Wuille Cc: Javier Mateos , Bitcoin Development Mailing List Content-Type: multipart/alternative; boundary="00000000000067ab4a0631b94b28" X-Original-Sender: martin.habovstiak@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="fl5PD/ud"; spf=pass (google.com: domain of martin.habovstiak@gmail.com designates 2607:f8b0:4864:20::736 as permitted sender) smtp.mailfrom=martin.habovstiak@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=pass header.i=@googlegroups.com Precedence: list Mailing-list: list bitcoindev@googlegroups.com; contact bitcoindev+owners@googlegroups.com List-ID: X-Google-Group-Id: 786775582512 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , X-Spam-Score: -0.5 (/) --00000000000067ab4a0631b94b28 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, I was dismissing the proposal for the same reason you do but it just occurred to me that substrings might be better than OP_CAT because it's possible to make them unabusable without any arbitrary limit on item size. The idea is to store stack elements on the heap inside struct { ref_count, length, data[] } and put struct { pointer_to_item, position, length } on the stack. (Rust developers may be familiar with the `bytes` crate that does this.) Substring operations would only duplicate the pointers with adjusted position and length so there's no way to blow up the stack using them. Of course there's an exception if OP_SHA256 is used on a shorter slice but the same is true today - you can already write OP_ZERO OP_SHA256 OP_DUP OP_DUP... Funnily, this can be used to optimize OP_DUP as well which would now add constant amount of memory, so the "exploit" above would need to use two bytes per every large object. Anyway, while I would personally prefer not having arbitrary limits on item sizes, since the limit is already there, it might not matter. I guess something worth considering if any other future soft fork somehow enables larger items. Have a nice day! Martin D=C5=88a ut 1. 4. 2025, 16:49 Pieter Wuille nap=C3= =ADsal(a): > On Monday, March 31st, 2025 at 4:41 PM, Javier Mateos < > javierpmateos@gmail.com> wrote: > > 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 whe= re > the substring could be in any position > > > Whoever produces the signature/witness for spending the coin always knows > the position already, so the script can always be modified to instead tak= e > that position as an additional input. > > This is a general principle: the point of scripts is verifying provided > information, not computing it. As another example, this means that there = is > no need for a division or square root opcode if one has a multiplication > opcode. > > -- > Pieter > > -- > 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/frERrHlzWhpskJw74fBQorSrXEaB= P1d4XBUgM-Nkww_2ulhc7i2Lqmu2kcAlvh5fd7LzYiBmX5HNBtg7Ownbsa0KZ26ihfJjri6R01k= uozA%3D%40wuille.net > > . > > --=20 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 e= mail to bitcoindev+unsubscribe@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/bitcoindev/= CALkkCJb1RdC646q1QrOP%2ByQut7EG4NLJNm3cyxW4S1%3DEx1NBmQ%40mail.gmail.com. --00000000000067ab4a0631b94b28 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

I was di= smissing the proposal for the same reason you do but it just occurred to me= that substrings might be better than OP_CAT because it's possible to m= ake them unabusable without any arbitrary limit on item size.

The idea is to store stack elements o= n the heap inside struct { ref_count, length, data[] } and put struct { poi= nter_to_item, position, length } on the stack. (Rust developers may be fami= liar with the `bytes` crate that does this.)
Substri= ng operations would only duplicate the pointers with adjusted position and = length so there's no way to blow up the stack using them.

Of course there's an exception if= OP_SHA256 is used on a shorter slice but the same is true today - you can = already write OP_ZERO OP_SHA256 OP_DUP OP_DUP...
Funnily, this can be used to optimize OP_DUP as we= ll which would now add constant amount of memory, so the "exploit"= ; above would need to use two bytes per every large object.

Anyway, while I would personally pref= er not having arbitrary limits on item sizes, since the limit is already th= ere, it might not matter. I guess something worth considering if any other = future soft fork somehow enables larger items.

<= /div>
Have a nice day!

Martin


D=C5=88a ut 1.= 4. 2025, 16:49 Pieter Wuille <bitcoin-dev@wuille.net> nap=C3=ADsal(a):
On Monday, March 31st, 2025 at 4:41 PM, Javier Mateos <ja= vierpmateos@gmail.com> wrote:
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
=

Whoever produces the signature/witness for spending the coin always knows the=20 position already, so the script can always be modified to instead take=20 that position as an additional input.

This is a general principle: the point of scripts is verifying provided=20 information, not computing it. As another example, this means that there is no need for a division or square root opcode if one has a=20 multiplication opcode.

--
Pieter

--
You received this message because you are subscribed to the Google Groups &= quot;Bitcoin Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to bitcoindev+unsubscribe@googlegroups.com.=
To view this discussion visit https://g= roups.google.com/d/msgid/bitcoindev/frERrHlzWhpskJw74fBQorSrXEaBP1d4XBUgM-N= kww_2ulhc7i2Lqmu2kcAlvh5fd7LzYiBmX5HNBtg7Ownbsa0KZ26ihfJjri6R01kuozA%3D%40w= uille.net.

--
You received this message because you are subscribed to the Google Groups &= quot;Bitcoin Development Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to bitcoind= ev+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/= d/msgid/bitcoindev/CALkkCJb1RdC646q1QrOP%2ByQut7EG4NLJNm3cyxW4S1%3DEx1NBmQ%= 40mail.gmail.com.
--00000000000067ab4a0631b94b28--