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

Improved EIP-712 error handling #636

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,14 @@ void app_main(void) {
PRINTF("=> BAD LENGTH: %d\n", rx);
sw = APDU_RESPONSE_WRONG_DATA_LENGTH;
} else {
PRINTF("=> CLA=%02X | INS=%02X | P1=%02X | P2=%02X | Lc=%02X\n",
PRINTF("=> CLA=%02x, INS=%02x, P1=%02x, P2=%02x, LC=%02x, CDATA=%.*h\n",
cmd.cla,
cmd.ins,
cmd.p1,
cmd.p2,
cmd.lc);
cmd.lc,
cmd.lc,
cmd.data);

tx = 0;
flags = 0;
Expand Down
4 changes: 3 additions & 1 deletion src_features/signMessageEIP712/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ bool path_set_root(const char *const struct_name, uint8_t name_length) {
return false;
}

path_struct->root_struct = get_structn(struct_name, name_length);
if ((path_struct->root_struct = get_structn(struct_name, name_length)) == NULL) {
return false;
}

if (path_struct->root_struct == NULL) {
PRINTF("Struct name not found (");
Expand Down
15 changes: 13 additions & 2 deletions src_features/signMessageEIP712/type_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ static const void **get_struct_dependencies(uint8_t *const deps_count,
// get struct name
arg_structname = get_struct_field_typename(field_ptr, &arg_structname_length);
// from its name, get the pointer to its definition
arg_struct_ptr = get_structn(arg_structname, arg_structname_length);
if ((arg_struct_ptr = get_structn(arg_structname, arg_structname_length)) == NULL) {
PRINTF("Error: could not find EIP-712 dependency struct \"");
for (int i = 0; i < arg_structname_length; ++i) PRINTF("%c", arg_structname[i]);
PRINTF("\" during type_hash\n");
return NULL;
}

// check if it is not already present in the dependencies array
for (dep_idx = 0; dep_idx < *deps_count; ++dep_idx) {
Expand Down Expand Up @@ -167,12 +172,18 @@ static const void **get_struct_dependencies(uint8_t *const deps_count,
* @return whether the type_hash was successful or not
*/
bool type_hash(const char *const struct_name, const uint8_t struct_name_length, uint8_t *hash_buf) {
const void *const struct_ptr = get_structn(struct_name, struct_name_length);
const void *struct_ptr;
uint8_t deps_count = 0;
const void **deps;
void *mem_loc_bak = mem_alloc(0);
cx_err_t error = CX_INTERNAL_ERROR;

if ((struct_ptr = get_structn(struct_name, struct_name_length)) == NULL) {
PRINTF("Error: could not find EIP-712 struct \"");
for (int i = 0; i < struct_name_length; ++i) PRINTF("%c", struct_name[i]);
PRINTF("\" for type_hash\n");
return false;
}
CX_CHECK(cx_keccak_init_no_throw(&global_sha3, 256));
deps = get_struct_dependencies(&deps_count, NULL, struct_ptr);
if ((deps_count > 0) && (deps == NULL)) {
Expand Down
Loading