Skip to content

Commit

Permalink
PR review.
Browse files Browse the repository at this point in the history
  • Loading branch information
agrojean-ledger committed Jun 10, 2024
1 parent 6246b54 commit b90583c
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 78 deletions.
20 changes: 2 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,37 +85,23 @@ ifeq ($(TARGET_NAME),TARGET_NANOS)
DISABLE_STANDARD_BAGL_UX_FLOW = 1
endif

# vendor/ledger-nanopb
DEFINES += PB_FIELD_32BIT=1

# vendor/printf
DEFINES += PRINTF_DISABLE_SUPPORT_FLOAT PRINTF_DISABLE_SUPPORT_EXPONENTIAL PRINTF_DISABLE_SUPPORT_PTRDIFF_T
DEFINES += PRINTF_FTOA_BUFFER_SIZE=0
# endif

# U2F
DEFINES += HAVE_U2F HAVE_IO_U2F
DEFINES += U2F_PROXY_MAGIC=\"BOIL\"

# nanopb
CFLAGS += -Og -Iproto
CFLAGS += -I.

# printf
# CFLAGS += -Ivendor/printf/

# enable color from inside a script
CFLAGS += -fcolor-diagnostics
LDFLAGS += -Og -flto=thin

# Allow usage of function from lib_standard_app/crypto_helpers.c
APP_SOURCE_FILES += ${BOLOS_SDK}/lib_standard_app/crypto_helpers.c
INCLUDES_PATH += ${BOLOS_SDK}/lib_standard_app

include vendor/nanopb/extra/nanopb.mk

DEFINES += PB_NO_ERRMSG=1
SOURCE_FILES += $(NANOPB_CORE)
CFLAGS += "-I$(NANOPB_DIR)"
CFLAGS += "-I$(NANOPB_DIR)" -I.

