@@ -28,17 +28,6 @@ swap_globals_t G_swap_state;
28
28
// Save the BSS address where we will write the return value when finished
29
29
static uint8_t * G_swap_sign_return_value_address ;
30
30
31
- static const char * chain_ids [] = {COIN_DEFAULT_CHAINID , OSMOSIS_CHAINID , DYDX_CHAINID , MANTRA_CHAINID , XION_CHAINID };
32
-
33
- bool is_allowed_chainid (const char * chainId ) {
34
- for (uint32_t i = 0 ; i < array_length (chain_ids ); i ++ ) {
35
- if (strcmp (chainId , PIC (chain_ids [i ])) == 0 ) {
36
- return true;
37
- }
38
- }
39
- return false;
40
- }
41
-
42
31
bool copy_transaction_parameters (create_transaction_parameters_t * sign_transaction_params ) {
43
32
if (sign_transaction_params == NULL ) {
44
33
return false;
@@ -91,7 +80,6 @@ bool copy_transaction_parameters(create_transaction_parameters_t *sign_transacti
91
80
return true;
92
81
}
93
82
94
-
95
83
/*
96
84
* This function verifies that a received transaction follows the expected format
97
85
* based on the current application mode (expert or normal). The verification
@@ -138,11 +126,13 @@ parser_error_t parser_msg_send(parser_context_t *ctx_parsed_tx, uint8_t displayI
138
126
}
139
127
char tmpKey [20 ] = {0 };
140
128
char tmpValue [65 ] = {0 };
129
+ int8_t chain_index = 0 ;
141
130
142
131
// Check if app is in expert mode
143
132
CHECK_PARSER_ERR (parser_getItem (ctx_parsed_tx , displayIdx , tmpKey , sizeof (tmpKey ), tmpValue , sizeof (tmpValue ), pageIdx , & pageCount ))
144
133
if (strcmp (tmpKey , "Chain ID" ) == 0 ) {
145
- if (!is_allowed_chainid (tmpValue )) {
134
+ chain_index = find_chain_index_by_chain_id (tmpValue );
135
+ if (chain_index == -1 ) {
146
136
ZEMU_LOGF (200 , " Not supported Chain Id\n" );
147
137
return parser_swap_wrong_chain_id ;
148
138
}
@@ -153,14 +143,14 @@ parser_error_t parser_msg_send(parser_context_t *ctx_parsed_tx, uint8_t displayI
153
143
154
144
// Check source address is present
155
145
CHECK_PARSER_ERR (parser_getItem (ctx_parsed_tx , displayIdx , tmpKey , sizeof (tmpKey ), tmpValue , sizeof (tmpValue ), pageIdx , & pageCount ))
156
- if (strcmp (tmpKey , "Type" ) != 0 && strcmp (tmpValue , "Send" ) != 0 ) {
146
+ if (strcmp (tmpKey , "Type" ) != 0 || strcmp (tmpValue , "Send" ) != 0 ) {
157
147
return parser_swap_unexpected_field ;
158
148
}
159
149
160
150
// Check amount
161
151
displayIdx += 1 ;
162
152
char tmp_amount [100 ] = {0 };
163
- zxerr_t zxerr = format_amount (G_swap_state .amount , G_swap_state .amount_length , tmp_amount , sizeof (tmp_amount ));
153
+ zxerr_t zxerr = format_amount (G_swap_state .amount , G_swap_state .amount_length , tmp_amount , sizeof (tmp_amount ), chain_index );
164
154
if (zxerr != zxerr_ok ) {
165
155
return parser_swap_wrap_amount_computation_error ;
166
156
}
@@ -199,7 +189,7 @@ parser_error_t parser_msg_send(parser_context_t *ctx_parsed_tx, uint8_t displayI
199
189
}
200
190
201
191
//Check fees
202
- zxerr = format_amount (G_swap_state .fees , G_swap_state .fees_length , tmp_amount , sizeof (tmp_amount ));
192
+ zxerr = format_amount (G_swap_state .fees , G_swap_state .fees_length , tmp_amount , sizeof (tmp_amount ), chain_index );
203
193
if (zxerr != zxerr_ok ) {
204
194
return parser_swap_wrap_amount_computation_error ;
205
195
}
@@ -209,17 +199,33 @@ parser_error_t parser_msg_send(parser_context_t *ctx_parsed_tx, uint8_t displayI
209
199
return parser_swap_wrong_fee ;
210
200
}
211
201
212
- switch (has_memo ){
202
+ switch (has_memo ) {
213
203
case 0 :
214
- if ((app_mode_expert () && ctx_parsed_tx -> tx_obj -> tx_json .num_items != EXPERT_SEND_MODE_ITEMS - 1 ) || (!app_mode_expert () && ctx_parsed_tx -> tx_obj -> tx_json .num_items != NORMAL_SEND_MODE_ITEMS - 1 )) {
215
- return parser_swap_unexpected_number_of_items ;
204
+ // When there's no memo, expect one less item
205
+ if (chain_index != 0 || app_mode_expert ()) {
206
+ if (ctx_parsed_tx -> tx_obj -> tx_json .num_items != EXPERT_SEND_MODE_ITEMS - 1 ) {
207
+ return parser_swap_unexpected_number_of_items ;
208
+ }
209
+ } else {
210
+ if (ctx_parsed_tx -> tx_obj -> tx_json .num_items != NORMAL_SEND_MODE_ITEMS - 1 ) {
211
+ return parser_swap_unexpected_number_of_items ;
212
+ }
216
213
}
217
214
break ;
215
+
218
216
case 1 :
219
- if ((app_mode_expert () && ctx_parsed_tx -> tx_obj -> tx_json .num_items != EXPERT_SEND_MODE_ITEMS ) || (!app_mode_expert () && ctx_parsed_tx -> tx_obj -> tx_json .num_items != NORMAL_SEND_MODE_ITEMS )) {
220
- return parser_swap_unexpected_number_of_items ;
217
+ // When there is a memo, expect full number of items
218
+ if (chain_index != 0 || app_mode_expert ()) {
219
+ if (ctx_parsed_tx -> tx_obj -> tx_json .num_items != EXPERT_SEND_MODE_ITEMS ) {
220
+ return parser_swap_unexpected_number_of_items ;
221
+ }
222
+ } else {
223
+ if (ctx_parsed_tx -> tx_obj -> tx_json .num_items != NORMAL_SEND_MODE_ITEMS ) {
224
+ return parser_swap_unexpected_number_of_items ;
225
+ }
221
226
}
222
227
break ;
228
+
223
229
default :
224
230
break ;
225
231
}
@@ -271,11 +277,12 @@ parser_error_t parser_simple_transfer(parser_context_t *ctx_parsed_tx, uint8_t d
271
277
272
278
char tmpKey [20 ] = {0 };
273
279
char tmpValue [65 ] = {0 };
274
-
280
+ int8_t chain_index = 0 ;
275
281
// Check if app is in expert mode
276
282
CHECK_PARSER_ERR (parser_getItem (ctx_parsed_tx , displayIdx , tmpKey , sizeof (tmpKey ), tmpValue , sizeof (tmpValue ), pageIdx , & pageCount ))
277
283
if (strcmp (tmpKey , "Chain ID" ) == 0 ) {
278
- if (!is_allowed_chainid (tmpValue )) {
284
+ chain_index = find_chain_index_by_chain_id (tmpValue );
285
+ if (chain_index == -1 ) {
279
286
ZEMU_LOGF (200 , " Not supported Chain Id\n" );
280
287
return parser_swap_wrong_chain_id ;
281
288
}
@@ -292,7 +299,7 @@ parser_error_t parser_simple_transfer(parser_context_t *ctx_parsed_tx, uint8_t d
292
299
293
300
// Check source coins are equal to the amount and equal to destination coins
294
301
char tmp_amount [100 ] = {0 };
295
- zxerr_t zxerr = format_amount (G_swap_state .amount , G_swap_state .amount_length , tmp_amount , sizeof (tmp_amount ));
302
+ zxerr_t zxerr = format_amount (G_swap_state .amount , G_swap_state .amount_length , tmp_amount , sizeof (tmp_amount ), chain_index );
296
303
if (zxerr != zxerr_ok ) {
297
304
return parser_swap_wrap_amount_computation_error ;
298
305
}
@@ -340,7 +347,7 @@ parser_error_t parser_simple_transfer(parser_context_t *ctx_parsed_tx, uint8_t d
340
347
}
341
348
342
349
//Check fees
343
- zxerr = format_amount (G_swap_state .fees , G_swap_state .fees_length , tmp_amount , sizeof (tmp_amount ));
350
+ zxerr = format_amount (G_swap_state .fees , G_swap_state .fees_length , tmp_amount , sizeof (tmp_amount ), chain_index );
344
351
if (zxerr != zxerr_ok ) {
345
352
return parser_swap_wrap_amount_computation_error ;
346
353
}
@@ -350,17 +357,33 @@ parser_error_t parser_simple_transfer(parser_context_t *ctx_parsed_tx, uint8_t d
350
357
return parser_swap_wrong_fee ;
351
358
}
352
359
353
- switch (has_memo ){
360
+ switch (has_memo ) {
354
361
case 0 :
355
- if ((app_mode_expert () && ctx_parsed_tx -> tx_obj -> tx_json .num_items != EXPERT_MODE_ITEMS - 1 ) || (!app_mode_expert () && ctx_parsed_tx -> tx_obj -> tx_json .num_items != NORMAL_MODE_ITEMS - 1 )) {
356
- return parser_swap_unexpected_number_of_items ;
362
+ // When there's no memo, expect one less item
363
+ if (chain_index != 0 || app_mode_expert ()) {
364
+ if (ctx_parsed_tx -> tx_obj -> tx_json .num_items != EXPERT_SEND_MODE_ITEMS - 1 ) {
365
+ return parser_swap_unexpected_number_of_items ;
366
+ }
367
+ } else {
368
+ if (ctx_parsed_tx -> tx_obj -> tx_json .num_items != NORMAL_SEND_MODE_ITEMS - 1 ) {
369
+ return parser_swap_unexpected_number_of_items ;
370
+ }
357
371
}
358
372
break ;
373
+
359
374
case 1 :
360
- if ((app_mode_expert () && ctx_parsed_tx -> tx_obj -> tx_json .num_items != EXPERT_MODE_ITEMS ) || (!app_mode_expert () && ctx_parsed_tx -> tx_obj -> tx_json .num_items != NORMAL_MODE_ITEMS )) {
361
- return parser_swap_unexpected_number_of_items ;
375
+ // When there is a memo, expect full number of items
376
+ if (chain_index != 0 || app_mode_expert ()) {
377
+ if (ctx_parsed_tx -> tx_obj -> tx_json .num_items != EXPERT_SEND_MODE_ITEMS ) {
378
+ return parser_swap_unexpected_number_of_items ;
379
+ }
380
+ } else {
381
+ if (ctx_parsed_tx -> tx_obj -> tx_json .num_items != NORMAL_SEND_MODE_ITEMS ) {
382
+ return parser_swap_unexpected_number_of_items ;
383
+ }
362
384
}
363
385
break ;
386
+
364
387
default :
365
388
break ;
366
389
}
0 commit comments