From 5fbf938c33d751ea7cad4dbdedf6c47e876e227d Mon Sep 17 00:00:00 2001 From: Kobi Gurkan Date: Thu, 21 Jul 2022 22:20:29 +0300 Subject: [PATCH 1/5] feat: adds support for 3 important eth derivation paths --- Makefile | 2 +- src/celo.h | 2 +- src/main.c | 2 +- src_common/ethUstream.c | 15 ++++++++++++--- src_common/ethUstream.h | 3 ++- tests/test_tx_parser.c | 4 ++-- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index f57702c..3f2487f 100755 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ APPVERSION_P=8 APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P) # Celo -APP_LOAD_PARAMS += --path "44'/52752'" +APP_LOAD_PARAMS += --path "44'/52752'" --path "44'/60'/0'/0/0" --path "44'/60'/0'" --path "44'/60'/0'/0" APPNAME = "Celo" APP_LOAD_FLAGS=--appFlags 0 ifeq ($(TARGET_NAME), TARGET_NANOX) diff --git a/src/celo.h b/src/celo.h index a873eb3..8e417cd 100644 --- a/src/celo.h +++ b/src/celo.h @@ -12,7 +12,7 @@ void reset_app_context(); tokenDefinition_t* getKnownToken(uint8_t *tokenAddr); customStatus_e customProcessor(txContext_t *context); -void initTx(txContext_t *context, cx_sha3_t *sha3, txContent_t *content, ustreamProcess_t customProcessor, void *extra); +void initTx(txContext_t *context, cx_sha3_t *sha3, txContent_t *content, ustreamProcess_t customProcessor, bool isEthereum, void *extra); void finalizeParsing(bool direct); // TODO: this should not be exposed diff --git a/src/main.c b/src/main.c index 451ae6d..5492f61 100644 --- a/src/main.c +++ b/src/main.c @@ -297,7 +297,7 @@ void handleSign(uint8_t p1, uint8_t p2, const uint8_t *workBuffer, uint16_t data dataPresent = false; provisionType = PROVISION_NONE; //0x8000003c is the Ethereum path - initTx(&txContext, &sha3, &tmpContent.txContent, customProcessor, NULL); + initTx(&txContext, &sha3, &tmpContent.txContent, customProcessor, tmpCtx.transactionContext.derivationPath.path[1] == 0x8000003c, NULL); } else if (p1 != P1_MORE) { diff --git a/src_common/ethUstream.c b/src_common/ethUstream.c index 0c65a8f..4311215 100644 --- a/src_common/ethUstream.c +++ b/src_common/ethUstream.c @@ -497,8 +497,16 @@ static parserStatus_e processTxInternal(txContext_t *context) { } break; case TX_RLP_FEECURRENCY: - if (processFeeCurrency(context)) { - return USTREAM_FAULT; + //if this is an Ethereum transaction, skip the Celo fields + if (context->isEthereum) { + context->currentField+=3; + if (processTo(context)) { + return USTREAM_FAULT; + } + } else { + if (processFeeCurrency(context)) { + return USTREAM_FAULT; + } } break; case TX_RLP_GATEWAYTO: @@ -542,11 +550,12 @@ parserStatus_e continueTx(txContext_t *context) { } void initTx(txContext_t *context, cx_sha3_t *sha3, txContent_t *content, - ustreamProcess_t customProcessor, void *extra) { + ustreamProcess_t customProcessor, bool isEthereum, void *extra) { memset(context, 0, sizeof(txContext_t)); context->sha3 = sha3; context->content = content; context->customProcessor = customProcessor; + context->isEthereum = isEthereum; context->extra = extra; context->currentField = TX_RLP_CONTENT; #ifndef TESTING diff --git a/src_common/ethUstream.h b/src_common/ethUstream.h index 5b5b1f5..450a8c3 100644 --- a/src_common/ethUstream.h +++ b/src_common/ethUstream.h @@ -93,6 +93,7 @@ typedef struct txContent_t { typedef struct txContext_t { rlpTxField_e currentField; + bool isEthereum; cx_sha3_t *sha3; uint32_t currentFieldLength; uint32_t currentFieldPos; @@ -110,7 +111,7 @@ typedef struct txContext_t { } txContext_t; void initTx(txContext_t *context, cx_sha3_t *sha3, txContent_t *content, - ustreamProcess_t customProcessor, void *extra); + ustreamProcess_t customProcessor, bool isEthereum, void *extra); parserStatus_e processTx(txContext_t *context, const uint8_t *buffer, size_t length); parserStatus_e continueTx(txContext_t *context); int copyTxData(txContext_t *context, uint8_t *out, size_t length); diff --git a/tests/test_tx_parser.c b/tests/test_tx_parser.c index 0244877..73249ad 100644 --- a/tests/test_tx_parser.c +++ b/tests/test_tx_parser.c @@ -21,7 +21,7 @@ static void test_celo_tx_invalid_address(void **state) { txContent_t content; cx_sha3_t sha3; - initTx(&context, &sha3, &content, NULL, NULL); + initTx(&context, &sha3, &content, NULL, false, NULL); assert_int_equal(processTx(&context, tx_data, sizeof(tx_data)), USTREAM_FAULT); } @@ -44,7 +44,7 @@ static void test_celo_tx(void **state) { txContent_t content; cx_sha3_t sha3; - initTx(&context, &sha3, &content, NULL, NULL); + initTx(&context, &sha3, &content, NULL, false, NULL); assert_int_equal(processTx(&context, tx_data, sizeof(tx_data)), USTREAM_FINISHED); assert_int_equal(content.destinationLength, MAX_ADDRESS); assert_memory_equal(content.destination, to, MAX_ADDRESS); From 7c4865ef8a773d5e7f6446ef0e8113db25cfa485 Mon Sep 17 00:00:00 2001 From: Kobi Gurkan Date: Thu, 3 Nov 2022 14:16:45 +0200 Subject: [PATCH 2/5] fix: add missing breaks --- src/celo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/celo.c b/src/celo.c index b1ddbfe..9a1074d 100644 --- a/src/celo.c +++ b/src/celo.c @@ -233,15 +233,16 @@ customStatus_e customProcessor(txContext_t *context) { copyTxData(context, dataContext.withdrawContext.data + context->currentFieldPos, copySize); + break; case PROVISION_RELOCK: copyTxData(context, dataContext.relockContext.data + context->currentFieldPos, copySize); + break; case PROVISION_CREATE_ACCOUNT: copyTxData(context, dataContext.createAccountContext.data + context->currentFieldPos, copySize); - break; default: break; From 070928f01ea93c48b74ca99da9cfb4bfabbd290d Mon Sep 17 00:00:00 2001 From: Kobi Gurkan Date: Thu, 21 Sep 2023 23:24:32 +0300 Subject: [PATCH 3/5] allow only celo chain ids --- src/celo.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/celo.c b/src/celo.c index 9a1074d..63ef206 100644 --- a/src/celo.c +++ b/src/celo.c @@ -21,6 +21,9 @@ static const uint8_t WITHDRAW_METHOD_ID[] = { 0x2e, 0x1a, 0x7d, 0x4d }; static const uint8_t RELOCK_METHOD_ID[] = { 0xb2, 0xfb, 0x30, 0xcb }; static const uint8_t CREATE_ACCOUNT_METHOD_ID[] = { 0x9d, 0xca, 0x36, 0x2f }; +static uint32_t ALLOWED_CHAIN_IDS[3]={ 42220, 44787, 17323 }; +#define NUM_ALLOWED_CHAIN_IDS 3 + void io_seproxyhal_send_status(uint32_t sw) { G_io_apdu_buffer[0] = ((sw >> 8) & 0xff); G_io_apdu_buffer[1] = (sw & 0xff); @@ -336,6 +339,28 @@ void finalizeParsing(bool direct) { char *ticker = CHAINID_COINNAME " "; char *feeTicker = CHAINID_COINNAME " "; uint8_t tickerOffset = 0; + uint32_t v; + bool foundV = false; + + // Check for allowed chain IDs + v = getV(&tmpContent.txContent); + + for (i=0; i Date: Mon, 2 Oct 2023 18:54:10 +0300 Subject: [PATCH 4/5] add baklava --- src/celo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/celo.c b/src/celo.c index 63ef206..4908402 100644 --- a/src/celo.c +++ b/src/celo.c @@ -21,8 +21,8 @@ static const uint8_t WITHDRAW_METHOD_ID[] = { 0x2e, 0x1a, 0x7d, 0x4d }; static const uint8_t RELOCK_METHOD_ID[] = { 0xb2, 0xfb, 0x30, 0xcb }; static const uint8_t CREATE_ACCOUNT_METHOD_ID[] = { 0x9d, 0xca, 0x36, 0x2f }; -static uint32_t ALLOWED_CHAIN_IDS[3]={ 42220, 44787, 17323 }; -#define NUM_ALLOWED_CHAIN_IDS 3 +static uint32_t ALLOWED_CHAIN_IDS[4]={ 42220, 44787, 17323, 62320 }; +#define NUM_ALLOWED_CHAIN_IDS 4 void io_seproxyhal_send_status(uint32_t sw) { G_io_apdu_buffer[0] = ((sw >> 8) & 0xff); From a8889d850b7e16998a04dd1c5d91763654a62736 Mon Sep 17 00:00:00 2001 From: Francois Beutin Date: Wed, 4 Oct 2023 15:55:58 +0200 Subject: [PATCH 5/5] Fix one compilation warning --- src/celo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/celo.c b/src/celo.c index 8cf4301..748f9c4 100644 --- a/src/celo.c +++ b/src/celo.c @@ -335,8 +335,8 @@ void finalizeParsing(bool direct) { uint32_t i; uint8_t decimals = WEI_TO_ETHER; uint8_t feeDecimals = WEI_TO_ETHER; - char *ticker = CHAINID_COINNAME " "; - char *feeTicker = CHAINID_COINNAME " "; + const char *ticker = CHAINID_COINNAME " "; + const char *feeTicker = CHAINID_COINNAME " "; uint8_t tickerOffset = 0; uint32_t v; bool foundV = false; @@ -581,4 +581,4 @@ void finalizeParsing(bool direct) { } } #endif // NO_CONSENT -} \ No newline at end of file +}