Skip to content

Commit 5b2c852

Browse files
Merge pull request #996 from LedgerHQ/cev/optimizations_cleanup
Optimizations & Cleanup
2 parents de18010 + e7784ad commit 5b2c852

33 files changed

Lines changed: 149 additions & 254 deletions

File tree

makefile_conf/features.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX TARGET_APEX
4747
DEFINES += HAVE_TRANSACTION_CHECKS
4848
endif
4949

50-
# Gating signing - TODO: Reactivate this once the feature is fully available E2E
51-
DEFINES += HAVE_GATING_SUPPORT
5250

5351
EIP7702_TEST_WHITELIST ?= 0
5452
ifneq ($(EIP7702_TEST_WHITELIST),0)

src/apdu_constants.h

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,17 @@ uint16_t handle_get_public_key(uint8_t p1,
8383
uint8_t p2,
8484
const uint8_t *dataBuffer,
8585
uint8_t dataLength,
86-
unsigned int *flags,
8786
unsigned int *tx);
8887
uint16_t handle_provide_erc20_token_information(const uint8_t *workBuffer,
8988
uint8_t dataLength,
9089
unsigned int *tx);
9190
uint16_t handle_provide_nft_information(const uint8_t *dataBuffer,
9291
uint8_t dataLength,
9392
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);
93+
uint16_t handle_sign(uint8_t p1, uint8_t p2, const uint8_t *dataBuffer, uint8_t dataLength);
9994
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);
95+
uint16_t handle_sign_personal_message(uint8_t p1, const uint8_t *const payload, uint8_t length);
96+
uint16_t handle_sign_eip712_message_v0(uint8_t p1, const uint8_t *dataBuffer, uint8_t dataLength);
10897

10998
uint16_t handle_set_external_plugin(const uint8_t *workBuffer, uint8_t dataLength);
11099

@@ -114,7 +103,6 @@ uint16_t handle_perform_privacy_operation(uint8_t p1,
114103
uint8_t p2,
115104
const uint8_t *workBuffer,
116105
uint8_t dataLength,
117-
unsigned int *flags,
118106
unsigned int *tx);
119107

120108
#ifdef HAVE_ETH2
@@ -123,15 +111,10 @@ uint16_t handle_get_eth2_public_key(uint8_t p1,
123111
uint8_t p2,
124112
const uint8_t *dataBuffer,
125113
uint8_t dataLength,
126-
unsigned int *flags,
127114
unsigned int *tx);
128115

129116
#endif
130117

131-
uint16_t handle_safe_account(uint8_t p1,
132-
uint8_t p2,
133-
const uint8_t *data,
134-
uint8_t length,
135-
uint32_t *flags);
118+
uint16_t handle_safe_account(uint8_t p1, uint8_t p2, const uint8_t *data, uint8_t length);
136119

137120
extern uint16_t apdu_response_code;

src/features/generic_tx_parser/gtp_param_datetime.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "shared_context.h"
77
#include "tlv_library.h"
88
#include "tlv_utils.h"
9+
#include "common_utils.h"
910

