Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui, psbt: Use SIGHASH_DEFAULT when signing PSBTs #850

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

achow101
Copy link
Member

@achow101 achow101 commented Jan 6, 2025

SIGHASH_DEFAULT should be used to indicate SIGHASH_DEFAULT for taproot inputs, and SIGHASH_ALL for all other input types. This avoids adding an unnecessary byte to the end of all Taproot signatures added to PSBTs signed in the GUI.

See also bitcoin/bitcoin#22514

SIGHASH_DEFAULT should be used to indicate SIGHASH_DEFAULT for taproot
inputs, and SIGHASH_ALL for all other input types. This avoids adding an
unnecessary byte to the end of all Taproot signatures added to PSBTs
signed in the GUI.
@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 6, 2025

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK Sjors, pablomartin4btc

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #832 (Improve user dialog when signing multisig psbts by mjdietzx)
  • #bitcoin/bitcoin/31622 (psbt: add non-default sighash types to PSBTs and unify sighash type match checking by achow101)
  • #bitcoin/bitcoin/29675 (wallet: Be able to receive and spend inputs involving MuSig2 aggregate keys by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@luke-jr
Copy link
Member

luke-jr commented Jan 8, 2025

This avoids adding an unnecessary byte to the end of all Taproot signatures added to PSBTs signed in the GUI.

Two bytes, isn't it? For the PSBT_IN_SIGHASH keytype

@achow101
Copy link
Member Author

achow101 commented Jan 8, 2025

This avoids adding an unnecessary byte to the end of all Taproot signatures added to PSBTs signed in the GUI.

Two bytes, isn't it? For the PSBT_IN_SIGHASH keytype

No, that field is not added. This is referring to the actual signature that will show up in the scriptWitness, and as appears in PSBT_IN_TAPROOT_*_SIG fields beforehand.

@Sjors
Copy link
Member

Sjors commented Jan 16, 2025

utACK 3e97ff9

It would be useful for the FillPSBT doc in wallet.h to explain that passing SIGHASH_DEFAULT will use SIGHASH_ALL for pre-taproot inputs.

You have to crawl all the way to MutableTransactionSignatureCreator::CreateSig to find this out:

// BASE/WITNESS_V0 signatures don't support explicit SIGHASH_DEFAULT, use SIGHASH_ALL instead.
const int hashtype = nHashType == SIGHASH_DEFAULT ? SIGHASH_ALL : nHashType;

bitcoin/bitcoin@e94bb4e makes this problem go away though.


Additional background:
https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#taproot-key-path-spending-signature-validation

A Taproot signature is a 64-byte Schnorr signature, as defined in BIP340, with the sighash byte appended in the usual Bitcoin fashion. This sighash byte is optional. If omitted, the resulting signatures are 64 bytes, and a SIGHASH_DEFAULT mode is implied.

Copy link
Contributor

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 3e97ff9

I agree with @Sjors but is that not covered by doc at the /** Signature hash types/flags */ enum definition (src/script/interpreter.h)?

bitcoin/bitcoin@e94bb4e makes this problem go away though.

is that part of a PR?

@Sjors
Copy link
Member

Sjors commented Jan 17, 2025

@pablomartin4btc it's part of #31622.

The description in interpreter.h is ambiguous. It says "Taproot only". It also says "equivalent to SIGHASH_ALL", but doesn't say that it gets converted (and obviously a constant can't guarantee that actually happens).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants