Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ ifeq ($(APPNAME), "Aleo")
# - ENABLE_TESTING_SWAP: will lead to the enabling of the swap related C code of the standard_app
# ONLY works on Speculos, not on device
# Testing only SWAP flag
# ENABLE_TESTING_SWAP = 1
#ENABLE_TESTING_SWAP = 1
# Production enabled SWAP flag
# ENABLE_SWAP = 1
ENABLE_SWAP = 1
endif
# --8<-- [end:variables]

Expand Down
1 change: 1 addition & 0 deletions fuzzing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ target_include_directories(
${APP_SRC}/account
${APP_SRC}/crypto
${APP_SRC}/db
${APP_SRC}/format
${APP_SRC}/handler
${APP_SRC}/helper
${APP_SRC}/transaction
Expand Down
38 changes: 22 additions & 16 deletions src/account/account.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@

#include "account.h"

#define HASH_INPUT_MAX_LENGTH (8)
/*#define HASH_INPUT_MAX_LENGTH (8)

static field_t hash_input[HASH_INPUT_MAX_LENGTH];
static char text_buffer[32];
static field_t hash_input[HASH_INPUT_MAX_LENGTH];*/
Comment on lines +35 to +37
static char text_buffer[32];

const field_t ACCOUNT_SK_SIG_DOMAIN = {
.big.u64 = {0xc9a73b0068afb54b, 0x95d2050edfd00d2d, 0x30b27b31e4cc8dc3, 0x127ef5e8bbf7590e}
Expand Down Expand Up @@ -92,16 +92,17 @@

static int private_key_from_seed(const field_t *seed, scalar_t *sk_sig, scalar_t *r_sig)
{
_Static_assert(HASH_INPUT_MAX_LENGTH >= 4, "hash_input size won't fit");
int status = -1;
//_Static_assert(HASH_INPUT_MAX_LENGTH >= 4, "hash_input size won't fit");
int status = -1;
field_t hash_input[4];

// Compute sk_sig
memset(hash_input, 0, sizeof(hash_input));
memcpy(&hash_input[2], &ACCOUNT_SK_SIG_DOMAIN, sizeof(field_t));
memcpy(&hash_input[3], seed, sizeof(field_t));
status = hash_to_scalar_psd2(hash_input, 2 + 2, sk_sig);
if (status < 0) {
return -1;
goto end;
}
PRINTF("sk_sig : ");
scalar_println(sk_sig);
Expand All @@ -112,11 +113,13 @@
memcpy(&hash_input[3], seed, sizeof(field_t));
status = hash_to_scalar_psd2(hash_input, 2 + 2, r_sig);
if (status < 0) {
return -1;
goto end;
}
PRINTF("r_sig : ");
scalar_println(r_sig);

end:
explicit_bzero(hash_input, sizeof(hash_input));
return status;
}

Expand Down Expand Up @@ -146,15 +149,16 @@
compute_key_t *compute_key,
scalar_t *view_key)
{
_Static_assert(HASH_INPUT_MAX_LENGTH >= 6, "hash_input size won't fit");
int status = -1;
//_Static_assert(HASH_INPUT_MAX_LENGTH >= 6, "hash_input size won't fit");
int status = -1;
field_t hash_input[6];

memset(hash_input, 0, sizeof(hash_input));
memcpy(&hash_input[4], &compute_key->pk_sig.x, sizeof(field_t));
memcpy(&hash_input[5], &compute_key->pr_sig.x, sizeof(field_t));
status = hash_to_scalar_psd4(hash_input, 4 + 2, &compute_key->sk_prf);
if (status < 0) {
return -1;
goto end;
}
PRINTF("sk_prf : ");
scalar_println(&compute_key->sk_prf);
Expand All @@ -165,6 +169,8 @@
PRINTF("view_key : ");
scalar_println(view_key);

end:
explicit_bzero(hash_input, sizeof(hash_input));
return status;
}

Expand All @@ -182,8 +188,9 @@

static int graph_key_from_view_key(const scalar_t *view_key, field_t *graph_key)
{
_Static_assert(HASH_INPUT_MAX_LENGTH >= 7, "hash_input size won't fit");
//_Static_assert(HASH_INPUT_MAX_LENGTH >= 7, "hash_input size won't fit");
int status = -1;
field_t hash_input[7];
field_t f_view_key;
scalar_to_field(view_key, &f_view_key);

Expand All @@ -195,6 +202,7 @@
PRINTF("graph key : ");
field_println(graph_key);

explicit_bzero(hash_input, sizeof(hash_input));
return status;
}

Expand Down Expand Up @@ -257,7 +265,6 @@
PRINTF("%s\n", address);

end:
explicit_bzero(hash_input, sizeof(hash_input));
explicit_bzero(&account, sizeof(account_t));

return status;
Expand Down Expand Up @@ -311,7 +318,6 @@
PRINTF("%s\n", viewkey);

end:
explicit_bzero(hash_input, sizeof(hash_input));
explicit_bzero(&account, sizeof(account_t));

return status;
Expand Down Expand Up @@ -375,7 +381,6 @@
return 0;

error:
explicit_bzero(hash_input, sizeof(hash_input));
explicit_bzero(account, sizeof(account_t));
return status;
}
Expand All @@ -389,6 +394,7 @@
{
int status = -1;
field_t nonce;
field_t hash_input[8];
scalar_t *r = NULL;

LEDGER_ASSERT(account != NULL, "NULL account");
Expand All @@ -408,7 +414,7 @@
r = &G_context.r_list.array[index];

// Compute a `r0` as `hash_to_scalar_psd4(domain || sk_sig || nonce)`
_Static_assert(HASH_INPUT_MAX_LENGTH >= 7, "hash_input size won't fit");
//_Static_assert(HASH_INPUT_MAX_LENGTH >= 7, "hash_input size won't fit");
memset(hash_input, 0, sizeof(hash_input));
memcpy(&hash_input[4], &LEDGER_APP_ALEO_DOMAIN, sizeof(field_t));
scalar_to_field(&account->private_key.sk_sig, &hash_input[5]);
Expand Down Expand Up @@ -440,7 +446,7 @@
}

