Skip to content

Commit

Permalink
Remove Blindsigning for Large tx from settings
Browse files Browse the repository at this point in the history
[tests]Update blindsign_different_modes accordingly
  • Loading branch information
ajinkyaraj-23 committed Sep 30, 2024
1 parent d1f99a0 commit 8eb6afa
Show file tree
Hide file tree
Showing 98 changed files with 162 additions and 271 deletions.
11 changes: 0 additions & 11 deletions app/src/apdu_sign.c
Original file line number Diff line number Diff line change
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
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);
}
19 changes: 5 additions & 14 deletions app/src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ 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)
Expand Down Expand Up @@ -124,9 +118,9 @@ typedef struct {

/* 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 +143,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
2 changes: 1 addition & 1 deletion app/src/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void
blindsign_toggle()
{
FUNC_ENTER();
toggle_blindsign_status();
toggle_blindsigning();
ui_settings_init(SETTINGS_BLINDSIGN_PAGE);
FUNC_LEAVE();
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/ui_stream_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ tz_ui_stream_cb(void)
tz_ui_stream_t *s = &global.stream;
tz_ui_stream_display_t *c = &s->current_screen;

if (N_settings.blindsign_status == ST_BLINDSIGN_ON) {
if (N_settings.blindsigning) {
nbgl_useCaseReviewStreamingContinueExt(
&c->list, tz_transaction_choice, blindsign_skip_callback);
} else {
Expand Down Expand Up @@ -300,7 +300,7 @@ tz_ui_stream_init(void (*cb)(tz_ui_cb_type_t cb_type))
global.blindsign_reason = REASON_NONE;
memset(&global.error_code, '\0', ERROR_CODE_SIZE);
nbgl_operationType_t op_type = TYPE_TRANSACTION;
if (N_settings.blindsign_status == ST_BLINDSIGN_ON) {
if (N_settings.blindsigning) {
op_type |= SKIPPABLE_OPERATION;
}
nbgl_useCaseReviewStreamingStart(op_type, &C_tezos,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
25 changes: 16 additions & 9 deletions tests/integration/touch/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from utils import tezos_app, BlindsigningStatus
from utils import tezos_app

if __name__ == "__main__":
app = tezos_app(__file__)

app.assert_home()
app.remove_settings_and_info()

app.welcome.settings()
app.set_expert_mode(initial_status=False)
app.set_expert_mode(initial_status=True)
app.set_blindsigning_status(BlindsigningStatus.Large_Tx_only)
app.set_blindsigning_status(BlindsigningStatus.ON)
app.set_blindsigning_status(BlindsigningStatus.OFF)
app.assert_settings()

app.settings.toggle_blindsigning()
app.assert_settings(blindsigning=True)

app.settings.toggle_expert_mode()
app.assert_settings(blindsigning=True, expert_mode=True)

app.settings.toggle_blindsigning()
app.assert_settings(expert_mode=True)

app.settings.toggle_expert_mode()
app.assert_settings()

app.welcome.settings()
app.settings.next()
app.settings.next()
app.assert_info()

app.settings.multi_page_exit()
app.settings.exit()
app.assert_home()

app.quit()
Loading

0 comments on commit 8eb6afa

Please sign in to comment.