Add the unified opt-in signature hash - #154
Open
kwsantiago wants to merge 3 commits into
Open
kwsantiago wants to merge 3 commits into
kwsantiago wants to merge 3 commits into
Conversation
kwsantiago
force-pushed
the
upstream-pr/unified-sighash
branch
from
September 3, 2026 12:48
b5b952c to
e7ad23c
Compare
Bitcoin Knots v29.4.1.knots20260508 defines one signature message for every script type, opted into per input by hash type bit 0x20. It is specified in doc/unified-sighash.md at that tag. That release is a hardfork of Bitcoin and also changes its proof of work; this is the signature message alone and carries no activation height. Transaction.sighash_unified builds it for bare/P2SH, segwit v0, taproot key path and tapscript. SIGHASH.check_unified decides which hash types the message defines, which differs by script type: bare and segwit v0 read the byte the legacy way, where 0x20 is a hash type of its own, and taproot keeps BIP341's reading, where it is reserved. The message is laid out as BIP341 lays out its own so the two can be read side by side. The locktime is committed to as five bytes rather than four, so that widening the field later does not have to invalidate every signature made under this message. The digest memos are now keyed on what they were computed over. sighash_unified is the first caller to pass the spent outputs as an argument rather than read them off self, and one Transaction can be asked for two digests over two different sets. Knots' 166 cross-implementation vectors are vendored byte-identical to that tag and reproduced here.
sign_with negotiates the hash type. The opt-in bit names which algorithm signs rather than what the signature covers, so it is compared separately: a caller may ask for it over a PSBT declaring plain ALL, which is what every wallet predating the hardfork writes, and the type actually signed is recorded back on the input so the field and the signature agree. Where the bit is not in play the comparison is embit's own, unchanged. A caller naming a plain hash type gets exactly what it named, and a taproot input declaring DEFAULT signed with an explicit ALL keeps DEFAULT and its 64 byte signature. Two hash types are refused rather than adjusted. A bare 0x20 or 0xA0 on taproot names no output type, and the bit cannot ride on SIGHASH_DEFAULT, which appends no byte to hold it. SIGHASH_SINGLE with no output at the input's index cannot build the message, so that input is skipped rather than aborting the call and discarding the signatures already made. PSBTView keeps its constant footprint. The message commits to two aggregates over every spent output, neither depending on the input being signed, so one pass over the stream answers for the whole transaction and only those two hashes are kept. Under ANYONECANPAY the siblings are not read at all. The prevout index comes off the wire, so it is checked against the transaction it points into: a crafted one is a PSBTError naming the input rather than an IndexError out of the middle of signing.
The bit selects a Bitcoin consensus rule and does not apply to Liquid. Without a refusal, PSET.sighash and PSETView.sighash route it straight at the Bitcoin digest over Liquid data, where a confidential value is a commitment rather than an int, producing a digest no Liquid implementation would make. Both classes need their own: PSETView inherits PSBTView.sign_with, whose default hash type is SIGHASH.DEFAULT rather than PSET's LSIGHASH.ALL, so the bit is never stripped on the way in. LSIGHASH.RANGEPROOF is 0x40, so there is no collision with 0x20 and legitimate Liquid signing is unaffected.
kwsantiago
force-pushed
the
upstream-pr/unified-sighash
branch
from
September 3, 2026 12:54
e7ad23c to
087d020
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bitcoin Knots
v29.4.1.knots20260508defines one signature message for every script type, opted into per input by hash type bit0x20. It is specified in doc/unified-sighash.md at that tag.That release is a hardfork of Bitcoin and also changes its proof of work. This is the signature message alone and carries no activation height.
Adds
Transaction.sighash_unified()andPSBTView.sighash_unified(), covering bare/P2SH, segwit v0, taproot key path and tapscript.sign_with(), andSIGHASH.UNIFIED.PSBTViewkeeps its constant footprint: it holds the two aggregates over the spent outputs, not the outputs.Unchanged without the bit
Signing that never sets
0x20is byte-identical tomaster: 43,560 rows over every declared and requested hash type, four script types, witness and non-witness spent outputs, for bothPSBTandPSBTView.Verified
src/test/data/unified_sighash.json, vendored byte-identical.Transaction,PSBTandPSBTViewagree on every digest.