// Compute a `rx` as `hash_to_scalar_psd4(domain || sk_sig || nonce || index)`
_Static_assert(HASH_INPUT_MAX_LENGTH >= 8, "hash_input size won't fit");
//_Static_assert(HASH_INPUT_MAX_LENGTH >= 8, "hash_input size won't fit");
memset(hash_input, 0, sizeof(hash_input));
memcpy(&hash_input[4], &LEDGER_APP_ALEO_DOMAIN, sizeof(field_t));
scalar_to_field(&account->private_key.sk_sig, &hash_input[5]);
Expand Down
5 changes: 5 additions & 0 deletions src/account/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <stdbool.h> // bool

#include "os.h"
#include "swap.h"
#include "ledger_assert.h"
#include "globals.h"
#include "group.h"
Expand Down Expand Up @@ -410,6 +411,10 @@ static void display_progression(uint8_t step)
uint8_t current_step = step;
uint8_t total_step = (1 + G_context.nested_call_count) * 5;

if (G_called_from_swap) {
return;
}

if (G_context.signing_state == SIGNING_STATE_FEES) {
text = "Signing transaction";
}
Expand Down
23 changes: 17 additions & 6 deletions src/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "os.h"
#include "ux.h"
#include "swap.h"
#include "swap_error_code_helpers.h"

#include "types.h"
#include "globals.h"
Expand Down Expand Up @@ -55,14 +56,10 @@ void app_main(void)
io_init();
time_ms = 0;

#ifdef HAVE_SWAP
// When called in swap context as a library, we don't want to show the menu
if (!G_called_from_swap) {
#endif
ui_menu_main();
#ifdef HAVE_SWAP
}
#endif

// Reset context
explicit_bzero(&G_context, sizeof(G_context));
Expand Down Expand Up @@ -117,7 +114,14 @@ void app_ticker_event_callback(void)
account_erase(&G_context.account);
r_list_erase();
#ifndef FUZZ
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
if (!G_called_from_swap) {
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
}
else {
send_swap_error_simple(SW_SWAP_FAIL, SWAP_EC_ERROR_INTERNAL, SWAP_ERROR_CODE);
// unreachable
os_sched_exit(0);
}
#endif // FUZZ
}
}
Expand All @@ -127,7 +131,14 @@ void app_ticker_event_callback(void)
if (G_context.r_list_alive_remaining_time_ms < 100) {
G_context.r_list_alive_remaining_time_ms = 0;
r_list_erase();
ui_menu_main();
if (!G_called_from_swap) {
ui_menu_main();
}
else {
send_swap_error_simple(SW_SWAP_FAIL, SWAP_EC_ERROR_INTERNAL, SWAP_ERROR_CODE);
// unreachable
os_sched_exit(0);
}
}
}
}
5 changes: 5 additions & 0 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,10 @@
*/
#define R_LIST_MAX_VALIDITY_TIME_MS (5 * 1000)

