Now supports EIP-712 filtering with missing chain id & contract address
This commit is contained in:
@@ -52,6 +52,10 @@ bool eip712_context_init(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Since they are optional, they might not be provided by the JSON data
|
||||
explicit_bzero(eip712_context->contract_addr, sizeof(eip712_context->contract_addr));
|
||||
eip712_context->chain_id = 0;
|
||||
|
||||
struct_state = NOT_INITIALIZED;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
typedef struct {
|
||||
uint8_t contract_addr[ADDRESS_LENGTH];
|
||||
uint64_t chain_id;
|
||||
uint8_t schema_hash[224 / 8];
|
||||
} s_eip712_context;
|
||||
|
||||
|
||||
@@ -181,15 +181,14 @@ static bool field_hash_domain_special_fields(const void *const field_ptr,
|
||||
}
|
||||
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) {
|
||||
eip712_context->chain_id = u64_from_BE(data, data_length);
|
||||
if ((eip712_context->chain_id != 0) && (eip712_context->chain_id != chainConfig->chainId)) {
|
||||
apdu_response_code = APDU_RESPONSE_CONDITION_NOT_SATISFIED;
|
||||
PRINTF("EIP712Domain chain ID mismatch, expected 0x%.*h, got 0x%.*h !\n",
|
||||
sizeof(chainConfig->chainId),
|
||||
&chainConfig->chainId,
|
||||
sizeof(chainId),
|
||||
&chainId);
|
||||
sizeof(eip712_context->chain_id),
|
||||
&eip712_context->chain_id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ static bool verify_filtering_signature(uint8_t dname_length,
|
||||
cx_sha256_init(&hash_ctx);
|
||||
|
||||
// Chain ID
|
||||
chain_id = __builtin_bswap64(chainConfig->chainId);
|
||||
chain_id = __builtin_bswap64(eip712_context->chain_id);
|
||||
hash_nbytes((uint8_t *) &chain_id, sizeof(chain_id), (cx_hash_t *) &hash_ctx);
|
||||
|
||||
// Contract address
|
||||
|
||||
Reference in New Issue
Block a user