diff --git a/apps/evm_family/evm_helpers.c b/apps/evm_family/evm_helpers.c index d42efcb75..0485b043e 100644 --- a/apps/evm_family/evm_helpers.c +++ b/apps/evm_family/evm_helpers.c @@ -62,7 +62,6 @@ #include "evm_helpers.h" -#include "eth.h" #include "evm_priv.h" #include "evm_txn_helpers.h" #include "evm_typed_data_helper.h" diff --git a/apps/evm_family/evm_typed_data_helper.c b/apps/evm_family/evm_typed_data_helper.c index 4807a9b79..d70485e93 100644 --- a/apps/evm_family/evm_typed_data_helper.c +++ b/apps/evm_family/evm_typed_data_helper.c @@ -64,7 +64,6 @@ #include "coin_utils.h" #include "eip712_utils.h" -#include "eth.h" #include "evm_priv.h" /***************************************************************************** diff --git a/apps/evm_family/evm_typed_data_helper.h b/apps/evm_family/evm_typed_data_helper.h index 8508497dc..87e56bcd1 100644 --- a/apps/evm_family/evm_typed_data_helper.h +++ b/apps/evm_family/evm_typed_data_helper.h @@ -12,7 +12,7 @@ /***************************************************************************** * INCLUDES *****************************************************************************/ -#include "eth.h" + #include "evm_priv.h" /***************************************************************************** diff --git a/common/coin_support/coin_utils.c b/common/coin_support/coin_utils.c index da3318527..7e42fd171 100644 --- a/common/coin_support/coin_utils.c +++ b/common/coin_support/coin_utils.c @@ -62,7 +62,6 @@ #include "avalanche.h" #include "bsc.h" #include "etc.h" -#include "eth.h" #include "fantom.h" #include "harmony.h" #include "near.h" @@ -84,224 +83,6 @@ void s_memcpy(uint8_t *dst, *offset += len; } -int64_t byte_array_to_txn_metadata(const uint8_t *metadata_byte_array, - const uint32_t size, - txn_metadata *txn_metadata_ptr) { - if (metadata_byte_array == NULL || txn_metadata_ptr == NULL) - return -1; - memzero(txn_metadata_ptr, sizeof(txn_metadata)); - - int64_t offset = 0, len = 0; - - s_memcpy(txn_metadata_ptr->purpose_index, - metadata_byte_array, - size, - sizeof(txn_metadata_ptr->purpose_index), - &offset); - s_memcpy(txn_metadata_ptr->coin_index, - metadata_byte_array, - size, - sizeof(txn_metadata_ptr->coin_index), - &offset); - s_memcpy(txn_metadata_ptr->account_index, - metadata_byte_array, - size, - sizeof(txn_metadata_ptr->account_index), - &offset); - s_memcpy(txn_metadata_ptr->input_count, - metadata_byte_array, - size, - sizeof(txn_metadata_ptr->input_count), - &offset); - - len = (*txn_metadata_ptr->input_count) * sizeof(address_type); - txn_metadata_ptr->input = (address_type *)cy_malloc(len); - - uint8_t metadataInputIndex = 0; - for (; metadataInputIndex < *txn_metadata_ptr->input_count; - metadataInputIndex++) { - address_type *input = &txn_metadata_ptr->input[metadataInputIndex]; - s_memcpy(input->change_index, - metadata_byte_array, - size, - sizeof(input->change_index), - &offset); - s_memcpy(input->address_index, - metadata_byte_array, - size, - sizeof(input->address_index), - &offset); - } - - s_memcpy(txn_metadata_ptr->output_count, - metadata_byte_array, - size, - sizeof(txn_metadata_ptr->output_count), - &offset); - - len = sizeof(address_type); // decode 1 output address - txn_metadata_ptr->output = (address_type *)cy_malloc(len); - - uint8_t metadataOutputIndex = 0; - for (; metadataOutputIndex < 1; metadataOutputIndex++) { - address_type *output = &txn_metadata_ptr->output[metadataOutputIndex]; - s_memcpy(output->change_index, - metadata_byte_array, - size, - sizeof(output->change_index), - &offset); - s_memcpy(output->address_index, - metadata_byte_array, - size, - sizeof(output->address_index), - &offset); - } - - s_memcpy(txn_metadata_ptr->change_count, - metadata_byte_array, - size, - sizeof(txn_metadata_ptr->change_count), - &offset); - - len = sizeof(address_type); // decode 1 change address - txn_metadata_ptr->change = (address_type *)cy_malloc(len); - - uint8_t metadataChangeIndex = 0; - for (; metadataChangeIndex < *txn_metadata_ptr->change_count; - metadataChangeIndex++) { - address_type *change = &txn_metadata_ptr->change[metadataChangeIndex]; - s_memcpy(change->change_index, - metadata_byte_array, - size, - sizeof(change->change_index), - &offset); - s_memcpy(change->address_index, - metadata_byte_array, - size, - sizeof(change->address_index), - &offset); - } - - s_memcpy(txn_metadata_ptr->transaction_fees, - metadata_byte_array, - size, - sizeof(txn_metadata_ptr->transaction_fees), - &offset); - - // Should be set in decoding flow - txn_metadata_ptr->eth_val_decimal[0] = 0xFF; - offset++; - - size_t token_name_len = - strnlen((const char *)(metadata_byte_array + offset), size - offset) + 1; - - if (metadata_byte_array[offset + token_name_len - 1] != 0) - return -1; - - txn_metadata_ptr->token_name = (char *)cy_malloc(token_name_len); - - s_memcpy((uint8_t *)txn_metadata_ptr->token_name, - metadata_byte_array, - size, - token_name_len, - &offset); - - txn_metadata_ptr->is_token_transfer = strncmp(txn_metadata_ptr->token_name, - ETHEREUM_TOKEN_SYMBOL, - token_name_len) != 0; - - if (offset + sizeof(txn_metadata_ptr->network_chain_id) > size) - return -1; - txn_metadata_ptr->network_chain_id = - U64_READ_BE_ARRAY(metadata_byte_array + offset); - offset += sizeof(txn_metadata_ptr->network_chain_id); - - txn_metadata_ptr->is_token_transfer = - strncmp( - txn_metadata_ptr->token_name, - get_coin_symbol(BYTE_ARRAY_TO_UINT32(txn_metadata_ptr->coin_index), - txn_metadata_ptr->network_chain_id), - token_name_len) != 0; - - if (offset + 1 <= size) - txn_metadata_ptr->is_harmony_address = metadata_byte_array[offset++]; - - if (offset + sizeof(txn_metadata_ptr->address_tag) > size) - return -1; - txn_metadata_ptr->address_tag = - U16_READ_BE_ARRAY(metadata_byte_array + offset); - offset += sizeof(txn_metadata_ptr->address_tag); - - return offset; -} - -int64_t byte_array_to_recv_txn_data(Receive_Transaction_Data *txn_data_ptr, - const uint8_t *data_byte_array, - const uint32_t size) { - if (txn_data_ptr == NULL || data_byte_array == NULL) - return -1; - memzero(txn_data_ptr, sizeof(Receive_Transaction_Data)); - - int64_t offset = 0; - - s_memcpy(txn_data_ptr->wallet_id, - data_byte_array, - size, - sizeof(txn_data_ptr->wallet_id), - &offset); - s_memcpy(txn_data_ptr->purpose, - data_byte_array, - size, - sizeof(txn_data_ptr->purpose), - &offset); - s_memcpy(txn_data_ptr->coin_index, - data_byte_array, - size, - sizeof(txn_data_ptr->coin_index), - &offset); - s_memcpy(txn_data_ptr->account_index, - data_byte_array, - size, - sizeof(txn_data_ptr->account_index), - &offset); - s_memcpy(txn_data_ptr->change_index, - data_byte_array, - size, - sizeof(txn_data_ptr->change_index), - &offset); - s_memcpy(txn_data_ptr->address_index, - data_byte_array, - size, - sizeof(txn_data_ptr->address_index), - &offset); - - size_t token_name_len = - strnlen((const char *)(data_byte_array + offset), size - offset) + 1; - - if (data_byte_array[offset + token_name_len - 1] != 0) - return -1; - - txn_data_ptr->token_name = (char *)cy_malloc(token_name_len); - - s_memcpy((uint8_t *)txn_data_ptr->token_name, - data_byte_array, - size, - token_name_len, - &offset); - - if (offset + sizeof(txn_data_ptr->network_chain_id) > size) - return -1; - txn_data_ptr->network_chain_id = U64_READ_BE_ARRAY(data_byte_array + offset); - offset += sizeof(txn_data_ptr->network_chain_id); - - if (offset + sizeof(txn_data_ptr->address_tag) > size) - return -1; - txn_data_ptr->address_tag = U16_READ_BE_ARRAY(data_byte_array + offset); - offset += sizeof(txn_data_ptr->address_tag); - - return offset; -} - bool derive_hdnode_from_path(const uint32_t *path, const size_t path_length, const char *curve, @@ -318,246 +99,6 @@ bool derive_hdnode_from_path(const uint32_t *path, return true; } -void get_address_node(const txn_metadata *txn_metadata_ptr, - const int16_t index, - const char *mnemonic, - const char *passphrase, - HDNode *hdnode) { - uint8_t bip39seed[512 / 8]; - mnemonic_to_seed(mnemonic, passphrase, bip39seed, 0); - hdnode_from_seed(bip39seed, 512 / 8, SECP256K1_NAME, hdnode); - hdnode_private_ckd(hdnode, - BYTE_ARRAY_TO_UINT32(txn_metadata_ptr->purpose_index)); - hdnode_private_ckd(hdnode, - BYTE_ARRAY_TO_UINT32(txn_metadata_ptr->coin_index)); - hdnode_private_ckd(hdnode, - BYTE_ARRAY_TO_UINT32(txn_metadata_ptr->account_index)); - if (index == -1) { - hdnode_private_ckd( - hdnode, BYTE_ARRAY_TO_UINT32(txn_metadata_ptr->change[0].change_index)); - hdnode_private_ckd( - hdnode, - BYTE_ARRAY_TO_UINT32(txn_metadata_ptr->change[0].address_index)); - } else if (index >= 0) { - hdnode_private_ckd( - hdnode, - BYTE_ARRAY_TO_UINT32(txn_metadata_ptr->input[index].change_index)); - hdnode_private_ckd( - hdnode, - BYTE_ARRAY_TO_UINT32(txn_metadata_ptr->input[index].address_index)); - } - hdnode_fill_public_key(hdnode); - memzero(bip39seed, sizeof(bip39seed)); -} - -const char *get_coin_symbol(uint32_t coin_index, uint64_t chain_id) { - switch (coin_index) { - case 0x80000000U: - case 0x80000001: - return "BTC"; - case 0x80000002: - return "LTC"; - case 0x80000003: - return "DOGE"; - case 0x80000005: - return "DASH"; - case ETHEREUM: { - switch (chain_id) { - case ETHEREUM_MAINNET_CHAIN: - return ETHEREUM_TOKEN_SYMBOL; - case POLYGON_MAINNET_CHAIN: - return POLYGON_TOKEN_SYMBOL; - case BSC_MAINNET_CHAIN: - return BSC_TOKEN_SYMBOL; - case FANTOM_MAINNET_CHAIN: - return FANTOM_TOKEN_SYMBOL; - case AVALANCHE_MAINNET_CHAIN: - return AVALANCHE_TOKEN_SYMBOL; - case OPTIMISM_MAINNET_CHAIN: - return OPTIMISM_TOKEN_SYMBOL; - case ETC_MAINNET_CHAIN: - return ETC_TOKEN_SYMBOL; - case HARMONY_MAINNET_CHAIN: - return HARMONY_TOKEN_SYMBOL; - case ARBITRUM_MAINNET_CHAIN: - return ARBITRUM_TOKEN_SYMBOL; - default: { - ASSERT(false); - return "invalid"; - } - } - } - case SOLANA: - return "SOL"; - default: { - ASSERT(false); - return "invalid"; - } - } -} - -const char *get_coin_name(uint32_t coin_index, uint64_t chain_id) { - switch (coin_index) { - case 0x80000000: - return "Bitcoin"; - case 0x80000001: - return "Bitcoin Testnet"; - case 0x80000002: - return "Litecoin"; - case 0x80000003: - return "Dogecoin"; - case 0x80000005: - return "Dash"; - case ETHEREUM: { - switch (chain_id) { - case ETHEREUM_MAINNET_CHAIN: - return ETHEREUM_MAINNET_NAME; - case POLYGON_MAINNET_CHAIN: - return POLYGON_MAINNET_NAME; - case BSC_MAINNET_CHAIN: - return BSC_MAINNET_NAME; - case FANTOM_MAINNET_CHAIN: - return FANTOM_MAINNET_NAME; - case AVALANCHE_MAINNET_CHAIN: - return AVALANCHE_MAINNET_NAME; - case OPTIMISM_MAINNET_CHAIN: - return OPTIMISM_MAINNET_NAME; - case ETC_MAINNET_CHAIN: - return ETC_MAINNET_NAME; - case HARMONY_MAINNET_CHAIN: - return HARMONY_MAINNET_NAME; - case ARBITRUM_MAINNET_CHAIN: - return ARBITRUM_MAINNET_NAME; - default: { - ASSERT(false); - return "invalid"; - } - } - } - case SOLANA: - return "Solana"; - default: { - ASSERT(false); - return "invalid"; - } - } -} - -void get_version(const uint32_t purpose_id, - const uint32_t coin_index, - uint8_t *address_version, - uint32_t *pub_version) { - uint8_t assigned_add_version = 0x0; - uint32_t assigned_pub_version = 0x0; - - switch (purpose_id) { - case NATIVE_SEGWIT: - switch (coin_index) { - case BTC_TEST: - assigned_pub_version = 0x045f1cf6; - assigned_add_version = 0x6f; - break; - case BITCOIN: - assigned_pub_version = 0x04b24746; - assigned_add_version = 0x00; - break; - case LITCOIN: - assigned_pub_version = 0x0488b21e; - assigned_add_version = 0x30; - break; - case DOGE: - assigned_pub_version = 0x02facafd; - assigned_add_version = 0x1E; - break; - case DASH: - assigned_pub_version = 0x0488b21e; - assigned_add_version = 0x4c; - break; - default: - break; - } - break; - - case NON_SEGWIT: - switch (coin_index) { - case BTC_TEST: - assigned_pub_version = 0x043587cf; - assigned_add_version = 0x6f; - break; - case BITCOIN: - assigned_pub_version = 0x0488b21e; - assigned_add_version = 0x00; - break; - case LITCOIN: - assigned_pub_version = 0x0488b21e; - assigned_add_version = 0x30; - break; - case DOGE: - assigned_pub_version = 0x02facafd; - assigned_add_version = 0x1E; - break; - case DASH: - assigned_pub_version = 0x0488b21e; - assigned_add_version = 0x4c; - break; - case ETHEREUM: - case NEAR: - assigned_pub_version = 0x0488b21e; - assigned_add_version = 0x00; - break; - case SOLANA: - assigned_pub_version = 0x0488b21e; - assigned_add_version = 0x00; - break; - default: - break; - } - break; - - default: - break; - } - - if (address_version) { - *address_version = assigned_add_version; - } - - if (pub_version) { - *pub_version = assigned_pub_version; - } -} - -bool validate_txn_metadata(const txn_metadata *mdata_ptr) { - if (mdata_ptr->purpose_index[0] < 0x80 || mdata_ptr->coin_index[0] < 0x80 || - mdata_ptr->account_index[0] < 0x80) - return false; - if (BYTE_ARRAY_TO_UINT32(mdata_ptr->purpose_index) == NON_SEGWIT && - (BYTE_ARRAY_TO_UINT32(mdata_ptr->coin_index) == NEAR || - BYTE_ARRAY_TO_UINT32(mdata_ptr->coin_index) == SOLANA)) { - if (mdata_ptr->input_count[0] > 0 && - (mdata_ptr->input->change_index[0] < 0x80 || - mdata_ptr->input->address_index[0] < 0x80)) - return false; - return true; - } - if (mdata_ptr->input_count[0] > 0 && - (mdata_ptr->input->change_index[0] >= 0x80 || - mdata_ptr->input->address_index[0] >= 0x80)) - return false; - if (mdata_ptr->output_count[0] > 0 && - (mdata_ptr->output->change_index[0] >= 0x80 || - mdata_ptr->output->address_index[0] >= 0x80)) - return false; - if (mdata_ptr->change_count[0] > 0 && - (mdata_ptr->change->change_index[0] >= 0x80 || - mdata_ptr->change->address_index[0] >= 0x80)) - return false; - if (BYTE_ARRAY_TO_UINT32(mdata_ptr->purpose_index) == NON_SEGWIT && - BYTE_ARRAY_TO_UINT32(mdata_ptr->coin_index) == ETHEREUM && - mdata_ptr->token_name[0] == '\0') - return false; - return true; -} ui_display_node *ui_create_display_node(const char *title, const size_t title_size, const char *value, @@ -589,89 +130,6 @@ void bech32_addr_encode(char *output, bech32_encode(output, hrp, data, datalen); } -bool verify_xpub_derivation_path(const uint32_t *path, uint8_t depth) { - bool status = false; - - if (depth < 2) - return status; - - uint32_t purpose = path[0], coin = path[1]; - - switch (coin) { - case NEAR: - status = false; - break; - - case SOLANA: - status = sol_verify_derivation_path(path, depth); - break; - - case LITCOIN: - case DOGE: - case DASH: // m/44'/5' /i' - case ETHEREUM: // m/44'/60' /i' - status = (purpose == NON_SEGWIT && depth == XPUB_DEFAULT_DEPTH && - is_hardened(path[2])); - break; - - case BTC_TEST: // m/44'/1' /i' - case BITCOIN: // m/44'/0' /i' - status = (purpose == NON_SEGWIT || purpose == NATIVE_SEGWIT) && - (depth == XPUB_DEFAULT_DEPTH) && is_hardened(path[2]); - break; - - default: - break; - } - - return status; -} - -bool verify_receive_derivation_path(const uint32_t *path, uint8_t depth) { - bool status = false; - - if (depth < 2) - return status; - - uint32_t purpose = path[0], coin = path[1]; - - switch (coin) { - case NEAR: - status = false; - break; - - case SOLANA: // m/44'/501'/i'/j' - status = sol_verify_derivation_path(path, depth); - break; - - case LITCOIN: - case DOGE: - case DASH: // m/44'/5' /i'/0 /j - status = (depth == ADDR_DEFAULT_DEPTH) && (purpose == NON_SEGWIT) && - is_hardened(path[2]) && (path[3] == 0) && - is_non_hardened(path[4]); - break; - - case ETHEREUM: // m/44'/60' /i'/0 /0 - status = (depth == ADDR_DEFAULT_DEPTH) && (purpose == NON_SEGWIT) && - is_hardened(path[2]) && (path[3] == 0) && (path[4] == 0); - break; - - case BTC_TEST: - case BITCOIN: // m/44'/0' /i'/0 /j - status = (depth == ADDR_DEFAULT_DEPTH) && - (purpose == NON_SEGWIT || purpose == NATIVE_SEGWIT) && - is_hardened(path[2]) && (path[3] == 0) && - is_non_hardened(path[4]); - break; - - default: - break; - } - - return status; -} - FUNC_RETURN_CODES hd_path_array_to_string(const uint32_t *path, const size_t path_length, const bool harden_all, diff --git a/common/coin_support/coin_utils.h b/common/coin_support/coin_utils.h index 0a74e08ba..397e65e23 100644 --- a/common/coin_support/coin_utils.h +++ b/common/coin_support/coin_utils.h @@ -266,43 +266,6 @@ int64_t byte_array_to_add_coin_data(Add_Coin_Data *data_ptr, const uint8_t *byte_array, size_t size); -/** - * @brief Converts byte array represented transaction metadata to struct - * txn_metadata. - * @details - * - * @param [in] txn_metadata_byte_array Transaction metadata byte array to be - * converted. - * @param [in] size Size of the byte array - * txn_metadata_byte_array - * @param [out] txn_metadata_ptr Pointer to the txn_metadata instance to - * store the field values. - * - * @return Offset used in conversion - * @retval - * - * @see - * @since v1.0.0 - * - * @note - */ -int64_t byte_array_to_txn_metadata(const uint8_t *txn_metadata_byte_array, - uint32_t size, - txn_metadata *txn_metadata_ptr); - -/** - * @brief Deserialize byte array to receive transaction data - * - * @param [out] txn_data_ptr Pointer to the receive transaction data - * instance - * @param [in] data_byte_array Byte array to be deserialized - * @param [in] size Size of the byte array data_byte_array - * @return int32_t Offset used in conversion - */ -int64_t byte_array_to_recv_txn_data(Receive_Transaction_Data *txn_data_ptr, - const uint8_t *data_byte_array, - const uint32_t size); - /** * @brief Generates the node from provided seed at the requested path * @details The function performs hardened derivation of the nodes at the @@ -325,163 +288,11 @@ bool derive_hdnode_from_path(const uint32_t *path, const uint8_t *seed, HDNode *hdnode); -/** - * @brief Get the address from HDNode. - * @details - * - * @param [in] txn_metadata_ptr Pointer to txn_metadata instance. - * @param [in] index Input index. - * @param [in] mnemonic char array storing mnemonics. - * @param [in] passphrase char array storing passphrase. - * @param [out] hdnode Pointer to HDNode instance used to derive - * the address. - * - * @return - * @retval - * - * @see - * @since v1.0.0 - * - * @note - */ -void get_address_node(const txn_metadata *txn_metadata_ptr, - const int16_t index, - const char *mnemonic, - const char *passphrase, - HDNode *hdnode); -/** - * @brief Get the coin name for the passed coin index and chain id. - * @details - * - * @param [in] coin_index Coin index - * @param [in] chain_id Chain ID (Passed to distinguish between different - * EVM chains) - * - * @return [const] char array of name of the coin. - * @retval - * - * @see - * @since v1.0.0 - * - * @note - */ -const char *get_coin_name(uint32_t coin_index, uint64_t chain_id); - -/** - * @brief Get the coin symbol for the passed coin index and chain id - * @details - * - * @param [in] coin_index Coin index - * @param [in] chain_id Chain ID (Passed to distinguish between different - * EVM chains) - * - * @return [const] char array of symbol of the coin - * @retval - * - * @see - * @since v1.0.0 - * - * @note - */ -const char *get_coin_symbol(uint32_t coin_index, uint64_t chain_id); - -/** - * @brief Get the version address and public key for segwit and non segwit - * coins. - * @details - * - * @param [in] purpose_id Purpose Id of the coin. - * @param [in] coin_index Coin index of the coin. - * @param [out] address_version Pointer to uint8_t instance to store the - * addres version. - * @param [out] pub_version Pointer to uint32_t to instance store the - * public key version. - * - * @return - * @retval - * - * @see - * @since v1.0.0 - * - * @note - */ -void get_version(uint32_t purpose_id, - uint32_t coin_index, - uint8_t *address_version, - uint32_t *pub_version); - -/** - * @brief - * @details - * - * @param [in] txn_metadata_ptr - * - * @return bool - * @retval - * - * @see - * @since v1.0.0 - * - * @note - */ -bool validate_txn_metadata(const txn_metadata *txn_metadata_ptr); - -/** - * @brief Validates transaction metadata for near coin. - * @details - * - * @param [in] metadata_ptr - * - * @return bool - * @retval - * - * @see - * @since v1.0.0 - * - * @note - */ -bool validate_txn_metadata_near(const txn_metadata *mdata_ptr); - void bech32_addr_encode(char *output, char *hrp, uint8_t *address_bytes, uint8_t byte_len); -/** - * @brief Verifies the derivation path for xpub during coin export step - * The function verifies all the indices for exact match of purpose_id, coin_id, - * and other relevant indices. The hardness of the derivation index in the path - * is also checked for validity. If the depth of derivation does not match the - * supported derivation paths or any of the above checks do not pass for a given - * coin, this function will return false. - * - * @param[in] path The address derivation path to be checked - * @param[in] depth The number of levels in the derivation path - * - * @return bool true if the path values are valid. False otherwise. - * - * @since v1.0.0 - */ -bool verify_xpub_derivation_path(const uint32_t *path, uint8_t depth); - -/** - * @brief Verifies if the specified derivation path is valid based on checks - * on intermediate values. - * The function verifies all the indices for exact match of purpose_id, coin_id, - * and other relevant indices. The hardness of the derivation index in the path - * is also checked for validity. If the depth of derivation does not match the - * supported derivation paths or any of the above checks do not pass for a given - * coin, this function will return false. - * - * @param[in] path The address derivation path to be checked - * @param[in] depth The number of levels in the derivation path - * - * @return bool Returns true if the path values are valid. False otherwise. - * - * @since v1.0.0 - */ -bool verify_receive_derivation_path(const uint32_t *path, uint8_t depth); - /** * @brief Generates an user readable derivation path from a uint32_t path array. * will only write the output until the out_len is reached, i.e. an error diff --git a/common/coin_support/eth.c b/common/coin_support/eth.c index d1e4a8f5b..d289cde18 100644 --- a/common/coin_support/eth.c +++ b/common/coin_support/eth.c @@ -250,7 +250,6 @@ void sig_unsigned_byte_array(const uint8_t *eth_unsigned_txn_byte_array, keccak_256(eth_unsigned_txn_byte_array, eth_unsigned_txn_len, digest); uint8_t recid; HDNode hdnode; - get_address_node(transaction_metadata, 0, mnemonics, passphrase, &hdnode); ecdsa_sign_digest(&secp256k1, hdnode.private_key, digest, sig, &recid, NULL); memcpy(sig + 64, &recid, 1); } diff --git a/common/coin_support/eth_sign_data/abi_encode.c b/common/coin_support/eth_sign_data/abi_encode.c index 9bd32675f..4bf2a2ba7 100644 --- a/common/coin_support/eth_sign_data/abi_encode.c +++ b/common/coin_support/eth_sign_data/abi_encode.c @@ -61,7 +61,6 @@ #include "abi.h" #include "assert_conf.h" -#include "eth.h" #include "utils.h" /* Global functions diff --git a/src/controller_main.c b/src/controller_main.c index 9717c57a1..ae4392b8a 100644 --- a/src/controller_main.c +++ b/src/controller_main.c @@ -291,80 +291,6 @@ void _timeout_listener(lv_task_t *task) { reset_flow_level(); } -#if X1WALLET_MAIN -/** - * @brief Checks the state of wallet for the wallet id passed before loading the - * into Wallet instance. - * @details The functions looks for an operational wallet instance with the - * requested wallet id. If the wallet is found to be in a non-operational state, - * the function returns false with an appropriate response wrapped in the - * WALLET_DOES_NOT_EXISTS command sent to the desktop app.
Payload - * transmitted along with command type (WALLET_DOES_NOT_EXISTS) data byte is the - * rejection reason - * - 0x00 - No wallets found - * - 0x01 - Wallet not verified/locked - * - 0x02 - Wallet not present - * And a rejection with command type WALLET_IS_LOCKED - * - * @param data_array Wallet id of the wallet - * - * @return bool Indicates the status for the search - * @retval true if an operational wallet is found - * @retval false otherwise - * - * @see wallet, WALLET_DOES_NOT_EXISTS, get_wallet_count(), is_wallet_partial(), - * get_wallet_id(), get_wallet_state(), WALLET_IS_LOCKED, VALID_WALLET, - * is_wallet_locked() - * @since v1.0.0 - * - * @note - */ -static bool wallet_selector(uint8_t *data_array) { - uint8_t wallet_id[WALLET_ID_SIZE]; - uint16_t offset = 0; - uint8_t number_of_options = get_wallet_count(); - - // No wallets found on device - if (number_of_options == 0) { - comm_reject_request(WALLET_DOES_NOT_EXISTS, 0); - return false; - } - - memcpy(wallet_id, data_array + offset, WALLET_ID_SIZE); - offset += WALLET_ID_SIZE; - - uint8_t walletIndex = 0; - - for (; walletIndex < MAX_WALLETS_ALLOWED; walletIndex++) { - if (memcmp(wallet_id, get_wallet_id(walletIndex), WALLET_ID_SIZE) == 0) { - if (get_wallet_state(walletIndex) == VALID_WALLET) { - memcpy(wallet.wallet_name, get_wallet_name(walletIndex), NAME_SIZE); - wallet.wallet_info = get_wallet_info(walletIndex); - if (is_wallet_partial(walletIndex)) { - comm_reject_request(WALLET_DOES_NOT_EXISTS, 1); - return false; - } - // if wallet is locked - if (is_wallet_locked(walletIndex)) { - comm_reject_request(WALLET_IS_LOCKED, 0); - return false; - } - // Found a valid wallet - return true; - - } else { - // Wallet is unverified - comm_reject_request(WALLET_DOES_NOT_EXISTS, 1); - return false; - } - } - } - - comm_reject_request(WALLET_DOES_NOT_EXISTS, 2); - return false; -} -#endif - void desktop_listener_task(lv_task_t *data) { En_command_type_t command; uint8_t *data_array = NULL; @@ -386,187 +312,14 @@ void desktop_listener_task(lv_task_t *data) { } break; #endif case SEND_TXN_START: { - if (wallet_selector(data_array)) { - CY_Reset_Not_Allow(false); - uint16_t offset = WALLET_ID_SIZE; - uint32_t coin_index; - if (byte_array_to_txn_metadata( - data_array + offset, - msg_size - offset, - &var_send_transaction_data.transaction_metadata) == -1) { - clear_message_received_data(); - comm_reject_invalid_cmd(); - return; - } - - flow_level.show_desktop_start_screen = true; - var_send_transaction_data.transaction_confirmation_list_index = 0; - flow_level.level_one = LEVEL_TWO_OLD_WALLET; - - coin_index = BYTE_ARRAY_TO_UINT32( - var_send_transaction_data.transaction_metadata.coin_index); - - if (coin_index == ETHEREUM) { - flow_level.level_two = LEVEL_THREE_SEND_TRANSACTION_ETH; - snprintf(flow_level.confirmation_screen_text, - sizeof(flow_level.confirmation_screen_text), - UI_TEXT_SEND_TOKEN_PROMPT, - var_send_transaction_data.transaction_metadata.token_name, - get_coin_name(coin_index, - var_send_transaction_data - .transaction_metadata.network_chain_id), - wallet.wallet_name); - } else if (false) { - // flow_level.level_two = LEVEL_THREE_SEND_TRANSACTION_NEAR; - if (var_send_transaction_data.transaction_metadata - .network_chain_id == 1) { - snprintf( - flow_level.confirmation_screen_text, - sizeof(flow_level.confirmation_screen_text), - "Add %s account to %s", - get_coin_name(coin_index, - var_send_transaction_data.transaction_metadata - .network_chain_id), - wallet.wallet_name); - } else { - snprintf( - flow_level.confirmation_screen_text, - sizeof(flow_level.confirmation_screen_text), - UI_TEXT_SEND_TOKEN_PROMPT, - get_coin_symbol(coin_index, - receive_transaction_data.network_chain_id), - get_coin_name(coin_index, - var_send_transaction_data.transaction_metadata - .network_chain_id), - wallet.wallet_name); - } - } else if (coin_index == SOLANA_COIN_INDEX) { - flow_level.level_two = LEVEL_THREE_SEND_TRANSACTION_SOLANA; - snprintf(flow_level.confirmation_screen_text, - sizeof(flow_level.confirmation_screen_text), - UI_TEXT_SEND_TOKEN_PROMPT, - get_coin_symbol(coin_index, - receive_transaction_data.network_chain_id), - get_coin_name(coin_index, - var_send_transaction_data - .transaction_metadata.network_chain_id), - wallet.wallet_name); - } else { - } - if (!validate_txn_metadata( - &var_send_transaction_data.transaction_metadata)) { - comm_reject_request(SEND_TXN_REQ_UNSIGNED_TXN, 0); - reset_flow_level(); - } - } clear_message_received_data(); } break; case SIGN_MSG_START: { - if (wallet_selector(data_array)) { - CY_Reset_Not_Allow(false); - uint16_t offset = WALLET_ID_SIZE; - uint32_t coin_index; - if (byte_array_to_txn_metadata( - data_array + offset, - msg_size - offset, - &var_send_transaction_data.transaction_metadata) == -1) { - clear_message_received_data(); - comm_reject_invalid_cmd(); - return; - } - flow_level.show_desktop_start_screen = true; - var_send_transaction_data.transaction_confirmation_list_index = 0; - flow_level.level_one = LEVEL_TWO_OLD_WALLET; - - coin_index = BYTE_ARRAY_TO_UINT32( - var_send_transaction_data.transaction_metadata.coin_index); - - if (coin_index == ETHEREUM) { - flow_level.level_two = LEVEL_THREE_SIGN_MESSAGE_ETH; - snprintf(flow_level.confirmation_screen_text, - sizeof(flow_level.confirmation_screen_text), - UI_TEXT_SIGN_PROMPT, - var_send_transaction_data.transaction_metadata.token_name, - get_coin_name(coin_index, - var_send_transaction_data - .transaction_metadata.network_chain_id), - wallet.wallet_name); - } - if (!validate_txn_metadata( - &var_send_transaction_data.transaction_metadata)) { - comm_reject_request(SEND_TXN_REQ_UNSIGNED_TXN, 0); - reset_flow_level(); - } - } clear_message_received_data(); } break; case RECV_TXN_START: { - if (wallet_selector(data_array)) { - CY_Reset_Not_Allow(false); - - int64_t offset = byte_array_to_recv_txn_data( - &receive_transaction_data, data_array, msg_size); - uint32_t path[5] = { - BYTE_ARRAY_TO_UINT32(receive_transaction_data.purpose), - BYTE_ARRAY_TO_UINT32(receive_transaction_data.coin_index), - BYTE_ARRAY_TO_UINT32(receive_transaction_data.account_index), - BYTE_ARRAY_TO_UINT32(receive_transaction_data.change_index), - BYTE_ARRAY_TO_UINT32(receive_transaction_data.address_index)}; - uint8_t depth = path[1] == SOLANA - ? sol_get_derivation_depth( - receive_transaction_data.address_tag) - : 5; - - if (offset == -1 || !verify_receive_derivation_path(path, depth)) { - comm_reject_invalid_cmd(); - clear_message_received_data(); - return; - } - flow_level.show_desktop_start_screen = true; - - uint32_t coin_index = - BYTE_ARRAY_TO_UINT32(receive_transaction_data.coin_index); - - if (false && receive_transaction_data.near_account_type == 1) { - memcpy(&receive_transaction_data.near_registered_account, - data_array + offset, - 65); - } - - if (coin_index == ETHEREUM) { - flow_level.level_two = LEVEL_THREE_RECEIVE_TRANSACTION_ETH; - snprintf(flow_level.confirmation_screen_text, - sizeof(flow_level.confirmation_screen_text), - UI_TEXT_RECEIVE_TOKEN_PROMPT, - receive_transaction_data.token_name, - get_coin_name(coin_index, - receive_transaction_data.network_chain_id), - wallet.wallet_name); - } else if (false) { - flow_level.level_two = LEVEL_THREE_RECEIVE_TRANSACTION_NEAR; - snprintf(flow_level.confirmation_screen_text, - sizeof(flow_level.confirmation_screen_text), - UI_TEXT_RECEIVE_TOKEN_PROMPT, - get_coin_symbol(coin_index, - receive_transaction_data.network_chain_id), - get_coin_name(coin_index, - receive_transaction_data.network_chain_id), - wallet.wallet_name); - } else if (coin_index == SOLANA_COIN_INDEX) { - flow_level.level_two = LEVEL_THREE_RECEIVE_TRANSACTION_SOLANA; - snprintf(flow_level.confirmation_screen_text, - sizeof(flow_level.confirmation_screen_text), - UI_TEXT_RECEIVE_TOKEN_PROMPT, - get_coin_symbol(coin_index, - receive_transaction_data.network_chain_id), - get_coin_name(coin_index, - receive_transaction_data.network_chain_id), - wallet.wallet_name); - } else { - } - } clear_message_received_data(); } break; #elif X1WALLET_INITIAL @@ -612,31 +365,7 @@ void desktop_listener_task(lv_task_t *data) { #error Specify what to build (X1WALLET_INITIAL or X1WALLET_MAIN) #endif case LIST_SUPPORTED_COINS: { - uint32_t coins[] = {U32_SWAP_ENDIANNESS(COIN_TYPE_ETHEREUM), - U32_SWAP_ENDIANNESS(ETH_COIN_VERSION), - U32_SWAP_ENDIANNESS(COIN_TYPE_NEAR), - // U32_SWAP_ENDIANNESS(NEAR_COIN_VERSION), - U32_SWAP_ENDIANNESS(COIN_TYPE_SOLANA), - U32_SWAP_ENDIANNESS(SOL_COIN_VERSION), - U32_SWAP_ENDIANNESS(COIN_TYPE_POLYGON), - U32_SWAP_ENDIANNESS(POLYGON_COIN_VERSION), - U32_SWAP_ENDIANNESS(COIN_TYPE_BSC), - U32_SWAP_ENDIANNESS(BSC_COIN_VERSION), - U32_SWAP_ENDIANNESS(COIN_TYPE_FANTOM), - U32_SWAP_ENDIANNESS(FANTOM_COIN_VERSION), - U32_SWAP_ENDIANNESS(COIN_TYPE_AVALANCHE), - U32_SWAP_ENDIANNESS(AVALANCHE_COIN_VERSION), - U32_SWAP_ENDIANNESS(COIN_TYPE_OPTIMISM), - U32_SWAP_ENDIANNESS(OPTIMISM_COIN_VERSION), - U32_SWAP_ENDIANNESS(COIN_TYPE_HARMONY), - U32_SWAP_ENDIANNESS(HARMONY_COIN_VERSION), - U32_SWAP_ENDIANNESS(COIN_TYPE_ETHEREUM_CLASSIC), - U32_SWAP_ENDIANNESS(ETC_COIN_VERSION), - U32_SWAP_ENDIANNESS(COIN_TYPE_ARBITRUM), - U32_SWAP_ENDIANNESS(ARBITRUM_COIN_VERSION)}; clear_message_received_data(); - transmit_data_to_app( - LIST_SUPPORTED_COINS, (uint8_t *)coins, sizeof(coins)); } break; default: diff --git a/src/level_four/core/controller/receive_transaction_controller_eth.c b/src/level_four/core/controller/receive_transaction_controller_eth.c index 7126fb228..da21f1a66 100644 --- a/src/level_four/core/controller/receive_transaction_controller_eth.c +++ b/src/level_four/core/controller/receive_transaction_controller_eth.c @@ -176,13 +176,6 @@ void receive_transaction_controller_eth() { hdnode_private_ckd( &node, BYTE_ARRAY_TO_UINT32(receive_transaction_data.account_index)); - uint32_t version; - uint8_t address_version; - get_version(BYTE_ARRAY_TO_UINT32(receive_transaction_data.purpose), - BYTE_ARRAY_TO_UINT32(receive_transaction_data.coin_index), - &address_version, - &version); - hdnode_fill_public_key(&node); hdnode_public_ckd( diff --git a/src/level_four/core/tasks/send_transaction_tasks_eth.c b/src/level_four/core/tasks/send_transaction_tasks_eth.c index e281c43b0..7c1d265ab 100644 --- a/src/level_four/core/tasks/send_transaction_tasks_eth.c +++ b/src/level_four/core/tasks/send_transaction_tasks_eth.c @@ -236,15 +236,7 @@ void send_transaction_tasks_eth() { instruction_scr_destructor(); eth_get_fee_string(ð_unsigned_txn_ptr, fee, sizeof(fee), ETH_DECIMAL); - snprintf( - display, - sizeof(display), - UI_TEXT_SEND_TXN_FEE, - fee, - get_coin_symbol( - U32_READ_BE_ARRAY( - var_send_transaction_data.transaction_metadata.coin_index), - var_send_transaction_data.transaction_metadata.network_chain_id)); + snprintf(display, sizeof(display), UI_TEXT_SEND_TXN_FEE, fee, ""); confirm_scr_init(display); } break; diff --git a/src/level_four/core/tasks/send_transaction_tasks_solana.c b/src/level_four/core/tasks/send_transaction_tasks_solana.c index bbec35978..fceb1c858 100644 --- a/src/level_four/core/tasks/send_transaction_tasks_solana.c +++ b/src/level_four/core/tasks/send_transaction_tasks_solana.c @@ -142,15 +142,11 @@ void send_transaction_tasks_solana() { sizeof(amount_decimal_string))) break; instruction_scr_destructor(); - snprintf( - display, - sizeof(display), - UI_TEXT_VERIFY_AMOUNT, - amount_decimal_string, - get_coin_symbol( - BYTE_ARRAY_TO_UINT32( - var_send_transaction_data.transaction_metadata.coin_index), - 0)); + snprintf(display, + sizeof(display), + UI_TEXT_VERIFY_AMOUNT, + amount_decimal_string, + ""); confirm_scr_init(display); } break; @@ -176,15 +172,11 @@ void send_transaction_tasks_solana() { sizeof(amount_decimal_string))) break; instruction_scr_destructor(); - snprintf( - display, - sizeof(display), - UI_TEXT_VERIFY_AMOUNT, - amount_decimal_string, - get_coin_symbol( - BYTE_ARRAY_TO_UINT32( - var_send_transaction_data.transaction_metadata.coin_index), - 0)); + snprintf(display, + sizeof(display), + UI_TEXT_VERIFY_AMOUNT, + amount_decimal_string, + ""); confirm_scr_init(display); } break; diff --git a/src/level_four/core/tasks/sign_message_tasks_eth.c b/src/level_four/core/tasks/sign_message_tasks_eth.c index 65d866a04..c455da8c6 100644 --- a/src/level_four/core/tasks/sign_message_tasks_eth.c +++ b/src/level_four/core/tasks/sign_message_tasks_eth.c @@ -58,7 +58,6 @@ */ #include "constant_texts.h" #include "controller_level_four.h" -#include "eth.h" #include "int-util.h" #include "math.h" #include "tasks_level_four.h" diff --git a/tests/common/util/xpub_verify_tests.c b/tests/common/util/xpub_verify_tests.c index e2700889d..5f91ab7b3 100644 --- a/tests/common/util/xpub_verify_tests.c +++ b/tests/common/util/xpub_verify_tests.c @@ -4,7 +4,7 @@ #include "coin_utils.h" #include "dash_app.h" #include "doge_app.h" -#include "eth.h" +#include "evm_helpers.h" #include "ltc_app.h" #include "near.h" #include "near_helpers.h" @@ -78,12 +78,6 @@ const uint32_t paths[][7] = { 0x80000000, 0x8fffffff}, // sol invalid - // account 0 - {3, 1, NON_SEGWIT, ETHEREUM, 0x80000000}, // eth valid - // account 0x7fffffff - {3, 1, NON_SEGWIT, ETHEREUM, 0xffffffff}, // eth valid - // non-hardened - {3, 0, NON_SEGWIT, ETHEREUM, 0x00000000}, // eth invalid // wrong depth for xpub {5, 0, @@ -92,8 +86,6 @@ const uint32_t paths[][7] = { 0x80000000, 0x80000000, 0xffffffff}, // eth invalid - // wrong purpose-id - {3, 0, NATIVE_SEGWIT, ETHEREUM, 0x80000000}, // eth invalid // wrong depth and purpose-id {5, 0, @@ -115,7 +107,6 @@ const uint32_t paths[][7] = { {3, 1, NATIVE_SEGWIT, BITCOIN, 0x80000000}, // btc valid {3, 1, NATIVE_SEGWIT, BITCOIN, 0x8fffffff}, // btc valid {3, 1, NON_SEGWIT, BITCOIN, 0x80000000}, // btc valid - {3, 1, NON_SEGWIT, BTC_TEST, 0x8fffffff}, // btct valid {3, 1, NON_SEGWIT, DOGE, 0x80000000}, // doge valid {3, 1, NON_SEGWIT, DOGE, 0x8fffffff}, // doge valid {3, 1, NON_SEGWIT, DASH, 0x8fffffff}, // dash valid @@ -191,8 +182,11 @@ TEST(xpub, derivation_path_tests) { case SOLANA: status = solana_derivation_path_guard(&paths[i][2], depth); break; + case ETHEREUM: + status = evm_derivation_path_guard(&paths[i][2], depth); + break; default: - status = verify_xpub_derivation_path(&paths[i][2], depth); + status = false; break; }