bitbox02-rust: remove redundant mock_memory calls
What changed, and why it matters
This commit only cleans up test code by removing unnecessary calls to a mock memory setup function. It does not change the actual firmware that runs on the BitBox02 device, so it has no security impact on users.
No security action required. This is a test-only refactoring. Routine code review is sufficient.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit removes redundant bitbox02::testing::mock_memory() invocations from Rust unit tests across 11 files. The project introduced a HAL (Hardware Abstraction Layer) with a TestingHal type whose memory field already provides the same mocked memory state, making the old global mock_memory() calls redundant. In keystore.rs and salt.rs, the old global bitbox02::memory::set_salt_root call is replaced with mock_hal.memory.set_salt_root. No production code paths are modified.
Changed components
Rust unit tests in bitbox02-rust (bitcoin API, restore, set_device_name, set_mnemonic_passphrase_enabled, keystore, salt modules)Inspect captured patch +2 / −38
diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin.rs
index 1e394b7..e7f4ab5 100644
--- a/src/rust/bitbox02-rust/src/hww/api/bitcoin.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin.rs
@@ -327,7 +327,6 @@ mod tests {
use crate::keystore::testing::{TEST_MNEMONIC, mock_unlocked, mock_unlocked_using_mnemonic};
use alloc::boxed::Box;
use alloc::vec::Vec;
- use bitbox02::testing::mock_memory;
use pb::btc_script_config::multisig::ScriptType as MultisigScriptType;
use util::bb02_async::block_on;
use util::bip32::HARDENED;
@@ -984,7 +983,6 @@ mod tests {
},
];
for test in tests.iter() {
- mock_memory();
let name = "some name";
mock_unlocked_using_mnemonic(
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/multisig.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/multisig.rs
index 93c408f..cd42f7d 100644
--- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/multisig.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/multisig.rs
@@ -323,7 +323,6 @@ mod tests {
use crate::keystore::testing::mock_unlocked_using_mnemonic;
use bip32::parse_xpub;
- use bitbox02::testing::mock_memory;
use util::bip32::HARDENED;
#[test]
diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/registration.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/registration.rs
index 37f54fc..425172c 100644
--- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/registration.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/registration.rs
@@ -168,7 +168,6 @@ mod tests {
use crate::bip32::parse_xpub;
use crate::keystore::testing::mock_unlocked_using_mnemonic;
- use bitbox02::testing::mock_memory;
use util::bip32::HARDENED;
use crate::hal::testing::TestingHal;
@@ -178,7 +177,6 @@ mod tests {
#[test]
fn test_process_is_script_config_registered() {
fn test(sort_xpubs: SortXpubs) {
- mock_memory();
let mut mock_hal = TestingHal::new();
let keypath = &[48 + HARDENED, 0 + HARDENED, 10 + HARDENED, 2 + HARDENED];
diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/script_configs.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/script_configs.rs
index 16f9f35..758d7a9 100644
--- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/script_configs.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/script_configs.rs
@@ -64,7 +64,6 @@ mod tests {
use super::*;
use crate::bip32::parse_xpub;
use crate::keystore::testing::mock_unlocked;
- use bitbox02::testing::mock_memory;
#[test]
fn test_self_transfer_representation_simple_type() {
diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs
index 8a39a7e..64c5777 100644
--- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/signtx.rs
@@ -1293,7 +1293,6 @@ mod tests {
use crate::hal::{Memory, testing::TestingHal};
use crate::keystore::testing::{mock_unlocked, mock_unlocked_using_mnemonic};
use alloc::boxed::Box;
- use bitbox02::testing::mock_memory;
use hex_lit::hex;
use pb::btc_payment_request_request::{Memo, memo};
use util::bb02_async::block_on;
@@ -1818,7 +1817,6 @@ mod tests {
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
);
- mock_memory();
let params = super::super::params::get(pb::BtcCoin::Btc);
let keypath = &[48 + HARDENED, params.bip44_coin, 0 + HARDENED, 2 + HARDENED];
@@ -2890,8 +2888,6 @@ mod tests {
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
);
- // For the multisig registration below.
- mock_memory();
// Hash of the multisig configuration as computed by `btc_common_multisig_hash_sorted()`.
let multisig_hash =
@@ -3063,8 +3059,6 @@ mod tests {
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
);
- // For the multisig registration below.
- mock_memory();
// Hash of the multisig configuration as computed by `btc_common_multisig_hash_sorted()`.
let multisig_hash =
@@ -3138,8 +3132,6 @@ mod tests {
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
);
- // For the multisig registration below.
- mock_memory();
// Hash of the multisig configuration as computed by `btc_common_multisig_hash_sorted()`.
let multisig_hash =
@@ -3236,8 +3228,6 @@ mod tests {
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
);
- // For the policy registration below.
- mock_memory();
let keypath_account = &[48 + HARDENED, 1 + HARDENED, 0 + HARDENED, 3 + HARDENED];
@@ -3361,8 +3351,6 @@ mod tests {
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
);
- // For the policy registration below.
- mock_memory();
let keypath_account = &[48 + HARDENED, 1 + HARDENED, 0 + HARDENED, 3 + HARDENED];
@@ -3425,8 +3413,6 @@ mod tests {
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
);
- // For the policy registration below.
- mock_memory();
let keypath_account = &[48 + HARDENED, 1 + HARDENED, 0 + HARDENED, 3 + HARDENED];
@@ -3548,8 +3534,6 @@ mod tests {
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
);
- // For the policy registration below.
- mock_memory();
let keypath_account = &[48 + HARDENED, 1 + HARDENED, 0 + HARDENED, 3 + HARDENED];
@@ -3609,8 +3593,6 @@ mod tests {
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
);
- // For the policy registration below.
- mock_memory();
let keypath_account = &[48 + HARDENED, 1 + HARDENED, 0 + HARDENED, 3 + HARDENED];
let wrong_keypath_account = &[48 + HARDENED, 1 + HARDENED, 0 + HARDENED, 4 + HARDENED];
@@ -3664,8 +3646,6 @@ mod tests {
"sudden tenant fault inject concert weather maid people chunk youth stumble grit",
"",
);
- // For the policy registration below.
- mock_memory();
let keypath_account = &[48 + HARDENED, 1 + HARDENED, 0 + HARDENED, 3 + HARDENED];
diff --git a/src/rust/bitbox02-rust/src/hww/api/bitcoin/xpubs.rs b/src/rust/bitbox02-rust/src/hww/api/bitcoin/xpubs.rs
index a1df800..666a064 100644
--- a/src/rust/bitbox02-rust/src/hww/api/bitcoin/xpubs.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/bitcoin/xpubs.rs
@@ -60,7 +60,6 @@ mod tests {
use super::*;
use crate::keystore::testing::{mock_unlocked, mock_unlocked_using_mnemonic};
- use bitbox02::testing::mock_memory;
use util::bb02_async::block_on;
use util::bip32::HARDENED;
diff --git a/src/rust/bitbox02-rust/src/hww/api/restore.rs b/src/rust/bitbox02-rust/src/hww/api/restore.rs
index 9542506..1bc0f67 100644
--- a/src/rust/bitbox02-rust/src/hww/api/restore.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/restore.rs
@@ -159,7 +159,6 @@ mod tests {
use crate::hal::testing::TestingHal;
use bitbox02::memory;
- use bitbox02::testing::mock_memory;
use util::bb02_async::block_on;
use alloc::boxed::Box;
@@ -167,7 +166,6 @@ mod tests {
#[test]
fn test_from_mnemonic() {
- mock_memory();
crate::keystore::lock();
let mnemonic_words: Vec<&str> = "boring mistake dish oyster truth pigeon viable emerge sort crash wire portion cannon couple enact box walk height pull today solid off enable tide"
.split(' ')
diff --git a/src/rust/bitbox02-rust/src/hww/api/set_device_name.rs b/src/rust/bitbox02-rust/src/hww/api/set_device_name.rs
index 1e0bc89..a37e2ff 100644
--- a/src/rust/bitbox02-rust/src/hww/api/set_device_name.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/set_device_name.rs
@@ -37,7 +37,6 @@ mod tests {
use crate::hal::testing::TestingHal;
use crate::hal::testing::ui::Screen;
use alloc::boxed::Box;
- use bitbox02::testing::mock_memory;
use util::bb02_async::block_on;
#[test]
@@ -45,7 +44,6 @@ mod tests {
const SOME_NAME: &str = "foo";
// All good.
- mock_memory();
let mut mock_hal = TestingHal::new();
assert_eq!(
block_on(process(
diff --git a/src/rust/bitbox02-rust/src/hww/api/set_mnemonic_passphrase_enabled.rs b/src/rust/bitbox02-rust/src/hww/api/set_mnemonic_passphrase_enabled.rs
index c9024a6..cd824c9 100644
--- a/src/rust/bitbox02-rust/src/hww/api/set_mnemonic_passphrase_enabled.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/set_mnemonic_passphrase_enabled.rs
@@ -39,13 +39,12 @@ mod tests {
use crate::hal::testing::TestingHal;
use crate::hal::testing::ui::Screen;
use alloc::boxed::Box;
- use bitbox02::testing::mock_memory;
use util::bb02_async::block_on;
#[test]
pub fn test_mnemonic_passphrase_enabled() {
// All good.
- mock_memory();
+
// Enable:
let mut mock_hal = TestingHal::new();
assert_eq!(
diff --git a/src/rust/bitbox02-rust/src/keystore.rs b/src/rust/bitbox02-rust/src/keystore.rs
index 06c2e80..b261a22 100644
--- a/src/rust/bitbox02-rust/src/keystore.rs
+++ b/src/rust/bitbox02-rust/src/keystore.rs
@@ -1440,7 +1440,6 @@ mod tests {
#[test]
fn test_unlock_migrate_password_algo() {
- mock_memory();
lock();
let mut mock_hal = TestingHal::new();
@@ -1449,7 +1448,7 @@ mod tests {
let mock_salt_root =
hex!("3333333333333333444444444444444411111111111111112222222222222222");
- bitbox02::memory::set_salt_root(&mock_salt_root).unwrap();
+ mock_hal.memory.set_salt_root(&mock_salt_root);
let password = "password";
diff --git a/src/rust/bitbox02-rust/src/salt.rs b/src/rust/bitbox02-rust/src/salt.rs
index fac8904..76e1521 100644
--- a/src/rust/bitbox02-rust/src/salt.rs
+++ b/src/rust/bitbox02-rust/src/salt.rs
@@ -30,7 +30,6 @@ pub fn hash_data(
mod tests {
use super::*;
use crate::hal::testing::TestingHal;
- use bitbox02::testing::mock_memory;
use core::convert::TryInto;
use hex_lit::hex;
@@ -39,7 +38,6 @@ mod tests {
#[test]
fn test_hash_data() {
- mock_memory();
let mut mock_hal = TestingHal::new();
mock_hal.memory.set_salt_root(&MOCK_SALT_ROOT);
@@ -52,7 +50,6 @@ mod tests {
#[test]
fn test_hash_data_empty_inputs() {
- mock_memory();
let mut mock_hal = TestingHal::new();
mock_hal.memory.set_salt_root(&MOCK_SALT_ROOT);
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.