bitcoin: move annex and code_separator_pos to the end
What changed, and why it matters
This commit simply reorders the arguments of two Bitcoin Taproot sighash functions so that less commonly used parameters (annex and code_separator_pos) appear at the end of the argument list. It is a developer-experience/API cleanup change, not a security fix. There is no change to the underlying cryptographic logic, transaction parsing, or signature validation.
No security action required. Treat as a normal API-breaking change and update any downstream callers to the new argument order when upgrading.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch changes the parameter order for SighashCache::taproot_key_spend_signature_hash and SighashCache::taproot_script_spend_signature_hash. In both functions, sighash_type is moved earlier and the optional annex (and code_separator_pos for script spend) is moved to the end. All call sites in the example code and tests are updated to match the new order. The function bodies and the data hashed remain identical.
Changed components
bitcoin/src/crypto/sighash.rsbitcoin/examples/sign-tx-taproot.rsInspect captured patch +7 / −7
### bitcoin/examples/sign-tx-taproot.rs
@@ -61,7 +61,7 @@ fn main() {
let mut sighasher = SighashCache::new(&mut unsigned_tx);
let sighash = sighasher
- .taproot_key_spend_signature_hash(input_index, &prevouts, None, sighash_type)
+ .taproot_key_spend_signature_hash(input_index, &prevouts, sighash_type, None)
.expect("failed to construct sighash");
// Sign the sighash and update the witness stack.
### bitcoin/src/crypto/sighash.rs
@@ -520,8 +520,8 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
&mut self,
input_index: usize,
prevouts: &Prevouts<T>,
- annex: Option<Annex>,
sighash_type: TapSighashType,
+ annex: Option<Annex>,
) -> Result<TapSighash, TaprootError> {
let mut enc = sha256t::Hash::<TapSighashTag>::engine();
self.taproot_encode_signing_data_to(
@@ -545,10 +545,10 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
&mut self,
input_index: usize,
prevouts: &Prevouts<T>,
- annex: Option<Annex>,
leaf_hash: S,
- code_separator_pos: Option<u32>,
sighash_type: TapSighashType,
+ annex: Option<Annex>,
+ code_separator_pos: Option<u32>,
) -> Result<TapSighash, TaprootError> {
let mut enc = sha256t::Hash::<TapSighashTag>::engine();
self.taproot_encode_signing_data_to(
@@ -1782,16 +1782,16 @@ mod tests {
Some((leaf_hash, _)) => sighash_cache.taproot_script_spend_signature_hash(
input_index,
&prevouts,
- annex,
leaf_hash,
- code_separator_pos,
sighash_type,
+ annex,
+ code_separator_pos,
),
None => sighash_cache.taproot_key_spend_signature_hash(
input_index,
&prevouts,
- annex,
sighash_type,
+ annex,
),
};
assert_eq!(spend_hash.unwrap(), hash);Why this scored 20/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.