From 201dc55eae586c994935f44169a0d14a6c2988b9 Mon Sep 17 00:00:00 2001 From: Pasta Ghost Date: Thu, 14 Oct 2021 21:56:13 -0600 Subject: [PATCH 01/23] Add initial Osmosis support --- deps/device-protocol | 2 +- include/keepkey/firmware/coins.def | 1 + include/keepkey/firmware/fsm.h | 4 + include/keepkey/firmware/osmosis.h | 26 ++ include/keepkey/transport/interface.h | 1 + .../transport/messages-osmosis.options | 23 ++ lib/firmware/CMakeLists.txt | 1 + lib/firmware/fsm.c | 3 + lib/firmware/fsm_msg_osmosis.h | 277 ++++++++++++++++++ lib/firmware/messagemap.def | 9 + lib/firmware/osmosis.c | 251 ++++++++++++++++ lib/transport/CMakeLists.txt | 9 + 12 files changed, 606 insertions(+), 1 deletion(-) create mode 100644 include/keepkey/firmware/osmosis.h create mode 100644 include/keepkey/transport/messages-osmosis.options create mode 100644 lib/firmware/fsm_msg_osmosis.h create mode 100644 lib/firmware/osmosis.c diff --git a/deps/device-protocol b/deps/device-protocol index b4bf792b6..1b37e52c2 160000 --- a/deps/device-protocol +++ b/deps/device-protocol @@ -1 +1 @@ -Subproject commit b4bf792b657fc03cfbd64854f2a73ad6c18dc4bf +Subproject commit 1b37e52c2c27a939ac82208823bb3dbf1b0c6b2e diff --git a/include/keepkey/firmware/coins.def b/include/keepkey/firmware/coins.def index 7d3b65687..ec34640d8 100644 --- a/include/keepkey/firmware/coins.def +++ b/include/keepkey/firmware/coins.def @@ -44,5 +44,6 @@ X(true, "THORChain", true, "RUNE", false, NA, false, NA, false, N X(true, "Terra", true, "LUNA", false, NA, false, NA, false, NA, false, {0}, true, 0x8000014a, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "terra", false, false, false, 0, false, 0, false, "" ) X(true, "Kava", true, "KAVA", false, NA, false, NA, false, NA, false, {0}, true, 0x800001cb, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "kava", false, false, false, 0, false, 0, false, "" ) X(true, "Secret", true, "SCRT", false, NA, false, NA, false, NA, false, {0}, true, 0x80000211, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "secret", false, false, false, 0, false, 0, false, "" ) +X(true, "Osmosis", true, "OSMO", false, NA, false, NA, false, NA, false, {0}, true, 0x80000076, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "osmo", false, false, false, 0, false, 0, false, "" ) #undef X #undef NO_CONTRACT diff --git a/include/keepkey/firmware/fsm.h b/include/keepkey/firmware/fsm.h index 8d6265f95..edf18f712 100644 --- a/include/keepkey/firmware/fsm.h +++ b/include/keepkey/firmware/fsm.h @@ -107,6 +107,10 @@ void fsm_msgThorchainGetAddress(const ThorchainGetAddress *msg); void fsm_msgThorchainSignTx(const ThorchainSignTx *msg); void fsm_msgThorchainMsgAck(const ThorchainMsgAck *msg); +void fsm_msgOsmosisGetAddress(const OsmosisGetAddress *msg); +void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg); +void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg); + #if DEBUG_LINK // void fsm_msgDebugLinkDecision(DebugLinkDecision *msg); void fsm_msgDebugLinkGetState(DebugLinkGetState *msg); diff --git a/include/keepkey/firmware/osmosis.h b/include/keepkey/firmware/osmosis.h new file mode 100644 index 000000000..bac96d26e --- /dev/null +++ b/include/keepkey/firmware/osmosis.h @@ -0,0 +1,26 @@ +#ifndef KEEPKEY_FIRMWARE_OSMOSIS_H +#define KEEPKEY_FIRMWARE_OSMOSIS_H + +#include "messages.pb.h" +#include "trezor/crypto/bip32.h" + +#include +#include + +typedef struct _OsmosisSignTx OsmosisSignTx; +typedef struct _OsmosisMsgDelegate OsmosisMsgDelegate; +typedef struct _OsmosisMsgUndelegate OsmosisMsgUndelegate; +typedef struct _OsmosisMsgClaim OsmosisMsgClaim; + +bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg); +bool osmosis_signTxUpdateMsgSend(const uint64_t amount, const char *to_address); +bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg); +bool osmosis_signTxUpdateMsgUndelegate(const OsmosisMsgUndelegate *undelegatemsg); +bool osmosis_signTxUpdateMsgClaim(const OsmosisMsgClaim *claimmsg); +bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature); +bool osmosis_signingIsInited(void); +bool osmosis_signingIsFinished(void); +void osmosis_signAbort(void); +const OsmosisSignTx *osmosis_getOsmosisSignTx(void); + +#endif diff --git a/include/keepkey/transport/interface.h b/include/keepkey/transport/interface.h index d995e85ee..fdcba553f 100644 --- a/include/keepkey/transport/interface.h +++ b/include/keepkey/transport/interface.h @@ -32,6 +32,7 @@ #include "messages-ripple.pb.h" #include "messages-tendermint.pb.h" #include "messages-thorchain.pb.h" +#include "messages-osmosis.pb.h" #include "types.pb.h" #include "trezor_transport.h" diff --git a/include/keepkey/transport/messages-osmosis.options b/include/keepkey/transport/messages-osmosis.options new file mode 100644 index 000000000..69d0246de --- /dev/null +++ b/include/keepkey/transport/messages-osmosis.options @@ -0,0 +1,23 @@ +OsmosisGetAddress.address_n max_count:10 + +OsmosisAddress.address max_size:46 + +OsmosisSignTx.address_n max_count:10 +OsmosisSignTx.chain_id max_size:32 +OsmosisSignTx.memo max_size:256 + +OsmosisMsgSend.from_address max_size:46 +OsmosisMsgSend.to_address max_size:46 + +OsmosisMsgDelegate.delegator_address max_size:46 +OsmosisMsgDelegate.validator_address max_size:53 + +OsmosisMsgUndelegate.delegator_address max_size:46 +OsmosisMsgUndelegate.validator_address max_size:53 + +OsmosisMsgClaim.delegator_address max_size:46 +OsmosisMsgClaim.validator_address max_size:53 + + +OsmosisSignedTx.public_key max_size:33 +OsmosisSignedTx.signature max_size:64 diff --git a/lib/firmware/CMakeLists.txt b/lib/firmware/CMakeLists.txt index 00581ab48..500905569 100644 --- a/lib/firmware/CMakeLists.txt +++ b/lib/firmware/CMakeLists.txt @@ -20,6 +20,7 @@ set(sources fsm.c home_sm.c nano.c + osmosis.c passphrase_sm.c pin_sm.c policy.c diff --git a/lib/firmware/fsm.c b/lib/firmware/fsm.c index 3eeb8b723..aede2f4ed 100644 --- a/lib/firmware/fsm.c +++ b/lib/firmware/fsm.c @@ -44,6 +44,7 @@ #include "keepkey/firmware/ethereum_tokens.h" #include "keepkey/firmware/fsm.h" #include "keepkey/firmware/home_sm.h" +#include "keepkey/firmware/osmosis.h" #include "keepkey/firmware/passphrase_sm.h" #include "keepkey/firmware/pin_sm.h" #include "keepkey/firmware/policy.h" @@ -78,6 +79,7 @@ #include "messages-nano.pb.h" #include "messages-ripple.pb.h" #include "messages-thorchain.pb.h" +#include "messages-osmosis.pb.h" #include @@ -277,3 +279,4 @@ void fsm_msgClearSession(ClearSession *msg) { #include "fsm_msg_ripple.h" #include "fsm_msg_tendermint.h" #include "fsm_msg_thorchain.h" +#include "fsm_msg_osmosis.h" diff --git a/lib/firmware/fsm_msg_osmosis.h b/lib/firmware/fsm_msg_osmosis.h new file mode 100644 index 000000000..aa32c5216 --- /dev/null +++ b/lib/firmware/fsm_msg_osmosis.h @@ -0,0 +1,277 @@ + +void fsm_msgOsmosisGetAddress(const OsmosisGetAddress *msg) { + RESP_INIT(OsmosisAddress); + + CHECK_INITIALIZED + + CHECK_PIN + + const CoinType *coin = fsm_getCoin(true, "Osmosis"); + if (!coin) { + return; + } + HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, + msg->address_n_count, NULL); + char mainnet[] = "osmo"; + char testnet[] = "tosmo"; + char *pfix; + + if (!node) { + return; + } + + hdnode_fill_public_key(node); + + pfix = mainnet; + if (msg->has_testnet && msg->testnet) { + pfix = testnet; + } + + if (!tendermint_getAddress(node, pfix, resp->address)) { + memzero(node, sizeof(*node)); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Can't encode address")); + layoutHome(); + return; + } + + if (msg->has_show_display && msg->show_display) { + char node_str[NODE_STRING_LENGTH]; + if (!bip32_node_to_string(node_str, sizeof(node_str), coin, msg->address_n, + msg->address_n_count, /*whole_account=*/false, + /*show_addridx=*/false) && + !bip32_path_to_string(node_str, sizeof(node_str), msg->address_n, + msg->address_n_count)) { + memset(node_str, 0, sizeof(node_str)); + memzero(node, sizeof(*node)); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Can't create Bip32 Path String")); + layoutHome(); + } + + bool mismatch = + tendermint_pathMismatched(coin, msg->address_n, msg->address_n_count); + if (mismatch) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "WARNING", + "Wrong address path for selected coin. Continue at your own " + "risk!")) { + memzero(node, sizeof(*node)); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + } + + if (!confirm_ethereum_address(node_str, resp->address)) { + memzero(node, sizeof(*node)); + fsm_sendFailure(FailureType_Failure_ActionCancelled, + "Show address cancelled"); + layoutHome(); + return; + } + } + + resp->has_address = true; + + memzero(node, sizeof(*node)); + msg_write(MessageType_MessageType_OsmosisAddress, resp); + layoutHome(); +} + +void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg) { + CHECK_INITIALIZED + CHECK_PIN + + if (!msg->has_account_number || !msg->has_chain_id || !msg->has_fee_amount || + !msg->has_gas || !msg->has_sequence) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Missing Fields On Message"); + layoutHome(); + return; + } + + HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, + msg->address_n_count, NULL); + if (!node) { + return; + } + + hdnode_fill_public_key(node); + + RESP_INIT(OsmosisMsgRequest); + + if (!osmosis_signTxInit(node, msg)) { + osmosis_signAbort(); + memzero(node, sizeof(*node)); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Failed to initialize transaction signing")); + layoutHome(); + return; + } + + memzero(node, sizeof(*node)); + msg_write(MessageType_MessageType_OsmosisMsgRequest, resp); + layoutHome(); +} + +void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { + // Confirm transaction basics + // supports only 1 message ack + CHECK_PARAM(osmosis_signingIsInited(), "Signing not in progress"); + if (msg->has_send && msg->send.has_to_address && msg->send.has_amount) { + // pass + } else if (msg->has_delegate && msg->delegate.has_delegator_address && + msg->delegate.has_validator_address && msg->delegate.has_amount) { + // pass + } else if (msg->has_undelegate && msg->undelegate.has_delegator_address && + msg->undelegate.has_validator_address && + msg->undelegate.has_amount) { + // pass + } else if (msg->has_claim && msg->claim.has_delegator_address && + msg->claim.has_validator_address && msg->claim.has_amount) { + // pass + } else { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Invalid Osmosis Message Type")); + layoutHome(); + return; + } + + const CoinType *coin = fsm_getCoin(true, "Osmosis"); + if (!coin) { + return; + } + + const OsmosisSignTx *sign_tx = osmosis_getOsmosisSignTx(); + + if (msg->has_send) { + switch (msg->send.address_type) { + case OutputAddressType_TRANSFER: + default: { + char amount_str[32]; + bn_format_uint64(msg->send.amount, NULL, " OSMO", 8, 0, false, + amount_str, sizeof(amount_str)); + if (!confirm_transaction_output( + ButtonRequestType_ButtonRequest_ConfirmOutput, amount_str, + msg->send.to_address)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + break; + } + } + if (!osmosis_signTxUpdateMsgSend(msg->send.amount, + msg->send.to_address)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include send message in transaction"); + layoutHome(); + return; + } + + } else if (msg->has_delegate) { + char amount_str[32]; + bn_format_uint64(msg->delegate.amount, NULL, " OSMO", 8, 0, false, + amount_str, sizeof(amount_str)); + + if(!confirm_with_custom_layout( + &layout_standard_notification, + ButtonRequestType_ButtonRequest_SignExchange, "Delegate", + "Delegate %s to %s?", amount_str, msg->delegate.validator_address)){ + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgDelegate(&(msg->delegate))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include delegate message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_undelegate) { + char amount_str[32]; + bn_format_uint64(msg->undelegate.amount, NULL, " OSMO", 8, 0, false, + amount_str, sizeof(amount_str)); + + if(!confirm_with_custom_layout( + &layout_standard_notification, + ButtonRequestType_ButtonRequest_SignExchange, "Undelegate", + "Undelegate %s from %s?", amount_str, msg->undelegate.validator_address)){ + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgUndelegate(&(msg->undelegate))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include undelegate message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_claim) { + char amount_str[32]; + bn_format_uint64(msg->claim.amount, NULL, " OSMO", 8, 0, false, amount_str, + sizeof(amount_str)); + if(!confirm_with_custom_layout( + &layout_standard_notification, + ButtonRequestType_ButtonRequest_SignExchange, "Claim", + "Claim %s from %s?", amount_str, msg->claim.validator_address)){ + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgClaim(&(msg->claim))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include claim message in transaction"); + layoutHome(); + return; + } + } + + if (!osmosis_signingIsFinished()) { + RESP_INIT(OsmosisMsgRequest); + msg_write(MessageType_MessageType_OsmosisMsgRequest, resp); + return; + } + + char node_str[NODE_STRING_LENGTH]; + if (!bip32_node_to_string(node_str, sizeof(node_str), coin, + sign_tx->address_n, sign_tx->address_n_count, + /*whole_account=*/false, + /*show_addridx=*/false) && + !bip32_path_to_string(node_str, sizeof(node_str), sign_tx->address_n, + sign_tx->address_n_count)) { + memset(node_str, 0, sizeof(node_str)); + } + + RESP_INIT(OsmosisSignedTx); + + if (!osmosis_signTxFinalize(resp->public_key.bytes, resp->signature.bytes)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to finalize signature"); + layoutHome(); + return; + } + + resp->public_key.size = 33; + resp->has_public_key = true; + resp->signature.size = 64; + resp->has_signature = true; + osmosis_signAbort(); + layoutHome(); + msg_write(MessageType_MessageType_OsmosisSignedTx, resp); +} \ No newline at end of file diff --git a/lib/firmware/messagemap.def b/lib/firmware/messagemap.def index efab425b9..3632f12fe 100644 --- a/lib/firmware/messagemap.def +++ b/lib/firmware/messagemap.def @@ -60,6 +60,11 @@ MSG_IN(MessageType_MessageType_ThorchainSignTx, ThorchainSignTx, fsm_msgThorchainSignTx) MSG_IN(MessageType_MessageType_ThorchainMsgAck, ThorchainMsgAck, fsm_msgThorchainMsgAck) + MSG_IN(MessageType_MessageType_OsmosisGetAddress, OsmosisGetAddress, fsm_msgOsmosisGetAddress) + MSG_IN(MessageType_MessageType_OsmosisSignTx, OsmosisSignTx, fsm_msgOsmosisSignTx) + MSG_IN(MessageType_MessageType_OsmosisMsgAck, OsmosisMsgAck, fsm_msgOsmosisMsgAck) + + /* Normal Out Messages */ MSG_OUT(MessageType_MessageType_Success, Success, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_Failure, Failure, NO_PROCESS_FUNC) @@ -108,6 +113,10 @@ MSG_OUT(MessageType_MessageType_ThorchainMsgRequest, ThorchainMsgRequest, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_ThorchainSignedTx, ThorchainSignedTx, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_OsmosisAddress, OsmosisAddress, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_OsmosisMsgRequest, OsmosisMsgRequest, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_OsmosisSignedTx, OsmosisSignedTx, NO_PROCESS_FUNC) + #if DEBUG_LINK /* Debug Messages */ DEBUG_IN(MessageType_MessageType_DebugLinkDecision, DebugLinkDecision, NO_PROCESS_FUNC) diff --git a/lib/firmware/osmosis.c b/lib/firmware/osmosis.c new file mode 100644 index 000000000..1379696d9 --- /dev/null +++ b/lib/firmware/osmosis.c @@ -0,0 +1,251 @@ +/* + * This file is part of the Keepkey project. + * + * Copyright (C) 2021 Shapeshift + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +#include "keepkey/firmware/osmosis.h" +#include "keepkey/board/confirm_sm.h" +#include "keepkey/board/util.h" +#include "keepkey/firmware/home_sm.h" +#include "keepkey/firmware/storage.h" +#include "keepkey/firmware/tendermint.h" +#include "trezor/crypto/secp256k1.h" +#include "trezor/crypto/ecdsa.h" +#include "trezor/crypto/memzero.h" +#include "trezor/crypto/segwit_addr.h" + +#include +#include + +static CONFIDENTIAL HDNode node; +static SHA256_CTX ctx; +static bool initialized; +static uint32_t msgs_remaining; +static OsmosisSignTx msg; +static bool testnet; + +const OsmosisSignTx *osmosis_getOsmosisSignTx(void) { return &msg; } + +bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg) { + initialized = true; + msgs_remaining = _msg->msg_count; + testnet = false; + + if (_msg->has_testnet) { + testnet = _msg->testnet; + } + + memzero(&node, sizeof(node)); + memcpy(&node, _node, sizeof(node)); + memcpy(&msg, _msg, sizeof(msg)); + + bool success = true; + char buffer[64 + 1]; + + sha256_Init(&ctx); + + // Each segment guaranteed to be less than or equal to 64 bytes + // 19 + ^20 + 1 = ^40 + if (!tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "{\"account_number\":\"%" PRIu64 "\"", + msg.account_number)) + return false; + + // + const char *const chainid_prefix = ",\"chain_id\":\""; + sha256_Update(&ctx, (uint8_t *)chainid_prefix, strlen(chainid_prefix)); + tendermint_sha256UpdateEscaped(&ctx, msg.chain_id, strlen(msg.chain_id)); + + // 30 + ^10 + 19 = ^59 + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\",\"fee\":{\"amount\":[{\"amount\":\"%" PRIu32 + "\",\"denom\":\"rune\"}]", + msg.fee_amount); + + // 8 + ^10 + 2 = ^20 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"gas\":\"%" PRIu32 "\"}", msg.gas); + + // + const char *const memo_prefix = ",\"memo\":\""; + sha256_Update(&ctx, (uint8_t *)memo_prefix, strlen(memo_prefix)); + if (msg.has_memo) { + tendermint_sha256UpdateEscaped(&ctx, msg.memo, strlen(msg.memo)); + } + + // 10 + sha256_Update(&ctx, (uint8_t *)"\",\"msgs\":[", 10); + + return success; +} + +bool osmosis_signTxUpdateMsgSend(const uint64_t amount, + const char *to_address) { + char mainnetp[] = "osmo"; + char testnetp[] = "tosmo"; + char *pfix; + char buffer[64 + 1]; + + size_t decoded_len; + char hrp[45]; + uint8_t decoded[38]; + if (!bech32_decode(hrp, decoded, &decoded_len, to_address)) { + return false; + } + + char from_address[46]; + + pfix = mainnetp; + if (testnet) { + pfix = testnetp; + } + + if (!tendermint_getAddress(&node, pfix, from_address)) { + return false; + } + + bool success = true; + + const char *const prelude = "{\"type\":\"cosmos-sdk/MsgSend\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + // 21 + ^20 + 19 = ^60 + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":[{\"amount\":\"%" PRIu64 "\",\"denom\":\"uosmo\"}]", amount); + + // 17 + 45 + 1 = 63 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"from_address\":\"%s\"", from_address); + + // 15 + 45 + 3 = 63 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"to_address\":\"%s\"}}", to_address); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"cosmos-sdk/MsgDelegate\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"delegator_address\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + delegatemsg->delegator_address); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + delegatemsg->validator_address); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"uosmo\",\"amount\":\"%" PRIu64 "\"}}}", + delegatemsg->amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgUndelegate( + const OsmosisMsgUndelegate *undelegatemsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"cosmos-sdk/MsgUndelegate\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"delegator_address\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + undelegatemsg->delegator_address); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + undelegatemsg->validator_address); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"uosmo\",\"amount\":\"%" PRIu64 "\"}}}", + undelegatemsg->amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgClaim(const OsmosisMsgClaim *claimmsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = "{\"type\":\"cosmos-sdk/MsgClaim\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"delegator_address\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + claimmsg->delegator_address); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + claimmsg->validator_address); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"uosmo\",\"amount\":\"%" PRIu64 "\"}}}", + claimmsg->amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature) { + char buffer[64 + 1]; + + // 16 + ^20 = ^36 + if (!tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "],\"sequence\":\"%" PRIu64 "\"}", msg.sequence)) + return false; + + hdnode_fill_public_key(&node); + memcpy(public_key, node.public_key, 33); + + uint8_t hash[SHA256_DIGEST_LENGTH]; + sha256_Final(&ctx, hash); + return ecdsa_sign_digest(&secp256k1, node.private_key, hash, signature, NULL, + NULL) == 0; +} + +bool osmosis_signingIsInited(void) { return initialized; } + +bool osmosis_signingIsFinished(void) { return msgs_remaining == 0; } + +void osmosis_signAbort(void) { + initialized = false; + msgs_remaining = 0; + memzero(&msg, sizeof(msg)); + memzero(&node, sizeof(node)); +} diff --git a/lib/transport/CMakeLists.txt b/lib/transport/CMakeLists.txt index 70575edcf..584ada103 100644 --- a/lib/transport/CMakeLists.txt +++ b/lib/transport/CMakeLists.txt @@ -13,6 +13,7 @@ set(protoc_pb_sources ${DEVICE_PROTOCOL}/messages-ripple.proto ${DEVICE_PROTOCOL}/messages-tendermint.proto ${DEVICE_PROTOCOL}/messages-thorchain.proto + ${DEVICE_PROTOCOL}/messages-osmosis.proto ${DEVICE_PROTOCOL}/messages.proto) set(protoc_pb_options @@ -25,6 +26,7 @@ set(protoc_pb_options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-ripple.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-tendermint.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-thorchain.options + ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-osmosis.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages.options) set(protoc_c_sources @@ -37,6 +39,7 @@ set(protoc_c_sources ${CMAKE_BINARY_DIR}/lib/transport/messages-ripple.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-tendermint.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-thorchain.pb.c + ${CMAKE_BINARY_DIR}/lib/transport/messages-osmosis.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages.pb.c) set(protoc_c_headers @@ -49,6 +52,7 @@ set(protoc_c_headers ${CMAKE_BINARY_DIR}/include/messages-ripple.pb.h ${CMAKE_BINARY_DIR}/include/messages-tendermint.pb.h ${CMAKE_BINARY_DIR}/include/messages-thorchain.pb.h + ${CMAKE_BINARY_DIR}/include/messages-osmosis.pb.h ${CMAKE_BINARY_DIR}/include/messages.pb.h) set(protoc_pb_sources_moved @@ -61,6 +65,7 @@ set(protoc_pb_sources_moved ${CMAKE_BINARY_DIR}/lib/transport/messages-ripple.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-tendermint.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-thorchain.proto + ${CMAKE_BINARY_DIR}/lib/transport/messages-osmosis.proto ${CMAKE_BINARY_DIR}/lib/transport/messages.proto) add_custom_command( @@ -118,6 +123,10 @@ add_custom_command( ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb "--nanopb_out=-f messages-thorchain.options:." messages-thorchain.proto + COMMAND + ${PROTOC_BINARY} -I. -I/usr/include + --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb + "--nanopb_out=-f messages-osmosis.options:." messages-osmosis.proto COMMAND ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb From 8b480e860922007d45f8ad400aa9e77f6cceac03 Mon Sep 17 00:00:00 2001 From: mcchadwick Date: Tue, 16 Nov 2021 00:43:32 -0700 Subject: [PATCH 02/23] WIP: Add Osmosis support --- deps/device-protocol | 2 +- include/keepkey/firmware/osmosis.h | 12 + .../transport/messages-osmosis.options | 24 ++ lib/firmware/fsm_msg_osmosis.h | 357 ++++++++++++++++-- lib/firmware/osmosis.c | 262 ++++++++++++- 5 files changed, 608 insertions(+), 49 deletions(-) diff --git a/deps/device-protocol b/deps/device-protocol index 1b37e52c2..a05a52633 160000 --- a/deps/device-protocol +++ b/deps/device-protocol @@ -1 +1 @@ -Subproject commit 1b37e52c2c27a939ac82208823bb3dbf1b0c6b2e +Subproject commit a05a52633c8c14150829196268ebc82bb265390a diff --git a/include/keepkey/firmware/osmosis.h b/include/keepkey/firmware/osmosis.h index bac96d26e..ebf9ff6cb 100644 --- a/include/keepkey/firmware/osmosis.h +++ b/include/keepkey/firmware/osmosis.h @@ -11,12 +11,24 @@ typedef struct _OsmosisSignTx OsmosisSignTx; typedef struct _OsmosisMsgDelegate OsmosisMsgDelegate; typedef struct _OsmosisMsgUndelegate OsmosisMsgUndelegate; typedef struct _OsmosisMsgClaim OsmosisMsgClaim; +typedef struct _OsmosisMsgLPAdd OsmosisMsgLPAdd; +typedef struct _OsmosisMsgLPRemove OsmosisMsgLPRemove; +typedef struct _OsmosisMsgFarmTokens OsmosisMsgFarmTokens; +typedef struct _OsmosisMsgIBCDeposit OsmosisMsgIBCDeposit; +typedef struct _OsmosisMsgIBCWithdrawal OsmosisMsgIBCWithdrawal; +typedef struct _OsmosisMsgSwap OsmosisMsgSwap; bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg); bool osmosis_signTxUpdateMsgSend(const uint64_t amount, const char *to_address); bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg); bool osmosis_signTxUpdateMsgUndelegate(const OsmosisMsgUndelegate *undelegatemsg); +bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg); +bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove *lpremovemsg); +bool osmosis_signTxUpdateMsgFarmTokens(const OsmosisMsgFarmTokens *msgfarmtokens); +bool osmosis_signTxUpdateMsgIBCDeposit(const OsmosisMsgIBCDeposit *ibcdepositmsg); +bool osmosis_signTxUpdateMsgIBCWithdrawal(const OsmosisMsgIBCWithdrawal *ibcwithdrawalmsg); bool osmosis_signTxUpdateMsgClaim(const OsmosisMsgClaim *claimmsg); +bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap *swapmsg); bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature); bool osmosis_signingIsInited(void); bool osmosis_signingIsFinished(void); diff --git a/include/keepkey/transport/messages-osmosis.options b/include/keepkey/transport/messages-osmosis.options index 69d0246de..b9a3e549f 100644 --- a/include/keepkey/transport/messages-osmosis.options +++ b/include/keepkey/transport/messages-osmosis.options @@ -18,6 +18,30 @@ OsmosisMsgUndelegate.validator_address max_size:53 OsmosisMsgClaim.delegator_address max_size:46 OsmosisMsgClaim.validator_address max_size:53 +OsmosisMsgLPAdd.sender max_size:46 +OsmosisMsgLPAdd.pool_id max_size:16 + +OsmosisMsgLPRemove.sender max_size:46 +OsmosisMsgLPRemove.pool_id max_size:16 + +OsmosisMsgFarmTokens.owner max_size:46 + +OsmosisMsgIBCDeposit.source_port max_size:16 +OsmosisMsgIBCDeposit.source_channel max_size:16 +OsmosisMsgIBCDeposit.sender max_size:46 +OsmosisMsgIBCDeposit.receiver max_size:46 + +OsmosisMsgIBCWithdrawal.source_port max_size:16 +OsmosisMsgIBCWithdrawal.source_channel max_size:16 +OsmosisMsgIBCWithdrawal.sender max_size:46 +OsmosisMsgIBCWithdrawal.receiver max_size:46 + +OsmosisMsgSwap.sender max_size:46 +OsmosisMsgSwap.pool_id max_size:16 +OsmosisMsgSwap.token_out_denom max_size:8 OsmosisSignedTx.public_key max_size:33 OsmosisSignedTx.signature max_size:64 + +OsmosisToken.denom max_size:72 + diff --git a/lib/firmware/fsm_msg_osmosis.h b/lib/firmware/fsm_msg_osmosis.h index aa32c5216..1b8d9514d 100644 --- a/lib/firmware/fsm_msg_osmosis.h +++ b/lib/firmware/fsm_msg_osmosis.h @@ -119,17 +119,47 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { // Confirm transaction basics // supports only 1 message ack CHECK_PARAM(osmosis_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_token && + msg->send.token.has_amount) { // pass } else if (msg->has_delegate && msg->delegate.has_delegator_address && - msg->delegate.has_validator_address && msg->delegate.has_amount) { + msg->delegate.has_validator_address && msg->delegate.has_token) { // pass } else if (msg->has_undelegate && msg->undelegate.has_delegator_address && msg->undelegate.has_validator_address && - msg->undelegate.has_amount) { + msg->undelegate.has_token) { // pass } else if (msg->has_claim && msg->claim.has_delegator_address && - msg->claim.has_validator_address && msg->claim.has_amount) { + msg->claim.has_validator_address && msg->claim.has_token) { + // pass + } else if (msg->has_lp_add && msg->lp_add.has_sender && + msg->lp_add.has_pool_id && msg->lp_add.has_share_out_amount && + msg->lp_add.has_token_in_max_a && msg->lp_add.has_token_in_max_b) { + // pass + } else if (msg->has_lp_remove && msg->lp_remove.has_sender && + msg->lp_remove.has_pool_id && + msg->lp_remove.has_share_out_amount && + msg->lp_remove.has_token_out_min_a && + msg->lp_remove.has_token_out_min_b) { + // pass + } else if (msg->has_farm_tokens && msg->farm_tokens.has_owner && + msg->farm_tokens.has_duration && msg->farm_tokens.has_token) { + // pass + } else if (msg->has_ibc_deposit && msg->ibc_deposit.has_source_port && + msg->ibc_deposit.has_source_channel && + msg->ibc_deposit.has_token && msg->ibc_deposit.has_sender && + msg->ibc_deposit.has_receiver && + msg->ibc_deposit.has_timeout_height) { + // pass + } else if (msg->has_ibc_withdrawal && msg->ibc_withdrawal.has_source_port && + msg->ibc_withdrawal.has_source_channel && + msg->ibc_withdrawal.has_token && msg->ibc_withdrawal.has_sender && + msg->ibc_withdrawal.has_receiver && + msg->ibc_withdrawal.has_timeout_height) { + // pass + } else if (msg->has_swap && msg->swap.has_sender && msg->swap.has_pool_id && + msg->swap.has_token_out_denom && msg->swap.has_token_in && + msg->swap.has_token_out_min_amount) { // pass } else { osmosis_signAbort(); @@ -151,11 +181,10 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { case OutputAddressType_TRANSFER: default: { char amount_str[32]; - bn_format_uint64(msg->send.amount, NULL, " OSMO", 8, 0, false, + bn_format_uint64(msg->send.token.amount, NULL, " OSMO", 8, 0, false, amount_str, sizeof(amount_str)); - if (!confirm_transaction_output( - ButtonRequestType_ButtonRequest_ConfirmOutput, amount_str, - msg->send.to_address)) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Transfer", + "Send %s to %s?", amount_str, msg->send.to_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); @@ -165,8 +194,8 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { break; } } - if (!osmosis_signTxUpdateMsgSend(msg->send.amount, - msg->send.to_address)) { + if (!osmosis_signTxUpdateMsgSend(msg->send.token.amount, + msg->send.to_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include send message in transaction"); @@ -176,18 +205,17 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } else if (msg->has_delegate) { char amount_str[32]; - bn_format_uint64(msg->delegate.amount, NULL, " OSMO", 8, 0, false, + bn_format_uint64(msg->delegate.token.amount, NULL, " OSMO", 8, 0, false, amount_str, sizeof(amount_str)); - if(!confirm_with_custom_layout( - &layout_standard_notification, - ButtonRequestType_ButtonRequest_SignExchange, "Delegate", - "Delegate %s to %s?", amount_str, msg->delegate.validator_address)){ - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Delegate", + "Delegate %s to %s?", amount_str, + msg->delegate.validator_address)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } if (!osmosis_signTxUpdateMsgDelegate(&(msg->delegate))) { osmosis_signAbort(); @@ -198,18 +226,17 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } } else if (msg->has_undelegate) { char amount_str[32]; - bn_format_uint64(msg->undelegate.amount, NULL, " OSMO", 8, 0, false, + bn_format_uint64(msg->undelegate.token.amount, NULL, " OSMO", 8, 0, false, amount_str, sizeof(amount_str)); - if(!confirm_with_custom_layout( - &layout_standard_notification, - ButtonRequestType_ButtonRequest_SignExchange, "Undelegate", - "Undelegate %s from %s?", amount_str, msg->undelegate.validator_address)){ - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Undelegate", + "Undelegate %s from %s?", amount_str, + msg->undelegate.validator_address)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } if (!osmosis_signTxUpdateMsgUndelegate(&(msg->undelegate))) { osmosis_signAbort(); @@ -220,17 +247,16 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } } else if (msg->has_claim) { char amount_str[32]; - bn_format_uint64(msg->claim.amount, NULL, " OSMO", 8, 0, false, amount_str, - sizeof(amount_str)); - if(!confirm_with_custom_layout( - &layout_standard_notification, - ButtonRequestType_ButtonRequest_SignExchange, "Claim", - "Claim %s from %s?", amount_str, msg->claim.validator_address)){ - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } + bn_format_uint64(msg->claim.token.amount, NULL, " OSMO", 8, 0, false, + amount_str, sizeof(amount_str)); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim", + "Claim %s from %s?", amount_str, + msg->claim.validator_address)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } if (!osmosis_signTxUpdateMsgClaim(&(msg->claim))) { osmosis_signAbort(); @@ -239,6 +265,255 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { layoutHome(); return; } + } else if (msg->has_lp_add) { + char amount_a_str[32]; + char amount_b_str[32]; + const char *denom_a_str = + strcmp(msg->lp_add.token_in_max_a.denom, "uosmo") == 0 + ? "OSMO" + : msg->lp_add.token_in_max_a.denom; + const char *denom_b_str = + strcmp(msg->lp_add.token_in_max_b.denom, "uosmo") == 0 + ? "OSMO" + : msg->lp_add.token_in_max_b.denom; + + bn_format_uint64(msg->lp_add.token_in_max_a.amount, NULL, NULL, 8, 0, false, + amount_a_str, sizeof(amount_a_str)); + + bn_format_uint64(msg->lp_add.token_in_max_b.amount, NULL, NULL, 8, 0, false, + amount_b_str, sizeof(amount_b_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", + "Confirm Token A:\nAmount: %s\nDenom: %s", amount_a_str, + denom_a_str)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", + "Confirm Token B:\nAmount: %s\nDenom: %s", amount_b_str, + denom_b_str)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", + "Confirm Pool ID: %s", msg->lp_add.pool_id)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgLPAdd(&(msg->lp_add))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include LP Add message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_lp_remove) { + char amount_a_str[32]; + char amount_b_str[32]; + const char *denom_a_str = + strcmp(msg->lp_remove.token_out_min_a.denom, "uosmo") == 0 + ? "OSMO" + : msg->lp_remove.token_out_min_a.denom; + const char *denom_b_str = + strcmp(msg->lp_remove.token_out_min_b.denom, "uosmo") == 0 + ? "OSMO" + : msg->lp_remove.token_out_min_b.denom; + + bn_format_uint64(msg->lp_remove.token_out_min_a.amount, NULL, NULL, 8, 0, + false, amount_a_str, sizeof(amount_a_str)); + + bn_format_uint64(msg->lp_remove.token_out_min_b.amount, NULL, NULL, 8, 0, + false, amount_b_str, sizeof(amount_b_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", + "Confirm Token A:\nAmount: %s\nDenom: %s", amount_a_str, + denom_a_str)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", + "Confirm Token B:\nAmount: %s\nDenom: %s", amount_b_str, + denom_b_str)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", + "Confirm Pool ID: %s", msg->lp_remove.pool_id)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgLPRemove(&(msg->lp_remove))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include LP Remove message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_farm_tokens) { + char amount_str[32]; + bn_format_uint64(msg->farm_tokens.token.amount, NULL, " OSMO", 8, 0, false, + amount_str, sizeof(amount_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Farm Tokens", + "Lock %s in %s?", amount_str, msg->farm_tokens.token.denom)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Owner", "%s", + msg->farm_tokens.owner)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Duration", + "%lld", msg->farm_tokens.duration)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgFarmTokens(&(msg->farm_tokens))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include Farm Tokens message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_ibc_deposit) { + char amount_str[32]; + bn_format_uint64(msg->ibc_deposit.token.amount, NULL, " OSMO", 8, 0, false, + amount_str, sizeof(amount_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Deposit", + "Send %s on %s to %s?", amount_str, + msg->ibc_deposit.source_port, + msg->ibc_deposit.source_channel)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Sender Address", "%s", msg->ibc_deposit.sender)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Receiver Address", "%s", msg->ibc_deposit.receiver)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgIBCDeposit(&(msg->ibc_deposit))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include IBC Deposit message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_ibc_withdrawal) { + char amount_str[32]; + bn_format_uint64(msg->ibc_withdrawal.token.amount, NULL, " OSMO", 8, 0, + false, amount_str, sizeof(amount_str)); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Withdrawal", + "Receive %s on %s from %s?", amount_str, + msg->ibc_withdrawal.source_port, + msg->ibc_withdrawal.source_channel)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Sender Address", "%s", msg->ibc_withdrawal.sender)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Receiver Address", "%s", + msg->ibc_withdrawal.receiver)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgIBCWithdrawal(&(msg->ibc_withdrawal))) { + osmosis_signAbort(); + fsm_sendFailure( + FailureType_Failure_SyntaxError, + "Failed to include IBC Withdrawal message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_swap) { + char amount_in_str[32] = {' '}; + char amount_out_str[32] = {' '}; + bn_format_uint64(msg->swap.token_in.amount, NULL, msg->swap.token_in.denom, + 8, 0, false, amount_in_str + (1 * sizeof(char)), + sizeof(amount_in_str)); + bn_format_uint64( + msg->swap.token_out_min_amount, NULL, msg->swap.token_out_denom, 8, 0, + false, amount_out_str + (1 * sizeof(char)), sizeof(amount_out_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Swap", + "Swap %s for at least %lld?", amount_in_str, + msg->swap.token_out_min_amount)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Pool ID", "%s", + msg->swap.pool_id)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgSwap(&(msg->swap))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include Swap message in transaction"); + layoutHome(); + return; + } } if (!osmosis_signingIsFinished()) { diff --git a/lib/firmware/osmosis.c b/lib/firmware/osmosis.c index 1379696d9..e25ea0220 100644 --- a/lib/firmware/osmosis.c +++ b/lib/firmware/osmosis.c @@ -156,13 +156,16 @@ bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", delegatemsg->delegator_address); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"validator_address\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", delegatemsg->validator_address); success &= tendermint_snprintf( &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"uosmo\",\"amount\":\"%" PRIu64 "\"}}}", - delegatemsg->amount); + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}}}", + delegatemsg->token.denom, delegatemsg->token.amount); msgs_remaining--; return success; @@ -184,24 +187,236 @@ bool osmosis_signTxUpdateMsgUndelegate( success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", undelegatemsg->delegator_address); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"validator_address\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", undelegatemsg->validator_address); success &= tendermint_snprintf( &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"uosmo\",\"amount\":\"%" PRIu64 "\"}}}", - undelegatemsg->amount); + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}}}", + undelegatemsg->token.denom, undelegatemsg->token.amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"osmosis/gamm/join-pool\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + lpaddmsg->sender); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + lpaddmsg->pool_id); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"shareOutAmount\":"); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", + lpaddmsg->share_out_amount); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenInMaxs\":[{"); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"},", + lpaddmsg->token_in_max_a.denom, lpaddmsg->token_in_max_a.amount); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", + lpaddmsg->token_in_max_b.denom, lpaddmsg->token_in_max_b.amount); msgs_remaining--; return success; } +bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove *lpremovemsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"osmosis/gamm/exit-pool\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + lpremovemsg->sender); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + lpremovemsg->pool_id); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"shareOutAmount\":"); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", + lpremovemsg->share_out_amount); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenInMaxs\":[{"); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"},", + lpremovemsg->token_out_min_a.denom, lpremovemsg->token_out_min_a.amount); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", + lpremovemsg->token_out_min_b.denom, lpremovemsg->token_out_min_b.amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgFarmTokens( + const OsmosisMsgFarmTokens *msgfarmtokens) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"osmosis/lockup/lock-tokens\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"owner\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + msgfarmtokens->owner); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"duration\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"%" PRIu64 "\",", msgfarmtokens->duration); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"coins\":[{"); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", + msgfarmtokens->token.denom, msgfarmtokens->token.amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgIBCDeposit( + const OsmosisMsgIBCDeposit *ibcdepositmsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->sender); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_channel\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token\":{\"denom\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->token.denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", + ibcdepositmsg->token.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"timeout_height\":{\"revision_height\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", + ibcdepositmsg->timeout_height.revision_number); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}},", + ibcdepositmsg->timeout_height.revision_height); + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgIBCWithdrawal( + const OsmosisMsgIBCWithdrawal *ibcwithdrawalmsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcwithdrawalmsg->sender); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_channel\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcwithdrawalmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token\":{\"denom\":\"ibc/"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s", + &(ibcwithdrawalmsg->token.denom[3])); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\",\"amount\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", + ibcwithdrawalmsg->token.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcwithdrawalmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcwithdrawalmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"timeout_height\":{\"revision_height\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", + ibcwithdrawalmsg->timeout_height.revision_number); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}},", + ibcwithdrawalmsg->timeout_height.revision_height); + msgs_remaining--; + return success; +} + bool osmosis_signTxUpdateMsgClaim(const OsmosisMsgClaim *claimmsg) { char buffer[64 + 1]; bool success = true; - const char *const prelude = "{\"type\":\"cosmos-sdk/MsgClaim\",\"value\":{"; + const char *const prelude = + "{\"type\":\"cosmos-sdk/MsgWithdrawDelegatorReward\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), @@ -215,8 +430,41 @@ bool osmosis_signTxUpdateMsgClaim(const OsmosisMsgClaim *claimmsg) { success &= tendermint_snprintf( &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"uosmo\",\"amount\":\"%" PRIu64 "\"}}}", - claimmsg->amount); + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}}}", + claimmsg->token.denom, claimmsg->token.amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap *swapmsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"osmosis/gamm/swap-exact-amount-in\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + swapmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"routes\":[{"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"poolId\":%s\",", swapmsg->pool_id); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"tokenOutDenom\":%s\"}],", + swapmsg->token_out_denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenIn\":{"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"denom\":%s\",", swapmsg->token_in.denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":\"%" PRIu64 "\"},", + swapmsg->token_in.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"tokenOutMinAmount\":\"%" PRIu64 "\"}}", + swapmsg->token_out_min_amount); msgs_remaining--; return success; From 8691e3ab4eea061e2e87692cb1142464522c77f4 Mon Sep 17 00:00:00 2001 From: mcchadwick Date: Sun, 21 Nov 2021 22:52:51 -0800 Subject: [PATCH 03/23] WIP: Sort Osmosis message fields --- lib/firmware/osmosis.c | 214 ++++++++++++++++++++++++----------------- 1 file changed, 126 insertions(+), 88 deletions(-) diff --git a/lib/firmware/osmosis.c b/lib/firmware/osmosis.c index e25ea0220..d0974c5f2 100644 --- a/lib/firmware/osmosis.c +++ b/lib/firmware/osmosis.c @@ -58,6 +58,8 @@ bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg) { sha256_Init(&ctx); + //TODO: Check and see if account number and chain ID parameters are valid/necessary here. + // Each segment guaranteed to be less than or equal to 64 bytes // 19 + ^20 + 1 = ^40 if (!tendermint_snprintf(&ctx, buffer, sizeof(buffer), @@ -74,7 +76,7 @@ bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\",\"fee\":{\"amount\":[{\"amount\":\"%" PRIu32 - "\",\"denom\":\"rune\"}]", + "\",\"denom\":\"osmo\"}]", msg.fee_amount); // 8 + ^10 + 2 = ^20 @@ -150,6 +152,11 @@ bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg) { "{\"type\":\"cosmos-sdk/MsgDelegate\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"},", + delegatemsg->token.amount, delegatemsg->token.denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"delegator_address\":"); @@ -159,14 +166,9 @@ bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"validator_address\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\"}}", delegatemsg->validator_address); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}}}", - delegatemsg->token.denom, delegatemsg->token.amount); - msgs_remaining--; return success; } @@ -181,6 +183,11 @@ bool osmosis_signTxUpdateMsgUndelegate( "{\"type\":\"cosmos-sdk/MsgUndelegate\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"},", + undelegatemsg->token.amount, undelegatemsg->token.denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"delegator_address\":"); @@ -190,14 +197,9 @@ bool osmosis_signTxUpdateMsgUndelegate( success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"validator_address\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\"}}", undelegatemsg->validator_address); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}}}", - undelegatemsg->token.denom, undelegatemsg->token.amount); - msgs_remaining--; return success; } @@ -211,15 +213,15 @@ bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg) { "{\"type\":\"osmosis/gamm/join-pool\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - lpaddmsg->sender); + lpaddmsg->pool_id); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - lpaddmsg->pool_id); + lpaddmsg->sender); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"shareOutAmount\":"); @@ -231,15 +233,35 @@ bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenInMaxs\":[{"); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"},", - lpaddmsg->token_in_max_a.denom, lpaddmsg->token_in_max_a.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\""); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", - lpaddmsg->token_in_max_b.denom, lpaddmsg->token_in_max_b.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s", + lpaddmsg->token_in_max_a.amount); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\",\"denom\":\"%" PRIu64 "\"},", + lpaddmsg->token_in_max_a.denom); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\""); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s", + lpaddmsg->token_in_max_b.amount); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\",\"denom\":\"%" PRIu64 "\"},", + lpaddmsg->token_in_max_b.denom); + + // success &= tendermint_snprintf( + // &ctx, buffer, sizeof(buffer), + // "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"},", + // lpaddmsg->token_in_max_a.denom, lpaddmsg->token_in_max_a.amount); + + // success &= tendermint_snprintf( + // &ctx, buffer, sizeof(buffer), + // "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", + // lpaddmsg->token_in_max_b.denom, lpaddmsg->token_in_max_b.amount); msgs_remaining--; return success; @@ -254,15 +276,15 @@ bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove *lpremovemsg) { "{\"type\":\"osmosis/gamm/exit-pool\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - lpremovemsg->sender); + lpremovemsg->pool_id); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - lpremovemsg->pool_id); + lpremovemsg->sender); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"shareOutAmount\":"); @@ -276,13 +298,13 @@ bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove *lpremovemsg) { success &= tendermint_snprintf( &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"},", - lpremovemsg->token_out_min_a.denom, lpremovemsg->token_out_min_a.amount); + "\"amount\":{\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"},", + lpremovemsg->token_out_min_a.amount, lpremovemsg->token_out_min_a.denom); success &= tendermint_snprintf( &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", - lpremovemsg->token_out_min_b.denom, lpremovemsg->token_out_min_b.amount); + "\"amount\":{\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"}]}}", + lpremovemsg->token_out_min_b.amount, lpremovemsg->token_out_min_b.denom); msgs_remaining--; return success; @@ -298,22 +320,22 @@ bool osmosis_signTxUpdateMsgFarmTokens( "{\"type\":\"osmosis/lockup/lock-tokens\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"owner\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"coins\":[{"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - msgfarmtokens->owner); + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"}]}}", + msgfarmtokens->token.amount, msgfarmtokens->token.denom); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"duration\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", msgfarmtokens->duration); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"coins\":[{"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"owner\":"); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", - msgfarmtokens->token.denom, msgfarmtokens->token.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + msgfarmtokens->owner); msgs_remaining--; return success; @@ -329,37 +351,45 @@ bool osmosis_signTxUpdateMsgIBCDeposit( "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->receiver); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", ibcdepositmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_channel\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->sender); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"token\":{\"denom\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->token.denom); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":"); + ibcdepositmsg->source_channel); + success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", - ibcdepositmsg->token.amount); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->sender); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->sender); + ibcdepositmsg->source_port); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"timeout_height\":{\"revision_height\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", + ibcdepositmsg->timeout_height.revision_height); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"revision_number\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", ibcdepositmsg->timeout_height.revision_number); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token\":{\"amount\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->token.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":"); success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}},", - ibcdepositmsg->timeout_height.revision_height); + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}}", + ibcdepositmsg->token.denom); + msgs_remaining--; return success; } @@ -373,39 +403,45 @@ bool osmosis_signTxUpdateMsgIBCWithdrawal( const char *const prelude = "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->receiver); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcwithdrawalmsg->sender); + ibcdepositmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_channel\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcwithdrawalmsg->sender); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"token\":{\"denom\":\"ibc/"); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s", - &(ibcwithdrawalmsg->token.denom[3])); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\",\"amount\":"); + ibcdepositmsg->source_channel); + success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", - ibcwithdrawalmsg->token.amount); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcwithdrawalmsg->sender); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcwithdrawalmsg->sender); + ibcdepositmsg->source_port); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"timeout_height\":{\"revision_height\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", - ibcwithdrawalmsg->timeout_height.revision_number); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":"); + ibcdepositmsg->timeout_height.revision_height); + success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}},", - ibcwithdrawalmsg->timeout_height.revision_height); + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"revision_number\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", + ibcdepositmsg->timeout_height.revision_number); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token\":{\"amount\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->token.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}}", + ibcdepositmsg->token.denom); msgs_remaining--; return success; } @@ -446,22 +482,24 @@ bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap *swapmsg) { "{\"type\":\"osmosis/gamm/swap-exact-amount-in\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - swapmsg->sender); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"routes\":[{"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":%s\",", swapmsg->pool_id); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenOutDenom\":%s\"}],", swapmsg->token_out_denom); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + swapmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenIn\":{"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"denom\":%s\",", swapmsg->token_in.denom); + "\"amount\":%s\",", swapmsg->token_in.amount); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":\"%" PRIu64 "\"},", - swapmsg->token_in.amount); + "\"denom\":\"%" PRIu64 "\"},", + swapmsg->token_in.denom); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenOutMinAmount\":\"%" PRIu64 "\"}}", swapmsg->token_out_min_amount); From f6ae9359ac933a41c39dfac8ab343aeda41db1b6 Mon Sep 17 00:00:00 2001 From: pastaghost Date: Fri, 27 May 2022 14:03:50 -0600 Subject: [PATCH 04/23] wip - fsm/message map build errors --- deps/device-protocol | 2 +- include/keepkey/firmware/app_confirm.h | 1 + include/keepkey/firmware/app_layout.h | 30 +- include/keepkey/firmware/fsm.h | 8 +- include/keepkey/firmware/osmosis.h | 26 - include/keepkey/firmware/signtx_tendermint.h | 35 +- include/keepkey/transport/interface.h | 2 +- .../transport/messages-osmosis.options | 81 +- lib/firmware/app_confirm.c | 16 + lib/firmware/app_layout.c | 42 + lib/firmware/fsm.c | 4 +- lib/firmware/fsm_msg_osmosis.h | 744 ++++++++++++------ lib/firmware/messagemap.def | 17 +- lib/firmware/signtx_tendermint.c | 41 +- lib/transport/CMakeLists.txt | 18 +- 15 files changed, 718 insertions(+), 349 deletions(-) diff --git a/deps/device-protocol b/deps/device-protocol index 4d7774c2b..d9c2dd9fd 160000 --- a/deps/device-protocol +++ b/deps/device-protocol @@ -1 +1 @@ -Subproject commit 4d7774c2bb929f417bcae38b69d5b9fa73497d3f +Subproject commit d9c2dd9fd6996d22615f1d1f6c1adbe9870d541f diff --git a/include/keepkey/firmware/app_confirm.h b/include/keepkey/firmware/app_confirm.h index 6d15e6bf6..6c5d43e6f 100644 --- a/include/keepkey/firmware/app_confirm.h +++ b/include/keepkey/firmware/app_confirm.h @@ -48,6 +48,7 @@ bool confirm_address(const char *desc, const char *address); bool confirm_xpub(const char *node_str, const char *xpub); bool confirm_sign_identity(const IdentityType *identity, const char *challenge); bool confirm_cosmos_address(const char *desc, const char *address); +bool confirm_osmosis_address(const char *desc, const char *address); bool confirm_ethereum_address(const char *desc, const char *address); bool confirm_nano_address(const char *desc, const char *address); bool confirm_omni(ButtonRequestType button_request, const char *title, diff --git a/include/keepkey/firmware/app_layout.h b/include/keepkey/firmware/app_layout.h index 7ea9997c6..8c7eb17e7 100644 --- a/include/keepkey/firmware/app_layout.h +++ b/include/keepkey/firmware/app_layout.h @@ -39,19 +39,19 @@ #define NO_TITLE_WIDTH 250 /* PIN Matrix */ -#define MATRIX_MASK_COLOR 0x00 -#define MATRIX_MASK_MARGIN 3 -#define PIN_MATRIX_GRID_SIZE 18 -#define PIN_MATRIX_ANIMATION_FREQUENCY_MS 40 -#define PIN_MATRIX_BACKGROUND 0x11 -#define PIN_MATRIX_STEP1 0x11 -#define PIN_MATRIX_STEP2 0x33 -#define PIN_MATRIX_STEP3 0x77 -#define PIN_MATRIX_STEP4 0xBB -#define PIN_MATRIX_FOREGROUND 0xFF -#define PIN_SLIDE_DELAY 20 -#define PIN_MAX_ANIMATION_MS 1000 -#define PIN_LEFT_MARGIN 195 +#define MATRIX_MASK_COLOR 0x00 +#define MATRIX_MASK_MARGIN 3 +#define PIN_MATRIX_GRID_SIZE 18 +#define PIN_MATRIX_ANIMATION_FREQUENCY_MS 40 +#define PIN_MATRIX_BACKGROUND 0x11 +#define PIN_MATRIX_STEP1 0x11 +#define PIN_MATRIX_STEP2 0x33 +#define PIN_MATRIX_STEP3 0x77 +#define PIN_MATRIX_STEP4 0xBB +#define PIN_MATRIX_FOREGROUND 0xFF +#define PIN_SLIDE_DELAY 20 +#define PIN_MAX_ANIMATION_MS 1000 +#define PIN_LEFT_MARGIN 195 /* Recovery Cypher */ #define CIPHER_ROWS 2 @@ -111,7 +111,9 @@ void layout_xpub_notification(const char *desc, const char *xpub, void layout_address_notification(const char *desc, const char *address, NotificationType type); void layout_cosmos_address_notification(const char *desc, const char *address, - NotificationType type); + NotificationType type); +void layout_osmosis_address_notification(const char *desc, const char *address, + NotificationType type); void layout_ethereum_address_notification(const char *desc, const char *address, NotificationType type); void layout_nano_address_notification(const char *desc, const char *address, diff --git a/include/keepkey/firmware/fsm.h b/include/keepkey/firmware/fsm.h index edf18f712..aaf33d97d 100644 --- a/include/keepkey/firmware/fsm.h +++ b/include/keepkey/firmware/fsm.h @@ -103,14 +103,14 @@ void fsm_msgCosmosGetAddress(const CosmosGetAddress *msg); void fsm_msgCosmosSignTx(const CosmosSignTx *msg); void fsm_msgCosmosMsgAck(const CosmosMsgAck *msg); -void fsm_msgThorchainGetAddress(const ThorchainGetAddress *msg); -void fsm_msgThorchainSignTx(const ThorchainSignTx *msg); -void fsm_msgThorchainMsgAck(const ThorchainMsgAck *msg); - void fsm_msgOsmosisGetAddress(const OsmosisGetAddress *msg); void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg); void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg); +void fsm_msgThorchainGetAddress(const ThorchainGetAddress *msg); +void fsm_msgThorchainSignTx(const ThorchainSignTx *msg); +void fsm_msgThorchainMsgAck(const ThorchainMsgAck *msg); + #if DEBUG_LINK // void fsm_msgDebugLinkDecision(DebugLinkDecision *msg); void fsm_msgDebugLinkGetState(DebugLinkGetState *msg); diff --git a/include/keepkey/firmware/osmosis.h b/include/keepkey/firmware/osmosis.h index ebf9ff6cb..38bed14c0 100644 --- a/include/keepkey/firmware/osmosis.h +++ b/include/keepkey/firmware/osmosis.h @@ -8,31 +8,5 @@ #include typedef struct _OsmosisSignTx OsmosisSignTx; -typedef struct _OsmosisMsgDelegate OsmosisMsgDelegate; -typedef struct _OsmosisMsgUndelegate OsmosisMsgUndelegate; -typedef struct _OsmosisMsgClaim OsmosisMsgClaim; -typedef struct _OsmosisMsgLPAdd OsmosisMsgLPAdd; -typedef struct _OsmosisMsgLPRemove OsmosisMsgLPRemove; -typedef struct _OsmosisMsgFarmTokens OsmosisMsgFarmTokens; -typedef struct _OsmosisMsgIBCDeposit OsmosisMsgIBCDeposit; -typedef struct _OsmosisMsgIBCWithdrawal OsmosisMsgIBCWithdrawal; -typedef struct _OsmosisMsgSwap OsmosisMsgSwap; - -bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg); -bool osmosis_signTxUpdateMsgSend(const uint64_t amount, const char *to_address); -bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg); -bool osmosis_signTxUpdateMsgUndelegate(const OsmosisMsgUndelegate *undelegatemsg); -bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg); -bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove *lpremovemsg); -bool osmosis_signTxUpdateMsgFarmTokens(const OsmosisMsgFarmTokens *msgfarmtokens); -bool osmosis_signTxUpdateMsgIBCDeposit(const OsmosisMsgIBCDeposit *ibcdepositmsg); -bool osmosis_signTxUpdateMsgIBCWithdrawal(const OsmosisMsgIBCWithdrawal *ibcwithdrawalmsg); -bool osmosis_signTxUpdateMsgClaim(const OsmosisMsgClaim *claimmsg); -bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap *swapmsg); -bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature); -bool osmosis_signingIsInited(void); -bool osmosis_signingIsFinished(void); -void osmosis_signAbort(void); -const OsmosisSignTx *osmosis_getOsmosisSignTx(void); #endif diff --git a/include/keepkey/firmware/signtx_tendermint.h b/include/keepkey/firmware/signtx_tendermint.h index f3f5ad892..68a539974 100644 --- a/include/keepkey/firmware/signtx_tendermint.h +++ b/include/keepkey/firmware/signtx_tendermint.h @@ -13,14 +13,12 @@ bool tendermint_signTxInit(const HDNode *_node, const void *_msg, const size_t msgsize, const char *denom); bool tendermint_signTxUpdateMsgSend(const uint64_t amount, const char *to_address, - const char *chainstr, - const char *denom, + const char *chainstr, const char *denom, const char *msgTypePrefix); bool tendermint_signTxUpdateMsgDelegate(const uint64_t amount, const char *delegator_address, const char *validator_address, - const char *chainstr, - const char *denom, + const char *chainstr, const char *denom, const char *msgTypePrefix); bool tendermint_signTxUpdateMsgUndelegate(const uint64_t amount, const char *delegator_address, @@ -35,14 +33,39 @@ bool tendermint_signTxUpdateMsgRedelegate( bool tendermint_signTxUpdateMsgRewards(const uint64_t *amount, const char *delegator_address, const char *validator_address, - const char *chainstr, - const char *denom, + const char *chainstr, const char *denom, const char *msgTypePrefix); +bool tendermint_signTxUpdateMsgLPAdd( + const char *sender, const char *pool_id, const uint64_t share_out_amount, + const char *denom_in_max_a, const uint64_t amount_in_max_a, + const char *denom_in_max_b, const uint64_t amount_in_max_b, + const char *chainstr, const char *denom, const char *msgTypePrefix); +bool tendermint_signTxUpdateMsgLPRemove( + const char *sender, const char *pool_id, const uint64_t share_out_amount, + const char *denom_out_min_a, const uint64_t amount_out_min_a, + const char *denom_out_min_b, const uint64_t amount_out_min_b, + const char *chainstr, const char *denom, const char *msgTypePrefix); +bool tendermint_signTxUpdateMsgLPStake(const char *owner, + const uint64_t duration, + const uint64_t amount, + const char *chainstr, const char *denom, + const char *msgTypePrefix); +bool tendermint_signTxUpdateMsgLPUnstake(const char *owner, const char *id, + const char *chainstr, + const char *denom, + const char *msgTypePrefix); bool tendermint_signTxUpdateMsgIBCTransfer( const uint64_t amount, const char *sender, const char *receiver, const char *source_channel, const char *source_port, const char *revision_number, const char *revision_height, const char *chainstr, const char *denom, const char *msgTypePrefix); +bool tendermint_signTxUpdateMsgSwap(const char *sender, const char *pool_id, + const char *token_out_denom, + const char *token_in_denom, + const uint64_t token_in_amount, + const uint64_t token_out_min_amount, + const char *chainstr, const char *denom, + const char *msgTypePrefix); bool tendermint_signTxFinalize(uint8_t *public_key, uint8_t *signature); bool tendermint_signingIsInited(void); bool tendermint_signingIsFinished(void); diff --git a/include/keepkey/transport/interface.h b/include/keepkey/transport/interface.h index fdcba553f..4186db8ce 100644 --- a/include/keepkey/transport/interface.h +++ b/include/keepkey/transport/interface.h @@ -28,11 +28,11 @@ #include "messages-binance.pb.h" #include "messages-cosmos.pb.h" +#include "messages-osmosis.pb.h" #include "messages-eos.pb.h" #include "messages-ripple.pb.h" #include "messages-tendermint.pb.h" #include "messages-thorchain.pb.h" -#include "messages-osmosis.pb.h" #include "types.pb.h" #include "trezor_transport.h" diff --git a/include/keepkey/transport/messages-osmosis.options b/include/keepkey/transport/messages-osmosis.options index b9a3e549f..a0fa2c357 100644 --- a/include/keepkey/transport/messages-osmosis.options +++ b/include/keepkey/transport/messages-osmosis.options @@ -1,47 +1,60 @@ OsmosisGetAddress.address_n max_count:10 -OsmosisAddress.address max_size:46 +OsmosisAddress.address max_size:53 OsmosisSignTx.address_n max_count:10 OsmosisSignTx.chain_id max_size:32 OsmosisSignTx.memo max_size:256 -OsmosisMsgSend.from_address max_size:46 -OsmosisMsgSend.to_address max_size:46 +OsmosisMsgSend.from_address max_size:53 +OsmosisMsgSend.to_address max_size:53 +OsmosisMsgSend.denom max_size:9 -OsmosisMsgDelegate.delegator_address max_size:46 +OsmosisMsgDelegate.delegator_address max_size:53 OsmosisMsgDelegate.validator_address max_size:53 +OsmosisMsgDelegate.denom max_size:9 -OsmosisMsgUndelegate.delegator_address max_size:46 +OsmosisMsgUndelegate.delegator_address max_size:53 OsmosisMsgUndelegate.validator_address max_size:53 - -OsmosisMsgClaim.delegator_address max_size:46 -OsmosisMsgClaim.validator_address max_size:53 - -OsmosisMsgLPAdd.sender max_size:46 -OsmosisMsgLPAdd.pool_id max_size:16 - -OsmosisMsgLPRemove.sender max_size:46 -OsmosisMsgLPRemove.pool_id max_size:16 - -OsmosisMsgFarmTokens.owner max_size:46 - -OsmosisMsgIBCDeposit.source_port max_size:16 -OsmosisMsgIBCDeposit.source_channel max_size:16 -OsmosisMsgIBCDeposit.sender max_size:46 -OsmosisMsgIBCDeposit.receiver max_size:46 - -OsmosisMsgIBCWithdrawal.source_port max_size:16 -OsmosisMsgIBCWithdrawal.source_channel max_size:16 -OsmosisMsgIBCWithdrawal.sender max_size:46 -OsmosisMsgIBCWithdrawal.receiver max_size:46 - -OsmosisMsgSwap.sender max_size:46 -OsmosisMsgSwap.pool_id max_size:16 -OsmosisMsgSwap.token_out_denom max_size:8 +OsmosisMsgUndelegate.denom max_size:9 + +OsmosisMsgRedelegate.delegator_address max_size:53 +OsmosisMsgRedelegate.validator_src_address max_size:53 +OsmosisMsgRedelegate.validator_dst_address max_size:53 +OsmosisMsgRedelegate.denom max_size:9 + +OsmosisMsgRewards.delegator_address max_size:53 +OsmosisMsgRewards.validator_address max_size:53 +OsmosisMsgRewards.denom max_size:9 + +OsmosisMsgLPAdd.sender max_size:53 +OsmosisMsgLPAdd.pool_id max_size:129 +OsmosisMsgLPAdd.denom_in_max_a max_size:9 +OsmosisMsgLPAdd.denom_in_max_b max_size:9 + +OsmosisMsgLPRemove.sender max_size:53 +OsmosisMsgLPRemove.pool_id max_size:129 +OsmosisMsgLPRemove.denom_out_min_a max_size:9 +OsmosisMsgLPRemove.denom_out_min_b max_size:9 + +OsmosisMsgLPStake.owner max_size:53 +OsmosisMsgLPStake.denom max_size:9 + +OsmosisMsgLPUnstake.owner max_size:53 +OsmosisMsgLPUnstake.id max_size:129 + +OsmosisMsgIBCTransfer.sender max_size:53 +OsmosisMsgIBCTransfer.receiver max_size:53 +OsmosisMsgIBCTransfer.source_channel max_size:32 +OsmosisMsgIBCTransfer.source_port max_size:32 +OsmosisMsgIBCTransfer.revision_height max_size:16 +OsmosisMsgIBCTransfer.revision_number max_size:9 +OsmosisMsgIBCTransfer.denom max_size:9 + +OsmosisMsgSwap.sender max_size:53 +OsmosisMsgSwap.pool_id max_size:129 +OsmosisMsgSwap.token_out_denom max_size:9 +OsmosisMsgSwap.token_in_denom max_size:9 OsmosisSignedTx.public_key max_size:33 -OsmosisSignedTx.signature max_size:64 - -OsmosisToken.denom max_size:72 - +OsmosisSignedTx.signature max_size:64 \ No newline at end of file diff --git a/lib/firmware/app_confirm.c b/lib/firmware/app_confirm.c index 3308d1c14..86e7976f8 100644 --- a/lib/firmware/app_confirm.c +++ b/lib/firmware/app_confirm.c @@ -290,6 +290,22 @@ bool confirm_xpub(const char *node_str, const char *xpub) { desc, "%s", address); } + /* + * confirm_osmosis_address() - Show osmosis address confirmation + * + * INPUT + * - desc: description to show with address + * - address: address to display both as string and in QR + * OUTPUT + * true/false of confirmation + * + */ + bool confirm_osmosis_address(const char *desc, const char *address) { + return confirm_with_custom_layout(&layout_osmosis_address_notification, + ButtonRequestType_ButtonRequest_Address, + desc, "%s", address); + } + /* * confirm_ethereum_address() - Show ethereum address confirmation * diff --git a/lib/firmware/app_layout.c b/lib/firmware/app_layout.c index 382263bf1..dfa7e5dfe 100644 --- a/lib/firmware/app_layout.c +++ b/lib/firmware/app_layout.c @@ -473,6 +473,48 @@ void layout_cosmos_address_notification(const char *desc, const char *address, layout_notification_icon(type, &sp); } +/* + * layout_osmosis_address_notification() - Display osmosis address + * notification + * + * INPUT + * - desc: description of address being shown (normal or multisig) + * - address: osmosis address to display + * - type: notification type + * OUTPUT + * none + */ +void layout_osmosis_address_notification(const char *desc, const char *address, + NotificationType type) { + DrawableParams sp; + const Font *address_font = get_body_font(); + ; + Canvas *canvas = layout_get_canvas(); + + call_leaving_handler(); + layout_clear(); + + if (strcmp(desc, "") != 0) { + const Font *title_font = get_title_font(); + sp.y = TOP_MARGIN_FOR_TWO_LINES; + sp.x = LEFT_MARGIN + 65; + sp.color = BODY_COLOR; + draw_string(canvas, title_font, desc, &sp, TRANSACTION_WIDTH - 2, + font_height(title_font) + BODY_FONT_LINE_PADDING); + } + + /* Body */ + sp.y = TOP_MARGIN_FOR_TWO_LINES + TOP_MARGIN + TOP_MARGIN; + sp.x = LEFT_MARGIN + 65; + sp.color = BODY_COLOR; + + draw_string(canvas, address_font, address, &sp, 140, + font_height(address_font) + BODY_FONT_LINE_PADDING); + + layout_address(address, QR_LARGE); + layout_notification_icon(type, &sp); +} + /* * layout_ethereum_address_notification() - Display ethereum address * notification diff --git a/lib/firmware/fsm.c b/lib/firmware/fsm.c index aede2f4ed..e7160bc95 100644 --- a/lib/firmware/fsm.c +++ b/lib/firmware/fsm.c @@ -75,11 +75,11 @@ #include "messages.pb.h" #include "messages-binance.pb.h" #include "messages-cosmos.pb.h" +#include "messages-osmosis.pb.h" #include "messages-eos.pb.h" #include "messages-nano.pb.h" #include "messages-ripple.pb.h" #include "messages-thorchain.pb.h" -#include "messages-osmosis.pb.h" #include @@ -275,8 +275,8 @@ void fsm_msgClearSession(ClearSession *msg) { #include "fsm_msg_debug.h" #include "fsm_msg_eos.h" #include "fsm_msg_cosmos.h" +#include "fsm_msg_osmosis.h" #include "fsm_msg_binance.h" #include "fsm_msg_ripple.h" #include "fsm_msg_tendermint.h" #include "fsm_msg_thorchain.h" -#include "fsm_msg_osmosis.h" diff --git a/lib/firmware/fsm_msg_osmosis.h b/lib/firmware/fsm_msg_osmosis.h index 1b8d9514d..9fd0e5f0b 100644 --- a/lib/firmware/fsm_msg_osmosis.h +++ b/lib/firmware/fsm_msg_osmosis.h @@ -1,4 +1,3 @@ - void fsm_msgOsmosisGetAddress(const OsmosisGetAddress *msg) { RESP_INIT(OsmosisAddress); @@ -12,22 +11,13 @@ void fsm_msgOsmosisGetAddress(const OsmosisGetAddress *msg) { } HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count, NULL); - char mainnet[] = "osmo"; - char testnet[] = "tosmo"; - char *pfix; - if (!node) { return; } hdnode_fill_public_key(node); - pfix = mainnet; - if (msg->has_testnet && msg->testnet) { - pfix = testnet; - } - - if (!tendermint_getAddress(node, pfix, resp->address)) { + if (!tendermint_getAddress(node, "osmo", resp->address)) { memzero(node, sizeof(*node)); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Can't encode address")); @@ -84,7 +74,7 @@ void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg) { if (!msg->has_account_number || !msg->has_chain_id || !msg->has_fee_amount || !msg->has_gas || !msg->has_sequence) { - osmosis_signAbort(); + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Missing Fields On Message"); layoutHome(); @@ -101,8 +91,9 @@ void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg) { RESP_INIT(OsmosisMsgRequest); - if (!osmosis_signTxInit(node, msg)) { - osmosis_signAbort(); + if (!tendermint_signTxInit(node, (void *)msg, sizeof(OsmosisSignTx), + "uosmo")) { + tendermint_signAbort(); memzero(node, sizeof(*node)); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Failed to initialize transaction signing")); @@ -117,411 +108,669 @@ void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg) { void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { // Confirm transaction basics - // supports only 1 message ack - CHECK_PARAM(osmosis_signingIsInited(), "Signing not in progress"); - if (msg->has_send && msg->send.has_to_address && msg->send.has_token && - msg->send.token.has_amount) { - // pass - } else if (msg->has_delegate && msg->delegate.has_delegator_address && - msg->delegate.has_validator_address && msg->delegate.has_token) { - // pass - } else if (msg->has_undelegate && msg->undelegate.has_delegator_address && - msg->undelegate.has_validator_address && - msg->undelegate.has_token) { - // pass - } else if (msg->has_claim && msg->claim.has_delegator_address && - msg->claim.has_validator_address && msg->claim.has_token) { - // pass - } else if (msg->has_lp_add && msg->lp_add.has_sender && - msg->lp_add.has_pool_id && msg->lp_add.has_share_out_amount && - msg->lp_add.has_token_in_max_a && msg->lp_add.has_token_in_max_b) { - // pass - } else if (msg->has_lp_remove && msg->lp_remove.has_sender && - msg->lp_remove.has_pool_id && - msg->lp_remove.has_share_out_amount && - msg->lp_remove.has_token_out_min_a && - msg->lp_remove.has_token_out_min_b) { - // pass - } else if (msg->has_farm_tokens && msg->farm_tokens.has_owner && - msg->farm_tokens.has_duration && msg->farm_tokens.has_token) { - // pass - } else if (msg->has_ibc_deposit && msg->ibc_deposit.has_source_port && - msg->ibc_deposit.has_source_channel && - msg->ibc_deposit.has_token && msg->ibc_deposit.has_sender && - msg->ibc_deposit.has_receiver && - msg->ibc_deposit.has_timeout_height) { - // pass - } else if (msg->has_ibc_withdrawal && msg->ibc_withdrawal.has_source_port && - msg->ibc_withdrawal.has_source_channel && - msg->ibc_withdrawal.has_token && msg->ibc_withdrawal.has_sender && - msg->ibc_withdrawal.has_receiver && - msg->ibc_withdrawal.has_timeout_height) { - // pass - } else if (msg->has_swap && msg->swap.has_sender && msg->swap.has_pool_id && - msg->swap.has_token_out_denom && msg->swap.has_token_in && - msg->swap.has_token_out_min_amount) { - // pass - } else { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_FirmwareError, - _("Invalid Osmosis Message Type")); - layoutHome(); - return; - } + CHECK_PARAM(tendermint_signingIsInited(), "Signing not in progress"); const CoinType *coin = fsm_getCoin(true, "Osmosis"); if (!coin) { return; } - const OsmosisSignTx *sign_tx = osmosis_getOsmosisSignTx(); + const OsmosisSignTx *sign_tx = (OsmosisSignTx *)tendermint_getSignTx(); if (msg->has_send) { - switch (msg->send.address_type) { - case OutputAddressType_TRANSFER: - default: { - char amount_str[32]; - bn_format_uint64(msg->send.token.amount, NULL, " OSMO", 8, 0, false, - amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Transfer", - "Send %s to %s?", amount_str, msg->send.to_address)) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } + if (!msg->send.has_to_address || !msg->send.has_amount) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } - break; - } + char amount_str[32]; + bn_format_uint64(msg->send.amount, NULL, " OSMO", 6, 0, false, amount_str, + sizeof(amount_str)); + if (!confirm_transaction_output( + ButtonRequestType_ButtonRequest_ConfirmOutput, amount_str, + msg->send.to_address)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; } - if (!osmosis_signTxUpdateMsgSend(msg->send.token.amount, - msg->send.to_address)) { - osmosis_signAbort(); + + if (!tendermint_signTxUpdateMsgSend(msg->send.amount, msg->send.to_address, + "osmosis", "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include send message in transaction"); layoutHome(); return; } - } else if (msg->has_delegate) { + /** Confirm required transaction parameters exist */ + if (!msg->delegate.has_delegator_address || + !msg->delegate.has_validator_address || !msg->delegate.has_amount) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + /** Confirm transaction parameters on-screen */ char amount_str[32]; - bn_format_uint64(msg->delegate.token.amount, NULL, " OSMO", 8, 0, false, + bn_format_uint64(msg->delegate.amount, NULL, " OSMO", 6, 0, false, amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Delegate", - "Delegate %s to %s?", amount_str, - msg->delegate.validator_address)) { - osmosis_signAbort(); + if (!confirm_osmosis_address("Confirm delegator address", + msg->delegate.delegator_address)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm_osmosis_address("Confirm validator address", + msg->delegate.validator_address)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm_with_custom_layout( + &layout_notification_no_title_bold, + ButtonRequestType_ButtonRequest_ConfirmOutput, "", "Delegate %s?", + amount_str)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgDelegate(&(msg->delegate))) { - osmosis_signAbort(); + if (!tendermint_signTxUpdateMsgDelegate(msg->delegate.amount, + msg->delegate.delegator_address, + msg->delegate.validator_address, + "osmosis", "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include delegate message in transaction"); layoutHome(); return; } } else if (msg->has_undelegate) { + /** Confirm required transaction parameters exist */ + if (!msg->undelegate.has_delegator_address || + !msg->undelegate.has_validator_address || !msg->undelegate.has_amount) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + /** Confirm transaction parameters on-screen */ char amount_str[32]; - bn_format_uint64(msg->undelegate.token.amount, NULL, " OSMO", 8, 0, false, + bn_format_uint64(msg->undelegate.amount, NULL, " OSMO", 6, 0, false, amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Undelegate", - "Undelegate %s from %s?", amount_str, - msg->undelegate.validator_address)) { - osmosis_signAbort(); + if (!confirm_osmosis_address("Confirm delegator address", + msg->undelegate.delegator_address)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgUndelegate(&(msg->undelegate))) { - osmosis_signAbort(); + if (!confirm_osmosis_address("Confirm validator address", + msg->undelegate.validator_address)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm_with_custom_layout( + &layout_notification_no_title_bold, + ButtonRequestType_ButtonRequest_ConfirmOutput, "", "Undelegate %s?", + amount_str)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!tendermint_signTxUpdateMsgUndelegate( + msg->undelegate.amount, msg->undelegate.delegator_address, + msg->undelegate.validator_address, "osmosis", "uosmo", + "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include undelegate message in transaction"); layoutHome(); return; } - } else if (msg->has_claim) { + } else if (msg->has_redelegate) { + /** Confirm required transaction parameters exist */ + if (!msg->redelegate.has_delegator_address || + !msg->redelegate.has_validator_src_address || + !msg->redelegate.has_validator_dst_address || + !msg->redelegate.has_amount) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + /** Confirm transaction parameters on-screen */ char amount_str[32]; - bn_format_uint64(msg->claim.token.amount, NULL, " OSMO", 8, 0, false, + bn_format_uint64(msg->redelegate.amount, NULL, " OSMO", 6, 0, false, amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim", - "Claim %s from %s?", amount_str, - msg->claim.validator_address)) { - osmosis_signAbort(); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Redelegate", + "Redelegate %s?", amount_str)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgClaim(&(msg->claim))) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include claim message in transaction"); + if (!confirm_osmosis_address("Delegator address", + msg->redelegate.delegator_address)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - } else if (msg->has_lp_add) { - char amount_a_str[32]; - char amount_b_str[32]; - const char *denom_a_str = - strcmp(msg->lp_add.token_in_max_a.denom, "uosmo") == 0 - ? "OSMO" - : msg->lp_add.token_in_max_a.denom; - const char *denom_b_str = - strcmp(msg->lp_add.token_in_max_b.denom, "uosmo") == 0 - ? "OSMO" - : msg->lp_add.token_in_max_b.denom; - - bn_format_uint64(msg->lp_add.token_in_max_a.amount, NULL, NULL, 8, 0, false, - amount_a_str, sizeof(amount_a_str)); - - bn_format_uint64(msg->lp_add.token_in_max_b.amount, NULL, NULL, 8, 0, false, - amount_b_str, sizeof(amount_b_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", - "Confirm Token A:\nAmount: %s\nDenom: %s", amount_a_str, - denom_a_str)) { - osmosis_signAbort(); + if (!confirm_osmosis_address("Validator source address", + msg->redelegate.validator_src_address)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", - "Confirm Token B:\nAmount: %s\nDenom: %s", amount_b_str, - denom_b_str)) { - osmosis_signAbort(); + if (!confirm_osmosis_address("Validator dest. address", + msg->redelegate.validator_dst_address)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", - "Confirm Pool ID: %s", msg->lp_add.pool_id)) { - osmosis_signAbort(); + if (!tendermint_signTxUpdateMsgRedelegate( + msg->redelegate.amount, msg->redelegate.delegator_address, + msg->redelegate.validator_src_address, + msg->redelegate.validator_dst_address, "osmosis", "uosmo", + "cosmos-sdk")) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include redelegate message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_rewards) { + /** Confirm required transaction parameters exist */ + if (!msg->rewards.has_delegator_address || + !msg->rewards.has_validator_address) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + + if (msg->rewards.has_amount) { + /** Confirm transaction parameters on-screen */ + char amount_str[32]; + bn_format_uint64(msg->rewards.amount, NULL, " OSMO", 6, 0, false, + amount_str, sizeof(amount_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", + "Claim %s?", amount_str)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + } else { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", + "Claim all available rewards?")) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + } + + if (!confirm_osmosis_address("Confirm delegator address", + msg->rewards.delegator_address)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgLPAdd(&(msg->lp_add))) { - osmosis_signAbort(); + if (!confirm_osmosis_address("Confirm validator address", + msg->rewards.validator_address)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!tendermint_signTxUpdateMsgRewards( + msg->rewards.has_amount ? &msg->rewards.amount : NULL, + msg->rewards.delegator_address, msg->rewards.validator_address, + "osmosis", "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include LP Add message in transaction"); + "Failed to include rewards message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_lp_add) { + /** Confirm required transaction parameters exist */ + if (!msg->lp_add.has_sender || !msg->lp_add.has_pool_id || + !msg->lp_add.has_share_out_amount || !msg->lp_add.has_denom_in_max_a || + !msg->lp_add.has_amount_in_max_a || !msg->lp_add.has_denom_in_max_b || + !msg->lp_add.has_amount_in_max_b) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); layoutHome(); return; } - } else if (msg->has_lp_remove) { - char amount_a_str[32]; - char amount_b_str[32]; - const char *denom_a_str = - strcmp(msg->lp_remove.token_out_min_a.denom, "uosmo") == 0 - ? "OSMO" - : msg->lp_remove.token_out_min_a.denom; - const char *denom_b_str = - strcmp(msg->lp_remove.token_out_min_b.denom, "uosmo") == 0 - ? "OSMO" - : msg->lp_remove.token_out_min_b.denom; - - bn_format_uint64(msg->lp_remove.token_out_min_a.amount, NULL, NULL, 8, 0, - false, amount_a_str, sizeof(amount_a_str)); - - bn_format_uint64(msg->lp_remove.token_out_min_b.amount, NULL, NULL, 8, 0, - false, amount_b_str, sizeof(amount_b_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", - "Confirm Token A:\nAmount: %s\nDenom: %s", amount_a_str, - denom_a_str)) { - osmosis_signAbort(); + /** Confirm transaction parameters on-screen */ + char amount_str_a[32]; + char denom_str_a[12]; + sprintf(denom_str_a, " %s", msg->lp_add.denom_in_max_a); + bn_format_uint64(msg->lp_add.amount_in_max_a, NULL, denom_str_a, 6, 0, + false, amount_str_a, sizeof(amount_str_a)); + char amount_str_b[32]; + char denom_str_b[12]; + sprintf(denom_str_b, " %s", msg->lp_add.denom_in_max_b); + bn_format_uint64(msg->lp_add.amount_in_max_b, NULL, denom_str_b, 6, 0, + false, amount_str_b, sizeof(amount_str_b)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", + "Deposit %s and %s?", amount_str_a, amount_str_b)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", - "Confirm Token B:\nAmount: %s\nDenom: %s", amount_b_str, - denom_b_str)) { - osmosis_signAbort(); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", "%s", + msg->lp_add.pool_id)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", - "Confirm Pool ID: %s", msg->lp_remove.pool_id)) { - osmosis_signAbort(); + // TODO: Should this be a percentage? If so, multiply by 100 and add percent + // sign + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Pool share amount", + "%llu", msg->lp_add.share_out_amount)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgLPRemove(&(msg->lp_remove))) { - osmosis_signAbort(); + // TODO: Create signTxUpdateMsgLPAdd function + if (!tendermint_signTxUpdateMsgLPAdd( + msg->lp_add.sender, msg->lp_add.pool_id, + msg->lp_add.share_out_amount, msg->lp_add.denom_in_max_a, + msg->lp_add.amount_in_max_a, msg->lp_add.denom_in_max_b, + msg->lp_add.amount_in_max_b, "osmosis", "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include LP Remove message in transaction"); + "Failed to include rewards message in transaction"); layoutHome(); return; } - } else if (msg->has_farm_tokens) { - char amount_str[32]; - bn_format_uint64(msg->farm_tokens.token.amount, NULL, " OSMO", 8, 0, false, - amount_str, sizeof(amount_str)); + } else if (msg->has_lp_remove) { + /** Confirm required transaction parameters exist */ + if (!msg->lp_remove.has_sender || !msg->lp_remove.has_pool_id || + !msg->lp_remove.has_share_out_amount || + !msg->lp_remove.has_denom_out_min_a || + !msg->lp_remove.has_amount_out_min_a || + !msg->lp_remove.has_denom_out_min_b || + !msg->lp_remove.has_amount_out_min_b) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + + /** Confirm transaction parameters on-screen */ + char amount_str_a[32]; + char denom_str_a[12]; + sprintf(denom_str_a, " %s", msg->lp_remove.denom_out_min_a); + bn_format_uint64(msg->lp_remove.amount_out_min_a, NULL, denom_str_a, 6, 0, + false, amount_str_a, sizeof(amount_str_a)); + char amount_str_b[32]; + char denom_str_b[12]; + sprintf(denom_str_b, " %s", msg->lp_remove.denom_out_min_b); + bn_format_uint64(msg->lp_remove.amount_out_min_b, NULL, denom_str_b, 6, 0, + false, amount_str_b, sizeof(amount_str_b)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Farm Tokens", - "Lock %s in %s?", amount_str, msg->farm_tokens.token.denom)) { - osmosis_signAbort(); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", + "Withdraw %s and %s?", amount_str_a, amount_str_b)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Owner", "%s", - msg->farm_tokens.owner)) { - osmosis_signAbort(); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", "%s", + msg->lp_remove.pool_id)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Duration", - "%lld", msg->farm_tokens.duration)) { - osmosis_signAbort(); + // TODO: Should this be a percentage? If so, multiply by 100 and add percent + // sign + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Pool share amount", + "%llu", msg->lp_remove.share_out_amount)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgFarmTokens(&(msg->farm_tokens))) { - osmosis_signAbort(); + // TODO: Create signTxUpdateMsgLPAdd function + if (!tendermint_signTxUpdateMsgLPRemove( + msg->lp_remove.sender, msg->lp_remove.pool_id, + msg->lp_remove.share_out_amount, msg->lp_remove.denom_out_min_a, + msg->lp_remove.amount_out_min_a, msg->lp_remove.denom_out_min_b, + msg->lp_remove.amount_out_min_b, "osmosis", "uosmo", + "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include Farm Tokens message in transaction"); + "Failed to include rewards message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_lp_stake) { + char *lockup_duration; + char *supported_lockup_durations[] = {"1 day", "1 week", "2 weeks"}; + /** Confirm required transaction parameters exist */ + if (!msg->lp_stake.has_owner || !msg->lp_stake.has_duration || + !msg->lp_stake.has_denom || !msg->lp_stake.has_amount) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); layoutHome(); return; } - } else if (msg->has_ibc_deposit) { + switch (msg->lp_stake.duration) { + case 86400: + /* 1 day in seconds */ + lockup_duration = supported_lockup_durations[0]; + break; + case 604800: + /* 1 week in seconds */ + lockup_duration = supported_lockup_durations[1]; + break; + case 1209600: + /* 2 weeks in seconds */ + lockup_duration = supported_lockup_durations[2]; + break; + default: + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Unsupported lockup duration")); + layoutHome(); + return; + } + + /** Confirm transaction parameters on-screen */ char amount_str[32]; - bn_format_uint64(msg->ibc_deposit.token.amount, NULL, " OSMO", 8, 0, false, + char denom_str[12]; + sprintf(denom_str, " %s", msg->lp_stake.denom); + bn_format_uint64(msg->lp_stake.amount, NULL, denom_str, 6, 0, false, amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Deposit", - "Send %s on %s to %s?", amount_str, - msg->ibc_deposit.source_port, - msg->ibc_deposit.source_channel)) { - osmosis_signAbort(); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Bonding", "Bond %s?", + amount_str)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, - "Confirm Sender Address", "%s", msg->ibc_deposit.sender)) { - osmosis_signAbort(); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm lockup period", + "Lock tokens for %s?", lockup_duration)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, - "Confirm Receiver Address", "%s", msg->ibc_deposit.receiver)) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + if (!tendermint_signTxUpdateMsgLPStake( + msg->lp_stake.owner, msg->lp_stake.duration, msg->lp_stake.amount, + "osmosis", "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include rewards message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_lp_unstake) { + /** Confirm required transaction parameters exist */ + if (!msg->lp_unstake.has_owner || !msg->lp_unstake.has_id) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgIBCDeposit(&(msg->ibc_deposit))) { - osmosis_signAbort(); + // if (msg->lp_unstake.has_amount) { + // /** Confirm transaction parameters on-screen */ + // char amount_str[32]; + // bn_format_uint64(msg->lp_unstake.amount, NULL, " OSMO", 6, 0, false, + // amount_str, sizeof(amount_str)); + + // if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", + // "Claim %s?", amount_str)) { + // tendermint_signAbort(); + // fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + // layoutHome(); + // return; + // } + // } else { + // if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", + // "Claim all available lp_unstake?")) { + // tendermint_signAbort(); + // fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + // layoutHome(); + // return; + // } + // } + + // if (!confirm_osmosis_address("Confirm delegator address", + // msg->lp_unstake.delegator_address)) { + // tendermint_signAbort(); + // fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + // layoutHome(); + // return; + // } + + // if (!confirm_osmosis_address("Confirm validator address", + // msg->lp_unstake.validator_address)) { + // tendermint_signAbort(); + // fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + // layoutHome(); + // return; + // } + + if (!tendermint_signTxUpdateMsgLPUnstake(msg->lp_unstake.owner, + msg->lp_unstake.id, "osmosis", + "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include IBC Deposit message in transaction"); + "Failed to include lp_unstake message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_ibc_transfer) { + /** Confirm required transaction parameters exist */ + if (!msg->ibc_transfer.has_sender || + !msg->ibc_transfer.has_source_channel || + !msg->ibc_transfer.has_source_port || + !msg->ibc_transfer.has_revision_height || + !msg->ibc_transfer.has_revision_number || + !msg->ibc_transfer.has_denom) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); layoutHome(); return; } - } else if (msg->has_ibc_withdrawal) { + /** Confirm transaction parameters on-screen */ char amount_str[32]; - bn_format_uint64(msg->ibc_withdrawal.token.amount, NULL, " OSMO", 8, 0, - false, amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Withdrawal", - "Receive %s on %s from %s?", amount_str, - msg->ibc_withdrawal.source_port, - msg->ibc_withdrawal.source_channel)) { - osmosis_signAbort(); + bn_format_uint64(msg->ibc_transfer.amount, NULL, " OSMO", 6, 0, false, + amount_str, sizeof(amount_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Transfer", + "Transfer %s to %s?", amount_str, msg->ibc_transfer.sender)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Source Channel", "%s", + msg->ibc_transfer.source_channel)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Source Port", + "%s", msg->ibc_transfer.source_port)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } if (!confirm(ButtonRequestType_ButtonRequest_Other, - "Confirm Sender Address", "%s", msg->ibc_withdrawal.sender)) { - osmosis_signAbort(); + "Confirm Revision Height", "%s", + msg->ibc_transfer.revision_height)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } if (!confirm(ButtonRequestType_ButtonRequest_Other, - "Confirm Receiver Address", "%s", - msg->ibc_withdrawal.receiver)) { - osmosis_signAbort(); + "Confirm Revision Number", "%s", + msg->ibc_transfer.revision_number)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgIBCWithdrawal(&(msg->ibc_withdrawal))) { - osmosis_signAbort(); - fsm_sendFailure( - FailureType_Failure_SyntaxError, - "Failed to include IBC Withdrawal message in transaction"); + if (!tendermint_signTxUpdateMsgIBCTransfer( + msg->ibc_transfer.amount, msg->ibc_transfer.sender, + msg->ibc_transfer.receiver, msg->ibc_transfer.source_channel, + msg->ibc_transfer.source_port, msg->ibc_transfer.revision_number, + msg->ibc_transfer.revision_height, "osmosis", "uosmo", + "cosmos-sdk")) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include IBC transfer message in transaction"); layoutHome(); return; } } else if (msg->has_swap) { - char amount_in_str[32] = {' '}; - char amount_out_str[32] = {' '}; - bn_format_uint64(msg->swap.token_in.amount, NULL, msg->swap.token_in.denom, - 8, 0, false, amount_in_str + (1 * sizeof(char)), - sizeof(amount_in_str)); - bn_format_uint64( - msg->swap.token_out_min_amount, NULL, msg->swap.token_out_denom, 8, 0, - false, amount_out_str + (1 * sizeof(char)), sizeof(amount_out_str)); + /** Confirm required transaction parameters exist */ + if (!msg->swap.has_sender || + !msg->swap.has_pool_id | !msg->swap.has_token_out_denom || + !msg->swap.has_token_in_denom || !msg->swap.has_token_in_amount || + !msg->swap.has_token_out_min_amount) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + + /** Confirm transaction parameters on-screen */ + char token_in_amount_str[32]; + char token_in_denom_str[12]; + sprintf(token_in_denom_str, " %s", msg->swap.token_in_denom); + bn_format_uint64(msg->swap.token_in_amount, NULL, token_in_denom_str, 6, 0, + false, token_in_amount_str, sizeof(token_in_amount_str)); + char token_out_amount_str[32]; + char token_out_denom_str[12]; + sprintf(token_out_denom_str, " %s", msg->swap.token_out_denom); + bn_format_uint64(msg->swap.token_out_min_amount, NULL, token_out_denom_str, + 6, 0, false, token_out_amount_str, + sizeof(token_out_amount_str)); if (!confirm(ButtonRequestType_ButtonRequest_Other, "Swap", - "Swap %s for at least %lld?", amount_in_str, - msg->swap.token_out_min_amount)) { - osmosis_signAbort(); + "Swap %s for at least %s?", token_in_amount_str, + token_out_amount_str)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Pool ID", "%s", + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", "%s", msg->swap.pool_id)) { - osmosis_signAbort(); + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgSwap(&(msg->swap))) { - osmosis_signAbort(); + if (!tendermint_signTxUpdateMsgSwap( + msg->swap.sender, msg->swap.pool_id, msg->swap.token_out_denom, + msg->swap.token_in_denom, msg->swap.token_in_amount, + msg->swap.token_out_min_amount, "osmosis", "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include Swap message in transaction"); + "Failed to include swap message in transaction"); layoutHome(); return; } + } else { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Invalid Osmosis message type")); + layoutHome(); + return; } - if (!osmosis_signingIsFinished()) { + if (!tendermint_signingIsFinished()) { RESP_INIT(OsmosisMsgRequest); msg_write(MessageType_MessageType_OsmosisMsgRequest, resp); return; } + if (sign_tx->has_memo && (strlen(sign_tx->memo) > 0)) { + if (!confirm(ButtonRequestType_ButtonRequest_ConfirmMemo, _("Memo"), "%s", + sign_tx->memo)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + } + char node_str[NODE_STRING_LENGTH]; if (!bip32_node_to_string(node_str, sizeof(node_str), coin, sign_tx->address_n, sign_tx->address_n_count, @@ -532,10 +781,21 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { memset(node_str, 0, sizeof(node_str)); } + if (!confirm(ButtonRequestType_ButtonRequest_SignTx, node_str, + "Sign this Osmosis transaction on %s? " + "It includes a fee of %" PRIu32 " uATOM and %" PRIu32 " gas.", + sign_tx->chain_id, sign_tx->fee_amount, sign_tx->gas)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + RESP_INIT(OsmosisSignedTx); - if (!osmosis_signTxFinalize(resp->public_key.bytes, resp->signature.bytes)) { - osmosis_signAbort(); + if (!tendermint_signTxFinalize(resp->public_key.bytes, + resp->signature.bytes)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to finalize signature"); layoutHome(); @@ -546,7 +806,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { resp->has_public_key = true; resp->signature.size = 64; resp->has_signature = true; - osmosis_signAbort(); + tendermint_signAbort(); layoutHome(); msg_write(MessageType_MessageType_OsmosisSignedTx, resp); } \ No newline at end of file diff --git a/lib/firmware/messagemap.def b/lib/firmware/messagemap.def index 3632f12fe..b5f26ebe2 100644 --- a/lib/firmware/messagemap.def +++ b/lib/firmware/messagemap.def @@ -45,6 +45,10 @@ MSG_IN(MessageType_MessageType_CosmosSignTx, CosmosSignTx, fsm_msgCosmosSignTx) MSG_IN(MessageType_MessageType_CosmosMsgAck, CosmosMsgAck, fsm_msgCosmosMsgAck) + MSG_IN(MessageType_MessageType_CosmosGetAddress, OsmosisGetAddress, fsm_msgOsmosisGetAddress) + MSG_IN(MessageType_MessageType_OsmosisSignTx, OsmosisSignTx, fsm_msgOsmosisSignTx) + MSG_IN(MessageType_MessageType_OsmosisMsgAck, OsmosisMsgAck, fsm_msgOsmosisMsgAck) + MSG_IN(MessageType_MessageType_BinanceGetAddress, BinanceGetAddress, fsm_msgBinanceGetAddress) MSG_IN(MessageType_MessageType_BinanceSignTx, BinanceSignTx, fsm_msgBinanceSignTx) MSG_IN(MessageType_MessageType_BinanceTransferMsg, BinanceTransferMsg, fsm_msgBinanceTransferMsg) @@ -60,11 +64,6 @@ MSG_IN(MessageType_MessageType_ThorchainSignTx, ThorchainSignTx, fsm_msgThorchainSignTx) MSG_IN(MessageType_MessageType_ThorchainMsgAck, ThorchainMsgAck, fsm_msgThorchainMsgAck) - MSG_IN(MessageType_MessageType_OsmosisGetAddress, OsmosisGetAddress, fsm_msgOsmosisGetAddress) - MSG_IN(MessageType_MessageType_OsmosisSignTx, OsmosisSignTx, fsm_msgOsmosisSignTx) - MSG_IN(MessageType_MessageType_OsmosisMsgAck, OsmosisMsgAck, fsm_msgOsmosisMsgAck) - - /* Normal Out Messages */ MSG_OUT(MessageType_MessageType_Success, Success, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_Failure, Failure, NO_PROCESS_FUNC) @@ -97,6 +96,10 @@ MSG_OUT(MessageType_MessageType_CosmosMsgRequest, CosmosMsgRequest, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_CosmosSignedTx, CosmosSignedTx, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_OsmosisAddress, OsmosisAddress, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_OsmosisMsgRequest, OsmosisMsgRequest, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_OsmosisSignedTx, OsmosisSignedTx, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_BinanceAddress, BinanceAddress, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_BinancePublicKey, BinancePublicKey, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_BinanceTxRequest, BinanceTxRequest, NO_PROCESS_FUNC) @@ -113,10 +116,6 @@ MSG_OUT(MessageType_MessageType_ThorchainMsgRequest, ThorchainMsgRequest, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_ThorchainSignedTx, ThorchainSignedTx, NO_PROCESS_FUNC) - MSG_OUT(MessageType_MessageType_OsmosisAddress, OsmosisAddress, NO_PROCESS_FUNC) - MSG_OUT(MessageType_MessageType_OsmosisMsgRequest, OsmosisMsgRequest, NO_PROCESS_FUNC) - MSG_OUT(MessageType_MessageType_OsmosisSignedTx, OsmosisSignedTx, NO_PROCESS_FUNC) - #if DEBUG_LINK /* Debug Messages */ DEBUG_IN(MessageType_MessageType_DebugLinkDecision, DebugLinkDecision, NO_PROCESS_FUNC) diff --git a/lib/firmware/signtx_tendermint.c b/lib/firmware/signtx_tendermint.c index 0b28eab69..1fb1bba7c 100644 --- a/lib/firmware/signtx_tendermint.c +++ b/lib/firmware/signtx_tendermint.c @@ -398,7 +398,8 @@ bool tendermint_signTxUpdateMsgRewards(const uint64_t *amount, // 9 + ^24 + 38 = ^72 success &= tendermint_snprintf( &ctx, buffer, sizeof(buffer), - "{\"type\":\"%s/MsgWithdrawDelegationReward\",\"value\":{", msgTypePrefix); + "{\"type\":\"%s/MsgWithdrawDelegationReward\",\"value\":{", + msgTypePrefix); // 20 + ^20 + 11 + ^9 + 3 = ^65 if (amount != NULL) { @@ -429,6 +430,34 @@ bool tendermint_signTxUpdateMsgRewards(const uint64_t *amount, return success; } +bool tendermint_signTxUpdateMsgLPAdd( + const char *sender, const char *pool_id, const uint64_t share_out_amount, + const char *denom_in_max_a, const uint64_t amount_in_max_a, + const char *denom_in_max_b, const uint64_t amount_in_max_b, + const char *chainstr, const char *denom, const char *msgTypePrefix) { + return false; +} +bool tendermint_signTxUpdateMsgLPRemove( + const char *sender, const char *pool_id, const uint64_t share_out_amount, + const char *denom_out_min_a, const uint64_t amount_out_min_a, + const char *denom_out_min_b, const uint64_t amount_out_min_b, + const char *chainstr, const char *denom, const char *msgTypePrefix) { + return false; +} +bool tendermint_signTxUpdateMsgLPStake(const char *owner, + const uint64_t duration, + const uint64_t amount, + const char *chainstr, const char *denom, + const char *msgTypePrefix) { + return false; +} +bool tendermint_signTxUpdateMsgLPUnstake(const char *owner, const char *id, + const char *chainstr, + const char *denom, + const char *msgTypePrefix) { + return false; +} + bool tendermint_signTxUpdateMsgIBCTransfer( const uint64_t amount, const char *sender, const char *receiver, const char *source_channel, const char *source_port, @@ -509,6 +538,16 @@ bool tendermint_signTxUpdateMsgIBCTransfer( return success; } +bool tendermint_signTxUpdateMsgSwap(const char *sender, const char *pool_id, + const char *token_out_denom, + const char *token_in_denom, + const uint64_t token_in_amount, + const uint64_t token_out_min_amount, + const char *chainstr, const char *denom, + const char *msgTypePrefix) { + return false; +} + bool tendermint_signTxFinalize(uint8_t *public_key, uint8_t *signature) { char buffer[128]; diff --git a/lib/transport/CMakeLists.txt b/lib/transport/CMakeLists.txt index 584ada103..66b95e87e 100644 --- a/lib/transport/CMakeLists.txt +++ b/lib/transport/CMakeLists.txt @@ -10,10 +10,10 @@ set(protoc_pb_sources ${DEVICE_PROTOCOL}/messages-nano.proto ${DEVICE_PROTOCOL}/messages-binance.proto ${DEVICE_PROTOCOL}/messages-cosmos.proto + ${DEVICE_PROTOCOL}/messages-osmosis.proto ${DEVICE_PROTOCOL}/messages-ripple.proto ${DEVICE_PROTOCOL}/messages-tendermint.proto ${DEVICE_PROTOCOL}/messages-thorchain.proto - ${DEVICE_PROTOCOL}/messages-osmosis.proto ${DEVICE_PROTOCOL}/messages.proto) set(protoc_pb_options @@ -23,10 +23,10 @@ set(protoc_pb_options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-nano.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-binance.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-cosmos.options + ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-osmosis.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-ripple.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-tendermint.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-thorchain.options - ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-osmosis.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages.options) set(protoc_c_sources @@ -36,10 +36,10 @@ set(protoc_c_sources ${CMAKE_BINARY_DIR}/lib/transport/messages-nano.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-binance.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-cosmos.pb.c + ${CMAKE_BINARY_DIR}/lib/transport/messages-osmosis.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-ripple.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-tendermint.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-thorchain.pb.c - ${CMAKE_BINARY_DIR}/lib/transport/messages-osmosis.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages.pb.c) set(protoc_c_headers @@ -49,10 +49,10 @@ set(protoc_c_headers ${CMAKE_BINARY_DIR}/include/messages-nano.pb.h ${CMAKE_BINARY_DIR}/include/messages-binance.pb.h ${CMAKE_BINARY_DIR}/include/messages-cosmos.pb.h + ${CMAKE_BINARY_DIR}/include/messages-osmosis.pb.h ${CMAKE_BINARY_DIR}/include/messages-ripple.pb.h ${CMAKE_BINARY_DIR}/include/messages-tendermint.pb.h ${CMAKE_BINARY_DIR}/include/messages-thorchain.pb.h - ${CMAKE_BINARY_DIR}/include/messages-osmosis.pb.h ${CMAKE_BINARY_DIR}/include/messages.pb.h) set(protoc_pb_sources_moved @@ -62,10 +62,10 @@ set(protoc_pb_sources_moved ${CMAKE_BINARY_DIR}/lib/transport/messages-nano.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-binance.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-cosmos.proto + ${CMAKE_BINARY_DIR}/lib/transport/messages-osmosis.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-ripple.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-tendermint.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-thorchain.proto - ${CMAKE_BINARY_DIR}/lib/transport/messages-osmosis.proto ${CMAKE_BINARY_DIR}/lib/transport/messages.proto) add_custom_command( @@ -114,19 +114,19 @@ add_custom_command( COMMAND ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb - "--nanopb_out=-f messages-ripple.options:." messages-ripple.proto + "--nanopb_out=-f messages-osmosis.options:." messages-osmosis.proto COMMAND ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb - "--nanopb_out=-f messages-tendermint.options:." messages-tendermint.proto + "--nanopb_out=-f messages-ripple.options:." messages-ripple.proto COMMAND ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb - "--nanopb_out=-f messages-thorchain.options:." messages-thorchain.proto + "--nanopb_out=-f messages-tendermint.options:." messages-tendermint.proto COMMAND ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb - "--nanopb_out=-f messages-osmosis.options:." messages-osmosis.proto + "--nanopb_out=-f messages-thorchain.options:." messages-thorchain.proto COMMAND ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb From 28078b7d5423e8ed9d6677bef570537c6ca5ed61 Mon Sep 17 00:00:00 2001 From: pastaghost Date: Sun, 7 Aug 2022 18:37:00 -0600 Subject: [PATCH 05/23] fix: osmosis message type typo --- lib/firmware/messagemap.def | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/firmware/messagemap.def b/lib/firmware/messagemap.def index b5f26ebe2..4d68b43db 100644 --- a/lib/firmware/messagemap.def +++ b/lib/firmware/messagemap.def @@ -45,7 +45,7 @@ MSG_IN(MessageType_MessageType_CosmosSignTx, CosmosSignTx, fsm_msgCosmosSignTx) MSG_IN(MessageType_MessageType_CosmosMsgAck, CosmosMsgAck, fsm_msgCosmosMsgAck) - MSG_IN(MessageType_MessageType_CosmosGetAddress, OsmosisGetAddress, fsm_msgOsmosisGetAddress) + MSG_IN(MessageType_MessageType_OsmosisGetAddress, OsmosisGetAddress, fsm_msgOsmosisGetAddress) MSG_IN(MessageType_MessageType_OsmosisSignTx, OsmosisSignTx, fsm_msgOsmosisSignTx) MSG_IN(MessageType_MessageType_OsmosisMsgAck, OsmosisMsgAck, fsm_msgOsmosisMsgAck) From c381836c11b20911b00216c70780de9ae4925293 Mon Sep 17 00:00:00 2001 From: Pasta Ghost Date: Thu, 14 Oct 2021 21:56:13 -0600 Subject: [PATCH 06/23] Add initial Osmosis support --- deps/device-protocol | 2 +- deps/python-keepkey | 2 +- include/keepkey/firmware/coins.def | 1 + include/keepkey/firmware/fsm.h | 4 + include/keepkey/firmware/osmosis.h | 26 ++ include/keepkey/transport/interface.h | 1 + .../transport/messages-osmosis.options | 23 ++ lib/firmware/CMakeLists.txt | 1 + lib/firmware/fsm.c | 3 + lib/firmware/fsm_msg_osmosis.h | 277 ++++++++++++++++++ lib/firmware/messagemap.def | 9 + lib/firmware/osmosis.c | 251 ++++++++++++++++ lib/transport/CMakeLists.txt | 9 + 13 files changed, 607 insertions(+), 2 deletions(-) create mode 100644 include/keepkey/firmware/osmosis.h create mode 100644 include/keepkey/transport/messages-osmosis.options create mode 100644 lib/firmware/fsm_msg_osmosis.h create mode 100644 lib/firmware/osmosis.c diff --git a/deps/device-protocol b/deps/device-protocol index 817fc54d7..d9c2dd9fd 160000 --- a/deps/device-protocol +++ b/deps/device-protocol @@ -1 +1 @@ -Subproject commit 817fc54d7582d85b4519daf38f2f7c4070cb97ed +Subproject commit d9c2dd9fd6996d22615f1d1f6c1adbe9870d541f diff --git a/deps/python-keepkey b/deps/python-keepkey index 7bddc11d7..b697b08a2 160000 --- a/deps/python-keepkey +++ b/deps/python-keepkey @@ -1 +1 @@ -Subproject commit 7bddc11d7ee8208161d8b428ad5b6760dd450a98 +Subproject commit b697b08a29676c780f3fb16106d902efcbabbe5a diff --git a/include/keepkey/firmware/coins.def b/include/keepkey/firmware/coins.def index d86f4098d..6fb8b3db1 100644 --- a/include/keepkey/firmware/coins.def +++ b/include/keepkey/firmware/coins.def @@ -44,5 +44,6 @@ X(true, "THORChain", true, "RUNE", false, NA, false, NA, false, N X(true, "Terra", true, "LUNA", false, NA, false, NA, false, NA, false, {0}, true, 0x8000014a, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "terra", false, false, false, 0, false, 0, false, "" ) X(true, "Kava", true, "KAVA", false, NA, false, NA, false, NA, false, {0}, true, 0x800001cb, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "kava", false, false, false, 0, false, 0, false, "" ) X(true, "Secret", true, "SCRT", false, NA, false, NA, false, NA, false, {0}, true, 0x80000211, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "secret", false, false, false, 0, false, 0, false, "" ) +X(true, "Osmosis", true, "OSMO", false, NA, false, NA, false, NA, false, {0}, true, 0x80000076, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "osmo", false, false, false, 0, false, 0, false, "" ) #undef X #undef NO_CONTRACT diff --git a/include/keepkey/firmware/fsm.h b/include/keepkey/firmware/fsm.h index 9b09af194..a9f04c913 100644 --- a/include/keepkey/firmware/fsm.h +++ b/include/keepkey/firmware/fsm.h @@ -109,6 +109,10 @@ void fsm_msgThorchainGetAddress(const ThorchainGetAddress *msg); void fsm_msgThorchainSignTx(const ThorchainSignTx *msg); void fsm_msgThorchainMsgAck(const ThorchainMsgAck *msg); +void fsm_msgOsmosisGetAddress(const OsmosisGetAddress *msg); +void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg); +void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg); + #if DEBUG_LINK // void fsm_msgDebugLinkDecision(DebugLinkDecision *msg); void fsm_msgDebugLinkGetState(DebugLinkGetState *msg); diff --git a/include/keepkey/firmware/osmosis.h b/include/keepkey/firmware/osmosis.h new file mode 100644 index 000000000..bac96d26e --- /dev/null +++ b/include/keepkey/firmware/osmosis.h @@ -0,0 +1,26 @@ +#ifndef KEEPKEY_FIRMWARE_OSMOSIS_H +#define KEEPKEY_FIRMWARE_OSMOSIS_H + +#include "messages.pb.h" +#include "trezor/crypto/bip32.h" + +#include +#include + +typedef struct _OsmosisSignTx OsmosisSignTx; +typedef struct _OsmosisMsgDelegate OsmosisMsgDelegate; +typedef struct _OsmosisMsgUndelegate OsmosisMsgUndelegate; +typedef struct _OsmosisMsgClaim OsmosisMsgClaim; + +bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg); +bool osmosis_signTxUpdateMsgSend(const uint64_t amount, const char *to_address); +bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg); +bool osmosis_signTxUpdateMsgUndelegate(const OsmosisMsgUndelegate *undelegatemsg); +bool osmosis_signTxUpdateMsgClaim(const OsmosisMsgClaim *claimmsg); +bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature); +bool osmosis_signingIsInited(void); +bool osmosis_signingIsFinished(void); +void osmosis_signAbort(void); +const OsmosisSignTx *osmosis_getOsmosisSignTx(void); + +#endif diff --git a/include/keepkey/transport/interface.h b/include/keepkey/transport/interface.h index d87b5a1fa..d0c166174 100644 --- a/include/keepkey/transport/interface.h +++ b/include/keepkey/transport/interface.h @@ -33,6 +33,7 @@ #include "messages-ripple.pb.h" #include "messages-tendermint.pb.h" #include "messages-thorchain.pb.h" +#include "messages-osmosis.pb.h" #include "types.pb.h" #include "trezor_transport.h" diff --git a/include/keepkey/transport/messages-osmosis.options b/include/keepkey/transport/messages-osmosis.options new file mode 100644 index 000000000..69d0246de --- /dev/null +++ b/include/keepkey/transport/messages-osmosis.options @@ -0,0 +1,23 @@ +OsmosisGetAddress.address_n max_count:10 + +OsmosisAddress.address max_size:46 + +OsmosisSignTx.address_n max_count:10 +OsmosisSignTx.chain_id max_size:32 +OsmosisSignTx.memo max_size:256 + +OsmosisMsgSend.from_address max_size:46 +OsmosisMsgSend.to_address max_size:46 + +OsmosisMsgDelegate.delegator_address max_size:46 +OsmosisMsgDelegate.validator_address max_size:53 + +OsmosisMsgUndelegate.delegator_address max_size:46 +OsmosisMsgUndelegate.validator_address max_size:53 + +OsmosisMsgClaim.delegator_address max_size:46 +OsmosisMsgClaim.validator_address max_size:53 + + +OsmosisSignedTx.public_key max_size:33 +OsmosisSignedTx.signature max_size:64 diff --git a/lib/firmware/CMakeLists.txt b/lib/firmware/CMakeLists.txt index 00581ab48..500905569 100644 --- a/lib/firmware/CMakeLists.txt +++ b/lib/firmware/CMakeLists.txt @@ -20,6 +20,7 @@ set(sources fsm.c home_sm.c nano.c + osmosis.c passphrase_sm.c pin_sm.c policy.c diff --git a/lib/firmware/fsm.c b/lib/firmware/fsm.c index 1f90b517c..01b4d62cc 100644 --- a/lib/firmware/fsm.c +++ b/lib/firmware/fsm.c @@ -44,6 +44,7 @@ #include "keepkey/firmware/ethereum_tokens.h" #include "keepkey/firmware/fsm.h" #include "keepkey/firmware/home_sm.h" +#include "keepkey/firmware/osmosis.h" #include "keepkey/firmware/passphrase_sm.h" #include "keepkey/firmware/pin_sm.h" #include "keepkey/firmware/policy.h" @@ -79,6 +80,7 @@ #include "messages-nano.pb.h" #include "messages-ripple.pb.h" #include "messages-thorchain.pb.h" +#include "messages-osmosis.pb.h" #include @@ -278,3 +280,4 @@ void fsm_msgClearSession(ClearSession *msg) { #include "fsm_msg_ripple.h" #include "fsm_msg_tendermint.h" #include "fsm_msg_thorchain.h" +#include "fsm_msg_osmosis.h" diff --git a/lib/firmware/fsm_msg_osmosis.h b/lib/firmware/fsm_msg_osmosis.h new file mode 100644 index 000000000..aa32c5216 --- /dev/null +++ b/lib/firmware/fsm_msg_osmosis.h @@ -0,0 +1,277 @@ + +void fsm_msgOsmosisGetAddress(const OsmosisGetAddress *msg) { + RESP_INIT(OsmosisAddress); + + CHECK_INITIALIZED + + CHECK_PIN + + const CoinType *coin = fsm_getCoin(true, "Osmosis"); + if (!coin) { + return; + } + HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, + msg->address_n_count, NULL); + char mainnet[] = "osmo"; + char testnet[] = "tosmo"; + char *pfix; + + if (!node) { + return; + } + + hdnode_fill_public_key(node); + + pfix = mainnet; + if (msg->has_testnet && msg->testnet) { + pfix = testnet; + } + + if (!tendermint_getAddress(node, pfix, resp->address)) { + memzero(node, sizeof(*node)); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Can't encode address")); + layoutHome(); + return; + } + + if (msg->has_show_display && msg->show_display) { + char node_str[NODE_STRING_LENGTH]; + if (!bip32_node_to_string(node_str, sizeof(node_str), coin, msg->address_n, + msg->address_n_count, /*whole_account=*/false, + /*show_addridx=*/false) && + !bip32_path_to_string(node_str, sizeof(node_str), msg->address_n, + msg->address_n_count)) { + memset(node_str, 0, sizeof(node_str)); + memzero(node, sizeof(*node)); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Can't create Bip32 Path String")); + layoutHome(); + } + + bool mismatch = + tendermint_pathMismatched(coin, msg->address_n, msg->address_n_count); + if (mismatch) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "WARNING", + "Wrong address path for selected coin. Continue at your own " + "risk!")) { + memzero(node, sizeof(*node)); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + } + + if (!confirm_ethereum_address(node_str, resp->address)) { + memzero(node, sizeof(*node)); + fsm_sendFailure(FailureType_Failure_ActionCancelled, + "Show address cancelled"); + layoutHome(); + return; + } + } + + resp->has_address = true; + + memzero(node, sizeof(*node)); + msg_write(MessageType_MessageType_OsmosisAddress, resp); + layoutHome(); +} + +void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg) { + CHECK_INITIALIZED + CHECK_PIN + + if (!msg->has_account_number || !msg->has_chain_id || !msg->has_fee_amount || + !msg->has_gas || !msg->has_sequence) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Missing Fields On Message"); + layoutHome(); + return; + } + + HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, + msg->address_n_count, NULL); + if (!node) { + return; + } + + hdnode_fill_public_key(node); + + RESP_INIT(OsmosisMsgRequest); + + if (!osmosis_signTxInit(node, msg)) { + osmosis_signAbort(); + memzero(node, sizeof(*node)); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Failed to initialize transaction signing")); + layoutHome(); + return; + } + + memzero(node, sizeof(*node)); + msg_write(MessageType_MessageType_OsmosisMsgRequest, resp); + layoutHome(); +} + +void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { + // Confirm transaction basics + // supports only 1 message ack + CHECK_PARAM(osmosis_signingIsInited(), "Signing not in progress"); + if (msg->has_send && msg->send.has_to_address && msg->send.has_amount) { + // pass + } else if (msg->has_delegate && msg->delegate.has_delegator_address && + msg->delegate.has_validator_address && msg->delegate.has_amount) { + // pass + } else if (msg->has_undelegate && msg->undelegate.has_delegator_address && + msg->undelegate.has_validator_address && + msg->undelegate.has_amount) { + // pass + } else if (msg->has_claim && msg->claim.has_delegator_address && + msg->claim.has_validator_address && msg->claim.has_amount) { + // pass + } else { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Invalid Osmosis Message Type")); + layoutHome(); + return; + } + + const CoinType *coin = fsm_getCoin(true, "Osmosis"); + if (!coin) { + return; + } + + const OsmosisSignTx *sign_tx = osmosis_getOsmosisSignTx(); + + if (msg->has_send) { + switch (msg->send.address_type) { + case OutputAddressType_TRANSFER: + default: { + char amount_str[32]; + bn_format_uint64(msg->send.amount, NULL, " OSMO", 8, 0, false, + amount_str, sizeof(amount_str)); + if (!confirm_transaction_output( + ButtonRequestType_ButtonRequest_ConfirmOutput, amount_str, + msg->send.to_address)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + break; + } + } + if (!osmosis_signTxUpdateMsgSend(msg->send.amount, + msg->send.to_address)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include send message in transaction"); + layoutHome(); + return; + } + + } else if (msg->has_delegate) { + char amount_str[32]; + bn_format_uint64(msg->delegate.amount, NULL, " OSMO", 8, 0, false, + amount_str, sizeof(amount_str)); + + if(!confirm_with_custom_layout( + &layout_standard_notification, + ButtonRequestType_ButtonRequest_SignExchange, "Delegate", + "Delegate %s to %s?", amount_str, msg->delegate.validator_address)){ + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgDelegate(&(msg->delegate))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include delegate message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_undelegate) { + char amount_str[32]; + bn_format_uint64(msg->undelegate.amount, NULL, " OSMO", 8, 0, false, + amount_str, sizeof(amount_str)); + + if(!confirm_with_custom_layout( + &layout_standard_notification, + ButtonRequestType_ButtonRequest_SignExchange, "Undelegate", + "Undelegate %s from %s?", amount_str, msg->undelegate.validator_address)){ + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgUndelegate(&(msg->undelegate))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include undelegate message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_claim) { + char amount_str[32]; + bn_format_uint64(msg->claim.amount, NULL, " OSMO", 8, 0, false, amount_str, + sizeof(amount_str)); + if(!confirm_with_custom_layout( + &layout_standard_notification, + ButtonRequestType_ButtonRequest_SignExchange, "Claim", + "Claim %s from %s?", amount_str, msg->claim.validator_address)){ + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgClaim(&(msg->claim))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include claim message in transaction"); + layoutHome(); + return; + } + } + + if (!osmosis_signingIsFinished()) { + RESP_INIT(OsmosisMsgRequest); + msg_write(MessageType_MessageType_OsmosisMsgRequest, resp); + return; + } + + char node_str[NODE_STRING_LENGTH]; + if (!bip32_node_to_string(node_str, sizeof(node_str), coin, + sign_tx->address_n, sign_tx->address_n_count, + /*whole_account=*/false, + /*show_addridx=*/false) && + !bip32_path_to_string(node_str, sizeof(node_str), sign_tx->address_n, + sign_tx->address_n_count)) { + memset(node_str, 0, sizeof(node_str)); + } + + RESP_INIT(OsmosisSignedTx); + + if (!osmosis_signTxFinalize(resp->public_key.bytes, resp->signature.bytes)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to finalize signature"); + layoutHome(); + return; + } + + resp->public_key.size = 33; + resp->has_public_key = true; + resp->signature.size = 64; + resp->has_signature = true; + osmosis_signAbort(); + layoutHome(); + msg_write(MessageType_MessageType_OsmosisSignedTx, resp); +} \ No newline at end of file diff --git a/lib/firmware/messagemap.def b/lib/firmware/messagemap.def index 6e88170bc..b21f982be 100644 --- a/lib/firmware/messagemap.def +++ b/lib/firmware/messagemap.def @@ -63,6 +63,11 @@ MSG_IN(MessageType_MessageType_ThorchainSignTx, ThorchainSignTx, fsm_msgThorchainSignTx) MSG_IN(MessageType_MessageType_ThorchainMsgAck, ThorchainMsgAck, fsm_msgThorchainMsgAck) + MSG_IN(MessageType_MessageType_OsmosisGetAddress, OsmosisGetAddress, fsm_msgOsmosisGetAddress) + MSG_IN(MessageType_MessageType_OsmosisSignTx, OsmosisSignTx, fsm_msgOsmosisSignTx) + MSG_IN(MessageType_MessageType_OsmosisMsgAck, OsmosisMsgAck, fsm_msgOsmosisMsgAck) + + /* Normal Out Messages */ MSG_OUT(MessageType_MessageType_Success, Success, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_Failure, Failure, NO_PROCESS_FUNC) @@ -114,6 +119,10 @@ MSG_OUT(MessageType_MessageType_ThorchainMsgRequest, ThorchainMsgRequest, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_ThorchainSignedTx, ThorchainSignedTx, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_OsmosisAddress, OsmosisAddress, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_OsmosisMsgRequest, OsmosisMsgRequest, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_OsmosisSignedTx, OsmosisSignedTx, NO_PROCESS_FUNC) + #if DEBUG_LINK /* Debug Messages */ DEBUG_IN(MessageType_MessageType_DebugLinkDecision, DebugLinkDecision, NO_PROCESS_FUNC) diff --git a/lib/firmware/osmosis.c b/lib/firmware/osmosis.c new file mode 100644 index 000000000..1379696d9 --- /dev/null +++ b/lib/firmware/osmosis.c @@ -0,0 +1,251 @@ +/* + * This file is part of the Keepkey project. + * + * Copyright (C) 2021 Shapeshift + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +#include "keepkey/firmware/osmosis.h" +#include "keepkey/board/confirm_sm.h" +#include "keepkey/board/util.h" +#include "keepkey/firmware/home_sm.h" +#include "keepkey/firmware/storage.h" +#include "keepkey/firmware/tendermint.h" +#include "trezor/crypto/secp256k1.h" +#include "trezor/crypto/ecdsa.h" +#include "trezor/crypto/memzero.h" +#include "trezor/crypto/segwit_addr.h" + +#include +#include + +static CONFIDENTIAL HDNode node; +static SHA256_CTX ctx; +static bool initialized; +static uint32_t msgs_remaining; +static OsmosisSignTx msg; +static bool testnet; + +const OsmosisSignTx *osmosis_getOsmosisSignTx(void) { return &msg; } + +bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg) { + initialized = true; + msgs_remaining = _msg->msg_count; + testnet = false; + + if (_msg->has_testnet) { + testnet = _msg->testnet; + } + + memzero(&node, sizeof(node)); + memcpy(&node, _node, sizeof(node)); + memcpy(&msg, _msg, sizeof(msg)); + + bool success = true; + char buffer[64 + 1]; + + sha256_Init(&ctx); + + // Each segment guaranteed to be less than or equal to 64 bytes + // 19 + ^20 + 1 = ^40 + if (!tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "{\"account_number\":\"%" PRIu64 "\"", + msg.account_number)) + return false; + + // + const char *const chainid_prefix = ",\"chain_id\":\""; + sha256_Update(&ctx, (uint8_t *)chainid_prefix, strlen(chainid_prefix)); + tendermint_sha256UpdateEscaped(&ctx, msg.chain_id, strlen(msg.chain_id)); + + // 30 + ^10 + 19 = ^59 + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\",\"fee\":{\"amount\":[{\"amount\":\"%" PRIu32 + "\",\"denom\":\"rune\"}]", + msg.fee_amount); + + // 8 + ^10 + 2 = ^20 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"gas\":\"%" PRIu32 "\"}", msg.gas); + + // + const char *const memo_prefix = ",\"memo\":\""; + sha256_Update(&ctx, (uint8_t *)memo_prefix, strlen(memo_prefix)); + if (msg.has_memo) { + tendermint_sha256UpdateEscaped(&ctx, msg.memo, strlen(msg.memo)); + } + + // 10 + sha256_Update(&ctx, (uint8_t *)"\",\"msgs\":[", 10); + + return success; +} + +bool osmosis_signTxUpdateMsgSend(const uint64_t amount, + const char *to_address) { + char mainnetp[] = "osmo"; + char testnetp[] = "tosmo"; + char *pfix; + char buffer[64 + 1]; + + size_t decoded_len; + char hrp[45]; + uint8_t decoded[38]; + if (!bech32_decode(hrp, decoded, &decoded_len, to_address)) { + return false; + } + + char from_address[46]; + + pfix = mainnetp; + if (testnet) { + pfix = testnetp; + } + + if (!tendermint_getAddress(&node, pfix, from_address)) { + return false; + } + + bool success = true; + + const char *const prelude = "{\"type\":\"cosmos-sdk/MsgSend\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + // 21 + ^20 + 19 = ^60 + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":[{\"amount\":\"%" PRIu64 "\",\"denom\":\"uosmo\"}]", amount); + + // 17 + 45 + 1 = 63 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"from_address\":\"%s\"", from_address); + + // 15 + 45 + 3 = 63 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"to_address\":\"%s\"}}", to_address); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"cosmos-sdk/MsgDelegate\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"delegator_address\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + delegatemsg->delegator_address); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + delegatemsg->validator_address); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"uosmo\",\"amount\":\"%" PRIu64 "\"}}}", + delegatemsg->amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgUndelegate( + const OsmosisMsgUndelegate *undelegatemsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"cosmos-sdk/MsgUndelegate\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"delegator_address\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + undelegatemsg->delegator_address); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + undelegatemsg->validator_address); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"uosmo\",\"amount\":\"%" PRIu64 "\"}}}", + undelegatemsg->amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgClaim(const OsmosisMsgClaim *claimmsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = "{\"type\":\"cosmos-sdk/MsgClaim\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"delegator_address\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + claimmsg->delegator_address); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + claimmsg->validator_address); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"uosmo\",\"amount\":\"%" PRIu64 "\"}}}", + claimmsg->amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature) { + char buffer[64 + 1]; + + // 16 + ^20 = ^36 + if (!tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "],\"sequence\":\"%" PRIu64 "\"}", msg.sequence)) + return false; + + hdnode_fill_public_key(&node); + memcpy(public_key, node.public_key, 33); + + uint8_t hash[SHA256_DIGEST_LENGTH]; + sha256_Final(&ctx, hash); + return ecdsa_sign_digest(&secp256k1, node.private_key, hash, signature, NULL, + NULL) == 0; +} + +bool osmosis_signingIsInited(void) { return initialized; } + +bool osmosis_signingIsFinished(void) { return msgs_remaining == 0; } + +void osmosis_signAbort(void) { + initialized = false; + msgs_remaining = 0; + memzero(&msg, sizeof(msg)); + memzero(&node, sizeof(node)); +} diff --git a/lib/transport/CMakeLists.txt b/lib/transport/CMakeLists.txt index f611e03bc..7a9d65986 100644 --- a/lib/transport/CMakeLists.txt +++ b/lib/transport/CMakeLists.txt @@ -13,6 +13,7 @@ set(protoc_pb_sources ${DEVICE_PROTOCOL}/messages-ripple.proto ${DEVICE_PROTOCOL}/messages-tendermint.proto ${DEVICE_PROTOCOL}/messages-thorchain.proto + ${DEVICE_PROTOCOL}/messages-osmosis.proto ${DEVICE_PROTOCOL}/messages.proto) set(protoc_pb_options @@ -25,6 +26,7 @@ set(protoc_pb_options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-ripple.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-tendermint.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-thorchain.options + ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-osmosis.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages.options) set(protoc_c_sources @@ -37,6 +39,7 @@ set(protoc_c_sources ${CMAKE_BINARY_DIR}/lib/transport/messages-ripple.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-tendermint.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-thorchain.pb.c + ${CMAKE_BINARY_DIR}/lib/transport/messages-osmosis.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages.pb.c) set(protoc_c_headers @@ -49,6 +52,7 @@ set(protoc_c_headers ${CMAKE_BINARY_DIR}/include/messages-ripple.pb.h ${CMAKE_BINARY_DIR}/include/messages-tendermint.pb.h ${CMAKE_BINARY_DIR}/include/messages-thorchain.pb.h + ${CMAKE_BINARY_DIR}/include/messages-osmosis.pb.h ${CMAKE_BINARY_DIR}/include/messages.pb.h) set(protoc_pb_sources_moved @@ -61,6 +65,7 @@ set(protoc_pb_sources_moved ${CMAKE_BINARY_DIR}/lib/transport/messages-ripple.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-tendermint.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-thorchain.proto + ${CMAKE_BINARY_DIR}/lib/transport/messages-osmosis.proto ${CMAKE_BINARY_DIR}/lib/transport/messages.proto) add_custom_command( @@ -118,6 +123,10 @@ add_custom_command( ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb "--nanopb_out=-f messages-thorchain.options:." messages-thorchain.proto + COMMAND + ${PROTOC_BINARY} -I. -I/usr/include + --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb + "--nanopb_out=-f messages-osmosis.options:." messages-osmosis.proto COMMAND ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb From 6ff964a3f082192a8927c5803a3d54985af3d945 Mon Sep 17 00:00:00 2001 From: mcchadwick Date: Tue, 16 Nov 2021 00:43:32 -0700 Subject: [PATCH 07/23] WIP: Add Osmosis support --- include/keepkey/firmware/osmosis.h | 12 + .../transport/messages-osmosis.options | 24 ++ lib/firmware/fsm_msg_osmosis.h | 357 ++++++++++++++++-- lib/firmware/osmosis.c | 262 ++++++++++++- 4 files changed, 607 insertions(+), 48 deletions(-) diff --git a/include/keepkey/firmware/osmosis.h b/include/keepkey/firmware/osmosis.h index bac96d26e..ebf9ff6cb 100644 --- a/include/keepkey/firmware/osmosis.h +++ b/include/keepkey/firmware/osmosis.h @@ -11,12 +11,24 @@ typedef struct _OsmosisSignTx OsmosisSignTx; typedef struct _OsmosisMsgDelegate OsmosisMsgDelegate; typedef struct _OsmosisMsgUndelegate OsmosisMsgUndelegate; typedef struct _OsmosisMsgClaim OsmosisMsgClaim; +typedef struct _OsmosisMsgLPAdd OsmosisMsgLPAdd; +typedef struct _OsmosisMsgLPRemove OsmosisMsgLPRemove; +typedef struct _OsmosisMsgFarmTokens OsmosisMsgFarmTokens; +typedef struct _OsmosisMsgIBCDeposit OsmosisMsgIBCDeposit; +typedef struct _OsmosisMsgIBCWithdrawal OsmosisMsgIBCWithdrawal; +typedef struct _OsmosisMsgSwap OsmosisMsgSwap; bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg); bool osmosis_signTxUpdateMsgSend(const uint64_t amount, const char *to_address); bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg); bool osmosis_signTxUpdateMsgUndelegate(const OsmosisMsgUndelegate *undelegatemsg); +bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg); +bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove *lpremovemsg); +bool osmosis_signTxUpdateMsgFarmTokens(const OsmosisMsgFarmTokens *msgfarmtokens); +bool osmosis_signTxUpdateMsgIBCDeposit(const OsmosisMsgIBCDeposit *ibcdepositmsg); +bool osmosis_signTxUpdateMsgIBCWithdrawal(const OsmosisMsgIBCWithdrawal *ibcwithdrawalmsg); bool osmosis_signTxUpdateMsgClaim(const OsmosisMsgClaim *claimmsg); +bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap *swapmsg); bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature); bool osmosis_signingIsInited(void); bool osmosis_signingIsFinished(void); diff --git a/include/keepkey/transport/messages-osmosis.options b/include/keepkey/transport/messages-osmosis.options index 69d0246de..b9a3e549f 100644 --- a/include/keepkey/transport/messages-osmosis.options +++ b/include/keepkey/transport/messages-osmosis.options @@ -18,6 +18,30 @@ OsmosisMsgUndelegate.validator_address max_size:53 OsmosisMsgClaim.delegator_address max_size:46 OsmosisMsgClaim.validator_address max_size:53 +OsmosisMsgLPAdd.sender max_size:46 +OsmosisMsgLPAdd.pool_id max_size:16 + +OsmosisMsgLPRemove.sender max_size:46 +OsmosisMsgLPRemove.pool_id max_size:16 + +OsmosisMsgFarmTokens.owner max_size:46 + +OsmosisMsgIBCDeposit.source_port max_size:16 +OsmosisMsgIBCDeposit.source_channel max_size:16 +OsmosisMsgIBCDeposit.sender max_size:46 +OsmosisMsgIBCDeposit.receiver max_size:46 + +OsmosisMsgIBCWithdrawal.source_port max_size:16 +OsmosisMsgIBCWithdrawal.source_channel max_size:16 +OsmosisMsgIBCWithdrawal.sender max_size:46 +OsmosisMsgIBCWithdrawal.receiver max_size:46 + +OsmosisMsgSwap.sender max_size:46 +OsmosisMsgSwap.pool_id max_size:16 +OsmosisMsgSwap.token_out_denom max_size:8 OsmosisSignedTx.public_key max_size:33 OsmosisSignedTx.signature max_size:64 + +OsmosisToken.denom max_size:72 + diff --git a/lib/firmware/fsm_msg_osmosis.h b/lib/firmware/fsm_msg_osmosis.h index aa32c5216..1b8d9514d 100644 --- a/lib/firmware/fsm_msg_osmosis.h +++ b/lib/firmware/fsm_msg_osmosis.h @@ -119,17 +119,47 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { // Confirm transaction basics // supports only 1 message ack CHECK_PARAM(osmosis_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_token && + msg->send.token.has_amount) { // pass } else if (msg->has_delegate && msg->delegate.has_delegator_address && - msg->delegate.has_validator_address && msg->delegate.has_amount) { + msg->delegate.has_validator_address && msg->delegate.has_token) { // pass } else if (msg->has_undelegate && msg->undelegate.has_delegator_address && msg->undelegate.has_validator_address && - msg->undelegate.has_amount) { + msg->undelegate.has_token) { // pass } else if (msg->has_claim && msg->claim.has_delegator_address && - msg->claim.has_validator_address && msg->claim.has_amount) { + msg->claim.has_validator_address && msg->claim.has_token) { + // pass + } else if (msg->has_lp_add && msg->lp_add.has_sender && + msg->lp_add.has_pool_id && msg->lp_add.has_share_out_amount && + msg->lp_add.has_token_in_max_a && msg->lp_add.has_token_in_max_b) { + // pass + } else if (msg->has_lp_remove && msg->lp_remove.has_sender && + msg->lp_remove.has_pool_id && + msg->lp_remove.has_share_out_amount && + msg->lp_remove.has_token_out_min_a && + msg->lp_remove.has_token_out_min_b) { + // pass + } else if (msg->has_farm_tokens && msg->farm_tokens.has_owner && + msg->farm_tokens.has_duration && msg->farm_tokens.has_token) { + // pass + } else if (msg->has_ibc_deposit && msg->ibc_deposit.has_source_port && + msg->ibc_deposit.has_source_channel && + msg->ibc_deposit.has_token && msg->ibc_deposit.has_sender && + msg->ibc_deposit.has_receiver && + msg->ibc_deposit.has_timeout_height) { + // pass + } else if (msg->has_ibc_withdrawal && msg->ibc_withdrawal.has_source_port && + msg->ibc_withdrawal.has_source_channel && + msg->ibc_withdrawal.has_token && msg->ibc_withdrawal.has_sender && + msg->ibc_withdrawal.has_receiver && + msg->ibc_withdrawal.has_timeout_height) { + // pass + } else if (msg->has_swap && msg->swap.has_sender && msg->swap.has_pool_id && + msg->swap.has_token_out_denom && msg->swap.has_token_in && + msg->swap.has_token_out_min_amount) { // pass } else { osmosis_signAbort(); @@ -151,11 +181,10 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { case OutputAddressType_TRANSFER: default: { char amount_str[32]; - bn_format_uint64(msg->send.amount, NULL, " OSMO", 8, 0, false, + bn_format_uint64(msg->send.token.amount, NULL, " OSMO", 8, 0, false, amount_str, sizeof(amount_str)); - if (!confirm_transaction_output( - ButtonRequestType_ButtonRequest_ConfirmOutput, amount_str, - msg->send.to_address)) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Transfer", + "Send %s to %s?", amount_str, msg->send.to_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); @@ -165,8 +194,8 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { break; } } - if (!osmosis_signTxUpdateMsgSend(msg->send.amount, - msg->send.to_address)) { + if (!osmosis_signTxUpdateMsgSend(msg->send.token.amount, + msg->send.to_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include send message in transaction"); @@ -176,18 +205,17 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } else if (msg->has_delegate) { char amount_str[32]; - bn_format_uint64(msg->delegate.amount, NULL, " OSMO", 8, 0, false, + bn_format_uint64(msg->delegate.token.amount, NULL, " OSMO", 8, 0, false, amount_str, sizeof(amount_str)); - if(!confirm_with_custom_layout( - &layout_standard_notification, - ButtonRequestType_ButtonRequest_SignExchange, "Delegate", - "Delegate %s to %s?", amount_str, msg->delegate.validator_address)){ - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Delegate", + "Delegate %s to %s?", amount_str, + msg->delegate.validator_address)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } if (!osmosis_signTxUpdateMsgDelegate(&(msg->delegate))) { osmosis_signAbort(); @@ -198,18 +226,17 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } } else if (msg->has_undelegate) { char amount_str[32]; - bn_format_uint64(msg->undelegate.amount, NULL, " OSMO", 8, 0, false, + bn_format_uint64(msg->undelegate.token.amount, NULL, " OSMO", 8, 0, false, amount_str, sizeof(amount_str)); - if(!confirm_with_custom_layout( - &layout_standard_notification, - ButtonRequestType_ButtonRequest_SignExchange, "Undelegate", - "Undelegate %s from %s?", amount_str, msg->undelegate.validator_address)){ - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Undelegate", + "Undelegate %s from %s?", amount_str, + msg->undelegate.validator_address)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } if (!osmosis_signTxUpdateMsgUndelegate(&(msg->undelegate))) { osmosis_signAbort(); @@ -220,17 +247,16 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } } else if (msg->has_claim) { char amount_str[32]; - bn_format_uint64(msg->claim.amount, NULL, " OSMO", 8, 0, false, amount_str, - sizeof(amount_str)); - if(!confirm_with_custom_layout( - &layout_standard_notification, - ButtonRequestType_ButtonRequest_SignExchange, "Claim", - "Claim %s from %s?", amount_str, msg->claim.validator_address)){ - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } + bn_format_uint64(msg->claim.token.amount, NULL, " OSMO", 8, 0, false, + amount_str, sizeof(amount_str)); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim", + "Claim %s from %s?", amount_str, + msg->claim.validator_address)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } if (!osmosis_signTxUpdateMsgClaim(&(msg->claim))) { osmosis_signAbort(); @@ -239,6 +265,255 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { layoutHome(); return; } + } else if (msg->has_lp_add) { + char amount_a_str[32]; + char amount_b_str[32]; + const char *denom_a_str = + strcmp(msg->lp_add.token_in_max_a.denom, "uosmo") == 0 + ? "OSMO" + : msg->lp_add.token_in_max_a.denom; + const char *denom_b_str = + strcmp(msg->lp_add.token_in_max_b.denom, "uosmo") == 0 + ? "OSMO" + : msg->lp_add.token_in_max_b.denom; + + bn_format_uint64(msg->lp_add.token_in_max_a.amount, NULL, NULL, 8, 0, false, + amount_a_str, sizeof(amount_a_str)); + + bn_format_uint64(msg->lp_add.token_in_max_b.amount, NULL, NULL, 8, 0, false, + amount_b_str, sizeof(amount_b_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", + "Confirm Token A:\nAmount: %s\nDenom: %s", amount_a_str, + denom_a_str)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", + "Confirm Token B:\nAmount: %s\nDenom: %s", amount_b_str, + denom_b_str)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", + "Confirm Pool ID: %s", msg->lp_add.pool_id)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgLPAdd(&(msg->lp_add))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include LP Add message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_lp_remove) { + char amount_a_str[32]; + char amount_b_str[32]; + const char *denom_a_str = + strcmp(msg->lp_remove.token_out_min_a.denom, "uosmo") == 0 + ? "OSMO" + : msg->lp_remove.token_out_min_a.denom; + const char *denom_b_str = + strcmp(msg->lp_remove.token_out_min_b.denom, "uosmo") == 0 + ? "OSMO" + : msg->lp_remove.token_out_min_b.denom; + + bn_format_uint64(msg->lp_remove.token_out_min_a.amount, NULL, NULL, 8, 0, + false, amount_a_str, sizeof(amount_a_str)); + + bn_format_uint64(msg->lp_remove.token_out_min_b.amount, NULL, NULL, 8, 0, + false, amount_b_str, sizeof(amount_b_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", + "Confirm Token A:\nAmount: %s\nDenom: %s", amount_a_str, + denom_a_str)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", + "Confirm Token B:\nAmount: %s\nDenom: %s", amount_b_str, + denom_b_str)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", + "Confirm Pool ID: %s", msg->lp_remove.pool_id)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgLPRemove(&(msg->lp_remove))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include LP Remove message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_farm_tokens) { + char amount_str[32]; + bn_format_uint64(msg->farm_tokens.token.amount, NULL, " OSMO", 8, 0, false, + amount_str, sizeof(amount_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Farm Tokens", + "Lock %s in %s?", amount_str, msg->farm_tokens.token.denom)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Owner", "%s", + msg->farm_tokens.owner)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Duration", + "%lld", msg->farm_tokens.duration)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgFarmTokens(&(msg->farm_tokens))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include Farm Tokens message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_ibc_deposit) { + char amount_str[32]; + bn_format_uint64(msg->ibc_deposit.token.amount, NULL, " OSMO", 8, 0, false, + amount_str, sizeof(amount_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Deposit", + "Send %s on %s to %s?", amount_str, + msg->ibc_deposit.source_port, + msg->ibc_deposit.source_channel)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Sender Address", "%s", msg->ibc_deposit.sender)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Receiver Address", "%s", msg->ibc_deposit.receiver)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgIBCDeposit(&(msg->ibc_deposit))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include IBC Deposit message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_ibc_withdrawal) { + char amount_str[32]; + bn_format_uint64(msg->ibc_withdrawal.token.amount, NULL, " OSMO", 8, 0, + false, amount_str, sizeof(amount_str)); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Withdrawal", + "Receive %s on %s from %s?", amount_str, + msg->ibc_withdrawal.source_port, + msg->ibc_withdrawal.source_channel)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Sender Address", "%s", msg->ibc_withdrawal.sender)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Receiver Address", "%s", + msg->ibc_withdrawal.receiver)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgIBCWithdrawal(&(msg->ibc_withdrawal))) { + osmosis_signAbort(); + fsm_sendFailure( + FailureType_Failure_SyntaxError, + "Failed to include IBC Withdrawal message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_swap) { + char amount_in_str[32] = {' '}; + char amount_out_str[32] = {' '}; + bn_format_uint64(msg->swap.token_in.amount, NULL, msg->swap.token_in.denom, + 8, 0, false, amount_in_str + (1 * sizeof(char)), + sizeof(amount_in_str)); + bn_format_uint64( + msg->swap.token_out_min_amount, NULL, msg->swap.token_out_denom, 8, 0, + false, amount_out_str + (1 * sizeof(char)), sizeof(amount_out_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Swap", + "Swap %s for at least %lld?", amount_in_str, + msg->swap.token_out_min_amount)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Pool ID", "%s", + msg->swap.pool_id)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgSwap(&(msg->swap))) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include Swap message in transaction"); + layoutHome(); + return; + } } if (!osmosis_signingIsFinished()) { diff --git a/lib/firmware/osmosis.c b/lib/firmware/osmosis.c index 1379696d9..e25ea0220 100644 --- a/lib/firmware/osmosis.c +++ b/lib/firmware/osmosis.c @@ -156,13 +156,16 @@ bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", delegatemsg->delegator_address); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"validator_address\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", delegatemsg->validator_address); success &= tendermint_snprintf( &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"uosmo\",\"amount\":\"%" PRIu64 "\"}}}", - delegatemsg->amount); + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}}}", + delegatemsg->token.denom, delegatemsg->token.amount); msgs_remaining--; return success; @@ -184,24 +187,236 @@ bool osmosis_signTxUpdateMsgUndelegate( success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", undelegatemsg->delegator_address); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"validator_address\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", undelegatemsg->validator_address); success &= tendermint_snprintf( &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"uosmo\",\"amount\":\"%" PRIu64 "\"}}}", - undelegatemsg->amount); + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}}}", + undelegatemsg->token.denom, undelegatemsg->token.amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"osmosis/gamm/join-pool\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + lpaddmsg->sender); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + lpaddmsg->pool_id); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"shareOutAmount\":"); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", + lpaddmsg->share_out_amount); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenInMaxs\":[{"); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"},", + lpaddmsg->token_in_max_a.denom, lpaddmsg->token_in_max_a.amount); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", + lpaddmsg->token_in_max_b.denom, lpaddmsg->token_in_max_b.amount); msgs_remaining--; return success; } +bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove *lpremovemsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"osmosis/gamm/exit-pool\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + lpremovemsg->sender); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + lpremovemsg->pool_id); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"shareOutAmount\":"); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", + lpremovemsg->share_out_amount); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenInMaxs\":[{"); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"},", + lpremovemsg->token_out_min_a.denom, lpremovemsg->token_out_min_a.amount); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", + lpremovemsg->token_out_min_b.denom, lpremovemsg->token_out_min_b.amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgFarmTokens( + const OsmosisMsgFarmTokens *msgfarmtokens) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"osmosis/lockup/lock-tokens\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"owner\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + msgfarmtokens->owner); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"duration\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"%" PRIu64 "\",", msgfarmtokens->duration); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"coins\":[{"); + + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", + msgfarmtokens->token.denom, msgfarmtokens->token.amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgIBCDeposit( + const OsmosisMsgIBCDeposit *ibcdepositmsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->sender); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_channel\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token\":{\"denom\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->token.denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", + ibcdepositmsg->token.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"timeout_height\":{\"revision_height\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", + ibcdepositmsg->timeout_height.revision_number); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}},", + ibcdepositmsg->timeout_height.revision_height); + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgIBCWithdrawal( + const OsmosisMsgIBCWithdrawal *ibcwithdrawalmsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcwithdrawalmsg->sender); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_channel\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcwithdrawalmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token\":{\"denom\":\"ibc/"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s", + &(ibcwithdrawalmsg->token.denom[3])); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\",\"amount\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", + ibcwithdrawalmsg->token.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcwithdrawalmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcwithdrawalmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"timeout_height\":{\"revision_height\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", + ibcwithdrawalmsg->timeout_height.revision_number); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}},", + ibcwithdrawalmsg->timeout_height.revision_height); + msgs_remaining--; + return success; +} + bool osmosis_signTxUpdateMsgClaim(const OsmosisMsgClaim *claimmsg) { char buffer[64 + 1]; bool success = true; - const char *const prelude = "{\"type\":\"cosmos-sdk/MsgClaim\",\"value\":{"; + const char *const prelude = + "{\"type\":\"cosmos-sdk/MsgWithdrawDelegatorReward\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), @@ -215,8 +430,41 @@ bool osmosis_signTxUpdateMsgClaim(const OsmosisMsgClaim *claimmsg) { success &= tendermint_snprintf( &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"uosmo\",\"amount\":\"%" PRIu64 "\"}}}", - claimmsg->amount); + "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}}}", + claimmsg->token.denom, claimmsg->token.amount); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap *swapmsg) { + char buffer[64 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"osmosis/gamm/swap-exact-amount-in\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + swapmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"routes\":[{"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"poolId\":%s\",", swapmsg->pool_id); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"tokenOutDenom\":%s\"}],", + swapmsg->token_out_denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenIn\":{"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"denom\":%s\",", swapmsg->token_in.denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":\"%" PRIu64 "\"},", + swapmsg->token_in.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"tokenOutMinAmount\":\"%" PRIu64 "\"}}", + swapmsg->token_out_min_amount); msgs_remaining--; return success; From b80d33ea48bfdd981d7c667c06311e4bcaade289 Mon Sep 17 00:00:00 2001 From: mcchadwick Date: Sun, 21 Nov 2021 22:52:51 -0800 Subject: [PATCH 08/23] WIP: Sort Osmosis message fields --- lib/firmware/osmosis.c | 214 ++++++++++++++++++++++++----------------- 1 file changed, 126 insertions(+), 88 deletions(-) diff --git a/lib/firmware/osmosis.c b/lib/firmware/osmosis.c index e25ea0220..d0974c5f2 100644 --- a/lib/firmware/osmosis.c +++ b/lib/firmware/osmosis.c @@ -58,6 +58,8 @@ bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg) { sha256_Init(&ctx); + //TODO: Check and see if account number and chain ID parameters are valid/necessary here. + // Each segment guaranteed to be less than or equal to 64 bytes // 19 + ^20 + 1 = ^40 if (!tendermint_snprintf(&ctx, buffer, sizeof(buffer), @@ -74,7 +76,7 @@ bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\",\"fee\":{\"amount\":[{\"amount\":\"%" PRIu32 - "\",\"denom\":\"rune\"}]", + "\",\"denom\":\"osmo\"}]", msg.fee_amount); // 8 + ^10 + 2 = ^20 @@ -150,6 +152,11 @@ bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg) { "{\"type\":\"cosmos-sdk/MsgDelegate\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"},", + delegatemsg->token.amount, delegatemsg->token.denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"delegator_address\":"); @@ -159,14 +166,9 @@ bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"validator_address\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\"}}", delegatemsg->validator_address); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}}}", - delegatemsg->token.denom, delegatemsg->token.amount); - msgs_remaining--; return success; } @@ -181,6 +183,11 @@ bool osmosis_signTxUpdateMsgUndelegate( "{\"type\":\"cosmos-sdk/MsgUndelegate\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"},", + undelegatemsg->token.amount, undelegatemsg->token.denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"delegator_address\":"); @@ -190,14 +197,9 @@ bool osmosis_signTxUpdateMsgUndelegate( success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"validator_address\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\"}}", undelegatemsg->validator_address); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}}}", - undelegatemsg->token.denom, undelegatemsg->token.amount); - msgs_remaining--; return success; } @@ -211,15 +213,15 @@ bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg) { "{\"type\":\"osmosis/gamm/join-pool\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - lpaddmsg->sender); + lpaddmsg->pool_id); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - lpaddmsg->pool_id); + lpaddmsg->sender); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"shareOutAmount\":"); @@ -231,15 +233,35 @@ bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenInMaxs\":[{"); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"},", - lpaddmsg->token_in_max_a.denom, lpaddmsg->token_in_max_a.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\""); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", - lpaddmsg->token_in_max_b.denom, lpaddmsg->token_in_max_b.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s", + lpaddmsg->token_in_max_a.amount); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\",\"denom\":\"%" PRIu64 "\"},", + lpaddmsg->token_in_max_a.denom); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\""); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s", + lpaddmsg->token_in_max_b.amount); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\",\"denom\":\"%" PRIu64 "\"},", + lpaddmsg->token_in_max_b.denom); + + // success &= tendermint_snprintf( + // &ctx, buffer, sizeof(buffer), + // "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"},", + // lpaddmsg->token_in_max_a.denom, lpaddmsg->token_in_max_a.amount); + + // success &= tendermint_snprintf( + // &ctx, buffer, sizeof(buffer), + // "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", + // lpaddmsg->token_in_max_b.denom, lpaddmsg->token_in_max_b.amount); msgs_remaining--; return success; @@ -254,15 +276,15 @@ bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove *lpremovemsg) { "{\"type\":\"osmosis/gamm/exit-pool\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - lpremovemsg->sender); + lpremovemsg->pool_id); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - lpremovemsg->pool_id); + lpremovemsg->sender); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"shareOutAmount\":"); @@ -276,13 +298,13 @@ bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove *lpremovemsg) { success &= tendermint_snprintf( &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"},", - lpremovemsg->token_out_min_a.denom, lpremovemsg->token_out_min_a.amount); + "\"amount\":{\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"},", + lpremovemsg->token_out_min_a.amount, lpremovemsg->token_out_min_a.denom); success &= tendermint_snprintf( &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", - lpremovemsg->token_out_min_b.denom, lpremovemsg->token_out_min_b.amount); + "\"amount\":{\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"}]}}", + lpremovemsg->token_out_min_b.amount, lpremovemsg->token_out_min_b.denom); msgs_remaining--; return success; @@ -298,22 +320,22 @@ bool osmosis_signTxUpdateMsgFarmTokens( "{\"type\":\"osmosis/lockup/lock-tokens\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"owner\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"coins\":[{"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - msgfarmtokens->owner); + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"}]}}", + msgfarmtokens->token.amount, msgfarmtokens->token.denom); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"duration\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", msgfarmtokens->duration); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"coins\":[{"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"owner\":"); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", - msgfarmtokens->token.denom, msgfarmtokens->token.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + msgfarmtokens->owner); msgs_remaining--; return success; @@ -329,37 +351,45 @@ bool osmosis_signTxUpdateMsgIBCDeposit( "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->receiver); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", ibcdepositmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_channel\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->sender); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"token\":{\"denom\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->token.denom); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":"); + ibcdepositmsg->source_channel); + success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", - ibcdepositmsg->token.amount); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->sender); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->sender); + ibcdepositmsg->source_port); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"timeout_height\":{\"revision_height\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", + ibcdepositmsg->timeout_height.revision_height); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"revision_number\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", ibcdepositmsg->timeout_height.revision_number); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token\":{\"amount\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->token.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":"); success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}},", - ibcdepositmsg->timeout_height.revision_height); + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}}", + ibcdepositmsg->token.denom); + msgs_remaining--; return success; } @@ -373,39 +403,45 @@ bool osmosis_signTxUpdateMsgIBCWithdrawal( const char *const prelude = "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->receiver); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcwithdrawalmsg->sender); + ibcdepositmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_channel\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcwithdrawalmsg->sender); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"token\":{\"denom\":\"ibc/"); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s", - &(ibcwithdrawalmsg->token.denom[3])); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\",\"amount\":"); + ibcdepositmsg->source_channel); + success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", - ibcwithdrawalmsg->token.amount); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcwithdrawalmsg->sender); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcwithdrawalmsg->sender); + ibcdepositmsg->source_port); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"timeout_height\":{\"revision_height\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", - ibcwithdrawalmsg->timeout_height.revision_number); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":"); + ibcdepositmsg->timeout_height.revision_height); + success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}},", - ibcwithdrawalmsg->timeout_height.revision_height); + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"revision_number\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", + ibcdepositmsg->timeout_height.revision_number); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token\":{\"amount\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + ibcdepositmsg->token.amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}}", + ibcdepositmsg->token.denom); msgs_remaining--; return success; } @@ -446,22 +482,24 @@ bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap *swapmsg) { "{\"type\":\"osmosis/gamm/swap-exact-amount-in\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - swapmsg->sender); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"routes\":[{"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":%s\",", swapmsg->pool_id); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenOutDenom\":%s\"}],", swapmsg->token_out_denom); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + swapmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenIn\":{"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"denom\":%s\",", swapmsg->token_in.denom); + "\"amount\":%s\",", swapmsg->token_in.amount); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":\"%" PRIu64 "\"},", - swapmsg->token_in.amount); + "\"denom\":\"%" PRIu64 "\"},", + swapmsg->token_in.denom); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenOutMinAmount\":\"%" PRIu64 "\"}}", swapmsg->token_out_min_amount); From 99d6ed2dbbea036c71e97cad6868d99e21e9cbcc Mon Sep 17 00:00:00 2001 From: pastaghost Date: Fri, 27 May 2022 14:03:50 -0600 Subject: [PATCH 09/23] wip - fsm/message map build errors --- include/keepkey/firmware/app_confirm.h | 1 + include/keepkey/firmware/app_layout.h | 30 +- include/keepkey/firmware/fsm.h | 8 +- include/keepkey/firmware/osmosis.h | 26 - include/keepkey/firmware/signtx_tendermint.h | 35 +- include/keepkey/transport/interface.h | 2 +- .../transport/messages-osmosis.options | 81 +- lib/firmware/app_confirm.c | 16 + lib/firmware/app_layout.c | 42 + lib/firmware/fsm.c | 4 +- lib/firmware/fsm_msg_osmosis.h | 744 ++++++++++++------ lib/firmware/messagemap.def | 17 +- lib/firmware/signtx_tendermint.c | 41 +- lib/transport/CMakeLists.txt | 18 +- 14 files changed, 717 insertions(+), 348 deletions(-) diff --git a/include/keepkey/firmware/app_confirm.h b/include/keepkey/firmware/app_confirm.h index 5185d2ea6..906e8debc 100644 --- a/include/keepkey/firmware/app_confirm.h +++ b/include/keepkey/firmware/app_confirm.h @@ -47,6 +47,7 @@ bool confirm_address(const char *desc, const char *address); bool confirm_xpub(const char *node_str, const char *xpub); bool confirm_sign_identity(const IdentityType *identity, const char *challenge); bool confirm_cosmos_address(const char *desc, const char *address); +bool confirm_osmosis_address(const char *desc, const char *address); bool confirm_ethereum_address(const char *desc, const char *address); bool confirm_nano_address(const char *desc, const char *address); bool confirm_omni(ButtonRequestType button_request, const char *title, diff --git a/include/keepkey/firmware/app_layout.h b/include/keepkey/firmware/app_layout.h index 7ea9997c6..8c7eb17e7 100644 --- a/include/keepkey/firmware/app_layout.h +++ b/include/keepkey/firmware/app_layout.h @@ -39,19 +39,19 @@ #define NO_TITLE_WIDTH 250 /* PIN Matrix */ -#define MATRIX_MASK_COLOR 0x00 -#define MATRIX_MASK_MARGIN 3 -#define PIN_MATRIX_GRID_SIZE 18 -#define PIN_MATRIX_ANIMATION_FREQUENCY_MS 40 -#define PIN_MATRIX_BACKGROUND 0x11 -#define PIN_MATRIX_STEP1 0x11 -#define PIN_MATRIX_STEP2 0x33 -#define PIN_MATRIX_STEP3 0x77 -#define PIN_MATRIX_STEP4 0xBB -#define PIN_MATRIX_FOREGROUND 0xFF -#define PIN_SLIDE_DELAY 20 -#define PIN_MAX_ANIMATION_MS 1000 -#define PIN_LEFT_MARGIN 195 +#define MATRIX_MASK_COLOR 0x00 +#define MATRIX_MASK_MARGIN 3 +#define PIN_MATRIX_GRID_SIZE 18 +#define PIN_MATRIX_ANIMATION_FREQUENCY_MS 40 +#define PIN_MATRIX_BACKGROUND 0x11 +#define PIN_MATRIX_STEP1 0x11 +#define PIN_MATRIX_STEP2 0x33 +#define PIN_MATRIX_STEP3 0x77 +#define PIN_MATRIX_STEP4 0xBB +#define PIN_MATRIX_FOREGROUND 0xFF +#define PIN_SLIDE_DELAY 20 +#define PIN_MAX_ANIMATION_MS 1000 +#define PIN_LEFT_MARGIN 195 /* Recovery Cypher */ #define CIPHER_ROWS 2 @@ -111,7 +111,9 @@ void layout_xpub_notification(const char *desc, const char *xpub, void layout_address_notification(const char *desc, const char *address, NotificationType type); void layout_cosmos_address_notification(const char *desc, const char *address, - NotificationType type); + NotificationType type); +void layout_osmosis_address_notification(const char *desc, const char *address, + NotificationType type); void layout_ethereum_address_notification(const char *desc, const char *address, NotificationType type); void layout_nano_address_notification(const char *desc, const char *address, diff --git a/include/keepkey/firmware/fsm.h b/include/keepkey/firmware/fsm.h index a9f04c913..c81714251 100644 --- a/include/keepkey/firmware/fsm.h +++ b/include/keepkey/firmware/fsm.h @@ -105,14 +105,14 @@ void fsm_msgCosmosGetAddress(const CosmosGetAddress *msg); void fsm_msgCosmosSignTx(const CosmosSignTx *msg); void fsm_msgCosmosMsgAck(const CosmosMsgAck *msg); -void fsm_msgThorchainGetAddress(const ThorchainGetAddress *msg); -void fsm_msgThorchainSignTx(const ThorchainSignTx *msg); -void fsm_msgThorchainMsgAck(const ThorchainMsgAck *msg); - void fsm_msgOsmosisGetAddress(const OsmosisGetAddress *msg); void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg); void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg); +void fsm_msgThorchainGetAddress(const ThorchainGetAddress *msg); +void fsm_msgThorchainSignTx(const ThorchainSignTx *msg); +void fsm_msgThorchainMsgAck(const ThorchainMsgAck *msg); + #if DEBUG_LINK // void fsm_msgDebugLinkDecision(DebugLinkDecision *msg); void fsm_msgDebugLinkGetState(DebugLinkGetState *msg); diff --git a/include/keepkey/firmware/osmosis.h b/include/keepkey/firmware/osmosis.h index ebf9ff6cb..38bed14c0 100644 --- a/include/keepkey/firmware/osmosis.h +++ b/include/keepkey/firmware/osmosis.h @@ -8,31 +8,5 @@ #include typedef struct _OsmosisSignTx OsmosisSignTx; -typedef struct _OsmosisMsgDelegate OsmosisMsgDelegate; -typedef struct _OsmosisMsgUndelegate OsmosisMsgUndelegate; -typedef struct _OsmosisMsgClaim OsmosisMsgClaim; -typedef struct _OsmosisMsgLPAdd OsmosisMsgLPAdd; -typedef struct _OsmosisMsgLPRemove OsmosisMsgLPRemove; -typedef struct _OsmosisMsgFarmTokens OsmosisMsgFarmTokens; -typedef struct _OsmosisMsgIBCDeposit OsmosisMsgIBCDeposit; -typedef struct _OsmosisMsgIBCWithdrawal OsmosisMsgIBCWithdrawal; -typedef struct _OsmosisMsgSwap OsmosisMsgSwap; - -bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg); -bool osmosis_signTxUpdateMsgSend(const uint64_t amount, const char *to_address); -bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg); -bool osmosis_signTxUpdateMsgUndelegate(const OsmosisMsgUndelegate *undelegatemsg); -bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg); -bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove *lpremovemsg); -bool osmosis_signTxUpdateMsgFarmTokens(const OsmosisMsgFarmTokens *msgfarmtokens); -bool osmosis_signTxUpdateMsgIBCDeposit(const OsmosisMsgIBCDeposit *ibcdepositmsg); -bool osmosis_signTxUpdateMsgIBCWithdrawal(const OsmosisMsgIBCWithdrawal *ibcwithdrawalmsg); -bool osmosis_signTxUpdateMsgClaim(const OsmosisMsgClaim *claimmsg); -bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap *swapmsg); -bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature); -bool osmosis_signingIsInited(void); -bool osmosis_signingIsFinished(void); -void osmosis_signAbort(void); -const OsmosisSignTx *osmosis_getOsmosisSignTx(void); #endif diff --git a/include/keepkey/firmware/signtx_tendermint.h b/include/keepkey/firmware/signtx_tendermint.h index f3f5ad892..68a539974 100644 --- a/include/keepkey/firmware/signtx_tendermint.h +++ b/include/keepkey/firmware/signtx_tendermint.h @@ -13,14 +13,12 @@ bool tendermint_signTxInit(const HDNode *_node, const void *_msg, const size_t msgsize, const char *denom); bool tendermint_signTxUpdateMsgSend(const uint64_t amount, const char *to_address, - const char *chainstr, - const char *denom, + const char *chainstr, const char *denom, const char *msgTypePrefix); bool tendermint_signTxUpdateMsgDelegate(const uint64_t amount, const char *delegator_address, const char *validator_address, - const char *chainstr, - const char *denom, + const char *chainstr, const char *denom, const char *msgTypePrefix); bool tendermint_signTxUpdateMsgUndelegate(const uint64_t amount, const char *delegator_address, @@ -35,14 +33,39 @@ bool tendermint_signTxUpdateMsgRedelegate( bool tendermint_signTxUpdateMsgRewards(const uint64_t *amount, const char *delegator_address, const char *validator_address, - const char *chainstr, - const char *denom, + const char *chainstr, const char *denom, const char *msgTypePrefix); +bool tendermint_signTxUpdateMsgLPAdd( + const char *sender, const char *pool_id, const uint64_t share_out_amount, + const char *denom_in_max_a, const uint64_t amount_in_max_a, + const char *denom_in_max_b, const uint64_t amount_in_max_b, + const char *chainstr, const char *denom, const char *msgTypePrefix); +bool tendermint_signTxUpdateMsgLPRemove( + const char *sender, const char *pool_id, const uint64_t share_out_amount, + const char *denom_out_min_a, const uint64_t amount_out_min_a, + const char *denom_out_min_b, const uint64_t amount_out_min_b, + const char *chainstr, const char *denom, const char *msgTypePrefix); +bool tendermint_signTxUpdateMsgLPStake(const char *owner, + const uint64_t duration, + const uint64_t amount, + const char *chainstr, const char *denom, + const char *msgTypePrefix); +bool tendermint_signTxUpdateMsgLPUnstake(const char *owner, const char *id, + const char *chainstr, + const char *denom, + const char *msgTypePrefix); bool tendermint_signTxUpdateMsgIBCTransfer( const uint64_t amount, const char *sender, const char *receiver, const char *source_channel, const char *source_port, const char *revision_number, const char *revision_height, const char *chainstr, const char *denom, const char *msgTypePrefix); +bool tendermint_signTxUpdateMsgSwap(const char *sender, const char *pool_id, + const char *token_out_denom, + const char *token_in_denom, + const uint64_t token_in_amount, + const uint64_t token_out_min_amount, + const char *chainstr, const char *denom, + const char *msgTypePrefix); bool tendermint_signTxFinalize(uint8_t *public_key, uint8_t *signature); bool tendermint_signingIsInited(void); bool tendermint_signingIsFinished(void); diff --git a/include/keepkey/transport/interface.h b/include/keepkey/transport/interface.h index d0c166174..1a3b7e34f 100644 --- a/include/keepkey/transport/interface.h +++ b/include/keepkey/transport/interface.h @@ -29,11 +29,11 @@ #include "messages-ethereum.pb.h" #include "messages-binance.pb.h" #include "messages-cosmos.pb.h" +#include "messages-osmosis.pb.h" #include "messages-eos.pb.h" #include "messages-ripple.pb.h" #include "messages-tendermint.pb.h" #include "messages-thorchain.pb.h" -#include "messages-osmosis.pb.h" #include "types.pb.h" #include "trezor_transport.h" diff --git a/include/keepkey/transport/messages-osmosis.options b/include/keepkey/transport/messages-osmosis.options index b9a3e549f..a0fa2c357 100644 --- a/include/keepkey/transport/messages-osmosis.options +++ b/include/keepkey/transport/messages-osmosis.options @@ -1,47 +1,60 @@ OsmosisGetAddress.address_n max_count:10 -OsmosisAddress.address max_size:46 +OsmosisAddress.address max_size:53 OsmosisSignTx.address_n max_count:10 OsmosisSignTx.chain_id max_size:32 OsmosisSignTx.memo max_size:256 -OsmosisMsgSend.from_address max_size:46 -OsmosisMsgSend.to_address max_size:46 +OsmosisMsgSend.from_address max_size:53 +OsmosisMsgSend.to_address max_size:53 +OsmosisMsgSend.denom max_size:9 -OsmosisMsgDelegate.delegator_address max_size:46 +OsmosisMsgDelegate.delegator_address max_size:53 OsmosisMsgDelegate.validator_address max_size:53 +OsmosisMsgDelegate.denom max_size:9 -OsmosisMsgUndelegate.delegator_address max_size:46 +OsmosisMsgUndelegate.delegator_address max_size:53 OsmosisMsgUndelegate.validator_address max_size:53 - -OsmosisMsgClaim.delegator_address max_size:46 -OsmosisMsgClaim.validator_address max_size:53 - -OsmosisMsgLPAdd.sender max_size:46 -OsmosisMsgLPAdd.pool_id max_size:16 - -OsmosisMsgLPRemove.sender max_size:46 -OsmosisMsgLPRemove.pool_id max_size:16 - -OsmosisMsgFarmTokens.owner max_size:46 - -OsmosisMsgIBCDeposit.source_port max_size:16 -OsmosisMsgIBCDeposit.source_channel max_size:16 -OsmosisMsgIBCDeposit.sender max_size:46 -OsmosisMsgIBCDeposit.receiver max_size:46 - -OsmosisMsgIBCWithdrawal.source_port max_size:16 -OsmosisMsgIBCWithdrawal.source_channel max_size:16 -OsmosisMsgIBCWithdrawal.sender max_size:46 -OsmosisMsgIBCWithdrawal.receiver max_size:46 - -OsmosisMsgSwap.sender max_size:46 -OsmosisMsgSwap.pool_id max_size:16 -OsmosisMsgSwap.token_out_denom max_size:8 +OsmosisMsgUndelegate.denom max_size:9 + +OsmosisMsgRedelegate.delegator_address max_size:53 +OsmosisMsgRedelegate.validator_src_address max_size:53 +OsmosisMsgRedelegate.validator_dst_address max_size:53 +OsmosisMsgRedelegate.denom max_size:9 + +OsmosisMsgRewards.delegator_address max_size:53 +OsmosisMsgRewards.validator_address max_size:53 +OsmosisMsgRewards.denom max_size:9 + +OsmosisMsgLPAdd.sender max_size:53 +OsmosisMsgLPAdd.pool_id max_size:129 +OsmosisMsgLPAdd.denom_in_max_a max_size:9 +OsmosisMsgLPAdd.denom_in_max_b max_size:9 + +OsmosisMsgLPRemove.sender max_size:53 +OsmosisMsgLPRemove.pool_id max_size:129 +OsmosisMsgLPRemove.denom_out_min_a max_size:9 +OsmosisMsgLPRemove.denom_out_min_b max_size:9 + +OsmosisMsgLPStake.owner max_size:53 +OsmosisMsgLPStake.denom max_size:9 + +OsmosisMsgLPUnstake.owner max_size:53 +OsmosisMsgLPUnstake.id max_size:129 + +OsmosisMsgIBCTransfer.sender max_size:53 +OsmosisMsgIBCTransfer.receiver max_size:53 +OsmosisMsgIBCTransfer.source_channel max_size:32 +OsmosisMsgIBCTransfer.source_port max_size:32 +OsmosisMsgIBCTransfer.revision_height max_size:16 +OsmosisMsgIBCTransfer.revision_number max_size:9 +OsmosisMsgIBCTransfer.denom max_size:9 + +OsmosisMsgSwap.sender max_size:53 +OsmosisMsgSwap.pool_id max_size:129 +OsmosisMsgSwap.token_out_denom max_size:9 +OsmosisMsgSwap.token_in_denom max_size:9 OsmosisSignedTx.public_key max_size:33 -OsmosisSignedTx.signature max_size:64 - -OsmosisToken.denom max_size:72 - +OsmosisSignedTx.signature max_size:64 \ No newline at end of file diff --git a/lib/firmware/app_confirm.c b/lib/firmware/app_confirm.c index 78de26d49..80bad9fca 100644 --- a/lib/firmware/app_confirm.c +++ b/lib/firmware/app_confirm.c @@ -273,6 +273,22 @@ bool confirm_xpub(const char *node_str, const char *xpub) { desc, "%s", address); } + /* + * confirm_osmosis_address() - Show osmosis address confirmation + * + * INPUT + * - desc: description to show with address + * - address: address to display both as string and in QR + * OUTPUT + * true/false of confirmation + * + */ + bool confirm_osmosis_address(const char *desc, const char *address) { + return confirm_with_custom_layout(&layout_osmosis_address_notification, + ButtonRequestType_ButtonRequest_Address, + desc, "%s", address); + } + /* * confirm_ethereum_address() - Show ethereum address confirmation * diff --git a/lib/firmware/app_layout.c b/lib/firmware/app_layout.c index 382263bf1..dfa7e5dfe 100644 --- a/lib/firmware/app_layout.c +++ b/lib/firmware/app_layout.c @@ -473,6 +473,48 @@ void layout_cosmos_address_notification(const char *desc, const char *address, layout_notification_icon(type, &sp); } +/* + * layout_osmosis_address_notification() - Display osmosis address + * notification + * + * INPUT + * - desc: description of address being shown (normal or multisig) + * - address: osmosis address to display + * - type: notification type + * OUTPUT + * none + */ +void layout_osmosis_address_notification(const char *desc, const char *address, + NotificationType type) { + DrawableParams sp; + const Font *address_font = get_body_font(); + ; + Canvas *canvas = layout_get_canvas(); + + call_leaving_handler(); + layout_clear(); + + if (strcmp(desc, "") != 0) { + const Font *title_font = get_title_font(); + sp.y = TOP_MARGIN_FOR_TWO_LINES; + sp.x = LEFT_MARGIN + 65; + sp.color = BODY_COLOR; + draw_string(canvas, title_font, desc, &sp, TRANSACTION_WIDTH - 2, + font_height(title_font) + BODY_FONT_LINE_PADDING); + } + + /* Body */ + sp.y = TOP_MARGIN_FOR_TWO_LINES + TOP_MARGIN + TOP_MARGIN; + sp.x = LEFT_MARGIN + 65; + sp.color = BODY_COLOR; + + draw_string(canvas, address_font, address, &sp, 140, + font_height(address_font) + BODY_FONT_LINE_PADDING); + + layout_address(address, QR_LARGE); + layout_notification_icon(type, &sp); +} + /* * layout_ethereum_address_notification() - Display ethereum address * notification diff --git a/lib/firmware/fsm.c b/lib/firmware/fsm.c index 01b4d62cc..23a493c9d 100644 --- a/lib/firmware/fsm.c +++ b/lib/firmware/fsm.c @@ -76,11 +76,11 @@ #include "messages-ethereum.pb.h" #include "messages-binance.pb.h" #include "messages-cosmos.pb.h" +#include "messages-osmosis.pb.h" #include "messages-eos.pb.h" #include "messages-nano.pb.h" #include "messages-ripple.pb.h" #include "messages-thorchain.pb.h" -#include "messages-osmosis.pb.h" #include @@ -276,8 +276,8 @@ void fsm_msgClearSession(ClearSession *msg) { #include "fsm_msg_debug.h" #include "fsm_msg_eos.h" #include "fsm_msg_cosmos.h" +#include "fsm_msg_osmosis.h" #include "fsm_msg_binance.h" #include "fsm_msg_ripple.h" #include "fsm_msg_tendermint.h" #include "fsm_msg_thorchain.h" -#include "fsm_msg_osmosis.h" diff --git a/lib/firmware/fsm_msg_osmosis.h b/lib/firmware/fsm_msg_osmosis.h index 1b8d9514d..9fd0e5f0b 100644 --- a/lib/firmware/fsm_msg_osmosis.h +++ b/lib/firmware/fsm_msg_osmosis.h @@ -1,4 +1,3 @@ - void fsm_msgOsmosisGetAddress(const OsmosisGetAddress *msg) { RESP_INIT(OsmosisAddress); @@ -12,22 +11,13 @@ void fsm_msgOsmosisGetAddress(const OsmosisGetAddress *msg) { } HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count, NULL); - char mainnet[] = "osmo"; - char testnet[] = "tosmo"; - char *pfix; - if (!node) { return; } hdnode_fill_public_key(node); - pfix = mainnet; - if (msg->has_testnet && msg->testnet) { - pfix = testnet; - } - - if (!tendermint_getAddress(node, pfix, resp->address)) { + if (!tendermint_getAddress(node, "osmo", resp->address)) { memzero(node, sizeof(*node)); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Can't encode address")); @@ -84,7 +74,7 @@ void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg) { if (!msg->has_account_number || !msg->has_chain_id || !msg->has_fee_amount || !msg->has_gas || !msg->has_sequence) { - osmosis_signAbort(); + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Missing Fields On Message"); layoutHome(); @@ -101,8 +91,9 @@ void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg) { RESP_INIT(OsmosisMsgRequest); - if (!osmosis_signTxInit(node, msg)) { - osmosis_signAbort(); + if (!tendermint_signTxInit(node, (void *)msg, sizeof(OsmosisSignTx), + "uosmo")) { + tendermint_signAbort(); memzero(node, sizeof(*node)); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Failed to initialize transaction signing")); @@ -117,411 +108,669 @@ void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg) { void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { // Confirm transaction basics - // supports only 1 message ack - CHECK_PARAM(osmosis_signingIsInited(), "Signing not in progress"); - if (msg->has_send && msg->send.has_to_address && msg->send.has_token && - msg->send.token.has_amount) { - // pass - } else if (msg->has_delegate && msg->delegate.has_delegator_address && - msg->delegate.has_validator_address && msg->delegate.has_token) { - // pass - } else if (msg->has_undelegate && msg->undelegate.has_delegator_address && - msg->undelegate.has_validator_address && - msg->undelegate.has_token) { - // pass - } else if (msg->has_claim && msg->claim.has_delegator_address && - msg->claim.has_validator_address && msg->claim.has_token) { - // pass - } else if (msg->has_lp_add && msg->lp_add.has_sender && - msg->lp_add.has_pool_id && msg->lp_add.has_share_out_amount && - msg->lp_add.has_token_in_max_a && msg->lp_add.has_token_in_max_b) { - // pass - } else if (msg->has_lp_remove && msg->lp_remove.has_sender && - msg->lp_remove.has_pool_id && - msg->lp_remove.has_share_out_amount && - msg->lp_remove.has_token_out_min_a && - msg->lp_remove.has_token_out_min_b) { - // pass - } else if (msg->has_farm_tokens && msg->farm_tokens.has_owner && - msg->farm_tokens.has_duration && msg->farm_tokens.has_token) { - // pass - } else if (msg->has_ibc_deposit && msg->ibc_deposit.has_source_port && - msg->ibc_deposit.has_source_channel && - msg->ibc_deposit.has_token && msg->ibc_deposit.has_sender && - msg->ibc_deposit.has_receiver && - msg->ibc_deposit.has_timeout_height) { - // pass - } else if (msg->has_ibc_withdrawal && msg->ibc_withdrawal.has_source_port && - msg->ibc_withdrawal.has_source_channel && - msg->ibc_withdrawal.has_token && msg->ibc_withdrawal.has_sender && - msg->ibc_withdrawal.has_receiver && - msg->ibc_withdrawal.has_timeout_height) { - // pass - } else if (msg->has_swap && msg->swap.has_sender && msg->swap.has_pool_id && - msg->swap.has_token_out_denom && msg->swap.has_token_in && - msg->swap.has_token_out_min_amount) { - // pass - } else { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_FirmwareError, - _("Invalid Osmosis Message Type")); - layoutHome(); - return; - } + CHECK_PARAM(tendermint_signingIsInited(), "Signing not in progress"); const CoinType *coin = fsm_getCoin(true, "Osmosis"); if (!coin) { return; } - const OsmosisSignTx *sign_tx = osmosis_getOsmosisSignTx(); + const OsmosisSignTx *sign_tx = (OsmosisSignTx *)tendermint_getSignTx(); if (msg->has_send) { - switch (msg->send.address_type) { - case OutputAddressType_TRANSFER: - default: { - char amount_str[32]; - bn_format_uint64(msg->send.token.amount, NULL, " OSMO", 8, 0, false, - amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Transfer", - "Send %s to %s?", amount_str, msg->send.to_address)) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } + if (!msg->send.has_to_address || !msg->send.has_amount) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } - break; - } + char amount_str[32]; + bn_format_uint64(msg->send.amount, NULL, " OSMO", 6, 0, false, amount_str, + sizeof(amount_str)); + if (!confirm_transaction_output( + ButtonRequestType_ButtonRequest_ConfirmOutput, amount_str, + msg->send.to_address)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; } - if (!osmosis_signTxUpdateMsgSend(msg->send.token.amount, - msg->send.to_address)) { - osmosis_signAbort(); + + if (!tendermint_signTxUpdateMsgSend(msg->send.amount, msg->send.to_address, + "osmosis", "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include send message in transaction"); layoutHome(); return; } - } else if (msg->has_delegate) { + /** Confirm required transaction parameters exist */ + if (!msg->delegate.has_delegator_address || + !msg->delegate.has_validator_address || !msg->delegate.has_amount) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + /** Confirm transaction parameters on-screen */ char amount_str[32]; - bn_format_uint64(msg->delegate.token.amount, NULL, " OSMO", 8, 0, false, + bn_format_uint64(msg->delegate.amount, NULL, " OSMO", 6, 0, false, amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Delegate", - "Delegate %s to %s?", amount_str, - msg->delegate.validator_address)) { - osmosis_signAbort(); + if (!confirm_osmosis_address("Confirm delegator address", + msg->delegate.delegator_address)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm_osmosis_address("Confirm validator address", + msg->delegate.validator_address)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm_with_custom_layout( + &layout_notification_no_title_bold, + ButtonRequestType_ButtonRequest_ConfirmOutput, "", "Delegate %s?", + amount_str)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgDelegate(&(msg->delegate))) { - osmosis_signAbort(); + if (!tendermint_signTxUpdateMsgDelegate(msg->delegate.amount, + msg->delegate.delegator_address, + msg->delegate.validator_address, + "osmosis", "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include delegate message in transaction"); layoutHome(); return; } } else if (msg->has_undelegate) { + /** Confirm required transaction parameters exist */ + if (!msg->undelegate.has_delegator_address || + !msg->undelegate.has_validator_address || !msg->undelegate.has_amount) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + /** Confirm transaction parameters on-screen */ char amount_str[32]; - bn_format_uint64(msg->undelegate.token.amount, NULL, " OSMO", 8, 0, false, + bn_format_uint64(msg->undelegate.amount, NULL, " OSMO", 6, 0, false, amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Undelegate", - "Undelegate %s from %s?", amount_str, - msg->undelegate.validator_address)) { - osmosis_signAbort(); + if (!confirm_osmosis_address("Confirm delegator address", + msg->undelegate.delegator_address)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgUndelegate(&(msg->undelegate))) { - osmosis_signAbort(); + if (!confirm_osmosis_address("Confirm validator address", + msg->undelegate.validator_address)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm_with_custom_layout( + &layout_notification_no_title_bold, + ButtonRequestType_ButtonRequest_ConfirmOutput, "", "Undelegate %s?", + amount_str)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!tendermint_signTxUpdateMsgUndelegate( + msg->undelegate.amount, msg->undelegate.delegator_address, + msg->undelegate.validator_address, "osmosis", "uosmo", + "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include undelegate message in transaction"); layoutHome(); return; } - } else if (msg->has_claim) { + } else if (msg->has_redelegate) { + /** Confirm required transaction parameters exist */ + if (!msg->redelegate.has_delegator_address || + !msg->redelegate.has_validator_src_address || + !msg->redelegate.has_validator_dst_address || + !msg->redelegate.has_amount) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + /** Confirm transaction parameters on-screen */ char amount_str[32]; - bn_format_uint64(msg->claim.token.amount, NULL, " OSMO", 8, 0, false, + bn_format_uint64(msg->redelegate.amount, NULL, " OSMO", 6, 0, false, amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim", - "Claim %s from %s?", amount_str, - msg->claim.validator_address)) { - osmosis_signAbort(); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Redelegate", + "Redelegate %s?", amount_str)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgClaim(&(msg->claim))) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include claim message in transaction"); + if (!confirm_osmosis_address("Delegator address", + msg->redelegate.delegator_address)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - } else if (msg->has_lp_add) { - char amount_a_str[32]; - char amount_b_str[32]; - const char *denom_a_str = - strcmp(msg->lp_add.token_in_max_a.denom, "uosmo") == 0 - ? "OSMO" - : msg->lp_add.token_in_max_a.denom; - const char *denom_b_str = - strcmp(msg->lp_add.token_in_max_b.denom, "uosmo") == 0 - ? "OSMO" - : msg->lp_add.token_in_max_b.denom; - - bn_format_uint64(msg->lp_add.token_in_max_a.amount, NULL, NULL, 8, 0, false, - amount_a_str, sizeof(amount_a_str)); - - bn_format_uint64(msg->lp_add.token_in_max_b.amount, NULL, NULL, 8, 0, false, - amount_b_str, sizeof(amount_b_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", - "Confirm Token A:\nAmount: %s\nDenom: %s", amount_a_str, - denom_a_str)) { - osmosis_signAbort(); + if (!confirm_osmosis_address("Validator source address", + msg->redelegate.validator_src_address)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", - "Confirm Token B:\nAmount: %s\nDenom: %s", amount_b_str, - denom_b_str)) { - osmosis_signAbort(); + if (!confirm_osmosis_address("Validator dest. address", + msg->redelegate.validator_dst_address)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", - "Confirm Pool ID: %s", msg->lp_add.pool_id)) { - osmosis_signAbort(); + if (!tendermint_signTxUpdateMsgRedelegate( + msg->redelegate.amount, msg->redelegate.delegator_address, + msg->redelegate.validator_src_address, + msg->redelegate.validator_dst_address, "osmosis", "uosmo", + "cosmos-sdk")) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include redelegate message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_rewards) { + /** Confirm required transaction parameters exist */ + if (!msg->rewards.has_delegator_address || + !msg->rewards.has_validator_address) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + + if (msg->rewards.has_amount) { + /** Confirm transaction parameters on-screen */ + char amount_str[32]; + bn_format_uint64(msg->rewards.amount, NULL, " OSMO", 6, 0, false, + amount_str, sizeof(amount_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", + "Claim %s?", amount_str)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + } else { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", + "Claim all available rewards?")) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + } + + if (!confirm_osmosis_address("Confirm delegator address", + msg->rewards.delegator_address)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgLPAdd(&(msg->lp_add))) { - osmosis_signAbort(); + if (!confirm_osmosis_address("Confirm validator address", + msg->rewards.validator_address)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!tendermint_signTxUpdateMsgRewards( + msg->rewards.has_amount ? &msg->rewards.amount : NULL, + msg->rewards.delegator_address, msg->rewards.validator_address, + "osmosis", "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include LP Add message in transaction"); + "Failed to include rewards message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_lp_add) { + /** Confirm required transaction parameters exist */ + if (!msg->lp_add.has_sender || !msg->lp_add.has_pool_id || + !msg->lp_add.has_share_out_amount || !msg->lp_add.has_denom_in_max_a || + !msg->lp_add.has_amount_in_max_a || !msg->lp_add.has_denom_in_max_b || + !msg->lp_add.has_amount_in_max_b) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); layoutHome(); return; } - } else if (msg->has_lp_remove) { - char amount_a_str[32]; - char amount_b_str[32]; - const char *denom_a_str = - strcmp(msg->lp_remove.token_out_min_a.denom, "uosmo") == 0 - ? "OSMO" - : msg->lp_remove.token_out_min_a.denom; - const char *denom_b_str = - strcmp(msg->lp_remove.token_out_min_b.denom, "uosmo") == 0 - ? "OSMO" - : msg->lp_remove.token_out_min_b.denom; - - bn_format_uint64(msg->lp_remove.token_out_min_a.amount, NULL, NULL, 8, 0, - false, amount_a_str, sizeof(amount_a_str)); - - bn_format_uint64(msg->lp_remove.token_out_min_b.amount, NULL, NULL, 8, 0, - false, amount_b_str, sizeof(amount_b_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", - "Confirm Token A:\nAmount: %s\nDenom: %s", amount_a_str, - denom_a_str)) { - osmosis_signAbort(); + /** Confirm transaction parameters on-screen */ + char amount_str_a[32]; + char denom_str_a[12]; + sprintf(denom_str_a, " %s", msg->lp_add.denom_in_max_a); + bn_format_uint64(msg->lp_add.amount_in_max_a, NULL, denom_str_a, 6, 0, + false, amount_str_a, sizeof(amount_str_a)); + char amount_str_b[32]; + char denom_str_b[12]; + sprintf(denom_str_b, " %s", msg->lp_add.denom_in_max_b); + bn_format_uint64(msg->lp_add.amount_in_max_b, NULL, denom_str_b, 6, 0, + false, amount_str_b, sizeof(amount_str_b)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", + "Deposit %s and %s?", amount_str_a, amount_str_b)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", - "Confirm Token B:\nAmount: %s\nDenom: %s", amount_b_str, - denom_b_str)) { - osmosis_signAbort(); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", "%s", + msg->lp_add.pool_id)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", - "Confirm Pool ID: %s", msg->lp_remove.pool_id)) { - osmosis_signAbort(); + // TODO: Should this be a percentage? If so, multiply by 100 and add percent + // sign + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Pool share amount", + "%llu", msg->lp_add.share_out_amount)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgLPRemove(&(msg->lp_remove))) { - osmosis_signAbort(); + // TODO: Create signTxUpdateMsgLPAdd function + if (!tendermint_signTxUpdateMsgLPAdd( + msg->lp_add.sender, msg->lp_add.pool_id, + msg->lp_add.share_out_amount, msg->lp_add.denom_in_max_a, + msg->lp_add.amount_in_max_a, msg->lp_add.denom_in_max_b, + msg->lp_add.amount_in_max_b, "osmosis", "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include LP Remove message in transaction"); + "Failed to include rewards message in transaction"); layoutHome(); return; } - } else if (msg->has_farm_tokens) { - char amount_str[32]; - bn_format_uint64(msg->farm_tokens.token.amount, NULL, " OSMO", 8, 0, false, - amount_str, sizeof(amount_str)); + } else if (msg->has_lp_remove) { + /** Confirm required transaction parameters exist */ + if (!msg->lp_remove.has_sender || !msg->lp_remove.has_pool_id || + !msg->lp_remove.has_share_out_amount || + !msg->lp_remove.has_denom_out_min_a || + !msg->lp_remove.has_amount_out_min_a || + !msg->lp_remove.has_denom_out_min_b || + !msg->lp_remove.has_amount_out_min_b) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + + /** Confirm transaction parameters on-screen */ + char amount_str_a[32]; + char denom_str_a[12]; + sprintf(denom_str_a, " %s", msg->lp_remove.denom_out_min_a); + bn_format_uint64(msg->lp_remove.amount_out_min_a, NULL, denom_str_a, 6, 0, + false, amount_str_a, sizeof(amount_str_a)); + char amount_str_b[32]; + char denom_str_b[12]; + sprintf(denom_str_b, " %s", msg->lp_remove.denom_out_min_b); + bn_format_uint64(msg->lp_remove.amount_out_min_b, NULL, denom_str_b, 6, 0, + false, amount_str_b, sizeof(amount_str_b)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Farm Tokens", - "Lock %s in %s?", amount_str, msg->farm_tokens.token.denom)) { - osmosis_signAbort(); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", + "Withdraw %s and %s?", amount_str_a, amount_str_b)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Owner", "%s", - msg->farm_tokens.owner)) { - osmosis_signAbort(); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", "%s", + msg->lp_remove.pool_id)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Duration", - "%lld", msg->farm_tokens.duration)) { - osmosis_signAbort(); + // TODO: Should this be a percentage? If so, multiply by 100 and add percent + // sign + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Pool share amount", + "%llu", msg->lp_remove.share_out_amount)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgFarmTokens(&(msg->farm_tokens))) { - osmosis_signAbort(); + // TODO: Create signTxUpdateMsgLPAdd function + if (!tendermint_signTxUpdateMsgLPRemove( + msg->lp_remove.sender, msg->lp_remove.pool_id, + msg->lp_remove.share_out_amount, msg->lp_remove.denom_out_min_a, + msg->lp_remove.amount_out_min_a, msg->lp_remove.denom_out_min_b, + msg->lp_remove.amount_out_min_b, "osmosis", "uosmo", + "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include Farm Tokens message in transaction"); + "Failed to include rewards message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_lp_stake) { + char *lockup_duration; + char *supported_lockup_durations[] = {"1 day", "1 week", "2 weeks"}; + /** Confirm required transaction parameters exist */ + if (!msg->lp_stake.has_owner || !msg->lp_stake.has_duration || + !msg->lp_stake.has_denom || !msg->lp_stake.has_amount) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); layoutHome(); return; } - } else if (msg->has_ibc_deposit) { + switch (msg->lp_stake.duration) { + case 86400: + /* 1 day in seconds */ + lockup_duration = supported_lockup_durations[0]; + break; + case 604800: + /* 1 week in seconds */ + lockup_duration = supported_lockup_durations[1]; + break; + case 1209600: + /* 2 weeks in seconds */ + lockup_duration = supported_lockup_durations[2]; + break; + default: + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Unsupported lockup duration")); + layoutHome(); + return; + } + + /** Confirm transaction parameters on-screen */ char amount_str[32]; - bn_format_uint64(msg->ibc_deposit.token.amount, NULL, " OSMO", 8, 0, false, + char denom_str[12]; + sprintf(denom_str, " %s", msg->lp_stake.denom); + bn_format_uint64(msg->lp_stake.amount, NULL, denom_str, 6, 0, false, amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Deposit", - "Send %s on %s to %s?", amount_str, - msg->ibc_deposit.source_port, - msg->ibc_deposit.source_channel)) { - osmosis_signAbort(); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Bonding", "Bond %s?", + amount_str)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, - "Confirm Sender Address", "%s", msg->ibc_deposit.sender)) { - osmosis_signAbort(); + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm lockup period", + "Lock tokens for %s?", lockup_duration)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, - "Confirm Receiver Address", "%s", msg->ibc_deposit.receiver)) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + if (!tendermint_signTxUpdateMsgLPStake( + msg->lp_stake.owner, msg->lp_stake.duration, msg->lp_stake.amount, + "osmosis", "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include rewards message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_lp_unstake) { + /** Confirm required transaction parameters exist */ + if (!msg->lp_unstake.has_owner || !msg->lp_unstake.has_id) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgIBCDeposit(&(msg->ibc_deposit))) { - osmosis_signAbort(); + // if (msg->lp_unstake.has_amount) { + // /** Confirm transaction parameters on-screen */ + // char amount_str[32]; + // bn_format_uint64(msg->lp_unstake.amount, NULL, " OSMO", 6, 0, false, + // amount_str, sizeof(amount_str)); + + // if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", + // "Claim %s?", amount_str)) { + // tendermint_signAbort(); + // fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + // layoutHome(); + // return; + // } + // } else { + // if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", + // "Claim all available lp_unstake?")) { + // tendermint_signAbort(); + // fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + // layoutHome(); + // return; + // } + // } + + // if (!confirm_osmosis_address("Confirm delegator address", + // msg->lp_unstake.delegator_address)) { + // tendermint_signAbort(); + // fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + // layoutHome(); + // return; + // } + + // if (!confirm_osmosis_address("Confirm validator address", + // msg->lp_unstake.validator_address)) { + // tendermint_signAbort(); + // fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + // layoutHome(); + // return; + // } + + if (!tendermint_signTxUpdateMsgLPUnstake(msg->lp_unstake.owner, + msg->lp_unstake.id, "osmosis", + "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include IBC Deposit message in transaction"); + "Failed to include lp_unstake message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_ibc_transfer) { + /** Confirm required transaction parameters exist */ + if (!msg->ibc_transfer.has_sender || + !msg->ibc_transfer.has_source_channel || + !msg->ibc_transfer.has_source_port || + !msg->ibc_transfer.has_revision_height || + !msg->ibc_transfer.has_revision_number || + !msg->ibc_transfer.has_denom) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); layoutHome(); return; } - } else if (msg->has_ibc_withdrawal) { + /** Confirm transaction parameters on-screen */ char amount_str[32]; - bn_format_uint64(msg->ibc_withdrawal.token.amount, NULL, " OSMO", 8, 0, - false, amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Withdrawal", - "Receive %s on %s from %s?", amount_str, - msg->ibc_withdrawal.source_port, - msg->ibc_withdrawal.source_channel)) { - osmosis_signAbort(); + bn_format_uint64(msg->ibc_transfer.amount, NULL, " OSMO", 6, 0, false, + amount_str, sizeof(amount_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Transfer", + "Transfer %s to %s?", amount_str, msg->ibc_transfer.sender)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Source Channel", "%s", + msg->ibc_transfer.source_channel)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Source Port", + "%s", msg->ibc_transfer.source_port)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } if (!confirm(ButtonRequestType_ButtonRequest_Other, - "Confirm Sender Address", "%s", msg->ibc_withdrawal.sender)) { - osmosis_signAbort(); + "Confirm Revision Height", "%s", + msg->ibc_transfer.revision_height)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } if (!confirm(ButtonRequestType_ButtonRequest_Other, - "Confirm Receiver Address", "%s", - msg->ibc_withdrawal.receiver)) { - osmosis_signAbort(); + "Confirm Revision Number", "%s", + msg->ibc_transfer.revision_number)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgIBCWithdrawal(&(msg->ibc_withdrawal))) { - osmosis_signAbort(); - fsm_sendFailure( - FailureType_Failure_SyntaxError, - "Failed to include IBC Withdrawal message in transaction"); + if (!tendermint_signTxUpdateMsgIBCTransfer( + msg->ibc_transfer.amount, msg->ibc_transfer.sender, + msg->ibc_transfer.receiver, msg->ibc_transfer.source_channel, + msg->ibc_transfer.source_port, msg->ibc_transfer.revision_number, + msg->ibc_transfer.revision_height, "osmosis", "uosmo", + "cosmos-sdk")) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include IBC transfer message in transaction"); layoutHome(); return; } } else if (msg->has_swap) { - char amount_in_str[32] = {' '}; - char amount_out_str[32] = {' '}; - bn_format_uint64(msg->swap.token_in.amount, NULL, msg->swap.token_in.denom, - 8, 0, false, amount_in_str + (1 * sizeof(char)), - sizeof(amount_in_str)); - bn_format_uint64( - msg->swap.token_out_min_amount, NULL, msg->swap.token_out_denom, 8, 0, - false, amount_out_str + (1 * sizeof(char)), sizeof(amount_out_str)); + /** Confirm required transaction parameters exist */ + if (!msg->swap.has_sender || + !msg->swap.has_pool_id | !msg->swap.has_token_out_denom || + !msg->swap.has_token_in_denom || !msg->swap.has_token_in_amount || + !msg->swap.has_token_out_min_amount) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + + /** Confirm transaction parameters on-screen */ + char token_in_amount_str[32]; + char token_in_denom_str[12]; + sprintf(token_in_denom_str, " %s", msg->swap.token_in_denom); + bn_format_uint64(msg->swap.token_in_amount, NULL, token_in_denom_str, 6, 0, + false, token_in_amount_str, sizeof(token_in_amount_str)); + char token_out_amount_str[32]; + char token_out_denom_str[12]; + sprintf(token_out_denom_str, " %s", msg->swap.token_out_denom); + bn_format_uint64(msg->swap.token_out_min_amount, NULL, token_out_denom_str, + 6, 0, false, token_out_amount_str, + sizeof(token_out_amount_str)); if (!confirm(ButtonRequestType_ButtonRequest_Other, "Swap", - "Swap %s for at least %lld?", amount_in_str, - msg->swap.token_out_min_amount)) { - osmosis_signAbort(); + "Swap %s for at least %s?", token_in_amount_str, + token_out_amount_str)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Pool ID", "%s", + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", "%s", msg->swap.pool_id)) { - osmosis_signAbort(); + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgSwap(&(msg->swap))) { - osmosis_signAbort(); + if (!tendermint_signTxUpdateMsgSwap( + msg->swap.sender, msg->swap.pool_id, msg->swap.token_out_denom, + msg->swap.token_in_denom, msg->swap.token_in_amount, + msg->swap.token_out_min_amount, "osmosis", "uosmo", "cosmos-sdk")) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include Swap message in transaction"); + "Failed to include swap message in transaction"); layoutHome(); return; } + } else { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Invalid Osmosis message type")); + layoutHome(); + return; } - if (!osmosis_signingIsFinished()) { + if (!tendermint_signingIsFinished()) { RESP_INIT(OsmosisMsgRequest); msg_write(MessageType_MessageType_OsmosisMsgRequest, resp); return; } + if (sign_tx->has_memo && (strlen(sign_tx->memo) > 0)) { + if (!confirm(ButtonRequestType_ButtonRequest_ConfirmMemo, _("Memo"), "%s", + sign_tx->memo)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + } + char node_str[NODE_STRING_LENGTH]; if (!bip32_node_to_string(node_str, sizeof(node_str), coin, sign_tx->address_n, sign_tx->address_n_count, @@ -532,10 +781,21 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { memset(node_str, 0, sizeof(node_str)); } + if (!confirm(ButtonRequestType_ButtonRequest_SignTx, node_str, + "Sign this Osmosis transaction on %s? " + "It includes a fee of %" PRIu32 " uATOM and %" PRIu32 " gas.", + sign_tx->chain_id, sign_tx->fee_amount, sign_tx->gas)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + RESP_INIT(OsmosisSignedTx); - if (!osmosis_signTxFinalize(resp->public_key.bytes, resp->signature.bytes)) { - osmosis_signAbort(); + if (!tendermint_signTxFinalize(resp->public_key.bytes, + resp->signature.bytes)) { + tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to finalize signature"); layoutHome(); @@ -546,7 +806,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { resp->has_public_key = true; resp->signature.size = 64; resp->has_signature = true; - osmosis_signAbort(); + tendermint_signAbort(); layoutHome(); msg_write(MessageType_MessageType_OsmosisSignedTx, resp); } \ No newline at end of file diff --git a/lib/firmware/messagemap.def b/lib/firmware/messagemap.def index b21f982be..dd9b55ace 100644 --- a/lib/firmware/messagemap.def +++ b/lib/firmware/messagemap.def @@ -48,6 +48,10 @@ MSG_IN(MessageType_MessageType_CosmosSignTx, CosmosSignTx, fsm_msgCosmosSignTx) MSG_IN(MessageType_MessageType_CosmosMsgAck, CosmosMsgAck, fsm_msgCosmosMsgAck) + MSG_IN(MessageType_MessageType_CosmosGetAddress, OsmosisGetAddress, fsm_msgOsmosisGetAddress) + MSG_IN(MessageType_MessageType_OsmosisSignTx, OsmosisSignTx, fsm_msgOsmosisSignTx) + MSG_IN(MessageType_MessageType_OsmosisMsgAck, OsmosisMsgAck, fsm_msgOsmosisMsgAck) + MSG_IN(MessageType_MessageType_BinanceGetAddress, BinanceGetAddress, fsm_msgBinanceGetAddress) MSG_IN(MessageType_MessageType_BinanceSignTx, BinanceSignTx, fsm_msgBinanceSignTx) MSG_IN(MessageType_MessageType_BinanceTransferMsg, BinanceTransferMsg, fsm_msgBinanceTransferMsg) @@ -63,11 +67,6 @@ MSG_IN(MessageType_MessageType_ThorchainSignTx, ThorchainSignTx, fsm_msgThorchainSignTx) MSG_IN(MessageType_MessageType_ThorchainMsgAck, ThorchainMsgAck, fsm_msgThorchainMsgAck) - MSG_IN(MessageType_MessageType_OsmosisGetAddress, OsmosisGetAddress, fsm_msgOsmosisGetAddress) - MSG_IN(MessageType_MessageType_OsmosisSignTx, OsmosisSignTx, fsm_msgOsmosisSignTx) - MSG_IN(MessageType_MessageType_OsmosisMsgAck, OsmosisMsgAck, fsm_msgOsmosisMsgAck) - - /* Normal Out Messages */ MSG_OUT(MessageType_MessageType_Success, Success, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_Failure, Failure, NO_PROCESS_FUNC) @@ -103,6 +102,10 @@ MSG_OUT(MessageType_MessageType_CosmosMsgRequest, CosmosMsgRequest, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_CosmosSignedTx, CosmosSignedTx, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_OsmosisAddress, OsmosisAddress, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_OsmosisMsgRequest, OsmosisMsgRequest, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_OsmosisSignedTx, OsmosisSignedTx, NO_PROCESS_FUNC) + MSG_OUT(MessageType_MessageType_BinanceAddress, BinanceAddress, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_BinancePublicKey, BinancePublicKey, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_BinanceTxRequest, BinanceTxRequest, NO_PROCESS_FUNC) @@ -119,10 +122,6 @@ MSG_OUT(MessageType_MessageType_ThorchainMsgRequest, ThorchainMsgRequest, NO_PROCESS_FUNC) MSG_OUT(MessageType_MessageType_ThorchainSignedTx, ThorchainSignedTx, NO_PROCESS_FUNC) - MSG_OUT(MessageType_MessageType_OsmosisAddress, OsmosisAddress, NO_PROCESS_FUNC) - MSG_OUT(MessageType_MessageType_OsmosisMsgRequest, OsmosisMsgRequest, NO_PROCESS_FUNC) - MSG_OUT(MessageType_MessageType_OsmosisSignedTx, OsmosisSignedTx, NO_PROCESS_FUNC) - #if DEBUG_LINK /* Debug Messages */ DEBUG_IN(MessageType_MessageType_DebugLinkDecision, DebugLinkDecision, NO_PROCESS_FUNC) diff --git a/lib/firmware/signtx_tendermint.c b/lib/firmware/signtx_tendermint.c index 0b28eab69..1fb1bba7c 100644 --- a/lib/firmware/signtx_tendermint.c +++ b/lib/firmware/signtx_tendermint.c @@ -398,7 +398,8 @@ bool tendermint_signTxUpdateMsgRewards(const uint64_t *amount, // 9 + ^24 + 38 = ^72 success &= tendermint_snprintf( &ctx, buffer, sizeof(buffer), - "{\"type\":\"%s/MsgWithdrawDelegationReward\",\"value\":{", msgTypePrefix); + "{\"type\":\"%s/MsgWithdrawDelegationReward\",\"value\":{", + msgTypePrefix); // 20 + ^20 + 11 + ^9 + 3 = ^65 if (amount != NULL) { @@ -429,6 +430,34 @@ bool tendermint_signTxUpdateMsgRewards(const uint64_t *amount, return success; } +bool tendermint_signTxUpdateMsgLPAdd( + const char *sender, const char *pool_id, const uint64_t share_out_amount, + const char *denom_in_max_a, const uint64_t amount_in_max_a, + const char *denom_in_max_b, const uint64_t amount_in_max_b, + const char *chainstr, const char *denom, const char *msgTypePrefix) { + return false; +} +bool tendermint_signTxUpdateMsgLPRemove( + const char *sender, const char *pool_id, const uint64_t share_out_amount, + const char *denom_out_min_a, const uint64_t amount_out_min_a, + const char *denom_out_min_b, const uint64_t amount_out_min_b, + const char *chainstr, const char *denom, const char *msgTypePrefix) { + return false; +} +bool tendermint_signTxUpdateMsgLPStake(const char *owner, + const uint64_t duration, + const uint64_t amount, + const char *chainstr, const char *denom, + const char *msgTypePrefix) { + return false; +} +bool tendermint_signTxUpdateMsgLPUnstake(const char *owner, const char *id, + const char *chainstr, + const char *denom, + const char *msgTypePrefix) { + return false; +} + bool tendermint_signTxUpdateMsgIBCTransfer( const uint64_t amount, const char *sender, const char *receiver, const char *source_channel, const char *source_port, @@ -509,6 +538,16 @@ bool tendermint_signTxUpdateMsgIBCTransfer( return success; } +bool tendermint_signTxUpdateMsgSwap(const char *sender, const char *pool_id, + const char *token_out_denom, + const char *token_in_denom, + const uint64_t token_in_amount, + const uint64_t token_out_min_amount, + const char *chainstr, const char *denom, + const char *msgTypePrefix) { + return false; +} + bool tendermint_signTxFinalize(uint8_t *public_key, uint8_t *signature) { char buffer[128]; diff --git a/lib/transport/CMakeLists.txt b/lib/transport/CMakeLists.txt index 7a9d65986..22ddebd05 100644 --- a/lib/transport/CMakeLists.txt +++ b/lib/transport/CMakeLists.txt @@ -10,10 +10,10 @@ set(protoc_pb_sources ${DEVICE_PROTOCOL}/messages-nano.proto ${DEVICE_PROTOCOL}/messages-binance.proto ${DEVICE_PROTOCOL}/messages-cosmos.proto + ${DEVICE_PROTOCOL}/messages-osmosis.proto ${DEVICE_PROTOCOL}/messages-ripple.proto ${DEVICE_PROTOCOL}/messages-tendermint.proto ${DEVICE_PROTOCOL}/messages-thorchain.proto - ${DEVICE_PROTOCOL}/messages-osmosis.proto ${DEVICE_PROTOCOL}/messages.proto) set(protoc_pb_options @@ -23,10 +23,10 @@ set(protoc_pb_options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-nano.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-binance.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-cosmos.options + ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-osmosis.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-ripple.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-tendermint.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-thorchain.options - ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages-osmosis.options ${CMAKE_SOURCE_DIR}/include/keepkey/transport/messages.options) set(protoc_c_sources @@ -36,10 +36,10 @@ set(protoc_c_sources ${CMAKE_BINARY_DIR}/lib/transport/messages-nano.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-binance.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-cosmos.pb.c + ${CMAKE_BINARY_DIR}/lib/transport/messages-osmosis.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-ripple.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-tendermint.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages-thorchain.pb.c - ${CMAKE_BINARY_DIR}/lib/transport/messages-osmosis.pb.c ${CMAKE_BINARY_DIR}/lib/transport/messages.pb.c) set(protoc_c_headers @@ -49,10 +49,10 @@ set(protoc_c_headers ${CMAKE_BINARY_DIR}/include/messages-nano.pb.h ${CMAKE_BINARY_DIR}/include/messages-binance.pb.h ${CMAKE_BINARY_DIR}/include/messages-cosmos.pb.h + ${CMAKE_BINARY_DIR}/include/messages-osmosis.pb.h ${CMAKE_BINARY_DIR}/include/messages-ripple.pb.h ${CMAKE_BINARY_DIR}/include/messages-tendermint.pb.h ${CMAKE_BINARY_DIR}/include/messages-thorchain.pb.h - ${CMAKE_BINARY_DIR}/include/messages-osmosis.pb.h ${CMAKE_BINARY_DIR}/include/messages.pb.h) set(protoc_pb_sources_moved @@ -62,10 +62,10 @@ set(protoc_pb_sources_moved ${CMAKE_BINARY_DIR}/lib/transport/messages-nano.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-binance.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-cosmos.proto + ${CMAKE_BINARY_DIR}/lib/transport/messages-osmosis.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-ripple.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-tendermint.proto ${CMAKE_BINARY_DIR}/lib/transport/messages-thorchain.proto - ${CMAKE_BINARY_DIR}/lib/transport/messages-osmosis.proto ${CMAKE_BINARY_DIR}/lib/transport/messages.proto) add_custom_command( @@ -114,19 +114,19 @@ add_custom_command( COMMAND ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb - "--nanopb_out=-f messages-ripple.options:." messages-ripple.proto + "--nanopb_out=-f messages-osmosis.options:." messages-osmosis.proto COMMAND ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb - "--nanopb_out=-f messages-tendermint.options:." messages-tendermint.proto + "--nanopb_out=-f messages-ripple.options:." messages-ripple.proto COMMAND ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb - "--nanopb_out=-f messages-thorchain.options:." messages-thorchain.proto + "--nanopb_out=-f messages-tendermint.options:." messages-tendermint.proto COMMAND ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb - "--nanopb_out=-f messages-osmosis.options:." messages-osmosis.proto + "--nanopb_out=-f messages-thorchain.options:." messages-thorchain.proto COMMAND ${PROTOC_BINARY} -I. -I/usr/include --plugin=nanopb=${NANOPB_DIR}/generator/protoc-gen-nanopb From 5bb497a726dca888da26a537747a6e7a918d1334 Mon Sep 17 00:00:00 2001 From: pastaghost Date: Sun, 7 Aug 2022 18:37:00 -0600 Subject: [PATCH 10/23] fix: osmosis message type typo --- lib/firmware/messagemap.def | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/firmware/messagemap.def b/lib/firmware/messagemap.def index dd9b55ace..98d9c646a 100644 --- a/lib/firmware/messagemap.def +++ b/lib/firmware/messagemap.def @@ -48,7 +48,7 @@ MSG_IN(MessageType_MessageType_CosmosSignTx, CosmosSignTx, fsm_msgCosmosSignTx) MSG_IN(MessageType_MessageType_CosmosMsgAck, CosmosMsgAck, fsm_msgCosmosMsgAck) - MSG_IN(MessageType_MessageType_CosmosGetAddress, OsmosisGetAddress, fsm_msgOsmosisGetAddress) + MSG_IN(MessageType_MessageType_OsmosisGetAddress, OsmosisGetAddress, fsm_msgOsmosisGetAddress) MSG_IN(MessageType_MessageType_OsmosisSignTx, OsmosisSignTx, fsm_msgOsmosisSignTx) MSG_IN(MessageType_MessageType_OsmosisMsgAck, OsmosisMsgAck, fsm_msgOsmosisMsgAck) From 31efceb99240d98d3d7866a78aec320ac7a29142 Mon Sep 17 00:00:00 2001 From: pastaghost Date: Fri, 11 Nov 2022 11:16:29 -0700 Subject: [PATCH 11/23] wip --- deps/device-protocol | 2 +- deps/python-keepkey | 2 +- lib/firmware/fsm_msg_osmosis.h | 346 +++++++++++++++++-------------- lib/firmware/osmosis.c | 326 +++++++++++++++++------------ lib/firmware/signtx_tendermint.c | 72 +++---- 5 files changed, 413 insertions(+), 335 deletions(-) diff --git a/deps/device-protocol b/deps/device-protocol index 82ec74705..a12f0b243 160000 --- a/deps/device-protocol +++ b/deps/device-protocol @@ -1 +1 @@ -Subproject commit 82ec74705e5798580b532fac02fbbe5f5740f1e2 +Subproject commit a12f0b243a1d8f8283dbca8ecff0862ce4d521b5 diff --git a/deps/python-keepkey b/deps/python-keepkey index b697b08a2..4a1ee20c9 160000 --- a/deps/python-keepkey +++ b/deps/python-keepkey @@ -1 +1 @@ -Subproject commit b697b08a29676c780f3fb16106d902efcbabbe5a +Subproject commit 4a1ee20c99819f86268040f61ba290230471f3d7 diff --git a/lib/firmware/fsm_msg_osmosis.h b/lib/firmware/fsm_msg_osmosis.h index 9fd0e5f0b..035bbd5d4 100644 --- a/lib/firmware/fsm_msg_osmosis.h +++ b/lib/firmware/fsm_msg_osmosis.h @@ -248,126 +248,6 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { layoutHome(); return; } - } else if (msg->has_redelegate) { - /** Confirm required transaction parameters exist */ - if (!msg->redelegate.has_delegator_address || - !msg->redelegate.has_validator_src_address || - !msg->redelegate.has_validator_dst_address || - !msg->redelegate.has_amount) { - tendermint_signAbort(); - fsm_sendFailure(FailureType_Failure_FirmwareError, - _("Message is missing required parameters")); - layoutHome(); - return; - } - /** Confirm transaction parameters on-screen */ - char amount_str[32]; - bn_format_uint64(msg->redelegate.amount, NULL, " OSMO", 6, 0, false, - amount_str, sizeof(amount_str)); - - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Redelegate", - "Redelegate %s?", amount_str)) { - tendermint_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } - - if (!confirm_osmosis_address("Delegator address", - msg->redelegate.delegator_address)) { - tendermint_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } - - if (!confirm_osmosis_address("Validator source address", - msg->redelegate.validator_src_address)) { - tendermint_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } - - if (!confirm_osmosis_address("Validator dest. address", - msg->redelegate.validator_dst_address)) { - tendermint_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } - - if (!tendermint_signTxUpdateMsgRedelegate( - msg->redelegate.amount, msg->redelegate.delegator_address, - msg->redelegate.validator_src_address, - msg->redelegate.validator_dst_address, "osmosis", "uosmo", - "cosmos-sdk")) { - tendermint_signAbort(); - fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include redelegate message in transaction"); - layoutHome(); - return; - } - } else if (msg->has_rewards) { - /** Confirm required transaction parameters exist */ - if (!msg->rewards.has_delegator_address || - !msg->rewards.has_validator_address) { - tendermint_signAbort(); - fsm_sendFailure(FailureType_Failure_FirmwareError, - _("Message is missing required parameters")); - layoutHome(); - return; - } - - if (msg->rewards.has_amount) { - /** Confirm transaction parameters on-screen */ - char amount_str[32]; - bn_format_uint64(msg->rewards.amount, NULL, " OSMO", 6, 0, false, - amount_str, sizeof(amount_str)); - - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", - "Claim %s?", amount_str)) { - tendermint_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } - } else { - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", - "Claim all available rewards?")) { - tendermint_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } - } - - if (!confirm_osmosis_address("Confirm delegator address", - msg->rewards.delegator_address)) { - tendermint_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } - - if (!confirm_osmosis_address("Confirm validator address", - msg->rewards.validator_address)) { - tendermint_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } - - if (!tendermint_signTxUpdateMsgRewards( - msg->rewards.has_amount ? &msg->rewards.amount : NULL, - msg->rewards.delegator_address, msg->rewards.validator_address, - "osmosis", "uosmo", "cosmos-sdk")) { - tendermint_signAbort(); - fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include rewards message in transaction"); - layoutHome(); - return; - } } else if (msg->has_lp_add) { /** Confirm required transaction parameters exist */ if (!msg->lp_add.has_sender || !msg->lp_add.has_pool_id || @@ -485,12 +365,19 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } // TODO: Create signTxUpdateMsgLPAdd function - if (!tendermint_signTxUpdateMsgLPRemove( - msg->lp_remove.sender, msg->lp_remove.pool_id, - msg->lp_remove.share_out_amount, msg->lp_remove.denom_out_min_a, - msg->lp_remove.amount_out_min_a, msg->lp_remove.denom_out_min_b, - msg->lp_remove.amount_out_min_b, "osmosis", "uosmo", - "cosmos-sdk")) { + // if (!tendermint_signTxUpdateMsgLPRemove( + // msg->lp_remove.sender, msg->lp_remove.pool_id, + // msg->lp_remove.share_out_amount, msg->lp_remove.denom_out_min_a, + // msg->lp_remove.amount_out_min_a, msg->lp_remove.denom_out_min_b, + // msg->lp_remove.amount_out_min_b, "osmosis", "uosmo", + // "cosmos-sdk")) { + // tendermint_signAbort(); + // fsm_sendFailure(FailureType_Failure_SyntaxError, + // "Failed to include rewards message in transaction"); + // layoutHome(); + // return; + // } + if (!osmosis_signTxUpdateMsgLPRemove(msg)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include rewards message in transaction"); @@ -553,9 +440,16 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!tendermint_signTxUpdateMsgLPStake( - msg->lp_stake.owner, msg->lp_stake.duration, msg->lp_stake.amount, - "osmosis", "uosmo", "cosmos-sdk")) { + // if (!tendermint_signTxUpdateMsgLPStake( + // msg->lp_stake.owner, msg->lp_stake.duration, + // msg->lp_stake.amount, "osmosis", "uosmo", "cosmos-sdk")) { + // tendermint_signAbort(); + // fsm_sendFailure(FailureType_Failure_SyntaxError, + // "Failed to include rewards message in transaction"); + // layoutHome(); + // return; + // } + if (!osmosis_signTxUpdateMsgLPStake(msg)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include rewards message in transaction"); @@ -620,14 +514,12 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { layoutHome(); return; } - } else if (msg->has_ibc_transfer) { + } else if (msg->has_redelegate) { /** Confirm required transaction parameters exist */ - if (!msg->ibc_transfer.has_sender || - !msg->ibc_transfer.has_source_channel || - !msg->ibc_transfer.has_source_port || - !msg->ibc_transfer.has_revision_height || - !msg->ibc_transfer.has_revision_number || - !msg->ibc_transfer.has_denom) { + if (!msg->redelegate.has_delegator_address || + !msg->redelegate.has_validator_src_address || + !msg->redelegate.has_validator_dst_address || + !msg->redelegate.has_amount) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Message is missing required parameters")); @@ -636,61 +528,109 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } /** Confirm transaction parameters on-screen */ char amount_str[32]; - bn_format_uint64(msg->ibc_transfer.amount, NULL, " OSMO", 6, 0, false, + bn_format_uint64(msg->redelegate.amount, NULL, " OSMO", 6, 0, false, amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Transfer", - "Transfer %s to %s?", amount_str, msg->ibc_transfer.sender)) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Redelegate", + "Redelegate %s?", amount_str)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, - "Confirm Source Channel", "%s", - msg->ibc_transfer.source_channel)) { + if (!confirm_osmosis_address("Delegator address", + msg->redelegate.delegator_address)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Source Port", - "%s", msg->ibc_transfer.source_port)) { + if (!confirm_osmosis_address("Validator source address", + msg->redelegate.validator_src_address)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, - "Confirm Revision Height", "%s", - msg->ibc_transfer.revision_height)) { + if (!confirm_osmosis_address("Validator dest. address", + msg->redelegate.validator_dst_address)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, - "Confirm Revision Number", "%s", - msg->ibc_transfer.revision_number)) { + if (!tendermint_signTxUpdateMsgRedelegate( + msg->redelegate.amount, msg->redelegate.delegator_address, + msg->redelegate.validator_src_address, + msg->redelegate.validator_dst_address, "osmosis", "uosmo", + "cosmos-sdk")) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include redelegate message in transaction"); + layoutHome(); + return; + } + } else if (msg->has_rewards) { + /** Confirm required transaction parameters exist */ + if (!msg->rewards.has_delegator_address || + !msg->rewards.has_validator_address) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + + if (msg->rewards.has_amount) { + /** Confirm transaction parameters on-screen */ + char amount_str[32]; + bn_format_uint64(msg->rewards.amount, NULL, " OSMO", 6, 0, false, + amount_str, sizeof(amount_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", + "Claim %s?", amount_str)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + } else { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", + "Claim all available rewards?")) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + } + + if (!confirm_osmosis_address("Confirm delegator address", + msg->rewards.delegator_address)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!tendermint_signTxUpdateMsgIBCTransfer( - msg->ibc_transfer.amount, msg->ibc_transfer.sender, - msg->ibc_transfer.receiver, msg->ibc_transfer.source_channel, - msg->ibc_transfer.source_port, msg->ibc_transfer.revision_number, - msg->ibc_transfer.revision_height, "osmosis", "uosmo", - "cosmos-sdk")) { + if (!confirm_osmosis_address("Confirm validator address", + msg->rewards.validator_address)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!tendermint_signTxUpdateMsgRewards( + msg->rewards.has_amount ? &msg->rewards.amount : NULL, + msg->rewards.delegator_address, msg->rewards.validator_address, + "osmosis", "uosmo", "cosmos-sdk")) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include IBC transfer message in transaction"); + "Failed to include rewards message in transaction"); layoutHome(); return; } @@ -737,16 +677,100 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!tendermint_signTxUpdateMsgSwap( - msg->swap.sender, msg->swap.pool_id, msg->swap.token_out_denom, - msg->swap.token_in_denom, msg->swap.token_in_amount, - msg->swap.token_out_min_amount, "osmosis", "uosmo", "cosmos-sdk")) { + // if (!tendermint_signTxUpdateMsgSwap( + // msg->swap.sender, msg->swap.pool_id, msg->swap.token_out_denom, + // msg->swap.token_in_denom, msg->swap.token_in_amount, + // msg->swap.token_out_min_amount, "osmosis", "uosmo", + // "cosmos-sdk")) { + // tendermint_signAbort(); + // fsm_sendFailure(FailureType_Failure_SyntaxError, + // "Failed to include swap message in transaction"); + // layoutHome(); + // return; + // } + + if (!osmosis_signTxUpdateMsgSwap(msg)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include swap message in transaction"); layoutHome(); return; } + + } else if (msg->has_ibc_transfer) { + /** Confirm required transaction parameters exist */ + if (!msg->ibc_transfer.has_sender || + !msg->ibc_transfer.has_source_channel || + !msg->ibc_transfer.has_source_port || + !msg->ibc_transfer.has_revision_height || + !msg->ibc_transfer.has_revision_number || + !msg->ibc_transfer.has_denom) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_FirmwareError, + _("Message is missing required parameters")); + layoutHome(); + return; + } + /** Confirm transaction parameters on-screen */ + char amount_str[32]; + bn_format_uint64(msg->ibc_transfer.amount, NULL, " OSMO", 6, 0, false, + amount_str, sizeof(amount_str)); + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Transfer", + "Transfer %s to %s?", amount_str, msg->ibc_transfer.sender)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Source Channel", "%s", + msg->ibc_transfer.source_channel)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Source Port", + "%s", msg->ibc_transfer.source_port)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Revision Height", "%s", + msg->ibc_transfer.revision_height)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Revision Number", "%s", + msg->ibc_transfer.revision_number)) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!tendermint_signTxUpdateMsgIBCTransfer( + msg->ibc_transfer.amount, msg->ibc_transfer.sender, + msg->ibc_transfer.receiver, msg->ibc_transfer.source_channel, + msg->ibc_transfer.source_port, msg->ibc_transfer.revision_number, + msg->ibc_transfer.revision_height, "osmosis", "uosmo", + "cosmos-sdk")) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_SyntaxError, + "Failed to include IBC transfer message in transaction"); + layoutHome(); + return; + } } else { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, diff --git a/lib/firmware/osmosis.c b/lib/firmware/osmosis.c index d0974c5f2..a0396ccbc 100644 --- a/lib/firmware/osmosis.c +++ b/lib/firmware/osmosis.c @@ -58,7 +58,8 @@ bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg) { sha256_Init(&ctx); - //TODO: Check and see if account number and chain ID parameters are valid/necessary here. + // TODO: Check and see if account number and chain ID parameters are + // valid/necessary here. // Each segment guaranteed to be less than or equal to 64 bytes // 19 + ^20 + 1 = ^40 @@ -152,10 +153,10 @@ bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg) { "{\"type\":\"cosmos-sdk/MsgDelegate\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":{\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"},", - delegatemsg->token.amount, delegatemsg->token.denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\"%" PRIu64 + "\",\"denom\":\"%s\"},", + delegatemsg->amount, delegatemsg->denom); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"delegator_address\":"); @@ -183,10 +184,10 @@ bool osmosis_signTxUpdateMsgUndelegate( "{\"type\":\"cosmos-sdk/MsgUndelegate\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":{\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"},", - undelegatemsg->token.amount, undelegatemsg->token.denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\"%" PRIu64 + "\",\"denom\":\"%s\"},", + undelegatemsg->amount, undelegatemsg->denom); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"delegator_address\":"); @@ -213,10 +214,8 @@ bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg) { "{\"type\":\"osmosis/gamm/join-pool\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - lpaddmsg->pool_id); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"poolId\":\"%s\",", lpaddmsg->pool_id); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); @@ -234,34 +233,20 @@ bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg) { tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenInMaxs\":[{"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":{\"amount\":\""); + "\"amount\":\"%" PRIu64 "\",", + lpaddmsg->amount_in_max_a); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s", - lpaddmsg->token_in_max_a.amount); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\",\"denom\":\"%" PRIu64 "\"},", - lpaddmsg->token_in_max_a.denom); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":{\"amount\":\""); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s", - lpaddmsg->token_in_max_b.amount); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":\"%s\"},", + lpaddmsg->denom_in_max_a); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\",\"denom\":\"%" PRIu64 "\"},", - lpaddmsg->token_in_max_b.denom); - - // success &= tendermint_snprintf( - // &ctx, buffer, sizeof(buffer), - // "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"},", - // lpaddmsg->token_in_max_a.denom, lpaddmsg->token_in_max_a.amount); + "\"amount\":\"%" PRIu64 "\",", + lpaddmsg->amount_in_max_b); - // success &= tendermint_snprintf( - // &ctx, buffer, sizeof(buffer), - // "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}]}}", - // lpaddmsg->token_in_max_b.denom, lpaddmsg->token_in_max_b.amount); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":\"%s\"},", + lpaddmsg->denom_in_max_b); msgs_remaining--; return success; @@ -294,24 +279,29 @@ bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove *lpremovemsg) { lpremovemsg->share_out_amount); success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenInMaxs\":[{"); + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenOutMins\":[{"); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":{\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"},", - lpremovemsg->token_out_min_a.amount, lpremovemsg->token_out_min_a.denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":\"%" PRIu64 "\",", + lpremovemsg->amount_out_min_a); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":{\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"}]}}", - lpremovemsg->token_out_min_b.amount, lpremovemsg->token_out_min_b.denom); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":\"%s\"},", + lpremovemsg->denom_out_min_a); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":\"%" PRIu64 "\",", + lpremovemsg->amount_out_min_b); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":\"%s\"},", + lpremovemsg->denom_out_min_b); msgs_remaining--; return success; } -bool osmosis_signTxUpdateMsgFarmTokens( - const OsmosisMsgFarmTokens *msgfarmtokens) { +bool osmosis_signTxUpdateMsgLPStake(const OsmosisMsgLPStake *msgstake) { char buffer[64 + 1]; bool success = true; @@ -322,152 +312,103 @@ bool osmosis_signTxUpdateMsgFarmTokens( success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"coins\":[{"); - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":\"%s\",\"denom\":\"%" PRIu64 "\"}]}}", - msgfarmtokens->token.amount, msgfarmtokens->token.denom); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":\"%" PRIu64 "\",\"denom\":\"%s\"}],", + msgstake->amount, msgstake->denom); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"duration\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"%" PRIu64 "\",", msgfarmtokens->duration); + "\"%" PRIu64 "\",", msgstake->duration); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"owner\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - msgfarmtokens->owner); + msgstake->owner); msgs_remaining--; return success; } -bool osmosis_signTxUpdateMsgIBCDeposit( - const OsmosisMsgIBCDeposit *ibcdepositmsg) { +bool osmosis_signTxUpdateMsgLPUnstake(const OsmosisMsgLPUnstake *msgunstake) { char buffer[64 + 1]; bool success = true; const char *const prelude = - "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; + "{\"type\":\"osmosis/lockup/begin-unlock-period-lock\",\"value\":"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->receiver); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->sender); - - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_channel\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->source_channel); - - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->source_port); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"timeout_height\":{\"revision_height\":"); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", - ibcdepositmsg->timeout_height.revision_height); - - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"revision_number\":"); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", - ibcdepositmsg->timeout_height.revision_number); + "{\"ID\":\"%s\",", msgunstake->id); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"token\":{\"amount\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->token.amount); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":"); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}}", - ibcdepositmsg->token.denom); + "\"owner\":\"%s\"}}", msgunstake->owner); msgs_remaining--; return success; } -bool osmosis_signTxUpdateMsgIBCWithdrawal( - const OsmosisMsgIBCWithdrawal *ibcwithdrawalmsg) { +bool osmosis_signTxUpdateMsgRedelegate( + const OsmosisMsgRedelegate *redelegatemsg) { char buffer[64 + 1]; bool success = true; const char *const prelude = - "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; + "{\"type\":\"cosmos-sdk/MsgRedelegate\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->receiver); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\"%" PRIu64 + "\",\"denom\":\"%s\"},", + redelegatemsg->amount, redelegatemsg->denom); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"delegator_address\":"); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_channel\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->source_channel); + redelegatemsg->delegator_address); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"validator_dst_address\":"); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->source_port); + redelegatemsg->validator_dst_address); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"timeout_height\":{\"revision_height\":"); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", - ibcdepositmsg->timeout_height.revision_height); + "\"validator_src_address\":"); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"revision_number\":"); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", - ibcdepositmsg->timeout_height.revision_number); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\"}}", + redelegatemsg->validator_src_address); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"token\":{\"amount\":"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - ibcdepositmsg->token.amount); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":"); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}}", - ibcdepositmsg->token.denom); msgs_remaining--; return success; } -bool osmosis_signTxUpdateMsgClaim(const OsmosisMsgClaim *claimmsg) { +bool osmosis_signTxUpdateMsgRewards(const OsmosisMsgRewards *rewardsmsg) { char buffer[64 + 1]; bool success = true; const char *const prelude = - "{\"type\":\"cosmos-sdk/MsgWithdrawDelegatorReward\",\"value\":{"; + "{\"type\":\"cosmos-sdk/MsgWithdrawDelegationReward\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\"%" PRIu64 + "\",\"denom\":\"%s\"},", + rewardsmsg->amount, rewardsmsg->denom); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"delegator_address\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - claimmsg->delegator_address); + rewardsmsg->delegator_address); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - claimmsg->validator_address); - - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":{\"denom\":\"%s\",\"amount\":\"%" PRIu64 "\"}}}", - claimmsg->token.denom, claimmsg->token.amount); + rewardsmsg->validator_address); msgs_remaining--; return success; @@ -496,10 +437,10 @@ bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap *swapmsg) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenIn\":{"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":%s\",", swapmsg->token_in.amount); + "\"amount\":%" PRIu64 "\",", + swapmsg->token_in_amount); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"denom\":\"%" PRIu64 "\"},", - swapmsg->token_in.denom); + "\"denom\":\"%s\"},", swapmsg->token_in_denom); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenOutMinAmount\":\"%" PRIu64 "\"}}", swapmsg->token_out_min_amount); @@ -508,6 +449,119 @@ bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap *swapmsg) { return success; } +// bool osmosis_signTxUpdateMsgIBCDeposit( +// const OsmosisMsgIBCDeposit *ibcdepositmsg) { +// char buffer[64 + 1]; + +// bool success = true; + +// const char *const prelude = +// "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; +// sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), +// "\"receiver\":"); success &= tendermint_snprintf(&ctx, buffer, +// sizeof(buffer), "\"%s\",", +// ibcdepositmsg->receiver); + +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), +// "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, +// sizeof(buffer), "\"%s\",", +// ibcdepositmsg->sender); + +// success &= +// tendermint_snprintf(&ctx, buffer, sizeof(buffer), +// "\"source_channel\":"); +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", +// ibcdepositmsg->source_channel); + +// success &= +// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", +// ibcdepositmsg->source_port); + +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), +// "\"timeout_height\":{\"revision_height\":"); +// success &= +// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", +// ibcdepositmsg->timeout_height.revision_height); + +// success &= +// tendermint_snprintf(&ctx, buffer, sizeof(buffer), +// "\"revision_number\":"); +// success &= +// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", +// ibcdepositmsg->timeout_height.revision_number); + +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), +// "\"token\":{\"amount\":"); +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", +// ibcdepositmsg->token.amount); +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":"); +// success &= +// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}}", +// ibcdepositmsg->token.denom); + +// msgs_remaining--; +// return success; +// } + +// bool osmosis_signTxUpdateMsgIBCWithdrawal( +// const OsmosisMsgIBCWithdrawal *ibcwithdrawalmsg) { +// char buffer[64 + 1]; + +// bool success = true; + +// const char *const prelude = +// "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; +// sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), +// "\"receiver\":"); success &= tendermint_snprintf(&ctx, buffer, +// sizeof(buffer), "\"%s\",", +// ibcwithdrawalmsg->receiver); + +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), +// "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, +// sizeof(buffer), "\"%s\",", +// ibcwithdrawalmsg->sender); + +// success &= +// tendermint_snprintf(&ctx, buffer, sizeof(buffer), +// "\"source_channel\":"); +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", +// ibcwithdrawalmsg->source_channel); + +// success &= +// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", +// ibcwithdrawalmsg->source_port); + +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), +// "\"timeout_height\":{\"revision_height\":"); +// success &= +// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", +// ibcwithdrawalmsg->timeout_height.revision_height); + +// success &= +// tendermint_snprintf(&ctx, buffer, sizeof(buffer), +// "\"revision_number\":"); +// success &= +// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", +// ibcwithdrawalmsg->timeout_height.revision_number); + +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), +// "\"token\":{\"amount\":"); +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", +// ibcwithdrawalmsg->amount); +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":"); +// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), +// "\"%" PRIu64 "\"}}}", +// ibcwithdrawalmsg->denom); +// msgs_remaining--; +// return success; +// } + bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature) { char buffer[64 + 1]; diff --git a/lib/firmware/signtx_tendermint.c b/lib/firmware/signtx_tendermint.c index 1fb1bba7c..b2d95d647 100644 --- a/lib/firmware/signtx_tendermint.c +++ b/lib/firmware/signtx_tendermint.c @@ -430,33 +430,33 @@ bool tendermint_signTxUpdateMsgRewards(const uint64_t *amount, return success; } -bool tendermint_signTxUpdateMsgLPAdd( - const char *sender, const char *pool_id, const uint64_t share_out_amount, - const char *denom_in_max_a, const uint64_t amount_in_max_a, - const char *denom_in_max_b, const uint64_t amount_in_max_b, - const char *chainstr, const char *denom, const char *msgTypePrefix) { - return false; -} -bool tendermint_signTxUpdateMsgLPRemove( - const char *sender, const char *pool_id, const uint64_t share_out_amount, - const char *denom_out_min_a, const uint64_t amount_out_min_a, - const char *denom_out_min_b, const uint64_t amount_out_min_b, - const char *chainstr, const char *denom, const char *msgTypePrefix) { - return false; -} -bool tendermint_signTxUpdateMsgLPStake(const char *owner, - const uint64_t duration, - const uint64_t amount, - const char *chainstr, const char *denom, - const char *msgTypePrefix) { - return false; -} -bool tendermint_signTxUpdateMsgLPUnstake(const char *owner, const char *id, - const char *chainstr, - const char *denom, - const char *msgTypePrefix) { - return false; -} +// bool tendermint_signTxUpdateMsgLPAdd( +// const char *sender, const char *pool_id, const uint64_t share_out_amount, +// const char *denom_in_max_a, const uint64_t amount_in_max_a, +// const char *denom_in_max_b, const uint64_t amount_in_max_b, +// const char *chainstr, const char *denom, const char *msgTypePrefix) { +// return false; +// } +// bool tendermint_signTxUpdateMsgLPRemove( +// const char *sender, const char *pool_id, const uint64_t share_out_amount, +// const char *denom_out_min_a, const uint64_t amount_out_min_a, +// const char *denom_out_min_b, const uint64_t amount_out_min_b, +// const char *chainstr, const char *denom, const char *msgTypePrefix) { +// return false; +// } +// bool tendermint_signTxUpdateMsgLPStake(const char *owner, +// const uint64_t duration, +// const uint64_t amount, +// const char *chainstr, const char +// *denom, const char *msgTypePrefix) { +// return false; +// } +// bool tendermint_signTxUpdateMsgLPUnstake(const char *owner, const char *id, +// const char *chainstr, +// const char *denom, +// const char *msgTypePrefix) { +// return false; +// } bool tendermint_signTxUpdateMsgIBCTransfer( const uint64_t amount, const char *sender, const char *receiver, @@ -538,15 +538,15 @@ bool tendermint_signTxUpdateMsgIBCTransfer( return success; } -bool tendermint_signTxUpdateMsgSwap(const char *sender, const char *pool_id, - const char *token_out_denom, - const char *token_in_denom, - const uint64_t token_in_amount, - const uint64_t token_out_min_amount, - const char *chainstr, const char *denom, - const char *msgTypePrefix) { - return false; -} +// bool tendermint_signTxUpdateMsgSwap(const char *sender, const char *pool_id, +// const char *token_out_denom, +// const char *token_in_denom, +// const uint64_t token_in_amount, +// const uint64_t token_out_min_amount, +// const char *chainstr, const char *denom, +// const char *msgTypePrefix) { +// return false; +// } bool tendermint_signTxFinalize(uint8_t *public_key, uint8_t *signature) { char buffer[128]; From 678478ba76c3ca212bc455b54e314453b4d091c7 Mon Sep 17 00:00:00 2001 From: pastaghost Date: Tue, 15 Nov 2022 19:49:50 -0700 Subject: [PATCH 12/23] refactor: use common tendermint messages where applicable for osmosis --- include/keepkey/firmware/osmosis.h | 15 + lib/firmware/fsm_msg_osmosis.h | 111 +------ lib/firmware/osmosis.c | 450 +++-------------------------- lib/firmware/signtx_tendermint.c | 39 +-- 4 files changed, 69 insertions(+), 546 deletions(-) diff --git a/include/keepkey/firmware/osmosis.h b/include/keepkey/firmware/osmosis.h index 38bed14c0..065301066 100644 --- a/include/keepkey/firmware/osmosis.h +++ b/include/keepkey/firmware/osmosis.h @@ -8,5 +8,20 @@ #include typedef struct _OsmosisSignTx OsmosisSignTx; +typedef struct _OsmosisMsgLPAdd OsmosisMsgLPAdd; +typedef struct _OsmosisMsgLPRemove OsmosisMsgLPRemove; +typedef struct _OsmosisMsgLPStake OsmosisMsgLPStake; +typedef struct _OsmosisMsgLPUnstake OsmosisMsgLPUnstake; +typedef struct _OsmosisMsgSwap OsmosisMsgSwap; + +bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd msglpadd); + +bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove msglpremove); + +bool osmosis_signTxUpdateMsgLPStake(const OsmosisMsgLPStake msgstake); + +bool osmosis_signTxUpdateMsgLPUnstake(const OsmosisMsgLPUnstake msgunstake); + +bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap msgswap); #endif diff --git a/lib/firmware/fsm_msg_osmosis.h b/lib/firmware/fsm_msg_osmosis.h index 035bbd5d4..1a8ea2a50 100644 --- a/lib/firmware/fsm_msg_osmosis.h +++ b/lib/firmware/fsm_msg_osmosis.h @@ -300,11 +300,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } // TODO: Create signTxUpdateMsgLPAdd function - if (!tendermint_signTxUpdateMsgLPAdd( - msg->lp_add.sender, msg->lp_add.pool_id, - msg->lp_add.share_out_amount, msg->lp_add.denom_in_max_a, - msg->lp_add.amount_in_max_a, msg->lp_add.denom_in_max_b, - msg->lp_add.amount_in_max_b, "osmosis", "uosmo", "cosmos-sdk")) { + if (!osmosis_signTxUpdateMsgLPAdd(msg->lp_add)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include rewards message in transaction"); @@ -364,20 +360,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - // TODO: Create signTxUpdateMsgLPAdd function - // if (!tendermint_signTxUpdateMsgLPRemove( - // msg->lp_remove.sender, msg->lp_remove.pool_id, - // msg->lp_remove.share_out_amount, msg->lp_remove.denom_out_min_a, - // msg->lp_remove.amount_out_min_a, msg->lp_remove.denom_out_min_b, - // msg->lp_remove.amount_out_min_b, "osmosis", "uosmo", - // "cosmos-sdk")) { - // tendermint_signAbort(); - // fsm_sendFailure(FailureType_Failure_SyntaxError, - // "Failed to include rewards message in transaction"); - // layoutHome(); - // return; - // } - if (!osmosis_signTxUpdateMsgLPRemove(msg)) { + if (!osmosis_signTxUpdateMsgLPRemove(msg->lp_remove)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include rewards message in transaction"); @@ -424,35 +407,18 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { bn_format_uint64(msg->lp_stake.amount, NULL, denom_str, 6, 0, false, amount_str, sizeof(amount_str)); - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Bonding", "Bond %s?", - amount_str)) { - tendermint_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } - - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm lockup period", - "Lock tokens for %s?", lockup_duration)) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Lock Tokens", + "Lock %s tokens for %s?", amount_str, lockup_duration)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - // if (!tendermint_signTxUpdateMsgLPStake( - // msg->lp_stake.owner, msg->lp_stake.duration, - // msg->lp_stake.amount, "osmosis", "uosmo", "cosmos-sdk")) { - // tendermint_signAbort(); - // fsm_sendFailure(FailureType_Failure_SyntaxError, - // "Failed to include rewards message in transaction"); - // layoutHome(); - // return; - // } - if (!osmosis_signTxUpdateMsgLPStake(msg)) { + if (!osmosis_signTxUpdateMsgLPStake(msg->lp_stake)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include rewards message in transaction"); + "Failed to include lp stake message in transaction"); layoutHome(); return; } @@ -466,48 +432,15 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - // if (msg->lp_unstake.has_amount) { - // /** Confirm transaction parameters on-screen */ - // char amount_str[32]; - // bn_format_uint64(msg->lp_unstake.amount, NULL, " OSMO", 6, 0, false, - // amount_str, sizeof(amount_str)); - - // if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", - // "Claim %s?", amount_str)) { - // tendermint_signAbort(); - // fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - // layoutHome(); - // return; - // } - // } else { - // if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", - // "Claim all available lp_unstake?")) { - // tendermint_signAbort(); - // fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - // layoutHome(); - // return; - // } - // } - - // if (!confirm_osmosis_address("Confirm delegator address", - // msg->lp_unstake.delegator_address)) { - // tendermint_signAbort(); - // fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - // layoutHome(); - // return; - // } - - // if (!confirm_osmosis_address("Confirm validator address", - // msg->lp_unstake.validator_address)) { - // tendermint_signAbort(); - // fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - // layoutHome(); - // return; - // } - - if (!tendermint_signTxUpdateMsgLPUnstake(msg->lp_unstake.owner, - msg->lp_unstake.id, "osmosis", - "uosmo", "cosmos-sdk")) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Unlock Tokens", + "Begin unbonding time for all bonded tokens in all pools?")) { + tendermint_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!osmosis_signTxUpdateMsgLPUnstake(msg->lp_unstake)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include lp_unstake message in transaction"); @@ -677,19 +610,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - // if (!tendermint_signTxUpdateMsgSwap( - // msg->swap.sender, msg->swap.pool_id, msg->swap.token_out_denom, - // msg->swap.token_in_denom, msg->swap.token_in_amount, - // msg->swap.token_out_min_amount, "osmosis", "uosmo", - // "cosmos-sdk")) { - // tendermint_signAbort(); - // fsm_sendFailure(FailureType_Failure_SyntaxError, - // "Failed to include swap message in transaction"); - // layoutHome(); - // return; - // } - - if (!osmosis_signTxUpdateMsgSwap(msg)) { + if (!osmosis_signTxUpdateMsgSwap(msg->swap)) { tendermint_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include swap message in transaction"); diff --git a/lib/firmware/osmosis.c b/lib/firmware/osmosis.c index a0396ccbc..ead49966c 100644 --- a/lib/firmware/osmosis.c +++ b/lib/firmware/osmosis.c @@ -31,181 +31,13 @@ #include #include -static CONFIDENTIAL HDNode node; static SHA256_CTX ctx; -static bool initialized; static uint32_t msgs_remaining; static OsmosisSignTx msg; -static bool testnet; const OsmosisSignTx *osmosis_getOsmosisSignTx(void) { return &msg; } -bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg) { - initialized = true; - msgs_remaining = _msg->msg_count; - testnet = false; - - if (_msg->has_testnet) { - testnet = _msg->testnet; - } - - memzero(&node, sizeof(node)); - memcpy(&node, _node, sizeof(node)); - memcpy(&msg, _msg, sizeof(msg)); - - bool success = true; - char buffer[64 + 1]; - - sha256_Init(&ctx); - - // TODO: Check and see if account number and chain ID parameters are - // valid/necessary here. - - // Each segment guaranteed to be less than or equal to 64 bytes - // 19 + ^20 + 1 = ^40 - if (!tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "{\"account_number\":\"%" PRIu64 "\"", - msg.account_number)) - return false; - - // - const char *const chainid_prefix = ",\"chain_id\":\""; - sha256_Update(&ctx, (uint8_t *)chainid_prefix, strlen(chainid_prefix)); - tendermint_sha256UpdateEscaped(&ctx, msg.chain_id, strlen(msg.chain_id)); - - // 30 + ^10 + 19 = ^59 - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\",\"fee\":{\"amount\":[{\"amount\":\"%" PRIu32 - "\",\"denom\":\"osmo\"}]", - msg.fee_amount); - - // 8 + ^10 + 2 = ^20 - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - ",\"gas\":\"%" PRIu32 "\"}", msg.gas); - - // - const char *const memo_prefix = ",\"memo\":\""; - sha256_Update(&ctx, (uint8_t *)memo_prefix, strlen(memo_prefix)); - if (msg.has_memo) { - tendermint_sha256UpdateEscaped(&ctx, msg.memo, strlen(msg.memo)); - } - - // 10 - sha256_Update(&ctx, (uint8_t *)"\",\"msgs\":[", 10); - - return success; -} - -bool osmosis_signTxUpdateMsgSend(const uint64_t amount, - const char *to_address) { - char mainnetp[] = "osmo"; - char testnetp[] = "tosmo"; - char *pfix; - char buffer[64 + 1]; - - size_t decoded_len; - char hrp[45]; - uint8_t decoded[38]; - if (!bech32_decode(hrp, decoded, &decoded_len, to_address)) { - return false; - } - - char from_address[46]; - - pfix = mainnetp; - if (testnet) { - pfix = testnetp; - } - - if (!tendermint_getAddress(&node, pfix, from_address)) { - return false; - } - - bool success = true; - - const char *const prelude = "{\"type\":\"cosmos-sdk/MsgSend\",\"value\":{"; - sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - - // 21 + ^20 + 19 = ^60 - success &= tendermint_snprintf( - &ctx, buffer, sizeof(buffer), - "\"amount\":[{\"amount\":\"%" PRIu64 "\",\"denom\":\"uosmo\"}]", amount); - - // 17 + 45 + 1 = 63 - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - ",\"from_address\":\"%s\"", from_address); - - // 15 + 45 + 3 = 63 - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - ",\"to_address\":\"%s\"}}", to_address); - - msgs_remaining--; - return success; -} - -bool osmosis_signTxUpdateMsgDelegate(const OsmosisMsgDelegate *delegatemsg) { - char buffer[64 + 1]; - - bool success = true; - - const char *const prelude = - "{\"type\":\"cosmos-sdk/MsgDelegate\",\"value\":{"; - sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":{\"amount\":\"%" PRIu64 - "\",\"denom\":\"%s\"},", - delegatemsg->amount, delegatemsg->denom); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"delegator_address\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - delegatemsg->delegator_address); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"validator_address\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\"}}", - delegatemsg->validator_address); - - msgs_remaining--; - return success; -} - -bool osmosis_signTxUpdateMsgUndelegate( - const OsmosisMsgUndelegate *undelegatemsg) { - char buffer[64 + 1]; - - bool success = true; - - const char *const prelude = - "{\"type\":\"cosmos-sdk/MsgUndelegate\",\"value\":{"; - sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":{\"amount\":\"%" PRIu64 - "\",\"denom\":\"%s\"},", - undelegatemsg->amount, undelegatemsg->denom); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"delegator_address\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - undelegatemsg->delegator_address); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"validator_address\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\"}}", - undelegatemsg->validator_address); - - msgs_remaining--; - return success; -} - -bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg) { +bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd msglpadd) { char buffer[64 + 1]; bool success = true; @@ -215,44 +47,41 @@ bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd *lpaddmsg) { sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"poolId\":\"%s\",", lpaddmsg->pool_id); + "\"poolId\":\"%s\",", msglpadd.pool_id); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - lpaddmsg->sender); + msglpadd.sender); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"shareOutAmount\":"); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", - lpaddmsg->share_out_amount); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"%" PRIu64 "\",", msglpadd.share_out_amount); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenInMaxs\":[{"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":\"%" PRIu64 "\",", - lpaddmsg->amount_in_max_a); + msglpadd.amount_in_max_a); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":\"%s\"},", - lpaddmsg->denom_in_max_a); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"denom\":\"%s\"},", msglpadd.denom_in_max_a); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":\"%" PRIu64 "\",", - lpaddmsg->amount_in_max_b); + msglpadd.amount_in_max_b); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":\"%s\"},", - lpaddmsg->denom_in_max_b); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"denom\":\"%s\"},", msglpadd.denom_in_max_b); msgs_remaining--; return success; } -bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove *lpremovemsg) { +bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove msglpremove) { char buffer[64 + 1]; bool success = true; @@ -264,44 +93,44 @@ bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove *lpremovemsg) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - lpremovemsg->pool_id); + msglpremove.pool_id); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - lpremovemsg->sender); + msglpremove.sender); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"shareOutAmount\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", - lpremovemsg->share_out_amount); + msglpremove.share_out_amount); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenOutMins\":[{"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":\"%" PRIu64 "\",", - lpremovemsg->amount_out_min_a); + msglpremove.amount_out_min_a); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":\"%s\"},", - lpremovemsg->denom_out_min_a); + msglpremove.denom_out_min_a); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":\"%" PRIu64 "\",", - lpremovemsg->amount_out_min_b); + msglpremove.amount_out_min_b); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":\"%s\"},", - lpremovemsg->denom_out_min_b); + msglpremove.denom_out_min_b); msgs_remaining--; return success; } -bool osmosis_signTxUpdateMsgLPStake(const OsmosisMsgLPStake *msgstake) { +bool osmosis_signTxUpdateMsgLPStake(const OsmosisMsgLPStake msgstake) { char buffer[64 + 1]; bool success = true; @@ -315,23 +144,23 @@ bool osmosis_signTxUpdateMsgLPStake(const OsmosisMsgLPStake *msgstake) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":\"%" PRIu64 "\",\"denom\":\"%s\"}],", - msgstake->amount, msgstake->denom); + msgstake.amount, msgstake.denom); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"duration\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"%" PRIu64 "\",", msgstake->duration); + "\"%" PRIu64 "\",", msgstake.duration); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"owner\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - msgstake->owner); + msgstake.owner); msgs_remaining--; return success; } -bool osmosis_signTxUpdateMsgLPUnstake(const OsmosisMsgLPUnstake *msgunstake) { +bool osmosis_signTxUpdateMsgLPUnstake(const OsmosisMsgLPUnstake msgunstake) { char buffer[64 + 1]; bool success = true; @@ -341,80 +170,16 @@ bool osmosis_signTxUpdateMsgLPUnstake(const OsmosisMsgLPUnstake *msgunstake) { sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "{\"ID\":\"%s\",", msgunstake->id); + "{\"ID\":\"%s\",", msgunstake.id); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"owner\":\"%s\"}}", msgunstake->owner); + "\"owner\":\"%s\"}}", msgunstake.owner); msgs_remaining--; return success; } -bool osmosis_signTxUpdateMsgRedelegate( - const OsmosisMsgRedelegate *redelegatemsg) { - char buffer[64 + 1]; - - bool success = true; - - const char *const prelude = - "{\"type\":\"cosmos-sdk/MsgRedelegate\",\"value\":{"; - sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":{\"amount\":\"%" PRIu64 - "\",\"denom\":\"%s\"},", - redelegatemsg->amount, redelegatemsg->denom); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"delegator_address\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - redelegatemsg->delegator_address); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"validator_dst_address\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - redelegatemsg->validator_dst_address); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"validator_src_address\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\"}}", - redelegatemsg->validator_src_address); - - msgs_remaining--; - return success; -} - -bool osmosis_signTxUpdateMsgRewards(const OsmosisMsgRewards *rewardsmsg) { - char buffer[64 + 1]; - - bool success = true; - - const char *const prelude = - "{\"type\":\"cosmos-sdk/MsgWithdrawDelegationReward\",\"value\":{"; - sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":{\"amount\":\"%" PRIu64 - "\",\"denom\":\"%s\"},", - rewardsmsg->amount, rewardsmsg->denom); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"delegator_address\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - rewardsmsg->delegator_address); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - rewardsmsg->validator_address); - - msgs_remaining--; - return success; -} - -bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap *swapmsg) { +bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap msgswap) { char buffer[64 + 1]; bool success = true; @@ -425,167 +190,26 @@ bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap *swapmsg) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"routes\":[{"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"poolId\":%s\",", swapmsg->pool_id); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"tokenOutDenom\":%s\"}],", - swapmsg->token_out_denom); + "\"poolId\":%s\",", msgswap.pool_id); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"tokenOutDenom\":%s\"}],", msgswap.token_out_denom); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - swapmsg->sender); + msgswap.sender); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenIn\":{"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":%" PRIu64 "\",", msgswap.token_in_amount); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":%" PRIu64 "\",", - swapmsg->token_in_amount); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"denom\":\"%s\"},", swapmsg->token_in_denom); + "\"denom\":\"%s\"},", msgswap.token_in_denom); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenOutMinAmount\":\"%" PRIu64 "\"}}", - swapmsg->token_out_min_amount); + msgswap.token_out_min_amount); msgs_remaining--; return success; } - -// bool osmosis_signTxUpdateMsgIBCDeposit( -// const OsmosisMsgIBCDeposit *ibcdepositmsg) { -// char buffer[64 + 1]; - -// bool success = true; - -// const char *const prelude = -// "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; -// sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), -// "\"receiver\":"); success &= tendermint_snprintf(&ctx, buffer, -// sizeof(buffer), "\"%s\",", -// ibcdepositmsg->receiver); - -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), -// "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, -// sizeof(buffer), "\"%s\",", -// ibcdepositmsg->sender); - -// success &= -// tendermint_snprintf(&ctx, buffer, sizeof(buffer), -// "\"source_channel\":"); -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", -// ibcdepositmsg->source_channel); - -// success &= -// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", -// ibcdepositmsg->source_port); - -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), -// "\"timeout_height\":{\"revision_height\":"); -// success &= -// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", -// ibcdepositmsg->timeout_height.revision_height); - -// success &= -// tendermint_snprintf(&ctx, buffer, sizeof(buffer), -// "\"revision_number\":"); -// success &= -// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", -// ibcdepositmsg->timeout_height.revision_number); - -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), -// "\"token\":{\"amount\":"); -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", -// ibcdepositmsg->token.amount); -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":"); -// success &= -// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"}}}", -// ibcdepositmsg->token.denom); - -// msgs_remaining--; -// return success; -// } - -// bool osmosis_signTxUpdateMsgIBCWithdrawal( -// const OsmosisMsgIBCWithdrawal *ibcwithdrawalmsg) { -// char buffer[64 + 1]; - -// bool success = true; - -// const char *const prelude = -// "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"; -// sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), -// "\"receiver\":"); success &= tendermint_snprintf(&ctx, buffer, -// sizeof(buffer), "\"%s\",", -// ibcwithdrawalmsg->receiver); - -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), -// "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, -// sizeof(buffer), "\"%s\",", -// ibcwithdrawalmsg->sender); - -// success &= -// tendermint_snprintf(&ctx, buffer, sizeof(buffer), -// "\"source_channel\":"); -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", -// ibcwithdrawalmsg->source_channel); - -// success &= -// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"source_port\":"); -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", -// ibcwithdrawalmsg->source_port); - -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), -// "\"timeout_height\":{\"revision_height\":"); -// success &= -// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", -// ibcwithdrawalmsg->timeout_height.revision_height); - -// success &= -// tendermint_snprintf(&ctx, buffer, sizeof(buffer), -// "\"revision_number\":"); -// success &= -// tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\"},", -// ibcwithdrawalmsg->timeout_height.revision_number); - -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), -// "\"token\":{\"amount\":"); -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", -// ibcwithdrawalmsg->amount); -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":"); -// success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), -// "\"%" PRIu64 "\"}}}", -// ibcwithdrawalmsg->denom); -// msgs_remaining--; -// return success; -// } - -bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature) { - char buffer[64 + 1]; - - // 16 + ^20 = ^36 - if (!tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "],\"sequence\":\"%" PRIu64 "\"}", msg.sequence)) - return false; - - hdnode_fill_public_key(&node); - memcpy(public_key, node.public_key, 33); - - uint8_t hash[SHA256_DIGEST_LENGTH]; - sha256_Final(&ctx, hash); - return ecdsa_sign_digest(&secp256k1, node.private_key, hash, signature, NULL, - NULL) == 0; -} - -bool osmosis_signingIsInited(void) { return initialized; } - -bool osmosis_signingIsFinished(void) { return msgs_remaining == 0; } - -void osmosis_signAbort(void) { - initialized = false; - msgs_remaining = 0; - memzero(&msg, sizeof(msg)); - memzero(&node, sizeof(node)); -} diff --git a/lib/firmware/signtx_tendermint.c b/lib/firmware/signtx_tendermint.c index b2d95d647..1f4ede820 100644 --- a/lib/firmware/signtx_tendermint.c +++ b/lib/firmware/signtx_tendermint.c @@ -18,6 +18,7 @@ */ #include "keepkey/firmware/cosmos.h" +#include "keepkey/firmware/osmosis.h" #include "keepkey/board/confirm_sm.h" #include "keepkey/board/util.h" #include "keepkey/firmware/home_sm.h" @@ -430,34 +431,6 @@ bool tendermint_signTxUpdateMsgRewards(const uint64_t *amount, return success; } -// bool tendermint_signTxUpdateMsgLPAdd( -// const char *sender, const char *pool_id, const uint64_t share_out_amount, -// const char *denom_in_max_a, const uint64_t amount_in_max_a, -// const char *denom_in_max_b, const uint64_t amount_in_max_b, -// const char *chainstr, const char *denom, const char *msgTypePrefix) { -// return false; -// } -// bool tendermint_signTxUpdateMsgLPRemove( -// const char *sender, const char *pool_id, const uint64_t share_out_amount, -// const char *denom_out_min_a, const uint64_t amount_out_min_a, -// const char *denom_out_min_b, const uint64_t amount_out_min_b, -// const char *chainstr, const char *denom, const char *msgTypePrefix) { -// return false; -// } -// bool tendermint_signTxUpdateMsgLPStake(const char *owner, -// const uint64_t duration, -// const uint64_t amount, -// const char *chainstr, const char -// *denom, const char *msgTypePrefix) { -// return false; -// } -// bool tendermint_signTxUpdateMsgLPUnstake(const char *owner, const char *id, -// const char *chainstr, -// const char *denom, -// const char *msgTypePrefix) { -// return false; -// } - bool tendermint_signTxUpdateMsgIBCTransfer( const uint64_t amount, const char *sender, const char *receiver, const char *source_channel, const char *source_port, @@ -538,16 +511,6 @@ bool tendermint_signTxUpdateMsgIBCTransfer( return success; } -// bool tendermint_signTxUpdateMsgSwap(const char *sender, const char *pool_id, -// const char *token_out_denom, -// const char *token_in_denom, -// const uint64_t token_in_amount, -// const uint64_t token_out_min_amount, -// const char *chainstr, const char *denom, -// const char *msgTypePrefix) { -// return false; -// } - bool tendermint_signTxFinalize(uint8_t *public_key, uint8_t *signature) { char buffer[128]; From 28f3af48447ef5e0fa18fed029b6cf05b3f6cad3 Mon Sep 17 00:00:00 2001 From: pastaghost Date: Fri, 2 Dec 2022 13:32:59 -0700 Subject: [PATCH 13/23] version bump --- CMakeLists.txt | 82 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67b208c4e..b8d92c6c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,9 @@ cmake_minimum_required(VERSION 3.7.2) -project(KeepKeyFirmware - - VERSION 7.5.0 - - LANGUAGES C CXX ASM) +project( + KeepKeyFirmware + VERSION 7.6.0 + LANGUAGES C CXX ASM) set(BOOTLOADER_MAJOR_VERSION 2) set(BOOTLOADER_MINOR_VERSION 1) @@ -13,10 +12,18 @@ set(BOOTLOADER_PATCH_VERSION 5) option(KK_EMULATOR "Build the emulator" OFF) option(KK_DEBUG_LINK "Build with debug-link enabled" OFF) option(KK_BUILD_FUZZERS "Build the fuzzers?" OFF) -set(LIBOPENCM3_PATH /root/libopencm3 CACHE PATH "Path to an already-built libopencm3") -set(PROTOC_BINARY protoc CACHE PATH "Path to the protobuf compiler binary") -set(NANOPB_DIR /root/nanopb CACHE PATH "Path to the nanopb build") -set(DEVICE_PROTOCOL ${CMAKE_SOURCE_DIR}/deps/device-protocol CACHE PATH "Path to device-protocol") +set(LIBOPENCM3_PATH + /root/libopencm3 + CACHE PATH "Path to an already-built libopencm3") +set(PROTOC_BINARY + protoc + CACHE PATH "Path to the protobuf compiler binary") +set(NANOPB_DIR + /root/nanopb + CACHE PATH "Path to the nanopb build") +set(DEVICE_PROTOCOL + ${CMAKE_SOURCE_DIR}/deps/device-protocol + CACHE PATH "Path to device-protocol") set(CMAKE_DEBUG_POSTFIX CACHE STRING "Debug library name postfix") list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") @@ -24,24 +31,35 @@ include(GetGitRevisionDescription) get_git_head_revision(GIT_REFSPEC GIT_SHA1) if(NOT EXISTS ${DEVICE_PROTOCOL}) - message(FATAL_ERROR "Missing deps/device-protocol symlink?") + message(FATAL_ERROR "Missing deps/device-protocol symlink?") endif() if(NOT EXISTS ${CMAKE_SOURCE_DIR}/deps/googletest/CMakeLists.txt) - message(FATAL_ERROR "googletest missing. Need to 'git submodule update --init --recursive") + message( + FATAL_ERROR + "googletest missing. Need to 'git submodule update --init --recursive") endif() if(NOT EXISTS ${CMAKE_SOURCE_DIR}/deps/crypto/trezor-firmware/crypto/Makefile) - message(FATAL_ERROR " trezor-crypto missing. Need to 'git submodule update --init --recursive") + message( + FATAL_ERROR + " trezor-crypto missing. Need to 'git submodule update --init --recursive" + ) endif() if(NOT EXISTS ${CMAKE_SOURCE_DIR}/deps/qrenc/QR-Code-generator/c/Makefile) - message(FATAL_ERROR " QR-Code-generator missing. Need to 'git submodule update --init --recursive") + message( + FATAL_ERROR + " QR-Code-generator missing. Need to 'git submodule update --init --recursive" + ) endif() find_program(NANOPB_GENERATOR nanopb_generator.py) if(${KK_EMULATOR} AND NOT NANOPB_GENERATOR) - message(FATAL_ERROR "Must install nanopb 0.3.9.4, and put nanopb-nanopb-0.3.9.4/generator on your PATH") + message( + FATAL_ERROR + "Must install nanopb 0.3.9.4, and put nanopb-nanopb-0.3.9.4/generator on your PATH" + ) endif() if(${KK_EMULATOR}) @@ -95,18 +113,20 @@ endif() if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") add_definitions(-DDEBUG_ON) add_definitions(-DMEMORY_PROTECT=0) -elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR - "${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel" OR - "${CMAKE_BUILD_TYPE}" STREQUAL "") +elseif( + "${CMAKE_BUILD_TYPE}" STREQUAL "Release" + OR "${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel" + OR "${CMAKE_BUILD_TYPE}" STREQUAL "") add_definitions(-DNDEBUG) add_definitions(-DMEMORY_PROTECT=1) if(NOT ${KK_EMULATOR}) - message(WARNING - "*********************************************************************\n" - "* You are about to build a release version of KeepKey firmware. The *\n" - "* resulting bootloader image will memory protect the flash on your *\n" - "* device, so please use it with extreme care. *\n" - "*********************************************************************") + message( + WARNING + "*********************************************************************\n" + "* You are about to build a release version of KeepKey firmware. The *\n" + "* resulting bootloader image will memory protect the flash on your *\n" + "* device, so please use it with extreme care. *\n" + "*********************************************************************") endif() else() message(ERROR "Must pick Release *or* Debug CMAKE_BUILD_TYPE") @@ -129,8 +149,8 @@ if(NOT ${KK_EMULATOR}) add_library(ssp_nonshared ${CMAKE_BINARY_DIR}/ssp.c) set_property(TARGET ssp PROPERTY LINKER_LANGUAGE CXX) set_property(TARGET ssp_nonshared PROPERTY LINKER_LANGUAGE CXX) - set_target_properties(ssp ssp_nonshared - PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + set_target_properties(ssp ssp_nonshared PROPERTIES LIBRARY_OUTPUT_DIRECTORY + ${CMAKE_BINARY_DIR}/lib) endif() add_subdirectory(lib) @@ -151,9 +171,13 @@ if(${KK_EMULATOR}) add_test(test-board ${CMAKE_BINARY_DIR}/bin/board-unit) add_test(test-crypto ${CMAKE_BINARY_DIR}/bin/crypto-unit) - add_custom_target(xunit - COMMAND ${CMAKE_BINARY_DIR}/bin/firmware-unit --gtest_output=xml:${CMAKE_BINARY_DIR}/unittests/firmware.xml - COMMAND ${CMAKE_BINARY_DIR}/bin/board-unit --gtest_output=xml:${CMAKE_BINARY_DIR}/unittests/board.xml - COMMAND ${CMAKE_BINARY_DIR}/bin/crypto-unit --gtest_output=xml:${CMAKE_BINARY_DIR}/unittests/crypto.xml) + add_custom_target( + xunit + COMMAND ${CMAKE_BINARY_DIR}/bin/firmware-unit + --gtest_output=xml:${CMAKE_BINARY_DIR}/unittests/firmware.xml + COMMAND ${CMAKE_BINARY_DIR}/bin/board-unit + --gtest_output=xml:${CMAKE_BINARY_DIR}/unittests/board.xml + COMMAND ${CMAKE_BINARY_DIR}/bin/crypto-unit + --gtest_output=xml:${CMAKE_BINARY_DIR}/unittests/crypto.xml) endif() From 78c5f079ffe233a31c421f746c2d10603122801f Mon Sep 17 00:00:00 2001 From: pastaghost Date: Fri, 2 Dec 2022 13:52:28 -0700 Subject: [PATCH 14/23] use separate signing paths for osmosis --- include/keepkey/firmware/osmosis.h | 36 ++ .../transport/messages-osmosis.options | 26 +- lib/firmware/fsm_msg_osmosis.h | 228 ++++---- lib/firmware/messagemap.def | 2 +- lib/firmware/osmosis.c | 508 +++++++++++++++++- 5 files changed, 657 insertions(+), 143 deletions(-) diff --git a/include/keepkey/firmware/osmosis.h b/include/keepkey/firmware/osmosis.h index 065301066..4b6f76023 100644 --- a/include/keepkey/firmware/osmosis.h +++ b/include/keepkey/firmware/osmosis.h @@ -14,6 +14,8 @@ typedef struct _OsmosisMsgLPStake OsmosisMsgLPStake; typedef struct _OsmosisMsgLPUnstake OsmosisMsgLPUnstake; typedef struct _OsmosisMsgSwap OsmosisMsgSwap; +bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg); + bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd msglpadd); bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove msglpremove); @@ -24,4 +26,38 @@ bool osmosis_signTxUpdateMsgLPUnstake(const OsmosisMsgLPUnstake msgunstake); bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap msgswap); +bool osmosis_signTxUpdateMsgSend(const uint64_t amount, const char *to_address, + const char *denom); + +bool osmosis_signTxUpdateMsgDelegate(const uint64_t amount, + const char *delegator_address, + const char *validator_address, + const char *denom); + +bool osmosis_signTxUpdateMsgUndelegate(const uint64_t amount, + const char *delegator_address, + const char *validator_address, + const char *denom); + +bool osmosis_signTxUpdateMsgRedelegate(const uint64_t amount, + const char *delegator_address, + const char *validator_src_address, + const char *validator_dst_address, + const char *denom); + +bool osmosis_signTxUpdateMsgRewards(const uint64_t *amount, + const char *delegator_address, + const char *validator_address, + const char *denom); +bool osmosis_signTxUpdateMsgIBCTransfer( + const uint64_t amount, const char *sender, const char *receiver, + const char *source_channel, const char *source_port, + const char *revision_number, const char *revision_height, + const char *denom); +bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature); +bool osmosis_signingIsInited(void); +bool osmosis_signingIsFinished(void); +void osmosis_signAbort(void); +const OsmosisSignTx *osmosis_getOsmosisSignTx(void); + #endif diff --git a/include/keepkey/transport/messages-osmosis.options b/include/keepkey/transport/messages-osmosis.options index a0fa2c357..a89404758 100644 --- a/include/keepkey/transport/messages-osmosis.options +++ b/include/keepkey/transport/messages-osmosis.options @@ -8,37 +8,37 @@ OsmosisSignTx.memo max_size:256 OsmosisMsgSend.from_address max_size:53 OsmosisMsgSend.to_address max_size:53 -OsmosisMsgSend.denom max_size:9 +OsmosisMsgSend.denom max_size:69 OsmosisMsgDelegate.delegator_address max_size:53 OsmosisMsgDelegate.validator_address max_size:53 -OsmosisMsgDelegate.denom max_size:9 +OsmosisMsgDelegate.denom max_size:69 OsmosisMsgUndelegate.delegator_address max_size:53 OsmosisMsgUndelegate.validator_address max_size:53 -OsmosisMsgUndelegate.denom max_size:9 +OsmosisMsgUndelegate.denom max_size:69 OsmosisMsgRedelegate.delegator_address max_size:53 OsmosisMsgRedelegate.validator_src_address max_size:53 OsmosisMsgRedelegate.validator_dst_address max_size:53 -OsmosisMsgRedelegate.denom max_size:9 +OsmosisMsgRedelegate.denom max_size:69 OsmosisMsgRewards.delegator_address max_size:53 OsmosisMsgRewards.validator_address max_size:53 -OsmosisMsgRewards.denom max_size:9 +OsmosisMsgRewards.denom max_size:69 OsmosisMsgLPAdd.sender max_size:53 OsmosisMsgLPAdd.pool_id max_size:129 -OsmosisMsgLPAdd.denom_in_max_a max_size:9 -OsmosisMsgLPAdd.denom_in_max_b max_size:9 +OsmosisMsgLPAdd.denom_in_max_a max_size:69 +OsmosisMsgLPAdd.denom_in_max_b max_size:69 OsmosisMsgLPRemove.sender max_size:53 OsmosisMsgLPRemove.pool_id max_size:129 -OsmosisMsgLPRemove.denom_out_min_a max_size:9 -OsmosisMsgLPRemove.denom_out_min_b max_size:9 +OsmosisMsgLPRemove.denom_out_min_a max_size:69 +OsmosisMsgLPRemove.denom_out_min_b max_size:69 OsmosisMsgLPStake.owner max_size:53 -OsmosisMsgLPStake.denom max_size:9 +OsmosisMsgLPStake.denom max_size:69 OsmosisMsgLPUnstake.owner max_size:53 OsmosisMsgLPUnstake.id max_size:129 @@ -49,12 +49,12 @@ OsmosisMsgIBCTransfer.source_channel max_size:32 OsmosisMsgIBCTransfer.source_port max_size:32 OsmosisMsgIBCTransfer.revision_height max_size:16 OsmosisMsgIBCTransfer.revision_number max_size:9 -OsmosisMsgIBCTransfer.denom max_size:9 +OsmosisMsgIBCTransfer.denom max_size:69 OsmosisMsgSwap.sender max_size:53 OsmosisMsgSwap.pool_id max_size:129 -OsmosisMsgSwap.token_out_denom max_size:9 -OsmosisMsgSwap.token_in_denom max_size:9 +OsmosisMsgSwap.token_out_denom max_size:69 +OsmosisMsgSwap.token_in_denom max_size:69 OsmosisSignedTx.public_key max_size:33 OsmosisSignedTx.signature max_size:64 \ No newline at end of file diff --git a/lib/firmware/fsm_msg_osmosis.h b/lib/firmware/fsm_msg_osmosis.h index 1a8ea2a50..8b3f22fed 100644 --- a/lib/firmware/fsm_msg_osmosis.h +++ b/lib/firmware/fsm_msg_osmosis.h @@ -74,7 +74,7 @@ void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg) { if (!msg->has_account_number || !msg->has_chain_id || !msg->has_fee_amount || !msg->has_gas || !msg->has_sequence) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Missing Fields On Message"); layoutHome(); @@ -91,9 +91,8 @@ void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg) { RESP_INIT(OsmosisMsgRequest); - if (!tendermint_signTxInit(node, (void *)msg, sizeof(OsmosisSignTx), - "uosmo")) { - tendermint_signAbort(); + if (!osmosis_signTxInit(node, msg)) { + osmosis_signAbort(); memzero(node, sizeof(*node)); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Failed to initialize transaction signing")); @@ -108,18 +107,18 @@ void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg) { void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { // Confirm transaction basics - CHECK_PARAM(tendermint_signingIsInited(), "Signing not in progress"); + CHECK_PARAM(osmosis_signingIsInited(), "Signing not in progress"); const CoinType *coin = fsm_getCoin(true, "Osmosis"); if (!coin) { return; } - const OsmosisSignTx *sign_tx = (OsmosisSignTx *)tendermint_getSignTx(); + const OsmosisSignTx *sign_tx = osmosis_getOsmosisSignTx(); if (msg->has_send) { if (!msg->send.has_to_address || !msg->send.has_amount) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Message is missing required parameters")); layoutHome(); @@ -132,15 +131,15 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm_transaction_output( ButtonRequestType_ButtonRequest_ConfirmOutput, amount_str, msg->send.to_address)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!tendermint_signTxUpdateMsgSend(msg->send.amount, msg->send.to_address, - "osmosis", "uosmo", "cosmos-sdk")) { - tendermint_signAbort(); + if (!osmosis_signTxUpdateMsgSend(msg->send.amount, msg->send.to_address, + msg->send.denom)) { + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include send message in transaction"); layoutHome(); @@ -150,7 +149,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { /** Confirm required transaction parameters exist */ if (!msg->delegate.has_delegator_address || !msg->delegate.has_validator_address || !msg->delegate.has_amount) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Message is missing required parameters")); layoutHome(); @@ -163,7 +162,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm_osmosis_address("Confirm delegator address", msg->delegate.delegator_address)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -171,7 +170,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm_osmosis_address("Confirm validator address", msg->delegate.validator_address)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -181,17 +180,16 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { &layout_notification_no_title_bold, ButtonRequestType_ButtonRequest_ConfirmOutput, "", "Delegate %s?", amount_str)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!tendermint_signTxUpdateMsgDelegate(msg->delegate.amount, - msg->delegate.delegator_address, - msg->delegate.validator_address, - "osmosis", "uosmo", "cosmos-sdk")) { - tendermint_signAbort(); + if (!osmosis_signTxUpdateMsgDelegate( + msg->delegate.amount, msg->delegate.delegator_address, + msg->delegate.validator_address, msg->delegate.denom)) { + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include delegate message in transaction"); layoutHome(); @@ -201,7 +199,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { /** Confirm required transaction parameters exist */ if (!msg->undelegate.has_delegator_address || !msg->undelegate.has_validator_address || !msg->undelegate.has_amount) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Message is missing required parameters")); layoutHome(); @@ -214,7 +212,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm_osmosis_address("Confirm delegator address", msg->undelegate.delegator_address)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -222,7 +220,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm_osmosis_address("Confirm validator address", msg->undelegate.validator_address)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -232,17 +230,16 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { &layout_notification_no_title_bold, ButtonRequestType_ButtonRequest_ConfirmOutput, "", "Undelegate %s?", amount_str)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!tendermint_signTxUpdateMsgUndelegate( + if (!osmosis_signTxUpdateMsgUndelegate( msg->undelegate.amount, msg->undelegate.delegator_address, - msg->undelegate.validator_address, "osmosis", "uosmo", - "cosmos-sdk")) { - tendermint_signAbort(); + msg->undelegate.validator_address, msg->undelegate.denom)) { + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include undelegate message in transaction"); layoutHome(); @@ -254,7 +251,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { !msg->lp_add.has_share_out_amount || !msg->lp_add.has_denom_in_max_a || !msg->lp_add.has_amount_in_max_a || !msg->lp_add.has_denom_in_max_b || !msg->lp_add.has_amount_in_max_b) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Message is missing required parameters")); layoutHome(); @@ -262,20 +259,28 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } /** Confirm transaction parameters on-screen */ - char amount_str_a[32]; - char denom_str_a[12]; + char amount_str_a[86]; + char denom_str_a[70]; sprintf(denom_str_a, " %s", msg->lp_add.denom_in_max_a); bn_format_uint64(msg->lp_add.amount_in_max_a, NULL, denom_str_a, 6, 0, false, amount_str_a, sizeof(amount_str_a)); - char amount_str_b[32]; - char denom_str_b[12]; + char amount_str_b[86]; + char denom_str_b[70]; sprintf(denom_str_b, " %s", msg->lp_add.denom_in_max_b); bn_format_uint64(msg->lp_add.amount_in_max_b, NULL, denom_str_b, 6, 0, false, amount_str_b, sizeof(amount_str_b)); if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", - "Deposit %s and %s?", amount_str_a, amount_str_b)) { - tendermint_signAbort(); + "Deposit %s and...", amount_str_a)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", + "... %s?", amount_str_b)) { + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -283,27 +288,26 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", "%s", msg->lp_add.pool_id)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - // TODO: Should this be a percentage? If so, multiply by 100 and add percent - // sign - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Pool share amount", - "%llu", msg->lp_add.share_out_amount)) { - tendermint_signAbort(); + if (!confirm( + ButtonRequestType_ButtonRequest_Other, "Pool share amount", + "Receive %.19f LP shares?", + (double)msg->lp_add.share_out_amount / 1000000000000000000.0f)) { + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - // TODO: Create signTxUpdateMsgLPAdd function if (!osmosis_signTxUpdateMsgLPAdd(msg->lp_add)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include rewards message in transaction"); + "Failed to include LP add message in transaction"); layoutHome(); return; } @@ -315,7 +319,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { !msg->lp_remove.has_amount_out_min_a || !msg->lp_remove.has_denom_out_min_b || !msg->lp_remove.has_amount_out_min_b) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Message is missing required parameters")); layoutHome(); @@ -323,20 +327,28 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } /** Confirm transaction parameters on-screen */ - char amount_str_a[32]; - char denom_str_a[12]; + char amount_str_a[86]; + char denom_str_a[70]; sprintf(denom_str_a, " %s", msg->lp_remove.denom_out_min_a); bn_format_uint64(msg->lp_remove.amount_out_min_a, NULL, denom_str_a, 6, 0, false, amount_str_a, sizeof(amount_str_a)); - char amount_str_b[32]; - char denom_str_b[12]; + char amount_str_b[86]; + char denom_str_b[70]; sprintf(denom_str_b, " %s", msg->lp_remove.denom_out_min_b); bn_format_uint64(msg->lp_remove.amount_out_min_b, NULL, denom_str_b, 6, 0, false, amount_str_b, sizeof(amount_str_b)); if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", - "Withdraw %s and %s?", amount_str_a, amount_str_b)) { - tendermint_signAbort(); + "Withdraw %s and...", amount_str_a)) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", + "... %s?", amount_str_b)) { + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -344,24 +356,24 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", "%s", msg->lp_remove.pool_id)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - // TODO: Should this be a percentage? If so, multiply by 100 and add percent - // sign - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Pool share amount", - "%llu", msg->lp_remove.share_out_amount)) { - tendermint_signAbort(); + if (!confirm( + ButtonRequestType_ButtonRequest_Other, "Pool share amount", + "Redeem %.19f LP shares?", + (double)msg->lp_remove.share_out_amount / 1000000000000000000.0f)) { + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } if (!osmosis_signTxUpdateMsgLPRemove(msg->lp_remove)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include rewards message in transaction"); layoutHome(); @@ -373,7 +385,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { /** Confirm required transaction parameters exist */ if (!msg->lp_stake.has_owner || !msg->lp_stake.has_duration || !msg->lp_stake.has_denom || !msg->lp_stake.has_amount) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Message is missing required parameters")); layoutHome(); @@ -393,7 +405,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { lockup_duration = supported_lockup_durations[2]; break; default: - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Unsupported lockup duration")); layoutHome(); @@ -401,22 +413,22 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } /** Confirm transaction parameters on-screen */ - char amount_str[32]; - char denom_str[12]; + char amount_str[86]; + char denom_str[70]; sprintf(denom_str, " %s", msg->lp_stake.denom); bn_format_uint64(msg->lp_stake.amount, NULL, denom_str, 6, 0, false, amount_str, sizeof(amount_str)); if (!confirm(ButtonRequestType_ButtonRequest_Other, "Lock Tokens", "Lock %s tokens for %s?", amount_str, lockup_duration)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } if (!osmosis_signTxUpdateMsgLPStake(msg->lp_stake)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include lp stake message in transaction"); layoutHome(); @@ -425,7 +437,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } else if (msg->has_lp_unstake) { /** Confirm required transaction parameters exist */ if (!msg->lp_unstake.has_owner || !msg->lp_unstake.has_id) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Message is missing required parameters")); layoutHome(); @@ -434,14 +446,14 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm(ButtonRequestType_ButtonRequest_Other, "Unlock Tokens", "Begin unbonding time for all bonded tokens in all pools?")) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } if (!osmosis_signTxUpdateMsgLPUnstake(msg->lp_unstake)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include lp_unstake message in transaction"); layoutHome(); @@ -453,7 +465,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { !msg->redelegate.has_validator_src_address || !msg->redelegate.has_validator_dst_address || !msg->redelegate.has_amount) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Message is missing required parameters")); layoutHome(); @@ -466,7 +478,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm(ButtonRequestType_ButtonRequest_Other, "Redelegate", "Redelegate %s?", amount_str)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -474,7 +486,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm_osmosis_address("Delegator address", msg->redelegate.delegator_address)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -482,7 +494,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm_osmosis_address("Validator source address", msg->redelegate.validator_src_address)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -490,18 +502,17 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm_osmosis_address("Validator dest. address", msg->redelegate.validator_dst_address)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!tendermint_signTxUpdateMsgRedelegate( + if (!osmosis_signTxUpdateMsgRedelegate( msg->redelegate.amount, msg->redelegate.delegator_address, msg->redelegate.validator_src_address, - msg->redelegate.validator_dst_address, "osmosis", "uosmo", - "cosmos-sdk")) { - tendermint_signAbort(); + msg->redelegate.validator_dst_address, msg->redelegate.denom)) { + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include redelegate message in transaction"); layoutHome(); @@ -511,7 +522,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { /** Confirm required transaction parameters exist */ if (!msg->rewards.has_delegator_address || !msg->rewards.has_validator_address) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Message is missing required parameters")); layoutHome(); @@ -526,7 +537,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", "Claim %s?", amount_str)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -534,7 +545,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } else { if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", "Claim all available rewards?")) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -543,7 +554,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm_osmosis_address("Confirm delegator address", msg->rewards.delegator_address)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -551,17 +562,17 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm_osmosis_address("Confirm validator address", msg->rewards.validator_address)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!tendermint_signTxUpdateMsgRewards( + if (!osmosis_signTxUpdateMsgRewards( msg->rewards.has_amount ? &msg->rewards.amount : NULL, msg->rewards.delegator_address, msg->rewards.validator_address, - "osmosis", "uosmo", "cosmos-sdk")) { - tendermint_signAbort(); + msg->rewards.denom)) { + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include rewards message in transaction"); layoutHome(); @@ -573,7 +584,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { !msg->swap.has_pool_id | !msg->swap.has_token_out_denom || !msg->swap.has_token_in_denom || !msg->swap.has_token_in_amount || !msg->swap.has_token_out_min_amount) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Message is missing required parameters")); layoutHome(); @@ -581,13 +592,13 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } /** Confirm transaction parameters on-screen */ - char token_in_amount_str[32]; - char token_in_denom_str[12]; + char token_in_amount_str[86]; + char token_in_denom_str[70]; sprintf(token_in_denom_str, " %s", msg->swap.token_in_denom); bn_format_uint64(msg->swap.token_in_amount, NULL, token_in_denom_str, 6, 0, false, token_in_amount_str, sizeof(token_in_amount_str)); - char token_out_amount_str[32]; - char token_out_denom_str[12]; + char token_out_amount_str[86]; + char token_out_denom_str[70]; sprintf(token_out_denom_str, " %s", msg->swap.token_out_denom); bn_format_uint64(msg->swap.token_out_min_amount, NULL, token_out_denom_str, 6, 0, false, token_out_amount_str, @@ -596,7 +607,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm(ButtonRequestType_ButtonRequest_Other, "Swap", "Swap %s for at least %s?", token_in_amount_str, token_out_amount_str)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -604,14 +615,14 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", "%s", msg->swap.pool_id)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } if (!osmosis_signTxUpdateMsgSwap(msg->swap)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include swap message in transaction"); layoutHome(); @@ -626,7 +637,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { !msg->ibc_transfer.has_revision_height || !msg->ibc_transfer.has_revision_number || !msg->ibc_transfer.has_denom) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Message is missing required parameters")); layoutHome(); @@ -639,7 +650,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Transfer", "Transfer %s to %s?", amount_str, msg->ibc_transfer.sender)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -648,7 +659,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Source Channel", "%s", msg->ibc_transfer.source_channel)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -656,7 +667,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Source Port", "%s", msg->ibc_transfer.source_port)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -665,7 +676,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Revision Height", "%s", msg->ibc_transfer.revision_height)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -674,33 +685,32 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Revision Number", "%s", msg->ibc_transfer.revision_number)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!tendermint_signTxUpdateMsgIBCTransfer( + if (!osmosis_signTxUpdateMsgIBCTransfer( msg->ibc_transfer.amount, msg->ibc_transfer.sender, msg->ibc_transfer.receiver, msg->ibc_transfer.source_channel, msg->ibc_transfer.source_port, msg->ibc_transfer.revision_number, - msg->ibc_transfer.revision_height, "osmosis", "uosmo", - "cosmos-sdk")) { - tendermint_signAbort(); + msg->ibc_transfer.revision_height, msg->ibc_transfer.denom)) { + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include IBC transfer message in transaction"); layoutHome(); return; } } else { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Invalid Osmosis message type")); layoutHome(); return; } - if (!tendermint_signingIsFinished()) { + if (!osmosis_signingIsFinished()) { RESP_INIT(OsmosisMsgRequest); msg_write(MessageType_MessageType_OsmosisMsgRequest, resp); return; @@ -709,7 +719,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (sign_tx->has_memo && (strlen(sign_tx->memo) > 0)) { if (!confirm(ButtonRequestType_ButtonRequest_ConfirmMemo, _("Memo"), "%s", sign_tx->memo)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -728,9 +738,9 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm(ButtonRequestType_ButtonRequest_SignTx, node_str, "Sign this Osmosis transaction on %s? " - "It includes a fee of %" PRIu32 " uATOM and %" PRIu32 " gas.", + "It includes a fee of %" PRIu32 " uOSMO and %" PRIu32 " gas.", sign_tx->chain_id, sign_tx->fee_amount, sign_tx->gas)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; @@ -740,7 +750,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!tendermint_signTxFinalize(resp->public_key.bytes, resp->signature.bytes)) { - tendermint_signAbort(); + osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to finalize signature"); layoutHome(); @@ -751,7 +761,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { resp->has_public_key = true; resp->signature.size = 64; resp->has_signature = true; - tendermint_signAbort(); + osmosis_signAbort(); layoutHome(); msg_write(MessageType_MessageType_OsmosisSignedTx, resp); } \ No newline at end of file diff --git a/lib/firmware/messagemap.def b/lib/firmware/messagemap.def index f6f05c892..6097a49e0 100644 --- a/lib/firmware/messagemap.def +++ b/lib/firmware/messagemap.def @@ -50,7 +50,7 @@ MSG_IN(MessageType_MessageType_CosmosSignTx, CosmosSignTx, fsm_msgCosmosSignTx) MSG_IN(MessageType_MessageType_CosmosMsgAck, CosmosMsgAck, fsm_msgCosmosMsgAck) - MSG_IN(MessageType_MessageType_OsmosisGetAddress, OsmosisGetAddress, fsm_msgOsmosisGetAddress) + MSG_IN(MessageType_MessageType_OsmosisGetAddress, OsmosisGetAddress, fsm_msgOsmosisGetAddress) MSG_IN(MessageType_MessageType_OsmosisSignTx, OsmosisSignTx, fsm_msgOsmosisSignTx) MSG_IN(MessageType_MessageType_OsmosisMsgAck, OsmosisMsgAck, fsm_msgOsmosisMsgAck) diff --git a/lib/firmware/osmosis.c b/lib/firmware/osmosis.c index ead49966c..9a5755c47 100644 --- a/lib/firmware/osmosis.c +++ b/lib/firmware/osmosis.c @@ -31,15 +31,72 @@ #include #include +static CONFIDENTIAL HDNode node; static SHA256_CTX ctx; +static bool initialized; static uint32_t msgs_remaining; static OsmosisSignTx msg; +static bool testnet; const OsmosisSignTx *osmosis_getOsmosisSignTx(void) { return &msg; } -bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd msglpadd) { +bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg) { + initialized = true; + msgs_remaining = _msg->msg_count; + testnet = false; + + if (_msg->has_testnet) { + testnet = _msg->testnet; + } + + memzero(&node, sizeof(node)); + memcpy(&node, _node, sizeof(node)); + memcpy(&msg, _msg, sizeof(msg)); + + bool success = true; char buffer[64 + 1]; + sha256_Init(&ctx); + + // Each segment guaranteed to be less than or equal to 64 bytes + // 19 + ^20 + 1 = ^40 + if (!tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "{\"account_number\":\"%" PRIu64 "\"", + msg.account_number)) + return false; + + // + const char *const chainid_prefix = ",\"chain_id\":\""; + sha256_Update(&ctx, (uint8_t *)chainid_prefix, strlen(chainid_prefix)); + tendermint_sha256UpdateEscaped(&ctx, msg.chain_id, strlen(msg.chain_id)); + + // 30 + ^10 + 19 = ^59 + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\",\"fee\":{\"amount\":[{\"amount\":\"%" PRIu32 + "\",\"denom\":\"uosmo\"}]", + msg.fee_amount); + + // 8 + ^10 + 2 = ^20 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"gas\":\"%" PRIu32 "\"}", msg.gas); + + // + const char *const memo_prefix = ",\"memo\":\""; + sha256_Update(&ctx, (uint8_t *)memo_prefix, strlen(memo_prefix)); + if (msg.has_memo) { + tendermint_sha256UpdateEscaped(&ctx, msg.memo, strlen(msg.memo)); + } + + // 10 + sha256_Update(&ctx, (uint8_t *)"\",\"msgs\":[", 10); + + return success; +} + +bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd msglpadd) { + char buffer[96 + 1]; + bool success = true; const char *const prelude = @@ -47,21 +104,21 @@ bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd msglpadd) { sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"poolId\":\"%s\",", msglpadd.pool_id); + "\"pool_id\":\"%s\",", msglpadd.pool_id); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", msglpadd.sender); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"shareOutAmount\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"share_out_amount\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", msglpadd.share_out_amount); success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenInMaxs\":[{"); + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"token_in_maxs\":[{"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":\"%" PRIu64 "\",", @@ -82,7 +139,7 @@ bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd msglpadd) { } bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove msglpremove) { - char buffer[64 + 1]; + char buffer[96 + 1]; bool success = true; @@ -90,7 +147,7 @@ bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove msglpremove) { "{\"type\":\"osmosis/gamm/exit-pool\",\"value\":{"; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"poolId\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"pool_id\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", msglpremove.pool_id); @@ -100,15 +157,15 @@ bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove msglpremove) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", msglpremove.sender); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"shareOutAmount\":"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"share_out_amount\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", msglpremove.share_out_amount); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenOutMins\":[{"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token_out_mins\":[{"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":\"%" PRIu64 "\",", @@ -131,7 +188,7 @@ bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove msglpremove) { } bool osmosis_signTxUpdateMsgLPStake(const OsmosisMsgLPStake msgstake) { - char buffer[64 + 1]; + char buffer[96 + 1]; bool success = true; @@ -161,7 +218,7 @@ bool osmosis_signTxUpdateMsgLPStake(const OsmosisMsgLPStake msgstake) { } bool osmosis_signTxUpdateMsgLPUnstake(const OsmosisMsgLPUnstake msgunstake) { - char buffer[64 + 1]; + char buffer[96 + 1]; bool success = true; @@ -180,7 +237,7 @@ bool osmosis_signTxUpdateMsgLPUnstake(const OsmosisMsgLPUnstake msgunstake) { } bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap msgswap) { - char buffer[64 + 1]; + char buffer[96 + 1]; bool success = true; @@ -190,26 +247,437 @@ bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap msgswap) { success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"routes\":[{"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"poolId\":%s\",", msgswap.pool_id); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"tokenOutDenom\":%s\"}],", msgswap.token_out_denom); + "\"pool_id\":%s\",", msgswap.pool_id); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token_out_denom\":%s\"}],", + msgswap.token_out_denom); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", msgswap.sender); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"tokenIn\":{"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"token_in\":{"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"amount\":%" PRIu64 "\",", msgswap.token_in_amount); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":\"%s\"},", msgswap.token_in_denom); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"tokenOutMinAmount\":\"%" PRIu64 "\"}}", + "\"token_out_min_amount\":\"%" PRIu64 "\"}}", msgswap.token_out_min_amount); msgs_remaining--; return success; } + +bool osmosis_signTxUpdateMsgSend(const uint64_t amount, const char *to_address, + const char *denom) { + char mainnetp[] = "osmo"; + char testnetp[] = "tosmo"; + char *pfix; + char buffer[64 + 1]; + + size_t decoded_len; + char hrp[45]; + uint8_t decoded[38]; + if (!bech32_decode(hrp, decoded, &decoded_len, to_address)) { + return false; + } + + char from_address[46]; + + pfix = mainnetp; + if (testnet) { + pfix = testnetp; + } + + if (!tendermint_getAddress(&node, pfix, from_address)) { + return false; + } + + bool success = true; + + const char *const prelude = "{\"type\":\"cosmos-sdk/MsgSend\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + // 21 + ^20 + 19 = ^60 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":[{\"amount\":\"%" PRIu64 + "\",\"denom\":\"%s\"}]", + amount, denom); + + // 17 + 45 + 1 = 63 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"from_address\":\"%s\"", from_address); + + // 15 + 45 + 3 = 63 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"to_address\":\"%s\"}}", to_address); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgDelegate(const uint64_t amount, + const char *delegator_address, + const char *validator_address, + const char *denom) { + char mainnetp[] = "osmo"; + char testnetp[] = "tosmo"; + char *pfix; + + char buffer[128]; + size_t decoded_len; + char hrp[45]; + uint8_t decoded[38]; + + if (!bech32_decode(hrp, decoded, &decoded_len, delegator_address)) { + return false; + } + + // ^14 + 39 + 1 = ^54 + char from_address[54]; + + pfix = mainnetp; + if (testnet) { + pfix = testnetp; + } + + if (!tendermint_getAddress(&node, pfix, from_address)) { + return false; + } + + bool success = true; + + // 9 + ^24 + 23 = ^56 + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "{\"type\":\"cosmos-sdk/MsgDelegate\",\"value\":{"); + + // 20 + ^20 + 11 + ^9 + 2 = ^62 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\"%" PRIu64 + "\",\"denom\":\"%s\"}", + amount, denom); + + // 22 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"delegator_address\":\""); + + // ^53 + 3 = ^56 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s\",\"", + delegator_address); + + // 20 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "validator_address\":\""); + + // ^53 + 3 = ^56 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s\"}}", + validator_address); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgUndelegate(const uint64_t amount, + const char *delegator_address, + const char *validator_address, + const char *denom) { + char mainnetp[] = "osmo"; + char testnetp[] = "tosmo"; + char *pfix; + + char buffer[128]; + size_t decoded_len; + char hrp[45]; + uint8_t decoded[38]; + + if (!bech32_decode(hrp, decoded, &decoded_len, delegator_address)) { + return false; + } + + // ^14 + 39 + 1 = ^54 + char from_address[54]; + + pfix = mainnetp; + if (testnet) { + pfix = testnetp; + } + if (!tendermint_getAddress(&node, pfix, from_address)) { + return false; + } + + bool success = true; + + // 9 + ^24 + 25 = ^58 + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "{\"type\":\"cosmos-sdk/MsgUndelegate\",\"value\":{"); + + // 20 + ^20 + 11 + ^9 + 2 = ^62 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\"%" PRIu64 + "\",\"denom\":\"%s\"}", + amount, denom); + + // 22 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"delegator_address\":\""); + + // ^53 + 3 = ^56 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s\",\"", + delegator_address); + + // 20 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "validator_address\":\""); + + // ^53 + 3 = ^56 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s\"}}", + validator_address); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgRedelegate(const uint64_t amount, + const char *delegator_address, + const char *validator_src_address, + const char *validator_dst_address, + const char *denom) { + char mainnetp[] = "osmo"; + char testnetp[] = "tosmo"; + char *pfix; + + char buffer[128]; + size_t decoded_len; + char hrp[45]; + uint8_t decoded[38]; + + if (!bech32_decode(hrp, decoded, &decoded_len, delegator_address)) { + return false; + } + + // ^14 + 39 + 1 = ^54 + char from_address[54]; + pfix = mainnetp; + if (testnet) { + pfix = testnetp; + } + if (!tendermint_getAddress(&node, pfix, from_address)) { + return false; + } + + bool success = true; + + // 9 + ^24 + 28 = ^64 + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "{\"type\":\"cosmos-sdk/MsgBeginRedelegate\",\"value\""); + + // 22 + ^20 + 11 + ^9 + 2 = ^64 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ":{\"amount\":{\"amount\":\"%" PRIu64 + "\",\"denom\":\"%s\"}", + amount, denom); + + // 22 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"delegator_address\":\""); + + // ^53 + 1 = ^54 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s", + delegator_address); + + // 27 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\",\"validator_dst_address\":\""); + + // ^53 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s", + validator_dst_address); + + // 27 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\",\"validator_src_address\":\""); + + // ^53 + 3 = ^56 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s\"}}", + validator_src_address); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgRewards(const uint64_t *amount, + const char *delegator_address, + const char *validator_address, + const char *denom) { + char mainnetp[] = "osmo"; + char testnetp[] = "tosmo"; + char *pfix; + + char buffer[128]; + size_t decoded_len; + char hrp[45]; + uint8_t decoded[38]; + + if (!bech32_decode(hrp, decoded, &decoded_len, delegator_address)) { + return false; + } + + pfix = mainnetp; + if (testnet) { + pfix = testnetp; + } + + // ^14 + 39 + 1 = ^54 + char from_address[54]; + if (!tendermint_getAddress(&node, pfix, from_address)) { + return false; + } + + bool success = true; + + // 9 + ^24 + 38 = ^72 + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "{\"type\":\"cosmos-sdk/MsgWithdrawDelegationReward\",\"value\":{"); + + // 20 + ^20 + 11 + ^9 + 3 = ^65 + if (amount != NULL) { + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\"%" PRIu64 + "\",\"denom\":\"%s\"},", + *amount, denom); + } + + // 21 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"delegator_address\":\""); + + // ^53 + 3 = ^56 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s\",\"", + delegator_address); + + // 20 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "validator_address\":\""); + + // ^53 + 3 = ^56 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s\"}}", + validator_address); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgIBCTransfer( + const uint64_t amount, const char *sender, const char *receiver, + const char *source_channel, const char *source_port, + const char *revision_number, const char *revision_height, + const char *denom) { + char mainnetp[] = "osmo"; + char testnetp[] = "tosmo"; + char *pfix; + + char buffer[128]; + size_t decoded_len; + char hrp[45]; + uint8_t decoded[38]; + + if (!bech32_decode(hrp, decoded, &decoded_len, receiver)) { + return false; + } + + pfix = mainnetp; + if (testnet) { + pfix = testnetp; + } + + // ^14 + 39 + 1 = ^54 + char from_address[54]; + if (!tendermint_getAddress(&node, pfix, from_address)) { + return false; + } + + bool success = true; + + // 9 + ^24 + 23 = ^56 + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "{\"type\":\"cosmos-sdk/MsgTransfer\",\"value\":{"); + + // 13 + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"receiver\":\""); + + // ^53 + 1 = ^54 + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s\"", receiver); + + // 11 + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), ",\"sender\":\""); + + // ^53 + 1 = ^54 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "%s\"", sender); + + // 19 + ^32 + 1 = ^52 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"source_channel\":\"%s\"", source_channel); + + // 16 + ^32 + 2 = ^40 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + ",\"source_port\":\"%s\",", source_port); + + // 37 + ^16 = ^53 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"timeout_height\":{\"revision_height\":\"%s", + revision_height); + + // 21 + ^9 + 3 = ^33 + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\",\"revision_number\":\"%s\"},", revision_number); + + // 20 + ^20 + 11 + ^9 + 3 = ^63 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token\":{\"amount\":\"%" PRIu64 + "\",\"denom\":\"%s\"}}}", + amount, denom); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature) { + char buffer[64 + 1]; + + // 16 + ^20 = ^36 + if (!tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "],\"sequence\":\"%" PRIu64 "\"}", msg.sequence)) + return false; + + hdnode_fill_public_key(&node); + memcpy(public_key, node.public_key, 33); + + uint8_t hash[SHA256_DIGEST_LENGTH]; + sha256_Final(&ctx, hash); + return ecdsa_sign_digest(&secp256k1, node.private_key, hash, signature, NULL, + NULL) == 0; +} + +bool osmosis_signingIsInited(void) { return initialized; } + +bool osmosis_signingIsFinished(void) { return msgs_remaining == 0; } + +void osmosis_signAbort(void) { + initialized = false; + msgs_remaining = 0; + memzero(&msg, sizeof(msg)); + memzero(&node, sizeof(node)); +} From 4ca7d94440638dc8505a1f8440a3528c97747f38 Mon Sep 17 00:00:00 2001 From: pastaghost Date: Fri, 16 Dec 2022 11:07:08 -0700 Subject: [PATCH 15/23] fix: reorder fee parameters --- lib/firmware/osmosis.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/firmware/osmosis.c b/lib/firmware/osmosis.c index 9a5755c47..934a0e836 100644 --- a/lib/firmware/osmosis.c +++ b/lib/firmware/osmosis.c @@ -70,16 +70,15 @@ bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg) { sha256_Update(&ctx, (uint8_t *)chainid_prefix, strlen(chainid_prefix)); tendermint_sha256UpdateEscaped(&ctx, msg.chain_id, strlen(msg.chain_id)); - // 30 + ^10 + 19 = ^59 - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\",\"fee\":{\"amount\":[{\"amount\":\"%" PRIu32 - "\",\"denom\":\"uosmo\"}]", - msg.fee_amount); + // 16 + ^10 + 2 = ^28 + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\",\"fee\":{\"gas\":\"%" PRIu32 "\",", msg.gas); - // 8 + ^10 + 2 = ^20 + // + ^10 + 19 = ^59 success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - ",\"gas\":\"%" PRIu32 "\"}", msg.gas); + "\"amount\":[{\"amount\":\"%" PRIu32 + "\",\"denom\":\"uosmo\"}]}", + msg.fee_amount); // const char *const memo_prefix = ",\"memo\":\""; From 804fae2f4632e2cf481cbfdb416d7c1f2b3f2de8 Mon Sep 17 00:00:00 2001 From: pastaghost Date: Fri, 16 Dec 2022 11:07:16 -0700 Subject: [PATCH 16/23] chore: update dependencies --- deps/device-protocol | 2 +- deps/python-keepkey | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/device-protocol b/deps/device-protocol index a12f0b243..82ec74705 160000 --- a/deps/device-protocol +++ b/deps/device-protocol @@ -1 +1 @@ -Subproject commit a12f0b243a1d8f8283dbca8ecff0862ce4d521b5 +Subproject commit 82ec74705e5798580b532fac02fbbe5f5740f1e2 diff --git a/deps/python-keepkey b/deps/python-keepkey index 4a1ee20c9..4b4cfcba3 160000 --- a/deps/python-keepkey +++ b/deps/python-keepkey @@ -1 +1 @@ -Subproject commit 4a1ee20c99819f86268040f61ba290230471f3d7 +Subproject commit 4b4cfcba323bd9bd6eea0e517220317c798a0e19 From f6db02b73b33423e2af94c9926f32231cbd34a92 Mon Sep 17 00:00:00 2001 From: pastaghost Date: Tue, 17 Jan 2023 00:37:40 -0700 Subject: [PATCH 17/23] chore: version bump --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8d92c6c0..465ec8205 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.7.2) project( KeepKeyFirmware - VERSION 7.6.0 + VERSION 7.7.0 LANGUAGES C CXX ASM) set(BOOTLOADER_MAJOR_VERSION 2) From ff6b06b74bc0e4e51d1aacf2dee9b6110cf2cc7d Mon Sep 17 00:00:00 2001 From: pastaghost Date: Tue, 21 Feb 2023 20:02:44 -0700 Subject: [PATCH 18/23] chore: update submodule --- deps/device-protocol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/device-protocol b/deps/device-protocol index 82ec74705..ed06392ad 160000 --- a/deps/device-protocol +++ b/deps/device-protocol @@ -1 +1 @@ -Subproject commit 82ec74705e5798580b532fac02fbbe5f5740f1e2 +Subproject commit ed06392ad973bec129e0ccc0b7c427391834b359 From cac942c60cb1db8db7a151098b43b519d158ff8e Mon Sep 17 00:00:00 2001 From: pastaghost Date: Tue, 21 Feb 2023 20:05:51 -0700 Subject: [PATCH 19/23] feat: add OSMO to coins table --- include/keepkey/firmware/coins.def | 3 ++- lib/firmware/coins.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/keepkey/firmware/coins.def b/include/keepkey/firmware/coins.def index dce436626..1817b6bde 100644 --- a/include/keepkey/firmware/coins.def +++ b/include/keepkey/firmware/coins.def @@ -39,11 +39,12 @@ X(true, "LTC Testnet", true, "tLTC", true, 48, true, 1000000, true, 5 X(true, ETHEREUM_TST, true, "tETH", true, NA, true, 100000, true, NA, true, "Ethereum Signed Message:\n", true, 0x80000001, true, 1, true, 18, false, NO_CONTRACT, false, 0, true, false, true, false, true, SECP256K1_STRING, false, "", false, "", false, false, false, 0, false, 0, false, "" ) X(true, "Binance", true, "BEP2", false, NA, false, NA, false, NA, false, {0}, true, 0x800002ca, false, 0, true, 8, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", true, "bnb", false, false, false, 0, false, 0, false, "" ) X(true, "Cosmos", true, "ATOM", false, NA, false, NA, false, NA, false, {0}, true, 0x80000076, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "cosmos", false, false, false, 0, false, 0, false, "" ) +X(true, "Osmosis", true, "OSMO", false, NA, false, NA, false, NA, false, {0}, true, 0x80000076, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "osmo", false, false, false, 0, false, 0, false, "" ) X(true, "Ripple", true, "Ripple",false, 0, false, 0, false, 0, false, {0}, true, 0x80000090, false, 0, false, 0, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "", false, false, true, 77429938, true, 78792518, false, "" ) X(true, "THORChain", true, "RUNE", false, NA, false, NA, false, NA, false, {0}, true, 0x800003a3, false, 0, true, 8, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "thor", false, false, false, 0, false, 0, false, "" ) X(true, "Terra", true, "LUNA", false, NA, false, NA, false, NA, false, {0}, true, 0x8000014a, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "terra", false, false, false, 0, false, 0, false, "" ) X(true, "Kava", true, "KAVA", false, NA, false, NA, false, NA, false, {0}, true, 0x800001cb, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "kava", false, false, false, 0, false, 0, false, "" ) X(true, "Secret", true, "SCRT", false, NA, false, NA, false, NA, false, {0}, true, 0x80000211, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "secret", false, false, false, 0, false, 0, false, "" ) -X(true, "Osmosis", true, "OSMO", false, NA, false, NA, false, NA, false, {0}, true, 0x80000076, false, 0, true, 6, false, NO_CONTRACT, false, 0, false, false, false, false, true, SECP256K1_STRING, false, "", false, "osmo", false, false, false, 0, false, 0, false, "" ) + #undef X #undef NO_CONTRACT diff --git a/lib/firmware/coins.c b/lib/firmware/coins.c index d71a2817f..1e29c1cc0 100644 --- a/lib/firmware/coins.c +++ b/lib/firmware/coins.c @@ -407,6 +407,8 @@ static const char *account_prefix(const CoinType *coin, bool isTendermint(const char *coin_name) { if (strcmp(coin_name, "Cosmos") == 0) return true; + if (strcmp(coin_name, "Osmosis") == 0) return true; + if (strcmp(coin_name, "Binance") == 0) return true; if (strcmp(coin_name, "THORChain") == 0) return true; From a99056d2cef5cc9f8fcbcb73244b45f26b12a73b Mon Sep 17 00:00:00 2001 From: pastaghost Date: Tue, 21 Feb 2023 20:06:22 -0700 Subject: [PATCH 20/23] feat: osmosis support verified --- include/keepkey/firmware/osmosis.h | 67 ++- include/keepkey/firmware/signtx_tendermint.h | 28 +- .../transport/messages-osmosis.options | 21 +- lib/firmware/app_layout.c | 4 +- lib/firmware/fsm_msg_osmosis.h | 198 +++---- lib/firmware/osmosis.c | 508 +++++++++--------- lib/firmware/signtx_tendermint.c | 3 +- 7 files changed, 403 insertions(+), 426 deletions(-) diff --git a/include/keepkey/firmware/osmosis.h b/include/keepkey/firmware/osmosis.h index 4b6f76023..340f018e8 100644 --- a/include/keepkey/firmware/osmosis.h +++ b/include/keepkey/firmware/osmosis.h @@ -14,46 +14,65 @@ typedef struct _OsmosisMsgLPStake OsmosisMsgLPStake; typedef struct _OsmosisMsgLPUnstake OsmosisMsgLPUnstake; typedef struct _OsmosisMsgSwap OsmosisMsgSwap; -bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg); - -bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd msglpadd); - -bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove msglpremove); - -bool osmosis_signTxUpdateMsgLPStake(const OsmosisMsgLPStake msgstake); +void debug_intermediate_hash(void); -bool osmosis_signTxUpdateMsgLPUnstake(const OsmosisMsgLPUnstake msgunstake); - -bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap msgswap); +bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg); -bool osmosis_signTxUpdateMsgSend(const uint64_t amount, const char *to_address, - const char *denom); +bool osmosis_signTxUpdateMsgSend(const char *amount, const char *to_address); -bool osmosis_signTxUpdateMsgDelegate(const uint64_t amount, +bool osmosis_signTxUpdateMsgDelegate(const char *amount, const char *delegator_address, const char *validator_address, const char *denom); -bool osmosis_signTxUpdateMsgUndelegate(const uint64_t amount, +bool osmosis_signTxUpdateMsgUndelegate(const char *amount, const char *delegator_address, const char *validator_address, const char *denom); -bool osmosis_signTxUpdateMsgRedelegate(const uint64_t amount, +bool osmosis_signTxUpdateMsgRedelegate(const char *amount, const char *delegator_address, const char *validator_src_address, const char *validator_dst_address, const char *denom); -bool osmosis_signTxUpdateMsgRewards(const uint64_t *amount, - const char *delegator_address, - const char *validator_address, - const char *denom); -bool osmosis_signTxUpdateMsgIBCTransfer( - const uint64_t amount, const char *sender, const char *receiver, - const char *source_channel, const char *source_port, - const char *revision_number, const char *revision_height, - const char *denom); +bool osmosis_signTxUpdateMsgLPAdd(const uint64_t pool_id, const char *sender, + const char *share_out_amount, + const char *amount_in_max_a, + const char *denom_in_max_a, + const char *amount_in_max_b, + const char *denom_in_max_b); + +bool osmosis_signTxUpdateMsgLPRemove(const uint64_t pool_id, const char *sender, + const char *share_out_amount, + const char *amount_out_min_a, + const char *denom_out_min_a, + const char *amount_out_min_b, + const char *denom_out_min_b); + +bool osmosis_signTxUpdateMsgLPStake(const char *amount, const char *denom, + const uint64_t duration, const char *owner); + +bool osmosis_signTxUpdateMsgLPUnstake(const char *id, const char *owner); + +bool osmosis_signTxUpdateMsgRewards(const char *delegator_address, + const char *validator_address); + +bool osmosis_signTxUpdateMsgIBCTransfer(const char *amount, const char *sender, + const char *receiver, + const char *source_channel, + const char *source_port, + const char *revision_number, + const char *revision_height, + const char *denom); + +bool osmosis_signTxUpdateMsgSwap(const uint64_t pool_id, + const char *token_out_denom, + const char *sender, + const char *token_in_amount, + const char *token_in_denom, + const char *token_out_min_amount); + bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature); bool osmosis_signingIsInited(void); bool osmosis_signingIsFinished(void); diff --git a/include/keepkey/firmware/signtx_tendermint.h b/include/keepkey/firmware/signtx_tendermint.h index 68a539974..8933e2d02 100644 --- a/include/keepkey/firmware/signtx_tendermint.h +++ b/include/keepkey/firmware/signtx_tendermint.h @@ -35,41 +35,15 @@ bool tendermint_signTxUpdateMsgRewards(const uint64_t *amount, const char *validator_address, const char *chainstr, const char *denom, const char *msgTypePrefix); -bool tendermint_signTxUpdateMsgLPAdd( - const char *sender, const char *pool_id, const uint64_t share_out_amount, - const char *denom_in_max_a, const uint64_t amount_in_max_a, - const char *denom_in_max_b, const uint64_t amount_in_max_b, - const char *chainstr, const char *denom, const char *msgTypePrefix); -bool tendermint_signTxUpdateMsgLPRemove( - const char *sender, const char *pool_id, const uint64_t share_out_amount, - const char *denom_out_min_a, const uint64_t amount_out_min_a, - const char *denom_out_min_b, const uint64_t amount_out_min_b, - const char *chainstr, const char *denom, const char *msgTypePrefix); -bool tendermint_signTxUpdateMsgLPStake(const char *owner, - const uint64_t duration, - const uint64_t amount, - const char *chainstr, const char *denom, - const char *msgTypePrefix); -bool tendermint_signTxUpdateMsgLPUnstake(const char *owner, const char *id, - const char *chainstr, - const char *denom, - const char *msgTypePrefix); bool tendermint_signTxUpdateMsgIBCTransfer( const uint64_t amount, const char *sender, const char *receiver, const char *source_channel, const char *source_port, const char *revision_number, const char *revision_height, const char *chainstr, const char *denom, const char *msgTypePrefix); -bool tendermint_signTxUpdateMsgSwap(const char *sender, const char *pool_id, - const char *token_out_denom, - const char *token_in_denom, - const uint64_t token_in_amount, - const uint64_t token_out_min_amount, - const char *chainstr, const char *denom, - const char *msgTypePrefix); bool tendermint_signTxFinalize(uint8_t *public_key, uint8_t *signature); bool tendermint_signingIsInited(void); bool tendermint_signingIsFinished(void); void tendermint_signAbort(void); const void *tendermint_getSignTx(void); -#endif +#endif \ No newline at end of file diff --git a/include/keepkey/transport/messages-osmosis.options b/include/keepkey/transport/messages-osmosis.options index a89404758..cf84163bb 100644 --- a/include/keepkey/transport/messages-osmosis.options +++ b/include/keepkey/transport/messages-osmosis.options @@ -7,38 +7,47 @@ OsmosisSignTx.chain_id max_size:32 OsmosisSignTx.memo max_size:256 OsmosisMsgSend.from_address max_size:53 -OsmosisMsgSend.to_address max_size:53 +OsmosisMsgSend.to_address max_size:53 OsmosisMsgSend.denom max_size:69 +OsmosisMsgSend.amount max_size:33 OsmosisMsgDelegate.delegator_address max_size:53 OsmosisMsgDelegate.validator_address max_size:53 OsmosisMsgDelegate.denom max_size:69 +OsmosisMsgDelegate.amount max_size:33 OsmosisMsgUndelegate.delegator_address max_size:53 OsmosisMsgUndelegate.validator_address max_size:53 OsmosisMsgUndelegate.denom max_size:69 +OsmosisMsgUndelegate.amount max_size:33 OsmosisMsgRedelegate.delegator_address max_size:53 OsmosisMsgRedelegate.validator_src_address max_size:53 OsmosisMsgRedelegate.validator_dst_address max_size:53 OsmosisMsgRedelegate.denom max_size:69 +OsmosisMsgRedelegate.amount max_size:33 +OsmosisMsgRedelegate.amount max_size:33 OsmosisMsgRewards.delegator_address max_size:53 OsmosisMsgRewards.validator_address max_size:53 -OsmosisMsgRewards.denom max_size:69 OsmosisMsgLPAdd.sender max_size:53 -OsmosisMsgLPAdd.pool_id max_size:129 OsmosisMsgLPAdd.denom_in_max_a max_size:69 OsmosisMsgLPAdd.denom_in_max_b max_size:69 +OsmosisMsgLPAdd.amount_in_max_a max_size:33 +OsmosisMsgLPAdd.amount_in_max_b max_size:33 +OsmosisMsgLPAdd.share_out_amount max_size:33 OsmosisMsgLPRemove.sender max_size:53 -OsmosisMsgLPRemove.pool_id max_size:129 OsmosisMsgLPRemove.denom_out_min_a max_size:69 OsmosisMsgLPRemove.denom_out_min_b max_size:69 +OsmosisMsgLPRemove.amount_out_min_a max_size:33 +OsmosisMsgLPRemove.amount_out_min_b max_size:33 +OsmosisMsgLPRemove.share_out_amount max_size:33 OsmosisMsgLPStake.owner max_size:53 OsmosisMsgLPStake.denom max_size:69 +OsmosisMsgLPStake.amount max_size:33 OsmosisMsgLPUnstake.owner max_size:53 OsmosisMsgLPUnstake.id max_size:129 @@ -50,11 +59,13 @@ OsmosisMsgIBCTransfer.source_port max_size:32 OsmosisMsgIBCTransfer.revision_height max_size:16 OsmosisMsgIBCTransfer.revision_number max_size:9 OsmosisMsgIBCTransfer.denom max_size:69 +OsmosisMsgIBCTransfer.amount max_size:33 OsmosisMsgSwap.sender max_size:53 -OsmosisMsgSwap.pool_id max_size:129 OsmosisMsgSwap.token_out_denom max_size:69 OsmosisMsgSwap.token_in_denom max_size:69 +OsmosisMsgSwap.token_in_amount max_size:33 +OsmosisMsgSwap.token_out_min_amount max_size:33 OsmosisSignedTx.public_key max_size:33 OsmosisSignedTx.signature max_size:64 \ No newline at end of file diff --git a/lib/firmware/app_layout.c b/lib/firmware/app_layout.c index dfa7e5dfe..6f431d74f 100644 --- a/lib/firmware/app_layout.c +++ b/lib/firmware/app_layout.c @@ -485,7 +485,7 @@ void layout_cosmos_address_notification(const char *desc, const char *address, * none */ void layout_osmosis_address_notification(const char *desc, const char *address, - NotificationType type) { + NotificationType type) { DrawableParams sp; const Font *address_font = get_body_font(); ; @@ -508,7 +508,7 @@ void layout_osmosis_address_notification(const char *desc, const char *address, sp.x = LEFT_MARGIN + 65; sp.color = BODY_COLOR; - draw_string(canvas, address_font, address, &sp, 140, + draw_string(canvas, address_font, address, &sp, 160, font_height(address_font) + BODY_FONT_LINE_PADDING); layout_address(address, QR_LARGE); diff --git a/lib/firmware/fsm_msg_osmosis.h b/lib/firmware/fsm_msg_osmosis.h index 8b3f22fed..720fa744a 100644 --- a/lib/firmware/fsm_msg_osmosis.h +++ b/lib/firmware/fsm_msg_osmosis.h @@ -11,13 +11,22 @@ void fsm_msgOsmosisGetAddress(const OsmosisGetAddress *msg) { } HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count, NULL); + char mainnet[] = "osmo"; + char testnet[] = "tosmo"; + char *pfix; + if (!node) { return; } hdnode_fill_public_key(node); - if (!tendermint_getAddress(node, "osmo", resp->address)) { + pfix = mainnet; + if (msg->has_testnet && msg->testnet) { + pfix = testnet; + } + + if (!tendermint_getAddress(node, pfix, resp->address)) { memzero(node, sizeof(*node)); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Can't encode address")); @@ -93,6 +102,7 @@ void fsm_msgOsmosisSignTx(const OsmosisSignTx *msg) { if (!osmosis_signTxInit(node, msg)) { osmosis_signAbort(); + memzero(node, sizeof(*node)); fsm_sendFailure(FailureType_Failure_FirmwareError, _("Failed to initialize transaction signing")); @@ -125,9 +135,8 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - char amount_str[32]; - bn_format_uint64(msg->send.amount, NULL, " OSMO", 6, 0, false, amount_str, - sizeof(amount_str)); + char amount_str[40]; + sprintf(amount_str, "%s OSMO", msg->send.amount); if (!confirm_transaction_output( ButtonRequestType_ButtonRequest_ConfirmOutput, amount_str, msg->send.to_address)) { @@ -137,14 +146,14 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!osmosis_signTxUpdateMsgSend(msg->send.amount, msg->send.to_address, - msg->send.denom)) { + if (!osmosis_signTxUpdateMsgSend(msg->send.amount, msg->send.to_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include send message in transaction"); layoutHome(); return; } + } else if (msg->has_delegate) { /** Confirm required transaction parameters exist */ if (!msg->delegate.has_delegator_address || @@ -156,10 +165,6 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } /** Confirm transaction parameters on-screen */ - char amount_str[32]; - bn_format_uint64(msg->delegate.amount, NULL, " OSMO", 6, 0, false, - amount_str, sizeof(amount_str)); - if (!confirm_osmosis_address("Confirm delegator address", msg->delegate.delegator_address)) { osmosis_signAbort(); @@ -178,8 +183,8 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm_with_custom_layout( &layout_notification_no_title_bold, - ButtonRequestType_ButtonRequest_ConfirmOutput, "", "Delegate %s?", - amount_str)) { + ButtonRequestType_ButtonRequest_ConfirmOutput, "", + "Delegate %s OSMO?", msg->delegate.amount)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); @@ -206,9 +211,6 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } /** Confirm transaction parameters on-screen */ - char amount_str[32]; - bn_format_uint64(msg->undelegate.amount, NULL, " OSMO", 6, 0, false, - amount_str, sizeof(amount_str)); if (!confirm_osmosis_address("Confirm delegator address", msg->undelegate.delegator_address)) { @@ -228,8 +230,8 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!confirm_with_custom_layout( &layout_notification_no_title_bold, - ButtonRequestType_ButtonRequest_ConfirmOutput, "", "Undelegate %s?", - amount_str)) { + ButtonRequestType_ButtonRequest_ConfirmOutput, "", + "Undelegate %s OSMO?", msg->undelegate.amount)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); @@ -259,19 +261,15 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } /** Confirm transaction parameters on-screen */ - char amount_str_a[86]; - char denom_str_a[70]; - sprintf(denom_str_a, " %s", msg->lp_add.denom_in_max_a); - bn_format_uint64(msg->lp_add.amount_in_max_a, NULL, denom_str_a, 6, 0, - false, amount_str_a, sizeof(amount_str_a)); - char amount_str_b[86]; - char denom_str_b[70]; - sprintf(denom_str_b, " %s", msg->lp_add.denom_in_max_b); - bn_format_uint64(msg->lp_add.amount_in_max_b, NULL, denom_str_b, 6, 0, - false, amount_str_b, sizeof(amount_str_b)); + char share_out_amount_buf[33] = {0}; + share_out_amount_buf[0] = msg->lp_add.share_out_amount[0]; + share_out_amount_buf[1] = '.'; + strncpy(&share_out_amount_buf[2], &msg->lp_add.share_out_amount[1], + (sizeof(share_out_amount_buf) / sizeof(char)) - 2); if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", - "Deposit %s and...", amount_str_a)) { + "Deposit %s %s and...", msg->lp_add.amount_in_max_a, + msg->lp_add.denom_in_max_a)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); @@ -279,32 +277,36 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", - "... %s?", amount_str_b)) { + "... %s %s?", msg->lp_add.amount_in_max_b, + msg->lp_add.denom_in_max_b)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", "%s", - msg->lp_add.pool_id)) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", + "%lld", msg->lp_add.pool_id)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm( - ButtonRequestType_ButtonRequest_Other, "Pool share amount", - "Receive %.19f LP shares?", - (double)msg->lp_add.share_out_amount / 1000000000000000000.0f)) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Pool share amount", + "Receive %s LP shares?", share_out_amount_buf)) { + // (double)msg->lp_add.share_out_amount / 1000000000000000000.0f)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgLPAdd(msg->lp_add)) { + if (!osmosis_signTxUpdateMsgLPAdd( + msg->lp_add.pool_id, msg->lp_add.sender, + msg->lp_add.share_out_amount, msg->lp_add.amount_in_max_a, + msg->lp_add.denom_in_max_a, msg->lp_add.amount_in_max_b, + msg->lp_add.denom_in_max_b)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include LP add message in transaction"); @@ -327,19 +329,15 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } /** Confirm transaction parameters on-screen */ - char amount_str_a[86]; - char denom_str_a[70]; - sprintf(denom_str_a, " %s", msg->lp_remove.denom_out_min_a); - bn_format_uint64(msg->lp_remove.amount_out_min_a, NULL, denom_str_a, 6, 0, - false, amount_str_a, sizeof(amount_str_a)); - char amount_str_b[86]; - char denom_str_b[70]; - sprintf(denom_str_b, " %s", msg->lp_remove.denom_out_min_b); - bn_format_uint64(msg->lp_remove.amount_out_min_b, NULL, denom_str_b, 6, 0, - false, amount_str_b, sizeof(amount_str_b)); + char share_out_amount_buf[33] = {0}; + share_out_amount_buf[0] = msg->lp_remove.share_out_amount[0]; + share_out_amount_buf[1] = '.'; + strncpy(&share_out_amount_buf[2], &msg->lp_remove.share_out_amount[1], + (sizeof(share_out_amount_buf) / sizeof(char)) - 2); if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", - "Withdraw %s and...", amount_str_a)) { + "Withdraw %s %s and...", msg->lp_remove.amount_out_min_a, + msg->lp_remove.denom_out_min_a)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); @@ -347,32 +345,35 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", - "... %s?", amount_str_b)) { + "... %s %s ?", msg->lp_remove.amount_out_min_b, + msg->lp_remove.denom_out_min_b)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", "%s", - msg->lp_remove.pool_id)) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", + "%lld", msg->lp_remove.pool_id)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm( - ButtonRequestType_ButtonRequest_Other, "Pool share amount", - "Redeem %.19f LP shares?", - (double)msg->lp_remove.share_out_amount / 1000000000000000000.0f)) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Pool share amount", + "Redeem %s LP shares?", share_out_amount_buf)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgLPRemove(msg->lp_remove)) { + if (!osmosis_signTxUpdateMsgLPRemove( + msg->lp_remove.pool_id, msg->lp_remove.sender, + msg->lp_remove.share_out_amount, msg->lp_remove.amount_out_min_a, + msg->lp_remove.denom_out_min_a, msg->lp_remove.amount_out_min_b, + msg->lp_remove.denom_out_min_b)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include rewards message in transaction"); @@ -413,21 +414,19 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } /** Confirm transaction parameters on-screen */ - char amount_str[86]; - char denom_str[70]; - sprintf(denom_str, " %s", msg->lp_stake.denom); - bn_format_uint64(msg->lp_stake.amount, NULL, denom_str, 6, 0, false, - amount_str, sizeof(amount_str)); if (!confirm(ButtonRequestType_ButtonRequest_Other, "Lock Tokens", - "Lock %s tokens for %s?", amount_str, lockup_duration)) { + "Lock %s %s for %s?", msg->lp_stake.amount, + msg->lp_stake.denom, lockup_duration)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgLPStake(msg->lp_stake)) { + if (!osmosis_signTxUpdateMsgLPStake( + msg->lp_stake.amount, msg->lp_stake.denom, msg->lp_stake.duration, + msg->lp_stake.owner)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include lp stake message in transaction"); @@ -452,7 +451,8 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!osmosis_signTxUpdateMsgLPUnstake(msg->lp_unstake)) { + if (!osmosis_signTxUpdateMsgLPUnstake(msg->lp_unstake.id, + msg->lp_unstake.owner)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include lp_unstake message in transaction"); @@ -472,12 +472,9 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } /** Confirm transaction parameters on-screen */ - char amount_str[32]; - bn_format_uint64(msg->redelegate.amount, NULL, " OSMO", 6, 0, false, - amount_str, sizeof(amount_str)); if (!confirm(ButtonRequestType_ButtonRequest_Other, "Redelegate", - "Redelegate %s?", amount_str)) { + "Redelegate %s OSMO?", msg->redelegate.amount)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); @@ -529,27 +526,12 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (msg->rewards.has_amount) { - /** Confirm transaction parameters on-screen */ - char amount_str[32]; - bn_format_uint64(msg->rewards.amount, NULL, " OSMO", 6, 0, false, - amount_str, sizeof(amount_str)); - - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", - "Claim %s?", amount_str)) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } - } else { - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", - "Claim all available rewards?")) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Claim Rewards", + "Claim all available rewards?")) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; } if (!confirm_osmosis_address("Confirm delegator address", @@ -568,10 +550,8 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!osmosis_signTxUpdateMsgRewards( - msg->rewards.has_amount ? &msg->rewards.amount : NULL, - msg->rewards.delegator_address, msg->rewards.validator_address, - msg->rewards.denom)) { + if (!osmosis_signTxUpdateMsgRewards(msg->rewards.delegator_address, + msg->rewards.validator_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include rewards message in transaction"); @@ -592,36 +572,29 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } /** Confirm transaction parameters on-screen */ - char token_in_amount_str[86]; - char token_in_denom_str[70]; - sprintf(token_in_denom_str, " %s", msg->swap.token_in_denom); - bn_format_uint64(msg->swap.token_in_amount, NULL, token_in_denom_str, 6, 0, - false, token_in_amount_str, sizeof(token_in_amount_str)); - char token_out_amount_str[86]; - char token_out_denom_str[70]; - sprintf(token_out_denom_str, " %s", msg->swap.token_out_denom); - bn_format_uint64(msg->swap.token_out_min_amount, NULL, token_out_denom_str, - 6, 0, false, token_out_amount_str, - sizeof(token_out_amount_str)); if (!confirm(ButtonRequestType_ButtonRequest_Other, "Swap", - "Swap %s for at least %s?", token_in_amount_str, - token_out_amount_str)) { + "Swap %s %s for at least %s %s?", msg->swap.token_in_amount, + msg->swap.token_in_denom, msg->swap.token_out_min_amount, + msg->swap.token_out_denom)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", "%s", - msg->swap.pool_id)) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", + "%lld", msg->swap.pool_id)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!osmosis_signTxUpdateMsgSwap(msg->swap)) { + if (!osmosis_signTxUpdateMsgSwap( + msg->swap.pool_id, msg->swap.token_out_denom, msg->swap.sender, + msg->swap.token_in_amount, msg->swap.token_in_denom, + msg->swap.token_out_min_amount)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to include swap message in transaction"); @@ -644,12 +617,10 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } /** Confirm transaction parameters on-screen */ - char amount_str[32]; - bn_format_uint64(msg->ibc_transfer.amount, NULL, " OSMO", 6, 0, false, - amount_str, sizeof(amount_str)); if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Transfer", - "Transfer %s to %s?", amount_str, msg->ibc_transfer.sender)) { + "Transfer %s %s to %s?", msg->ibc_transfer.amount, + msg->ibc_transfer.denom, msg->ibc_transfer.sender)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); @@ -748,8 +719,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { RESP_INIT(OsmosisSignedTx); - if (!tendermint_signTxFinalize(resp->public_key.bytes, - resp->signature.bytes)) { + if (!osmosis_signTxFinalize(resp->public_key.bytes, resp->signature.bytes)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_SyntaxError, "Failed to finalize signature"); diff --git a/lib/firmware/osmosis.c b/lib/firmware/osmosis.c index 934a0e836..d901ba4fc 100644 --- a/lib/firmware/osmosis.c +++ b/lib/firmware/osmosis.c @@ -54,7 +54,7 @@ bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg) { memcpy(&msg, _msg, sizeof(msg)); bool success = true; - char buffer[64 + 1]; + char buffer[64 + 1] = {0}; sha256_Init(&ctx); @@ -68,21 +68,24 @@ bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg) { // const char *const chainid_prefix = ",\"chain_id\":\""; sha256_Update(&ctx, (uint8_t *)chainid_prefix, strlen(chainid_prefix)); + tendermint_sha256UpdateEscaped(&ctx, msg.chain_id, strlen(msg.chain_id)); - // 16 + ^10 + 2 = ^28 - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\",\"fee\":{\"gas\":\"%" PRIu32 "\",", msg.gas); + // 30 + ^10 + 19 = ^59 + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\",\"fee\":{\"amount\":[{\"amount\":\"%" PRIu32 + "\",\"denom\":\"uosmo\"}]", + msg.fee_amount); - // + ^10 + 19 = ^59 + // 8 + ^10 + 2 = ^20 success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":[{\"amount\":\"%" PRIu32 - "\",\"denom\":\"uosmo\"}]}", - msg.fee_amount); + ",\"gas\":\"%" PRIu32 "\"}", msg.gas); // const char *const memo_prefix = ",\"memo\":\""; sha256_Update(&ctx, (uint8_t *)memo_prefix, strlen(memo_prefix)); + if (msg.has_memo) { tendermint_sha256UpdateEscaped(&ctx, msg.memo, strlen(msg.memo)); } @@ -93,194 +96,15 @@ bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg) { return success; } -bool osmosis_signTxUpdateMsgLPAdd(const OsmosisMsgLPAdd msglpadd) { - char buffer[96 + 1]; - - bool success = true; - - const char *const prelude = - "{\"type\":\"osmosis/gamm/join-pool\",\"value\":{"; - sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"pool_id\":\"%s\",", msglpadd.pool_id); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - msglpadd.sender); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"share_out_amount\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"%" PRIu64 "\",", msglpadd.share_out_amount); - - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"token_in_maxs\":[{"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":\"%" PRIu64 "\",", - msglpadd.amount_in_max_a); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"denom\":\"%s\"},", msglpadd.denom_in_max_a); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":\"%" PRIu64 "\",", - msglpadd.amount_in_max_b); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"denom\":\"%s\"},", msglpadd.denom_in_max_b); - - msgs_remaining--; - return success; -} - -bool osmosis_signTxUpdateMsgLPRemove(const OsmosisMsgLPRemove msglpremove) { - char buffer[96 + 1]; - - bool success = true; - - const char *const prelude = - "{\"type\":\"osmosis/gamm/exit-pool\",\"value\":{"; - sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"pool_id\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - msglpremove.pool_id); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - msglpremove.sender); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"share_out_amount\":"); - - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%" PRIu64 "\",", - msglpremove.share_out_amount); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"token_out_mins\":[{"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":\"%" PRIu64 "\",", - msglpremove.amount_out_min_a); - - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":\"%s\"},", - msglpremove.denom_out_min_a); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":\"%" PRIu64 "\",", - msglpremove.amount_out_min_b); - - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":\"%s\"},", - msglpremove.denom_out_min_b); - - msgs_remaining--; - return success; -} - -bool osmosis_signTxUpdateMsgLPStake(const OsmosisMsgLPStake msgstake) { - char buffer[96 + 1]; - - bool success = true; - - const char *const prelude = - "{\"type\":\"osmosis/lockup/lock-tokens\",\"value\":{"; - sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"coins\":[{"); - - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":\"%" PRIu64 "\",\"denom\":\"%s\"}],", - msgstake.amount, msgstake.denom); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"duration\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"%" PRIu64 "\",", msgstake.duration); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"owner\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - msgstake.owner); - - msgs_remaining--; - return success; -} - -bool osmosis_signTxUpdateMsgLPUnstake(const OsmosisMsgLPUnstake msgunstake) { - char buffer[96 + 1]; - - bool success = true; - - const char *const prelude = - "{\"type\":\"osmosis/lockup/begin-unlock-period-lock\",\"value\":"; - sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "{\"ID\":\"%s\",", msgunstake.id); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"owner\":\"%s\"}}", msgunstake.owner); - - msgs_remaining--; - return success; -} - -bool osmosis_signTxUpdateMsgSwap(const OsmosisMsgSwap msgswap) { - char buffer[96 + 1]; - - bool success = true; - - const char *const prelude = - "{\"type\":\"osmosis/gamm/swap-exact-amount-in\",\"value\":{"; - sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"routes\":[{"); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"pool_id\":%s\",", msgswap.pool_id); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"token_out_denom\":%s\"}],", - msgswap.token_out_denom); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", - msgswap.sender); - - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"token_in\":{"); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":%" PRIu64 "\",", msgswap.token_in_amount); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"denom\":\"%s\"},", msgswap.token_in_denom); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"token_out_min_amount\":\"%" PRIu64 "\"}}", - msgswap.token_out_min_amount); - - msgs_remaining--; - return success; -} - -bool osmosis_signTxUpdateMsgSend(const uint64_t amount, const char *to_address, - const char *denom) { +bool osmosis_signTxUpdateMsgSend(const char *amount, const char *to_address) { char mainnetp[] = "osmo"; char testnetp[] = "tosmo"; char *pfix; char buffer[64 + 1]; size_t decoded_len; - char hrp[45]; - uint8_t decoded[38]; + char hrp[45] = {0}; + uint8_t decoded[38] = {0}; if (!bech32_decode(hrp, decoded, &decoded_len, to_address)) { return false; } @@ -302,10 +126,9 @@ bool osmosis_signTxUpdateMsgSend(const uint64_t amount, const char *to_address, sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); // 21 + ^20 + 19 = ^60 - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":[{\"amount\":\"%" PRIu64 - "\",\"denom\":\"%s\"}]", - amount, denom); + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":[{\"amount\":\"%s\",\"denom\":\"uosmo\"}]", amount); // 17 + 45 + 1 = 63 success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), @@ -319,7 +142,7 @@ bool osmosis_signTxUpdateMsgSend(const uint64_t amount, const char *to_address, return success; } -bool osmosis_signTxUpdateMsgDelegate(const uint64_t amount, +bool osmosis_signTxUpdateMsgDelegate(const char *amount, const char *delegator_address, const char *validator_address, const char *denom) { @@ -327,17 +150,17 @@ bool osmosis_signTxUpdateMsgDelegate(const uint64_t amount, char testnetp[] = "tosmo"; char *pfix; - char buffer[128]; + char buffer[128] = {0}; size_t decoded_len; - char hrp[45]; - uint8_t decoded[38]; + char hrp[45] = {0}; + uint8_t decoded[38] = {0}; if (!bech32_decode(hrp, decoded, &decoded_len, delegator_address)) { return false; } // ^14 + 39 + 1 = ^54 - char from_address[54]; + char from_address[54] = {0}; pfix = mainnetp; if (testnet) { @@ -356,10 +179,9 @@ bool osmosis_signTxUpdateMsgDelegate(const uint64_t amount, "{\"type\":\"cosmos-sdk/MsgDelegate\",\"value\":{"); // 20 + ^20 + 11 + ^9 + 2 = ^62 - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":{\"amount\":\"%" PRIu64 - "\",\"denom\":\"%s\"}", - amount, denom); + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\"%s\",\"denom\":\"%s\"}", amount, denom); // 22 success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), @@ -381,7 +203,7 @@ bool osmosis_signTxUpdateMsgDelegate(const uint64_t amount, return success; } -bool osmosis_signTxUpdateMsgUndelegate(const uint64_t amount, +bool osmosis_signTxUpdateMsgUndelegate(const char *amount, const char *delegator_address, const char *validator_address, const char *denom) { @@ -389,17 +211,17 @@ bool osmosis_signTxUpdateMsgUndelegate(const uint64_t amount, char testnetp[] = "tosmo"; char *pfix; - char buffer[128]; + char buffer[128] = {0}; size_t decoded_len; - char hrp[45]; - uint8_t decoded[38]; + char hrp[45] = {0}; + uint8_t decoded[38] = {0}; if (!bech32_decode(hrp, decoded, &decoded_len, delegator_address)) { return false; } // ^14 + 39 + 1 = ^54 - char from_address[54]; + char from_address[54] = {0}; pfix = mainnetp; if (testnet) { @@ -417,10 +239,9 @@ bool osmosis_signTxUpdateMsgUndelegate(const uint64_t amount, "{\"type\":\"cosmos-sdk/MsgUndelegate\",\"value\":{"); // 20 + ^20 + 11 + ^9 + 2 = ^62 - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":{\"amount\":\"%" PRIu64 - "\",\"denom\":\"%s\"}", - amount, denom); + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"amount\":{\"amount\":\"%s\",\"denom\":\"%s\"}", amount, denom); // 22 success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), @@ -442,7 +263,7 @@ bool osmosis_signTxUpdateMsgUndelegate(const uint64_t amount, return success; } -bool osmosis_signTxUpdateMsgRedelegate(const uint64_t amount, +bool osmosis_signTxUpdateMsgRedelegate(const char *amount, const char *delegator_address, const char *validator_src_address, const char *validator_dst_address, @@ -451,17 +272,17 @@ bool osmosis_signTxUpdateMsgRedelegate(const uint64_t amount, char testnetp[] = "tosmo"; char *pfix; - char buffer[128]; + char buffer[128] = {0}; size_t decoded_len; - char hrp[45]; - uint8_t decoded[38]; + char hrp[45] = {0}; + uint8_t decoded[38] = {0}; if (!bech32_decode(hrp, decoded, &decoded_len, delegator_address)) { return false; } // ^14 + 39 + 1 = ^54 - char from_address[54]; + char from_address[54] = {0}; pfix = mainnetp; if (testnet) { pfix = testnetp; @@ -478,10 +299,9 @@ bool osmosis_signTxUpdateMsgRedelegate(const uint64_t amount, "{\"type\":\"cosmos-sdk/MsgBeginRedelegate\",\"value\""); // 22 + ^20 + 11 + ^9 + 2 = ^64 - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - ":{\"amount\":{\"amount\":\"%" PRIu64 - "\",\"denom\":\"%s\"}", - amount, denom); + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + ":{\"amount\":{\"amount\":\"%s\",\"denom\":\"%s\"}", amount, denom); // 22 success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), @@ -511,18 +331,160 @@ bool osmosis_signTxUpdateMsgRedelegate(const uint64_t amount, return success; } -bool osmosis_signTxUpdateMsgRewards(const uint64_t *amount, - const char *delegator_address, - const char *validator_address, - const char *denom) { +bool osmosis_signTxUpdateMsgLPAdd(const uint64_t pool_id, const char *sender, + const char *share_out_amount, + const char *amount_in_max_a, + const char *denom_in_max_a, + const char *amount_in_max_b, + const char *denom_in_max_b) { + char buffer[96 + 1] = {0}; + + bool success = true; + + const char *const prelude = + "{\"type\":\"osmosis/gamm/join-pool\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"pool_id\":\"%" PRIu64 "\",", pool_id); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", sender); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"share_out_amount\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + share_out_amount); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"token_in_maxs\":[{"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":\"%s\",", amount_in_max_a); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"denom\":\"%s\"},", denom_in_max_a); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "{\"amount\":\"%s\",", amount_in_max_b); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"denom\":\"%s\"}]}}", denom_in_max_b); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgLPRemove(const uint64_t pool_id, const char *sender, + const char *share_out_amount, + const char *amount_out_min_a, + const char *denom_out_min_a, + const char *amount_out_min_b, + const char *denom_out_min_b) { + char buffer[96 + 1] = {0}; + + bool success = true; + + const char *const prelude = + "{\"type\":\"osmosis/gamm/exit-pool\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"pool_id\":\"%" PRIu64 "\",", pool_id); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", sender); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"share_out_amount\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", + share_out_amount); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token_out_mins\":[{"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":\"%s\",", amount_out_min_a); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"denom\":\"%s\"},", denom_out_min_a); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "{\"amount\":\"%s\",", amount_out_min_b); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"denom\":\"%s\"}]}}", denom_out_min_b); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgLPStake(const char *amount, const char *denom, + const uint64_t duration, + const char *owner) { + char buffer[96 + 1] = {0}; + + bool success = true; + + const char *const prelude = + "{\"type\":\"osmosis/lockup/lock-tokens\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"coins\":[{"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":\"%s\",\"denom\":\"%s\"}],", + amount, denom); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"duration\":"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"%" PRIu64 "\",", duration); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"owner\":"); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", owner); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgLPUnstake(const char *id, const char *owner) { + char buffer[96 + 1]; + + bool success = true; + + const char *const prelude = + "{\"type\":\"osmosis/lockup/begin-unlock-period-lock\",\"value\":"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "{\"ID\":\"%s\",", id); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"owner\":\"%s\"}}", owner); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgRewards(const char *delegator_address, + const char *validator_address) { char mainnetp[] = "osmo"; char testnetp[] = "tosmo"; char *pfix; - char buffer[128]; + char buffer[128] = {0}; size_t decoded_len; - char hrp[45]; - uint8_t decoded[38]; + char hrp[45] = {0}; + uint8_t decoded[38] = {0}; if (!bech32_decode(hrp, decoded, &decoded_len, delegator_address)) { return false; @@ -534,7 +496,7 @@ bool osmosis_signTxUpdateMsgRewards(const uint64_t *amount, } // ^14 + 39 + 1 = ^54 - char from_address[54]; + char from_address[54] = {0}; if (!tendermint_getAddress(&node, pfix, from_address)) { return false; } @@ -546,14 +508,6 @@ bool osmosis_signTxUpdateMsgRewards(const uint64_t *amount, &ctx, buffer, sizeof(buffer), "{\"type\":\"cosmos-sdk/MsgWithdrawDelegationReward\",\"value\":{"); - // 20 + ^20 + 11 + ^9 + 3 = ^65 - if (amount != NULL) { - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":{\"amount\":\"%" PRIu64 - "\",\"denom\":\"%s\"},", - *amount, denom); - } - // 21 success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"delegator_address\":\""); @@ -574,19 +528,21 @@ bool osmosis_signTxUpdateMsgRewards(const uint64_t *amount, return success; } -bool osmosis_signTxUpdateMsgIBCTransfer( - const uint64_t amount, const char *sender, const char *receiver, - const char *source_channel, const char *source_port, - const char *revision_number, const char *revision_height, - const char *denom) { +bool osmosis_signTxUpdateMsgIBCTransfer(const char *amount, const char *sender, + const char *receiver, + const char *source_channel, + const char *source_port, + const char *revision_number, + const char *revision_height, + const char *denom) { char mainnetp[] = "osmo"; char testnetp[] = "tosmo"; char *pfix; - char buffer[128]; + char buffer[128] = {0}; size_t decoded_len; - char hrp[45]; - uint8_t decoded[38]; + char hrp[45] = {0}; + uint8_t decoded[38] = {0}; if (!bech32_decode(hrp, decoded, &decoded_len, receiver)) { return false; @@ -598,7 +554,7 @@ bool osmosis_signTxUpdateMsgIBCTransfer( } // ^14 + 39 + 1 = ^54 - char from_address[54]; + char from_address[54] = {0}; if (!tendermint_getAddress(&node, pfix, from_address)) { return false; } @@ -644,28 +600,76 @@ bool osmosis_signTxUpdateMsgIBCTransfer( "\",\"revision_number\":\"%s\"},", revision_number); // 20 + ^20 + 11 + ^9 + 3 = ^63 + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"token\":{\"amount\":\"%s\",\"denom\":\"%s\"}}}", amount, denom); + + msgs_remaining--; + return success; +} + +bool osmosis_signTxUpdateMsgSwap(const uint64_t pool_id, + const char *token_out_denom, + const char *sender, + const char *token_in_amount, + const char *token_in_denom, + const char *token_out_min_amount) { + char buffer[96 + 1] = {0}; + + // TODO: add testnet support + + bool success = true; + + const char *const prelude = + "{\"type\":\"osmosis/gamm/swap-exact-amount-in\",\"value\":{"; + sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"routes\":[{"); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"token\":{\"amount\":\"%" PRIu64 - "\",\"denom\":\"%s\"}}}", - amount, denom); + "\"pool_id\":\"%" PRIu64 "\",", pool_id); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token_out_denom\":%s\"}],", token_out_denom); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", sender); + + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"token_in\":{"); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"amount\":\"%s\",", token_in_amount); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"denom\":\"%s\"},", token_in_denom); + + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token_out_min_amount\":\"%s\"}}", + token_out_min_amount); msgs_remaining--; return success; } bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature) { - char buffer[64 + 1]; + char buffer[128] = {0}; - // 16 + ^20 = ^36 + // 14 + ^20 + 2 = ^36 if (!tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "],\"sequence\":\"%" PRIu64 "\"}", msg.sequence)) + "],\"sequence\":\"%" PRIu64 "\"}", msg.sequence)) { return false; + } hdnode_fill_public_key(&node); memcpy(public_key, node.public_key, 33); uint8_t hash[SHA256_DIGEST_LENGTH]; sha256_Final(&ctx, hash); + debug_final_hash(hash); return ecdsa_sign_digest(&secp256k1, node.private_key, hash, signature, NULL, NULL) == 0; } diff --git a/lib/firmware/signtx_tendermint.c b/lib/firmware/signtx_tendermint.c index 1f4ede820..8b87ebdc9 100644 --- a/lib/firmware/signtx_tendermint.c +++ b/lib/firmware/signtx_tendermint.c @@ -18,7 +18,6 @@ */ #include "keepkey/firmware/cosmos.h" -#include "keepkey/firmware/osmosis.h" #include "keepkey/board/confirm_sm.h" #include "keepkey/board/util.h" #include "keepkey/firmware/home_sm.h" @@ -539,4 +538,4 @@ void tendermint_signAbort(void) { msgs_remaining = 0; memzero(&tmsg, sizeof(tmsg)); memzero(&node, sizeof(node)); -} +} \ No newline at end of file From e31115dca483a0da84aff9d9d6dc67e6502f2893 Mon Sep 17 00:00:00 2001 From: pastaghost Date: Tue, 21 Feb 2023 22:16:54 -0700 Subject: [PATCH 21/23] chore: update submodule --- deps/device-protocol | 2 +- include/keepkey/transport/messages-osmosis.options | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/device-protocol b/deps/device-protocol index ed06392ad..22ca1d983 160000 --- a/deps/device-protocol +++ b/deps/device-protocol @@ -1 +1 @@ -Subproject commit ed06392ad973bec129e0ccc0b7c427391834b359 +Subproject commit 22ca1d983c3f513f338e2a0ba997427659646523 diff --git a/include/keepkey/transport/messages-osmosis.options b/include/keepkey/transport/messages-osmosis.options index cf84163bb..6da6dfeb8 100644 --- a/include/keepkey/transport/messages-osmosis.options +++ b/include/keepkey/transport/messages-osmosis.options @@ -43,7 +43,7 @@ OsmosisMsgLPRemove.denom_out_min_a max_size:69 OsmosisMsgLPRemove.denom_out_min_b max_size:69 OsmosisMsgLPRemove.amount_out_min_a max_size:33 OsmosisMsgLPRemove.amount_out_min_b max_size:33 -OsmosisMsgLPRemove.share_out_amount max_size:33 +OsmosisMsgLPRemove.share_in_amount max_size:33 OsmosisMsgLPStake.owner max_size:53 OsmosisMsgLPStake.denom max_size:69 From dcc9acc6677f42005f6c6df3a559889a20961039 Mon Sep 17 00:00:00 2001 From: pastaghost Date: Tue, 21 Feb 2023 22:17:47 -0700 Subject: [PATCH 22/23] refactor: remove unused staking code, fix lp_remove field name --- include/keepkey/firmware/osmosis.h | 7 --- lib/firmware/fsm_msg_osmosis.h | 87 ++---------------------------- lib/firmware/osmosis.c | 78 ++++----------------------- 3 files changed, 15 insertions(+), 157 deletions(-) diff --git a/include/keepkey/firmware/osmosis.h b/include/keepkey/firmware/osmosis.h index 340f018e8..9a3f39498 100644 --- a/include/keepkey/firmware/osmosis.h +++ b/include/keepkey/firmware/osmosis.h @@ -10,8 +10,6 @@ typedef struct _OsmosisSignTx OsmosisSignTx; typedef struct _OsmosisMsgLPAdd OsmosisMsgLPAdd; typedef struct _OsmosisMsgLPRemove OsmosisMsgLPRemove; -typedef struct _OsmosisMsgLPStake OsmosisMsgLPStake; -typedef struct _OsmosisMsgLPUnstake OsmosisMsgLPUnstake; typedef struct _OsmosisMsgSwap OsmosisMsgSwap; void debug_intermediate_hash(void); @@ -50,11 +48,6 @@ bool osmosis_signTxUpdateMsgLPRemove(const uint64_t pool_id, const char *sender, const char *amount_out_min_b, const char *denom_out_min_b); -bool osmosis_signTxUpdateMsgLPStake(const char *amount, const char *denom, - const uint64_t duration, const char *owner); - -bool osmosis_signTxUpdateMsgLPUnstake(const char *id, const char *owner); - bool osmosis_signTxUpdateMsgRewards(const char *delegator_address, const char *validator_address); diff --git a/lib/firmware/fsm_msg_osmosis.h b/lib/firmware/fsm_msg_osmosis.h index 720fa744a..6c3db2c1c 100644 --- a/lib/firmware/fsm_msg_osmosis.h +++ b/lib/firmware/fsm_msg_osmosis.h @@ -316,7 +316,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } else if (msg->has_lp_remove) { /** Confirm required transaction parameters exist */ if (!msg->lp_remove.has_sender || !msg->lp_remove.has_pool_id || - !msg->lp_remove.has_share_out_amount || + !msg->lp_remove.has_share_in_amount || !msg->lp_remove.has_denom_out_min_a || !msg->lp_remove.has_amount_out_min_a || !msg->lp_remove.has_denom_out_min_b || @@ -330,9 +330,9 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { /** Confirm transaction parameters on-screen */ char share_out_amount_buf[33] = {0}; - share_out_amount_buf[0] = msg->lp_remove.share_out_amount[0]; + share_out_amount_buf[0] = msg->lp_remove.share_in_amount[0]; share_out_amount_buf[1] = '.'; - strncpy(&share_out_amount_buf[2], &msg->lp_remove.share_out_amount[1], + strncpy(&share_out_amount_buf[2], &msg->lp_remove.share_in_amount[1], (sizeof(share_out_amount_buf) / sizeof(char)) - 2); if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", @@ -371,7 +371,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { if (!osmosis_signTxUpdateMsgLPRemove( msg->lp_remove.pool_id, msg->lp_remove.sender, - msg->lp_remove.share_out_amount, msg->lp_remove.amount_out_min_a, + msg->lp_remove.share_in_amount, msg->lp_remove.amount_out_min_a, msg->lp_remove.denom_out_min_a, msg->lp_remove.amount_out_min_b, msg->lp_remove.denom_out_min_b)) { osmosis_signAbort(); @@ -380,85 +380,6 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { layoutHome(); return; } - } else if (msg->has_lp_stake) { - char *lockup_duration; - char *supported_lockup_durations[] = {"1 day", "1 week", "2 weeks"}; - /** Confirm required transaction parameters exist */ - if (!msg->lp_stake.has_owner || !msg->lp_stake.has_duration || - !msg->lp_stake.has_denom || !msg->lp_stake.has_amount) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_FirmwareError, - _("Message is missing required parameters")); - layoutHome(); - return; - } - switch (msg->lp_stake.duration) { - case 86400: - /* 1 day in seconds */ - lockup_duration = supported_lockup_durations[0]; - break; - case 604800: - /* 1 week in seconds */ - lockup_duration = supported_lockup_durations[1]; - break; - case 1209600: - /* 2 weeks in seconds */ - lockup_duration = supported_lockup_durations[2]; - break; - default: - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_FirmwareError, - _("Unsupported lockup duration")); - layoutHome(); - return; - } - - /** Confirm transaction parameters on-screen */ - - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Lock Tokens", - "Lock %s %s for %s?", msg->lp_stake.amount, - msg->lp_stake.denom, lockup_duration)) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } - - if (!osmosis_signTxUpdateMsgLPStake( - msg->lp_stake.amount, msg->lp_stake.denom, msg->lp_stake.duration, - msg->lp_stake.owner)) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include lp stake message in transaction"); - layoutHome(); - return; - } - } else if (msg->has_lp_unstake) { - /** Confirm required transaction parameters exist */ - if (!msg->lp_unstake.has_owner || !msg->lp_unstake.has_id) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_FirmwareError, - _("Message is missing required parameters")); - layoutHome(); - return; - } - - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Unlock Tokens", - "Begin unbonding time for all bonded tokens in all pools?")) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } - - if (!osmosis_signTxUpdateMsgLPUnstake(msg->lp_unstake.id, - msg->lp_unstake.owner)) { - osmosis_signAbort(); - fsm_sendFailure(FailureType_Failure_SyntaxError, - "Failed to include lp_unstake message in transaction"); - layoutHome(); - return; - } } else if (msg->has_redelegate) { /** Confirm required transaction parameters exist */ if (!msg->redelegate.has_delegator_address || diff --git a/lib/firmware/osmosis.c b/lib/firmware/osmosis.c index d901ba4fc..a9ac61037 100644 --- a/lib/firmware/osmosis.c +++ b/lib/firmware/osmosis.c @@ -400,8 +400,8 @@ bool osmosis_signTxUpdateMsgLPRemove(const uint64_t pool_id, const char *sender, success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", sender); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"share_out_amount\":"); + success &= + tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"share_in_amount\":"); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", share_out_amount); @@ -425,56 +425,6 @@ bool osmosis_signTxUpdateMsgLPRemove(const uint64_t pool_id, const char *sender, return success; } -bool osmosis_signTxUpdateMsgLPStake(const char *amount, const char *denom, - const uint64_t duration, - const char *owner) { - char buffer[96 + 1] = {0}; - - bool success = true; - - const char *const prelude = - "{\"type\":\"osmosis/lockup/lock-tokens\",\"value\":{"; - sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"coins\":[{"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":\"%s\",\"denom\":\"%s\"}],", - amount, denom); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"duration\":"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"%" PRIu64 "\",", duration); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"owner\":"); - - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", owner); - - msgs_remaining--; - return success; -} - -bool osmosis_signTxUpdateMsgLPUnstake(const char *id, const char *owner) { - char buffer[96 + 1]; - - bool success = true; - - const char *const prelude = - "{\"type\":\"osmosis/lockup/begin-unlock-period-lock\",\"value\":"; - sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "{\"ID\":\"%s\",", id); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"owner\":\"%s\"}}", owner); - - msgs_remaining--; - return success; -} - bool osmosis_signTxUpdateMsgRewards(const char *delegator_address, const char *validator_address) { char mainnetp[] = "osmo"; @@ -621,28 +571,23 @@ bool osmosis_signTxUpdateMsgSwap(const uint64_t pool_id, bool success = true; const char *const prelude = - "{\"type\":\"osmosis/gamm/swap-exact-amount-in\",\"value\":{"; + "{\"type\":\"osmosis/gamm/swap-exact-amount-in\","; sha256_Update(&ctx, (uint8_t *)prelude, strlen(prelude)); - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"routes\":[{"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"pool_id\":\"%" PRIu64 "\",", pool_id); + success &= tendermint_snprintf( + &ctx, buffer, sizeof(buffer), + "\"value\":{\"routes\":[{\"pool_id\":\"%" PRIu64 "\",", pool_id); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"token_out_denom\":%s\"}],", token_out_denom); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"sender\":"); + "\"token_out_denom\":\"%s\"}],", token_out_denom); - success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"%s\",", sender); + success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"sender\":\"%s\",", sender); success &= - tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"token_in\":{"); - - success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), - "\"amount\":\"%s\",", token_in_amount); + tendermint_snprintf(&ctx, buffer, sizeof(buffer), + "\"token_in\":{\"amount\":\"%s\",", token_in_amount); success &= tendermint_snprintf(&ctx, buffer, sizeof(buffer), "\"denom\":\"%s\"},", token_in_denom); @@ -669,7 +614,6 @@ bool osmosis_signTxFinalize(uint8_t *public_key, uint8_t *signature) { uint8_t hash[SHA256_DIGEST_LENGTH]; sha256_Final(&ctx, hash); - debug_final_hash(hash); return ecdsa_sign_digest(&secp256k1, node.private_key, hash, signature, NULL, NULL) == 0; } From 7ffb1a569f7083a81d63f4ab4c75e7c3077c231d Mon Sep 17 00:00:00 2001 From: pastaghost Date: Fri, 24 Feb 2023 15:44:11 -0700 Subject: [PATCH 23/23] fix: osmosis tx display formatting --- include/keepkey/board/util.h | 4 + lib/board/util.c | 32 ++++++++ lib/firmware/fsm_msg_osmosis.h | 141 +++++++++++++++++++++------------ 3 files changed, 125 insertions(+), 52 deletions(-) diff --git a/include/keepkey/board/util.h b/include/keepkey/board/util.h index dd8b51ec7..17ccdc3c0 100644 --- a/include/keepkey/board/util.h +++ b/include/keepkey/board/util.h @@ -54,4 +54,8 @@ void dec64_to_str(uint64_t dec64_val, char *str); bool is_valid_ascii(const uint8_t *data, uint32_t size); +int base_to_precision(uint8_t *dest, const uint8_t *value, + const uint8_t dest_len, const uint8_t value_len, + const uint8_t precision); + #endif diff --git a/lib/board/util.c b/lib/board/util.c index ab9a58901..065f53edb 100644 --- a/lib/board/util.c +++ b/lib/board/util.c @@ -102,3 +102,35 @@ bool is_valid_ascii(const uint8_t *data, uint32_t size) { } return true; } + +/* convert number in base units to specified decimal precision */ +int base_to_precision(uint8_t *dest, const uint8_t *value, + const uint8_t dest_len, const uint8_t value_len, + const uint8_t precision) { + if (!(dest && value)) { + // invalid pointer + return -1; + } + if (value_len + 1 > dest_len) { + // value too large for output buffer + return -1; + } + memset(dest, '0', dest_len); + uint8_t leading_digits = + ((value_len - precision) > 0) ? (value_len - precision) : 0; + + if (!leading_digits) { + memcpy(dest, "0.", 2); + uint8_t offset = + 2 + (((precision - value_len) > 0) ? (precision - value_len) : 0); + strlcpy((char *)&dest[offset], (char *)value, value_len); + } else { + uint8_t copy_len = MIN((value_len - leading_digits), precision); + memcpy(dest, value, leading_digits); + dest[leading_digits] = '.'; + strlcpy((char *)&dest[leading_digits + 1], (char *)&value[leading_digits], + copy_len); + } + dest[dest_len] = '\0'; + return 0; +} diff --git a/lib/firmware/fsm_msg_osmosis.h b/lib/firmware/fsm_msg_osmosis.h index 6c3db2c1c..a84ae925b 100644 --- a/lib/firmware/fsm_msg_osmosis.h +++ b/lib/firmware/fsm_msg_osmosis.h @@ -1,3 +1,7 @@ +#include +#define OSMOSIS_PRECISION 6 +#define OSMOSIS_LP_ASSET_PRECISION 18 + void fsm_msgOsmosisGetAddress(const OsmosisGetAddress *msg) { RESP_INIT(OsmosisAddress); @@ -136,7 +140,8 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } char amount_str[40]; - sprintf(amount_str, "%s OSMO", msg->send.amount); + sprintf(amount_str, "%.6f OSMO", + atof(msg->send.amount) / pow(10, OSMOSIS_PRECISION)); if (!confirm_transaction_output( ButtonRequestType_ButtonRequest_ConfirmOutput, amount_str, msg->send.to_address)) { @@ -165,7 +170,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } /** Confirm transaction parameters on-screen */ - if (!confirm_osmosis_address("Confirm delegator address", + if (!confirm_osmosis_address("Confirm Delegator Address", msg->delegate.delegator_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); @@ -173,7 +178,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!confirm_osmosis_address("Confirm validator address", + if (!confirm_osmosis_address("Confirm Validator Address", msg->delegate.validator_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); @@ -181,10 +186,9 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!confirm_with_custom_layout( - &layout_notification_no_title_bold, - ButtonRequestType_ButtonRequest_ConfirmOutput, "", - "Delegate %s OSMO?", msg->delegate.amount)) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Amount", + "%.6f OSMO", + atof(msg->delegate.amount) / pow(10, OSMOSIS_PRECISION))) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); @@ -212,7 +216,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } /** Confirm transaction parameters on-screen */ - if (!confirm_osmosis_address("Confirm delegator address", + if (!confirm_osmosis_address("Confirm Delegator Address", msg->undelegate.delegator_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); @@ -220,7 +224,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!confirm_osmosis_address("Confirm validator address", + if (!confirm_osmosis_address("Confirm Validator Address", msg->undelegate.validator_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); @@ -228,10 +232,9 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!confirm_with_custom_layout( - &layout_notification_no_title_bold, - ButtonRequestType_ButtonRequest_ConfirmOutput, "", - "Undelegate %s OSMO?", msg->undelegate.amount)) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Amount", + "%.6f OSMO", + atof(msg->undelegate.amount) / pow(10, OSMOSIS_PRECISION))) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); @@ -261,15 +264,25 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } /** Confirm transaction parameters on-screen */ - char share_out_amount_buf[33] = {0}; - share_out_amount_buf[0] = msg->lp_add.share_out_amount[0]; - share_out_amount_buf[1] = '.'; - strncpy(&share_out_amount_buf[2], &msg->lp_add.share_out_amount[1], - (sizeof(share_out_amount_buf) / sizeof(char)) - 2); + char insoamt[33] = {0}; + uint8_t outsoamt[34] = {0}; + strlcpy(insoamt, msg->lp_add.share_out_amount, + sizeof(msg->lp_add.share_out_amount)); + + if (base_to_precision(outsoamt, (uint8_t *)insoamt, sizeof(outsoamt), + strlen(insoamt), OSMOSIS_LP_ASSET_PRECISION) < 0) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_Other, NULL); + layoutHome(); + return; + } if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", - "Deposit %s %s and...", msg->lp_add.amount_in_max_a, - msg->lp_add.denom_in_max_a)) { + "Deposit %.6f %s and...", + atof(msg->lp_add.amount_in_max_b) / pow(10, OSMOSIS_PRECISION), + (!strcmp(msg->lp_add.denom_in_max_b, "uosmo")) + ? "OSMO" + : msg->lp_add.denom_in_max_b)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); @@ -277,15 +290,18 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } if (!confirm(ButtonRequestType_ButtonRequest_Other, "Add Liquidity", - "... %s %s?", msg->lp_add.amount_in_max_b, - msg->lp_add.denom_in_max_b)) { + "... %.6f %s?", + atof(msg->lp_add.amount_in_max_a) / pow(10, OSMOSIS_PRECISION), + (!strcmp(msg->lp_add.denom_in_max_a, "uosmo")) + ? "OSMO" + : msg->lp_add.denom_in_max_a)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Pool ID", "%lld", msg->lp_add.pool_id)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); @@ -293,9 +309,9 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Pool share amount", - "Receive %s LP shares?", share_out_amount_buf)) { - // (double)msg->lp_add.share_out_amount / 1000000000000000000.0f)) { + if (!confirm(ButtonRequestType_ButtonRequest_Other, + "Confirm Share Out Amount", "Receive %s GAMM-%lld shares?", + outsoamt, msg->lp_add.pool_id)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); @@ -329,31 +345,46 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } /** Confirm transaction parameters on-screen */ - char share_out_amount_buf[33] = {0}; - share_out_amount_buf[0] = msg->lp_remove.share_in_amount[0]; - share_out_amount_buf[1] = '.'; - strncpy(&share_out_amount_buf[2], &msg->lp_remove.share_in_amount[1], - (sizeof(share_out_amount_buf) / sizeof(char)) - 2); + char insoamt[33] = {0}; + uint8_t outsoamt[34] = {0}; + strlcpy(insoamt, msg->lp_remove.share_in_amount, + sizeof(msg->lp_remove.share_in_amount)); + + if (base_to_precision(outsoamt, (uint8_t *)insoamt, sizeof(outsoamt), + strlen(insoamt), OSMOSIS_LP_ASSET_PRECISION) < 0) { + osmosis_signAbort(); + fsm_sendFailure(FailureType_Failure_Other, NULL); + layoutHome(); + return; + } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", - "Withdraw %s %s and...", msg->lp_remove.amount_out_min_a, - msg->lp_remove.denom_out_min_a)) { + if (!confirm( + ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", + "Withdraw %.6f %s and...", + atof(msg->lp_remove.amount_out_min_b) / pow(10, OSMOSIS_PRECISION), + (!strcmp(msg->lp_remove.denom_out_min_b, "uosmo")) + ? "OSMO" + : msg->lp_remove.denom_out_min_b)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", - "... %s %s ?", msg->lp_remove.amount_out_min_b, - msg->lp_remove.denom_out_min_b)) { + if (!confirm( + ButtonRequestType_ButtonRequest_Other, "Remove Liquidity", + "... %.6f %s ?", + atof(msg->lp_remove.amount_out_min_a) / pow(10, OSMOSIS_PRECISION), + (!strcmp(msg->lp_remove.denom_out_min_a, "uosmo")) + ? "OSMO" + : msg->lp_remove.denom_out_min_a)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Pool ID", "%lld", msg->lp_remove.pool_id)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); @@ -362,7 +393,8 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { } if (!confirm(ButtonRequestType_ButtonRequest_Other, "Pool share amount", - "Redeem %s LP shares?", share_out_amount_buf)) { + "Redeem %s GAMM-%lld shares?", outsoamt, + msg->lp_remove.pool_id)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); @@ -395,14 +427,15 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { /** Confirm transaction parameters on-screen */ if (!confirm(ButtonRequestType_ButtonRequest_Other, "Redelegate", - "Redelegate %s OSMO?", msg->redelegate.amount)) { + "Redelegate %.6f OSMO?", + atof(msg->send.amount) / pow(10, OSMOSIS_PRECISION))) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm_osmosis_address("Delegator address", + if (!confirm_osmosis_address("Delegator Address", msg->redelegate.delegator_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); @@ -410,7 +443,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!confirm_osmosis_address("Validator source address", + if (!confirm_osmosis_address("Validator Source Address", msg->redelegate.validator_src_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); @@ -418,7 +451,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!confirm_osmosis_address("Validator dest. address", + if (!confirm_osmosis_address("Validator Dest. Address", msg->redelegate.validator_dst_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); @@ -455,7 +488,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!confirm_osmosis_address("Confirm delegator address", + if (!confirm_osmosis_address("Confirm Delegator Address", msg->rewards.delegator_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); @@ -463,7 +496,7 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { return; } - if (!confirm_osmosis_address("Confirm validator address", + if (!confirm_osmosis_address("Confirm Validator Address", msg->rewards.validator_address)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); @@ -494,17 +527,20 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { /** Confirm transaction parameters on-screen */ - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Swap", - "Swap %s %s for at least %s %s?", msg->swap.token_in_amount, - msg->swap.token_in_denom, msg->swap.token_out_min_amount, - msg->swap.token_out_denom)) { + if (!confirm( + ButtonRequestType_ButtonRequest_Other, "Swap", + "Swap %.6f %s for at least %.6f %s?", + atof(msg->swap.token_in_amount) / pow(10, OSMOSIS_PRECISION), + msg->swap.token_in_denom, + atof(msg->swap.token_out_min_amount) / pow(10, OSMOSIS_PRECISION), + msg->swap.token_out_denom)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome(); return; } - if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm pool ID", + if (!confirm(ButtonRequestType_ButtonRequest_Other, "Confirm Pool ID", "%lld", msg->swap.pool_id)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); @@ -540,8 +576,9 @@ void fsm_msgOsmosisMsgAck(const OsmosisMsgAck *msg) { /** Confirm transaction parameters on-screen */ if (!confirm(ButtonRequestType_ButtonRequest_Other, "IBC Transfer", - "Transfer %s %s to %s?", msg->ibc_transfer.amount, - msg->ibc_transfer.denom, msg->ibc_transfer.sender)) { + "Transfer %.6f %s to %s?", + atof(msg->ibc_transfer.amount) / pow(10, OSMOSIS_PRECISION), + msg->ibc_transfer.denom, msg->ibc_transfer.receiver)) { osmosis_signAbort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); layoutHome();