PB_FILES = $(wildcard proto/*.proto)
C_PB_FILES = $(patsubst %.proto,%.pb.c,$(PB_FILES))
Expand All @@ -130,8 +116,6 @@ $(C_PB_FILES): %.pb.c: $(PB_FILES)
$(PYTHON_PB_FILES): %_pb2.py: $(PB_FILES)
$(PROTOC) $(PROTOC_OPTS) --python_out=. $*.proto



.PHONY: c_pb python_pb clean_python_pb
c_pb: $(C_PB_FILES)
python_pb: $(PYTHON_PB_FILES)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Hedera Ledger App

Hedera™ Hashgraph BOLOS application for Ledger Nano S, Nano S Plus, and Nano X.
Hedera™ Hashgraph BOLOS application for Ledger devices.

## Development

Expand Down
2 changes: 1 addition & 1 deletion src/get_app_configuration.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdint.h>

#include "io.h"
#include "app_io.h"
#include "os.h"
#include "ux.h"

Expand Down
6 changes: 3 additions & 3 deletions src/get_public_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include <stddef.h>
#include <stdint.h>

#include "globals.h"
#include "app_globals.h"
#include "handlers.h"
#include "hedera.h"
#include "io.h"
#include "app_io.h"
#include "ui_common.h"
#include "utils.h"

Expand All @@ -17,7 +17,7 @@ typedef struct get_public_key_context_s {
// Lines on the UI Screen
char ui_approve_l2[DISPLAY_SIZE + 1];

uint8_t raw_pubkey[65];
uint8_t raw_pubkey[RAW_PUBKEY_SIZE];

// Public Key Compare
uint8_t display_index;
Expand Down
5 changes: 2 additions & 3 deletions src/hedera.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#include <os.h>
#include <string.h>

#include "globals.h"
#include "lib_standard_app/crypto_helpers.h"
#include "crypto_helpers.h"
#include "utils.h"

static void hedera_set_path(uint32_t index, uint32_t path[static 5]) {
Expand All @@ -16,7 +15,7 @@ static void hedera_set_path(uint32_t index, uint32_t path[static 5]) {
path[4] = PATH_FOUR;
}

bool hedera_get_pubkey(uint32_t index, uint8_t raw_pubkey[static 65]) {
bool hedera_get_pubkey(uint32_t index, uint8_t raw_pubkey[static RAW_PUBKEY_SIZE]) {
static uint32_t path[5];

hedera_set_path(index, path);
Expand Down
3 changes: 2 additions & 1 deletion src/hedera.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#include <stdbool.h>
#include <stdint.h>
#include "app_globals.h"

bool hedera_get_pubkey(uint32_t index, uint8_t raw_pubkey[static 65]);
bool hedera_get_pubkey(uint32_t index, uint8_t raw_pubkey[static RAW_PUBKEY_SIZE]);

bool hedera_sign(uint32_t index, const uint8_t* tx, uint8_t tx_len,
/* out */ uint8_t* result);
9 changes: 3 additions & 6 deletions src/hedera_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ static void set_title(const char *title) {
static void set_senders_title(const char *title) {
#if defined(TARGET_NANOS)
set_title(title);
#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \
defined(TARGET_STAX) || defined(TARGET_FLEX)
#else
// st_ctx.senders_title --> st_ctx.title (NANOS)
hedera_safe_printf(st_ctx.senders_title, "%s", title);
#endif
Expand All @@ -142,8 +141,7 @@ static void set_senders_title(const char *title) {
static void set_recipients_title(const char *title) {
#if defined(TARGET_NANOS)
set_title(title);
#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \
defined(TARGET_STAX) || defined(TARGET_FLEX)
#else
// st_ctx.recipients_title --> st_ctx.title (NANOS)
hedera_safe_printf(st_ctx.recipients_title, "%s", title);
#endif
Expand All @@ -152,8 +150,7 @@ static void set_recipients_title(const char *title) {
static void set_amount_title(const char *title) {
#if defined(TARGET_NANOS)
set_title(title);
#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \
defined(TARGET_STAX) || defined(TARGET_FLEX)
#else
// st_ctx.senders_title --> st_ctx.title (NANOS)
hedera_safe_printf(st_ctx.amount_title, "%s", title);
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/hedera_format.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "globals.h"
#include "io.h"
#include "app_globals.h"
#include "app_io.h"
#include "sign_transaction.h"

void reformat_key(void);
Expand Down
6 changes: 2 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "globals.h"
#include "app_globals.h"
#include "glyphs.h"
#include "handlers.h"
#include "os.h"
Expand All @@ -16,8 +16,7 @@
// Things are marked volatile throughout the app to prevent unintended compiler
// reording of instructions (since the try-catch system is a macro)

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \
defined(TARGET_FLEX)
#if !defined(TARGET_NANOS)
ux_state_t G_ux;
bolos_ux_params_t G_ux_params;
#endif
Expand Down Expand Up @@ -150,7 +149,6 @@ __attribute__((section(".boot"))) int main() {
USB_power(0);
USB_power(1);

PRINTF("TEST 1\n");
// Shows the main menu
ui_idle();

Expand Down
36 changes: 12 additions & 24 deletions src/sign_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ void handle_transaction_body() {
#if defined(TARGET_NANOS)
MEMCLEAR(st_ctx.full);
MEMCLEAR(st_ctx.partial);
#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \
defined(TARGET_STAX) || defined(TARGET_FLEX)
#else
MEMCLEAR(st_ctx.amount_title);
MEMCLEAR(st_ctx.senders_title);
MEMCLEAR(st_ctx.operator);
Expand All @@ -91,8 +90,7 @@ void handle_transaction_body() {
// with Key #X?
reformat_key();

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \
defined(TARGET_FLEX)
#if !defined(TARGET_NANOS)
// All flows except Verify
if (!is_verify_account()) reformat_operator();
#endif
Expand All @@ -103,8 +101,7 @@ void handle_transaction_body() {
st_ctx.type = Create;
reformat_summary("Create Account");

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \
defined(TARGET_FLEX)
#if !defined(TARGET_NANOS)
reformat_stake_target();
reformat_collect_rewards();
reformat_amount_balance();
Expand All @@ -115,8 +112,7 @@ void handle_transaction_body() {
st_ctx.type = Update;
reformat_summary("Update Account");

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \
defined(TARGET_FLEX)
#if !defined(TARGET_NANOS)
reformat_stake_target();
reformat_collect_rewards();
reformat_updated_account();
Expand All @@ -127,8 +123,7 @@ void handle_transaction_body() {
st_ctx.type = Associate;
reformat_summary("Associate Token");

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \
defined(TARGET_FLEX)
#if !defined(TARGET_NANOS)
reformat_token_associate();
#endif
break;
Expand All @@ -137,8 +132,7 @@ void handle_transaction_body() {
st_ctx.type = Dissociate;
reformat_summary("Dissociate Token");

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \
defined(TARGET_FLEX)
#if !defined(TARGET_NANOS)
reformat_token_dissociate();
#endif
break;
Expand All @@ -147,8 +141,7 @@ void handle_transaction_body() {
st_ctx.type = TokenBurn;
reformat_summary("Burn Token");

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \
defined(TARGET_FLEX)
#if !defined(TARGET_NANOS)
reformat_token_burn();
reformat_amount_burn();
#endif
Expand All @@ -158,8 +151,7 @@ void handle_transaction_body() {
st_ctx.type = TokenMint;
reformat_summary("Mint Token");

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \
defined(TARGET_FLEX)
#if !defined(TARGET_NANOS)
reformat_token_mint();
reformat_amount_mint();
#endif
Expand All @@ -172,8 +164,7 @@ void handle_transaction_body() {
st_ctx.type = Verify;
reformat_summary("Verify Account");

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \
defined(TARGET_FLEX)
#if !defined(TARGET_NANOS)
reformat_verify_account();
#endif

Expand All @@ -192,8 +183,7 @@ void handle_transaction_body() {
st_ctx.transfer_to_index = 0;
}

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \
defined(TARGET_FLEX)
#if !defined(TARGET_NANOS)
reformat_sender_account();
reformat_recipient_account();
reformat_amount_transfer();
Expand All @@ -213,8 +203,7 @@ void handle_transaction_body() {
st_ctx.transfer_to_index = 0;
}

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \
defined(TARGET_FLEX)
#if !defined(TARGET_NANOS)
reformat_token_sender_account();
reformat_token_recipient_account();
reformat_token_transfer();
Expand All @@ -232,8 +221,7 @@ void handle_transaction_body() {
break;
}

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \
defined(TARGET_FLEX)
#if !defined(TARGET_NANOS)
// All flows except Verify
if (!is_verify_account()) {
reformat_fee();
Expand Down
8 changes: 3 additions & 5 deletions src/sign_transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "handlers.h"
#include "hedera.h"
#include "hedera_format.h"
#include "io.h"
#include "app_io.h"
#include "transaction_body.pb.h"
#include "ui_common.h"
#include "utils.h"
Expand Down Expand Up @@ -101,8 +101,7 @@ typedef struct sign_tx_context_s {
char recipients_title[TITLE_SIZE]; // alias for title
char amount_title[TITLE_SIZE]; // alias for title
};
#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \
defined(TARGET_STAX) || defined(TARGET_FLEX)
#else
char senders_title[DISPLAY_SIZE + 1];
char recipients_title[DISPLAY_SIZE + 1];
char amount_title[DISPLAY_SIZE + 1];
Expand Down Expand Up @@ -134,8 +133,7 @@ typedef struct sign_tx_context_s {
#if defined(TARGET_NANOS)
uint8_t display_index; // 1 -> Number Screens
uint8_t display_count; // Number Screens
#elif defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \
defined(TARGET_STAX) || defined(TARGET_FLEX)
#else
// Transaction Operator
char operator[DISPLAY_SIZE * 2 + 1];

Expand Down
1 change: 1 addition & 0 deletions src/ui/globals.h → src/ui/app_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define BIP32_PATH 5
#define DISPLAY_SIZE 18 // characters @ 11pt sys font

#define RAW_PUBKEY_SIZE 65
#define MAX_TX_SIZE 512
#define FULL_ADDRESS_LENGTH 54
#define ACCOUNT_ID_SIZE 19 * 3 + 2 + 1
Expand Down
2 changes: 1 addition & 1 deletion src/ui/io.h → src/ui/app_io.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "debug.h"
#include "globals.h"
#include "app_globals.h"
#include "os.h"
#include "os_io_seproxyhal.h"

Expand Down
2 changes: 1 addition & 1 deletion src/ui/io.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "io.h"
#include "app_io.h"

#include "ux.h"

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

#include <printf.h>

#include "io.h"
#include "app_io.h"
#include "os.h"
#include "ux.h"

Expand Down
4 changes: 1 addition & 3 deletions src/utils.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "utils.h"

#include "globals.h"

void public_key_to_bytes(unsigned char *dst, uint8_t raw_pubkey[static 65]) {
void public_key_to_bytes(unsigned char *dst, uint8_t raw_pubkey[static RAW_PUBKEY_SIZE]) {
if (dst == NULL || raw_pubkey == NULL) {
THROW(EXCEPTION_MALFORMED_APDU);
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

#include <os.h>
#include <stdint.h>
#include "app_globals.h"

#define MEMCLEAR(element) explicit_bzero(&element, sizeof(element))

#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))

void public_key_to_bytes(unsigned char *dst, uint8_t raw_pubkey[static 65]);
void public_key_to_bytes(unsigned char *dst, uint8_t raw_pubkey[static RAW_PUBKEY_SIZE]);

void bin2hex(uint8_t *dst, uint8_t *data, uint64_t inlen);
Loading

0 comments on commit b90583c

Please sign in to comment.