Merge pull request #438 from LedgerHQ/feat/apa/ens_on_other_chains

ENS on other chains
This commit is contained in:
apaillier-ledger
2023-07-07 13:40:43 +02:00
committed by GitHub
35 changed files with 129 additions and 110 deletions

View File

@@ -47,6 +47,8 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI,
uint32_t titleLength,
char *msg,
uint32_t msgLength) {
uint64_t chain_id;
memset((uint8_t *) queryContractUI, 0, sizeof(ethQueryContractUI_t));
// If no extra information was found, set the pointer to NULL
@@ -64,7 +66,8 @@ void eth_plugin_prepare_query_contract_UI(ethQueryContractUI_t *queryContractUI,
}
queryContractUI->screenIndex = screenIndex;
strlcpy(queryContractUI->network_ticker, get_tx_network_ticker(), MAX_TICKER_LEN);
chain_id = get_tx_chain_id();
strlcpy(queryContractUI->network_ticker, get_displayable_ticker(&chain_id), MAX_TICKER_LEN);
queryContractUI->title = title;
queryContractUI->titleLength = titleLength;
queryContractUI->msg = msg;

View File

@@ -24,36 +24,36 @@ const tokenDefinition_t TOKENS_EXTRA[NUM_TOKENS_EXTRA] = {
// Ropsten DeversiFi tokens
{{0x4c, 0x5f, 0x66, 0x59, 0x61, 0x97, 0xa8, 0x6f, 0xb3, 0x0a,
0x24, 0x35, 0xe2, 0xef, 0x4d, 0xdc, 0xb3, 0x93, 0x42, 0xc9},
"tUSDT ",
"tUSDT",
6},
{{0x1c, 0x0f, 0x17, 0x43, 0x67, 0x40, 0xbf, 0xb9, 0x2c, 0x10,
0x70, 0xee, 0x86, 0x32, 0x2d, 0xe8, 0x90, 0x83, 0x7c, 0x6a},
"tUSDT ",
"tUSDT",
6},
{{0xcd, 0x07, 0x7a, 0xbe, 0xdd, 0x83, 0x1a, 0x34, 0x43, 0xff,
0xbe, 0x24, 0xfb, 0x76, 0x66, 0x1b, 0xbb, 0x17, 0xeb, 0x69},
"tZRX ",
"tZRX",
18},
{{0x40, 0xd8, 0x97, 0x85, 0x00, 0xbf, 0x68, 0x32, 0x4a, 0x51,
0x53, 0x3c, 0xd6, 0xa2, 0x1e, 0x3e, 0x59, 0xbe, 0x32, 0x4a},
"tBTC ",
"tBTC",
18},
// Goerli DeversiFi tokens
{{0xd9, 0x97, 0xa8, 0x63, 0x46, 0xe7, 0x65, 0x18, 0xe6, 0x92,
0x25, 0x56, 0xf3, 0x4d, 0x76, 0x61, 0x30, 0xc0, 0xbb, 0xfd},
"tUSDT ",
"tUSDT",
6},
{{0xc1, 0xd5, 0x79, 0xeb, 0xff, 0x7c, 0x0f, 0x6c, 0xfd, 0x9a,
0xd5, 0xfb, 0x26, 0x7f, 0xec, 0x73, 0xbe, 0x70, 0xc8, 0xf7},
"tBTC ",
"tBTC",
18},
{{0xa8, 0xf3, 0x14, 0x4f, 0xea, 0x2c, 0x37, 0x5a, 0xd0, 0x58,
0xec, 0x12, 0x09, 0x9a, 0x5a, 0x21, 0xa2, 0x6f, 0xe9, 0x96},
"tDVF ",
"tDVF",
18},
{{0x4c, 0xda, 0xbe, 0xc1, 0x2a, 0x39, 0x7f, 0xb6, 0xef, 0xaf,
0x46, 0x13, 0xd5, 0xdf, 0xd7, 0x9b, 0x30, 0x9a, 0xe9, 0xfa},
"tXDVF ",
"tXDVF",
18},
};
@@ -69,11 +69,11 @@ const tokenDefinition_t TOKENS_EXTRA[NUM_TOKENS_EXTRA] = {
const tokenDefinition_t const TOKENS_ETHEREUM[NUM_TOKENS_ETHEREUM] = {
{{0xdb, 0x25, 0xf2, 0x11, 0xab, 0x05, 0xb1, 0xc9, 0x7d, 0x59,
0x55, 0x16, 0xf4, 0x57, 0x94, 0x52, 0x8a, 0x80, 0x7a, 0xd8},
"EURS ",
"EURS",
2},
{{0xa7, 0x44, 0x76, 0x44, 0x31, 0x19, 0xA9, 0x42, 0xdE, 0x49,
0x85, 0x90, 0xFe, 0x1f, 0x24, 0x54, 0xd7, 0xD4, 0xaC, 0x0d},
"GNT ",
"GNT",
18},
};
@@ -89,19 +89,19 @@ const tokenDefinition_t const TOKENS_ELLAISM[NUM_TOKENS_ELLAISM] = {
const tokenDefinition_t const TOKENS_ETHEREUM_CLASSIC[NUM_TOKENS_ETHEREUM_CLASSIC] = {
{{0x6F, 0x6D, 0xEb, 0x5d, 0xb0, 0xC4, 0x99, 0x4A, 0x82, 0x83,
0xA0, 0x1D, 0x6C, 0xFe, 0xEB, 0x27, 0xFc, 0x3b, 0xBe, 0x9C},
"Smart ",
"Smart",
0},
{{0x08, 0x5f, 0xb4, 0xf2, 0x40, 0x31, 0xea, 0xed, 0xbc, 0x2b,
0x61, 0x1a, 0xa5, 0x28, 0xf2, 0x23, 0x43, 0xeb, 0x52, 0xdb},
"BEC ",
"BEC",
8},
{{0x5a, 0xce, 0x17, 0xf8, 0x7c, 0x73, 0x91, 0xe5, 0x79, 0x2a,
0x76, 0x83, 0x06, 0x9a, 0x80, 0x25, 0xb8, 0x3b, 0xbd, 0x85},
"PLAY ",
"PLAY",
0},
{{0x6A, 0xDa, 0x6F, 0x48, 0xC8, 0x15, 0x68, 0x95, 0x02, 0xC4,
0x3e, 0xC1, 0xa5, 0x9F, 0x1b, 0x5D, 0xD3, 0xC0, 0x4E, 0x1F},
"UNV ",
"UNV",
18},
};
@@ -118,27 +118,27 @@ const tokenDefinition_t const TOKENS_RSK[NUM_TOKENS_RSK] = {};
const tokenDefinition_t const TOKENS_UBIQ[NUM_TOKENS_UBIQ] = {
{{0xd2, 0x45, 0x20, 0x7c, 0xfb, 0xf6, 0xeb, 0x6f, 0x34, 0x97,
0x0d, 0xb2, 0xa8, 0x07, 0xab, 0x1d, 0x17, 0x8f, 0xde, 0x6c},
"APX ",
"APX",
8},
{{0xff, 0x3b, 0xf0, 0x57, 0xad, 0xf3, 0xb0, 0xe0, 0x15, 0xb6,
0x46, 0x53, 0x31, 0xa6, 0x23, 0x6e, 0x55, 0x68, 0x82, 0x74},
"BEER ",
"BEER",
0},
{{0x08, 0x53, 0x3d, 0x6a, 0x06, 0xce, 0x36, 0x52, 0x98, 0xb1,
0x2e, 0xf9, 0x2e, 0xb4, 0x07, 0xcb, 0xa8, 0xaa, 0x82, 0x73},
"CEFS ",
"CEFS",
8},
{{0x94, 0xad, 0x7e, 0x41, 0xc1, 0xd4, 0x40, 0x22, 0xc4, 0xf4,
0x7c, 0xb1, 0xba, 0x01, 0x9f, 0xd1, 0xa0, 0x22, 0xc5, 0x36},
"DOT ",
"DOT",
8},
{{0x4b, 0x48, 0x99, 0xa1, 0x0f, 0x3e, 0x50, 0x7d, 0xb2, 0x07,
0xb0, 0xee, 0x24, 0x26, 0x02, 0x9e, 0xfa, 0x16, 0x8a, 0x67},
"QWARK ",
"QWARK",
8},
{{0x5e, 0x17, 0x15, 0xbb, 0x79, 0x80, 0x5b, 0xd6, 0x72, 0x72,
0x97, 0x60, 0xb3, 0xf7, 0xf3, 0x4d, 0x6f, 0x48, 0x50, 0x98},
"RICKS ",
"RICKS",
8},
};

View File

@@ -27,9 +27,12 @@
#include <stdint.h>
#include <string.h>
#include "shared_context.h"
#include "utils.h"
#include "ethUtils.h"
#include "chainConfig.h"
#include "ethUstream.h"
#include "network.h"
bool rlpCanDecode(uint8_t *buffer, uint32_t bufferLength, bool *valid) {
if (*buffer <= 0x7f) {
@@ -301,3 +304,32 @@ bool adjustDecimals(const char *src,
}
return true;
}
// Returns the chain ID. Defaults to 0 if txType was not found (For TX).
uint64_t get_tx_chain_id(void) {
uint64_t chain_id = 0;
switch (txContext.txType) {
case LEGACY:
chain_id = u64_from_BE(txContext.content->v, txContext.content->vLength);
break;
case EIP2930:
case EIP1559:
chain_id = u64_from_BE(tmpContent.txContent.chainID.value,
tmpContent.txContent.chainID.length);
break;
default:
PRINTF("Txtype `%d` not supported while generating chainID\n", txContext.txType);
break;
}
return chain_id;
}
const char *get_displayable_ticker(const uint64_t *chain_id) {
const char *ticker = get_network_ticker_from_chain_id(chain_id);
if (ticker == NULL) {
ticker = chainConfig->coinName;
}
return ticker;
}

View File

@@ -84,6 +84,10 @@ static __attribute__((no_instrument_function)) inline int ismaxint(uint8_t *buf,
return 1;
}
uint64_t get_tx_chain_id(void);
const char *get_displayable_ticker(const uint64_t *chain_id);
static const char HEXDIGITS[] = "0123456789abcdef";
#endif // _ETHUTILS_H_

View File

@@ -1,13 +1,13 @@
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include "os_utils.h"
#include "os_pic.h"
#include "network.h"
#include "os.h"
#include "shared_context.h"
#include "utils.h"
typedef enum { APP, TX } e_net_type;
typedef struct network_info_s {
const char *name;
const char *ticker;
uint64_t chain_id;
} network_info_t;
// Mappping of chain ids to networks.
static const network_info_t NETWORK_MAPPING[] = {
@@ -66,73 +66,33 @@ static const network_info_t NETWORK_MAPPING[] = {
{.chain_id = 39797, .name = "Energi", .ticker = "NRG"},
{.chain_id = 248, .name = "Oasys", .ticker = "OAS"}};
uint64_t get_tx_chain_id(void) {
uint64_t chain_id = 0;
switch (txContext.txType) {
case LEGACY:
chain_id = u64_from_BE(txContext.content->v, txContext.content->vLength);
break;
case EIP2930:
case EIP1559:
chain_id = u64_from_BE(tmpContent.txContent.chainID.value,
tmpContent.txContent.chainID.length);
break;
default:
PRINTF("Txtype `%d` not supported while generating chainID\n", txContext.txType);
break;
}
return chain_id;
}
uint64_t get_app_chain_id(void) {
return chainConfig->chainId;
}
static uint64_t get_chain_id(e_net_type type) {
return (type == APP) ? get_app_chain_id() : get_tx_chain_id();
}
static const network_info_t *get_network(e_net_type type) {
uint64_t chain_id = get_chain_id(type);
for (size_t i = 0; i < sizeof(NETWORK_MAPPING) / sizeof(*NETWORK_MAPPING); i++) {
if (NETWORK_MAPPING[i].chain_id == chain_id) {
return (const network_info_t *) PIC(&NETWORK_MAPPING[i]);
static const network_info_t *get_network_from_chain_id(const uint64_t *chain_id) {
for (size_t i = 0; i < ARRAYLEN(NETWORK_MAPPING); i++) {
if (NETWORK_MAPPING[i].chain_id == *chain_id) {
return (const network_info_t *) &NETWORK_MAPPING[i];
}
}
return NULL;
}
static const char *get_network_name(e_net_type type) {
const network_info_t *network = get_network(type);
if (network == NULL) {
const char *get_network_name_from_chain_id(const uint64_t *chain_id) {
const network_info_t *net = get_network_from_chain_id(chain_id);
if (net == NULL) {
return NULL;
} else {
return (const char *) PIC(network->name);
}
return PIC(net->name);
}
const char *get_app_network_name(void) {
return get_network_name(APP);
}
const char *get_network_ticker_from_chain_id(const uint64_t *chain_id) {
const network_info_t *net = get_network_from_chain_id(chain_id);
const char *get_tx_network_name(void) {
return get_network_name(TX);
}
static const char *get_network_ticker(e_net_type type) {
const network_info_t *network = get_network(type);
if (network == NULL) {
return chainConfig->coinName;
} else {
return (char *) PIC(network->ticker);
if (net == NULL) {
return NULL;
}
return PIC(net->ticker);
}
const char *get_app_network_ticker(void) {
return get_network_ticker(APP);
}
const char *get_tx_network_ticker(void) {
return get_network_ticker(TX);
bool chain_is_ethereum_compatible(const uint64_t *chain_id) {
return get_network_from_chain_id(chain_id) != NULL;
}

View File

@@ -2,24 +2,11 @@
#define _NETWORK_H_
#include <stdint.h>
#include "tokens.h"
#include "shared_context.h"
#include <stdbool.h>
typedef struct network_info_s {
const char *name;
const char *ticker;
uint64_t chain_id;
} network_info_t;
const char *get_network_name_from_chain_id(const uint64_t *chain_id);
const char *get_network_ticker_from_chain_id(const uint64_t *chain_id);
// Returns the chain ID. Defaults to 0 if txType was not found (For TX).
uint64_t get_tx_chain_id(void);
uint64_t get_app_chain_id(void);
// Returns a pointer to the network name, or NULL if there is none.
const char *get_tx_network_name(void);
const char *get_app_network_name(void);
// Returns a pointer to the network ticker, or chainConfig->coinName if there is none.
const char *get_tx_network_ticker(void);
const char *get_app_network_ticker(void);
bool chain_is_ethereum_compatible(const uint64_t *chain_id);
#endif // _NETWORK_H_

View File

@@ -10,6 +10,7 @@
#include "challenge.h"
#include "mem.h"
#include "hash_bytes.h"
#include "network.h"
static const uint8_t DOMAIN_NAME_PUB_KEY[] = {
#ifdef HAVE_DOMAIN_NAME_TEST_KEY
@@ -124,8 +125,8 @@ bool has_domain_name(const uint64_t *chain_id, const uint8_t *addr) {
bool ret = false;
if (g_domain_name_info.valid) {
// TODO: Remove once other domain name providers are supported
if ((*chain_id == ETHEREUM_MAINNET_CHAINID) &&
// Check if chain ID is known to be Ethereum-compatible (same derivation path)
if ((chain_is_ethereum_compatible(chain_id)) &&
(memcmp(addr, g_domain_name_info.addr, ADDRESS_LENGTH) == 0)) {
ret = true;
}

View File

@@ -196,7 +196,8 @@ static void address_to_string(uint8_t *in,
}
static void raw_fee_to_string(uint256_t *rawFee, char *displayBuffer, uint32_t displayBufferSize) {
const char *feeTicker = get_tx_network_ticker();
uint64_t chain_id = get_tx_chain_id();
const char *feeTicker = get_displayable_ticker(&chain_id);
uint8_t tickerOffset = 0;
uint32_t i;
@@ -263,10 +264,10 @@ static void nonce_to_string(const txInt256_t *nonce, char *out, size_t out_size)
}
static void get_network_as_string(char *out, size_t out_size) {
const char *name = get_tx_network_name();
uint64_t chain_id = get_tx_chain_id();
const char *name = get_network_name_from_chain_id(&chain_id);
if (name == NULL) {
// No network name found so simply copy the chain ID as the network name.
uint64_t chain_id = get_tx_chain_id();
u64_to_string(chain_id, out, out_size);
} else {
// Network name found, simply copy it.
@@ -313,7 +314,8 @@ static int strcasecmp_workaround(const char *str1, const char *str2) {
void finalizeParsing(bool direct) {
char displayBuffer[50];
uint8_t decimals = WEI_TO_ETHER;
const char *ticker = get_tx_network_ticker();
uint64_t chain_id = get_tx_chain_id();
const char *ticker = get_displayable_ticker(&chain_id);
ethPluginFinalize_t pluginFinalize;
bool use_standard_UI = true;

View File

@@ -3,7 +3,7 @@
#include "shared_context.h"
#include "ui_callbacks.h"
#include "ui_nbgl.h"
#include "network.h"
#include "ethUtils.h"
#include "plugins.h"
#include "domain_name.h"

View File

@@ -47,7 +47,8 @@ void ui_idle(void) {
tagline = staxSharedBuffer;
}
} else { // Ethereum app
app_name = get_app_network_name();
uint64_t mainnet_chain_id = ETHEREUM_MAINNET_CHAINID;
app_name = get_network_name_from_chain_id(&mainnet_chain_id);
}
nbgl_useCaseHome((char *) app_name,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 B

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 B

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@@ -139,13 +139,42 @@ def test_send_fund_non_mainnet(firmware: Firmware,
moves += [ NavInsID.RIGHT_CLICK ] * 5
moves += [ NavInsID.BOTH_CLICK ]
else:
moves += [ NavInsID.USE_CASE_REVIEW_TAP ] * 3
moves += [ NavInsID.USE_CASE_REVIEW_TAP ] * 2
moves += [ NavInsID.USE_CASE_REVIEW_CONFIRM ]
navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH,
"domain_name_non_mainnet",
moves)
def test_send_fund_unknown_chain(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
test_name: str):
app_client = EthAppClient(backend)
challenge = common(app_client)
with app_client.provide_domain_name(challenge, NAME, ADDR):
pass
with app_client.send_fund(BIP32_PATH,
NONCE,
GAS_PRICE,
GAS_LIMIT,
ADDR,
AMOUNT,
9):
moves = list()
if firmware.device.startswith("nano"):
moves += [ NavInsID.RIGHT_CLICK ] * 5
moves += [ NavInsID.BOTH_CLICK ]
else:
moves += [ NavInsID.USE_CASE_REVIEW_TAP ] * 3
moves += [ NavInsID.USE_CASE_REVIEW_CONFIRM ]
navigator.navigate_and_compare(ROOT_SCREENSHOT_PATH,
"domain_name_unknown_chain",
moves)
def test_send_fund_domain_too_long(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator):