|
62 | 62 |
|
63 | 63 | #include <ed25519-donna.h>
|
64 | 64 |
|
| 65 | +#include "int-util.h" |
65 | 66 | #include "reconstruct_wallet_flow.h"
|
66 | 67 | #include "solana_api.h"
|
67 | 68 | #include "solana_contracts.h"
|
@@ -355,6 +356,57 @@ STATIC bool solana_fetch_valid_transaction(solana_query_t *query) {
|
355 | 356 | return true;
|
356 | 357 | }
|
357 | 358 |
|
| 359 | +static bool verify_priority_fee() { |
| 360 | + if (solana_txn_context->transaction_info.compute_unit_price_micro_lamports > |
| 361 | + 0) { |
| 362 | + // verify priority fee |
| 363 | + uint64_t priority_fee, carry; |
| 364 | + |
| 365 | + // Capacity to multiply 2 numbers upto 8-byte value and store the result in |
| 366 | + // 2 separate 8-byte variables |
| 367 | + priority_fee = mul128( |
| 368 | + solana_txn_context->transaction_info.compute_unit_price_micro_lamports, |
| 369 | + solana_txn_context->transaction_info.compute_unit_limit, |
| 370 | + &carry); |
| 371 | + |
| 372 | + // prepare the whole 128-bit little-endian representation of priority fee |
| 373 | + uint8_t be_micro_lamports[16] = {0}; |
| 374 | + memcpy(be_micro_lamports, &priority_fee, sizeof(priority_fee)); |
| 375 | + memcpy(be_micro_lamports + sizeof(priority_fee), &carry, sizeof(carry)); |
| 376 | + |
| 377 | + // outputs 128-bit (16-byte) big-endian representation of priority fee |
| 378 | + cy_reverse_byte_array(be_micro_lamports, sizeof(be_micro_lamports)); |
| 379 | + |
| 380 | + char priority_fee_string[33] = {'\0'}, |
| 381 | + priority_fee_decimal_string[34] = {'\0'}; |
| 382 | + |
| 383 | + byte_array_to_hex_string(be_micro_lamports, |
| 384 | + sizeof(be_micro_lamports), |
| 385 | + priority_fee_string, |
| 386 | + sizeof(priority_fee_string)); |
| 387 | + if (!convert_byte_array_to_decimal_string( |
| 388 | + sizeof(priority_fee_string) - 1, |
| 389 | + solana_get_decimal() + 6, // +6 for micro |
| 390 | + priority_fee_string, |
| 391 | + priority_fee_decimal_string, |
| 392 | + sizeof(priority_fee_decimal_string))) { |
| 393 | + solana_send_error(ERROR_COMMON_ERROR_UNKNOWN_ERROR_TAG, 1); |
| 394 | + return false; |
| 395 | + } |
| 396 | + |
| 397 | + char display[100] = ""; |
| 398 | + snprintf(display, |
| 399 | + sizeof(display), |
| 400 | + UI_TEXT_VERIFY_PRIORITY_FEE, |
| 401 | + priority_fee_decimal_string, |
| 402 | + SOLANA_LUNIT); |
| 403 | + if (!core_confirmation(display, solana_send_error)) { |
| 404 | + return false; |
| 405 | + } |
| 406 | + } |
| 407 | + return true; |
| 408 | +} |
| 409 | + |
358 | 410 | static bool verify_solana_transfer_sol_transaction() {
|
359 | 411 | char address[45] = {0};
|
360 | 412 | size_t address_size = sizeof(address);
|
@@ -408,6 +460,9 @@ static bool verify_solana_transfer_sol_transaction() {
|
408 | 460 | return false;
|
409 | 461 | }
|
410 | 462 |
|
| 463 | + if (!verify_priority_fee()) |
| 464 | + return false; |
| 465 | + |
411 | 466 | set_app_flow_status(SOLANA_SIGN_TXN_STATUS_VERIFY);
|
412 | 467 | return true;
|
413 | 468 | }
|
@@ -649,6 +704,9 @@ static bool verify_solana_transfer_token_transaction() {
|
649 | 704 | return false;
|
650 | 705 | }
|
651 | 706 |
|
| 707 | + if (!verify_priority_fee()) |
| 708 | + return false; |
| 709 | + |
652 | 710 | set_app_flow_status(SOLANA_SIGN_TXN_STATUS_VERIFY);
|
653 | 711 | return true;
|
654 | 712 | }
|
|
0 commit comments