From c5fb10dd47b589953050a3929124c9916752a8de Mon Sep 17 00:00:00 2001 From: pscott Date: Fri, 6 Aug 2021 15:20:58 +0200 Subject: [PATCH 1/6] Remove check for v length --- src/utils.c | 10 +--------- src/utils.h | 4 +--- src_common/ethUstream.c | 14 +++++++++----- src_common/network.c | 5 ++--- src_features/signTx/logic_signTx.c | 7 +++---- src_features/signTx/ui_common_signTx.c | 4 +++- 6 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/utils.c b/src/utils.c index 85f2add..e3e04c6 100644 --- a/src/utils.c +++ b/src/utils.c @@ -54,9 +54,7 @@ int local_strchr(char *string, char ch) { return -1; } -// Almost like U4BE except that it takes `size` as a parameter. -// The `strict` parameter defines whether we should throw in case of a length > 4. -uint32_t u32_from_BE(uint8_t *in, uint8_t size, bool strict) { +uint32_t u32_from_BE(uint8_t *in, uint8_t size) { switch (size) { case 0: return 0; @@ -66,13 +64,7 @@ uint32_t u32_from_BE(uint8_t *in, uint8_t size, bool strict) { return (in[0] << 8) | in[1]; case 3: return (in[0] << 16) | (in[1] << 8) | in[2]; - case 4: - return (in[0] << 24) | (in[1] << 16) | (in[2] << 8) | in[3]; default: - if (strict) { - PRINTF("Unexpected format\n"); - THROW(EXCEPTION); - } return (in[0] << 24) | (in[1] << 16) | (in[2] << 8) | in[3]; } } diff --git a/src/utils.h b/src/utils.h index 17a59b5..f10ac19 100644 --- a/src/utils.h +++ b/src/utils.h @@ -28,9 +28,7 @@ void convertUint256BE(uint8_t* data, uint32_t length, uint256_t* target); int local_strchr(char* string, char ch); -// Converts a list of bytes (in BE) of length `size` to a uint32_t. `strict` will make the function -// throw if the size is > 4. -uint32_t u32_from_BE(uint8_t* in, uint8_t size, bool strict); +uint32_t u32_from_BE(uint8_t* in, uint8_t size); bool uint256_to_decimal(const uint8_t* value, size_t value_len, char* out, size_t out_len); diff --git a/src_common/ethUstream.c b/src_common/ethUstream.c index fc091cc..28e0d27 100644 --- a/src_common/ethUstream.c +++ b/src_common/ethUstream.c @@ -24,7 +24,6 @@ #define MAX_INT256 32 #define MAX_ADDRESS 20 -#define MAX_V 4 void initTx(txContext_t *context, cx_sha3_t *sha3, @@ -255,6 +254,10 @@ static void processTo(txContext_t *context) { } static void processData(txContext_t *context) { + PRINTF("DATA len: %d, DATA: %.*H\n", + context->currentFieldLength, + context->currentFieldLength, + context->workBuffer); if (context->currentFieldIsList) { PRINTF("Invalid type for RLP_DATA\n"); THROW(EXCEPTION); @@ -275,6 +278,7 @@ static void processData(txContext_t *context) { } static void processAndDiscard(txContext_t *context) { + PRINTF("DISCARDING: %.*H\n", context->currentFieldLength, context->workBuffer); if (context->currentFieldIsList) { PRINTF("Invalid type for Discarded field\n"); THROW(EXCEPTION); @@ -291,14 +295,14 @@ static void processAndDiscard(txContext_t *context) { } static void processV(txContext_t *context) { + PRINTF("current Length: %d\tBuff: %.*H\n", + context->currentFieldLength, + context->currentFieldLength, + context->workBuffer); if (context->currentFieldIsList) { PRINTF("Invalid type for RLP_V\n"); THROW(EXCEPTION); } - if (context->currentFieldLength > MAX_V) { - PRINTF("Invalid length for RLP_V\n"); - THROW(EXCEPTION); - } if (context->currentFieldPos < context->currentFieldLength) { uint32_t copySize = MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos); diff --git a/src_common/network.c b/src_common/network.c index 5f33b8a..f1181b8 100644 --- a/src_common/network.c +++ b/src_common/network.c @@ -26,13 +26,12 @@ uint32_t get_chain_id(void) { switch (txContext.txType) { case LEGACY: - chain_id = u32_from_BE(txContext.content->v, txContext.content->vLength, true); + chain_id = u32_from_BE(txContext.content->v, txContext.content->vLength); break; case EIP2930: case EIP1559: chain_id = u32_from_BE(tmpContent.txContent.chainID.value, - tmpContent.txContent.chainID.length, - true); + tmpContent.txContent.chainID.length); break; default: PRINTF("Txtype `%d` not supported while generating chainID\n", txContext.txType); diff --git a/src_features/signTx/logic_signTx.c b/src_features/signTx/logic_signTx.c index a7cb59e..9d6eb77 100644 --- a/src_features/signTx/logic_signTx.c +++ b/src_features/signTx/logic_signTx.c @@ -261,11 +261,10 @@ uint32_t get_chainID() { uint32_t chain_id = 0; if (txContext.txType == LEGACY) { - chain_id = u32_from_BE(txContext.content->v, txContext.content->vLength, true); + chain_id = u32_from_BE(txContext.content->v, txContext.content->vLength); } else if (txContext.txType == EIP2930 || txContext.txType == EIP1559) { - chain_id = u32_from_BE(tmpContent.txContent.chainID.value, - tmpContent.txContent.chainID.length, - true); + chain_id = + u32_from_BE(tmpContent.txContent.chainID.value, tmpContent.txContent.chainID.length); } else { PRINTF("Txtype `%u` not supported while generating chainID\n", txContext.txType); } diff --git a/src_features/signTx/ui_common_signTx.c b/src_features/signTx/ui_common_signTx.c index eb2ee11..72348a0 100644 --- a/src_features/signTx/ui_common_signTx.c +++ b/src_features/signTx/ui_common_signTx.c @@ -7,7 +7,7 @@ unsigned int io_seproxyhal_touch_tx_ok(__attribute__((unused)) const bagl_elemen uint8_t signature[100]; cx_ecfp_private_key_t privateKey; uint32_t tx = 0; - uint32_t v = u32_from_BE(tmpContent.txContent.v, tmpContent.txContent.vLength, true); + uint32_t v = u32_from_BE(tmpContent.txContent.v, tmpContent.txContent.vLength); io_seproxyhal_io_heartbeat(); os_perso_derive_node_bip32(CX_CURVE_256K1, tmpCtx.transactionContext.bip32Path, @@ -27,6 +27,8 @@ unsigned int io_seproxyhal_touch_tx_ok(__attribute__((unused)) const bagl_elemen sizeof(signature), &info); explicit_bzero(&privateKey, sizeof(privateKey)); + PRINTF("v: %.*H\n", tmpContent.txContent.vLength, tmpContent.txContent.v); + PRINTF("u32 v: %.*H\n", sizeof(v), &v); if (txContext.txType == EIP1559 || txContext.txType == EIP2930) { if (info & CX_ECCINFO_PARITY_ODD) { G_io_apdu_buffer[0] = 1; From 9d2c07d648aa7f95c02c6ec03c85d96f017450f5 Mon Sep 17 00:00:00 2001 From: pscott Date: Fri, 6 Aug 2021 16:46:03 +0200 Subject: [PATCH 2/6] remove double get_chainID fn --- src_features/signTx/logic_signTx.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src_features/signTx/logic_signTx.c b/src_features/signTx/logic_signTx.c index 9d6eb77..47960af 100644 --- a/src_features/signTx/logic_signTx.c +++ b/src_features/signTx/logic_signTx.c @@ -257,21 +257,6 @@ void prepareFeeDisplay() { sizeof(strings.common.maxFee)); } -uint32_t get_chainID() { - uint32_t chain_id = 0; - - if (txContext.txType == LEGACY) { - chain_id = u32_from_BE(txContext.content->v, txContext.content->vLength); - } else if (txContext.txType == EIP2930 || txContext.txType == EIP1559) { - chain_id = - u32_from_BE(tmpContent.txContent.chainID.value, tmpContent.txContent.chainID.length); - } else { - PRINTF("Txtype `%u` not supported while generating chainID\n", txContext.txType); - } - PRINTF("ChainID: %d\n", chain_id); - return chain_id; -} - void prepareNetworkDisplay() { char *name = get_network_name(); if (name == NULL) { From 3a4f477b1da2e18b699f7bd14aff46f2a1e4a023 Mon Sep 17 00:00:00 2001 From: pscott Date: Fri, 6 Aug 2021 19:15:31 +0200 Subject: [PATCH 3/6] Bump version --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6b88b48..ee6304a 100755 --- a/Makefile +++ b/Makefile @@ -30,8 +30,8 @@ APP_LOAD_PARAMS += --path "1517992542'/1101353413'" APPVERSION_M=1 APPVERSION_N=9 -APPVERSION_P=0 -APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P) +APPVERSION_P=2 +APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)-remove_v_check APP_LOAD_FLAGS= --appFlags 0x240 --dep Ethereum:$(APPVERSION) ifeq ($(CHAIN),) From c8bad8b2f83b42ae14fcc576d81a05e681573203 Mon Sep 17 00:00:00 2001 From: pscott Date: Fri, 6 Aug 2021 21:07:22 +0200 Subject: [PATCH 4/6] Remove debug prints; secure copy of chainid into v --- src_common/ethUstream.c | 11 ++--------- src_features/signTx/ui_common_signTx.c | 2 -- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src_common/ethUstream.c b/src_common/ethUstream.c index 28e0d27..a706e6e 100644 --- a/src_common/ethUstream.c +++ b/src_common/ethUstream.c @@ -254,10 +254,6 @@ static void processTo(txContext_t *context) { } static void processData(txContext_t *context) { - PRINTF("DATA len: %d, DATA: %.*H\n", - context->currentFieldLength, - context->currentFieldLength, - context->workBuffer); if (context->currentFieldIsList) { PRINTF("Invalid type for RLP_DATA\n"); THROW(EXCEPTION); @@ -278,7 +274,6 @@ static void processData(txContext_t *context) { } static void processAndDiscard(txContext_t *context) { - PRINTF("DISCARDING: %.*H\n", context->currentFieldLength, context->workBuffer); if (context->currentFieldIsList) { PRINTF("Invalid type for Discarded field\n"); THROW(EXCEPTION); @@ -295,10 +290,6 @@ static void processAndDiscard(txContext_t *context) { } static void processV(txContext_t *context) { - PRINTF("current Length: %d\tBuff: %.*H\n", - context->currentFieldLength, - context->currentFieldLength, - context->workBuffer); if (context->currentFieldIsList) { PRINTF("Invalid type for RLP_V\n"); THROW(EXCEPTION); @@ -306,6 +297,8 @@ static void processV(txContext_t *context) { if (context->currentFieldPos < context->currentFieldLength) { uint32_t copySize = MIN(context->commandLength, context->currentFieldLength - context->currentFieldPos); + // Make sure we do not copy more than the size of v. + copySize = MIN(copySize, sizeof(context->content->v)); copyTxData(context, context->content->v + context->currentFieldPos, copySize); } if (context->currentFieldPos == context->currentFieldLength) { diff --git a/src_features/signTx/ui_common_signTx.c b/src_features/signTx/ui_common_signTx.c index 72348a0..360f883 100644 --- a/src_features/signTx/ui_common_signTx.c +++ b/src_features/signTx/ui_common_signTx.c @@ -27,8 +27,6 @@ unsigned int io_seproxyhal_touch_tx_ok(__attribute__((unused)) const bagl_elemen sizeof(signature), &info); explicit_bzero(&privateKey, sizeof(privateKey)); - PRINTF("v: %.*H\n", tmpContent.txContent.vLength, tmpContent.txContent.v); - PRINTF("u32 v: %.*H\n", sizeof(v), &v); if (txContext.txType == EIP1559 || txContext.txType == EIP2930) { if (info & CX_ECCINFO_PARITY_ODD) { G_io_apdu_buffer[0] = 1; From fd73a08f24e433b93f77fe0da00d4423af7fe86a Mon Sep 17 00:00:00 2001 From: pscott Date: Wed, 11 Aug 2021 11:24:50 +0200 Subject: [PATCH 5/6] Update changelog --- CHANGELOG.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ad5dd6..ed66f06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [1.9.1](https://github.com/ledgerhq/app-ethereum/compare/1.8.8...1.9.1) - 2021-8-06 +## [1.9.1](https://github.com/ledgerhq/app-ethereum/compare/1.9.0...1.9.1) - 2021-8-11 ### Added -- Fix BSC app icons. -- Fix tokens for Theta app. +- Added support for bigger chainIDs. + +### Fixed + +- Fixed BSC icon colors. +- Fixed theta tokens. +- Fix BSC app name display. ## [1.9.0](https://github.com/ledgerhq/app-ethereum/compare/1.8.8...1.9.0) - 2021-8-05 From 28964ba02a414ff506922911cf31a853cb6f7921 Mon Sep 17 00:00:00 2001 From: pscott Date: Wed, 11 Aug 2021 11:25:19 +0200 Subject: [PATCH 6/6] Change Binance Smart Chain to BSC --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0180681..3d127f0 100755 --- a/Makefile +++ b/Makefile @@ -210,7 +210,7 @@ APPNAME = "Theta" else ifeq ($(CHAIN),bsc) APP_LOAD_PARAMS += --path "44'/60'" DEFINES += CHAINID_UPCASE=\"BSC\" CHAINID_COINNAME=\"BNB\" CHAIN_KIND=CHAIN_KIND_BSC CHAIN_ID=56 -APPNAME = "Binance Smart Chain" +APPNAME = "BSC" else ifeq ($(filter clean,$(MAKECMDGOALS)),) $(error Unsupported CHAIN - use ethereum, ropsten, ethereum_classic, expanse, poa, artis_sigma1, artis_tau1, rsk, rsk_testnet, ubiq, wanchain, kusd, musicoin, pirl, akroma, atheios, callisto, ethersocial, ellaism, ether1, ethergem, gochain, mix, reosc, hpb, tomochain, tobalaba, dexon, volta, ewc, webchain, thundercore, flare, flare_coston, theta)