Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stax-remove-bs-large-tx #296

Merged
merged 7 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
49 changes: 6 additions & 43 deletions app/src/apdu_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ static void handle_data_apdu_blind(void);
static void pass_from_clear_to_summary(void);
#ifdef HAVE_BAGL
static void init_too_many_screens_stream(void);
static void init_blind_warning_stream(void);
#endif
#ifdef HAVE_NBGL
static void continue_blindsign_cb(void);
Expand All @@ -89,7 +88,9 @@ static void init_summary_stream(void);
#define APDU_SIGN_ASSERT_STEP(x) \
APDU_SIGN_ASSERT(global.keys.apdu.sign.step == (x))

#ifdef HAVE_BAGL
#define SCREEN_DISPLAYED global.keys.apdu.sign.u.clear.screen_displayed
#endif

#ifdef HAVE_BAGL
void
Expand Down Expand Up @@ -237,9 +238,8 @@ refill_blo_im_full(void)

global.keys.apdu.sign.step = SIGN_ST_WAIT_USER_INPUT;
#ifdef HAVE_BAGL
if ((N_settings.blindsign_status != ST_BLINDSIGN_OFF)
if (N_settings.blindsigning
&& (SCREEN_DISPLAYED >= NB_MAX_SCREEN_ALLOWED)) {
global.blindsign_reason = REASON_TOO_MANY_SCREENS;
pass_from_clear_to_summary();
TZ_SUCCEED();
}
Expand Down Expand Up @@ -273,17 +273,6 @@ refill_blo_im_full(void)
#elif HAVE_NBGL
PRINTF("[DEBUG] field=%s complex=%d\n", st->field_info.field_name,
st->field_info.is_field_complex);
if ((N_settings.blindsign_status != ST_BLINDSIGN_OFF)
&& (SCREEN_DISPLAYED >= NB_MAX_SCREEN_ALLOWED)) {
strncpy(global.error_code, "TOO_MANY_SCREENS", ERROR_CODE_SIZE);
tz_ui_stream_push_all(TZ_UI_STREAM_CB_CANCEL,
st->field_info.field_name, "TOO_MANY_SCREENS",
TZ_UI_LAYOUT_BN, TZ_UI_ICON_NONE);

global.blindsign_reason = REASON_TOO_MANY_SCREENS;

TZ_SUCCEED();
}
if (st->field_info.is_field_complex
&& !global.keys.apdu.sign.u.clear.displayed_expert_warning) {
global.keys.apdu.sign.u.clear.last_field_index
Expand Down Expand Up @@ -334,11 +323,7 @@ refill_blo_done(void)

#ifdef HAVE_BAGL
if (global.step == ST_SUMMARY_SIGN) {
if (global.blindsign_reason == REASON_TOO_MANY_SCREENS) {
init_too_many_screens_stream();
} else {
init_blind_warning_stream();
}
init_too_many_screens_stream();
TZ_SUCCEED();
}
tz_ui_stream_push_accept_reject();
Expand Down Expand Up @@ -540,7 +525,9 @@ stream_cb(tz_ui_cb_type_t cb_type)
case TZ_UI_STREAM_CB_BLINDSIGN_REJECT: send_reject(EXC_PARSE_ERROR); break;
case TZ_UI_STREAM_CB_CANCEL: TZ_CHECK(send_cancel()); break;
case TZ_UI_STREAM_CB_BLINDSIGN: TZ_CHECK(pass_from_clear_to_blind()); break;
#ifdef HAVE_NBGL
case TZ_UI_STREAM_CB_SUMMARY: TZ_CHECK(pass_from_clear_to_summary()); break;
#endif
default: TZ_FAIL(EXC_UNKNOWN); break;
}
// clang-format on
Expand Down Expand Up @@ -686,20 +673,6 @@ init_too_many_screens_stream(void)
tz_ui_stream();
}

