Skip to content

Commit

Permalink
UI: do not update all screens data
Browse files Browse the repository at this point in the history
Update only screen potentially changed
  • Loading branch information
spalmer25 committed Apr 5, 2024
1 parent 7f21e81 commit 6e10118
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/apdu_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int handle_deauthorize(void) {
UPDATE_NVRAM(ram, { memset(&ram->baking_key, 0, sizeof(ram->baking_key)); });
#ifdef HAVE_BAGL
// Ignore calculation errors
calculate_baking_idle_screens_data();
calculate_idle_screen_authorized_key();
refresh_screens();
#endif // HAVE_BAGL

Expand Down
2 changes: 1 addition & 1 deletion src/apdu_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static int baking_sign_complete(bool const send_hash) {
result = perform_signature(send_hash);
#ifdef HAVE_BAGL
// Ignore calculation errors
calculate_baking_idle_screens_data();
calculate_idle_screen_hwm();
// The HWM screen is not updated to avoid slowing down the
// application. Updating the HWM screen may slow down the
// next signing.
Expand Down
25 changes: 23 additions & 2 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,33 @@ void __attribute__((noreturn)) app_exit(void);

#ifdef HAVE_BAGL

/**
* @brief Calculates the chain id for the idle screens
*
* @return tz_exc: exception, SW_OK if none
*/
tz_exc calculate_idle_screen_chain_id(void);

/**
* @brief Calculates the authorized key for the idle screens
*
* @return tz_exc: exception, SW_OK if none
*/
tz_exc calculate_idle_screen_authorized_key(void);

/**
* @brief Calculates the HWM for the idle screens
*
* @return tz_exc: exception, SW_OK if none
*/
tz_exc calculate_idle_screen_hwm(void);

/**
* @brief Calculates baking values for the idle screens
*
* @return bool: whether the values have been calculated successfully or not
* @return tz_exc: exception, SW_OK if none
*/
bool calculate_baking_idle_screens_data(void);
tz_exc calculate_baking_idle_screens_data(void);

/**
* @brief Prepare confirmation screens callbacks
Expand Down
50 changes: 42 additions & 8 deletions src/ui_bagl.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,25 @@ UX_FLOW(ux_idle_flow,
&ux_idle_quit_step,
FLOW_LOOP);

bool calculate_baking_idle_screens_data(void) {
tz_exc calculate_idle_screen_chain_id(void) {
tz_exc exc = SW_OK;

memset(&home_context, 0, sizeof(home_context));
memset(&home_context.chain_id, 0, sizeof(home_context.chain_id));

TZ_ASSERT(chain_id_to_string_with_aliases(home_context.chain_id,
sizeof(home_context.chain_id),
&N_data.main_chain_id) >= 0,
EXC_WRONG_LENGTH);

end:
return exc;
}

tz_exc calculate_idle_screen_authorized_key(void) {
tz_exc exc = SW_OK;

memset(&home_context.authorized_key, 0, sizeof(home_context.authorized_key));

if (N_data.baking_key.bip32_path.length == 0u) {
TZ_ASSERT(copy_string(home_context.authorized_key,
sizeof(home_context.authorized_key),
Expand All @@ -99,25 +108,50 @@ bool calculate_baking_idle_screens_data(void) {
&N_data.baking_key));
}

end:
return exc;
}

tz_exc calculate_idle_screen_hwm(void) {
tz_exc exc = SW_OK;

memset(&home_context.hwm, 0, sizeof(home_context.hwm));

TZ_ASSERT(hwm_to_string(home_context.hwm, sizeof(home_context.hwm), &N_data.hwm.main) >= 0,
EXC_WRONG_LENGTH);

return true;
end:
return exc;
}

tz_exc calculate_baking_idle_screens_data(void) {
tz_exc exc = SW_OK;

TZ_CHECK(calculate_idle_screen_chain_id());

TZ_CHECK(calculate_idle_screen_authorized_key());

TZ_CHECK(calculate_idle_screen_hwm());

end:
TZ_EXC_PRINT(exc);
return false;
return exc;
}

void ui_initial_screen(void) {
tz_exc exc = SW_OK;

// reserve a display stack slot if none yet
if (G_ux.stack_count == 0) {
ux_stack_push();
}

if (calculate_baking_idle_screens_data()) {
ux_flow_init(0, ux_idle_flow, NULL);
}
TZ_CHECK(calculate_baking_idle_screens_data());

ux_flow_init(0, ux_idle_flow, NULL);

return;
end:
TZ_EXC_PRINT(exc);
}

void ux_prepare_confirm_callbacks(ui_callback_t ok_c, ui_callback_t cxl_c) {
Expand Down

0 comments on commit 6e10118

Please sign in to comment.