Now checks the EIP712Domain chain ID
#include "ui_logic.h"
#include "ethUtils.h" // KECCAK256_HASH_BYTESIZE
#include "context.h" // contract_addr
+#include "utils.h" // u64_from_BE
static s_field_hashing *fh = NULL;
@@ -160,9 +161,10 @@ bool field_hash(const uint8_t *data,
// deallocate it
mem_dealloc(len);
+ if (path_get_root_type() == ROOT_DOMAIN)
+ {
// copy contract address into context
- if ((path_get_root_type() == ROOT_DOMAIN)
- && (strncmp(key, "verifyingContract", keylen) == 0))
+ if (strncmp(key, "verifyingContract", keylen) == 0)
{
if (data_length != sizeof(eip712_context->contract_addr))
{
@@ -171,6 +173,21 @@ bool field_hash(const uint8_t *data,
}
memcpy(eip712_context->contract_addr, data, data_length);
}
+ else if (strncmp(key, "chainId", keylen) == 0)
+ {
+ uint64_t chainId = u64_from_BE(data, data_length);
+
+ if (chainId != chainConfig->chainId)
+ {
+ PRINTF("EIP712Domain chain ID mismatch, expected 0x%.*h, got 0x%.*h !\n",
+ sizeof(chainConfig->chainId),
+ &chainConfig->chainId,
+ sizeof(chainId),
+ &chainId);
+ return false;
+ }
+ }
+ }
path_advance();
fh->state = FHS_IDLE;
ui_712_finalize_field();
