Merge remote-tracking branch 'agent/benma-agent/btc-validate-prevout-hash'
What changed, and why it matters
This commit adds a safety check in the BitBox02 hardware wallet's Bitcoin transaction signing code. It now rejects transaction inputs whose 'previous output hash' (a transaction identifier) is not exactly 32 bytes long. Previously, only a zero-value input was rejected. The change prevents malformed or attacker-crafted inputs with wrong hash lengths from being processed during signing. A new test verifies the device correctly refuses these invalid inputs.
No immediate user action required; this is a defensive hardening patch. Ensure firmware is updated to a version containing this commit. Developers should review whether other fixed-length fields in the signing protocol (e.g., public keys, signatures, script hashes) have similar length validation.
Security signals we found
Input validation hardening for fixed-length cryptographic identifier (32-byte prev_out_hash)
Prevention of malformed Bitcoin transaction inputs reaching signing logic
Addition of defensive unit test for invalid hash lengths
Evidence from the diff
In src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs, the validate_input() function now returns Error::InvalidInput if input.prev_out_hash.len() != 32 in addition to the existing prev_out_value == 0 check. The previous transaction output hash (txid) in Bitcoin must always be 32 bytes; accepting other lengths could lead to incorrect transaction serialization, signature computation over unintended data, or parsing issues downstream. The patch includes a unit test that exercises lengths 0, 31, and 33 bytes during both signing passes and confirms Error::InvalidInput is returned.
Changed components
BitBox02 firmware Bitcoin signing APIsrc/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rsInspect captured patch +36 / −1
### src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs
@@ -267,7 +267,7 @@ fn validate_input(
params: &super::params::Params,
script_config_account: &ValidatedScriptConfigWithKeypath,
) -> Result<(), Error> {
- if input.prev_out_value == 0 {
+ if input.prev_out_value == 0 || input.prev_out_hash.len() != 32 {
return Err(Error::InvalidInput);
}
validate_keypath(
@@ -2992,6 +2992,41 @@ mod tests {
}
}
+ #[async_test::test]
+ async fn test_process_invalid_prev_out_hash_length() {
+ for invalid_pass in [1, 2] {
+ for hash_len in [0, 31, 33] {
+ mock_unlocked();
+ let transaction = new_transaction(pb::BtcCoin::Btc).await;
+ let tx = transaction.clone();
+ let first_input_requests = alloc::rc::Rc::new(core::cell::Cell::new(0));
+ let first_input_requests_callback = first_input_requests.clone();
+ *crate::hww::MOCK_NEXT_REQUEST.0.borrow_mut() =
+ Some(Box::new(move |response: Response| {
+ let input_index = extract_next(&response).index;
+ let mut request = tx.borrow().make_host_request(response);
+ if let Request::BtcSignInput(input) = &mut request
+ && input_index == 0
+ {
+ let pass = first_input_requests_callback.get() + 1;
+ first_input_requests_callback.set(pass);
+ if pass == invalid_pass {
+ input.prev_out_hash.resize(hash_len, 0);
+ }
+ }
+ Ok(request)
+ }));
+
+ let init_request = transaction.borrow().init_request();
+ assert_eq!(
+ process(&mut TestingHal::new(), &init_request).await,
+ Err(Error::InvalidInput)
+ );
+ assert_eq!(first_input_requests.get(), invalid_pass);
+ }
+ }
+ }
+
#[async_test::test]
async fn test_silent_payment_rejects_input_keypath_mismatch() {
for (simple_type, purpose) in [Why this scored 60/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.