Merge rust-bitcoin/rust-bitcoin#7114: bitcoin: move annex and code_separator_pos to the end
What changed, and why it matters
This change simply reorders the arguments of two Bitcoin Taproot signature hash functions so that rarely-used optional parameters appear at the end. It is a developer-experience improvement and does not change any security behavior.
No security action needed. Treat as a normal API-breaking refactor when upgrading dependent code.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit swaps the parameter order in taproot_key_spend_signature_hash (moving annex after sighash_type) and taproot_script_spend_signature_hash (moving annex and code_separator_pos after sighash_type). All call sites are updated accordingly. The logic, types, and computations are unchanged; only the API surface is altered to produce clearer compiler errors for consumers upgrading the library.
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 19/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.