Skip to content

Commit

Permalink
Merge pull request #338 from keepkey/feature-osmosis
Browse files Browse the repository at this point in the history
feat: add osmosis support
  • Loading branch information
pastaghost authored Feb 24, 2023
2 parents 2d9f039 + 7ffb1a5 commit 8e9fff2
Show file tree
Hide file tree
Showing 23 changed files with 1,674 additions and 54 deletions.
82 changes: 53 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
cmake_minimum_required(VERSION 3.7.2)

project(KeepKeyFirmware

VERSION 7.6.1

LANGUAGES C CXX ASM)
project(
KeepKeyFirmware
VERSION 7.7.0
LANGUAGES C CXX ASM)

set(BOOTLOADER_MAJOR_VERSION 2)
set(BOOTLOADER_MINOR_VERSION 1)
Expand All @@ -13,35 +12,54 @@ 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/")
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})
Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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()
2 changes: 1 addition & 1 deletion deps/device-protocol
4 changes: 4 additions & 0 deletions include/keepkey/board/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions include/keepkey/firmware/app_confirm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 16 additions & 14 deletions include/keepkey/firmware/app_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions include/keepkey/firmware/coins.def
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +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, "" )

#undef X
#undef NO_CONTRACT
4 changes: 4 additions & 0 deletions include/keepkey/firmware/fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ void fsm_msgCosmosGetAddress(const CosmosGetAddress *msg);
void fsm_msgCosmosSignTx(const CosmosSignTx *msg);
void fsm_msgCosmosMsgAck(const CosmosMsgAck *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);
Expand Down
75 changes: 75 additions & 0 deletions include/keepkey/firmware/osmosis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef KEEPKEY_FIRMWARE_OSMOSIS_H
#define KEEPKEY_FIRMWARE_OSMOSIS_H

#include "messages.pb.h"
#include "trezor/crypto/bip32.h"

#include <stdbool.h>
#include <stdint.h>

typedef struct _OsmosisSignTx OsmosisSignTx;
typedef struct _OsmosisMsgLPAdd OsmosisMsgLPAdd;
typedef struct _OsmosisMsgLPRemove OsmosisMsgLPRemove;
typedef struct _OsmosisMsgSwap OsmosisMsgSwap;

void debug_intermediate_hash(void);

bool osmosis_signTxInit(const HDNode *_node, const OsmosisSignTx *_msg);

bool osmosis_signTxUpdateMsgSend(const char *amount, const char *to_address);

bool osmosis_signTxUpdateMsgDelegate(const char *amount,
const char *delegator_address,
const char *validator_address,
const char *denom);

bool osmosis_signTxUpdateMsgUndelegate(const char *amount,
const char *delegator_address,
const char *validator_address,
const char *denom);

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_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_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);
void osmosis_signAbort(void);
const OsmosisSignTx *osmosis_getOsmosisSignTx(void);

#endif
11 changes: 4 additions & 7 deletions include/keepkey/firmware/signtx_tendermint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -35,8 +33,7 @@ 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_signTxUpdateMsgIBCTransfer(
const uint64_t amount, const char *sender, const char *receiver,
Expand All @@ -49,4 +46,4 @@ bool tendermint_signingIsFinished(void);
void tendermint_signAbort(void);
const void *tendermint_getSignTx(void);

#endif
#endif
1 change: 1 addition & 0 deletions include/keepkey/transport/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#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"
Expand Down
Loading

0 comments on commit 8e9fff2

Please sign in to comment.