static void
init_blind_warning_stream(void)
{
tz_ui_stream_init(pass_to_summary_stream_cb);

tz_ui_stream_push_warning_not_trusted(NULL, NULL);
tz_ui_stream_push_risky_accept_reject(TZ_UI_STREAM_CB_VALIDATE,
TZ_UI_STREAM_CB_REJECT);

tz_ui_stream_close();

tz_ui_stream();
}

static void
bs_push_next(void)
{
Expand Down Expand Up @@ -814,16 +787,6 @@ handle_first_apdu_clear(__attribute__((unused)) command_t *cmd)
tz_ui_stream_push(TZ_UI_STREAM_CB_NOCB, "Review", "operation",
TZ_UI_LAYOUT_HOME_PB, TZ_UI_ICON_EYE);
#endif
if (N_settings.blindsign_status == ST_BLINDSIGN_ON) {
#ifdef TARGET_NANOS
tz_ui_stream_push(TZ_UI_STREAM_CB_SUMMARY, "Blindsign?", "",
TZ_UI_LAYOUT_HOME_PB, TZ_UI_ICON_WARNING);
#else
tz_ui_stream_push(TZ_UI_STREAM_CB_SUMMARY, "Switch to",
"blindsign?", TZ_UI_LAYOUT_HOME_PB,
TZ_UI_ICON_WARNING);
#endif
}
#endif
#ifdef HAVE_SWAP
} else {
Expand Down
8 changes: 5 additions & 3 deletions app/src/apdu_sign.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ typedef struct {
tz_parser_state parser_state;
size_t total_length;
uint8_t last_field_index;
uint8_t screen_displayed;
bool received_msg;
bool displayed_expert_warning;
#ifdef HAVE_BAGL
uint8_t screen_displayed;
#endif
bool received_msg;
bool displayed_expert_warning;
} clear;
/// @brief blindsigning state info.
struct {
Expand Down
11 changes: 2 additions & 9 deletions app/src/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ toggle_expert_mode(void)
}

void
set_blindsign_status(blindsign_state_t status)
toggle_blindsigning(void)
{
settings_t tmp;
memcpy(&tmp, (void *)&N_settings, sizeof(tmp));
tmp.blindsign_status = status;
tmp.blindsigning = !N_settings.blindsigning;
nvm_write((void *)&N_settings, (void *)&tmp, sizeof(N_settings));
}

void
toggle_blindsign_status(void)
{
blindsign_state_t status = (N_settings.blindsign_status + 1) % 3;
set_blindsign_status(status);
}
32 changes: 11 additions & 21 deletions app/src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,18 @@ typedef enum {
ST_ERROR /// In error state.
} main_step_t;

typedef enum {
ST_BLINDSIGN_LARGE_TX = 0,
ST_BLINDSIGN_ON = 1,
ST_BLINDSIGN_OFF = 2
} blindsign_state_t;

#ifdef TARGET_NANOS
#define NB_MAX_SCREEN_ALLOWED 20
#elif defined(HAVE_BAGL)
#define NB_MAX_SCREEN_ALLOWED 12
#else
#define NB_MAX_SCREEN_ALLOWED 8
#endif

#ifdef HAVE_NBGL
typedef enum {
REASON_NONE = 0,
REASON_PARSING_ERROR = 1,
REASON_TOO_MANY_SCREENS = 2
REASON_NONE = 0,
REASON_PARSING_ERROR = 1
} blindsign_reason_t;
#endif

/**
* @brief Global structure holding state of operations and buffer of the data
Expand Down Expand Up @@ -114,19 +107,19 @@ typedef struct {
/// "ON" , "OFF"
#endif

blindsign_reason_t
blindsign_reason; /// Blindsigning flow Summary or parsing error.
#ifdef HAVE_NBGL
blindsign_reason_t
blindsign_reason; /// Blindsigning flow Summary or parsing error.
char error_code[ERROR_CODE_SIZE]; /// Error code for parsing error.
#endif
main_step_t step; /// Current operational state of app.
} globals_t;

/* Settings */
typedef struct {
bool expert_mode; /// enable expert mode
blindsign_state_t blindsign_status; /// Blindsign status
} settings_t; /// Special settings available in the app.
bool expert_mode; /// enable expert mode
bool blindsigning; /// Blindsign status
} settings_t; /// Special settings available in the app.

