Skip to content

Conversation

@qlrd
Copy link

@qlrd qlrd commented Jul 15, 2025

Add a check for p2sh-p2wsh, p2sh-p2wpkh and raise an exception for
unknow types.

With this fix i was able to do a proper recognition of nested segwit multisig wallet when using this method to load a descriptor.

@qlrd qlrd changed the base branch from master to develop July 16, 2025 00:16
@qlrd qlrd force-pushed the fix-scriptpubkey-type-for-nested-segwit branch from 7c36b98 to b10ec83 Compare July 16, 2025 21:56
@qlrd qlrd changed the title fix: differentiate legacy and segwit types for p2sh fix: differentiate legacy and segwit types for p2sh when using Descriptor::scriptpubkey_type Jul 20, 2025
@qlrd qlrd force-pushed the fix-scriptpubkey-type-for-nested-segwit branch from b10ec83 to 8b3b079 Compare July 21, 2025 22:06
@qlrd qlrd requested a review from odudex July 21, 2025 22:08
@odudex
Copy link
Collaborator

odudex commented Jul 22, 2025

The commit from this pull request has now been merged into Embit's develop branch.
Edit: The change was reverted and removed from develop until the below issues are solved.

@jdlcdl
Copy link

jdlcdl commented Jul 22, 2025

Note: To include this in release-notes since this alters api/expected-return where existing projects may be expecting "p2sh"

@odudex
Copy link
Collaborator

odudex commented Jul 22, 2025

Another issue:
In order to use owns() method from descriptor.py and correctly detect change and self transfers in nested types, script_type() from script.py must be updated accordingly to cover detailed p2sh: p2sh-p2wpkh and p2sh-p2wsh

Edit: I believe script_type() can't retrieve more information than it does now. So another approach should be used

@tadeubas
Copy link
Member

How Specter DIY and SS does that if it is not implemented?

@qlrd
Copy link
Author

qlrd commented Jul 22, 2025

In order to use owns() method from descriptor.py and correctly detect change and self transfers in nested types, script_type() from script.py must be updated accordingly to cover detailed p2sh: p2sh-p2wpkh and p2sh-p2wsh

I think that something like this could be used in owns (but didn't tested):

- if psbt_scope.script_pubkey.script_type() != self.scriptpubkey_type():
+ if psbt_scope.script_pubkey.script_type() not in self.scriptpubkey_type():

I believe script_type() can't retrieve more information than it does now. So another approach should be used

yup, but during the sign procedure we can check, as a lib, if there's redeem_script and redeem_script.script_type() to assert p2sh, p2sh-p2wpkh, p2sh-p2wsh (i effectively did that).

How Specter DIY and SS does that if it is not implemented?

It's better to ask @kdmukai and @k9ert.

@odudex
Copy link
Collaborator

odudex commented Jul 23, 2025

I think that something like this could be used in owns (but didn't tested):

- if psbt_scope.script_pubkey.script_type() != self.scriptpubkey_type():
+ if psbt_scope.script_pubkey.script_type() not in self.scriptpubkey_type():

It seems to be a good idea!

yup, but during the sign procedure we can check, as a lib, if there's redeem_script and redeem_script.script_type() to assert p2sh, p2sh-p2wpkh, p2sh-p2wsh (i effectively did that).

With the above idea it might not be necessary.

@qlrd qlrd force-pushed the fix-scriptpubkey-type-for-nested-segwit branch 2 times, most recently from dc53d59 to 99e8046 Compare July 26, 2025 14:41
@qlrd
Copy link
Author

qlrd commented Jul 26, 2025

I think that something like this could be used in owns (but didn't tested):

- if psbt_scope.script_pubkey.script_type() != self.scriptpubkey_type():
+ if psbt_scope.script_pubkey.script_type() not in self.scriptpubkey_type():

It seems to be a good idea!

Changed. Also some test cases for singlesig and nested contexts (need to think in more cases and add some taproot cases).

@qlrd qlrd force-pushed the fix-scriptpubkey-type-for-nested-segwit branch 2 times, most recently from 48c6ecb to 979ce96 Compare July 26, 2025 22:06
@qlrd qlrd requested a review from odudex July 26, 2025 22:07
@qlrd qlrd force-pushed the fix-scriptpubkey-type-for-nested-segwit branch 2 times, most recently from c0c2469 to ef2dbcd Compare July 27, 2025 14:26
@qlrd
Copy link
Author

qlrd commented Jul 27, 2025

I think that something like this could be used in owns (but didn't tested):

- if psbt_scope.script_pubkey.script_type() != self.scriptpubkey_type():
+ if psbt_scope.script_pubkey.script_type() not in self.scriptpubkey_type():

It seems to be a good idea!

yup, but during the sign procedure we can check, as a lib, if there's redeem_script and redeem_script.script_type() to assert p2sh, p2sh-p2wpkh, p2sh-p2wsh (i effectively did that).

With the above idea it might not be necessary.

Also started with some signet PSBTs for testing Descriptor.owns

@qlrd qlrd force-pushed the fix-scriptpubkey-type-for-nested-segwit branch 3 times, most recently from a14f884 to b85d92f Compare July 28, 2025 00:55
qlrd and others added 3 commits August 4, 2025 12:46
Add a check for `p2sh-p2wsh`, `p2sh-p2wpkh` as well reorginize existing
scriptypes for `scriptpubkey_type`. Also add a bool type cast for
situations where some non-bool values could be returned in `is_wrapped`
and `is_segwit` property methods.

fix diybitcoinhardware#93

Co-authored-by: edilmedeiros <jose.edil@gmail.com>
Co-authored-by: moisespompilio
<93723302+moisesPompilio@users.noreply.github.com>
Add some singlesig test cases (common in descriptors like sparrow,
electrum, nunchuck...) calling for `Descriptor.scriptpubkey_type` and
add this last method in the multisig test cases, comparing if they
return, correctly, the p2sh, p2pkh, p2sh-p2wpkh, p2sh-p2wsh, p2wsh and
p2tr types. Also add tests for `Descriptor.owns` method for p2sh,
p2sh-p2wpkh, p2sh-p2wsh and p2wsh unsigned and signed PSBTs.
@qlrd qlrd force-pushed the fix-scriptpubkey-type-for-nested-segwit branch from b85d92f to 8115e45 Compare August 4, 2025 15:48
@odudex
Copy link
Collaborator

odudex commented Nov 4, 2025

These changes are not required anymore, am I right @qlrd ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scriptpubkey_type return p2sh when using p2sh-p2wsh

4 participants