Verify return value of plugin

This commit is contained in:
pscott
2021-04-23 19:15:30 +02:00
parent fe2aab08a1
commit 0af10691eb
8 changed files with 60 additions and 51 deletions

View File

@@ -56,10 +56,11 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI,
queryContractUI->msgLength = msgLength; 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; uint8_t i;
const uint8_t **selectors; const uint8_t **selectors;
dataContext.tokenContext.pluginAvailable = 0; dataContext.tokenContext.pluginStatus = ETH_PLUGIN_RESULT_UNAVAILABLE;
// Handle hardcoded plugin list // Handle hardcoded plugin list
PRINTF("Selector %.*H\n", 4, init->selector); PRINTF("Selector %.*H\n", 4, init->selector);
for (i = 0;; i++) { 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) || if ((INTERNAL_ETH_PLUGINS[i].availableCheck == NULL) ||
((PluginAvailableCheck) PIC(INTERNAL_ETH_PLUGINS[i].availableCheck))()) { ((PluginAvailableCheck) PIC(INTERNAL_ETH_PLUGINS[i].availableCheck))()) {
strcpy(dataContext.tokenContext.pluginName, INTERNAL_ETH_PLUGINS[i].alias); strcpy(dataContext.tokenContext.pluginName, INTERNAL_ETH_PLUGINS[i].alias);
dataContext.tokenContext.pluginAvailable = 1; dataContext.tokenContext.pluginStatus = ETH_PLUGIN_RESULT_OK;
contractAddress = NULL; contractAddress = NULL;
break; 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); PRINTF("eth_plugin_init ok %s\n", dataContext.tokenContext.pluginName);
dataContext.tokenContext.pluginAvailable = 1; dataContext.tokenContext.pluginStatus = ETH_PLUGIN_RESULT_OK;
return 1; return 1;
} }
@@ -122,7 +123,7 @@ int eth_plugin_call(uint8_t *contractAddress, int method, void *parameter) {
pluginRO.txContent = &tmpContent.txContent; pluginRO.txContent = &tmpContent.txContent;
if (contractAddress == NULL) { if (contractAddress == NULL) {
if (!dataContext.tokenContext.pluginAvailable) { if (dataContext.tokenContext.pluginStatus == ETH_PLUGIN_RESULT_UNAVAILABLE) {
PRINTF("Cached plugin call but no plugin available\n"); PRINTF("Cached plugin call but no plugin available\n");
return 0; return 0;
} }

View File

@@ -22,7 +22,8 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI,
char *msg, char *msg,
uint32_t msgLength); 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 // NULL for cached address, or base contract address
int eth_plugin_call(uint8_t *contractAddress, int method, void *parameter); int eth_plugin_call(uint8_t *contractAddress, int method, void *parameter);
int compound_plugin_call(uint8_t *contractAddress, int method, void *parameter); int compound_plugin_call(uint8_t *contractAddress, int method, void *parameter);

View File

@@ -25,7 +25,8 @@ typedef enum {
ETH_PLUGIN_RESULT_ERROR = 0x00, ETH_PLUGIN_RESULT_ERROR = 0x00,
ETH_PLUGIN_RESULT_OK = 0x01, ETH_PLUGIN_RESULT_OK = 0x01,
ETH_PLUGIN_RESULT_OK_ALIAS = 0x02, 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; } eth_plugin_result_t;

View File

@@ -48,7 +48,7 @@ typedef enum starkQuantumType_e {
typedef struct tokenContext_t { typedef struct tokenContext_t {
char pluginName[PLUGIN_ID_LENGTH]; char pluginName[PLUGIN_ID_LENGTH];
uint8_t pluginAvailable; uint8_t pluginStatus;
uint8_t data[32]; uint8_t data[32];
uint8_t fieldIndex; uint8_t fieldIndex;

View File

@@ -19,7 +19,7 @@ void getEth2PublicKey(uint32_t *bip32Path, uint8_t bip32PathLength, uint8_t *out
uint8_t tmp[96]; uint8_t tmp[96];
io_seproxyhal_io_heartbeat(); 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(); io_seproxyhal_io_heartbeat();
memset(tmp, 0, 48); memset(tmp, 0, 48);
memmove(tmp + 16, privateKeyData, 32); memmove(tmp + 16, privateKeyData, 32);

View File

@@ -39,7 +39,7 @@ void handleSign(uint8_t p1,
dataLength -= 4; dataLength -= 4;
} }
dataPresent = false; dataPresent = false;
dataContext.tokenContext.pluginAvailable = 0; dataContext.tokenContext.pluginStatus = ETH_PLUGIN_RESULT_UNAVAILABLE;
initTx(&txContext, &global_sha3, &tmpContent.txContent, customProcessor, NULL); initTx(&txContext, &global_sha3, &tmpContent.txContent, customProcessor, NULL);
} else if (p1 != P1_MORE) { } else if (p1 != P1_MORE) {
THROW(0x6B00); THROW(0x6B00);

View File

@@ -42,24 +42,29 @@ customStatus_e customProcessor(txContext_t *context) {
PRINTF("Missing function selector\n"); PRINTF("Missing function selector\n");
return CUSTOM_FAULT; 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 // 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 // as they wouldn't be displayed if the plugin consumes all data but fallbacks
if (!N_storage.contractDetails) { if (!N_storage.contractDetails) {
eth_plugin_prepare_init(&pluginInit, eth_plugin_prepare_init(&pluginInit,
context->workBuffer, context->workBuffer,
context->currentFieldLength); context->currentFieldLength);
dataContext.tokenContext.pluginAvailable = dataContext.tokenContext.pluginStatus =
eth_plugin_perform_init(tmpContent.txContent.destination, &pluginInit); eth_plugin_perform_init(tmpContent.txContent.destination, &pluginInit);
} }
PRINTF("pluginAvailable %d\n", dataContext.tokenContext.pluginAvailable); PRINTF("pluginstatus %d\n", dataContext.tokenContext.pluginStatus);
if (dataContext.tokenContext.pluginAvailable) { switch (dataContext.tokenContext.pluginStatus) {
dataContext.tokenContext.fieldIndex = 0; case ETH_PLUGIN_RESULT_ERROR:
dataContext.tokenContext.fieldOffset = 0; return CUSTOM_FAULT;
copyTxData(context, NULL, 4); case ETH_PLUGIN_RESULT_UNAVAILABLE:
if (context->currentFieldLength == 4) { break;
return CUSTOM_NOT_HANDLED; default:
} dataContext.tokenContext.fieldIndex = 0;
dataContext.tokenContext.fieldOffset = 0;
copyTxData(context, NULL, 4);
if (context->currentFieldLength == 4) {
return CUSTOM_NOT_HANDLED;
}
} }
} }
uint32_t blockSize; uint32_t blockSize;
@@ -77,7 +82,8 @@ customStatus_e customProcessor(txContext_t *context) {
dataContext.tokenContext.fieldOffset = 0; dataContext.tokenContext.fieldOffset = 0;
blockSize = 4; blockSize = 4;
} else { } else {
if (!N_storage.contractDetails && !dataContext.tokenContext.pluginAvailable) { if (!N_storage.contractDetails &&
dataContext.tokenContext.pluginStatus != ETH_PLUGIN_RESULT_OK) {
return CUSTOM_NOT_HANDLED; return CUSTOM_NOT_HANDLED;
} }
blockSize = 32 - (dataContext.tokenContext.fieldOffset % 32); blockSize = 32 - (dataContext.tokenContext.fieldOffset % 32);
@@ -106,7 +112,7 @@ customStatus_e customProcessor(txContext_t *context) {
if (copySize == blockSize) { if (copySize == blockSize) {
// Can process or display // Can process or display
if (dataContext.tokenContext.pluginAvailable) { if (dataContext.tokenContext.pluginStatus == ETH_PLUGIN_RESULT_OK) {
ethPluginProvideParameter_t pluginProvideParameter; ethPluginProvideParameter_t pluginProvideParameter;
eth_plugin_prepare_provide_parameter(&pluginProvideParameter, eth_plugin_prepare_provide_parameter(&pluginProvideParameter,
dataContext.tokenContext.data, dataContext.tokenContext.data,
@@ -257,7 +263,7 @@ void finalizeParsing(bool direct) {
32); 32);
// Finalize the plugin handling // Finalize the plugin handling
if (dataContext.tokenContext.pluginAvailable) { if (dataContext.tokenContext.pluginStatus == ETH_PLUGIN_RESULT_OK) {
genericUI = false; genericUI = false;
eth_plugin_prepare_finalize(&pluginFinalize); eth_plugin_prepare_finalize(&pluginFinalize);
if (!eth_plugin_call(NULL, ETH_PLUGIN_FINALIZE, (void *) &pluginFinalize)) { if (!eth_plugin_call(NULL, ETH_PLUGIN_FINALIZE, (void *) &pluginFinalize)) {

View File

@@ -59,10 +59,7 @@ static int check_deposit_contract(ethPluginInitContract_t *msg) {
txContent_t *content = msg->pluginSharedRO->txContent; txContent_t *content = msg->pluginSharedRO->txContent;
char destinationAddress[DEPOSIT_CONTRACT_LENGTH]; char destinationAddress[DEPOSIT_CONTRACT_LENGTH];
// uint8_t destinationLen = getEthDisplayableAddress(destinationAddress, content->destination); 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;
if (destinationLen != DEPOSIT_CONTRACT_LENGTH) { if (destinationLen != DEPOSIT_CONTRACT_LENGTH) {
PRINTF("eth2plugin: destination lengths differ. Expected %u got %u\n", 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 case 4 + (32 * 8): // withdrawal credentials
{ {
// uint8_t tmp[48]; uint8_t tmp[48];
// uint32_t withdrawalKeyPath[4]; uint32_t withdrawalKeyPath[4];
// withdrawalKeyPath[0] = WITHDRAWAL_KEY_PATH_1; withdrawalKeyPath[0] = WITHDRAWAL_KEY_PATH_1;
// withdrawalKeyPath[1] = WITHDRAWAL_KEY_PATH_2; withdrawalKeyPath[1] = WITHDRAWAL_KEY_PATH_2;
// if (eth2WithdrawalIndex > INDEX_MAX) { if (eth2WithdrawalIndex > INDEX_MAX) {
// PRINTF("eth2 plugin: withdrawal index is too big\n"); PRINTF("eth2 plugin: withdrawal index is too big\n");
// PRINTF("Got %u which is higher than INDEX_MAX (%u)\n", PRINTF("Got %u which is higher than INDEX_MAX (%u)\n",
// eth2WithdrawalIndex, eth2WithdrawalIndex,
// INDEX_MAX); INDEX_MAX);
// context->valid = 0; msg->result = ETH_PLUGIN_RESULT_ERROR;
// } context->valid = 0;
// withdrawalKeyPath[2] = eth2WithdrawalIndex; }
// withdrawalKeyPath[3] = WITHDRAWAL_KEY_PATH_4; withdrawalKeyPath[2] = eth2WithdrawalIndex;
// getEth2PublicKey(withdrawalKeyPath, 4, tmp); withdrawalKeyPath[3] = WITHDRAWAL_KEY_PATH_4;
// PRINTF("eth2 plugin computed withdrawal public key %.*H\n", 48, tmp); getEth2PublicKey(withdrawalKeyPath, 4, tmp);
// cx_hash_sha256(tmp, 48, tmp, 32); PRINTF("eth2 plugin computed withdrawal public key %.*H\n", 48, tmp);
// tmp[0] = 0; cx_hash_sha256(tmp, 48, tmp, 32);
// if (memcmp(tmp, msg->parameter, 32) != 0) { tmp[0] = 0;
// PRINTF("eth2 plugin invalid withdrawal credentials\n"); if (memcmp(tmp, msg->parameter, 32) != 0) {
// PRINTF("Got %.*H\n", 32, msg->parameter); PRINTF("eth2 plugin invalid withdrawal credentials\n");
// PRINTF("Expected %.*H\n", 32, tmp); PRINTF("Got %.*H\n", 32, msg->parameter);
// context->valid = 0; PRINTF("Expected %.*H\n", 32, tmp);
// } msg->result = ETH_PLUGIN_RESULT_ERROR;
msg->result = ETH_PLUGIN_RESULT_OK; context->valid = 0;
} else {
msg->result = ETH_PLUGIN_RESULT_OK;
}
} break; } break;
default: default: