Verify return value of plugin
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user