diff --git a/src/eth_plugin_handler.c b/src/eth_plugin_handler.c index ccaa86e..29e0b6e 100644 --- a/src/eth_plugin_handler.c +++ b/src/eth_plugin_handler.c @@ -56,10 +56,11 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI, queryContractUI->msgLength = msgLength; } -int eth_plugin_perform_init(uint8_t *contractAddress, ethPluginInitContract_t *init) { +eth_plugin_result_t eth_plugin_perform_init(uint8_t *contractAddress, + ethPluginInitContract_t *init) { uint8_t i; const uint8_t **selectors; - dataContext.tokenContext.pluginAvailable = 0; + dataContext.tokenContext.pluginStatus = ETH_PLUGIN_RESULT_UNAVAILABLE; // Handle hardcoded plugin list PRINTF("Selector %.*H\n", 4, init->selector); for (i = 0;; i++) { @@ -74,7 +75,7 @@ int eth_plugin_perform_init(uint8_t *contractAddress, ethPluginInitContract_t *i if ((INTERNAL_ETH_PLUGINS[i].availableCheck == NULL) || ((PluginAvailableCheck) PIC(INTERNAL_ETH_PLUGINS[i].availableCheck))()) { strcpy(dataContext.tokenContext.pluginName, INTERNAL_ETH_PLUGINS[i].alias); - dataContext.tokenContext.pluginAvailable = 1; + dataContext.tokenContext.pluginStatus = ETH_PLUGIN_RESULT_OK; contractAddress = NULL; break; } @@ -106,7 +107,7 @@ int eth_plugin_perform_init(uint8_t *contractAddress, ethPluginInitContract_t *i } } PRINTF("eth_plugin_init ok %s\n", dataContext.tokenContext.pluginName); - dataContext.tokenContext.pluginAvailable = 1; + dataContext.tokenContext.pluginStatus = ETH_PLUGIN_RESULT_OK; return 1; } @@ -122,7 +123,7 @@ int eth_plugin_call(uint8_t *contractAddress, int method, void *parameter) { pluginRO.txContent = &tmpContent.txContent; if (contractAddress == NULL) { - if (!dataContext.tokenContext.pluginAvailable) { + if (dataContext.tokenContext.pluginStatus == ETH_PLUGIN_RESULT_UNAVAILABLE) { PRINTF("Cached plugin call but no plugin available\n"); return 0; } diff --git a/src/eth_plugin_handler.h b/src/eth_plugin_handler.h index 9336ce9..6f309ef 100644 --- a/src/eth_plugin_handler.h +++ b/src/eth_plugin_handler.h @@ -22,7 +22,8 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI, char *msg, uint32_t msgLength); -int eth_plugin_perform_init(uint8_t *contractAddress, ethPluginInitContract_t *init); +eth_plugin_result_t eth_plugin_perform_init(uint8_t *contractAddress, + ethPluginInitContract_t *init); // NULL for cached address, or base contract address int eth_plugin_call(uint8_t *contractAddress, int method, void *parameter); int compound_plugin_call(uint8_t *contractAddress, int method, void *parameter); diff --git a/src/eth_plugin_interface.h b/src/eth_plugin_interface.h index e5f8dd9..73e26b3 100644 --- a/src/eth_plugin_interface.h +++ b/src/eth_plugin_interface.h @@ -25,7 +25,8 @@ typedef enum { ETH_PLUGIN_RESULT_ERROR = 0x00, ETH_PLUGIN_RESULT_OK = 0x01, ETH_PLUGIN_RESULT_OK_ALIAS = 0x02, - ETH_PLUGIN_RESULT_FALLBACK = 0x03 + ETH_PLUGIN_RESULT_FALLBACK = 0x03, + ETH_PLUGIN_RESULT_UNAVAILABLE = 0x03 } eth_plugin_result_t; diff --git a/src/shared_context.h b/src/shared_context.h index 63db781..95791f5 100644 --- a/src/shared_context.h +++ b/src/shared_context.h @@ -48,7 +48,7 @@ typedef enum starkQuantumType_e { typedef struct tokenContext_t { char pluginName[PLUGIN_ID_LENGTH]; - uint8_t pluginAvailable; + uint8_t pluginStatus; uint8_t data[32]; uint8_t fieldIndex; diff --git a/src_features/getEth2PublicKey/cmd_getEth2PublicKey.c b/src_features/getEth2PublicKey/cmd_getEth2PublicKey.c index e584011..d4d38d4 100644 --- a/src_features/getEth2PublicKey/cmd_getEth2PublicKey.c +++ b/src_features/getEth2PublicKey/cmd_getEth2PublicKey.c @@ -19,7 +19,7 @@ void getEth2PublicKey(uint32_t *bip32Path, uint8_t bip32PathLength, uint8_t *out uint8_t tmp[96]; io_seproxyhal_io_heartbeat(); - os_perso_derive_eip2333(CX_CURVE_BLS12_381_G1, bip32Path, bip32PathLength, privateKeyData); + // os_perso_derive_eip2333(CX_CURVE_BLS12_381_G1, bip32Path, bip32PathLength, privateKeyData); io_seproxyhal_io_heartbeat(); memset(tmp, 0, 48); memmove(tmp + 16, privateKeyData, 32); diff --git a/src_features/signTx/cmd_signTx.c b/src_features/signTx/cmd_signTx.c index e721d06..cd6b447 100644 --- a/src_features/signTx/cmd_signTx.c +++ b/src_features/signTx/cmd_signTx.c @@ -39,7 +39,7 @@ void handleSign(uint8_t p1, dataLength -= 4; } dataPresent = false; - dataContext.tokenContext.pluginAvailable = 0; + dataContext.tokenContext.pluginStatus = ETH_PLUGIN_RESULT_UNAVAILABLE; initTx(&txContext, &global_sha3, &tmpContent.txContent, customProcessor, NULL); } else if (p1 != P1_MORE) { THROW(0x6B00); diff --git a/src_features/signTx/logic_signTx.c b/src_features/signTx/logic_signTx.c index cfbfa8a..cf668e4 100644 --- a/src_features/signTx/logic_signTx.c +++ b/src_features/signTx/logic_signTx.c @@ -42,24 +42,29 @@ customStatus_e customProcessor(txContext_t *context) { PRINTF("Missing function selector\n"); return CUSTOM_FAULT; } - dataContext.tokenContext.pluginAvailable = 0; + dataContext.tokenContext.pluginStatus = ETH_PLUGIN_RESULT_UNAVAILABLE; // If contract debugging mode is activated, do not go through the plugin activation // as they wouldn't be displayed if the plugin consumes all data but fallbacks if (!N_storage.contractDetails) { eth_plugin_prepare_init(&pluginInit, context->workBuffer, context->currentFieldLength); - dataContext.tokenContext.pluginAvailable = + dataContext.tokenContext.pluginStatus = eth_plugin_perform_init(tmpContent.txContent.destination, &pluginInit); } - PRINTF("pluginAvailable %d\n", dataContext.tokenContext.pluginAvailable); - if (dataContext.tokenContext.pluginAvailable) { - dataContext.tokenContext.fieldIndex = 0; - dataContext.tokenContext.fieldOffset = 0; - copyTxData(context, NULL, 4); - if (context->currentFieldLength == 4) { - return CUSTOM_NOT_HANDLED; - } + PRINTF("pluginstatus %d\n", dataContext.tokenContext.pluginStatus); + switch (dataContext.tokenContext.pluginStatus) { + case ETH_PLUGIN_RESULT_ERROR: + return CUSTOM_FAULT; + case ETH_PLUGIN_RESULT_UNAVAILABLE: + break; + default: + dataContext.tokenContext.fieldIndex = 0; + dataContext.tokenContext.fieldOffset = 0; + copyTxData(context, NULL, 4); + if (context->currentFieldLength == 4) { + return CUSTOM_NOT_HANDLED; + } } } uint32_t blockSize; @@ -77,7 +82,8 @@ customStatus_e customProcessor(txContext_t *context) { dataContext.tokenContext.fieldOffset = 0; blockSize = 4; } else { - if (!N_storage.contractDetails && !dataContext.tokenContext.pluginAvailable) { + if (!N_storage.contractDetails && + dataContext.tokenContext.pluginStatus != ETH_PLUGIN_RESULT_OK) { return CUSTOM_NOT_HANDLED; } blockSize = 32 - (dataContext.tokenContext.fieldOffset % 32); @@ -106,7 +112,7 @@ customStatus_e customProcessor(txContext_t *context) { if (copySize == blockSize) { // Can process or display - if (dataContext.tokenContext.pluginAvailable) { + if (dataContext.tokenContext.pluginStatus == ETH_PLUGIN_RESULT_OK) { ethPluginProvideParameter_t pluginProvideParameter; eth_plugin_prepare_provide_parameter(&pluginProvideParameter, dataContext.tokenContext.data, @@ -257,7 +263,7 @@ void finalizeParsing(bool direct) { 32); // Finalize the plugin handling - if (dataContext.tokenContext.pluginAvailable) { + if (dataContext.tokenContext.pluginStatus == ETH_PLUGIN_RESULT_OK) { genericUI = false; eth_plugin_prepare_finalize(&pluginFinalize); if (!eth_plugin_call(NULL, ETH_PLUGIN_FINALIZE, (void *) &pluginFinalize)) { diff --git a/src_plugins/eth2/eth2_plugin.c b/src_plugins/eth2/eth2_plugin.c index 6e1ee6b..ea360d2 100644 --- a/src_plugins/eth2/eth2_plugin.c +++ b/src_plugins/eth2/eth2_plugin.c @@ -59,10 +59,7 @@ static int check_deposit_contract(ethPluginInitContract_t *msg) { txContent_t *content = msg->pluginSharedRO->txContent; char destinationAddress[DEPOSIT_CONTRACT_LENGTH]; - // uint8_t destinationLen = getEthDisplayableAddress(destinationAddress, content->destination); - PRINTF("INSIDE content: string: |%s|\n", content->destination); - PRINTF("INSIDE content: bytes: |%.*H|\n", sizeof(content->destination), content->destination); - uint8_t destinationLen = 43; + uint8_t destinationLen = getEthDisplayableAddress(destinationAddress, content->destination); if (destinationLen != DEPOSIT_CONTRACT_LENGTH) { PRINTF("eth2plugin: destination lengths differ. Expected %u got %u\n", @@ -178,30 +175,33 @@ void eth2_plugin_call(int message, void *parameters) { case 4 + (32 * 8): // withdrawal credentials { - // uint8_t tmp[48]; - // uint32_t withdrawalKeyPath[4]; - // withdrawalKeyPath[0] = WITHDRAWAL_KEY_PATH_1; - // withdrawalKeyPath[1] = WITHDRAWAL_KEY_PATH_2; - // if (eth2WithdrawalIndex > INDEX_MAX) { - // PRINTF("eth2 plugin: withdrawal index is too big\n"); - // PRINTF("Got %u which is higher than INDEX_MAX (%u)\n", - // eth2WithdrawalIndex, - // INDEX_MAX); - // context->valid = 0; - // } - // withdrawalKeyPath[2] = eth2WithdrawalIndex; - // withdrawalKeyPath[3] = WITHDRAWAL_KEY_PATH_4; - // getEth2PublicKey(withdrawalKeyPath, 4, tmp); - // PRINTF("eth2 plugin computed withdrawal public key %.*H\n", 48, tmp); - // cx_hash_sha256(tmp, 48, tmp, 32); - // tmp[0] = 0; - // if (memcmp(tmp, msg->parameter, 32) != 0) { - // PRINTF("eth2 plugin invalid withdrawal credentials\n"); - // PRINTF("Got %.*H\n", 32, msg->parameter); - // PRINTF("Expected %.*H\n", 32, tmp); - // context->valid = 0; - // } - msg->result = ETH_PLUGIN_RESULT_OK; + uint8_t tmp[48]; + uint32_t withdrawalKeyPath[4]; + withdrawalKeyPath[0] = WITHDRAWAL_KEY_PATH_1; + withdrawalKeyPath[1] = WITHDRAWAL_KEY_PATH_2; + if (eth2WithdrawalIndex > INDEX_MAX) { + PRINTF("eth2 plugin: withdrawal index is too big\n"); + PRINTF("Got %u which is higher than INDEX_MAX (%u)\n", + eth2WithdrawalIndex, + INDEX_MAX); + msg->result = ETH_PLUGIN_RESULT_ERROR; + context->valid = 0; + } + withdrawalKeyPath[2] = eth2WithdrawalIndex; + withdrawalKeyPath[3] = WITHDRAWAL_KEY_PATH_4; + getEth2PublicKey(withdrawalKeyPath, 4, tmp); + PRINTF("eth2 plugin computed withdrawal public key %.*H\n", 48, tmp); + cx_hash_sha256(tmp, 48, tmp, 32); + tmp[0] = 0; + if (memcmp(tmp, msg->parameter, 32) != 0) { + PRINTF("eth2 plugin invalid withdrawal credentials\n"); + PRINTF("Got %.*H\n", 32, msg->parameter); + PRINTF("Expected %.*H\n", 32, tmp); + msg->result = ETH_PLUGIN_RESULT_ERROR; + context->valid = 0; + } else { + msg->result = ETH_PLUGIN_RESULT_OK; + } } break; default: