Skip to content

Commit 839aba5

Browse files
Merge pull request #963 from LedgerHQ/cev/cleanup
Cleanup & Renaming
2 parents 8268cd1 + 14efac1 commit 839aba5

140 files changed

Lines changed: 719 additions & 612 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/eth_contract_support_embedded.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ The following online tool can be used to compute selectors https://emn178.github
3838
3939
A UI implementation might want to convert an ERC 20 token contract address to a ticker for easier validation
4040
41-
2 tickers can be temporarily provisioned to the application by using the PROVIDE ERC 20 TOKEN INFORMATION APDU, described in *src/features/provideErc20TokenInformation* - the UI can then iterate on the provisioned tickers to display relevant information to the user
41+
2 tickers can be temporarily provisioned to the application by using the PROVIDE ERC 20 TOKEN INFORMATION APDU, described in *src/features/provide_erc20_token_information* - the UI can then iterate on the provisioned tickers to display relevant information to the user
4242
4343
The same mechanism will be extended to support well known contract addresses in the future

makefile_conf/features.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Activate requested features
22
# ---------------------------
3-
# Bypass the signature verification for setExternalPlugin, setPlugin, provideERC20TokenInfo and provideNFTInfo calls
3+
# Bypass the signature verification for set_external_plugin, set_plugin, provide_erc20_token_information and provide_nft_information calls
44
BYPASS_SIGNATURES ?= 0
55
ifneq ($(BYPASS_SIGNATURES),0)
66
DEFINES += HAVE_BYPASS_SIGNATURES

src/apdu_constants.h

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -79,52 +79,52 @@
7979
#define APDU_NO_RESPONSE 0x0000
8080
#define APDU_RESPONSE_MODE_CHECK_FAILED 0x6001
8181

82-
uint16_t handleGetPublicKey(uint8_t p1,
83-
uint8_t p2,
84-
const uint8_t *dataBuffer,
85-
uint8_t dataLength,
86-
unsigned int *flags,
87-
unsigned int *tx);
88-
uint16_t handleProvideErc20TokenInformation(const uint8_t *workBuffer,
89-
uint8_t dataLength,
90-
unsigned int *tx);
91-
uint16_t handleProvideNFTInformation(const uint8_t *dataBuffer,
92-
uint8_t dataLength,
93-
unsigned int *tx);
94-
uint16_t handleSign(uint8_t p1,
95-
uint8_t p2,
96-
const uint8_t *dataBuffer,
97-
uint8_t dataLength,
98-
unsigned int *flags);
99-
uint16_t handleGetAppConfiguration(unsigned int *tx);
100-
uint16_t handleSignPersonalMessage(uint8_t p1,
101-
const uint8_t *const payload,
102-
uint8_t length,
103-
unsigned int *flags);
104-
uint16_t handleSignEIP712Message_v0(uint8_t p1,
105-
const uint8_t *dataBuffer,
106-
uint8_t dataLength,
107-
unsigned int *flags);
82+
uint16_t handle_get_public_key(uint8_t p1,
83+
uint8_t p2,
84+
const uint8_t *dataBuffer,
85+
uint8_t dataLength,
86+
unsigned int *flags,
87+
unsigned int *tx);
88+
uint16_t handle_provide_erc20_token_information(const uint8_t *workBuffer,
89+
uint8_t dataLength,
90+
unsigned int *tx);
91+
uint16_t handle_provide_nft_information(const uint8_t *dataBuffer,
92+
uint8_t dataLength,
93+
unsigned int *tx);
94+
uint16_t handle_sign(uint8_t p1,
95+
uint8_t p2,
96+
const uint8_t *dataBuffer,
97+
uint8_t dataLength,
98+
unsigned int *flags);
99+
uint16_t handle_get_app_configuration(unsigned int *tx);
100+
uint16_t handle_sign_personal_message(uint8_t p1,
101+
const uint8_t *const payload,
102+
uint8_t length,
103+
unsigned int *flags);
104+
uint16_t handle_sign_eip712_message_v0(uint8_t p1,
105+
const uint8_t *dataBuffer,
106+
uint8_t dataLength,
107+
unsigned int *flags);
108108

109-
uint16_t handleSetExternalPlugin(const uint8_t *workBuffer, uint8_t dataLength);
109+
uint16_t handle_set_external_plugin(const uint8_t *workBuffer, uint8_t dataLength);
110110

111-
uint16_t handleSetPlugin(const uint8_t *workBuffer, uint8_t dataLength);
111+
uint16_t handle_set_plugin(const uint8_t *workBuffer, uint8_t dataLength);
112112

113-
uint16_t handlePerformPrivacyOperation(uint8_t p1,
114-
uint8_t p2,
115-
const uint8_t *workBuffer,
116-
uint8_t dataLength,
117-
unsigned int *flags,
118-
unsigned int *tx);
113+
uint16_t handle_perform_privacy_operation(uint8_t p1,
114+
uint8_t p2,
115+
const uint8_t *workBuffer,
116+
uint8_t dataLength,
117+
unsigned int *flags,
118+
unsigned int *tx);
119119

