From 69773b0846900e190d7b1393d785ba76a223c9a7 Mon Sep 17 00:00:00 2001 From: pscott Date: Wed, 24 Mar 2021 16:08:48 +0100 Subject: [PATCH 1/5] Add Wno- flags to Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9d8c236..59418db 100755 --- a/Makefile +++ b/Makefile @@ -290,7 +290,7 @@ endif CC := $(CLANGPATH)clang #CFLAGS += -O0 -CFLAGS += -O3 -Os -I/usr/include +CFLAGS += -O3 -Os -I/usr/include -Wno-format-invalid-specifier -Wno-format-extra-args -Wno-main AS := $(GCCPATH)arm-none-eabi-gcc From acdbb36b4462c70aa88f67c2cc111d6a0177831e Mon Sep 17 00:00:00 2001 From: pscott Date: Wed, 24 Mar 2021 16:09:03 +0100 Subject: [PATCH 2/5] Fix warnings by including headers and casting --- src/eth_plugin_handler.c | 4 ++-- src/eth_plugin_internal.c | 10 +++++----- src/eth_plugin_ui.c | 1 + src/handle_get_printable_amount.c | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/eth_plugin_handler.c b/src/eth_plugin_handler.c index fe3c1e7..74bc3c8 100644 --- a/src/eth_plugin_handler.c +++ b/src/eth_plugin_handler.c @@ -64,13 +64,13 @@ int eth_plugin_perform_init(uint8_t *contractAddress, ethPluginInitContract_t *i PRINTF("Selector %.*H\n", 4, init->selector); for (i = 0;; i++) { uint8_t j; - selectors = PIC(INTERNAL_ETH_PLUGINS[i].selectors); + selectors = (const uint8_t **)PIC(INTERNAL_ETH_PLUGINS[i].selectors); if (selectors == NULL) { break; } for (j = 0; ((j < INTERNAL_ETH_PLUGINS[i].num_selectors) && (contractAddress != NULL)); j++) { - if (memcmp(init->selector, PIC(selectors[j]), SELECTOR_SIZE) == 0) { + if (memcmp(init->selector, (const void *)PIC(selectors[j]), SELECTOR_SIZE) == 0) { if ((INTERNAL_ETH_PLUGINS[i].availableCheck == NULL) || ((PluginAvailableCheck) PIC(INTERNAL_ETH_PLUGINS[i].availableCheck))()) { strcpy(dataContext.tokenContext.pluginName, INTERNAL_ETH_PLUGINS[i].alias); diff --git a/src/eth_plugin_internal.c b/src/eth_plugin_internal.c index 659819c..4cdb464 100644 --- a/src/eth_plugin_internal.c +++ b/src/eth_plugin_internal.c @@ -92,28 +92,28 @@ const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS] = { const internalEthPlugin_t const INTERNAL_ETH_PLUGINS[] = { {erc20_plugin_available_check, - ERC20_SELECTORS, + (const uint8_t **)ERC20_SELECTORS, NUM_ERC20_SELECTORS, "-erc20", erc20_plugin_call}, {erc721_plugin_available_check, - ERC721_SELECTORS, + (const uint8_t **)ERC721_SELECTORS, NUM_ERC721_SELECTORS, "-er721", erc721_plugin_call}, - {NULL, COMPOUND_SELECTORS, NUM_COMPOUND_SELECTORS, "-cmpd", compound_plugin_call}, + {NULL, (const uint8_t **)COMPOUND_SELECTORS, NUM_COMPOUND_SELECTORS, "-cmpd", compound_plugin_call}, #ifdef HAVE_ETH2 - {NULL, ETH2_SELECTORS, NUM_ETH2_SELECTORS, "-eth2", eth2_plugin_call}, + {NULL, (const uint8_t **)ETH2_SELECTORS, NUM_ETH2_SELECTORS, "-eth2", eth2_plugin_call}, #endif #ifdef HAVE_STARKWARE - {NULL, STARKWARE_SELECTORS, 10, "-strk", starkware_plugin_call}, + {NULL, (const uint8_t **)STARKWARE_SELECTORS, 10, "-strk", starkware_plugin_call}, #endif diff --git a/src/eth_plugin_ui.c b/src/eth_plugin_ui.c index 1d744fc..0d1fa5a 100644 --- a/src/eth_plugin_ui.c +++ b/src/eth_plugin_ui.c @@ -4,6 +4,7 @@ #endif #include "ui_callbacks.h" #include "eth_plugin_handler.h" +#include "ux.h" typedef enum { diff --git a/src/handle_get_printable_amount.c b/src/handle_get_printable_amount.c index b59dbf9..689b62e 100644 --- a/src/handle_get_printable_amount.c +++ b/src/handle_get_printable_amount.c @@ -5,6 +5,7 @@ #include "uint256.h" #include "string.h" #include +#include int handle_get_printable_amount(get_printable_amount_parameters_t* params, chain_config_t* config) { uint8_t decimals; From 9a798e36620faf01a52cf530686a2dc21bcbd560 Mon Sep 17 00:00:00 2001 From: pscott Date: Wed, 24 Mar 2021 16:32:08 +0100 Subject: [PATCH 3/5] Fix warnings for nanox sdk --- src/main.c | 4 +++- src_common/ethUstream.c | 1 + src_common/uint256.c | 2 +- src_features/getEth2PublicKey/cmd_getEth2PublicKey.c | 4 ++-- src_features/setEth2WithdrawalIndex/withdrawal_index.h | 8 ++++++++ src_features/signMessageEIP712/cmd_signMessage712.c | 4 ---- src_plugins/compound/compound_plugin.c | 2 +- src_plugins/erc721/erc721_plugin.c | 1 - src_plugins/starkware/starkware_plugin.c | 9 +++++---- 9 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 src_features/setEth2WithdrawalIndex/withdrawal_index.h diff --git a/src/main.c b/src/main.c index d939aff..0d95a07 100644 --- a/src/main.c +++ b/src/main.c @@ -54,8 +54,10 @@ bool called_from_swap; #ifdef HAVE_STARKWARE bool quantumSet; #endif + #ifdef HAVE_ETH2 -uint32_t eth2WithdrawalIndex; + uint32_t eth2WithdrawalIndex; + #include "withdrawal_index.h" #endif #include "ux.h" diff --git a/src_common/ethUstream.c b/src_common/ethUstream.c index f6f0ecd..d69116e 100644 --- a/src_common/ethUstream.c +++ b/src_common/ethUstream.c @@ -16,6 +16,7 @@ ********************************************************************************/ #include +#include #include "ethUstream.h" #include "ethUtils.h" diff --git a/src_common/uint256.c b/src_common/uint256.c index 0b32603..a15dca7 100644 --- a/src_common/uint256.c +++ b/src_common/uint256.c @@ -18,7 +18,7 @@ // Adapted from https://github.com/calccrypto/uint256_t #include -#include +#include #include "uint256.h" diff --git a/src_features/getEth2PublicKey/cmd_getEth2PublicKey.c b/src_features/getEth2PublicKey/cmd_getEth2PublicKey.c index d2845b3..a04fead 100644 --- a/src_features/getEth2PublicKey/cmd_getEth2PublicKey.c +++ b/src_features/getEth2PublicKey/cmd_getEth2PublicKey.c @@ -23,8 +23,8 @@ void getEth2PublicKey(uint32_t *bip32Path, uint8_t bip32PathLength, uint8_t *out io_seproxyhal_io_heartbeat(); memset(tmp, 0, 48); memmove(tmp + 16, privateKeyData, 32); - cx_ecfp_init_private_key(CX_CURVE_BLS12_381_G1, tmp, 48, &privateKey); - cx_ecfp_generate_pair(CX_CURVE_BLS12_381_G1, &publicKey, &privateKey, 1); + cx_ecfp_init_private_key(CX_CURVE_BLS12_381_G1, tmp, 48, (cx_ecfp_private_key_t *)&privateKey); + cx_ecfp_generate_pair(CX_CURVE_BLS12_381_G1, (cx_ecfp_public_key_t *)&publicKey, (cx_ecfp_private_key_t *)&privateKey, 1); explicit_bzero(tmp, 96); explicit_bzero((void *) &privateKey, sizeof(cx_ecfp_256_extended_private_key_t)); tmp[47] = 2; diff --git a/src_features/setEth2WithdrawalIndex/withdrawal_index.h b/src_features/setEth2WithdrawalIndex/withdrawal_index.h new file mode 100644 index 0000000..497b489 --- /dev/null +++ b/src_features/setEth2WithdrawalIndex/withdrawal_index.h @@ -0,0 +1,8 @@ +#include "stdint.h" + +void handleSetEth2WithdrawalIndex(uint8_t p1, + uint8_t p2, + uint8_t *dataBuffer, + uint16_t dataLength, + unsigned int *flags, + unsigned int *tx); \ No newline at end of file diff --git a/src_features/signMessageEIP712/cmd_signMessage712.c b/src_features/signMessageEIP712/cmd_signMessage712.c index d269909..bc9443e 100644 --- a/src_features/signMessageEIP712/cmd_signMessage712.c +++ b/src_features/signMessageEIP712/cmd_signMessage712.c @@ -3,10 +3,6 @@ #include "utils.h" #include "ui_flow.h" -static const char const SIGN_MAGIC[] = - "\x19" - "Ethereum Signed Message:\n"; - void handleSignEIP712Message(uint8_t p1, uint8_t p2, uint8_t *workBuffer, diff --git a/src_plugins/compound/compound_plugin.c b/src_plugins/compound/compound_plugin.c index a214343..90c2d4a 100644 --- a/src_plugins/compound/compound_plugin.c +++ b/src_plugins/compound/compound_plugin.c @@ -159,7 +159,7 @@ void compound_plugin_call(int message, void *parameters) { case COMPOUND_MINT: case CETH_MINT: msg->result = - get_underlying_asset_decimals(context->ticker_1, &context->decimals) + get_underlying_asset_decimals((char *)&context->ticker_1, &context->decimals) ? ETH_PLUGIN_RESULT_OK : ETH_PLUGIN_RESULT_FALLBACK; break; diff --git a/src_plugins/erc721/erc721_plugin.c b/src_plugins/erc721/erc721_plugin.c index 5577d67..812d88c 100644 --- a/src_plugins/erc721/erc721_plugin.c +++ b/src_plugins/erc721/erc721_plugin.c @@ -98,7 +98,6 @@ void erc721_plugin_call(int message, void *parameters) { case ETH_PLUGIN_PROVIDE_TOKEN: { ethPluginProvideToken_t *msg = (ethPluginProvideToken_t *) parameters; - erc721_parameters_t *context = (erc721_parameters_t *) msg->pluginContext; PRINTF("erc721 plugin provide token dest: %d - address: %d\n", (msg->token1 != NULL), (msg->token2 != NULL)); diff --git a/src_plugins/starkware/starkware_plugin.c b/src_plugins/starkware/starkware_plugin.c index 3e2e051..5bed1be 100644 --- a/src_plugins/starkware/starkware_plugin.c +++ b/src_plugins/starkware/starkware_plugin.c @@ -2,6 +2,8 @@ #include "eth_plugin_interface.h" #include "shared_context.h" // TODO : rewrite as independant code #include "eth_plugin_internal.h" // TODO : rewrite as independant code +#include "stark_utils.h" +#include "utils.h" #ifdef HAVE_STARKWARE @@ -156,7 +158,6 @@ typedef struct starkware_parameters_t { bool is_deversify_contract(const uint8_t *address) { uint32_t offset = 0; - uint8_t size = DEVERSIFI_CONTRACT[0]; uint8_t i; for (i = 0; i < DEVERSIFI_CONTRACT[0]; i++) { @@ -231,7 +232,7 @@ void starkware_print_stark_key(uint8_t *starkKey, char *destination) { void starkware_print_eth_address(uint8_t *address, char *destination) { destination[0] = '0'; destination[1] = 'x'; - getEthAddressStringFromBinary(address, destination + 2, &global_sha3, chainConfig); + getEthAddressStringFromBinary(address, (uint8_t *)(destination + 2), &global_sha3, chainConfig); destination[42] = '\0'; } @@ -313,7 +314,7 @@ void starkware_get_source_address(char *destination) { io_seproxyhal_io_heartbeat(); destination[0] = '0'; destination[1] = 'x'; - getEthAddressStringFromKey(&publicKey, destination + 2, &global_sha3, chainConfig); + getEthAddressStringFromKey(&publicKey, (uint8_t *)(destination + 2), &global_sha3, chainConfig); destination[42] = '\0'; } @@ -325,7 +326,7 @@ void starkware_plugin_call(int message, void *parameters) { starkware_parameters_t *context = (starkware_parameters_t *) msg->pluginContext; PRINTF("starkware plugin init\n"); for (i = 0; i < NUM_STARKWARE_SELECTORS; i++) { - if (memcmp(PIC(STARKWARE_SELECTORS[i]), msg->selector, SELECTOR_SIZE) == 0) { + if (memcmp((const void *)PIC(STARKWARE_SELECTORS[i]), msg->selector, SELECTOR_SIZE) == 0) { context->selectorIndex = i; break; } From 013538e9fe63662789583b973414dbb84aae3f7b Mon Sep 17 00:00:00 2001 From: pscott Date: Thu, 25 Mar 2021 10:43:59 +0100 Subject: [PATCH 4/5] Apply clang-format --- src/eth_plugin_handler.c | 4 ++-- src/eth_plugin_internal.c | 14 +++++++++----- src/main.c | 4 ++-- .../getEth2PublicKey/cmd_getEth2PublicKey.c | 7 +++++-- src_plugins/starkware/starkware_plugin.c | 14 +++++++++++--- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/eth_plugin_handler.c b/src/eth_plugin_handler.c index 74bc3c8..ccaa86e 100644 --- a/src/eth_plugin_handler.c +++ b/src/eth_plugin_handler.c @@ -64,13 +64,13 @@ int eth_plugin_perform_init(uint8_t *contractAddress, ethPluginInitContract_t *i PRINTF("Selector %.*H\n", 4, init->selector); for (i = 0;; i++) { uint8_t j; - selectors = (const uint8_t **)PIC(INTERNAL_ETH_PLUGINS[i].selectors); + selectors = (const uint8_t **) PIC(INTERNAL_ETH_PLUGINS[i].selectors); if (selectors == NULL) { break; } for (j = 0; ((j < INTERNAL_ETH_PLUGINS[i].num_selectors) && (contractAddress != NULL)); j++) { - if (memcmp(init->selector, (const void *)PIC(selectors[j]), SELECTOR_SIZE) == 0) { + if (memcmp(init->selector, (const void *) PIC(selectors[j]), SELECTOR_SIZE) == 0) { if ((INTERNAL_ETH_PLUGINS[i].availableCheck == NULL) || ((PluginAvailableCheck) PIC(INTERNAL_ETH_PLUGINS[i].availableCheck))()) { strcpy(dataContext.tokenContext.pluginName, INTERNAL_ETH_PLUGINS[i].alias); diff --git a/src/eth_plugin_internal.c b/src/eth_plugin_internal.c index 4cdb464..3619493 100644 --- a/src/eth_plugin_internal.c +++ b/src/eth_plugin_internal.c @@ -92,28 +92,32 @@ const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS] = { const internalEthPlugin_t const INTERNAL_ETH_PLUGINS[] = { {erc20_plugin_available_check, - (const uint8_t **)ERC20_SELECTORS, + (const uint8_t**) ERC20_SELECTORS, NUM_ERC20_SELECTORS, "-erc20", erc20_plugin_call}, {erc721_plugin_available_check, - (const uint8_t **)ERC721_SELECTORS, + (const uint8_t**) ERC721_SELECTORS, NUM_ERC721_SELECTORS, "-er721", erc721_plugin_call}, - {NULL, (const uint8_t **)COMPOUND_SELECTORS, NUM_COMPOUND_SELECTORS, "-cmpd", compound_plugin_call}, + {NULL, + (const uint8_t**) COMPOUND_SELECTORS, + NUM_COMPOUND_SELECTORS, + "-cmpd", + compound_plugin_call}, #ifdef HAVE_ETH2 - {NULL, (const uint8_t **)ETH2_SELECTORS, NUM_ETH2_SELECTORS, "-eth2", eth2_plugin_call}, + {NULL, (const uint8_t**) ETH2_SELECTORS, NUM_ETH2_SELECTORS, "-eth2", eth2_plugin_call}, #endif #ifdef HAVE_STARKWARE - {NULL, (const uint8_t **)STARKWARE_SELECTORS, 10, "-strk", starkware_plugin_call}, + {NULL, (const uint8_t**) STARKWARE_SELECTORS, 10, "-strk", starkware_plugin_call}, #endif diff --git a/src/main.c b/src/main.c index 0d95a07..5ec7870 100644 --- a/src/main.c +++ b/src/main.c @@ -56,8 +56,8 @@ bool quantumSet; #endif #ifdef HAVE_ETH2 - uint32_t eth2WithdrawalIndex; - #include "withdrawal_index.h" +uint32_t eth2WithdrawalIndex; +#include "withdrawal_index.h" #endif #include "ux.h" diff --git a/src_features/getEth2PublicKey/cmd_getEth2PublicKey.c b/src_features/getEth2PublicKey/cmd_getEth2PublicKey.c index a04fead..e584011 100644 --- a/src_features/getEth2PublicKey/cmd_getEth2PublicKey.c +++ b/src_features/getEth2PublicKey/cmd_getEth2PublicKey.c @@ -23,8 +23,11 @@ void getEth2PublicKey(uint32_t *bip32Path, uint8_t bip32PathLength, uint8_t *out io_seproxyhal_io_heartbeat(); memset(tmp, 0, 48); memmove(tmp + 16, privateKeyData, 32); - cx_ecfp_init_private_key(CX_CURVE_BLS12_381_G1, tmp, 48, (cx_ecfp_private_key_t *)&privateKey); - cx_ecfp_generate_pair(CX_CURVE_BLS12_381_G1, (cx_ecfp_public_key_t *)&publicKey, (cx_ecfp_private_key_t *)&privateKey, 1); + cx_ecfp_init_private_key(CX_CURVE_BLS12_381_G1, tmp, 48, (cx_ecfp_private_key_t *) &privateKey); + cx_ecfp_generate_pair(CX_CURVE_BLS12_381_G1, + (cx_ecfp_public_key_t *) &publicKey, + (cx_ecfp_private_key_t *) &privateKey, + 1); explicit_bzero(tmp, 96); explicit_bzero((void *) &privateKey, sizeof(cx_ecfp_256_extended_private_key_t)); tmp[47] = 2; diff --git a/src_plugins/starkware/starkware_plugin.c b/src_plugins/starkware/starkware_plugin.c index 5bed1be..b5f0d5f 100644 --- a/src_plugins/starkware/starkware_plugin.c +++ b/src_plugins/starkware/starkware_plugin.c @@ -232,7 +232,10 @@ void starkware_print_stark_key(uint8_t *starkKey, char *destination) { void starkware_print_eth_address(uint8_t *address, char *destination) { destination[0] = '0'; destination[1] = 'x'; - getEthAddressStringFromBinary(address, (uint8_t *)(destination + 2), &global_sha3, chainConfig); + getEthAddressStringFromBinary(address, + (uint8_t *) (destination + 2), + &global_sha3, + chainConfig); destination[42] = '\0'; } @@ -314,7 +317,10 @@ void starkware_get_source_address(char *destination) { io_seproxyhal_io_heartbeat(); destination[0] = '0'; destination[1] = 'x'; - getEthAddressStringFromKey(&publicKey, (uint8_t *)(destination + 2), &global_sha3, chainConfig); + getEthAddressStringFromKey(&publicKey, + (uint8_t *) (destination + 2), + &global_sha3, + chainConfig); destination[42] = '\0'; } @@ -326,7 +332,9 @@ void starkware_plugin_call(int message, void *parameters) { starkware_parameters_t *context = (starkware_parameters_t *) msg->pluginContext; PRINTF("starkware plugin init\n"); for (i = 0; i < NUM_STARKWARE_SELECTORS; i++) { - if (memcmp((const void *)PIC(STARKWARE_SELECTORS[i]), msg->selector, SELECTOR_SIZE) == 0) { + if (memcmp((const void *) PIC(STARKWARE_SELECTORS[i]), + msg->selector, + SELECTOR_SIZE) == 0) { context->selectorIndex = i; break; } From 75861077a36959c9dfe066efcfd7db6c5ac6cee1 Mon Sep 17 00:00:00 2001 From: pscott Date: Thu, 25 Mar 2021 10:44:58 +0100 Subject: [PATCH 5/5] Apply clang-format to compound_plugin --- src_plugins/compound/compound_plugin.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src_plugins/compound/compound_plugin.c b/src_plugins/compound/compound_plugin.c index 90c2d4a..5a0742d 100644 --- a/src_plugins/compound/compound_plugin.c +++ b/src_plugins/compound/compound_plugin.c @@ -158,10 +158,10 @@ void compound_plugin_call(int message, void *parameters) { case COMPOUND_REDEEM_UNDERLYING: case COMPOUND_MINT: case CETH_MINT: - msg->result = - get_underlying_asset_decimals((char *)&context->ticker_1, &context->decimals) - ? ETH_PLUGIN_RESULT_OK - : ETH_PLUGIN_RESULT_FALLBACK; + msg->result = get_underlying_asset_decimals((char *) &context->ticker_1, + &context->decimals) + ? ETH_PLUGIN_RESULT_OK + : ETH_PLUGIN_RESULT_FALLBACK; break; // Only case where we use the compound contract decimals