What changed, and why it matters
This commit swaps Rust's stable sort for an unstable sort in three places inside the BitBox02 firmware. The change only affects the order in which equal items are arranged, and the commit message explicitly states that equal items have identical contents, so the result is the same. The main benefit is a smaller firmware file and avoiding a possible memory allocation during sorting. There is no direct evidence this fixes a security vulnerability.
No immediate action required. Treat as a code-size optimization. If reviewing for audit purposes, verify the claim that equal serialized xpubs/public keys/keypaths are byte-identical and that unstable reordering therefore cannot change externally observable outputs.
Security signals we found
Behavior-preserving optimization with no change to sorted outputs when keys are unique or equal values are identical
Commit message explicitly addresses determinism concerns for registration hashes, output scripts, and witness order
No input validation, memory-safety, or cryptographic changes in the diff
Evidence from the diff
The patch replaces .sort() with .sort_unstable() for serialized multisig xpubs, derived public keys used in multisig output scripts, and Cardano signing keypaths. Unstable sorting does not preserve the relative order of equal elements, but the commit message argues that equal elements are byte-identical, so any permutation yields the same registration hash, the same multisig script, and the same deduplicated witness set. The change reduces firmware size by 832 bytes and removes the stable sort’s potential temporary allocation.
Changed components
Bitcoin multisig registration hash computationBitcoin multisig P2SH/P2WSH output script constructionCardano transaction signing keypath sorting and deduplicationInspect captured patch +3 / −3
### src/rust/bitbox02-rust/src/hww/api/bitcoin/multisig.rs
@@ -73,7 +73,7 @@ pub fn get_hash(
.map(|xpub| bip32::Xpub::from(xpub).serialize(None))
.collect::<Result<Vec<Vec<u8>>, ()>>()?;
if let SortXpubs::Yes = sort_xpubs {
- xpubs_serialized.sort();
+ xpubs_serialized.sort_unstable();
}
for xpub in xpubs_serialized.iter() {
hasher.update(xpub);
@@ -303,7 +303,7 @@ pub fn pkscript(
.to_vec())
})
.collect::<Result<_, _>>()?;
- pubkeys.sort();
+ pubkeys.sort_unstable();
let mut script_builder = bitcoin::script::Builder::new().push_int(multisig.threshold as _);
for pk in pubkeys.iter() {
### src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction.rs
@@ -317,7 +317,7 @@ async fn _process(
out
};
- signing_keypaths.sort();
+ signing_keypaths.sort_unstable();
signing_keypaths.dedup();
let mut shelley_witnesses: Vec<ShelleyWitness> = Vec::with_capacity(signing_keypaths.len());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.