Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hardcoded check to handle Ethermint's EIP-712 messages #673

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading