diff --git a/Makefile b/Makefile index 00a6c10..c2f3229 100755 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ APPVERSION_P=10 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),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX)) diff --git a/src/celo.c b/src/celo.c index ea8f1c1..748f9c4 100644 --- a/src/celo.c +++ b/src/celo.c @@ -20,6 +20,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[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); G_io_apdu_buffer[1] = (sw & 0xff); @@ -232,15 +235,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; @@ -331,9 +335,31 @@ 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; + + // Check for allowed chain IDs + v = getV(&tmpContent.txContent); + + for (i=0; iisEthereum) { + 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/unit/test_tx_parser.c b/tests/unit/test_tx_parser.c index 0244877..73249ad 100644 --- a/tests/unit/test_tx_parser.c +++ b/tests/unit/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);