Skip to content

Commit 2c574a0

Browse files
Merge pull request #673 from LedgerHQ/fix/apa/ethermint_eip712
Added hardcoded check to handle Ethermint's EIP-712 messages
2 parents 2c50cbc + cd6c45b commit 2c574a0

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src_features/signMessageEIP712/field_hash.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,37 @@ static bool field_hash_domain_special_fields(const void *const field_ptr,
174174
uint8_t data_length) {
175175
const char *key;
176176
uint8_t keylen;
177+
const char *ethermint_vc = "cosmos";
177178

178179
key = get_struct_field_keyname(field_ptr, &keylen);
179180
// copy contract address into context
180181
if (strncmp(key, "verifyingContract", keylen) == 0) {
181-
if (data_length != sizeof(eip712_context->contract_addr)) {
182-
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
183-
PRINTF("Unexpected verifyingContract length!\n");
184-
return false;
182+
switch (struct_field_type(field_ptr)) {
183+
case TYPE_SOL_ADDRESS:
184+
if (data_length > sizeof(eip712_context->contract_addr)) {
185+
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
186+
PRINTF("Error: verifyingContract too big\n");
187+
return false;
188+
}
189+
break;
190+
case TYPE_SOL_STRING:
191+
// hardcoded check for their non-standard implementation
192+
if ((data_length != strlen(ethermint_vc)) ||
193+
(strncmp((char *) data, ethermint_vc, data_length) != 0)) {
194+
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
195+
PRINTF("Error: non standard verifyingContract\n");
196+
return false;
197+
}
198+
break;
199+
default:
200+
apdu_response_code = APDU_RESPONSE_INVALID_DATA;
201+
PRINTF("Error: unexpected type for verifyingContract (%u)!\n",
202+
struct_field_type(field_ptr));
203+
return false;
185204
}
186205
memcpy(eip712_context->contract_addr, data, data_length);
206+
explicit_bzero(&eip712_context->contract_addr[data_length],
207+
sizeof(eip712_context->contract_addr) - data_length);
187208
} else if (strncmp(key, "chainId", keylen) == 0) {
188209
eip712_context->chain_id = u64_from_BE(data, data_length);
189210
}

0 commit comments

Comments
 (0)