From 8994c37be1aac45b5e57c8ae05b9f645a1586ad4 Mon Sep 17 00:00:00 2001 From: Julian Early Date: Sun, 16 Jun 2024 14:35:17 -0700 Subject: [PATCH] feat: add Base chain support --- apps/evm_family/base/base_app.c | 154 ++++++++++++++++++++++ apps/evm_family/base/base_app.h | 44 +++++++ common/coin_support/base.h | 21 +++ common/coin_support/coin_utils.c | 1 + common/coin_support/coin_utils.h | 1 + common/core/core_flow_init.c | 2 + utilities/cmake/firmware/firmware.cmake | 1 + utilities/cmake/simulator/simulator.cmake | 1 + 8 files changed, 225 insertions(+) create mode 100644 apps/evm_family/base/base_app.c create mode 100644 apps/evm_family/base/base_app.h create mode 100644 common/coin_support/base.h diff --git a/apps/evm_family/base/base_app.c b/apps/evm_family/base/base_app.c new file mode 100644 index 000000000..8046ba7ef --- /dev/null +++ b/apps/evm_family/base/base_app.c @@ -0,0 +1,154 @@ +/** + * @file base_app.c + * @author Cypherock X1 Team + * @brief BASE application configuration and helpers + * @copyright Copyright (c) 2023 HODL TECH PTE LTD + *
You may obtain a copy of license at https://mitcc.org/ + * + ****************************************************************************** + * @attention + * + * (c) Copyright 2023 by HODL TECH PTE LTD + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * "Commons Clause" License Condition v1.0 + * + * The Software is provided to you by the Licensor under the License, + * as defined below, subject to the following condition. + * + * Without limiting other conditions in the License, the grant of + * rights under the License will not include, and the License does not + * grant to you, the right to Sell the Software. + * + * For purposes of the foregoing, "Sell" means practicing any or all + * of the rights granted to you under the License to provide to third + * parties, for a fee or other consideration (including without + * limitation fees for hosting or consulting/ support services related + * to the Software), a product or service whose value derives, entirely + * or substantially, from the functionality of the Software. Any license + * notice or attribution required by the License must also include + * this Commons Clause License Condition notice. + * + * Software: All X1Wallet associated files. + * License: MIT + * Licensor: HODL TECH PTE LTD + * + ****************************************************************************** + */ + +/***************************************************************************** + * INCLUDES + *****************************************************************************/ + +#include "base_app.h" + +#include + +#include "evm_main.h" + +/***************************************************************************** + * EXTERN VARIABLES + *****************************************************************************/ + +/** + * @brief Whitelisted contracts with respective token symbol + * @details A map of Ethereum contract addresses with their token symbols. These + * will enable the device to verify the ERC20 token transaction in a + * user-friendly manner. + * + * @see erc20_contracts_t + */ +extern const erc20_contracts_t base_contracts[]; + +/***************************************************************************** + * PRIVATE MACROS AND DEFINES + *****************************************************************************/ + +/***************************************************************************** + * PRIVATE TYPEDEFS + *****************************************************************************/ + +/***************************************************************************** + * STATIC FUNCTION PROTOTYPES + *****************************************************************************/ + +/** + * @brief Checks if the provided token address is whitelisted and return the + * matching contract instance. + * + * @param address Reference to the buffer containing the token address + * @param contract Pointer to store the matched contract address instance + * + * @return bool Indicating if the provided token address is whitelisted + * @return true If the address matches to an entry in the whitelist + * @return false If the address does not match to an entry in the whitelist + */ +static bool is_token_whitelisted(const uint8_t *address, + const erc20_contracts_t **contract); + +/***************************************************************************** + * STATIC VARIABLES + *****************************************************************************/ + +static const evm_config_t base_app_config = { + .lunit_name = "ETH", + .name = "BASE", + .chain_id = 8453, + + // whitelisted contracts + .is_token_whitelisted = is_token_whitelisted, +}; + +static const cy_app_desc_t base_app_desc = { + .id = 18, + .version = + { + .major = 1, + .minor = 1, + .patch = 0, + }, + .app = evm_main, + .app_config = &base_app_config}; +/***************************************************************************** + * GLOBAL VARIABLES + *****************************************************************************/ + +/***************************************************************************** + * STATIC FUNCTIONS + *****************************************************************************/ + +static bool is_token_whitelisted(const uint8_t *address, + const erc20_contracts_t **contract) { + if (NULL != contract) { + *contract = NULL; + } + return false; +} + +/***************************************************************************** + * GLOBAL FUNCTIONS + *****************************************************************************/ + +const cy_app_desc_t *get_base_app_desc() { + return &base_app_desc; +} \ No newline at end of file diff --git a/apps/evm_family/base/base_app.h b/apps/evm_family/base/base_app.h new file mode 100644 index 000000000..ad72078bb --- /dev/null +++ b/apps/evm_family/base/base_app.h @@ -0,0 +1,44 @@ +/** + * @file BASE_app.h + * @author Cypherock X1 Team + * @brief BASE application configuration + * @copyright Copyright (c) 2023 HODL TECH PTE LTD + *
You may obtain a copy of license at https://mitcc.org/ + */ +#ifndef BASE_APP_H +#define BASE_APP_H + +/***************************************************************************** + * INCLUDES + *****************************************************************************/ + +#include "app_registry.h" +#include "evm_context.h" +/***************************************************************************** + * MACROS AND DEFINES + *****************************************************************************/ + +/// Number of entries in whitelisted contracts list +#define BASE_WHITELISTED_CONTRACTS_COUNT 0 + +/***************************************************************************** + * TYPEDEFS + *****************************************************************************/ + +/***************************************************************************** + * EXPORTED VARIABLES + *****************************************************************************/ + +/***************************************************************************** + * GLOBAL FUNCTION PROTOTYPES + *****************************************************************************/ + +/** + * @brief Returns the config for BASE chin app descriptor + * + * @return A const reference to cy_app_desc_t + */ +const cy_app_desc_t *get_base_app_desc(); + +#endif // BASE_APP_H diff --git a/common/coin_support/base.h b/common/coin_support/base.h new file mode 100644 index 000000000..608d09818 --- /dev/null +++ b/common/coin_support/base.h @@ -0,0 +1,21 @@ +/** + * @file base.h + * @author Cypherock X1 Team + * @brief BASE C-Chain network config + * Place to define all values specific to BASE C-Chain + * @copyright Copyright (c) 2022 HODL TECH PTE LTD + *
You may obtain a copy of license at https://mitcc.org/ + * + */ +#ifndef BASE_H +#define BASE_H + +#define BASE_COIN_VERSION 0x00000000 + +#define BASE_MAINNET_CHAIN 8453 + +#define BASE_MAINNET_NAME "Base" +#define BASE_TOKEN_SYMBOL "ETH" + +#endif diff --git a/common/coin_support/coin_utils.c b/common/coin_support/coin_utils.c index 7e42fd171..3d03d2bc4 100644 --- a/common/coin_support/coin_utils.c +++ b/common/coin_support/coin_utils.c @@ -59,6 +59,7 @@ #include "coin_utils.h" #include "arbitrum.h" +#include "base.h" #include "avalanche.h" #include "bsc.h" #include "etc.h" diff --git a/common/coin_support/coin_utils.h b/common/coin_support/coin_utils.h index 5a5832f07..4bbd4b8b7 100644 --- a/common/coin_support/coin_utils.h +++ b/common/coin_support/coin_utils.h @@ -85,6 +85,7 @@ typedef enum Coin_Type { COIN_TYPE_HARMONY = 0x0E, COIN_TYPE_ETHEREUM_CLASSIC = 0x0f, COIN_TYPE_ARBITRUM = 0x10, + COIN_TYPE_BASE = 0x11, } Coin_Type; #pragma pack(push, 1) diff --git a/common/core/core_flow_init.c b/common/core/core_flow_init.c index afecb734a..5baa755cc 100644 --- a/common/core/core_flow_init.c +++ b/common/core/core_flow_init.c @@ -64,6 +64,7 @@ #include "app_registry.h" #include "application_startup.h" #include "arbitrum_app.h" +#include "base_app.h" #include "avalanche_app.h" #include "bsc_app.h" #include "btc_app.h" @@ -177,4 +178,5 @@ void core_init_app_registry() { registry_add_app(get_avalanche_app_desc()); registry_add_app(get_optimism_app_desc()); registry_add_app(get_arbitrum_app_desc()); + registry_add_app(get_base_app_desc()); } \ No newline at end of file diff --git a/utilities/cmake/firmware/firmware.cmake b/utilities/cmake/firmware/firmware.cmake index 8a67d9695..d81ab3e04 100644 --- a/utilities/cmake/firmware/firmware.cmake +++ b/utilities/cmake/firmware/firmware.cmake @@ -55,6 +55,7 @@ target_include_directories(${EXECUTABLE} PRIVATE apps/evm_family/avalanche apps/evm_family/optimism apps/evm_family/arbitrum + apps/evm_family/base apps/near_app apps/solana_app diff --git a/utilities/cmake/simulator/simulator.cmake b/utilities/cmake/simulator/simulator.cmake index 9b78a9a81..bba294125 100644 --- a/utilities/cmake/simulator/simulator.cmake +++ b/utilities/cmake/simulator/simulator.cmake @@ -51,6 +51,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE apps/evm_family/avalanche apps/evm_family/optimism apps/evm_family/arbitrum + apps/evm_family/base apps/near_app apps/solana_app