1011
#define PARAM_DATETIME_TAGS(X) \
1112
X(0x00, TAG_VERSION, handle_version, ENFORCE_UNIQUE_TAG) \
@@ -52,8 +53,6 @@ bool format_param_datetime(const s_param_datetime *param, const char *name) {
5253
size_t buf_size = sizeof(strings.tmp.tmp);
5354
uint8_t time_buf[sizeof(time_t)] = {0};
5455
time_t timestamp;
55-
uint256_t block_height;
56-
5756
if ((ret = value_get(&param->value, &collec))) {
5857
for (int i = 0; i < collec.size; ++i) {
5958
if (param->type == DT_UNIX) {
@@ -71,8 +70,10 @@ bool format_param_datetime(const s_param_datetime *param, const char *name) {
7170
}
7271
}
7372
} else if (param->type == DT_BLOCKHEIGHT) {
74-
convertUint256BE(collec.value[i].ptr, collec.value[i].length, &block_height);
75-
if (!(ret = tostring256(&block_height, 10, buf, buf_size))) {
73+
if (!(ret = uint256_to_decimal(collec.value[i].ptr,
74+
collec.value[i].length,
75+
buf,
76+
buf_size))) {
7677
break;
7778
}
7879
}

src/features/generic_tx_parser/gtp_param_raw.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include <inttypes.h>
21
#include "os_print.h"
2+
#include "common_utils.h"
33
#include "gtp_param_raw.h"
44
#include "gtp_field.h"
55
#include "uint256.h"
@@ -107,7 +107,7 @@ bool format_uint(const s_field *field,
107107
return false;
108108
}
109109

110-
return *to_be_displayed ? tostring256(&value256, 10, buf, buf_size) : true;
110+
return *to_be_displayed ? uint256_to_decimal(value->ptr, value->length, buf, buf_size) : true;
111111
}
112112

113113
bool format_int(const s_value *def, const s_parsed_value *value, char *buf, size_t buf_size) {
@@ -134,19 +134,19 @@ bool format_int(const s_value *def, const s_parsed_value *value, char *buf, size
134134
break;
135135
case 64:
136136
uv.value64 = read_u64_be(tmp, 0);
137-
ret = snprintf(buf, buf_size, "%" PRId64, uv.value64) > 0;
137+
ret = format_i64(buf, buf_size, uv.value64);
138138
break;
139139
case 32:
140140
uv.value32 = read_u32_be(tmp, 0);
141-
ret = snprintf(buf, buf_size, "%" PRId32, uv.value32) > 0;
141+
ret = format_i64(buf, buf_size, (int64_t) uv.value32);
142142
break;
143143
case 16:
144144
uv.value16 = read_u16_be(tmp, 0);
145-
ret = snprintf(buf, buf_size, "%u" PRId16, uv.value16) > 0;
145+
ret = format_i64(buf, buf_size, (int64_t) uv.value16);
146146
break;
147147
case 8:
148148
uv.value8 = value->ptr[0];
149-
ret = snprintf(buf, buf_size, "%u" PRId8, uv.value8) > 0;
149+
ret = format_i64(buf, buf_size, (int64_t) uv.value8);
150150
break;
151151
default:
152152
ret = false;

src/features/get_eth2_public_key/cmd_get_eth2_public_key.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ uint16_t handle_get_eth2_public_key(uint8_t p1,
6363
uint8_t p2,
6464
const uint8_t *dataBuffer,
6565
uint8_t dataLength,
66-
unsigned int *flags,
6766
unsigned int *tx) {
6867
bip32_path_t bip32;
6968
cx_err_t error = CX_INTERNAL_ERROR;
@@ -91,7 +90,6 @@ uint16_t handle_get_eth2_public_key(uint8_t p1,
9190
return SWO_SUCCESS;
9291
}
9392
ui_display_public_eth2();
94-
*flags |= IO_ASYNCH_REPLY;
9593
// Return code will be sent after UI approve/cancel
9694
error = 0;
9795
end:

src/features/get_public_key/cmd_get_public_key.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ uint16_t handle_get_public_key(uint8_t p1,
1010
uint8_t p2,
1111
const uint8_t *dataBuffer,
1212
uint8_t dataLength,
13-
unsigned int *flags,
1413
unsigned int *tx) {
1514
bip32_path_t bip32;
1615
cx_err_t error = CX_INTERNAL_ERROR;
@@ -65,7 +64,6 @@ uint16_t handle_get_public_key(uint8_t p1,
6564
tmpCtx.publicKeyContext.address);
6665
// don't unnecessarily pass the current app's chain ID
6766
ui_display_public_key(g_chain_config->chain_id == chain_id ? NULL : &chain_id);
68-
*flags |= IO_ASYNCH_REPLY;
6967
// Return code will be sent after UI approve/cancel
7068
error = 0;
7169
end:

src/features/get_public_key/get_public_key.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ uint32_t set_result_get_publicKey() {
4848
G_io_tx_buffer[tx++] = CX_SECP256_PUB_KEY_SIZE;
4949
memmove(G_io_tx_buffer + tx, tmpCtx.publicKeyContext.publicKey.W, CX_SECP256_PUB_KEY_SIZE);
5050
tx += CX_SECP256_PUB_KEY_SIZE;
51-
G_io_tx_buffer[tx++] = 40;
52-
memmove(G_io_tx_buffer + tx, tmpCtx.publicKeyContext.address, 40);
53-
tx += 40;
51+
G_io_tx_buffer[tx++] = ADDRESS_LENGTH_HEX;
52+
memmove(G_io_tx_buffer + tx, tmpCtx.publicKeyContext.address, ADDRESS_LENGTH_HEX);
53+
tx += ADDRESS_LENGTH_HEX;
5454
if (tmpCtx.publicKeyContext.getChaincode) {
5555
memmove(G_io_tx_buffer + tx, tmpCtx.publicKeyContext.chainCode, INT256_LENGTH);
5656
tx += INT256_LENGTH;

src/features/perform_privacy_operation/cmd_perform_privacy_operation.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ uint16_t handle_perform_privacy_operation(uint8_t p1,
2727
uint8_t p2,
2828
const uint8_t *dataBuffer,
2929
uint8_t dataLength,
30-
unsigned int *flags,
3130
unsigned int *tx) {
3231
cx_ecfp_private_key_t privateKey;
3332
uint8_t privateKeyData[PRIVATE_KEY_LENGTH];
@@ -107,7 +106,6 @@ uint16_t handle_perform_privacy_operation(uint8_t p1,
107106
} else {
108107
ui_display_privacy_shared_secret();
109108
}
110-
*flags |= IO_ASYNCH_REPLY;
111109
// Return code will be sent after UI approve/cancel
112110
error = APDU_NO_RESPONSE;
113111
end:

src/features/provide_gating/cmd_get_gating.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*
1717
********************************************************************************/
1818

19-
#ifdef HAVE_GATING_SUPPORT
20-
2119
#include "cmd_get_gating.h"
2220
#include "app_mem_utils.h"
2321
#include "apdu_constants.h"
@@ -673,5 +671,3 @@ bool set_gating_warning(void) {
673671
set_gating_ui_screen();
674672
return true;
675673
}
676-
677-
#endif // HAVE_GATING_SUPPORT

src/features/provide_gating/cmd_get_gating.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@
1818

1919
#pragma once
2020

21-
#ifdef HAVE_GATING_SUPPORT
22-
2321
#include <stdint.h>
2422
#include <stdbool.h>
2523

2624
uint16_t handle_gating(uint8_t p1, uint8_t p2, const uint8_t *data, uint8_t length);
2725

2826
void clear_gating(void);
2927
bool set_gating_warning(void);
30-
31-
#endif // HAVE_GATING_SUPPORT

0 commit comments

Comments
 (0)