Merge remote-tracking branch 'agent/benma-agent/btc-prevtx-input-hash-length'
What changed, and why it matters
This commit adds a safety check in the BitBox02 hardware wallet's Bitcoin transaction signing code. When the device processes a previous transaction supplied by the host computer, it now verifies that each input's previous-output hash is exactly 32 bytes long before using it. Without this check, a malformed or attacker-crafted hash of the wrong length could have been fed into the transaction hasher, potentially leading to incorrect transaction signatures or unexpected device behavior. The change is defensive and includes new tests covering hash lengths of 0, 31, and 33 bytes.
Treat this as a security-hardening fix and include it in the next firmware release. Review adjacent host-supplied fields in the signing flow for similar missing length or format validations. No immediate end-user action is required beyond applying the firmware update once available.
Security signals we found
Input-length validation added to host-supplied previous transaction data
New unit tests explicitly exercise malformed hash lengths (0, 31, 33)
Defensive hardening at the host-device trust boundary in Bitcoin signing flow
Potential for incorrect hashing/signature if wrong-length hash were accepted
Evidence from the diff
In src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs, inside handle_prevtx(), after retrieving a prevtx_input from the host, the code now checks if prevtx_input.prev_out_hash.len() != 32 { return Err(Error::InvalidInput); } before calling hasher.update(prevtx_input.prev_out_hash.as_slice()). A unit test test_process_invalid_prevtx_input_hash_length was added that resizes the prev_out_hash to 0, 31, or 33 bytes for each of two prevtx input indexes and asserts that process() returns Error::InvalidInput. The patch is a length-validation hardening measure; it does not by itself demonstrate an exploitable vulnerability, but it closes a trust boundary where host-supplied data is consumed without prior length validation.
Changed components
BitBox02 firmwareBitcoin transaction signing APIsrc/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rshandle_prevtx() functionprocess() signing flowInspect captured patch +28 / −0
### src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs
@@ -384,6 +384,9 @@ async fn handle_prevtx(
);
let prevtx_input = get_prevtx_input(input_index, prevtx_input_index, next_response).await?;
+ if prevtx_input.prev_out_hash.len() != 32 {
+ return Err(Error::InvalidInput);
+ }
hasher.update(prevtx_input.prev_out_hash.as_slice());
hasher.update(prevtx_input.prev_out_index.to_le_bytes());
hasher.update(serialize(&VarInt(
@@ -3027,6 +3030,31 @@ mod tests {
}
}
+ #[async_test::test]
+ async fn test_process_invalid_prevtx_input_hash_length() {
+ for prevtx_input_index in [0, 1] {
+ for hash_len in [0, 31, 33] {
+ mock_unlocked();
+ let transaction = new_transaction(pb::BtcCoin::Btc).await;
+ {
+ let mut transaction = transaction.borrow_mut();
+ let input = &mut transaction.inputs[0];
+ input.prevtx_inputs[prevtx_input_index]
+ .prev_out_hash
+ .resize(hash_len, 0);
+ input.input.prev_out_hash = prevtx_hash(input);
+ }
+ mock_host_responder(transaction.clone());
+ let init_request = transaction.borrow().init_request();
+ assert_eq!(
+ process(&mut TestingHal::new(), &init_request).await,
+ Err(Error::InvalidInput),
+ "prevtx input {prevtx_input_index}, hash length {hash_len}"
+ );
+ }
+ }
+ }
+
#[async_test::test]
async fn test_silent_payment_rejects_input_keypath_mismatch() {
for (simple_type, purpose) in [Why this scored 59/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.