From 6ff2172f1bcc3348fcb5d36a66f80fae206bf071 Mon Sep 17 00:00:00 2001 From: pscott Date: Thu, 22 Apr 2021 10:08:05 +0200 Subject: [PATCH] Add upper bound for withdrawal index --- src_features/getEth2PublicKey/cmd_getEth2PublicKey.c | 2 +- .../setEth2WithdrawalIndex/cmd_setEth2WithdrawalIndex.c | 4 ++++ src_features/setEth2WithdrawalIndex/withdrawal_index.h | 2 ++ src_plugins/eth2/eth2_plugin.c | 6 ++++++ 4 files changed, 13 insertions(+), 1 deletion(-) 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/setEth2WithdrawalIndex/cmd_setEth2WithdrawalIndex.c b/src_features/setEth2WithdrawalIndex/cmd_setEth2WithdrawalIndex.c index ea99f03..24d528f 100644 --- a/src_features/setEth2WithdrawalIndex/cmd_setEth2WithdrawalIndex.c +++ b/src_features/setEth2WithdrawalIndex/cmd_setEth2WithdrawalIndex.c @@ -2,6 +2,7 @@ #include "shared_context.h" #include "apdu_constants.h" +#include "withdrawal_index.h" void handleSetEth2WithdrawalIndex(uint8_t p1, uint8_t p2, @@ -18,6 +19,9 @@ void handleSetEth2WithdrawalIndex(uint8_t p1, } eth2WithdrawalIndex = U4BE(dataBuffer, 0); + if (eth2WithdrawalIndex > INDEX_MAX) { + THROW(0x6A80); // scott throw this error code or create new one ? + } THROW(0x9000); } diff --git a/src_features/setEth2WithdrawalIndex/withdrawal_index.h b/src_features/setEth2WithdrawalIndex/withdrawal_index.h index 497b489..a70064f 100644 --- a/src_features/setEth2WithdrawalIndex/withdrawal_index.h +++ b/src_features/setEth2WithdrawalIndex/withdrawal_index.h @@ -1,5 +1,7 @@ #include "stdint.h" +#define INDEX_MAX 1337 // scott + void handleSetEth2WithdrawalIndex(uint8_t p1, uint8_t p2, uint8_t *dataBuffer, diff --git a/src_plugins/eth2/eth2_plugin.c b/src_plugins/eth2/eth2_plugin.c index e4d57a2..09279d0 100644 --- a/src_plugins/eth2/eth2_plugin.c +++ b/src_plugins/eth2/eth2_plugin.c @@ -6,6 +6,7 @@ #include "shared_context.h" #include "ethUtils.h" #include "utils.h" +#include "withdrawal_index.h" void getEth2PublicKey(uint32_t *bip32Path, uint8_t bip32PathLength, uint8_t *out); @@ -98,6 +99,11 @@ void eth2_plugin_call(int message, void *parameters) { uint32_t withdrawalKeyPath[4]; withdrawalKeyPath[0] = WITHDRAWAL_KEY_PATH_1; withdrawalKeyPath[1] = WITHDRAWAL_KEY_PATH_2; + if (eth2WithdrawalIndex > INDEX_MAX) { + PRINTF("eth2 plugin eth2 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);