What changed, and why it matters
This commit only changes test code. It replaces calls to a fake/global securechip event counter with calls through a test-only mock hardware abstraction layer (HAL). There is no change to the actual firmware behavior or any user-facing security feature.
No security action required. Treat as a normal test refactoring review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies four Rust test modules (backup.rs, show_mnemonic.rs, keystore.rs, unlock.rs). Each change is inside #[cfg(test)] mod tests blocks. It swaps bitbox02::securechip::fake_event_counter_reset() and bitbox02::securechip::fake_event_counter() for mock_hal.securechip.event_counter_reset() and mock_hal.securechip.get_event_counter(). This is a refactoring of test instrumentation to route securechip counter checks through the existing TestingHal mock, matching the project’s HAL abstraction. No production code paths are altered.
Changed components
src/rust/bitbox02-rust/src/hww/api/backup.rs (tests only)src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs (tests only)src/rust/bitbox02-rust/src/keystore.rs (tests only)src/rust/bitbox02-rust/src/workflow/unlock.rs (tests only)Inspect captured patch +18 / −18
diff --git a/src/rust/bitbox02-rust/src/hww/api/backup.rs b/src/rust/bitbox02-rust/src/hww/api/backup.rs
index 1e84b06..a115154 100644
--- a/src/rust/bitbox02-rust/src/hww/api/backup.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/backup.rs
@@ -187,7 +187,7 @@ mod tests {
let mut mock_hal = TestingHal::new();
mock_hal.sd.inserted = Some(true);
- bitbox02::securechip::fake_event_counter_reset();
+ mock_hal.securechip.event_counter_reset();
assert_eq!(
block_on(create(
&mut mock_hal,
@@ -198,7 +198,7 @@ mod tests {
)),
Ok(Response::Success(pb::Success {}))
);
- assert_eq!(bitbox02::securechip::fake_event_counter(), 1);
+ assert_eq!(mock_hal.securechip.get_event_counter(), 1);
assert_eq!(EXPECTED_TIMESTMAP, bitbox02::memory::get_seed_birthdate());
assert_eq!(
mock_hal.ui.screens,
@@ -246,7 +246,7 @@ mod tests {
password_entered = true;
Ok("password".into())
}));
- bitbox02::securechip::fake_event_counter_reset();
+ mock_hal.securechip.event_counter_reset();
assert_eq!(
block_on(create(
&mut mock_hal,
@@ -257,7 +257,7 @@ mod tests {
)),
Ok(Response::Success(pb::Success {}))
);
- assert_eq!(bitbox02::securechip::fake_event_counter(), 5);
+ assert_eq!(mock_hal.securechip.get_event_counter(), 5);
assert_eq!(
mock_hal.ui.screens,
vec![
diff --git a/src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs b/src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs
index 5648fb1..2fe7b34 100644
--- a/src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/show_mnemonic.rs
@@ -97,13 +97,13 @@ mod tests {
panic!("unexpected call to enter password")
}));
- bitbox02::securechip::fake_event_counter_reset();
+ mock_hal.securechip.event_counter_reset();
assert_eq!(
block_on(process(&mut mock_hal)),
Ok(Response::Success(pb::Success {}))
);
// 1 operation for one copy_seed() to get the seed to display it.
- assert_eq!(bitbox02::securechip::fake_event_counter(), 1);
+ assert_eq!(mock_hal.securechip.get_event_counter(), 1);
assert_eq!(
mock_hal.ui.screens,
@@ -151,12 +151,12 @@ mod tests {
Ok("password".into())
}));
- bitbox02::securechip::fake_event_counter_reset();
+ mock_hal.securechip.event_counter_reset();
assert_eq!(
block_on(process(&mut mock_hal)),
Ok(Response::Success(pb::Success {}))
);
- assert_eq!(bitbox02::securechip::fake_event_counter(), 5);
+ assert_eq!(mock_hal.securechip.get_event_counter(), 5);
assert_eq!(
mock_hal.ui.screens,
@@ -206,9 +206,9 @@ mod tests {
.ui
.set_enter_string(Box::new(|_params| Ok("wrong password".into())));
- bitbox02::securechip::fake_event_counter_reset();
+ mock_hal.securechip.event_counter_reset();
assert_eq!(block_on(process(&mut mock_hal)), Err(Error::Generic));
- assert_eq!(bitbox02::securechip::fake_event_counter(), 5);
+ assert_eq!(mock_hal.securechip.get_event_counter(), 5);
assert_eq!(
mock_hal.ui.screens,
diff --git a/src/rust/bitbox02-rust/src/keystore.rs b/src/rust/bitbox02-rust/src/keystore.rs
index 3402d8b..113f1e1 100644
--- a/src/rust/bitbox02-rust/src/keystore.rs
+++ b/src/rust/bitbox02-rust/src/keystore.rs
@@ -892,17 +892,17 @@ mod tests {
));
// First call: unlock. The first one does a seed rentention (1 securechip event).
- bitbox02::securechip::fake_event_counter_reset();
+ mock_hal.securechip.event_counter_reset();
assert_eq!(unlock(&mut mock_hal, "password").unwrap().as_slice(), seed);
- assert_eq!(bitbox02::securechip::fake_event_counter(), 6);
+ assert_eq!(mock_hal.securechip.get_event_counter(), 6);
// Loop to check that unlocking works while unlocked.
for _ in 0..2 {
// Further calls perform a password check.The password check does not do the retention
// so it ends up needing one secure chip operation less.
- bitbox02::securechip::fake_event_counter_reset();
+ mock_hal.securechip.event_counter_reset();
assert_eq!(unlock(&mut mock_hal, "password").unwrap().as_slice(), seed);
- assert_eq!(bitbox02::securechip::fake_event_counter(), 5);
+ assert_eq!(mock_hal.securechip.get_event_counter(), 5);
}
// Also check that the retained seed was encrypted with the expected encryption key.
diff --git a/src/rust/bitbox02-rust/src/workflow/unlock.rs b/src/rust/bitbox02-rust/src/workflow/unlock.rs
index 021b0f7..934799a 100644
--- a/src/rust/bitbox02-rust/src/workflow/unlock.rs
+++ b/src/rust/bitbox02-rust/src/workflow/unlock.rs
@@ -218,10 +218,10 @@ mod tests {
password_entered = true;
Ok("password".into())
}));
- bitbox02::securechip::fake_event_counter_reset();
+ mock_hal.securechip.event_counter_reset();
assert_eq!(block_on(unlock(&mut mock_hal)), Ok(()));
// 6 for keystore unlock, 1 for keystore bip39 unlock.
- assert_eq!(bitbox02::securechip::fake_event_counter(), 7);
+ assert_eq!(mock_hal.securechip.get_event_counter(), 7);
assert!(!crate::keystore::is_locked());
@@ -261,7 +261,7 @@ mod tests {
Ok("wrong password".into())
}));
- bitbox02::securechip::fake_event_counter_reset();
+ mock_hal.securechip.event_counter_reset();
assert!(matches!(
block_on(unlock_keystore(
&mut mock_hal,
@@ -270,7 +270,7 @@ mod tests {
)),
Err(UnlockError::IncorrectPassword),
));
- assert_eq!(bitbox02::securechip::fake_event_counter(), 5);
+ assert_eq!(mock_hal.securechip.get_event_counter(), 5);
// Checks that the device is locked.
assert!(crate::keystore::copy_seed().is_err());
Why this scored 15/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.