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

@@ -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: