Skip to content

Commit

Permalink
Merge pull request cosmos#151 from cosmos/dev
Browse files Browse the repository at this point in the history
Coins check (cosmos#150)
  • Loading branch information
chcmedeiros authored Feb 3, 2025
2 parents c9c4d9b + 21e2cb3 commit 631098f
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=2
# This is the `spec_version` field of `Runtime`
APPVERSION_N=36
# This is the patch version of this release
APPVERSION_P=6
APPVERSION_P=7
1 change: 1 addition & 0 deletions app/src/common/parser_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ typedef enum {
parser_swap_wrong_dest_address,
parser_swap_wrong_amount,
parser_swap_wrong_dest_coins,
parser_swap_wrong_source_coins,
parser_swap_wrong_memo,
parser_swap_wrong_fee,
parser_swap_unexpected_number_of_items,
Expand Down
2 changes: 2 additions & 0 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ const char *parser_getErrorDescription(parser_error_t err) {
return "Swap wrong type";
case parser_swap_memo_not_present:
return "Swap memo not present";
case parser_swap_wrong_source_coins:
return "Swap wrong source coins";

default:
return "Unrecognized error code";
Expand Down
24 changes: 16 additions & 8 deletions app/src/swap/handle_sign_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,29 @@ parser_error_t parser_simple_transfer(parser_context_t *ctx_parsed_tx, uint8_t d
return parser_swap_unexpected_field;
}

// Check source coins are equal to the amount and equal to destination coins
char tmp_amount[100] = {0};
zxerr_t zxerr = bytesAmountToStringBalance(G_swap_state.amount, G_swap_state.amount_length, tmp_amount, sizeof(tmp_amount));
if (zxerr != zxerr_ok) {
return parser_swap_wrap_amount_computation_error;
}

displayIdx += 1;
CHECK_PARSER_ERR(parser_getItem(ctx_parsed_tx, displayIdx, tmpKey, sizeof(tmpKey), tmpValue, sizeof(tmpValue), pageIdx, &pageCount))
if (strcmp(tmpKey, "Source Coins") != 0 || strcmp(tmpValue, tmp_amount) != 0) {
ZEMU_LOGF(200, "Wrong swap tx source coins ('%s', should be : '%s').\n", tmpValue, tmpKey);
return parser_swap_wrong_source_coins;
}

// Check destination address
displayIdx += 2;
displayIdx += 1;
CHECK_PARSER_ERR(parser_getItem(ctx_parsed_tx, displayIdx, tmpKey, sizeof(tmpKey), tmpValue, sizeof(tmpValue), pageIdx, &pageCount))
if (strcmp(tmpKey, "Dest Address") != 0 || strcmp(tmpValue, G_swap_state.destination_address) != 0) {
ZEMU_LOGF(200, "Wrong swap tx destination address ('%s', should be : '%s').\n", tmpValue, G_swap_state.destination_address);
return parser_swap_wrong_dest_address;
}

// Check destination coins
char tmp_amount[100] = {0};
zxerr_t zxerr = bytesAmountToStringBalance(G_swap_state.amount, G_swap_state.amount_length, tmp_amount, sizeof(tmp_amount));
if (zxerr != zxerr_ok) {
return parser_swap_wrap_amount_computation_error;
}

// Check destination coins
displayIdx += 1;
CHECK_PARSER_ERR(parser_getItem(ctx_parsed_tx, displayIdx, tmpKey, sizeof(tmpKey), tmpValue, sizeof(tmpValue), pageIdx, &pageCount))
if (strcmp(tmpKey, "Dest Coins") != 0 || strcmp(tmp_amount, tmpValue) != 0) {
Expand Down
Binary file modified tests_zemu/snapshots/fl-mainmenu/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_zemu/snapshots/s-mainmenu/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_zemu/snapshots/s-mainmenu/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_zemu/snapshots/sp-mainmenu/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_zemu/snapshots/sp-mainmenu/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_zemu/snapshots/st-mainmenu/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_zemu/snapshots/x-mainmenu/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_zemu/snapshots/x-mainmenu/00010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 631098f

Please sign in to comment.