Skip to content

Commit

Permalink
Expand the displayed info for function calls:
Browse files Browse the repository at this point in the history
- Parse `0x1::aptos_account::transfer_coins` function
- Now show "Transaction Type" for all entry_function calls
- Update gloden snapshots for tests
  • Loading branch information
vldmkr committed Jan 23, 2024
1 parent 0c940c3 commit 405777a
Show file tree
Hide file tree
Showing 65 changed files with 76 additions and 48 deletions.
3 changes: 2 additions & 1 deletion src/bcs/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ typedef struct {
typedef enum {
FUNC_UNKNOWN = 0,
FUNC_APTOS_ACCOUNT_TRANSFER = 1,
FUNC_COIN_TRANSFER = 2
FUNC_COIN_TRANSFER = 2,
FUNC_APTOS_ACCOUNT_TRANSFER_COINS = 3,
} entry_function_known_type_t;

typedef struct {
Expand Down
12 changes: 10 additions & 2 deletions src/transaction/deserialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ parser_status_e entry_function_payload_deserialize(buffer_t *buf, transaction_t
case FUNC_APTOS_ACCOUNT_TRANSFER:
return aptos_account_transfer_function_deserialize(buf, tx);
case FUNC_COIN_TRANSFER:
case FUNC_APTOS_ACCOUNT_TRANSFER_COINS:
return coin_transfer_function_deserialize(buf, tx);
default:
return PARSING_OK;
Expand Down Expand Up @@ -238,7 +239,8 @@ parser_status_e coin_transfer_function_deserialize(buffer_t *buf, transaction_t
return PAYLOAD_UNDEFINED_ERROR;
}
entry_function_payload_t *payload = &tx->payload.entry_function;
if (payload->known_type != FUNC_COIN_TRANSFER) {
if (payload->known_type != FUNC_COIN_TRANSFER &&
payload->known_type != FUNC_APTOS_ACCOUNT_TRANSFER_COINS) {
return PAYLOAD_UNDEFINED_ERROR;
}

Expand All @@ -247,7 +249,7 @@ parser_status_e coin_transfer_function_deserialize(buffer_t *buf, transaction_t
return TYPE_ARGS_SIZE_READ_ERROR;
}
if (payload->args.ty_size != 1) {
return -TYPE_ARGS_SIZE_UNEXPECTED_ERROR;
return TYPE_ARGS_SIZE_UNEXPECTED_ERROR;
}

uint32_t ty_arg_variant = TYPE_TAG_UNDEFINED;
Expand Down Expand Up @@ -344,5 +346,11 @@ entry_function_known_type_t determine_function_type(transaction_t *tx) {
return FUNC_COIN_TRANSFER;
}

if (tx->payload.entry_function.module_id.address[ADDRESS_LEN - 1] == 0x01 &&
bcs_cmp_bytes(&tx->payload.entry_function.module_id.name, "aptos_account", 13) &&
bcs_cmp_bytes(&tx->payload.entry_function.function_name, "transfer_coins", 14)) {
return FUNC_APTOS_ACCOUNT_TRANSFER_COINS;
}

return FUNC_UNKNOWN;
}
28 changes: 16 additions & 12 deletions src/ui/bagl_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ UX_STEP_NOCB(ux_display_tx_type_step,
bnnn_paging,
{
.title = "Transaction Type",
.text = g_struct,
.text = g_tx_type,
});
// Step with title/text for function
UX_STEP_NOCB(ux_display_function_step,
Expand Down Expand Up @@ -292,13 +292,15 @@ UX_FLOW(ux_display_blind_short_message_flow, &ux_display_blind_warn_step, SEQUEN
// FLOW to display entry_function transaction information:
// #1 screen : warning icon + "Blind Signing"
// #2 screen : eye icon + "Review Transaction"
// #3 screen : display function name
// #4 screen : display gas fee
// #5 screen : approve button
// #6 screen : reject button
// #3 screen : display tx type
// #4 screen : display function name
// #5 screen : display gas fee
// #6 screen : approve button
// #7 screen : reject button
UX_FLOW(ux_display_blind_tx_entry_function_flow,
&ux_display_blind_warn_step,
&ux_display_review_step,
&ux_display_tx_type_step,
&ux_display_function_step,
&ux_display_gas_fee_step,
&ux_display_approve_step,
Expand All @@ -325,15 +327,17 @@ UX_FLOW(ux_display_tx_aptos_account_transfer_flow,

// FLOW to display coin_transfer transaction information:
// #1 screen : eye icon + "Review Transaction"
// #2 screen : display function name
// #3 screen : display coin type
// #4 screen : display destination address
// #5 screen : display amount
// #6 screen : display gas fee
// #7 screen : approve button
// #8 screen : reject button
// #2 screen : display tx type
// #3 screen : display function name
// #4 screen : display coin type
// #5 screen : display destination address
// #6 screen : display amount
// #7 screen : display gas fee
// #8 screen : approve button
// #9 screen : reject button
UX_FLOW(ux_display_tx_coin_transfer_flow,
&ux_display_review_step,
&ux_display_tx_type_step,
&ux_display_function_step,
&ux_display_coin_type_step,
&ux_display_receiver_step,
Expand Down
36 changes: 23 additions & 13 deletions src/ui/common_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "../common/user_format.h"

char g_bip32_path[60];
char g_tx_type[60];
char g_address[67];
char g_gas_fee[30];
char g_struct[120];
Expand Down Expand Up @@ -101,27 +102,27 @@ int ui_prepare_transaction() {
case PAYLOAD_ENTRY_FUNCTION:
return ui_display_entry_function();
case PAYLOAD_SCRIPT:
memset(g_struct, 0, sizeof(g_struct));
snprintf(g_struct,
sizeof(g_struct),
memset(g_tx_type, 0, sizeof(g_tx_type));
snprintf(g_tx_type,
sizeof(g_tx_type),
"%s [payload = SCRIPT]",
RAW_TRANSACTION_SALT);
break;
default:
memset(g_struct, 0, sizeof(g_struct));
snprintf(g_struct,
sizeof(g_struct),
memset(g_tx_type, 0, sizeof(g_tx_type));
snprintf(g_tx_type,
sizeof(g_tx_type),
"%s [payload = UNKNOWN]",
RAW_TRANSACTION_SALT);
break;
}
} else if (transaction->tx_variant == TX_RAW_WITH_DATA) {
memset(g_struct, 0, sizeof(g_struct));
snprintf(g_struct, sizeof(g_struct), RAW_TRANSACTION_WITH_DATA_SALT);
memset(g_tx_type, 0, sizeof(g_tx_type));
snprintf(g_tx_type, sizeof(g_tx_type), RAW_TRANSACTION_WITH_DATA_SALT);
}
} else {
memset(g_struct, 0, sizeof(g_struct));
snprintf(g_struct, sizeof(g_struct), "unknown data type");
memset(g_tx_type, 0, sizeof(g_tx_type));
snprintf(g_tx_type, sizeof(g_tx_type), "unknown data type");
}

return UI_PREPARED;
Expand Down Expand Up @@ -154,8 +155,12 @@ int ui_prepare_entry_function() {
case FUNC_APTOS_ACCOUNT_TRANSFER:
return ui_display_tx_aptos_account_transfer();
case FUNC_COIN_TRANSFER:
case FUNC_APTOS_ACCOUNT_TRANSFER_COINS:
return ui_display_tx_coin_transfer();
default:
memset(g_tx_type, 0, sizeof(g_tx_type));
snprintf(g_tx_type, sizeof(g_tx_type), "Function call");
PRINTF("Tx Type: %s\n", g_tx_type);
break;
}

Expand All @@ -167,9 +172,9 @@ int ui_prepare_tx_aptos_account_transfer() {
&G_context.tx_info.transaction.payload.entry_function.args.transfer;

// For well-known functions, display the transaction type in human-readable format
memset(g_struct, 0, sizeof(g_struct));
snprintf(g_struct, sizeof(g_struct), "APT transfer");
PRINTF("Tx Type: %s\n", g_struct);
memset(g_tx_type, 0, sizeof(g_tx_type));
snprintf(g_tx_type, sizeof(g_tx_type), "APT transfer");
PRINTF("Tx Type: %s\n", g_tx_type);

memset(g_address, 0, sizeof(g_address));
if (0 > format_prefixed_hex(transfer->receiver, ADDRESS_LEN, g_address, sizeof(g_address))) {
Expand All @@ -193,6 +198,11 @@ int ui_prepare_tx_coin_transfer() {
&G_context.tx_info.transaction.payload.entry_function.args.coin_transfer;
char transfer_ty_coin_address_hex[67] = {0};

// For well-known functions, display the transaction type in human-readable format
memset(g_tx_type, 0, sizeof(g_tx_type));
snprintf(g_tx_type, sizeof(g_tx_type), "Coin transfer");
PRINTF("Tx Type: %s\n", g_tx_type);

// Be sure to display at least 1 byte, even if it is zero
size_t leading_zeros = count_leading_zeros(transfer->ty_coin.address, ADDRESS_LEN - 1);
if (0 > format_prefixed_hex(transfer->ty_coin.address + leading_zeros,
Expand Down
1 change: 1 addition & 0 deletions src/ui/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define UI_PREPARED -10

extern char g_bip32_path[60];
extern char g_tx_type[60];
extern char g_address[67];
extern char g_gas_fee[30];
extern char g_struct[120];
Expand Down
2 changes: 1 addition & 1 deletion src/ui/nbgl_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

static use_case_review_ctx_t blind_sign_ctx;

nbgl_layoutTagValue_t pairs[5];
nbgl_layoutTagValue_t pairs[6];
nbgl_layoutTagValueList_t pairList;
nbgl_pageInfoLongPress_t infoLongPress;

Expand Down
2 changes: 1 addition & 1 deletion src/ui/nbgl_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "nbgl_use_case.h"

extern nbgl_layoutTagValue_t pairs[5];
extern nbgl_layoutTagValue_t pairs[6];
extern nbgl_layoutTagValueList_t pairList;
extern nbgl_pageInfoLongPress_t infoLongPress;

Expand Down
40 changes: 22 additions & 18 deletions src/ui/nbgl_display_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void review_choice(bool confirm) {

static void review_default_continue(void) {
pairs[0].item = "Transaction Type";
pairs[0].value = g_struct;
pairs[0].value = g_tx_type;
pairs[1].item = "Gas Fee";
pairs[1].value = g_gas_fee;

Expand All @@ -71,13 +71,15 @@ static void review_default_continue(void) {
}

static void review_entry_function_continue(void) {
pairs[0].item = "Function";
pairs[0].value = g_function;
pairs[1].item = "Gas Fee";
pairs[1].value = g_gas_fee;
pairs[0].item = "Transaction Type";
pairs[0].value = g_tx_type;
pairs[1].item = "Function";
pairs[1].value = g_function;
pairs[2].item = "Gas Fee";
pairs[2].value = g_gas_fee;

pairList.nbMaxLinesForValue = 0;
pairList.nbPairs = 2;
pairList.nbPairs = 3;
pairList.pairs = pairs;

infoLongPress.icon = &C_aptos_logo_64px;
Expand All @@ -89,7 +91,7 @@ static void review_entry_function_continue(void) {

static void review_tx_aptos_account_transfer_continue(void) {
pairs[0].item = "Transaction Type";
pairs[0].value = g_struct;
pairs[0].value = g_tx_type;
pairs[1].item = "Function";
pairs[1].value = g_function;
pairs[2].item = "Receiver";
Expand All @@ -111,19 +113,21 @@ static void review_tx_aptos_account_transfer_continue(void) {
}

static void review_tx_coin_transfer_continue(void) {
pairs[0].item = "Function";
pairs[0].value = g_function;
pairs[1].item = "Coin Type";
pairs[1].value = g_struct;
pairs[2].item = "Receiver";
pairs[2].value = g_address;
pairs[3].item = "Amount";
pairs[3].value = g_amount;
pairs[4].item = "Gas Fee";
pairs[4].value = g_gas_fee;
pairs[0].item = "Transaction Type";
pairs[0].value = g_tx_type;
pairs[1].item = "Function";
pairs[1].value = g_function;
pairs[2].item = "Coin Type";
pairs[2].value = g_struct;
pairs[3].item = "Receiver";
pairs[3].value = g_address;
pairs[4].item = "Amount";
pairs[4].value = g_amount;
pairs[5].item = "Gas Fee";
pairs[5].value = g_gas_fee;

pairList.nbMaxLinesForValue = 0;
pairList.nbPairs = 5;
pairList.nbPairs = 6;
pairList.pairs = pairs;

infoLongPress.icon = &C_aptos_logo_64px;
Expand Down
Binary file modified tests/snapshots/nanos/test_blind_sign_tx_long_tx/part1/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_blind_sign_tx_long_tx/part1/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_blind_sign_tx_long_tx/part1/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_blind_sign_tx_long_tx/part1/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_blind_sign_tx_long_tx/part1/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_blind_sign_tx_long_tx/part1/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_blind_sign_tx_long_tx/part1/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_blind_sign_tx_long_tx/part1/00008.png
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 modified tests/snapshots/nanos/test_sign_tx_short_tx/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_sign_tx_short_tx/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_sign_tx_short_tx/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_sign_tx_short_tx/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_sign_tx_short_tx/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_sign_tx_short_tx/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_sign_tx_short_tx/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_sign_tx_short_tx/00008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_sign_tx_short_tx/00009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_sign_tx_short_tx/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanos/test_sign_tx_short_tx/00011.png
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 modified tests/snapshots/nanosp/test_blind_sign_tx_long_tx/part1/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanosp/test_blind_sign_tx_long_tx/part1/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanosp/test_blind_sign_tx_long_tx/part1/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanosp/test_blind_sign_tx_long_tx/part1/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/snapshots/nanosp/test_blind_sign_tx_long_tx/part1/00005.png
Binary file modified tests/snapshots/nanosp/test_sign_tx_short_tx/00001.png
Binary file modified tests/snapshots/nanosp/test_sign_tx_short_tx/00002.png
Binary file modified tests/snapshots/nanosp/test_sign_tx_short_tx/00003.png
Binary file modified tests/snapshots/nanosp/test_sign_tx_short_tx/00004.png
Binary file modified tests/snapshots/nanosp/test_sign_tx_short_tx/00005.png
Binary file modified tests/snapshots/nanosp/test_sign_tx_short_tx/00006.png
Binary file modified tests/snapshots/nanosp/test_sign_tx_short_tx/00007.png
Binary file modified tests/snapshots/nanosp/test_sign_tx_short_tx/00008.png
Binary file modified tests/snapshots/nanox/test_blind_sign_tx_long_tx/part1/00001.png
Binary file modified tests/snapshots/nanox/test_blind_sign_tx_long_tx/part1/00002.png
Binary file modified tests/snapshots/nanox/test_blind_sign_tx_long_tx/part1/00003.png
Binary file modified tests/snapshots/nanox/test_blind_sign_tx_long_tx/part1/00004.png
Binary file modified tests/snapshots/nanox/test_blind_sign_tx_long_tx/part1/00005.png
Binary file modified tests/snapshots/nanox/test_sign_tx_short_tx/00001.png
Binary file modified tests/snapshots/nanox/test_sign_tx_short_tx/00002.png
Binary file modified tests/snapshots/nanox/test_sign_tx_short_tx/00003.png
Binary file modified tests/snapshots/nanox/test_sign_tx_short_tx/00004.png
Binary file modified tests/snapshots/nanox/test_sign_tx_short_tx/00005.png
Binary file modified tests/snapshots/nanox/test_sign_tx_short_tx/00006.png
Binary file modified tests/snapshots/nanox/test_sign_tx_short_tx/00007.png
Binary file modified tests/snapshots/nanox/test_sign_tx_short_tx/00008.png
Binary file modified tests/snapshots/stax/test_blind_sign_tx_long_tx/part1/00002.png
Binary file modified tests/snapshots/stax/test_blind_sign_tx_long_tx/part1/00003.png
Binary file modified tests/snapshots/stax/test_blind_sign_tx_long_tx/part1/00004.png
Binary file modified tests/snapshots/stax/test_blind_sign_tx_long_tx/part1/00005.png
Binary file modified tests/snapshots/stax/test_sign_tx_short_tx/00001.png

0 comments on commit 405777a

Please sign in to comment.