/**
* Maximum size for amount formatting (39 chars for u128 + 2 for '0.').
*/
#define MAX_AMOUNT_SIZE (41)

#define ALEO_DECIMALS (6)
#define ALEO_TICKER "ALEO"
41 changes: 31 additions & 10 deletions src/handler/sign_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "os.h"
#include "cx.h"
#include "swap.h"
#include "ledger_assert.h"
#include "nbgl_use_case.h"
#include "menu.h"
Expand Down Expand Up @@ -74,7 +75,9 @@ static int sign_root_tx(buffer_t *cdata)
account_erase(&G_context.account);
r_list_erase();
#ifndef FUZZ
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
if (!G_called_from_swap) {
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
}
#endif // FUZZ
return io_send_sw(SW_DISPLAY_BIP32_PATH_FAIL);
}
Expand All @@ -93,7 +96,9 @@ static int sign_root_tx(buffer_t *cdata)
account_erase(&G_context.account);
r_list_erase();
#ifndef FUZZ
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
if (!G_called_from_swap) {
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
}
#endif // FUZZ
goto end;
}
Expand All @@ -106,7 +111,9 @@ static int sign_root_tx(buffer_t *cdata)
account_erase(&G_context.account);
r_list_erase();
#ifndef FUZZ
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
if (!G_called_from_swap) {
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
}
#endif // FUZZ
goto end;
}
Expand All @@ -116,7 +123,9 @@ static int sign_root_tx(buffer_t *cdata)
account_erase(&G_context.account);
r_list_erase();
#ifndef FUZZ
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
if (!G_called_from_swap) {
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
}
#endif // FUZZ
goto end;
}
Expand All @@ -128,7 +137,9 @@ static int sign_root_tx(buffer_t *cdata)
account_erase(&G_context.account);
r_list_erase();
#ifndef FUZZ
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
if (!G_called_from_swap) {
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_REJECTED, ui_menu_main);
}
#endif // FUZZ
}

Expand Down Expand Up @@ -201,15 +212,19 @@ static int sign_nested_call_tx(buffer_t *cdata)
G_context.fees_waiting_time_ms = 0;
G_context.signing_state = SIGNING_STATE_WAIT_FEES;
#ifndef FUZZ
nbgl_useCaseSpinner("Calculating fees");
if (!G_called_from_swap) {
nbgl_useCaseSpinner("Calculating fees");
}
#endif // FUZZ
}
else {
#ifndef FUZZ
account_erase(&G_context.account);
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_SIGNED, ui_menu_main);
G_context.signing_state = SIGNING_STATE_WAIT_INTENT;
#ifndef FUZZ
if (!G_called_from_swap) {
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_SIGNED, ui_menu_main);
}
#endif // FUZZ
G_context.signing_state = SIGNING_STATE_WAIT_INTENT;
}
}

Expand Down Expand Up @@ -299,7 +314,11 @@ static int sign_fee_tx(buffer_t *cdata)
validate_transaction(true);
account_erase(&G_context.account);
r_list_erase();
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_SIGNED, ui_menu_main);
#ifndef FUZZ
if (!G_called_from_swap) {
nbgl_useCaseReviewStatus(STATUS_TYPE_TRANSACTION_SIGNED, ui_menu_main);
}
#endif // FUZZ
G_context.signing_state = SIGNING_STATE_WAIT_INTENT;
status = 0;

Expand All @@ -313,6 +332,8 @@ int handler_sign_transaction(buffer_t *cdata, uint8_t mode, bool next_chunk)

LEDGER_ASSERT(cdata != NULL, "NULL cdata");

G_swap_response_ready = true;

if (!cdata->size) {
// Reject empty data
return io_send_sw(SWO_WRONG_DATA_LENGTH);
Expand Down
Loading
Loading