From 76c7f9dbd8a8ccf99eef8951d44300920e20e95e Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Mon, 7 Mar 2022 10:07:17 +0100 Subject: [PATCH 01/10] Fixes the location in memory of the address between nftInfo_t & tokenDefinition_t Both used as members of the same union, also unifies the type (array of uint8_t) --- src/nft.h | 14 +++------ src/tokens.h | 31 ++++++++----------- .../cmd_provideNFTInfo.c | 7 ++--- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/nft.h b/src/nft.h index 419f2c1..0ddda84 100644 --- a/src/nft.h +++ b/src/nft.h @@ -1,14 +1,8 @@ #include "tokens.h" -// An `nftInfo_t` must be the same size as a `tokenDefinition_t`. This is because both will be held -// in a `extraInfo_t` which is a union of a `nftInfo_t` and a `tokenDefinition_t`. By having both -// struct the same size, we know they will be aligned, which facilitates accessing the items. - -// We defined the collection name max length to be the size of a `tokenDefinition_t` and remove the -// `ADDRESS_LENGTH` which corresponds to `sizeof(contractAddress`). -#define COLLECTION_NAME_MAX_LEN (sizeof(tokenDefinition_t) - ADDRESS_LENGTH) +#define COLLECTION_NAME_MAX_LEN 70 typedef struct nftInfo_t { - char collectionName[COLLECTION_NAME_MAX_LEN]; - char contractAddress[ADDRESS_LENGTH]; -} nftInfo_t; \ No newline at end of file + uint8_t contractAddress[ADDRESS_LENGTH]; // must be first item + char collectionName[COLLECTION_NAME_MAX_LEN + 1]; +} nftInfo_t; diff --git a/src/tokens.h b/src/tokens.h index 4391d67..53a354e 100644 --- a/src/tokens.h +++ b/src/tokens.h @@ -25,14 +25,11 @@ #define MAX_ITEMS 2 typedef struct tokenDefinition_t { + uint8_t address[ADDRESS_LENGTH]; // must be first item #ifdef HAVE_CONTRACT_NAME_IN_DESCRIPTOR uint8_t contractName[ADDRESS_LENGTH]; #endif - uint8_t address[ADDRESS_LENGTH]; char ticker[MAX_TICKER_LEN]; - char nft_pad[20]; // Adding some padding because the `nftInfo_t` is based on the size of a - // `tokenDefinition_t`. By adding some padding here we give more space to the - // collection name in the `nftInfo_t`. See `nftInfo_t` for more information. uint8_t decimals; } tokenDefinition_t; @@ -46,25 +43,23 @@ extern tokenDefinition_t const TOKENS_EXTRA[NUM_TOKENS_EXTRA]; #ifndef HAVE_TOKENS_LIST +static const uint8_t LEDGER_SIGNATURE_PUBLIC_KEY[] = { #ifndef LEDGER_TEST_PUBLIC_KEY -static const uint8_t LEDGER_SIGNATURE_PUBLIC_KEY[] = { // production key 2019-01-11 03:07PM (erc20signer) - 0x04, 0x5e, 0x6c, 0x10, 0x20, 0xc1, 0x4d, 0xc4, 0x64, 0x42, 0xfe, 0x89, 0xf9, - 0x7c, 0x0b, 0x68, 0xcd, 0xb1, 0x59, 0x76, 0xdc, 0x24, 0xf2, 0x4c, 0x31, 0x6e, - 0x7b, 0x30, 0xfe, 0x4e, 0x8c, 0xc7, 0x6b, 0x14, 0x89, 0x15, 0x0c, 0x21, 0x51, - 0x4e, 0xbf, 0x44, 0x0f, 0xf5, 0xde, 0xa5, 0x39, 0x3d, 0x83, 0xde, 0x53, 0x58, - 0xcd, 0x09, 0x8f, 0xce, 0x8f, 0xd0, 0xf8, 0x1d, 0xaa, 0x94, 0x97, 0x91, 0x83}; - + 0x04, 0x5e, 0x6c, 0x10, 0x20, 0xc1, 0x4d, 0xc4, 0x64, 0x42, 0xfe, 0x89, 0xf9, 0x7c, + 0x0b, 0x68, 0xcd, 0xb1, 0x59, 0x76, 0xdc, 0x24, 0xf2, 0x4c, 0x31, 0x6e, 0x7b, 0x30, + 0xfe, 0x4e, 0x8c, 0xc7, 0x6b, 0x14, 0x89, 0x15, 0x0c, 0x21, 0x51, 0x4e, 0xbf, 0x44, + 0x0f, 0xf5, 0xde, 0xa5, 0x39, 0x3d, 0x83, 0xde, 0x53, 0x58, 0xcd, 0x09, 0x8f, 0xce, + 0x8f, 0xd0, 0xf8, 0x1d, 0xaa, 0x94, 0x97, 0x91, 0x83 #else -static const uint8_t LEDGER_SIGNATURE_PUBLIC_KEY[] = { // test key 2019-01-11 03:07PM (erc20signer) - 0x04, 0x20, 0xda, 0x62, 0x00, 0x3c, 0x0c, 0xe0, 0x97, 0xe3, 0x36, 0x44, 0xa1, - 0x0f, 0xe4, 0xc3, 0x04, 0x54, 0x06, 0x9a, 0x44, 0x54, 0xf0, 0xfa, 0x9d, 0x4e, - 0x84, 0xf4, 0x50, 0x91, 0x42, 0x9b, 0x52, 0x20, 0xaf, 0x9e, 0x35, 0xc0, 0xb2, - 0xd9, 0x28, 0x93, 0x80, 0x13, 0x73, 0x07, 0xde, 0x4d, 0xd1, 0xd4, 0x18, 0x42, - 0x8c, 0xf2, 0x1a, 0x93, 0xb3, 0x35, 0x61, 0xbb, 0x09, 0xd8, 0x8f, 0xe5, 0x79, -}; + 0x04, 0x20, 0xda, 0x62, 0x00, 0x3c, 0x0c, 0xe0, 0x97, 0xe3, 0x36, 0x44, 0xa1, 0x0f, + 0xe4, 0xc3, 0x04, 0x54, 0x06, 0x9a, 0x44, 0x54, 0xf0, 0xfa, 0x9d, 0x4e, 0x84, 0xf4, + 0x50, 0x91, 0x42, 0x9b, 0x52, 0x20, 0xaf, 0x9e, 0x35, 0xc0, 0xb2, 0xd9, 0x28, 0x93, + 0x80, 0x13, 0x73, 0x07, 0xde, 0x4d, 0xd1, 0xd4, 0x18, 0x42, 0x8c, 0xf2, 0x1a, 0x93, + 0xb3, 0x35, 0x61, 0xbb, 0x09, 0xd8, 0x8f, 0xe5, 0x79 #endif +}; #else diff --git a/src_features/provideNFTInformation/cmd_provideNFTInfo.c b/src_features/provideNFTInformation/cmd_provideNFTInfo.c index fefdd88..4a6161c 100644 --- a/src_features/provideNFTInformation/cmd_provideNFTInfo.c +++ b/src_features/provideNFTInformation/cmd_provideNFTInfo.c @@ -34,7 +34,6 @@ static const uint8_t LEDGER_NFT_METADATA_PUBLIC_KEY[] = { 0x7d, 0x0b, 0x46, 0x9a, 0x53, 0x11, 0xee, 0x6a, 0x1a, 0xcd, 0x1d, 0xa5, 0xaa, 0xb0, 0xf5, 0xc6, 0xdf, 0x13, 0x15, 0x8d, 0x28, 0xcc, 0x12, 0xd1, 0xdd, 0xa6, 0xec, 0xe9, 0x46, 0xb8, 0x9d, 0x5c, 0x05, 0x49, 0x92, 0x59, 0xc4 - #else 0x04, 0x98, 0x8d, 0xa6, 0xb2, 0x46, 0xf2, 0x8e, 0x77, 0xc1, 0xba, 0xb6, 0x75, 0xcb, 0x2a, 0x27, 0x44, 0xf7, 0xf5, 0xce, 0xc5, 0x6a, 0xe6, 0xe0, 0x32, 0x23, 0x33, 0x7b, @@ -117,10 +116,10 @@ void handleProvideNFTInformation(uint8_t p1, THROW(0x6A80); } - if (collectionNameLength + 1 > sizeof(nft->collectionName)) { + if (collectionNameLength > COLLECTION_NAME_MAX_LEN) { PRINTF("CollectionName too big: expected max %d, got %d\n", - sizeof(nft->collectionName), - collectionNameLength + 1); + COLLECTION_NAME_MAX_LEN, + collectionNameLength); THROW(0x6A80); } From 89070cd2bee4f50ec57001f1f7d6948d22c3d045 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Wed, 9 Mar 2022 11:47:38 +0100 Subject: [PATCH 02/10] Now only loops through tokens once to match it --- src/main.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main.c b/src/main.c index a06bac0..2b5c878 100644 --- a/src/main.c +++ b/src/main.c @@ -386,7 +386,8 @@ extraInfo_t *getKnownToken(uint8_t *contractAddress) { } } #endif - // + // Works for ERC-20 & NFT tokens since both structs in the union have the + // contract address aligned for (uint8_t i = 0; i < MAX_ITEMS; i++) { currentItem = (union extraInfo_t *) &tmpCtx.transactionContext.extraInfo[i].token; if (tmpCtx.transactionContext.tokenSet[i] && @@ -396,15 +397,6 @@ extraInfo_t *getKnownToken(uint8_t *contractAddress) { } } - for (uint8_t i = 0; i < MAX_ITEMS; i++) { - currentItem = (union extraInfo_t *) &tmpCtx.transactionContext.extraInfo[i].token; - if (tmpCtx.transactionContext.tokenSet[i] && - (memcmp(currentItem->nft.contractAddress, contractAddress, ADDRESS_LENGTH) == 0)) { - PRINTF("Token found at index %d\n", i); - return currentItem; - } - } - return NULL; } From c548aba364fd199d8eeaab3cc2fa9f1474d897e4 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Mon, 7 Mar 2022 14:21:32 +0100 Subject: [PATCH 03/10] Unify the include guards accross all header files --- src/apdu_constants.h | 5 +++++ src/chainConfig.h | 2 +- src/eth_plugin_handler.h | 5 +++-- src/eth_plugin_interface.h | 7 +++---- src/eth_plugin_internal.h | 5 +++-- src/nft.h | 5 +++++ src/poorstream.h | 6 +++--- src/shared_context.h | 7 +++---- src/stark_crypto.h | 6 +++--- src/stark_utils.h | 6 +++--- src/swap_lib_calls.h | 6 +++--- src/tokens.h | 2 +- src/ui_callbacks.h | 5 +++++ src/ui_flow.h | 5 +++++ src/utils.h | 2 +- src_common/ethUstream.h | 2 +- src_common/ethUtils.h | 2 +- src_common/network.h | 7 ++++++- src_common/uint256.h | 2 +- src_features/getEth2PublicKey/feature_getEth2PublicKey.h | 5 +++++ src_features/getPublicKey/feature_getPublicKey.h | 5 +++++ src_features/setEth2WithdrawalIndex/withdrawal_index.h | 7 ++++++- src_features/signTx/feature_signTx.h | 5 +++++ src_features/signTx/ui_plugin.h | 7 +++++-- .../stark_getPublicKey/feature_stark_getPublicKey.h | 5 +++++ src_plugins/erc1155/erc1155_plugin.h | 7 +++++-- src_plugins/erc721/erc721_plugin.h | 7 +++++-- 27 files changed, 97 insertions(+), 38 deletions(-) diff --git a/src/apdu_constants.h b/src/apdu_constants.h index f0c149b..474b29d 100644 --- a/src/apdu_constants.h +++ b/src/apdu_constants.h @@ -1,3 +1,6 @@ +#ifndef _APDU_CONSTANTS_H_ +#define _APDU_CONSTANTS_H_ + #include "shared_context.h" #define APP_FLAG_DATA_ALLOWED 0x01 @@ -156,3 +159,5 @@ void handleStarkwareUnsafeSign(uint8_t p1, unsigned int *tx); #endif + +#endif // _APDU_CONSTANTS_H_ diff --git a/src/chainConfig.h b/src/chainConfig.h index 733a1a6..0fe3834 100644 --- a/src/chainConfig.h +++ b/src/chainConfig.h @@ -69,4 +69,4 @@ typedef struct chain_config_s { #define ETHEREUM_MAINNET_CHAINID 1 -#endif /* _CHAIN_CONFIG_H_ */ +#endif // _CHAIN_CONFIG_H_ diff --git a/src/eth_plugin_handler.h b/src/eth_plugin_handler.h index 864c15c..76a7f1e 100644 --- a/src/eth_plugin_handler.h +++ b/src/eth_plugin_handler.h @@ -1,4 +1,5 @@ -#ifndef __ETH_PLUGIN_HANDLER_H__ +#ifndef _ETH_PLUGIN_HANDLER_H_ +#define _ETH_PLUGIN_HANDLER_H_ #include "eth_plugin_interface.h" @@ -27,4 +28,4 @@ eth_plugin_result_t eth_plugin_call(int method, void *parameter); void plugin_ui_start(void); -#endif +#endif // _ETH_PLUGIN_HANDLER_H_ diff --git a/src/eth_plugin_interface.h b/src/eth_plugin_interface.h index 31cbbde..f8b301c 100644 --- a/src/eth_plugin_interface.h +++ b/src/eth_plugin_interface.h @@ -1,6 +1,5 @@ -#ifndef __ETH_PLUGIN_INTERFACE_H__ - -#define __ETH_PLUGIN_INTERFACE_H__ +#ifndef _ETH_PLUGIN_INTERFACE_H_ +#define _ETH_PLUGIN_INTERFACE_H_ #include "os.h" #include "cx.h" @@ -179,4 +178,4 @@ typedef struct ethQueryContractUI_t { } ethQueryContractUI_t; -#endif +#endif // _ETH_PLUGIN_INTERFACE_H_ diff --git a/src/eth_plugin_internal.h b/src/eth_plugin_internal.h index 3285d73..f475797 100644 --- a/src/eth_plugin_internal.h +++ b/src/eth_plugin_internal.h @@ -1,4 +1,5 @@ -#ifndef __ETH_PLUGIN_INTERNAL_H__ +#ifndef _ETH_PLUGIN_INTERNAL_H_ +#define _ETH_PLUGIN_INTERNAL_H_ #include "eth_plugin_interface.h" @@ -45,4 +46,4 @@ extern const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS]; extern internalEthPlugin_t const INTERNAL_ETH_PLUGINS[]; -#endif +#endif // _ETH_PLUGIN_INTERNAL_H_ diff --git a/src/nft.h b/src/nft.h index 0ddda84..7c8b836 100644 --- a/src/nft.h +++ b/src/nft.h @@ -1,3 +1,6 @@ +#ifndef _NFT_H_ +#define _NFT_H_ + #include "tokens.h" #define COLLECTION_NAME_MAX_LEN 70 @@ -6,3 +9,5 @@ typedef struct nftInfo_t { uint8_t contractAddress[ADDRESS_LENGTH]; // must be first item char collectionName[COLLECTION_NAME_MAX_LEN + 1]; } nftInfo_t; + +#endif // _NFT_H_ diff --git a/src/poorstream.h b/src/poorstream.h index 7890687..6ac17a5 100644 --- a/src/poorstream.h +++ b/src/poorstream.h @@ -1,5 +1,5 @@ -#ifndef __POORSTREAM_H__ -#define __POORSTREAM_H__ +#ifndef _POORSTREAM_H_ +#define _POORSTREAM_H_ #include #include @@ -18,4 +18,4 @@ void poorstream_init(poorstream_t *stream, uint8_t *buffer); void poorstream_flush(poorstream_t *stream); void poorstream_write_bits(poorstream_t *stream, uint64_t bits, uint32_t num_bits); -#endif +#endif // _POORSTREAM_H_ diff --git a/src/shared_context.h b/src/shared_context.h index 43dc533..b8ea64b 100644 --- a/src/shared_context.h +++ b/src/shared_context.h @@ -1,6 +1,5 @@ -#ifndef __SHARED_CONTEXT_H__ - -#define __SHARED_CONTEXT_H__ +#ifndef _SHARED_CONTEXT_H_ +#define _SHARED_CONTEXT_H_ #include #include @@ -221,4 +220,4 @@ extern uint32_t eth2WithdrawalIndex; void reset_app_context(void); -#endif // __SHARED_CONTEXT_H__ +#endif // _SHARED_CONTEXT_H_ diff --git a/src/stark_crypto.h b/src/stark_crypto.h index 635cb79..5ce1be3 100644 --- a/src/stark_crypto.h +++ b/src/stark_crypto.h @@ -1,5 +1,5 @@ -#ifndef __STARK_CRYPTO_H__ -#define __STARK_CRYPTO_H__ +#ifndef _STARK_CRYPTO_H_ +#define _STARK_CRYPTO_H_ #include #include @@ -18,4 +18,4 @@ void pedersen(FieldElement res, /* out */ FieldElement a, FieldElement b); -#endif +#endif // _STARK_CRYPTO_H_ diff --git a/src/stark_utils.h b/src/stark_utils.h index aaf9d17..9ba69a2 100644 --- a/src/stark_utils.h +++ b/src/stark_utils.h @@ -1,5 +1,5 @@ -#ifndef __STARK_UTILS_H__ -#define __STARK_UTILS_H__ +#ifndef _STARK_UTILS_H_ +#define _STARK_UTILS_H_ #include #include @@ -32,4 +32,4 @@ int stark_sign(uint8_t *signature, /* out */ FieldElement msg, FieldElement condition); -#endif +#endif // _STARK_UTILS_H_ diff --git a/src/swap_lib_calls.h b/src/swap_lib_calls.h index c041964..937d610 100644 --- a/src/swap_lib_calls.h +++ b/src/swap_lib_calls.h @@ -1,5 +1,5 @@ -#ifndef SWAP_LIB_CALLS -#define SWAP_LIB_CALLS +#ifndef _SWAP_LIB_CALLS_H_ +#define _SWAP_LIB_CALLS_H_ #include "stdbool.h" @@ -50,4 +50,4 @@ typedef struct create_transaction_parameters_s { char* destination_address_extra_id; } create_transaction_parameters_t; -#endif +#endif // _SWAP_LIB_CALLS_H_ diff --git a/src/tokens.h b/src/tokens.h index 53a354e..ea69628 100644 --- a/src/tokens.h +++ b/src/tokens.h @@ -141,4 +141,4 @@ extern tokenDefinition_t const TOKENS_SHYFT[NUM_TOKENS_SHYFT]; #endif /* HAVE_TOKENS_LIST */ -#endif /* _TOKENS_H_ */ +#endif // _TOKENS_H_ diff --git a/src/ui_callbacks.h b/src/ui_callbacks.h index e7e78ab..a1a74cd 100644 --- a/src/ui_callbacks.h +++ b/src/ui_callbacks.h @@ -1,3 +1,6 @@ +#ifndef _UI_CALLBACKS_H_ +#define _UI_CALLBACKS_H_ + #include "shared_context.h" #include "ux.h" @@ -22,3 +25,5 @@ void io_seproxyhal_send_status(uint32_t sw); void format_signature_out(const uint8_t *signature); void finalizeParsing(bool direct); extraInfo_t *getKnownToken(uint8_t *contractAddress); + +#endif // _UI_CALLBACKS_H_ diff --git a/src/ui_flow.h b/src/ui_flow.h index 8797b95..aadc40d 100644 --- a/src/ui_flow.h +++ b/src/ui_flow.h @@ -1,3 +1,6 @@ +#ifndef _UI_FLOW_H_ +#define _UI_FLOW_H_ + #include "shared_context.h" #include "os_io_seproxyhal.h" @@ -52,3 +55,5 @@ extern const ux_flow_step_t* const ux_approval_starkware_verify_escape_flow[]; extern const ux_flow_step_t* const ux_stark_unsafe_sign_flow[]; #endif + +#endif // _UI_FLOW_H_ diff --git a/src/utils.h b/src/utils.h index be5ba3e..988ce08 100644 --- a/src/utils.h +++ b/src/utils.h @@ -41,4 +41,4 @@ void amountToString(const uint8_t* amount, bool parse_swap_config(uint8_t* config, uint8_t config_len, char* ticker, uint8_t* decimals); -#endif /* _UTILS_H_ */ \ No newline at end of file +#endif // _UTILS_H_ diff --git a/src_common/ethUstream.h b/src_common/ethUstream.h index e73cc95..f63dd65 100644 --- a/src_common/ethUstream.h +++ b/src_common/ethUstream.h @@ -164,4 +164,4 @@ parserStatus_e continueTx(txContext_t *context); void copyTxData(txContext_t *context, uint8_t *out, uint32_t length); uint8_t readTxByte(txContext_t *context); -#endif /* _ETHUSTREAM_H_ */ \ No newline at end of file +#endif // _ETHUSTREAM_H_ diff --git a/src_common/ethUtils.h b/src_common/ethUtils.h index 1099080..eadd639 100644 --- a/src_common/ethUtils.h +++ b/src_common/ethUtils.h @@ -87,4 +87,4 @@ static __attribute__((no_instrument_function)) inline int ismaxint(uint8_t *buf, static const char HEXDIGITS[] = "0123456789abcdef"; -#endif /* _ETHUTILS_H_ */ +#endif // _ETHUTILS_H_ diff --git a/src_common/network.h b/src_common/network.h index 7a6d2fc..8a4513a 100644 --- a/src_common/network.h +++ b/src_common/network.h @@ -1,3 +1,6 @@ +#ifndef _NETWORK_H_ +#define _NETWORK_H_ + #include #include "tokens.h" #include "shared_context.h" @@ -17,4 +20,6 @@ const network_info_t *get_network(void); // Returns a pointer to the network name, or NULL if there is none. const char *get_network_name(void); // Returns a pointer to the network ticker, or chainConfig->coinName if there is none. -const char *get_network_ticker(void); \ No newline at end of file +const char *get_network_ticker(void); + +#endif // _NETWORK_H_ diff --git a/src_common/uint256.h b/src_common/uint256.h index c55cd0c..5683c3e 100644 --- a/src_common/uint256.h +++ b/src_common/uint256.h @@ -73,4 +73,4 @@ void divmod256(uint256_t *l, uint256_t *r, uint256_t *div, uint256_t *mod); bool tostring128(uint128_t *number, uint32_t base, char *out, uint32_t outLength); bool tostring256(uint256_t *number, uint32_t base, char *out, uint32_t outLength); -#endif /* _UINT256_H_ */ \ No newline at end of file +#endif // _UINT256_H_ diff --git a/src_features/getEth2PublicKey/feature_getEth2PublicKey.h b/src_features/getEth2PublicKey/feature_getEth2PublicKey.h index 3b6dbe2..3d302f4 100644 --- a/src_features/getEth2PublicKey/feature_getEth2PublicKey.h +++ b/src_features/getEth2PublicKey/feature_getEth2PublicKey.h @@ -1,3 +1,8 @@ +#ifndef _GET_ETH2_PUB_KEY_H_ +#define _GET_ETH2_PUB_KEY_H_ + #include "shared_context.h" uint32_t set_result_get_eth2_publicKey(void); + +#endif // _GET_ETH2_PUB_KEY_H_ diff --git a/src_features/getPublicKey/feature_getPublicKey.h b/src_features/getPublicKey/feature_getPublicKey.h index e8e041a..8f819ba 100644 --- a/src_features/getPublicKey/feature_getPublicKey.h +++ b/src_features/getPublicKey/feature_getPublicKey.h @@ -1,3 +1,8 @@ +#ifndef _GET_PUB_KEY_H_ +#define _GET_PUB_KEY_H_ + #include "shared_context.h" uint32_t set_result_get_publicKey(void); + +#endif // _GET_PUB_KEY_H_ diff --git a/src_features/setEth2WithdrawalIndex/withdrawal_index.h b/src_features/setEth2WithdrawalIndex/withdrawal_index.h index 497b489..bf9d6a3 100644 --- a/src_features/setEth2WithdrawalIndex/withdrawal_index.h +++ b/src_features/setEth2WithdrawalIndex/withdrawal_index.h @@ -1,3 +1,6 @@ +#ifndef _SET_WITHDRAWAL_INDEX_H_ +#define _SET_WITHDRAWAL_INDEX_H_ + #include "stdint.h" void handleSetEth2WithdrawalIndex(uint8_t p1, @@ -5,4 +8,6 @@ void handleSetEth2WithdrawalIndex(uint8_t p1, uint8_t *dataBuffer, uint16_t dataLength, unsigned int *flags, - unsigned int *tx); \ No newline at end of file + unsigned int *tx); + +#endif // _SET_WITHDRAWAL_INDEX_H_ diff --git a/src_features/signTx/feature_signTx.h b/src_features/signTx/feature_signTx.h index 24400da..84d2cd5 100644 --- a/src_features/signTx/feature_signTx.h +++ b/src_features/signTx/feature_signTx.h @@ -1,3 +1,6 @@ +#ifndef _SIGN_TX_H_ +#define _SIGN_TX_H_ + #include "shared_context.h" typedef enum { @@ -12,3 +15,5 @@ void finalizeParsing(bool direct); void prepareFeeDisplay(); void prepareNetworkDisplay(); void ux_approve_tx(bool fromPlugin); + +#endif // _SIGN_TX_H_ diff --git a/src_features/signTx/ui_plugin.h b/src_features/signTx/ui_plugin.h index 28179b2..ae86b6a 100644 --- a/src_features/signTx/ui_plugin.h +++ b/src_features/signTx/ui_plugin.h @@ -1,5 +1,8 @@ -#pragma once +#ifndef _UI_PLUGIN_H_ +#define _UI_PLUGIN_H_ void plugin_ui_get_id(); void plugin_ui_get_item(); -void display_next_plugin_item(bool entering); \ No newline at end of file +void display_next_plugin_item(bool entering); + +#endif // _UI_PLUGIN_H_ diff --git a/src_features/stark_getPublicKey/feature_stark_getPublicKey.h b/src_features/stark_getPublicKey/feature_stark_getPublicKey.h index bb50747..4859722 100644 --- a/src_features/stark_getPublicKey/feature_stark_getPublicKey.h +++ b/src_features/stark_getPublicKey/feature_stark_getPublicKey.h @@ -1,3 +1,8 @@ +#ifndef _STARK_GET_PUB_KEY_H_ +#define _STARK_GET_PUB_KEY_H_ + #include "shared_context.h" uint32_t set_result_get_stark_publicKey(void); + +#endif // _STARK_GET_PUB_KEY_H_ diff --git a/src_plugins/erc1155/erc1155_plugin.h b/src_plugins/erc1155/erc1155_plugin.h index 0702fdf..691ebdf 100644 --- a/src_plugins/erc1155/erc1155_plugin.h +++ b/src_plugins/erc1155/erc1155_plugin.h @@ -1,6 +1,7 @@ -#ifdef HAVE_NFT_SUPPORT +#ifndef _ERC1155_PLUGIN_H_ +#define _ERC1155_PLUGIN_H_ -#pragma once +#ifdef HAVE_NFT_SUPPORT #include #include "eth_plugin_handler.h" @@ -53,3 +54,5 @@ void handle_provide_parameter_1155(void *parameters); void handle_query_contract_ui_1155(void *parameters); #endif // HAVE_NFT_SUPPORT + +#endif // _ERC1155_PLUGIN_H_ diff --git a/src_plugins/erc721/erc721_plugin.h b/src_plugins/erc721/erc721_plugin.h index 1846609..9c0f5c3 100644 --- a/src_plugins/erc721/erc721_plugin.h +++ b/src_plugins/erc721/erc721_plugin.h @@ -1,6 +1,7 @@ -#ifdef HAVE_NFT_SUPPORT +#ifndef _ERC721_PLUGIN_H_ +#define _ERC721_PLUGIN_H_ -#pragma once +#ifdef HAVE_NFT_SUPPORT #include #include "eth_plugin_handler.h" @@ -44,3 +45,5 @@ void handle_provide_parameter_721(void *parameters); void handle_query_contract_ui_721(void *parameters); #endif // HAVE_NFT_SUPPORT + +#endif // _ERC721_PLUGIN_H_ From 23202f6a6388c0516d685b5743663b7f306c0284 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Tue, 8 Mar 2022 17:59:36 +0100 Subject: [PATCH 04/10] Minimize includes in header files to what they depend on --- src/eth_plugin_internal.c | 1 + src/eth_plugin_internal.h | 2 ++ src/handle_swap_sign_transaction.c | 6 +++--- src/nft.h | 2 -- src/shared_context.h | 6 ------ src_features/getEth2PublicKey/logic_getEth2PublicKey.c | 3 ++- src_features/getPublicKey/logic_getPublicKey.c | 1 + src_features/signMessage/ui_common_signMessage.c | 1 + .../signMessageEIP712/ui_common_signMessage712.c | 1 + src_features/signTx/ui_common_signTx.c | 1 + .../stark_getPublicKey/logic_stark_getPublicKey.c | 3 ++- src_features/stark_sign/ui_common_stark_sign.c | 3 ++- .../stark_unsafe_sign/ui_common_stark_unsafe_sign.c | 3 ++- src_plugins/erc1155/erc1155_plugin.c | 2 ++ src_plugins/erc1155/erc1155_plugin.h | 9 ++++----- src_plugins/erc1155/erc1155_provide_parameters.c | 3 +++ src_plugins/erc1155/erc1155_ui.c | 4 ++++ src_plugins/erc721/erc721_plugin.c | 3 +++ src_plugins/erc721/erc721_plugin.h | 9 ++++----- src_plugins/erc721/erc721_ui.c | 4 ++++ src_plugins/starkware/starkware_plugin.c | 1 + 21 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/eth_plugin_internal.c b/src/eth_plugin_internal.c index c9858a8..0e28ca6 100644 --- a/src/eth_plugin_internal.c +++ b/src/eth_plugin_internal.c @@ -1,3 +1,4 @@ +#include #include "eth_plugin_internal.h" bool erc20_plugin_available_check(void); diff --git a/src/eth_plugin_internal.h b/src/eth_plugin_internal.h index f475797..4d26130 100644 --- a/src/eth_plugin_internal.h +++ b/src/eth_plugin_internal.h @@ -1,6 +1,8 @@ #ifndef _ETH_PLUGIN_INTERNAL_H_ #define _ETH_PLUGIN_INTERNAL_H_ +#include +#include #include "eth_plugin_interface.h" #define SELECTOR_SIZE 4 diff --git a/src/handle_swap_sign_transaction.c b/src/handle_swap_sign_transaction.c index d610e9e..75e4d3a 100644 --- a/src/handle_swap_sign_transaction.c +++ b/src/handle_swap_sign_transaction.c @@ -1,6 +1,6 @@ -#include "handle_swap_sign_transaction.h" -#include "usbd_core.h" +#include "os_io_seproxyhal.h" #include "ux.h" +#include "handle_swap_sign_transaction.h" #include "shared_context.h" #include "utils.h" @@ -79,4 +79,4 @@ void handle_swap_sign_transaction(chain_config_t* config) { BLE_power(1, "Nano X"); #endif // HAVE_BLE app_main(); -} \ No newline at end of file +} diff --git a/src/nft.h b/src/nft.h index 7c8b836..b8b9435 100644 --- a/src/nft.h +++ b/src/nft.h @@ -1,8 +1,6 @@ #ifndef _NFT_H_ #define _NFT_H_ -#include "tokens.h" - #define COLLECTION_NAME_MAX_LEN 70 typedef struct nftInfo_t { diff --git a/src/shared_context.h b/src/shared_context.h index b8ea64b..12b21f5 100644 --- a/src/shared_context.h +++ b/src/shared_context.h @@ -3,13 +3,7 @@ #include #include -#include - -#include "os.h" -#include "cx.h" -#include "os_io_seproxyhal.h" #include "ethUstream.h" -#include "uint256.h" #include "tokens.h" #include "chainConfig.h" #include "nft.h" diff --git a/src_features/getEth2PublicKey/logic_getEth2PublicKey.c b/src_features/getEth2PublicKey/logic_getEth2PublicKey.c index 9b112e2..6a0fc92 100644 --- a/src_features/getEth2PublicKey/logic_getEth2PublicKey.c +++ b/src_features/getEth2PublicKey/logic_getEth2PublicKey.c @@ -1,5 +1,6 @@ #ifdef HAVE_ETH2 +#include #include "shared_context.h" uint32_t set_result_get_eth2_publicKey() { @@ -9,4 +10,4 @@ uint32_t set_result_get_eth2_publicKey() { return tx; } -#endif +#endif // HAVE_ETH2 diff --git a/src_features/getPublicKey/logic_getPublicKey.c b/src_features/getPublicKey/logic_getPublicKey.c index d80896c..bc58e92 100644 --- a/src_features/getPublicKey/logic_getPublicKey.c +++ b/src_features/getPublicKey/logic_getPublicKey.c @@ -1,3 +1,4 @@ +#include #include "shared_context.h" uint32_t set_result_get_publicKey() { diff --git a/src_features/signMessage/ui_common_signMessage.c b/src_features/signMessage/ui_common_signMessage.c index 02b15c3..e2a901b 100644 --- a/src_features/signMessage/ui_common_signMessage.c +++ b/src_features/signMessage/ui_common_signMessage.c @@ -1,3 +1,4 @@ +#include "os_io_seproxyhal.h" #include "shared_context.h" #include "ui_callbacks.h" diff --git a/src_features/signMessageEIP712/ui_common_signMessage712.c b/src_features/signMessageEIP712/ui_common_signMessage712.c index db97137..e67cc4e 100644 --- a/src_features/signMessageEIP712/ui_common_signMessage712.c +++ b/src_features/signMessageEIP712/ui_common_signMessage712.c @@ -1,3 +1,4 @@ +#include "os_io_seproxyhal.h" #include "shared_context.h" #include "ui_callbacks.h" diff --git a/src_features/signTx/ui_common_signTx.c b/src_features/signTx/ui_common_signTx.c index 36a0bd9..3d27197 100644 --- a/src_features/signTx/ui_common_signTx.c +++ b/src_features/signTx/ui_common_signTx.c @@ -1,3 +1,4 @@ +#include "os_io_seproxyhal.h" #include "shared_context.h" #include "utils.h" #include "ui_callbacks.h" diff --git a/src_features/stark_getPublicKey/logic_stark_getPublicKey.c b/src_features/stark_getPublicKey/logic_stark_getPublicKey.c index 8c99cfd..9338cc4 100644 --- a/src_features/stark_getPublicKey/logic_stark_getPublicKey.c +++ b/src_features/stark_getPublicKey/logic_stark_getPublicKey.c @@ -1,5 +1,6 @@ #ifdef HAVE_STARKWARE +#include #include "shared_context.h" #include "feature_stark_getPublicKey.h" @@ -10,4 +11,4 @@ uint32_t set_result_get_stark_publicKey() { return tx; } -#endif +#endif // HAVE_STARKWARE diff --git a/src_features/stark_sign/ui_common_stark_sign.c b/src_features/stark_sign/ui_common_stark_sign.c index b5feede..533f67f 100644 --- a/src_features/stark_sign/ui_common_stark_sign.c +++ b/src_features/stark_sign/ui_common_stark_sign.c @@ -1,5 +1,6 @@ #ifdef HAVE_STARKWARE +#include "os_io_seproxyhal.h" #include "shared_context.h" #include "stark_utils.h" #include "ui_callbacks.h" @@ -32,4 +33,4 @@ unsigned int io_seproxyhal_touch_stark_ok(__attribute__((unused)) const bagl_ele return 0; // do not redraw the widget } -#endif +#endif // HAVE_STARKWARE diff --git a/src_features/stark_unsafe_sign/ui_common_stark_unsafe_sign.c b/src_features/stark_unsafe_sign/ui_common_stark_unsafe_sign.c index 2a75200..4c84e0b 100644 --- a/src_features/stark_unsafe_sign/ui_common_stark_unsafe_sign.c +++ b/src_features/stark_unsafe_sign/ui_common_stark_unsafe_sign.c @@ -1,5 +1,6 @@ #ifdef HAVE_STARKWARE +#include "os_io_seproxyhal.h" #include "shared_context.h" #include "stark_utils.h" #include "ui_callbacks.h" @@ -38,4 +39,4 @@ unsigned int io_seproxyhal_touch_stark_unsafe_sign_ok(__attribute__((unused)) return 0; // do not redraw the widget } -#endif +#endif // HAVE_STARKWARE diff --git a/src_plugins/erc1155/erc1155_plugin.c b/src_plugins/erc1155/erc1155_plugin.c index ea65515..9554497 100644 --- a/src_plugins/erc1155/erc1155_plugin.c +++ b/src_plugins/erc1155/erc1155_plugin.c @@ -1,7 +1,9 @@ #ifdef HAVE_NFT_SUPPORT +#include #include "erc1155_plugin.h" #include "eth_plugin_internal.h" +#include "ethUtils.h" static const uint8_t ERC1155_APPROVE_FOR_ALL_SELECTOR[SELECTOR_SIZE] = {0xa2, 0x2c, 0xb4, 0x65}; static const uint8_t ERC1155_SAFE_TRANSFER_SELECTOR[SELECTOR_SIZE] = {0xf2, 0x42, 0x43, 0x2a}; diff --git a/src_plugins/erc1155/erc1155_plugin.h b/src_plugins/erc1155/erc1155_plugin.h index 691ebdf..cb100c7 100644 --- a/src_plugins/erc1155/erc1155_plugin.h +++ b/src_plugins/erc1155/erc1155_plugin.h @@ -3,12 +3,11 @@ #ifdef HAVE_NFT_SUPPORT -#include -#include "eth_plugin_handler.h" -#include "shared_context.h" -#include "ethUtils.h" -#include "utils.h" +#include +#include +#include "ethUstream.h" #include "uint256.h" +#include "nft.h" // Internal plugin for EIP 1155: https://eips.ethereum.org/EIPS/eip-1155 diff --git a/src_plugins/erc1155/erc1155_provide_parameters.c b/src_plugins/erc1155/erc1155_provide_parameters.c index 800aafb..8b5e1ca 100644 --- a/src_plugins/erc1155/erc1155_provide_parameters.c +++ b/src_plugins/erc1155/erc1155_provide_parameters.c @@ -1,7 +1,10 @@ #ifdef HAVE_NFT_SUPPORT +#include #include "erc1155_plugin.h" #include "eth_plugin_internal.h" +#include "utils.h" +#include "ethUtils.h" static void handle_safe_transfer(ethPluginProvideParameter_t *msg, erc1155_context_t *context) { uint8_t new_value[INT256_LENGTH]; diff --git a/src_plugins/erc1155/erc1155_ui.c b/src_plugins/erc1155/erc1155_ui.c index e2679d4..2386793 100644 --- a/src_plugins/erc1155/erc1155_ui.c +++ b/src_plugins/erc1155/erc1155_ui.c @@ -1,6 +1,10 @@ #ifdef HAVE_NFT_SUPPORT +#include #include "erc1155_plugin.h" +#include "eth_plugin_interface.h" +#include "ethUtils.h" +#include "utils.h" static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc1155_context_t *context) { switch (msg->screenIndex) { diff --git a/src_plugins/erc721/erc721_plugin.c b/src_plugins/erc721/erc721_plugin.c index badddb3..449aa96 100644 --- a/src_plugins/erc721/erc721_plugin.c +++ b/src_plugins/erc721/erc721_plugin.c @@ -1,7 +1,10 @@ #ifdef HAVE_NFT_SUPPORT +#include #include "erc721_plugin.h" #include "eth_plugin_internal.h" +#include "eth_plugin_interface.h" +#include "ethUtils.h" static const uint8_t ERC721_APPROVE_SELECTOR[SELECTOR_SIZE] = {0x09, 0x5e, 0xa7, 0xb3}; static const uint8_t ERC721_APPROVE_FOR_ALL_SELECTOR[SELECTOR_SIZE] = {0xa2, 0x2c, 0xb4, 0x65}; diff --git a/src_plugins/erc721/erc721_plugin.h b/src_plugins/erc721/erc721_plugin.h index 9c0f5c3..17515f3 100644 --- a/src_plugins/erc721/erc721_plugin.h +++ b/src_plugins/erc721/erc721_plugin.h @@ -3,11 +3,10 @@ #ifdef HAVE_NFT_SUPPORT -#include -#include "eth_plugin_handler.h" -#include "shared_context.h" -#include "ethUtils.h" -#include "utils.h" +#include +#include +#include "ethUstream.h" +#include "nft.h" // Internal plugin for EIP 721: https://eips.ethereum.org/EIPS/eip-721 diff --git a/src_plugins/erc721/erc721_ui.c b/src_plugins/erc721/erc721_ui.c index ce0c4f5..a968aa6 100644 --- a/src_plugins/erc721/erc721_ui.c +++ b/src_plugins/erc721/erc721_ui.c @@ -1,6 +1,10 @@ #ifdef HAVE_NFT_SUPPORT +#include #include "erc721_plugin.h" +#include "eth_plugin_interface.h" +#include "ethUtils.h" +#include "utils.h" static void set_approval_ui(ethQueryContractUI_t *msg, erc721_context_t *context) { switch (msg->screenIndex) { diff --git a/src_plugins/starkware/starkware_plugin.c b/src_plugins/starkware/starkware_plugin.c index 11f7d8e..9800f7c 100644 --- a/src_plugins/starkware/starkware_plugin.c +++ b/src_plugins/starkware/starkware_plugin.c @@ -1,4 +1,5 @@ #include +#include "os_io_seproxyhal.h" #include "eth_plugin_interface.h" #include "shared_context.h" // TODO : rewrite as independant code #include "eth_plugin_internal.h" // TODO : rewrite as independant code From 7e1c8b14d43200d74c99fb667a15f7dd99525aef Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Tue, 8 Mar 2022 18:19:07 +0100 Subject: [PATCH 05/10] Small refactoring on number of NFT selectors --- src_plugins/erc1155/erc1155_plugin.c | 6 +++--- src_plugins/erc1155/erc1155_plugin.h | 3 +-- src_plugins/erc721/erc721_plugin.c | 6 +++--- src_plugins/erc721/erc721_plugin.h | 3 +-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src_plugins/erc1155/erc1155_plugin.c b/src_plugins/erc1155/erc1155_plugin.c index 9554497..9fa73f6 100644 --- a/src_plugins/erc1155/erc1155_plugin.c +++ b/src_plugins/erc1155/erc1155_plugin.c @@ -9,7 +9,7 @@ static const uint8_t ERC1155_APPROVE_FOR_ALL_SELECTOR[SELECTOR_SIZE] = {0xa2, 0x static const uint8_t ERC1155_SAFE_TRANSFER_SELECTOR[SELECTOR_SIZE] = {0xf2, 0x42, 0x43, 0x2a}; static const uint8_t ERC1155_SAFE_BATCH_TRANSFER[SELECTOR_SIZE] = {0x2e, 0xb2, 0xc2, 0xd6}; -const uint8_t *const ERC1155_SELECTORS[NUM_ERC1155_SELECTORS] = { +const uint8_t *const ERC1155_SELECTORS[SELECTORS_COUNT] = { ERC1155_APPROVE_FOR_ALL_SELECTOR, ERC1155_SAFE_TRANSFER_SELECTOR, ERC1155_SAFE_BATCH_TRANSFER, @@ -20,7 +20,7 @@ static void handle_init_contract(void *parameters) { erc1155_context_t *context = (erc1155_context_t *) msg->pluginContext; uint8_t i; - for (i = 0; i < NUM_ERC1155_SELECTORS; i++) { + for (i = 0; i < SELECTORS_COUNT; i++) { if (memcmp((uint8_t *) PIC(ERC1155_SELECTORS[i]), msg->selector, SELECTOR_SIZE) == 0) { context->selectorIndex = i; break; @@ -28,7 +28,7 @@ static void handle_init_contract(void *parameters) { } // No selector found. - if (i == NUM_ERC1155_SELECTORS) { + if (i == SELECTORS_COUNT) { PRINTF("Unknown erc1155 selector %.*H\n", SELECTOR_SIZE, msg->selector); msg->result = ETH_PLUGIN_RESULT_FALLBACK; return; diff --git a/src_plugins/erc1155/erc1155_plugin.h b/src_plugins/erc1155/erc1155_plugin.h index cb100c7..eb174bd 100644 --- a/src_plugins/erc1155/erc1155_plugin.h +++ b/src_plugins/erc1155/erc1155_plugin.h @@ -11,12 +11,11 @@ // Internal plugin for EIP 1155: https://eips.ethereum.org/EIPS/eip-1155 -#define NUM_ERC1155_SELECTORS 3 - typedef enum { SET_APPROVAL_FOR_ALL, SAFE_TRANSFER, SAFE_BATCH_TRANSFER, + SELECTORS_COUNT } erc1155_selector_t; typedef enum { diff --git a/src_plugins/erc721/erc721_plugin.c b/src_plugins/erc721/erc721_plugin.c index 449aa96..e802a54 100644 --- a/src_plugins/erc721/erc721_plugin.c +++ b/src_plugins/erc721/erc721_plugin.c @@ -12,7 +12,7 @@ static const uint8_t ERC721_TRANSFER_SELECTOR[SELECTOR_SIZE] = {0x23, 0xb8, 0x72 static const uint8_t ERC721_SAFE_TRANSFER_SELECTOR[SELECTOR_SIZE] = {0x42, 0x84, 0x2e, 0x0e}; static const uint8_t ERC721_SAFE_TRANSFER_DATA_SELECTOR[SELECTOR_SIZE] = {0xb8, 0x8d, 0x4f, 0xde}; -const uint8_t *const ERC721_SELECTORS[NUM_ERC721_SELECTORS] = { +const uint8_t *const ERC721_SELECTORS[SELECTORS_COUNT] = { ERC721_APPROVE_SELECTOR, ERC721_APPROVE_FOR_ALL_SELECTOR, ERC721_TRANSFER_SELECTOR, @@ -25,7 +25,7 @@ static void handle_init_contract(void *parameters) { erc721_context_t *context = (erc721_context_t *) msg->pluginContext; uint8_t i; - for (i = 0; i < NUM_ERC721_SELECTORS; i++) { + for (i = 0; i < SELECTORS_COUNT; i++) { if (memcmp((uint8_t *) PIC(ERC721_SELECTORS[i]), msg->selector, SELECTOR_SIZE) == 0) { context->selectorIndex = i; break; @@ -33,7 +33,7 @@ static void handle_init_contract(void *parameters) { } // No selector found. - if (i == NUM_ERC721_SELECTORS) { + if (i == SELECTORS_COUNT) { PRINTF("Unknown erc721 selector %.*H\n", SELECTOR_SIZE, msg->selector); msg->result = ETH_PLUGIN_RESULT_FALLBACK; return; diff --git a/src_plugins/erc721/erc721_plugin.h b/src_plugins/erc721/erc721_plugin.h index 17515f3..62870fa 100644 --- a/src_plugins/erc721/erc721_plugin.h +++ b/src_plugins/erc721/erc721_plugin.h @@ -10,14 +10,13 @@ // Internal plugin for EIP 721: https://eips.ethereum.org/EIPS/eip-721 -#define NUM_ERC721_SELECTORS 5 - typedef enum { APPROVE, SET_APPROVAL_FOR_ALL, TRANSFER, SAFE_TRANSFER, SAFE_TRANSFER_DATA, + SELECTORS_COUNT } erc721_selector_t; typedef enum { From fed91e2261f37d1de07f6b5fe1bf882186339da6 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Wed, 9 Mar 2022 10:15:51 +0100 Subject: [PATCH 06/10] Removed old os_strcmp function --- src/handle_check_address.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/handle_check_address.c b/src/handle_check_address.c index 48b6b94..274582a 100644 --- a/src/handle_check_address.c +++ b/src/handle_check_address.c @@ -6,11 +6,6 @@ #define ZERO(x) memset(&x, 0, sizeof(x)) -static int os_strcmp(const char* s1, const char* s2) { - size_t size = strlen(s1) + 1; - return memcmp(s1, s2, size); -} - int handle_check_address(check_address_parameters_t* params, chain_config_t* chain_config) { PRINTF("Params on the address %d\n", (unsigned int) params); PRINTF("Address to check %s\n", params->address_to_check); @@ -69,7 +64,7 @@ int handle_check_address(check_address_parameters_t* params, chain_config_t* cha offset_0x = 2; } - if (os_strcmp(locals_union1.address, params->address_to_check + offset_0x) != 0) { + if (strcmp(locals_union1.address, params->address_to_check + offset_0x) != 0) { PRINTF("Addresses don't match\n"); return 0; } From 853a85205d52d6bb5760fd05eb5bf41aa06ade6a Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Wed, 9 Mar 2022 11:51:50 +0100 Subject: [PATCH 07/10] Now checks if a proper plugin is loaded when receiving NFT metadata --- src_features/provideNFTInformation/cmd_provideNFTInfo.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src_features/provideNFTInformation/cmd_provideNFTInfo.c b/src_features/provideNFTInformation/cmd_provideNFTInfo.c index 4a6161c..e7fea89 100644 --- a/src_features/provideNFTInformation/cmd_provideNFTInfo.c +++ b/src_features/provideNFTInformation/cmd_provideNFTInfo.c @@ -63,8 +63,12 @@ void handleProvideNFTInformation(uint8_t p1, UNUSED(flags); uint8_t hash[INT256_LENGTH]; cx_ecfp_public_key_t nftKey; - PRINTF("In handle provide NFTInformation"); + PRINTF("In handle provide NFTInformation\n"); + if ((pluginType != ERC721) && (pluginType != ERC1155)) { + PRINTF("NFT metadata provided without proper plugin loaded!\n"); + THROW(0x6985); + } tmpCtx.transactionContext.currentItemIndex = (tmpCtx.transactionContext.currentItemIndex + 1) % MAX_ITEMS; nftInfo_t *nft = From a26da165df6fbf9b3158545fd6aa591ceb2b47a6 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Wed, 9 Mar 2022 15:03:38 +0100 Subject: [PATCH 08/10] Now prevents NFT signatures without NFT metadata --- src/eth_plugin_handler.c | 4 ++-- src/eth_plugin_handler.h | 3 +++ src/nft.h | 3 +++ src_plugins/erc1155/erc1155_plugin.c | 6 ++++++ src_plugins/erc721/erc721_plugin.c | 6 ++++++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/eth_plugin_handler.c b/src/eth_plugin_handler.c index accc232..8058c11 100644 --- a/src/eth_plugin_handler.c +++ b/src/eth_plugin_handler.c @@ -48,14 +48,14 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI, memset((uint8_t *) queryContractUI, 0, sizeof(ethQueryContractUI_t)); // If no extra information was found, set the pointer to NULL - if (allzeroes(&tmpCtx.transactionContext.extraInfo[1], sizeof(union extraInfo_t))) { + if (NO_EXTRA_INFO(tmpCtx, 1)) { queryContractUI->item1 = NULL; } else { queryContractUI->item1 = &tmpCtx.transactionContext.extraInfo[1]; } // If no extra information was found, set the pointer to NULL - if (allzeroes(&tmpCtx.transactionContext.extraInfo[0], sizeof(union extraInfo_t))) { + if (NO_EXTRA_INFO(tmpCtx, 0)) { queryContractUI->item2 = NULL; } else { queryContractUI->item2 = &tmpCtx.transactionContext.extraInfo[0]; diff --git a/src/eth_plugin_handler.h b/src/eth_plugin_handler.h index 76a7f1e..ba6ffee 100644 --- a/src/eth_plugin_handler.h +++ b/src/eth_plugin_handler.h @@ -3,6 +3,9 @@ #include "eth_plugin_interface.h" +#define NO_EXTRA_INFO(ctx, idx) \ + (allzeroes(&(ctx.transactionContext.extraInfo[idx]), sizeof(extraInfo_t))) + void eth_plugin_prepare_init(ethPluginInitContract_t *init, uint8_t *selector, uint32_t dataSize); void eth_plugin_prepare_provide_parameter(ethPluginProvideParameter_t *provideParameter, uint8_t *parameter, diff --git a/src/nft.h b/src/nft.h index b8b9435..43ee5d1 100644 --- a/src/nft.h +++ b/src/nft.h @@ -1,7 +1,10 @@ #ifndef _NFT_H_ #define _NFT_H_ +#include + #define COLLECTION_NAME_MAX_LEN 70 +#define NO_NFT_METADATA (NO_EXTRA_INFO(tmpCtx, 1)) typedef struct nftInfo_t { uint8_t contractAddress[ADDRESS_LENGTH]; // must be first item diff --git a/src_plugins/erc1155/erc1155_plugin.c b/src_plugins/erc1155/erc1155_plugin.c index 9fa73f6..4c530da 100644 --- a/src_plugins/erc1155/erc1155_plugin.c +++ b/src_plugins/erc1155/erc1155_plugin.c @@ -4,6 +4,7 @@ #include "erc1155_plugin.h" #include "eth_plugin_internal.h" #include "ethUtils.h" +#include "eth_plugin_handler.h" static const uint8_t ERC1155_APPROVE_FOR_ALL_SELECTOR[SELECTOR_SIZE] = {0xa2, 0x2c, 0xb4, 0x65}; static const uint8_t ERC1155_SAFE_TRANSFER_SELECTOR[SELECTOR_SIZE] = {0xf2, 0x42, 0x43, 0x2a}; @@ -19,6 +20,11 @@ static void handle_init_contract(void *parameters) { ethPluginInitContract_t *msg = (ethPluginInitContract_t *) parameters; erc1155_context_t *context = (erc1155_context_t *) msg->pluginContext; + if (NO_NFT_METADATA) { + PRINTF("No NFT metadata when trying to sign!\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + return; + } uint8_t i; for (i = 0; i < SELECTORS_COUNT; i++) { if (memcmp((uint8_t *) PIC(ERC1155_SELECTORS[i]), msg->selector, SELECTOR_SIZE) == 0) { diff --git a/src_plugins/erc721/erc721_plugin.c b/src_plugins/erc721/erc721_plugin.c index e802a54..12a0a92 100644 --- a/src_plugins/erc721/erc721_plugin.c +++ b/src_plugins/erc721/erc721_plugin.c @@ -5,6 +5,7 @@ #include "eth_plugin_internal.h" #include "eth_plugin_interface.h" #include "ethUtils.h" +#include "eth_plugin_handler.h" static const uint8_t ERC721_APPROVE_SELECTOR[SELECTOR_SIZE] = {0x09, 0x5e, 0xa7, 0xb3}; static const uint8_t ERC721_APPROVE_FOR_ALL_SELECTOR[SELECTOR_SIZE] = {0xa2, 0x2c, 0xb4, 0x65}; @@ -24,6 +25,11 @@ static void handle_init_contract(void *parameters) { ethPluginInitContract_t *msg = (ethPluginInitContract_t *) parameters; erc721_context_t *context = (erc721_context_t *) msg->pluginContext; + if (NO_NFT_METADATA) { + PRINTF("No NFT metadata when trying to sign!\n"); + msg->result = ETH_PLUGIN_RESULT_ERROR; + return; + } uint8_t i; for (i = 0; i < SELECTORS_COUNT; i++) { if (memcmp((uint8_t *) PIC(ERC721_SELECTORS[i]), msg->selector, SELECTOR_SIZE) == 0) { From fb28efc012978312820814e502cb97429787c696 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Wed, 9 Mar 2022 15:36:03 +0100 Subject: [PATCH 09/10] Removed the helper getNftContractAddress helper function and some NULL checks Useless since we don't allow NFT signing without the NFT metadata anymore --- src_common/ethUtils.c | 6 ------ src_common/ethUtils.h | 3 --- src_plugins/erc1155/erc1155_ui.c | 24 ++++++------------------ src_plugins/erc721/erc721_ui.c | 24 ++++++------------------ 4 files changed, 12 insertions(+), 45 deletions(-) diff --git a/src_common/ethUtils.c b/src_common/ethUtils.c index 4239136..804837c 100644 --- a/src_common/ethUtils.c +++ b/src_common/ethUtils.c @@ -237,12 +237,6 @@ void getEthDisplayableAddress(uint8_t *in, getEthAddressStringFromBinary(in, out + 2, sha3, chainId); } -uint8_t *getNftContractAddress(const ethQueryContractUI_t *const msg) { - // In case of no PROVIDE_NFT_INFO, we already have the address from the SET_PLUGIN - return ((msg->item1) ? ((uint8_t *) msg->item1->nft.contractAddress) - : msg->pluginSharedRO->txContent->destination); -} - bool adjustDecimals(const char *src, size_t srcLength, char *target, diff --git a/src_common/ethUtils.h b/src_common/ethUtils.h index eadd639..3c147cc 100644 --- a/src_common/ethUtils.h +++ b/src_common/ethUtils.h @@ -22,7 +22,6 @@ #include "cx.h" #include "chainConfig.h" -#include "eth_plugin_interface.h" /** * @brief Decode an RLP encoded field - see @@ -59,8 +58,6 @@ void getEthDisplayableAddress(uint8_t *in, cx_sha3_t *sha3, uint64_t chainId); -uint8_t *getNftContractAddress(const ethQueryContractUI_t *const msg); - bool adjustDecimals(const char *src, size_t srcLength, char *target, diff --git a/src_plugins/erc1155/erc1155_ui.c b/src_plugins/erc1155/erc1155_ui.c index 2386793..4306704 100644 --- a/src_plugins/erc1155/erc1155_ui.c +++ b/src_plugins/erc1155/erc1155_ui.c @@ -22,15 +22,11 @@ static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc1155_context_t break; case 1: strlcpy(msg->title, "To Manage ALL", msg->titleLength); - if (msg->item1) { - strlcpy(msg->msg, (const char *) &msg->item1->nft.collectionName, msg->msgLength); - } else { - strlcpy(msg->msg, "Not found", msg->msgLength); - } + strlcpy(msg->msg, msg->item1->nft.collectionName, msg->msgLength); break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - getEthDisplayableAddress(getNftContractAddress(msg), + getEthDisplayableAddress(msg->item1->nft.contractAddress, msg->msg, msg->msgLength, &global_sha3, @@ -55,15 +51,11 @@ static void set_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *contex break; case 1: strlcpy(msg->title, "Collection Name", msg->titleLength); - if (msg->item1) { - strlcpy(msg->msg, (const char *) &msg->item1->nft.collectionName, msg->msgLength); - } else { - strlcpy(msg->msg, "Not Found", msg->msgLength); - } + strlcpy(msg->msg, msg->item1->nft.collectionName, msg->msgLength); break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - getEthDisplayableAddress(getNftContractAddress(msg), + getEthDisplayableAddress(msg->item1->nft.contractAddress, msg->msg, msg->msgLength, &global_sha3, @@ -101,15 +93,11 @@ static void set_batch_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t * break; case 1: strlcpy(msg->title, "Collection Name", msg->titleLength); - if (msg->item1) { - strlcpy(msg->msg, (const char *) &msg->item1->nft.collectionName, msg->msgLength); - } else { - strlcpy(msg->msg, "Not Found", msg->msgLength); - } + strlcpy(msg->msg, msg->item1->nft.collectionName, msg->msgLength); break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - getEthDisplayableAddress(getNftContractAddress(msg), + getEthDisplayableAddress(msg->item1->nft.contractAddress, msg->msg, msg->msgLength, &global_sha3, diff --git a/src_plugins/erc721/erc721_ui.c b/src_plugins/erc721/erc721_ui.c index a968aa6..8fc4c59 100644 --- a/src_plugins/erc721/erc721_ui.c +++ b/src_plugins/erc721/erc721_ui.c @@ -18,15 +18,11 @@ static void set_approval_ui(ethQueryContractUI_t *msg, erc721_context_t *context break; case 1: strlcpy(msg->title, "To Manage Your", msg->titleLength); - if (msg->item1) { - strlcpy(msg->msg, (const char *) &msg->item1->nft.collectionName, msg->msgLength); - } else { - strlcpy(msg->msg, "Not Found", msg->msgLength); - } + strlcpy(msg->msg, msg->item1->nft.collectionName, msg->msgLength); break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - getEthDisplayableAddress(getNftContractAddress(msg), + getEthDisplayableAddress(msg->item1->nft.contractAddress, msg->msg, msg->msgLength, &global_sha3, @@ -62,15 +58,11 @@ static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc721_context_t break; case 1: strlcpy(msg->title, "To Manage ALL", msg->titleLength); - if (msg->item1) { - strlcpy(msg->msg, (const char *) &msg->item1->nft.collectionName, msg->msgLength); - } else { - strlcpy(msg->msg, "Not found", msg->msgLength); - } + strlcpy(msg->msg, msg->item1->nft.collectionName, msg->msgLength); break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - getEthDisplayableAddress(getNftContractAddress(msg), + getEthDisplayableAddress(msg->item1->nft.contractAddress, msg->msg, msg->msgLength, &global_sha3, @@ -95,15 +87,11 @@ static void set_transfer_ui(ethQueryContractUI_t *msg, erc721_context_t *context break; case 1: strlcpy(msg->title, "Collection Name", msg->titleLength); - if (msg->item1) { - strlcpy(msg->msg, (const char *) &msg->item1->nft.collectionName, msg->msgLength); - } else { - strlcpy(msg->msg, "Not Found", msg->msgLength); - } + strlcpy(msg->msg, msg->item1->nft.collectionName, msg->msgLength); break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - getEthDisplayableAddress(getNftContractAddress(msg), + getEthDisplayableAddress(msg->item1->nft.contractAddress, msg->msg, msg->msgLength, &global_sha3, From 8739b29338e196b0a0f4d0959216eb7b39fa3a06 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Wed, 9 Mar 2022 16:12:25 +0100 Subject: [PATCH 10/10] Updated the NFT Zemu tests --- .../nanox_erc1155_transfer_wo_info/00000.png | 1 - .../nanox_erc1155_transfer_wo_info/00001.png | 1 - .../nanox_erc1155_transfer_wo_info/00002.png | 1 - .../nanox_erc1155_transfer_wo_info/00003.png | Bin 457 -> 0 bytes .../nanox_erc1155_transfer_wo_info/00004.png | 1 - .../nanox_erc1155_transfer_wo_info/00005.png | 1 - .../nanox_erc1155_transfer_wo_info/00006.png | 1 - .../nanox_erc1155_transfer_wo_info/00007.png | 1 - .../nanox_erc1155_transfer_wo_info/00008.png | 1 - .../nanox_erc1155_transfer_wo_info/00009.png | 1 - .../nanox_erc1155_transfer_wo_info/00010.png | 1 - .../nanox_erc1155_transfer_wo_info/00011.png | 1 - .../nanox_erc1155_transfer_wo_info/00012.png | 1 - .../nanox_erc721_transfer_wo_info/00000.png | 1 - .../nanox_erc721_transfer_wo_info/00001.png | 1 - .../nanox_erc721_transfer_wo_info/00002.png | 1 - .../nanox_erc721_transfer_wo_info/00003.png | Bin 457 -> 0 bytes .../nanox_erc721_transfer_wo_info/00004.png | 1 - .../nanox_erc721_transfer_wo_info/00005.png | 1 - .../nanox_erc721_transfer_wo_info/00006.png | 1 - .../nanox_erc721_transfer_wo_info/00007.png | 1 - .../nanox_erc721_transfer_wo_info/00008.png | 1 - .../nanox_erc721_transfer_wo_info/00009.png | 1 - .../nanox_erc721_transfer_wo_info/00010.png | 1 - tests/src/erc1155.test.js | 48 ++++++++---------- tests/src/erc721.test.js | 21 +++----- 26 files changed, 30 insertions(+), 61 deletions(-) delete mode 120000 tests/snapshots/nanox_erc1155_transfer_wo_info/00000.png delete mode 120000 tests/snapshots/nanox_erc1155_transfer_wo_info/00001.png delete mode 120000 tests/snapshots/nanox_erc1155_transfer_wo_info/00002.png delete mode 100644 tests/snapshots/nanox_erc1155_transfer_wo_info/00003.png delete mode 120000 tests/snapshots/nanox_erc1155_transfer_wo_info/00004.png delete mode 120000 tests/snapshots/nanox_erc1155_transfer_wo_info/00005.png delete mode 120000 tests/snapshots/nanox_erc1155_transfer_wo_info/00006.png delete mode 120000 tests/snapshots/nanox_erc1155_transfer_wo_info/00007.png delete mode 120000 tests/snapshots/nanox_erc1155_transfer_wo_info/00008.png delete mode 120000 tests/snapshots/nanox_erc1155_transfer_wo_info/00009.png delete mode 120000 tests/snapshots/nanox_erc1155_transfer_wo_info/00010.png delete mode 120000 tests/snapshots/nanox_erc1155_transfer_wo_info/00011.png delete mode 120000 tests/snapshots/nanox_erc1155_transfer_wo_info/00012.png delete mode 120000 tests/snapshots/nanox_erc721_transfer_wo_info/00000.png delete mode 120000 tests/snapshots/nanox_erc721_transfer_wo_info/00001.png delete mode 120000 tests/snapshots/nanox_erc721_transfer_wo_info/00002.png delete mode 100644 tests/snapshots/nanox_erc721_transfer_wo_info/00003.png delete mode 120000 tests/snapshots/nanox_erc721_transfer_wo_info/00004.png delete mode 120000 tests/snapshots/nanox_erc721_transfer_wo_info/00005.png delete mode 120000 tests/snapshots/nanox_erc721_transfer_wo_info/00006.png delete mode 120000 tests/snapshots/nanox_erc721_transfer_wo_info/00007.png delete mode 120000 tests/snapshots/nanox_erc721_transfer_wo_info/00008.png delete mode 120000 tests/snapshots/nanox_erc721_transfer_wo_info/00009.png delete mode 120000 tests/snapshots/nanox_erc721_transfer_wo_info/00010.png diff --git a/tests/snapshots/nanox_erc1155_transfer_wo_info/00000.png b/tests/snapshots/nanox_erc1155_transfer_wo_info/00000.png deleted file mode 120000 index a808e25..0000000 --- a/tests/snapshots/nanox_erc1155_transfer_wo_info/00000.png +++ /dev/null @@ -1 +0,0 @@ -../nanox_erc1155_transfer/00000.png \ No newline at end of file diff --git a/tests/snapshots/nanox_erc1155_transfer_wo_info/00001.png b/tests/snapshots/nanox_erc1155_transfer_wo_info/00001.png deleted file mode 120000 index 18b62b5..0000000 --- a/tests/snapshots/nanox_erc1155_transfer_wo_info/00001.png +++ /dev/null @@ -1 +0,0 @@ -../nanox_erc1155_transfer/00001.png \ No newline at end of file diff --git a/tests/snapshots/nanox_erc1155_transfer_wo_info/00002.png b/tests/snapshots/nanox_erc1155_transfer_wo_info/00002.png deleted file mode 120000 index 3ba3b50..0000000 --- a/tests/snapshots/nanox_erc1155_transfer_wo_info/00002.png +++ /dev/null @@ -1 +0,0 @@ -../nanox_erc1155_transfer/00002.png \ No newline at end of file diff --git a/tests/snapshots/nanox_erc1155_transfer_wo_info/00003.png b/tests/snapshots/nanox_erc1155_transfer_wo_info/00003.png deleted file mode 100644 index b34af53fcd4c2abde410f077c7f6ee0d6d53ff3a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 457 zcmV;)0XF`LP)aH1MOvfRFde|Kx zk4HM~ZXu0%)_BH!_f^|Abk)(>WUbIS0Ty+MIfG@qEL4#p1T`OdcQM8kRvE?}<{6Ca zwAfu^t+i>+C6R;=YWZ3X1rR}zte)u}G(PPwmT z)k16fil@+F@-3*9OxfU>jA&ZB%HZG9v|CU^c2KQ*06Q+I=XEo$M`IRWWnk!!i> z*{Z z*OM;I{2aH1MOvfRFde|Kx zk4HM~ZXu0%)_BH!_f^|Abk)(>WUbIS0Ty+MIfG@qEL4#p1T`OdcQM8kRvE?}<{6Ca zwAfu^t+i>+C6R;=YWZ3X1rR}zte)u}G(PPwmT z)k16fil@+F@-3*9OxfU>jA&ZB%HZG9v|CU^c2KQ*06Q+I=XEo$M`IRWWnk!!i> z*{Z z*OM;I{2 { + test('[Nano ' + model.letter + '] Transfer ERC-1155 w/o NFT metadata', zemu(model, async (sim, eth) => { const current_screen = sim.getMainMenuSnapshot(); await send_apdu(eth.transport, set_plugin); - await send_apdu(eth.transport, sign_first); - let sign_promise = send_apdu(eth.transport, sign_more); - - await waitForAppScreen(sim, current_screen); - await sim.navigateAndCompareSnapshots('.', model.name + '_erc1155_transfer_wo_info', [10, -1, 0]); - - await sign_promise; - })); - - test('[Nano ' + model.letter + '] Transfer ERC-1155 w/o SET_PLUGIN', zemu(model, async (sim, eth) => { - const current_screen = sim.getMainMenuSnapshot(); - await send_apdu(eth.transport, provide_nft_info); let sign_tx = send_apdu(eth.transport, sign_first); await expect(sign_tx).rejects.toEqual(new TransportStatusError(0x6a80)); })); + + test('[Nano ' + model.letter + '] Transfer ERC-1155 w/o plugin loaded', zemu(model, async (sim, eth) => { + const current_screen = sim.getMainMenuSnapshot(); + let nft_info = send_apdu(eth.transport, provide_nft_info); + + await expect(nft_info).rejects.toEqual(new TransportStatusError(0x6985)); + })); } -test('[Nano ' + model.letter + '] Batch transfer ERC-1155', zemu(model, async (sim, eth) => { - +{ const set_plugin = apdu_as_string('e01600007401010745524331313535495f947276749ce646f68ac8c248420045cb7b5e2eb2c2d60000000000000001000147304502210087b35cefc53fd94e25404933eb0d5ff08f20ba655d181de3b24ff0099dc3317f02204a216aa9e0b84bef6e20fcb036bd49647bf0cab66732b99b49ec277ffb682aa1'); const provide_nft_info = apdu_as_string('e0140000820101194f70656e536561205368617265642053746f726566726f6e74495f947276749ce646f68ac8c248420045cb7b5e00000000000000010001473045022100c74cd613a27a9f4887210f5a3a0e12745e1ba0ab3a0d284cb6485d89c3cce4e602205a13e62a91164985cf58a838f8f531c0b91b980d206a5ba8df28270023ef93a3'); const sign_first = apdu_as_string('e004000096058000002c8000003c800000000000000000000000f9020b0e850d8cfd86008301617d94495f947276749ce646f68ac8c248420045cb7b5e80b901e42eb2c2d60000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d000000000000000000000000c2907efcce4011c491bbeda8a0fa63ba7aab596c00000000000000000000000000000000000000000000'); @@ -56,16 +50,18 @@ test('[Nano ' + model.letter + '] Batch transfer ERC-1155', zemu(model, async (s const sign_more_2 = apdu_as_string('e00480009689732473fcd0bbbe000000000000a30000000001abf06640f8ca8fc5e0ed471b10befcdf65a33e430000000000006a00000000640000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000010000'); const sign_more_3 = apdu_as_string('e00480006100000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000043078303000000000000000000000000000000000000000000000000000000000018080'); - const current_screen = sim.getMainMenuSnapshot(); - await send_apdu(eth.transport, set_plugin); - await send_apdu(eth.transport, provide_nft_info); - await send_apdu(eth.transport, sign_first); - await send_apdu(eth.transport, sign_more_1); - await send_apdu(eth.transport, sign_more_2); - let sign_promise = send_apdu(eth.transport, sign_more_3); + test('[Nano ' + model.letter + '] Batch transfer ERC-1155', zemu(model, async (sim, eth) => { + const current_screen = sim.getMainMenuSnapshot(); + await send_apdu(eth.transport, set_plugin); + await send_apdu(eth.transport, provide_nft_info); + await send_apdu(eth.transport, sign_first); + await send_apdu(eth.transport, sign_more_1); + await send_apdu(eth.transport, sign_more_2); + let sign_promise = send_apdu(eth.transport, sign_more_3); - await waitForAppScreen(sim, current_screen); - await sim.navigateAndCompareSnapshots('.', model.name + '_erc1155_batch_transfer', [8, -1, 0]); + await waitForAppScreen(sim, current_screen); + await sim.navigateAndCompareSnapshots('.', model.name + '_erc1155_batch_transfer', [8, -1, 0]); - await sign_promise; -})); + await sign_promise; + })); +} diff --git a/tests/src/erc721.test.js b/tests/src/erc721.test.js index 9dca820..1d05853 100644 --- a/tests/src/erc721.test.js +++ b/tests/src/erc721.test.js @@ -25,22 +25,17 @@ test('[Nano ' + model.letter + '] Transfer ERC-721', zemu(model, async (sim, eth await sign_promise; })); -test('[Nano ' + model.letter + '] Transfer ERC-721 w/o NFT_PROVIDE_INFORMATION', zemu(model, async(sim, eth) => { +test('[Nano ' + model.letter + '] Transfer ERC-721 w/o NFT metadata', zemu(model, async(sim, eth) => { const current_screen = sim.getMainMenuSnapshot(); await send_apdu(eth.transport, set_plugin); - await send_apdu(eth.transport, sign_first); - let sign_promise = send_apdu(eth.transport, sign_more); - - await waitForAppScreen(sim, current_screen); - await sim.navigateAndCompareSnapshots('.', model.name + '_erc721_transfer_wo_info', [8, -1, 0]); - - await sign_promise; -})); - -test('[Nano ' + model.letter + '] Transfer ERC-721 w/o SET_PLUGIN', zemu(model, async (sim, eth) => { - const current_screen = sim.getMainMenuSnapshot(); - await send_apdu(eth.transport, provide_nft_info); let sign_tx = send_apdu(eth.transport, sign_first); await expect(sign_tx).rejects.toEqual(new TransportStatusError(0x6a80)); })); + +test('[Nano ' + model.letter + '] Transfer ERC-721 w/o plugin loaded', zemu(model, async (sim, eth) => { + const current_screen = sim.getMainMenuSnapshot(); + let nft_info = send_apdu(eth.transport, provide_nft_info); + + await expect(nft_info).rejects.toEqual(new TransportStatusError(0x6985)); +}));