Skip to content

Commit

Permalink
Merge pull request #350 from keepkey/fix-mayachain-denom
Browse files Browse the repository at this point in the history
fix: support arbitrary mayachain denominations
  • Loading branch information
pastaghost authored Mar 5, 2024
2 parents 39db694 + 1297662 commit 33b3ae5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.7.2)

project(
KeepKeyFirmware
VERSION 7.9.1
VERSION 7.9.2
LANGUAGES C CXX ASM)

set(BOOTLOADER_MAJOR_VERSION 2)
Expand Down
2 changes: 1 addition & 1 deletion deps/device-protocol
2 changes: 1 addition & 1 deletion include/keepkey/firmware/mayachain.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef struct _MayachainSignTx MayachainSignTx;
typedef struct _MayachainMsgDeposit MayachainMsgDeposit;

bool mayachain_signTxInit(const HDNode *_node, const MayachainSignTx *_msg);
bool mayachain_signTxUpdateMsgSend(const uint64_t amount, const char *to_address);
bool mayachain_signTxUpdateMsgSend(const uint64_t amount, const char *to_address, const char *denom);
bool mayachain_signTxUpdateMsgDeposit(const MayachainMsgDeposit *depmsg);
bool mayachain_signTxFinalize(uint8_t *public_key, uint8_t *signature);
bool mayachain_signingIsInited(void);
Expand Down
1 change: 1 addition & 0 deletions include/keepkey/transport/messages-mayachain.options
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ MayachainSignTx.memo max_size:256

MayachainMsgSend.from_address max_size:46
MayachainMsgSend.to_address max_size:46
MayachainMsgSend.denom max_size:69

MayachainMsgDeposit.asset max_size:20
MayachainMsgDeposit.memo max_size:256
Expand Down
13 changes: 8 additions & 5 deletions lib/firmware/fsm_msg_mayachain.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void fsm_msgMayachainMsgAck(const MayachainMsgAck *msg) {
// Confirm transaction basics
// supports only 1 message ack
CHECK_PARAM(mayachain_signingIsInited(), "Signing not in progress");
if (msg->has_send && msg->send.has_to_address && msg->send.has_amount) {
if (msg->has_send && msg->send.has_to_address && msg->send.has_amount && msg->send.has_denom) {
// pass
} else if (msg->has_deposit && msg->deposit.has_asset &&
msg->deposit.has_amount && msg->deposit.has_memo &&
Expand All @@ -145,7 +145,9 @@ void fsm_msgMayachainMsgAck(const MayachainMsgAck *msg) {
case OutputAddressType_TRANSFER:
default: {
char amount_str[32];
bn_format_uint64(msg->send.amount, NULL, " cacao", 10, 0, false,
char denom_str[71];
sprintf(denom_str, " %s", msg->send.denom);
bn_format_uint64(msg->send.amount, NULL, denom_str, 10, 0, false,
amount_str, sizeof(amount_str));
if (!confirm_transaction_output(
ButtonRequestType_ButtonRequest_ConfirmOutput, amount_str,
Expand All @@ -160,7 +162,8 @@ void fsm_msgMayachainMsgAck(const MayachainMsgAck *msg) {
}
}
if (!mayachain_signTxUpdateMsgSend(msg->send.amount,
msg->send.to_address)) {
msg->send.to_address,
msg->send.denom)) {
mayachain_signAbort();
fsm_sendFailure(FailureType_Failure_SyntaxError,
"Failed to include send message in transaction");
Expand Down Expand Up @@ -240,8 +243,8 @@ void fsm_msgMayachainMsgAck(const MayachainMsgAck *msg) {
}

if (!confirm(ButtonRequestType_ButtonRequest_SignTx, node_str,
"Sign this CACAO transaction on %s? "
"Additional network fees apply.",
"Sign this %s transaction on %s? "
"Additional network fees apply.", msg->has_send ? msg->send.denom : "CACAO",
sign_tx->chain_id)) {
mayachain_signAbort();
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
Expand Down
7 changes: 4 additions & 3 deletions lib/firmware/mayachain.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ bool mayachain_signTxInit(const HDNode *_node, const MayachainSignTx *_msg) {
}

bool mayachain_signTxUpdateMsgSend(const uint64_t amount,
const char *to_address) {
const char *to_address,
const char *denom) {
char mainnetp[] = "maya";
char testnetp[] = "smaya";
char *pfix;
Expand Down Expand Up @@ -124,10 +125,10 @@ bool mayachain_signTxUpdateMsgSend(const uint64_t amount,
const char *const prelude = "{\"type\":\"mayachain/MsgSend\",\"value\":{";
sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude));

// 21 + ^20 + 19 = ^60
// 21 + ^20 + 11 + ^69 + 3 = ^124
success &= tendermint_snprintf(
&ctx, buffer, sizeof(buffer),
"\"amount\":[{\"amount\":\"%" PRIu64 "\",\"denom\":\"cacao\"}]", amount);
"\"amount\":[{\"amount\":\"%" PRIu64 "\",\"denom\":\"%s\"}]", amount, denom);

// 17 + 45 + 1 = 63
success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer),
Expand Down

0 comments on commit 33b3ae5

Please sign in to comment.