120120
#ifdef HAVE_ETH2
121121

122-
uint16_t handleGetEth2PublicKey(uint8_t p1,
123-
uint8_t p2,
124-
const uint8_t *dataBuffer,
125-
uint8_t dataLength,
126-
unsigned int *flags,
127-
unsigned int *tx);
122+
uint16_t handle_get_eth2_public_key(uint8_t p1,
123+
uint8_t p2,
124+
const uint8_t *dataBuffer,
125+
uint8_t dataLength,
126+
unsigned int *flags,
127+
unsigned int *tx);
128128

129129
#endif
130130

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ typedef struct chain_config_s {
2525
} chain_config_t;
2626

2727
#define ETHEREUM_MAINNET_CHAINID 1
28+
29+
// Chain ID Validation (per EIP-2294)
30+
// See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2294.md
31+
#define MAX_VALID_CHAIN_ID 0x7FFFFFFFFFFFFFDB

src/features/generic_tx_parser/gtp_field.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "calldata.h"
1919
#include "lists.h"
2020

21+
#define MAX_FIELD_NAME_SIZE 21
22+
2123
typedef enum {
2224
PARAM_TYPE_RAW = 0,
2325
PARAM_TYPE_AMOUNT,
@@ -49,7 +51,7 @@ typedef struct s_field_constraint {
4951

5052
typedef struct s_field {
5153
uint8_t version;
52-
char name[21];
54+
char name[MAX_FIELD_NAME_SIZE];
5355
e_param_type param_type;
5456
union {
5557
s_param_raw param_raw;

src/features/generic_tx_parser/gtp_param_network.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "tx_ctx.h"
1818
#include "apdu_constants.h"
1919
#include "tlv_apdu.h"
20+
#include "chain_config.h"
2021

2122
/**
2223
* @brief TLV tags for network parameter structure
@@ -88,7 +89,6 @@ bool handle_param_network_struct(const buffer_t *buf, s_param_network_context *c
8889
*/
8990
static bool format_network_name(const s_parsed_value *value, char *buf, size_t buf_size) {
9091
uint64_t chain_id = 0;
91-
uint64_t max_range = 0x7FFFFFFFFFFFFFDB; // per EIP-2294
9292

9393
// Check length
9494
if (value->length != sizeof(uint64_t)) {
@@ -99,7 +99,7 @@ static bool format_network_name(const s_parsed_value *value, char *buf, size_t b
9999
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2294.md
100100
chain_id = u64_from_BE(value->ptr, value->length);
101101
// Check if the chain_id is supported
102-
if ((chain_id > max_range) || (chain_id == 0)) {
102+
if ((chain_id > MAX_VALID_CHAIN_ID) || (chain_id == 0)) {
103103
PRINTF("Unsupported chain ID: %llu\n", chain_id);
104104
return false;
105105
}

src/features/generic_tx_parser/gtp_param_raw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ bool format_uint(const s_field *field,
111111
}
112112

113113
bool format_int(const s_value *def, const s_parsed_value *value, char *buf, size_t buf_size) {
114-
uint8_t tmp[32];
114+
uint8_t tmp[INT256_LENGTH];
115115
bool ret;
116116
union {
117117
uint256_t value256;

src/features/generic_tx_parser/gtp_param_token_amount.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include "gtp_value.h"
88
#include "common_utils.h"
99

10-
#define MAX_NATIVE_ADDRS 4
10+
#define MAX_NATIVE_ADDRS 4
11+
#define ABOVE_THRESHOLD_MSG_SIZE 21
1112

1213
typedef struct {
1314
uint8_t version;
@@ -17,7 +18,7 @@ typedef struct {
1718
uint8_t native_addr_count;
1819
uint8_t native_addrs[MAX_NATIVE_ADDRS][ADDRESS_LENGTH];
1920
uint256_t threshold;
20-
char above_threshold_msg[21];
21+
char above_threshold_msg[ABOVE_THRESHOLD_MSG_SIZE];
2122
} s_param_token_amount;
2223

2324
typedef struct {

src/features/generic_tx_parser/gtp_param_trusted_name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "gtp_field_table.h"
77
#include "utils.h"
88
#include "shared_context.h"
9-
#include "getPublicKey.h"
9+
#include "get_public_key.h"
1010
#include "apdu_constants.h"
1111
#include "tx_ctx.h"
1212
#include "tlv_apdu.h"

src/features/generic_tx_parser/gtp_param_unit.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
#include "buffer.h"
66
#include "gtp_value.h"
77

8+
#define BASE_STR_SIZE 11
9+
810
typedef struct {
911
uint8_t version;
1012
s_value value;
11-
char base[11];
13+
char base[BASE_STR_SIZE];
1214
uint8_t decimals;
1315
} s_param_unit;
1416

0 commit comments

Comments
 (0)