67
67
#include "evm_api.h"
68
68
#include "evm_priv.h"
69
69
#include "exchange_main.h"
70
+ #include "flash_api.h"
70
71
#include "ui_core_confirm.h"
71
72
#include "ui_screens.h"
73
+ #include "utils.h"
72
74
73
75
/*****************************************************************************
74
76
* EXTERN VARIABLES
@@ -166,6 +168,8 @@ bool evm_verify_clear_signing(const evm_txn_context_t *txn_context) {
166
168
char address [43 ] = "0x" ;
167
169
const uint8_t * to_address = NULL ;
168
170
const char * unit = g_evm_app -> lunit_name ;
171
+ char hex_str [30 ] = {'\0' };
172
+ char value [34 ] = {'\0' };
169
173
char fee [34 ] = "" ;
170
174
char display [40 ] = "" ;
171
175
@@ -179,6 +183,24 @@ bool evm_verify_clear_signing(const evm_txn_context_t *txn_context) {
179
183
return false;
180
184
}
181
185
186
+ // verify recipient amount
187
+ uint8_t zeros [32 ] = {0 };
188
+ if (memcmp (txn_context -> transaction_info .value ,
189
+ zeros ,
190
+ txn_context -> transaction_info .value_size [0 ]) != 0 ) {
191
+ uint8_t len = eth_get_value (txn_context , hex_str );
192
+ if (!convert_byte_array_to_decimal_string (
193
+ len , evm_get_decimal (txn_context ), hex_str , value , sizeof (value ))) {
194
+ evm_send_error (ERROR_COMMON_ERROR_UNKNOWN_ERROR_TAG , 1 );
195
+ return false;
196
+ }
197
+
198
+ snprintf (display , sizeof (display ), UI_TEXT_VERIFY_AMOUNT , value , unit );
199
+ if (!core_confirmation (display , evm_send_error )) {
200
+ return false;
201
+ }
202
+ }
203
+
182
204
// verify transaction fee
183
205
eth_get_fee_string (
184
206
& txn_context -> transaction_info , fee , sizeof (fee ), ETH_DECIMAL );
@@ -207,27 +229,71 @@ bool evm_verify_blind_signing(const evm_txn_context_t *txn_context) {
207
229
bool status = false;
208
230
const uint8_t * to_address = NULL ;
209
231
char address [43 ] = "0x" ;
210
- char path_str [64 ] = "" ;
211
232
char fee [34 ] = "" ;
212
233
char display [40 ] = "" ;
234
+ char amount_display [40 ] = "" ;
235
+ uint8_t zeros [32 ] = {0 };
236
+ bool verify_amount = false;
213
237
const char * unit = g_evm_app -> lunit_name ;
214
- const uint32_t * hd_path = txn_context -> init_info .derivation_path ;
215
- size_t depth = txn_context -> init_info .derivation_path_count ;
216
238
217
239
// TODO: decide on handling blind signing via wallet setting
218
240
to_address = txn_context -> transaction_info .to_address ;
219
241
ethereum_address_checksum (
220
242
to_address , & address [2 ], false, g_evm_app -> chain_id );
221
- hd_path_array_to_string ( hd_path , depth , false, path_str , sizeof ( path_str ));
243
+
222
244
eth_get_fee_string (
223
245
& txn_context -> transaction_info , fee , sizeof (fee ), ETH_DECIMAL );
224
246
snprintf (display , sizeof (display ), UI_TEXT_SEND_TXN_FEE , fee , unit );
225
- // show warning for unknown EVM function; take user consent
226
- if (!core_confirmation (UI_TEXT_BLIND_SIGNING_WARNING , evm_send_error ) ||
227
- !core_scroll_page (UI_TEXT_VERIFY_HD_PATH , path_str , evm_send_error ) ||
228
- !core_scroll_page (ui_text_verify_contract , address , evm_send_error ) ||
229
- !core_scroll_page (UI_TEXT_TXN_FEE , display , evm_send_error )) {
230
- return status ;
247
+
248
+ // verify recipient amount
249
+ if (memcmp (txn_context -> transaction_info .value ,
250
+ zeros ,
251
+ txn_context -> transaction_info .value_size [0 ]) != 0 ) {
252
+ verify_amount = true;
253
+ char hex_str [30 ] = {'\0' };
254
+ char value [34 ] = {'\0' };
255
+ uint8_t len = eth_get_value (txn_context , hex_str );
256
+ if (!convert_byte_array_to_decimal_string (
257
+ len , evm_get_decimal (txn_context ), hex_str , value , sizeof (value ))) {
258
+ evm_send_error (ERROR_COMMON_ERROR_UNKNOWN_ERROR_TAG , 1 );
259
+ return false;
260
+ }
261
+
262
+ snprintf (amount_display ,
263
+ sizeof (amount_display ),
264
+ UI_TEXT_VERIFY_AMOUNT ,
265
+ value ,
266
+ unit );
267
+ }
268
+
269
+ if (is_raw_calldata_enabled ()) {
270
+ uint64_t data_size = txn_context -> transaction_info .data_size ;
271
+ char data_str [2 + data_size * 2 + 1 ];
272
+ snprintf (data_str , sizeof (data_str ), "0x" );
273
+ byte_array_to_hex_string (txn_context -> transaction_info .data ,
274
+ data_size ,
275
+ data_str + 2 ,
276
+ sizeof (data_str ) - 2 );
277
+ if (!core_scroll_page (ui_text_verify_contract , address , evm_send_error ) ||
278
+ (verify_amount && !core_confirmation (amount_display , evm_send_error )) ||
279
+ !core_scroll_page (UI_TEXT_TXN_FEE , display , evm_send_error ) ||
280
+ !core_scroll_page (UI_TEXT_CALLDATA , data_str , evm_send_error )) {
281
+ return status ;
282
+ }
283
+ } else {
284
+ char path_str [64 ] = "" ;
285
+ const uint32_t * hd_path = txn_context -> init_info .derivation_path ;
286
+ size_t depth = txn_context -> init_info .derivation_path_count ;
287
+ hd_path_array_to_string (hd_path , depth , false, path_str , sizeof (path_str ));
288
+
289
+ // show warning for unknown EVM function; take user consent
290
+ if (!core_confirmation (UI_TEXT_BLIND_SIGNING_WARNING , evm_send_error ) ||
291
+ !core_scroll_page (UI_TEXT_VERIFY_HD_PATH , path_str , evm_send_error ) ||
292
+ !core_scroll_page (ui_text_verify_contract , address , evm_send_error ) ||
293
+ (verify_amount && !core_confirmation (amount_display , evm_send_error )) ||
294
+ !core_scroll_page (UI_TEXT_TXN_FEE , display , evm_send_error )) {
295
+ return status ;
296
+ }
231
297
}
232
298
233
299
return true;
0 commit comments