Now copies the EIP712 contract address into memory so it can be used later

This commit is contained in:
Alexandre Paillier
2022-06-09 15:21:27 +02:00
parent f480d5091e
commit 7e63bd8435
2 changed files with 17 additions and 9 deletions

View File

@@ -4,12 +4,14 @@
#ifdef HAVE_EIP712_FULL_SUPPORT
#include <stdbool.h>
#include "ethUstream.h" // ADDRESS_LENGTH
typedef struct
{
uint8_t *typenames_array;
uint8_t *structs_array;
uint8_t *current_struct_fields_array;
uint8_t contract_addr[ADDRESS_LENGTH];
} s_eip712_context;
extern s_eip712_context *eip712_context;

View File

@@ -10,6 +10,7 @@
#include "shared_context.h"
#include "ui_logic.h"
#include "ethUtils.h" // KECCAK256_HASH_BYTESIZE
#include "context.h" // contract_addr
static s_field_hashing *fh = NULL;
@@ -39,14 +40,13 @@ bool field_hash(const uint8_t *data,
const void *field_ptr;
e_type field_type;
uint8_t *value = NULL;
const char *key;
uint8_t keylen;
#ifdef DEBUG
const char *type;
uint8_t typelen;
const char *key;
uint8_t keylen;
#endif
if (fh == NULL)
{
return false;
@@ -56,10 +56,7 @@ bool field_hash(const uint8_t *data,
{
return false;
}
#ifdef HAVE_EIP712_HALF_BLIND
uint8_t keylen;
const char *key = get_struct_field_keyname(field_ptr, &keylen);
#endif // HAVE_EIP712_HALF_BLIND
key = get_struct_field_keyname(field_ptr, &keylen);
field_type = struct_field_type(field_ptr);
if (fh->state == FHS_IDLE) // first packet for this frame
{
@@ -142,8 +139,6 @@ bool field_hash(const uint8_t *data,
#ifdef HAVE_EIP712_HALF_BLIND
if (path_get_root_type() == ROOT_DOMAIN)
{
uint8_t keylen;
const char *key = get_struct_field_keyname(field_ptr, &keylen);
if ((keylen == 4) && (strncmp(key, "name", keylen) == 0))
{
#endif // HAVE_EIP712_HALF_BLIND
@@ -185,6 +180,17 @@ bool field_hash(const uint8_t *data,
// deallocate it
mem_dealloc(len);
// copy contract address into context
if ((path_get_root_type() == ROOT_DOMAIN)
&& (strncmp(key, "verifyingContract", keylen) == 0))
{
if (data_length != sizeof(eip712_context->contract_addr))
{
PRINTF("Unexpected verifyingContract length!\n");
return false;
}
memcpy(eip712_context->contract_addr, data, data_length);
}
path_advance();
fh->state = FHS_IDLE;
#ifdef HAVE_EIP712_HALF_BLIND