Proper cleanup after EIP712 message
This commit is contained in:
@@ -903,7 +903,6 @@ void coin_main(chain_config_t *coin_config) {
|
||||
}
|
||||
reset_app_context();
|
||||
tmpCtx.transactionContext.currentItemIndex = 0;
|
||||
init_eip712_context();
|
||||
|
||||
for (;;) {
|
||||
UX_INIT();
|
||||
|
||||
@@ -11,17 +11,18 @@
|
||||
uint8_t *typenames_array;
|
||||
uint8_t *structs_array;
|
||||
uint8_t *current_struct_fields_array;
|
||||
bool eip712_context_initialized = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a boolean indicating if the initialization was successful or not
|
||||
*/
|
||||
bool init_eip712_context(void)
|
||||
bool eip712_context_init(void)
|
||||
{
|
||||
// init global variables
|
||||
mem_init();
|
||||
|
||||
if (init_sol_typenames() == false)
|
||||
if (sol_typenames_init() == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -49,7 +50,17 @@ bool init_eip712_context(void)
|
||||
|
||||
// create len(types)
|
||||
*structs_array = 0;
|
||||
|
||||
eip712_context_initialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Make a deinit function
|
||||
void eip712_context_deinit(void)
|
||||
{
|
||||
path_deinit();
|
||||
field_hash_deinit();
|
||||
ui_712_deinit();
|
||||
mem_reset();
|
||||
eip712_context_initialized = false;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ extern uint8_t *typenames_array;
|
||||
extern uint8_t *structs_array;
|
||||
extern uint8_t *current_struct_fields_array;
|
||||
|
||||
bool init_eip712_context(void);
|
||||
bool eip712_context_init(void);
|
||||
void eip712_context_deinit(void);
|
||||
|
||||
extern bool eip712_context_initialized;
|
||||
|
||||
#endif // EIP712_CTX_H_
|
||||
|
||||
@@ -367,6 +367,13 @@ bool handle_eip712_struct_def(const uint8_t *const apdu_buf)
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
if (!eip712_context_initialized)
|
||||
{
|
||||
if (!eip712_context_init())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
switch (apdu_buf[OFFSET_P2])
|
||||
{
|
||||
case P2_NAME:
|
||||
@@ -391,7 +398,6 @@ bool handle_eip712_struct_def(const uint8_t *const apdu_buf)
|
||||
G_io_apdu_buffer[0] = 0x6A;
|
||||
G_io_apdu_buffer[1] = 0x80;
|
||||
}
|
||||
//*flags |= IO_ASYNCH_REPLY;
|
||||
// Send back the response, do not restart the event loop
|
||||
io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2);
|
||||
return ret;
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
|
||||
static s_field_hashing *fh = NULL;
|
||||
|
||||
bool field_hash_init(void)
|
||||
|
||||
bool field_hash_init(void)
|
||||
{
|
||||
if (fh == NULL)
|
||||
{
|
||||
@@ -23,6 +24,11 @@ bool field_hash_init(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
void field_hash_deinit(void)
|
||||
{
|
||||
fh = NULL;
|
||||
}
|
||||
|
||||
bool field_hash(const uint8_t *data,
|
||||
uint8_t data_length,
|
||||
bool partial)
|
||||
|
||||
@@ -19,6 +19,7 @@ typedef struct
|
||||
} s_field_hashing;
|
||||
|
||||
bool field_hash_init(void);
|
||||
void field_hash_deinit(void);
|
||||
bool field_hash(const uint8_t *data,
|
||||
uint8_t data_length,
|
||||
bool partial);
|
||||
|
||||
@@ -147,7 +147,6 @@ static bool path_depth_list_pop(void)
|
||||
memcpy(tmpCtx.messageSigningContext712.messageHash,
|
||||
shash,
|
||||
KECCAK256_HASH_BYTESIZE);
|
||||
mem_reset();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -573,3 +572,8 @@ bool path_init(void)
|
||||
}
|
||||
return path_struct != NULL;
|
||||
}
|
||||
|
||||
void path_deinit(void)
|
||||
{
|
||||
path_struct = NULL;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ bool path_set_root(const char *const struct_name, uint8_t length);
|
||||
const void *path_get_field(void);
|
||||
bool path_advance(void);
|
||||
bool path_init(void);
|
||||
void path_deinit(void);
|
||||
bool path_new_array_depth(uint8_t size);
|
||||
|
||||
#endif // PATH_H_
|
||||
|
||||
@@ -39,7 +39,7 @@ static bool find_enum_matches(const uint8_t (*enum_to_idx)[TYPES_COUNT - 1][IDX_
|
||||
return (enum_match != NULL);
|
||||
}
|
||||
|
||||
bool init_sol_typenames(void)
|
||||
bool sol_typenames_init(void)
|
||||
{
|
||||
const char *const typenames[] = {
|
||||
"int", // 0
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
bool init_sol_typenames(void);
|
||||
bool sol_typenames_init(void);
|
||||
|
||||
const char *get_struct_field_sol_typename(const uint8_t *ptr,
|
||||
uint8_t *const length);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "ui_flow_712.h"
|
||||
#include "ui_logic.h"
|
||||
#include "shared_context.h" // strings
|
||||
#include "common_712.h"
|
||||
|
||||
// clang-format off
|
||||
UX_STEP_NOCB(
|
||||
@@ -31,7 +30,7 @@ UX_STEP_INIT(
|
||||
UX_STEP_CB(
|
||||
ux_712_step_approve,
|
||||
pb,
|
||||
ui_712_approve_cb(NULL),
|
||||
ui_712_approve(NULL),
|
||||
{
|
||||
&C_icon_validate_14,
|
||||
"Approve",
|
||||
@@ -39,7 +38,7 @@ UX_STEP_CB(
|
||||
UX_STEP_CB(
|
||||
ux_712_step_reject,
|
||||
pb,
|
||||
ui_712_reject_cb(NULL),
|
||||
ui_712_reject(NULL),
|
||||
{
|
||||
&C_icon_crossmark,
|
||||
"Reject",
|
||||
|
||||
@@ -10,9 +10,14 @@
|
||||
#include "eip712.h" // get_struct_name
|
||||
#include "ethUtils.h" // getEthDisplayableAddress
|
||||
#include "utils.h" // uint256_to_decimal
|
||||
#include "common_712.h"
|
||||
#include "context.h" // eip712_context_deinit
|
||||
|
||||
|
||||
static t_ui_context *ui_ctx = NULL;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Called on the intermediate dummy screen between the dynamic step
|
||||
* && the approve/reject screen
|
||||
@@ -43,6 +48,8 @@ void ui_712_next_field(void)
|
||||
|
||||
/**
|
||||
* Used to notify of a new struct to review (domain or message)
|
||||
*
|
||||
* @param[in] struct_ptr pointer to the structure
|
||||
*/
|
||||
void ui_712_new_root_struct(const void *const struct_ptr)
|
||||
{
|
||||
@@ -165,3 +172,37 @@ bool ui_712_init(void)
|
||||
}
|
||||
return ui_ctx != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deinit function that simply unsets the struct pointer to NULL
|
||||
*/
|
||||
void ui_712_deinit(void)
|
||||
{
|
||||
ui_ctx = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Approve button handling, calls the common handler function then
|
||||
* deinitializes the EIP712 context altogether.
|
||||
* @param[in] e unused here, just needed to match the UI function signature
|
||||
* @return unused here, just needed to match the UI function signature
|
||||
*/
|
||||
unsigned int ui_712_approve(const bagl_element_t *e)
|
||||
{
|
||||
ui_712_approve_cb(e);
|
||||
eip712_context_deinit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reject button handling, calls the common handler function then
|
||||
* deinitializes the EIP712 context altogether.
|
||||
* @param[in] e unused here, just needed to match the UI function signature
|
||||
* @return unused here, just needed to match the UI function signature
|
||||
*/
|
||||
unsigned int ui_712_reject(const bagl_element_t *e)
|
||||
{
|
||||
ui_712_reject_cb(e);
|
||||
eip712_context_deinit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define UI_LOGIC_712_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ux.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -17,9 +18,12 @@ typedef struct
|
||||
} t_ui_context;
|
||||
|
||||
bool ui_712_init(void);
|
||||
void ui_712_deinit(void);
|
||||
void ui_712_next_field(void);
|
||||
void ui_712_new_root_struct(const void *const struct_ptr);
|
||||
void ui_712_new_field(const void *const field_ptr, const uint8_t *const data, uint8_t length);
|
||||
void ui_712_end_sign(void);
|
||||
unsigned int ui_712_approve(const bagl_element_t *e);
|
||||
unsigned int ui_712_reject(const bagl_element_t *e);
|
||||
|
||||
#endif // UI_LOGIC_712_H_
|
||||
|
||||
Reference in New Issue
Block a user