extern globals_t global;

Expand All @@ -149,9 +142,6 @@ void init_globals(void);
/// Toggles the persisted expert_mode setting
void toggle_expert_mode(void);

/// Toggles the persisted blindsign setting between "For large tx", "ON",
/// Toggles the persisted blindsign setting between "ON",
/// "OFF".
void toggle_blindsign_status(void);

/// set the blindsign setting between "For large tx", "ON", "OFF".
void set_blindsign_status(blindsign_state_t status);
void toggle_blindsigning(void);
116 changes: 48 additions & 68 deletions app/src/ui_home_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,115 +28,95 @@
#include "globals.h"
#include "nbgl_use_case.h"

static void controls_callback(int token,
__attribute__((unused)) uint8_t index,
__attribute__((unused)) int page);
void tz_ui_home_redisplay(uint8_t page);
void tz_ui_home_redisplay(void);

// -----------------------------------------------------------
// --------------------- SETTINGS MENU -----------------------
// -----------------------------------------------------------
#define SETTING_INFO_NB 3
#define SETTINGS_SWITCHES_NB 1
#define SETTINGS_RADIO_NB 3
#define SETTING_INFO_NB 3

static const char *const infoTypes[] = {"Version", "Developer", "Contact"};
static const char *const infoContents[] = {
APPVERSION, "Trilitech Kanvas Limited et al.", "[email protected]"};

enum {
EXPERT_MODE_TOKEN = FIRST_USER_TOKEN,
BLINDSIGN_MODE_TOKEN
BLIND_SIGNING_TOKEN
};
enum {
EXPERT_MODE_TOKEN_ID = 0,
BLINDSIGN_MODE_TOKEN_ID,
SETTINGS_CONTENTS_NB
};
enum {
EXPERT_MODE_PAGE = 0,
BLINDSIGN_PAGE = 1
BLIND_SIGNING_TOKEN_ID,
SETTINGS_SWITCHES_NB
};

static nbgl_contentSwitch_t expert_mode_switch = {0};
static nbgl_layoutSwitch_t switches[SETTINGS_SWITCHES_NB] = {0};

static const nbgl_contentInfoList_t infoList = {.nbInfos = SETTING_INFO_NB,
.infoTypes = infoTypes,
.infoContents = infoContents};

static const char *const blindsign_choices_text[]
= {"Blindsign For Large Tx", "Blindsigning ON", "Blindsigning OFF"};

static void
get_contents(uint8_t index, nbgl_content_t *content)
{
FUNC_ENTER(("Index: %d", index));
if (index == EXPERT_MODE_TOKEN_ID) {
content->content.switchesList.nbSwitches = SETTINGS_SWITCHES_NB;
content->content.switchesList.switches = &expert_mode_switch;
content->type = SWITCHES_LIST;
content->contentActionCallback = controls_callback;
} else {
content->content.choicesList.nbChoices = SETTINGS_RADIO_NB;
content->content.choicesList.names = blindsign_choices_text;
content->content.choicesList.token = BLINDSIGN_MODE_TOKEN;
content->content.choicesList.initChoice = N_settings.blindsign_status;
content->type = CHOICES_LIST;
content->contentActionCallback = controls_callback;
}
FUNC_LEAVE();
}

