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

Feat/adapt display to match klaytn tx #31

Merged
merged 10 commits into from
Apr 19, 2024
Merged
9 changes: 5 additions & 4 deletions src/helper/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
* limitations under the License.
*****************************************************************************/

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h> // bool
#include <stddef.h> // size_t
#include <stdint.h> // uint*_t
#include <string.h> // memcpy
#include <stdio.h> // snprintf

#include "format.h"
#include "../transaction/types.h"
Expand Down
73 changes: 66 additions & 7 deletions src/transaction/deserialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,41 @@ static bool processTxCancel(parser_context_t *parser_ctx) {
return error;
}

static bool processTxLegacy(parser_context_t *parser_ctx) {
bool error = false;
switch (parser_ctx->currentField) {
case LEGACY_RLP_NONCE:
error = processNonce(parser_ctx);
break;
case LEGACY_RLP_GASPRICE:
error = processGasprice(parser_ctx);
break;
case LEGACY_RLP_STARTGAS:
error = processGasLimit(parser_ctx);
break;
case LEGACY_RLP_TO:
error = processTo(parser_ctx);
break;
case LEGACY_RLP_VALUE:
error = processValue(parser_ctx);
break;
case LEGACY_RLP_DATA:
error = processData(parser_ctx);
break;
case LEGACY_RLP_CHAIN_ID:
error = processChainID(parser_ctx);
break;
case LEGACY_RLP_ZERO1:
case LEGACY_RLP_ZERO2:
error = processAndDiscard(parser_ctx);
break;
default:
PRINTF("Invalid RLP decoder parser_ctx\n");
return true;
}
return error;

}
// Actual transaction parsing

parser_status_e transaction_deserialize(buffer_t *buf, transaction_t *tx) {
Expand Down Expand Up @@ -506,6 +541,22 @@ parser_status_e transaction_deserialize(buffer_t *buf, transaction_t *tx) {
}
if (parser_ctx.outerRLP && !parser_ctx.processingOuterRLPField) {
parseNestedRlp(&parser_ctx);
// Hack to detect the tx type
// If the last field parsed was a fieldSingleByte it means the transaction is a Legacy transaction
if(parser_ctx.fieldSingleByte){
parser_ctx.tx->txType = LEGACY;
} else {
// The bype after the nested rlp is the tx type,
parseRLP(&parser_ctx);
parser_ctx.tx->txType = parser_ctx.workBuffer[0];
//Cancel changes made by last parseRLP
parser_ctx.workBuffer--;
parser_ctx.commandLength++;
parser_ctx.processingField = false;
}
PRINTF("Transaction type: %d\n", parser_ctx.tx->txType);


continue;
}
if (!parser_ctx.processingField) {
Expand All @@ -516,21 +567,29 @@ parser_status_e transaction_deserialize(buffer_t *buf, transaction_t *tx) {
}

PRINTF("Current field: %d\n", parser_ctx.currentField);
// switch (parser_ctx.tx->txType) {
switch (parser_ctx.tx->txType) {
bool fault;
// case CANCEL:
case LEGACY:
fault = processTxLegacy(&parser_ctx);
if (fault) {
return PARSING_ERROR;
} else {
break;
}
case CANCEL:
// case FEE_DELEGATED_CANCEL:
// case PARTIAL_FEE_DELEGATED_CANCEL:
fault = processTxCancel(&parser_ctx);
if (fault) {
return PARSING_ERROR;
} else {
// break;
break;
}
// default:
// PRINTF("Transaction type %d is not supported\n", parser_ctx.tx->txType);
// return PARSING_ERROR;
// }
default:
PRINTF("Transaction type %d is not supported\n", parser_ctx.tx->txType);
return PARSING_ERROR;
}

}
}

