Skip to content

Commit

Permalink
Merge pull request #325 from keepkey/typed-data-mhash
Browse files Browse the repository at this point in the history
fixed a couple of confirm bugs for eip-712
  • Loading branch information
pastaghost authored Nov 11, 2022
2 parents d3047c4 + e3566ea commit be2cc4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/firmware/ethereum.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This file is part of the TREZOR project.
* This file is part of the KeepKey project.
*
* Copyright (C) 2022 markrypto <[email protected]>
* Copyright (C) 2016 Alex Beregszaszi <[email protected]>
Expand Down Expand Up @@ -1068,7 +1068,7 @@ void ethereum_typed_hash_sign(const EthereumSignTypedHash *msg,
uint8_t v = 0;
if (0 != eip712_sign(msg->domain_separator_hash.bytes, msg->message_hash.bytes,
msg->has_message_hash, node, &v, resp->signature.bytes)) {
fsm_sendFailure(FailureType_Failure_Other, _("EIP-712 typed hash signing failed"));
fsm_sendFailure(FailureType_Failure_Other, _("EIP-712 hash signing failed"));
return;
}

Expand Down
22 changes: 14 additions & 8 deletions lib/firmware/fsm_msg_ethereum.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,23 @@ void fsm_msgEthereumSignTypedHash(const EthereumSignTypedHash *msg) {

// No message hash when setting primaryType="EIP712Domain"
// https://ethereum-magicians.org/t/eip-712-standards-clarification-primarytype-as-domaintype/3286
if (msg->has_message_hash) {
char str[64+1];
int ctr;
char *addrTitleStr = "Verify Address";
confirm(ButtonRequestType_ButtonRequest_Other, addrTitleStr, "Confirm address: %s", resp->address);
char str[64+1];
int ctr;

confirm(ButtonRequestType_ButtonRequest_Other, "Verify Address", "Confirm address: %s", resp->address);

for (ctr=0; ctr<64/2; ctr++) {
snprintf(&str[2*ctr], 3, "%02x", msg->domain_separator_hash.bytes[ctr]);
}
confirm(ButtonRequestType_ButtonRequest_Other, "Typed Data domain", "Confirm hash digest: %s", str);

char *hashTitleStr = "EIP-712 domain hash";
if (msg->has_message_hash) {
for (ctr=0; ctr<64/2; ctr++) {
snprintf(&str[2*ctr], 3, "%02x", msg->domain_separator_hash.bytes[ctr]);
snprintf(&str[2*ctr], 3, "%02x", msg->message_hash.bytes[ctr]);
}
confirm(ButtonRequestType_ButtonRequest_Other, hashTitleStr, "Confirm hash digest: %s", str);
confirm(ButtonRequestType_ButtonRequest_Other, "Typed Data message", "Confirm hash digest: %s", str);
} else {
confirm(ButtonRequestType_ButtonRequest_Other, "Typed Data message", "Confirm: No message");
}

ethereum_typed_hash_sign(msg, node, resp);
Expand Down

0 comments on commit be2cc4a

Please sign in to comment.