static void
controls_callback(int token, __attribute__((unused)) uint8_t index,
__attribute__((unused)) int page)
{
FUNC_ENTER(("Token : %d, Index: %d, Page: %d", token, index, page));
uint8_t switch_value;
if (token == EXPERT_MODE_TOKEN) {
if (token == BLIND_SIGNING_TOKEN) {
switch_value = !N_settings.blindsigning;
toggle_blindsigning();
switches[BLIND_SIGNING_TOKEN_ID].initState
= (nbgl_state_t)(switch_value);
} else if (token == EXPERT_MODE_TOKEN) {
switch_value = !N_settings.expert_mode;
toggle_expert_mode();
expert_mode_switch.initState = (nbgl_state_t)(switch_value);
}
if (token == BLINDSIGN_MODE_TOKEN) {
blindsign_state_t blindsign_status = (blindsign_state_t)(index % 3);
set_blindsign_status(blindsign_status);
tz_ui_home_redisplay(BLINDSIGN_PAGE);
switches[EXPERT_MODE_TOKEN_ID].initState
= (nbgl_state_t)(switch_value);
}
FUNC_LEAVE();
}

#define HOME_TEXT "This app enables signing transactions on the Tezos Network"
#define SETTINGS_CONTENTS_NB 1
static const nbgl_content_t contentsList[SETTINGS_CONTENTS_NB] = {
{.content.switchesList.nbSwitches = SETTINGS_SWITCHES_NB,
.content.switchesList.switches = switches,
.type = SWITCHES_LIST,
.contentActionCallback = controls_callback}
};

static const nbgl_genericContents_t tezos_settingContents
= {.callbackCallNeeded = false,
.contentsList = contentsList,
.nbContents = SETTINGS_CONTENTS_NB};
;

#define HOME_TEXT "This app enables signing transactions on the Tezos Network"
void
initSettings(void)
{
expert_mode_switch.initState = (nbgl_state_t)(N_settings.expert_mode);
expert_mode_switch.text = "Expert mode";
expert_mode_switch.subText = "Enable expert mode signing";
expert_mode_switch.token = EXPERT_MODE_TOKEN;
expert_mode_switch.tuneId = TUNE_TAP_CASUAL;
switches[EXPERT_MODE_TOKEN_ID].initState
= (nbgl_state_t)(N_settings.expert_mode);
switches[EXPERT_MODE_TOKEN_ID].text = "Expert mode";
switches[EXPERT_MODE_TOKEN_ID].subText = "Enable expert mode signing";
switches[EXPERT_MODE_TOKEN_ID].token = EXPERT_MODE_TOKEN;
switches[EXPERT_MODE_TOKEN_ID].tuneId = TUNE_TAP_CASUAL;

switches[BLIND_SIGNING_TOKEN_ID].initState
= (nbgl_state_t)(N_settings.blindsigning);
switches[BLIND_SIGNING_TOKEN_ID].text = "Blind signing";
switches[BLIND_SIGNING_TOKEN_ID].subText
= "Enable transaction blind signing";
switches[BLIND_SIGNING_TOKEN_ID].token = BLIND_SIGNING_TOKEN;
switches[BLIND_SIGNING_TOKEN_ID].tuneId = TUNE_TAP_CASUAL;
}

void
tz_ui_home_redisplay(uint8_t page)
tz_ui_home_redisplay(void)
{
FUNC_ENTER(("void"));

initSettings();
static nbgl_genericContents_t tezos_settingContents = {0};
tezos_settingContents.callbackCallNeeded = false;
tezos_settingContents.nbContents = SETTINGS_CONTENTS_NB;

static nbgl_content_t contents[SETTINGS_CONTENTS_NB] = {0};
get_contents(EXPERT_MODE_TOKEN_ID, &contents[EXPERT_MODE_TOKEN_ID]);
get_contents(BLINDSIGN_MODE_TOKEN_ID, &contents[BLINDSIGN_MODE_TOKEN_ID]);

tezos_settingContents.contentsList = contents;

PRINTF("Entered settings and initialized\n");

nbgl_useCaseHomeAndSettings("Tezos Wallet", &C_tezos, HOME_TEXT, page,
&tezos_settingContents, &infoList, NULL,
app_exit);
nbgl_useCaseHomeAndSettings("Tezos Wallet", &C_tezos, HOME_TEXT,
INIT_HOME_PAGE, &tezos_settingContents,
&infoList, NULL, app_exit);

FUNC_LEAVE();
}
Expand Down
Loading
Loading