Skip to content

Commit

Permalink
fix(core): Update factory reset condition to ignore write attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
amanCypherock committed Dec 27, 2023
1 parent 7d8bd84 commit 68bae40
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
23 changes: 23 additions & 0 deletions common/interfaces/flash_interface/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,29 @@ bool wallet_is_filled(uint8_t index, wallet_state *state_output) {
return false;
}

bool wallet_is_filled_with_share(uint8_t index) {
if (MAX_WALLETS_ALLOWED <= index) {
return false;
}

/* Make sure that we always work on the latest RAM instance */
get_flash_ram_instance();

wallet_state state = flash_ram_instance.wallets[index].state;
// Read card states without write attempt state
uint8_t cards_states = flash_ram_instance.wallets[index].cards_states & 0x0F;

// If wallet state state is where share is present on device and card state is
// not zero, then wallet is filled
if (((UNVERIFIED_VALID_WALLET == state) || (VALID_WALLET == state) ||
(INVALID_WALLET == state)) &&
(0x00 != cards_states)) {
return true;
}

return false;
}

/**
* @brief Save a new wallet on the flash
*
Expand Down
11 changes: 11 additions & 0 deletions common/interfaces/flash_interface/flash_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
*/
bool wallet_is_filled(uint8_t index, wallet_state *state_output);

/**
* @brief The function checks if a wallet is filled with a share based on its
* index.
*
* @param index The index required to be checked for wallet existance
*
* @return a boolean value. It returns true if the wallet at the given index is
* filled with a share, and false otherwise.
*/
bool wallet_is_filled_with_share(uint8_t index);

/**
* Update auth state and first_boot_on_update variables in firewall
*/
Expand Down
4 changes: 1 addition & 3 deletions src/wallet/wallet_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ uint8_t get_filled_wallet_meta_data_list(wallet_list_t *list) {
}

for (uint8_t wallet_idx = 0; wallet_idx < MAX_WALLETS_ALLOWED; wallet_idx++) {
wallet_state state = INVALID_WALLET;
if (!wallet_is_filled(wallet_idx, &state) ||
VALID_WALLET_WITHOUT_DEVICE_SHARE == state) {
if (!wallet_is_filled_with_share(wallet_idx)) {
continue;
}

Expand Down

0 comments on commit 68bae40

Please sign in to comment.