public inbox for bitcoindev@googlegroups.com
 help / color / mirror / Atom feed
From: "'conduition' via Bitcoin Development Mailing List" <bitcoindev@googlegroups.com>
To: Anthony Towns <aj@erisian.com.au>
Cc: Bitcoin Development Mailing List <bitcoindev@googlegroups.com>
Subject: Re: [bitcoindev] OP_CAT Enables Winternitz Signatures
Date: Tue, 08 Jul 2025 00:16:33 +0000	[thread overview]
Message-ID: <h9N4uIp0MgaASuEBpqsHjiQb9ahGbca3mG5V6iPVumT9ICT4monwV1ScgV3kdV2ka9CkQiSqEGkxA_eqqGQJ1TtFmWUlJEhi0McZU6yGBl0=@proton.me> (raw)
In-Reply-To: <aGkYLuZZz2itqVJx@erisian.com.au>


[-- Attachment #1.1: Type: text/plain, Size: 3147 bytes --]

Great idea AJ, I didn't think about OP_DUP OP_ADD as a
stand-in for OP_LSHIFT. That saves a bunch of bytes. We can
save even more by using `OP_SIZE` to check if the combined
number is greater than 127, since the interpreter's OP_ADD
`output` should always be canonically represented as a
2-byte value if `128 <= output <= 255` (correct?).

This lets us elide the SWAP/ROT operations, dropping it to
35 bytes per of script per iteration of that loop (down
from 58 in my first impl!). Total savings across all loops
is 736 bytes, bringing the total script+witness size down
to about 7212 bytes, or 1803 vbytes. Very groovy!

// ... <b63> <b64>
SWAP DUP ADD DUP ADD DUP ADD DUP ADD ADD
SIZE <2> EQUAL IF
  <128> SWAP SUB
  IFDUP NOT IF <0x80> ENDIF
ELSE
  DUP NOT IF <0x00> ENDIF
ENDIF

I revised the gist with the updated bitshift code, and more
detailed comments. Thank you!

https://gist.github.com/conduition/c6fd78e90c21f669fad7e3b5fe113182#file-winternitz-ts-L100-L137

regards,
conduition



On Saturday, July 5th, 2025 at 6:54 AM, Anthony Towns <aj@erisian.com.au> wrote:

> On Sun, Jun 08, 2025 at 03:20:08AM +0000, 'conduition' via Bitcoin Development Mailing List wrote:
> 

> > See a prototype implementation in pseudo-script on
> > github here.
> > 

> > https://gist.github.com/conduition/c6fd78e90c21f669fad7e3b5fe113182
> 

> 

> I think you can do the four-bit pair to eight-bit conversion slightly
> better with:
> 

> DUP 8 GREATERTHANOREQUAL # is the high-bit going to be set?
> SWAP ROT SWAP # drop that flag lower in the stack
> DUP ADD DUP ADD DUP ADD DUP ADD ADD # combine them mathematically
> SWAP IF # was the flag set?
> 128 SWAP SUB # subtract from 128 converts 0x8100-0xff00 to 0x81-0xff
> IFDUP NOT IF "0x80" ENDIF # special case 0x80 "negative zero"
> ELSE
> IFDUP NOT IF "0x00" ENDIF # special case actual 0
> ENDIF
> 

> Should save about 640 bytes of script (11%, 8% total), I think.
> 

> > PS If anyone would like to test this on signet, I'd
> > be more than happy to help. I couldn't get my OP_CAT
> > transactions mined for some reason so i stuck to regtest.
> 

> 

> inquisition.bitcoin-signet.net was down for a few days when you posted
> this, due to running out of disk space, which probably would have made
> getting txs relayed pretty hard. You'd probably have more luck now.
> 

> Cheers,
> aj
> 

> --
> 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/aGkYLuZZz2itqVJx%40erisian.com.au.

-- 
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/h9N4uIp0MgaASuEBpqsHjiQb9ahGbca3mG5V6iPVumT9ICT4monwV1ScgV3kdV2ka9CkQiSqEGkxA_eqqGQJ1TtFmWUlJEhi0McZU6yGBl0%3D%40proton.me.

[-- Attachment #1.2: publickey - conduition@proton.me - 0x474891AD.asc --]
[-- Type: application/pgp-keys, Size: 649 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 343 bytes --]

      reply	other threads:[~2025-07-08  1:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-08  3:20 [bitcoindev] OP_CAT Enables Winternitz Signatures 'conduition' via Bitcoin Development Mailing List
     [not found] ` <QcOCx8vBMDuw4xf05H5SbIOPee2MZqV5IQa2opvAXcMeMzzFooHYL97qy5ZCLUEjqXHlHoyAucpmkwwU2i3bhO95SJrWP-oRU6mqamnTvRc=@pm.me>
2025-06-09 15:31   ` 'conduition' via Bitcoin Development Mailing List
2025-07-07 10:40     ` Jonas Nick
2025-07-08  0:49       ` 'conduition' via Bitcoin Development Mailing List
2025-07-05 12:18 ` Anthony Towns
2025-07-08  0:16   ` 'conduition' via Bitcoin Development Mailing List [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='h9N4uIp0MgaASuEBpqsHjiQb9ahGbca3mG5V6iPVumT9ICT4monwV1ScgV3kdV2ka9CkQiSqEGkxA_eqqGQJ1TtFmWUlJEhi0McZU6yGBl0=@proton.me' \
    --to=bitcoindev@googlegroups.com \
    --cc=aj@erisian.com.au \
    --cc=conduition@proton.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox