AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 60 Bitcoin

Merge rust-bitcoin/rust-bitcoin#7067: Add annex and codeseparator position to taproot sighash methods

Public commit record

What the developer wrote

Authored by Andrew Poelstra

96/100 · Strong
Merge rust-bitcoin/rust-bitcoin#7067: Add annex and codeseparator position to taproot sighash methods

897a4e32f3cce741955f3ec906e9013f36ffb2ac bitcoin: add codeseparator test vectors from Core (anshumancanrock)
65b7d7dfa9b07c9208f1a1502b469d6681a60161 bitcoin: test taproot sighash methods (anshumancanrock)
f8e2f4eea0e43d3da53c217d9870f039080a1f78 bitcoin: add annex and codeseparator position to taproot sighash methods (anshumancanrock)

Pull request description:

Fixes #7019

`taproot_key_spend_signature_hash` and `taproot_script_spend_signature_hash` have no way to pass an annex, so they return the wrong sighash for any input that has one. The script spend one also hardcodes the codeseparator position to `0xFFFFFFFF`, which is wrong once an `OP_CODESEPARATOR` has executed.

I Added `annex: Option<Annex>` to both, and `code_separator_pos: Option<u32>` to the script spend one (`None` = no `OP_CODESEPARATOR` was executed). Arg order matches `taproot_signature_hash`.

The existing taproot sighash tests, including the annex ones, now also go through these methods. There's also a small test for the codeseparator position.

The mainnet example from the issue is tx `f859a4e6692c3f15a279449eac191ecb9d17d2d6c003bbae9a55e5da07147eab`, in block 896088 (not 896078). Its signature verifies with the annex and fails without it.


ACKs for top commit:
jrakibi:
ACK 897a4e32f3cce741955f3ec906e9013f36ffb2ac
apoelstra:
ACK 897a4e32f3cce741955f3ec906e9013f36ffb2ac; successfully ran local tests


Tree-SHA512: 9465eb838a7b3454e4307341b725a0f49ce44bd3ee2764108e85f79bd8d796bfb2d04ddcae49e6c47f669a2bd28c025ec4013befc04af8ea93bd2c86541d8179
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This commit fixes a bug in how Bitcoin transaction signatures are calculated for Taproot-style transactions. Previously, two helper methods could not accept an optional extra data chunk called an 'annex' and always assumed no special code-separator instruction had run. That meant any transaction using those features would compute an incorrect signature hash, causing a valid signature to be rejected. The change adds the missing parameters so the helpers match the more complete API. It is a correctness fix rather than a memory-safety or remote-exploitable vulnerability, but incorrect sighashes can break wallets, tests, or services that rely on these methods.

Recommended action

Review downstream callers of `taproot_key_spend_signature_hash` and `taproot_script_spend_signature_hash` to ensure they now pass the correct annex and code-separator position; update any code that relied on the old hardcoded behavior. Consider this a bug-fix release for the sighash module.

Security signals we found

01

API correctness fix for BIP-341 Taproot sighash computation

02

Previously hardcoded annex and code-separator values produced incorrect signature hashes

03

Incorrect sighash can cause signature verification failures for valid transactions

04

New test vectors from Bitcoin Core cover code-separator positions

05

No memory-unsafe code, panic paths, or input-validation bypass observed

Risk score

Why this scored 60/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 8/15
Affected reach 10/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.