Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ldg 417 migrate msgdeposit txtype logic #3

Merged
merged 17 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 20 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
BasedOnStyle: Google
IndentWidth: 4
---
Language: Cpp
ColumnLimit: 100
PointerAlignment: Right
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: true
AllowAllParametersOfDeclarationOnNextLine: false
SortIncludes: false
SpaceAfterCStyleCast: true
AllowShortCaseLabelsOnASingleLine: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
BinPackArguments: false
BinPackParameters: false
---
8 changes: 8 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Checklist
<!-- Put an `x` in each box when you have completed the items. -->
- [ ] App update process has been followed <!-- See comment below -->
- [ ] Target branch is `develop` <!-- unless you have a very good reason -->
- [ ] Application version has been bumped <!-- required if your changes are to be deployed -->

<!-- Make sure you followed the process described in https://developers.ledger.com/docs/embedded-app/maintenance/ before opening your Pull Request.
Don't hesitate to contact us directly on Discord if you have any questions ! https://developers.ledger.com/discord -->
17 changes: 0 additions & 17 deletions .sonarcloud.properties

This file was deleted.

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#* limitations under the License.
#********************************************************************************
cmake_minimum_required(VERSION 3.0)
project(ledger-cosmos VERSION 0.0.0)
project(ledger-thorchain VERSION 0.0.0)
enable_testing()

