Skip to content

Commit

Permalink
Added hardcoded check to handle Ethermint's EIP-712 messages
Browse files Browse the repository at this point in the history
  • Loading branch information
apaillier-ledger committed Nov 25, 2024
1 parent 2c50cbc commit cd6c45b
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src_features/signMessageEIP712/field_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,37 @@ static bool field_hash_domain_special_fields(const void *const field_ptr,
uint8_t data_length) {
const char *key;
uint8_t keylen;
const char *ethermint_vc = "cosmos";

key = get_struct_field_keyname(field_ptr, &keylen);
// copy contract address into context
if (strncmp(key, "verifyingContract", keylen) == 0) {
if (data_length != sizeof(eip712_context->contract_addr)) {
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
PRINTF("Unexpected verifyingContract length!\n");
return false;
switch (struct_field_type(field_ptr)) {
case TYPE_SOL_ADDRESS:
if (data_length > sizeof(eip712_context->contract_addr)) {
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
PRINTF("Error: verifyingContract too big\n");
return false;
}
break;
case TYPE_SOL_STRING:
// hardcoded check for their non-standard implementation
if ((data_length != strlen(ethermint_vc)) ||
(strncmp((char *) data, ethermint_vc, data_length) != 0)) {
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
PRINTF("Error: non standard verifyingContract\n");
return false;
}
break;
default:
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
PRINTF("Error: unexpected type for verifyingContract (%u)!\n",
struct_field_type(field_ptr));
return false;
}
memcpy(eip712_context->contract_addr, data, data_length);
explicit_bzero(&eip712_context->contract_addr[data_length],
sizeof(eip712_context->contract_addr) - data_length);
} else if (strncmp(key, "chainId", keylen) == 0) {
eip712_context->chain_id = u64_from_BE(data, data_length);
}
Expand Down

0 comments on commit cd6c45b

Please sign in to comment.