Skip to content

Add the unified opt-in signature hash - #154

Open
kwsantiago wants to merge 3 commits into
diybitcoinhardware:masterfrom
privkeyio:upstream-pr/unified-sighash
Open

kwsantiago wants to merge 3 commits into
diybitcoinhardware:masterfrom
privkeyio:upstream-pr/unified-sighash

Conversation

@kwsantiago

@kwsantiago kwsantiago commented Sep 3, 2026 •

Copy link
Copy Markdown

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.

Adds

  • Transaction.sighash_unified() and PSBTView.sighash_unified(), covering bare/P2SH, segwit v0, taproot key path and tapscript.
  • Hash type negotiation in sign_with(), and SIGHASH.UNIFIED.
  • Liquid refuses the bit.

PSBTView keeps its constant footprint: it holds the two aggregates over the spent outputs, not the outputs.

Unchanged without the bit

Signing that never sets 0x20 is byte-identical to master: 43,560 rows over every declared and requested hash type, four script types, witness and non-witness spent outputs, for both PSBT and PSBTView.

Verified

  • All 166 cross-implementation vectors from Knots' src/test/data/unified_sighash.json, vendored byte-identical.
  • 64 tests.
  • Transaction, PSBT and PSBTView agree on every digest.
  • Signing accepted and mined by a Knots regtest node.

@kwsantiago
kwsantiago force-pushed the upstream-pr/unified-sighash branch from b5b952c to e7ad23c Compare September 3, 2026 12:48
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
kwsantiago force-pushed the upstream-pr/unified-sighash branch from e7ad23c to 087d020 Compare September 3, 2026 12:54

This branch has not been deployed

No deployments
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.

1 participant