Skip to content

support SIGHASH_ANYONECANPAY in taproot sighash - #3

Open
fmoletta-muun wants to merge 3 commits into
release-0.15.4-sighash-anyone-can-payfrom
0.15.4-sighash-anyone-can-pay
Open

support SIGHASH_ANYONECANPAY in taproot sighash#3
fmoletta-muun wants to merge 3 commits into
release-0.15.4-sighash-anyone-can-payfrom
0.15.4-sighash-anyone-can-pay

Conversation

@fmoletta-muun

Copy link
Copy Markdown
Collaborator

Accept ALL | ANYONECANPAY (0x81, BIP341) in hashForTaprootSignature: skip the four all-input midstate hashes and commit to the signed input's outpoint, spent output and sequence instead. Write the full sighash type byte into the message (the masked byte was only correct for types without the flag) and fix the sign of the anyone-can-pay term in the buffer size formula. ANYONECANPAY alone (0x80) stays rejected: it is not a valid taproot sighash type. Golden values from btcd v0.24.2 with txscript.SigHashAll|txscript.SigHashAnyOneCanPay.

Accept ALL | ANYONECANPAY (0x81, BIP341) in hashForTaprootSignature:
skip the four all-input midstate hashes and commit to the signed
input's outpoint, spent output and sequence instead. Write the full
sighash type byte into the message (the masked byte was only correct
for types without the flag) and fix the sign of the anyone-can-pay
term in the buffer size formula. ANYONECANPAY alone (0x80) stays
rejected: it is not a valid taproot sighash type. Golden values from
btcd v0.24.2 with txscript.SigHashAll|txscript.SigHashAnyOneCanPay.
@fmoletta-muun fmoletta-muun self-assigned this Jul 27, 2026
@fmoletta-muun
fmoletta-muun requested a review from champo July 28, 2026 14:37
*
* <p>Limitations: only SigHash.DEFAULT and SigHash.ALL without ANYONECANPAY are supported; SigHash.NONE,
* SigHash.SINGLE and the annex are not implemented. OP_CODESEPARATOR is not supported: the codesep_pos in the
* <p>Limitations: only SigHash.DEFAULT, SigHash.ALL and SigHash.ALL | SigHash.ANYONECANPAY are supported;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not just use the existing enum ANYONECANPAY_ALL?

This way you also don't need to loss the type Transaction.SigHash which was changed to byte in

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense! Updated here c19d01a

Replace SigHash.ALL | SigHash.ANYONECANPAY with the existing
ANYONECANPAY_ALL enum constant in javadoc, comments and tests. The
test helper takes Transaction.SigHash again and converts with
byteValue(), so call sites pass plain enum constants without casts.
No behavior change.
tapLeafHash,
parseTaprootPrevOuts(),
sigHashType
sigHashType.byteValue()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We can also require the Transaction.SigHash type in hashForTaprootSignature
Suggestion: link

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure! b7c04ff

@kovin-muun kovin-muun left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚀

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.

2 participants