Skip to content

Commit 2008370

Browse files
Removed legacy extra info handling
1 parent fa045ef commit 2008370

6 files changed

Lines changed: 29 additions & 89 deletions

File tree

src/features/sign_tx/logic_sign_tx.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,6 @@ __attribute__((noinline)) static uint16_t finalize_parsing_helper(const txContex
285285

286286
// Verify the chain
287287
if (g_chain_config->chain_id != ETHEREUM_MAINNET_CHAINID) {
288-
chain_id = get_tx_chain_id();
289-
290288
if (g_chain_config->chain_id != chain_id) {
291289
PRINTF("Invalid chainID %llu expected %llu\n", chain_id, g_chain_config->chain_id);
292290
report_finalize_error();
@@ -333,24 +331,28 @@ __attribute__((noinline)) static uint16_t finalize_parsing_helper(const txContex
333331
error = APDU_NO_RESPONSE;
334332
goto end;
335333
}
334+
335+
// store the lookup addresses
336+
// not needed to set them for PLUGIN_PROVIDE_INFO since it is done within this function,
337+
// but required for PLUGIN_QUERY_CONTRACT_UI
338+
dataContext.tokenContext.token_lookup1 = pluginFinalize.tokenLookup1;
339+
dataContext.tokenContext.token_lookup2 = pluginFinalize.tokenLookup2;
340+
336341
// Lookup tokens if requested
337342
ethPluginProvideInfo_t pluginProvideInfo;
338343
eth_plugin_prepare_provide_info(&pluginProvideInfo);
339-
if ((pluginFinalize.tokenLookup1 != NULL) || (pluginFinalize.tokenLookup2 != NULL)) {
340-
if (pluginFinalize.tokenLookup1 != NULL) {
341-
PRINTF("Lookup1: %.*H\n", ADDRESS_LENGTH, pluginFinalize.tokenLookup1);
342-
pluginProvideInfo.item1 = get_asset_info_by_addr(pluginFinalize.tokenLookup1);
343-
if (pluginProvideInfo.item1 != NULL) {
344-
PRINTF("Token1 ticker: %s\n", pluginProvideInfo.item1->token.ticker);
345-
}
346-
}
347-
if (pluginFinalize.tokenLookup2 != NULL) {
348-
PRINTF("Lookup2: %.*H\n", ADDRESS_LENGTH, pluginFinalize.tokenLookup2);
349-
pluginProvideInfo.item2 = get_asset_info_by_addr(pluginFinalize.tokenLookup2);
350-
if (pluginProvideInfo.item2 != NULL) {
351-
PRINTF("Token2 ticker: %s\n", pluginProvideInfo.item2->token.ticker);
352-
}
353-
}
344+
pluginProvideInfo.item1 =
345+
get_matching_asset_info(&chain_id, dataContext.tokenContext.token_lookup1);
346+
if (pluginProvideInfo.item1 != NULL) {
347+
PRINTF("Asset1 ticker: %s\n", pluginProvideInfo.item1->token.ticker);
348+
}
349+
pluginProvideInfo.item2 =
350+
get_matching_asset_info(&chain_id, dataContext.tokenContext.token_lookup2);
351+
if (pluginProvideInfo.item2 != NULL) {
352+
PRINTF("Asset2 ticker: %s\n", pluginProvideInfo.item2->token.ticker);
353+
}
354+
if ((dataContext.tokenContext.token_lookup1 != NULL) ||
355+
(dataContext.tokenContext.token_lookup2 != NULL)) {
354356
if (eth_plugin_call(ETH_PLUGIN_PROVIDE_INFO, (void *) &pluginProvideInfo) <=
355357
ETH_PLUGIN_RESULT_UNSUCCESSFUL) {
356358
PRINTF("Plugin provide token call failed\n");

src/manage_asset_info.c

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -36,51 +36,6 @@ extraInfo_t *get_matching_asset_info(const uint64_t *chain_id, const uint8_t *ad
3636
}
3737

3838
void forget_known_assets(void) {
39-
memset(tmpCtx.transactionContext.assetSet, false, MAX_ASSETS);
40-
tmpCtx.transactionContext.currentAssetIndex = 0;
4139
clear_token_infos();
4240
clear_nft_infos();
4341
}
44-
45-
static extraInfo_t *get_asset_info(int index) {
46-
if ((index < 0) || (index >= MAX_ASSETS)) {
47-
return NULL;
48-
}
49-
return &tmpCtx.transactionContext.extraInfo[index];
50-
}
51-
52-
static bool asset_info_is_set(int index) {
53-
if ((index < 0) || (index >= MAX_ASSETS)) {
54-
return false;
55-
}
56-
return tmpCtx.transactionContext.assetSet[index];
57-
}
58-
59-
int get_asset_index_by_addr(const uint8_t *addr) {
60-
// Works for ERC-20 & NFT tokens since both structs in the union have the
61-
// contract address aligned
62-
for (int i = 0; i < MAX_ASSETS; i++) {
63-
extraInfo_t *asset = get_asset_info(i);
64-
if (asset_info_is_set(i) && (memcmp(asset->token.address, addr, ADDRESS_LENGTH) == 0)) {
65-
PRINTF("Asset found at index %d\n", i);
66-
return i;
67-
}
68-
}
69-
return -1;
70-
}
71-
72-
extraInfo_t *get_asset_info_by_addr(const uint8_t *addr) {
73-
return get_asset_info(get_asset_index_by_addr(addr));
74-
}
75-
76-
extraInfo_t *get_current_asset_info(void) {
77-
return get_asset_info(tmpCtx.transactionContext.currentAssetIndex);
78-
}
79-
80-
void validate_current_asset_info(void) {
81-
// mark it as set
82-
tmpCtx.transactionContext.assetSet[tmpCtx.transactionContext.currentAssetIndex] = true;
83-
// increment index
84-
tmpCtx.transactionContext.currentAssetIndex =
85-
(tmpCtx.transactionContext.currentAssetIndex + 1) % MAX_ASSETS;
86-
}

src/manage_asset_info.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,3 @@
55

66
extraInfo_t *get_matching_asset_info(const uint64_t *chain_id, const uint8_t *address);
77
void forget_known_assets(void);
8-
int get_asset_index_by_addr(const uint8_t *addr);
9-
extraInfo_t *get_asset_info_by_addr(const uint8_t *contractAddress);
10-
extraInfo_t *get_current_asset_info(void);
11-
void validate_current_asset_info(void);

src/plugins/eth_plugin_handler.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "swap_with_calldata_plugin.h"
1313
#include "eip7002_plugin.h"
1414
#include "eip7251_plugin.h"
15+
#include "manage_asset_info.h"
16+
#include "utils.h"
1517

1618
// All internal alias names start with 'minus'
1719

@@ -77,22 +79,14 @@ void eth_plugin_prepare_query_contract_ui(ethQueryContractUI_t *query_contract_u
7779

7880
explicit_bzero((uint8_t *) query_contract_ui, sizeof(ethQueryContractUI_t));
7981

80-
// If no extra information was found, set the pointer to NULL
81-
if (NO_EXTRA_INFO(tmpCtx, 0)) {
82-
query_contract_ui->item1 = NULL;
83-
} else {
84-
query_contract_ui->item1 = &tmpCtx.transactionContext.extraInfo[0];
85-
}
82+
chain_id = get_tx_chain_id();
8683

87-
// If no extra information was found, set the pointer to NULL
88-
if (NO_EXTRA_INFO(tmpCtx, 1)) {
89-
query_contract_ui->item2 = NULL;
90-
} else {
91-
query_contract_ui->item2 = &tmpCtx.transactionContext.extraInfo[1];
92-
}
84+
query_contract_ui->item1 =
85+
get_matching_asset_info(&chain_id, dataContext.tokenContext.token_lookup1);
86+
query_contract_ui->item2 =
87+
get_matching_asset_info(&chain_id, dataContext.tokenContext.token_lookup2);
9388

9489
query_contract_ui->screenIndex = screen_index;
95-
chain_id = get_tx_chain_id();
9690
strlcpy(query_contract_ui->network_ticker,
9791
get_displayable_ticker(&chain_id, g_chain_config, true),
9892
sizeof(query_contract_ui->network_ticker));

src/plugins/eth_plugin_handler.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
#include "eth_plugin_interface.h"
44

5-
#define NO_EXTRA_INFO(ctx, idx) \
6-
(allzeroes(&(ctx.transactionContext.extraInfo[idx]), sizeof(extraInfo_t)))
7-
8-
#define NO_NFT_METADATA (NO_EXTRA_INFO(tmpCtx, 0))
9-
105
void eth_plugin_prepare_init(ethPluginInitContract_t *init,
116
const uint8_t *selector,
127
uint32_t data_size);

src/shared_context.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
#define N_storage (*(volatile internalStorage_t *) PIC(&N_storage_real))
3030

31-
#define MAX_ASSETS 5
32-
3331
typedef struct internalStorage_t {
3432
bool dataAllowed;
3533
bool contractDetails;
@@ -49,6 +47,9 @@ typedef struct internalStorage_t {
4947
typedef struct tokenContext_t {
5048
char pluginName[PLUGIN_ID_LENGTH];
5149

50+
const uint8_t *token_lookup1;
51+
const uint8_t *token_lookup2;
52+
5253
uint8_t data[INT256_LENGTH];
5354
uint16_t fieldIndex;
5455
uint8_t fieldOffset;
@@ -83,9 +84,6 @@ typedef struct publicKeyContext_t {
8384
typedef struct transactionContext_t {
8485
bip32_path_t bip32;
8586
uint8_t hash[INT256_LENGTH];
86-
union extraInfo_t extraInfo[MAX_ASSETS];
87-
bool assetSet[MAX_ASSETS];
88-
uint8_t currentAssetIndex;
8987
} transactionContext_t;
9088

9189
typedef struct messageSigningContext_t {

0 commit comments

Comments
 (0)