cmake_policy(SET CMP0025 NEW)
Expand Down
45 changes: 5 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
# Ledger Cosmos app
# Ledger THORChain app
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![GithubActions](https://github.com/cosmos/ledger-cosmos/actions/workflows/main.yml/badge.svg)](https://github.com/cosmos/ledger-cosmos/blob/main/.github/workflows/main.yaml)

---

![zondax_light](docs/zondax_light.png#gh-light-mode-only)
![zondax_dark](docs/zondax_dark.png#gh-dark-mode-only)

_Please visit our website at [zondax.ch](zondax.ch)_

You can also visit [Zondax Hub](https://hub.zondax.ch/cosmos) to test any of the versions of the app
Forked from [Cosmos App](https://github.com/LedgerHQ/app-cosmos) by Zondax

---

This project contains the Cosmos app for Ledger Nano S, Nano S+, X and Stax.
This project contains the THORChain app for Ledger Nano S, Nano S+, X and Stax.

- Ledger Nano S/S+/X/Stax Cosmos app
- Ledger Nano S/S+/X/Stax THORChain app
- Specs / Documentation
- C++ unit tests
- Zemu tests
Expand All @@ -28,28 +22,6 @@ Please:
- **Do not use a Ledger device with funds for development purposes.**
- **Have a separate and marked device that is used ONLY for development and testing**

Tip:

- In releases, you will find a precompiled test app. If you are just curious, you can run `zxtool.sh` and avoid building.

## Download and install a prerelease

*Once the app is approved by Ledger, it will be available in their app store (Ledger Live).
You can get builds generated by CircleCI from the release tab. THESE ARE UNVETTED DEVELOPMENT RELEASES*

Download a release from here (https://github.com/Zondax/ledger-cosmos/releases). You only need `zxtool.sh`

If the file is not executable, run
```sh
chmod +x ./zxtool.sh
```

then run:

```sh
./installer_s.sh load
```

# Development

## Preconditions
Expand Down Expand Up @@ -116,14 +88,7 @@ If you see conan is not found, check that you installed the package in the same

## How to test with Zemu?

> What is Zemu?? Great you asked!!
> As part of this project, we are making public a beta version of our internal testing+emulation framework for Ledger apps.
>
> Npm Package here: https://www.npmjs.com/package/@zondax/zemu
>
> Repo here: https://github.com/Zondax/zemu

Let's go! First install everything:
First, install everything:
> At this moment, if you change the app you will need to run `make` before running the test again.

```bash
Expand Down
79 changes: 0 additions & 79 deletions SECURITY.md

This file was deleted.

14 changes: 9 additions & 5 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ $(info ************ TARGET_NAME = [$(TARGET_NAME)])
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.app_testing

ifndef COIN
COIN=ATOM
COIN=RUNE
endif

$(info COIN = [$(COIN)])

ifeq ($(COIN),ATOM)
ifeq ($(COIN),RUNE)
# Main app configuration
APPNAME = "Cosmos"
APPPATH = "44'/118'" --path "44'/60'"
APPNAME = "THORChain"
APPPATH = "44'/931'"
else
define error_message

Expand All @@ -52,6 +52,8 @@ endif

APP_LOAD_PARAMS = --curve secp256k1 $(COMMON_LOAD_PARAMS) --path $(APPPATH)

ENABLE_PENDING_REVIEW_SCREEN ?= 1

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices

$(info TARGET_NAME = [$(TARGET_NAME)])
Expand All @@ -64,9 +66,11 @@ endif
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.platform
DEFINES += HAVE_HASH HAVE_BLAKE2 HAVE_SHA256 HAVE_SHA512
CFLAGS += -I$(MY_DIR)/../deps/tinycbor/src
CFLAGS += -g3 -ggdb3 -O3
APP_SOURCE_PATH += $(MY_DIR)/../deps/tinycbor-ledger
APP_SOURCE_PATH += $(MY_DIR)/../deps/jsmn/src


.PHONY: rust
rust:
@echo "No rust code"
Expand All @@ -87,7 +91,7 @@ dep/%.d: %.c Makefile

.PHONY: listvariants
listvariants:
@echo VARIANTS COIN ATOM
@echo VARIANTS COIN RUNE

.PHONY: version
version:
Expand Down
4 changes: 2 additions & 2 deletions app/Makefile.version
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is the `transaction_version` field of `Runtime`
APPVERSION_M=2
# This is the `spec_version` field of `Runtime`
APPVERSION_N=35
APPVERSION_N=3
# This is the patch version of this release
APPVERSION_P=18
APPVERSION_P=0
Binary file modified app/glyphs/icon_app.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 3 additions & 15 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@

#include "chain_config.h"

static const char *msg_error1 = "Expert Mode";
static const char *msg_error2 = "Required";

__Z_INLINE void handle_getversion(__Z_UNUSED volatile uint32_t *flags, volatile uint32_t *tx, __Z_UNUSED uint32_t rx) {
#ifdef DEBUG
G_io_apdu_buffer[0] = 0xFF;
Expand Down Expand Up @@ -95,7 +92,7 @@ __Z_INLINE void extractHDPath(uint32_t rx, uint32_t offset) {

// Check values
if (hdPath[0] != HDPATH_0_DEFAULT ||
((hdPath[1] != HDPATH_1_DEFAULT) && (hdPath[1] != HDPATH_ETH_1_DEFAULT)) ||
(hdPath[1] != HDPATH_1_DEFAULT) ||
hdPath[3] != HDPATH_3_DEFAULT) {
THROW(APDU_CODE_DATA_INVALID);
}
Expand All @@ -116,14 +113,11 @@ static void extractHDPath_HRP(uint32_t rx, uint32_t offset) {

// Check if HRP was sent
if ((rx - offset) > sizeof(uint32_t) * HDPATH_LEN_DEFAULT) {
uint8_t hrp_bech32_len = extractHRP(rx, offset + sizeof(uint32_t) * HDPATH_LEN_DEFAULT);
encoding = checkChainConfig(hdPath[1], bech32_hrp, hrp_bech32_len);
encoding = checkChainConfig(hdPath[1]);
if (encoding == UNSUPPORTED) {
ZEMU_LOGF(50, "Chain config not supported for: %s\n", bech32_hrp)
THROW(APDU_CODE_COMMAND_NOT_ALLOWED);
}
} else if (hdPath[1] == HDPATH_ETH_1_DEFAULT) {
THROW(APDU_CODE_COMMAND_NOT_ALLOWED);
}
}

Expand Down Expand Up @@ -165,7 +159,7 @@ __Z_INLINE void handleGetAddrSecp256K1(volatile uint32_t *flags, volatile uint32
extractHDPath(rx, OFFSET_DATA + 1 + len);

// Verify encoding
encoding = checkChainConfig(hdPath[1], bech32_hrp, bech32_hrp_len);
encoding = checkChainConfig(hdPath[1]);
if (encoding == UNSUPPORTED) {
ZEMU_LOGF(50, "Chain config not supported for: %s\n", bech32_hrp)
THROW(APDU_CODE_COMMAND_NOT_ALLOWED);
Expand Down Expand Up @@ -197,12 +191,6 @@ __Z_INLINE void handleSign(volatile uint32_t *flags, volatile uint32_t *tx, uint
// Let grab P2 value and if it's not valid, the parser should reject it
const tx_type_e sign_type = (tx_type_e) G_io_apdu_buffer[OFFSET_P2];

if ((hdPath[1] == HDPATH_ETH_1_DEFAULT) && !app_mode_expert()) {
*flags |= IO_ASYNCH_REPLY;
view_custom_error_show(PIC(msg_error1),PIC(msg_error2));
THROW(APDU_CODE_DATA_INVALID);
}

parser_tx_obj.tx_json.own_addr = (const char *) (G_io_apdu_buffer + VIEW_ADDRESS_OFFSET_SECP256K1);
const char *error_msg = tx_parse(sign_type);
if (error_msg != NULL) {
Expand Down
29 changes: 1 addition & 28 deletions app/src/chain_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,10 @@
#include "chain_config.h"
#include <zxmacros.h>

typedef struct {
const uint32_t path;
const char *hrp;
const address_encoding_e encoding;
} chain_config_t;

// To enable custom config for a new chain, just add a new entry in this array with path, hrp and encoding
static const chain_config_t chainConfig[] = {
// {118, cosmos, BECH32_COSMOS},
{60, "inj", BECH32_ETH},
{60, "evmos", BECH32_ETH}
};

static const uint32_t chainConfigLen = sizeof(chainConfig) / sizeof(chainConfig[0]);

address_encoding_e checkChainConfig(uint32_t path, const char* hrp, uint8_t hrpLen) {
address_encoding_e checkChainConfig(uint32_t path) {
// Always allowed for 118 (default Cosmos)
if (path == HDPATH_1_DEFAULT) {
return BECH32_COSMOS;
}

// Check special cases
for (uint32_t i = 0; i < chainConfigLen; i++) {
if (path == (0x80000000u | chainConfig[i].path)) {
const char* hrpPtr = (const char *) PIC(chainConfig[i].hrp);
const uint16_t hrpPtrLen = strlen(hrpPtr);
if (hrpPtrLen == hrpLen && memcmp(hrpPtr, hrp, hrpLen) == 0) {
return chainConfig[i].encoding;
}
}
}

return UNSUPPORTED;
}
2 changes: 1 addition & 1 deletion app/src/chain_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C" {
#include <stdbool.h>
#include "coin.h"

address_encoding_e checkChainConfig(uint32_t path, const char* hrp, uint8_t hrpLen);
address_encoding_e checkChainConfig(uint32_t path);

#ifdef __cplusplus
}
Expand Down
Loading
Loading