public inbox for bitcoindev@googlegroups.com
 help / color / mirror / Atom feed
From: symphonicbtc <symphonicbtc@proton•me>
To: Tobin Harding <me@tobin•cc>,
	"bitcoin-dev@lists•linuxfoundation.org"
	<bitcoin-dev@lists•linuxfoundation.org>
Subject: Re: [bitcoin-dev] segwit naming ambiguity
Date: Fri, 11 Aug 2023 07:38:13 +0000	[thread overview]
Message-ID: <XuIlG8ZnGSikbG0DQ34BAQE_k7bTBoO_YgeAVuynutat-0pQuSF0GfdpvUApGH94g66zXtkgEguy0NnxxnGuBzm-7PA1U40cIa9UsEI8_Yg=@proton.me> (raw)
In-Reply-To: <ZNW9BenWIhgX95zl@alke>

Transactions should be considered segwit if they match the witness program structure of "A scriptPubKey (or redeemScript as defined in BIP16/P2SH) that consists of a 1-byte push opcode (for 0 to 16) followed by a data push between 2 and 40 bytes" as defined in [BIP141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#witness-program). This would return true for version 0 segwit outputs as well as version 1 taproot outputs.

I would propose a different function for differentiating v0 vs taproot scripts. Bitcoin core uses an [enum](https://github.com/bitcoin/bitcoin/blob/master/src/script/standard.h#L51), of which you can use something similar. Core also uses a different [enum](https://github.com/bitcoin/bitcoin/blob/master/src/outputtype.h) for wallet logic, but it has a highly confusing naming scheme which imo should be avoided.

Additionally, witness programs nested inside P2SH need to be considered. The context in which these are interpreted depends on whether or not they should be differentiated from other P2SH, as is shown with the 2 separate enums from core. It is possible that this would cause some ambiguity, and it should be explicitly documented how such functions would return for different types of programs. These nested programs should technically also be considered segwit for a simple `is_segwit`, as they have segregated witness data.

v0 is the most common way of referring to version 0 segwit.

Symphonic


------- Original Message -------
On Friday, August 11th, 2023 at 4:45 AM, Tobin Harding via bitcoin-dev bitcoin-dev@lists•linuxfoundation.org wrote:

> Question for OG bitcoin API designers please.
>
> If you were to see the following function
>
> `is_segwit()`
>
> would you assume it returns `true` or `false` for a p2tr transaction?
>
> Currently we (rust-bitcoin) are being liberal with the use of `v0` but
> its a pretty ugly. Is there an official, or widely used, name for segwit v0?
>
> Thanks,
> Tobin.
> _______________________________________________
> bitcoin-dev mailing list
> bitcoin-dev@lists•linuxfoundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev


  reply	other threads:[~2023-08-11  7:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-11  4:45 Tobin Harding
2023-08-11  7:38 ` symphonicbtc [this message]
2023-08-11  7:49 ` Antoine Poinsot
2023-08-11 10:06 ` Pavol Rusnak
2023-08-11 13:45 ` Andrew Poelstra

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='XuIlG8ZnGSikbG0DQ34BAQE_k7bTBoO_YgeAVuynutat-0pQuSF0GfdpvUApGH94g66zXtkgEguy0NnxxnGuBzm-7PA1U40cIa9UsEI8_Yg=@proton.me' \
    --to=symphonicbtc@proton$(echo .)me \
    --cc=bitcoin-dev@lists$(echo .)linuxfoundation.org \
    --cc=me@tobin$(echo .)cc \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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