api/restore: add unit test and count security chip events
What changed, and why it matters
This commit only adds a new automated test for the wallet-restore feature. It does not change any production code, fix a bug, or alter device behavior. The test checks that restoring from a mnemonic phrase prompts the user twice for a password and triggers a specific number of secure-chip events.
No security action required; this is a test-only change. Review the test for correctness during normal code review if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a Rust unit test, test_from_mnemonic, in src/rust/bitbox02-rust/src/hww/api/restore.rs. It uses a mocked hardware abstraction layer (TestingHal) and mocked memory/keystore/secure-chip functions to exercise from_mnemonic. Assertions verify UI prompts, secure-chip event counter value (19), keystore unlock state, memory initialization state, and seed length. No production logic is modified.
Changed components
src/rust/bitbox02-rust/src/hww/api/restore.rsInspect captured patch +47 / −0
diff --git a/src/rust/bitbox02-rust/src/hww/api/restore.rs b/src/rust/bitbox02-rust/src/hww/api/restore.rs
index 6d029d9..d58c593 100644
--- a/src/rust/bitbox02-rust/src/hww/api/restore.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/restore.rs
@@ -168,3 +168,50 @@ pub async fn from_mnemonic(
unlock::unlock_bip39(hal).await;
Ok(Response::Success(pb::Success {}))
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ use crate::bb02_async::block_on;
+ use crate::hal::testing::TestingHal;
+ use bitbox02::testing::mock_memory;
+ use bitbox02::{keystore, memory};
+
+ use alloc::boxed::Box;
+
+ #[test]
+ fn test_from_mnemonic() {
+ mock_memory();
+ keystore::lock();
+ let mut counter = 0u32;
+ let mut mock_hal = TestingHal::new();
+ mock_hal.ui.set_enter_string(Box::new(|params| {
+ counter += 1;
+ match counter {
+ 1 => assert_eq!(params.title, "Set password"),
+ 2 => assert_eq!(params.title, "Repeat password"),
+ _ => panic!("too many user inputs"),
+ }
+ Ok("password".into())
+ }));
+
+ bitbox02::securechip::fake_event_counter_reset();
+ assert_eq!(
+ block_on(from_mnemonic(
+ &mut mock_hal,
+ &pb::RestoreFromMnemonicRequest {
+ timestamp: 0,
+ timezone_offset: 0,
+ }
+ )),
+ Ok(Response::Success(pb::Success {}))
+ );
+ assert_eq!(bitbox02::securechip::fake_event_counter(), 19);
+ drop(mock_hal); // to remove mutable borrow of counter
+ assert_eq!(counter, 2);
+ assert!(!keystore::is_locked());
+ assert!(memory::is_initialized());
+ assert!(keystore::copy_seed().unwrap().len() == 32);
+ }
+}
Why this scored 13/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.