Expand Down
2 changes: 0 additions & 2 deletions src/transaction/deserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/
typedef enum {
LEGACY_RLP_NONE = RLP_NONE,
LEGACY_RLP_CONTENT,
LEGACY_RLP_TYPE,
LEGACY_RLP_NONCE,
LEGACY_RLP_GASPRICE,
LEGACY_RLP_STARTGAS,
Expand Down
2 changes: 1 addition & 1 deletion src/transaction/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ typedef struct {
uint8_t nonce; /// nonce (8 bytes)
uint256_t gasprice;
uint256_t startgas; /// also known as `gaslimit`
uint8_t *to; /// pointer to address (20 bytes)
uint8_t to[ADDRESS_LEN]; /// pointer to address (20 bytes)
uint8_t ratio; /// ratio for partial fee delegated tx
uint256_t value; /// amount value
uint256_t chainID;
Expand Down
81 changes: 54 additions & 27 deletions src/ui/bagl_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,29 @@ UX_FLOW(ux_display_transaction_flow,
&ux_display_nonce_step,
&ux_display_gas_price_step,
&ux_display_gas_limit_step,
// &ux_display_to_step, // or ux_display_smart_contract_step
// &ux_display_fee_ratio_step,
// &ux_display_amount_step,
&ux_display_to_step, // or ux_display_smart_contract_step
&ux_display_fee_ratio_step,
&ux_display_amount_step,
&ux_display_approve_step,
&ux_display_reject_step);

UX_FLOW(ux_display_legacy_transaction_flow,
&ux_display_review_step,
&ux_display_type_step,
&ux_display_nonce_step,
&ux_display_gas_price_step,
&ux_display_gas_limit_step,
&ux_display_to_step,
&ux_display_amount_step,
&ux_display_approve_step,
&ux_display_reject_step);

UX_FLOW(ux_display_cancel_transaction_flow,
&ux_display_review_step,
&ux_display_type_step,
&ux_display_nonce_step,
&ux_display_gas_price_step,
&ux_display_gas_limit_step,
&ux_display_approve_step,
&ux_display_reject_step);

Expand All @@ -220,8 +240,8 @@ int ui_display_transaction() {
memset(g_nonce, 0, sizeof(g_nonce));
memset(g_gasPrice, 0, sizeof(g_gasPrice));
memset(g_gasLimit, 0, sizeof(g_gasLimit));
// memset(g_to, 0, sizeof(g_to));
// memset(g_feeRatio, 0, sizeof(g_feeRatio));
memset(g_to, 0, sizeof(g_to));
memset(g_feeRatio, 0, sizeof(g_feeRatio));
memset(g_amount, 0, sizeof(g_amount));

char type[50] = {0};
Expand Down Expand Up @@ -252,31 +272,38 @@ int ui_display_transaction() {
}
strncpy(g_gasLimit, gasLimit, sizeof(g_gasLimit));

// char to[43] = {0};
// if (format_hex(G_context.tx_info.transaction.to, ADDRESS_LEN, to, sizeof(to)) == -1) {
// return io_send_sw(SW_DISPLAY_ADDRESS_FAIL);
// }
// strncpy(g_to, to, sizeof(g_to));

// char feeRatio[30] = {0};
// if (!format_u64(feeRatio, sizeof(feeRatio), G_context.tx_info.transaction.ratio)) {
// return io_send_sw(SW_DISPLAY_FEERATIO_FAIL);
// }
// strncpy(g_feeRatio, feeRatio, sizeof(g_feeRatio));

// char amount[50] = {0};
// if (!ammount_to_string(G_context.tx_info.transaction.value,
// EXPONENT_SMALLEST_UNIT,
// amount,
// sizeof(amount))) {
// return io_send_sw(SW_DISPLAY_AMOUNT_FAIL);
// }
// snprintf(g_amount, sizeof(g_amount), "KLAY %.*s", sizeof(amount), amount);
if (format_hex(G_context.tx_info.transaction.to, ADDRESS_LEN, g_to, sizeof(g_to)) == -1) {
return io_send_sw(SW_DISPLAY_ADDRESS_FAIL);
}

g_validate_callback = &ui_action_validate_transaction;
char feeRatio[30] = {0};
if (!format_u64(feeRatio, sizeof(feeRatio), G_context.tx_info.transaction.ratio)) {
return io_send_sw(SW_DISPLAY_FEERATIO_FAIL);
}
strncpy(g_feeRatio, feeRatio, sizeof(g_feeRatio));

char amount[50] = {0};
if (!ammount_to_string(G_context.tx_info.transaction.value,
EXPONENT_SMALLEST_UNIT,
amount,
sizeof(amount))) {
return io_send_sw(SW_DISPLAY_AMOUNT_FAIL);
}
snprintf(g_amount, sizeof(g_amount), "KLAY %.*s", sizeof(amount), amount);

ux_flow_init(0, ux_display_transaction_flow, NULL);
g_validate_callback = &ui_action_validate_transaction;

switch(G_context.tx_info.transaction.txType) {
case LEGACY:
ux_flow_init(0, ux_display_legacy_transaction_flow, NULL);
break;
case CANCEL:
ux_flow_init(0, ux_display_cancel_transaction_flow, NULL);
break;
default:
ux_flow_init(0, ux_display_transaction_flow, NULL);
break;
}
return 0;
}

Expand Down
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.
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.
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.
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.
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 removed tests/snapshots/nanos/test_sign_tx_long_tx/00001.png
Binary file not shown.
Binary file removed tests/snapshots/nanos/test_sign_tx_long_tx/00002.png
Binary file not shown.
Binary file removed tests/snapshots/nanos/test_sign_tx_long_tx/00003.png
Binary file not shown.
Binary file removed tests/snapshots/nanos/test_sign_tx_long_tx/00004.png
Binary file not shown.
Binary file removed tests/snapshots/nanos/test_sign_tx_refused/00000.png
Binary file not shown.
Binary file removed tests/snapshots/nanos/test_sign_tx_refused/00001.png
Binary file not shown.
Binary file removed tests/snapshots/nanos/test_sign_tx_refused/00002.png
Binary file not shown.
Binary file removed tests/snapshots/nanos/test_sign_tx_refused/00003.png
Binary file not shown.
Binary file removed tests/snapshots/nanos/test_sign_tx_refused/00004.png
Binary file not shown.
Binary file removed tests/snapshots/nanos/test_sign_tx_refused/00005.png
Binary file not shown.
Binary file removed tests/snapshots/nanos/test_sign_tx_refused/00006.png
Binary file not shown.
Binary file removed tests/snapshots/nanos/test_sign_tx_refused/00007.png
Binary file not shown.
Binary file removed tests/snapshots/nanos/test_sign_tx_short_tx/00000.png
Diff not rendered.
Binary file removed tests/snapshots/nanos/test_sign_tx_short_tx/00001.png
Diff not rendered.
Binary file removed tests/snapshots/nanos/test_sign_tx_short_tx/00002.png
Diff not rendered.
Binary file removed tests/snapshots/nanos/test_sign_tx_short_tx/00003.png
Diff not rendered.
Binary file removed tests/snapshots/nanos/test_sign_tx_short_tx/00004.png
Diff not rendered.
Binary file removed tests/snapshots/nanos/test_sign_tx_short_tx/00005.png
Diff not rendered.
Binary file removed tests/snapshots/nanos/test_sign_tx_short_tx/00006.png
Diff not rendered.
Binary file removed tests/snapshots/nanosp/test_sign_tx_long_tx/00001.png
Diff not rendered.
Binary file removed tests/snapshots/nanosp/test_sign_tx_long_tx/00002.png
Diff not rendered.
Binary file removed tests/snapshots/nanosp/test_sign_tx_refused/00001.png
Diff not rendered.
Binary file removed tests/snapshots/nanosp/test_sign_tx_refused/00002.png
Diff not rendered.
Binary file removed tests/snapshots/nanosp/test_sign_tx_refused/00004.png
Diff not rendered.
Binary file removed tests/snapshots/nanosp/test_sign_tx_short_tx/00000.png
Diff not rendered.
Binary file removed tests/snapshots/nanosp/test_sign_tx_short_tx/00001.png
Diff not rendered.
Binary file removed tests/snapshots/nanosp/test_sign_tx_short_tx/00002.png
Diff not rendered.
Binary file removed tests/snapshots/nanosp/test_sign_tx_short_tx/00003.png
Diff not rendered.
Binary file removed tests/snapshots/nanosp/test_sign_tx_short_tx/00004.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_long_tx/00000.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_long_tx/00001.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_long_tx/00002.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_long_tx/00003.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_long_tx/00004.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_refused/00000.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_refused/00001.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_refused/00002.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_refused/00003.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_refused/00004.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_refused/00005.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_short_tx/00000.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_short_tx/00001.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_short_tx/00002.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_short_tx/00003.png
Diff not rendered.
Binary file removed tests/snapshots/nanox/test_sign_tx_short_tx/00004.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_app_mainmenu/00000.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_app_mainmenu/00001.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_app_mainmenu/00002.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_app_mainmenu/00003.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_app_mainmenu/00004.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_app_mainmenu/00005.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_app_mainmenu/00006.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_app_mainmenu/00007.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_app_mainmenu/00008.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_app_mainmenu/00009.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_app_mainmenu/00010.png
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.
Binary file removed tests/snapshots/stax/test_sign_tx_long_tx/00000.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_sign_tx_long_tx/00001.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_sign_tx_long_tx/00002.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_sign_tx_long_tx/00003.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_sign_tx_long_tx/00004.png
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.
Binary file removed tests/snapshots/stax/test_sign_tx_short_tx/00000.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_sign_tx_short_tx/00001.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_sign_tx_short_tx/00002.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_sign_tx_short_tx/00003.png
Diff not rendered.
Binary file removed tests/snapshots/stax/test_sign_tx_short_tx/00004.png
Diff not rendered.
15 changes: 15 additions & 0 deletions tests/test_sign_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ def test_sign_tx_cancel_tx(firmware, backend, navigator, test_name):
raw_transaction_hex = "e8a2e13819850ba43b7400830493e0946e93a3acfbadf457f29fb0e57fa42274004c32ea8203e98080"
perform_test_sign_tx_with_raw_tx(firmware, backend, navigator, test_name, raw_transaction_hex)

def test_sign_tx_legacy_tx(firmware, backend, navigator, test_name):
#The encoding is RLP, and the transaction is as follows:
# encode(
# nonce: 0x19
# gasPrice: 0x0ba43b7400, #50000000000
# gas: 0x0493e0, #300000
# to: 0x0ee56b604c869e3792c99e35c1c424f88f87dc8a
# value: 0x01
# input:
# chainId: 0x03e9, #1001
# 0
# 0
#)
raw_transaction_hex = "e719850ba43b7400830493e0940ee56b604c869e3792c99e35c1c424f88f87dc8a01808203e98080"
perform_test_sign_tx_with_raw_tx(firmware, backend, navigator, test_name, raw_transaction_hex)

# # In this test se send to the device a transaction to sign and validate it on screen
# # The transaction is short and will be sent in one chunk
Expand Down
Loading