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

@@ -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);

View File

@@ -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);

View File

@@ -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)) {