Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ftheirs committed May 13, 2024
1 parent 4981a42 commit 90920d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
13 changes: 8 additions & 5 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ DEBUG:=0

MY_DIR := $(dir $(lastword $(MAKEFILE_LIST)))

# This enables automatically the ethereum application
# This enables automatically the ethereum application
# for all targets except for the nanos
ifneq ($(TARGET_NAME), TARGET_NANOS)
FEATURE_ETH = 1
Expand Down Expand Up @@ -91,7 +91,7 @@ endif
ifeq ($(TARGET_NAME),TARGET_NANOX)
RUST_TARGET:=thumbv6m-none-eabi
APP_FULL:=1
# Why just here and not common setting for similar targets
# Why just here and not common setting for similar targets
# like nanosplus and stax?
# ifeq ($(FEATURE_ETH), 1))
# APP_LOAD_PARAMS += --appFlags 0xa50
Expand Down Expand Up @@ -126,10 +126,13 @@ ifeq ($(FEATURE_ETH), 1)
CHAIN_ID = 1
TICKER = "ETH"

# These flags are needed by cmd_getAppConfiguration.c from ETH app
CFLAGS += -DMAJOR_VERSION=${APPVERSION_M} -DMINOR_VERSION=${APPVERSION_N} -DPATCH_VERSION=${APPVERSION_P}

# Do not compile eth app if target is nanos
ifeq (,$(filter $(TARGET_NAME),TARGET_NANOS))
DEFINES += HAVE_ETH_INTEGRATION
DEFINES += HAVE_ETH2
DEFINES += HAVE_ETH2
DEFINES_LIB += USE_LIB_ETHEREUM

# EIP-712
Expand All @@ -141,7 +144,7 @@ ifeq ($(FEATURE_ETH), 1)
DEFINES += CHAIN_ID=1
DEFINES += HAVE_BOLOS_APP_STACK_CANARY
DEFINES += HAVE_HASH3
# TODO: This should not be necessary
# TODO: This should not be necessary
# but compilation fails after enabling it with HAVE_HASH3
DEFINES += CX_KECCAK_256_SIZE=32
# Dynamic memory allocator
Expand All @@ -165,7 +168,7 @@ ifeq ($(FEATURE_ETH), 1)
DEFINES += BLE_SEGMENT_SIZE=32 #max MTU, min 20

DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""
# This should not be necessary but app-ethereum/main.c needs
# This should not be necessary but app-ethereum/main.c needs
# it although we are not compiling it as a binary.
DEFINES += CHAINID_COINNAME=\"$(TICKER)\" CHAIN_ID=$(CHAIN_ID)

Expand Down
27 changes: 6 additions & 21 deletions app/src/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

// taken from ethereum/src/main.c
void ui_idle(void);
chain_config_t *chainConfig = NULL;

uint32_t set_result_get_publicKey(void);
void finalizeParsing(bool);
Expand Down Expand Up @@ -101,21 +100,6 @@ void io_seproxyhal_send_status(uint32_t sw) {
}

// clang-format on
extraInfo_t *getKnownToken(uint8_t *contractAddress) {
union extraInfo_t *currentItem = NULL;
// Works for ERC-20 & NFT tokens since both structs in the union have the
// contract address aligned
for (uint8_t i = 0; i < MAX_ITEMS; i++) {
currentItem = (union extraInfo_t *) &tmpCtx.transactionContext.extraInfo[i].token;
if (tmpCtx.transactionContext.tokenSet[i] &&
(memcmp(currentItem->token.address, contractAddress, ADDRESS_LENGTH) == 0)) {
PRINTF("Token found at index %d\n", i);
return currentItem;
}
}

return NULL;
}

const uint8_t *parseBip32(const uint8_t *dataBuffer, uint8_t *dataLength, bip32_path_t *bip32) {
if (*dataLength < 1) {
Expand Down Expand Up @@ -171,7 +155,8 @@ void handle_eth_apdu(volatile uint32_t *flags, volatile uint32_t *tx,

switch (buffer[OFFSET_INS]) {
case INS_GET_PUBLIC_KEY:
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_ITEMS);

forget_known_assets();
handleGetPublicKey(buffer[OFFSET_P1],
buffer[OFFSET_P2],
buffer + OFFSET_CDATA,
Expand Down Expand Up @@ -246,7 +231,7 @@ void handle_eth_apdu(volatile uint32_t *flags, volatile uint32_t *tx,
break;

case INS_SIGN_PERSONAL_MESSAGE:
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_ITEMS);
forget_known_assets();
*flags |= IO_ASYNCH_REPLY;
if (!handleSignPersonalMessage(buffer[OFFSET_P1],
buffer[OFFSET_P2],
Expand All @@ -259,7 +244,7 @@ void handle_eth_apdu(volatile uint32_t *flags, volatile uint32_t *tx,
case INS_SIGN_EIP_712_MESSAGE:
switch (buffer[OFFSET_P2]) {
case P2_EIP712_LEGACY_IMPLEM:
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_ITEMS);
forget_known_assets();
handleSignEIP712Message_v0(buffer[OFFSET_P1],
buffer[OFFSET_P2],
buffer + OFFSET_CDATA,
Expand All @@ -281,7 +266,7 @@ void handle_eth_apdu(volatile uint32_t *flags, volatile uint32_t *tx,
#ifdef HAVE_ETH2

case INS_GET_ETH2_PUBLIC_KEY:
memset(tmpCtx.transactionContext.tokenSet, 0, MAX_ITEMS);
forget_known_assets();
handleGetEth2PublicKey(buffer[OFFSET_P1],
buffer[OFFSET_P2],
buffer + OFFSET_CDATA,
Expand Down Expand Up @@ -385,7 +370,7 @@ void handle_eth_apdu(volatile uint32_t *flags, volatile uint32_t *tx,
END_TRY;
}

// Taken from ethereum app, this might be useful but need to double check if it fullfil our
// Taken from ethereum app, this might be useful but need to double check if it fullfil our
// purpose for signing eip712
/* Eth clones do not actually contain any logic, they delegate everything to the ETH application.
* Start Eth in lib mode with the correct chain config
Expand Down

0 comments on commit 90920d9

Please sign in to comment.