Skip to content

Commit

Permalink
Merge pull request #6 from Zondax/main
Browse files Browse the repository at this point in the history
Upgrade Statemine
  • Loading branch information
lpascal-ledger authored Feb 21, 2022
2 parents 1e8f828 + 1f89328 commit 69b7bf2
Show file tree
Hide file tree
Showing 50 changed files with 12,825 additions and 7,323 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ file(GLOB_RECURSE LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser_impl.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser_txdef.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/substrate*.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/substrate/substrate*.c
)

add_library(app_lib STATIC ${LIB_SRC})
Expand All @@ -126,6 +126,7 @@ target_include_directories(app_lib PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/app/src
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib
${CMAKE_CURRENT_SOURCE_DIR}/app/src/common
${CMAKE_CURRENT_SOURCE_DIR}/app/src/substrate
)

##############################################################
Expand Down
245 changes: 125 additions & 120 deletions README.md

Large diffs are not rendered by default.

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=4
APPVERSION_M=5
# This is the `spec_version` field of `Runtime`
APPVERSION_N=601
APPVERSION_N=700
# This is the patch version of this release
APPVERSION_P=0
51 changes: 2 additions & 49 deletions app/src/coin.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* (c) 2020 Zondax GmbH
* (c) 2019 - 2022 Zondax GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,51 +15,4 @@
********************************************************************************/
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#define CLA 0x97

#define HDPATH_LEN_DEFAULT 5
#define HDPATH_0_DEFAULT (0x80000000 | 0x2c)
#define HDPATH_1_DEFAULT (0x80000000 | 0x1b2) // 434 - Kusama/Statemine
#define HDPATH_1_RECOVERY (0x80000000 | 0x162) // 354 - Polkadot

#define SK_LEN_25519 64u
#define SCALAR_LEN_ED25519 32u
#define SIG_PLUS_TYPE_LEN 65u

#define PK_LEN_25519 32u
#define MAX_SIGN_SIZE 256u
#define BLAKE2B_DIGEST_SIZE 32u

typedef enum {
key_ed25519 = 0,

#if defined(SUPPORT_SR25519)
key_sr25519 = 1
#endif

} key_kind_e;

// Coin Specific
#define PK_ADDRESS_TYPE COIN_ADDR_TYPE_KUSAMA
#define SUPPORTED_TX_VERSION_CURRENT LEDGER_MAJOR_VERSION
#define SUPPORTED_TX_VERSION_PREVIOUS (LEDGER_MAJOR_VERSION - 1)
#define SUPPORTED_SPEC_VERSION (LEDGER_MINOR_VERSION + 0)
#define SUPPORTED_MINIMUM_SPEC_VERSION 0

#define COIN_AMOUNT_DECIMAL_PLACES 12

#define COIN_GENESIS_HASH "48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a"
#define COIN_NAME "Statemine"
#define COIN_TICKER "KSM "

#define COIN_SECRET_REQUIRED_CLICKS 0

#include "coin_standard.h"

#ifdef __cplusplus
}
#endif
#include "substrate_coin.h"
30 changes: 0 additions & 30 deletions app/src/coin_ss58.h

This file was deleted.

39 changes: 0 additions & 39 deletions app/src/coin_standard.h

This file was deleted.

1 change: 1 addition & 0 deletions app/src/common/parser_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ typedef enum {
parser_unexpected_callIndex,
parser_unexpected_unparsed_bytes,
parser_print_not_supported,
parser_tx_nesting_not_supported,
parser_tx_nesting_limit_reached,
parser_tx_call_vec_too_large,
} parser_error_t;
Expand Down
1 change: 0 additions & 1 deletion app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "app_mode.h"
#include "parser.h"
#include "coin.h"
#include "coin_ss58.h"
#include "substrate_dispatch.h"

#if defined(TARGET_NANOX)
Expand Down
3 changes: 2 additions & 1 deletion app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "coin.h"
#include "crypto_helper.h"
#include "bignum.h"
#include "coin_ss58.h"
#include "substrate_types.h"
#include "substrate_dispatch.h"

Expand Down Expand Up @@ -85,6 +84,8 @@ const char *parser_getErrorDescription(parser_error_t err) {
return "Unexpected unparsed bytes";
case parser_print_not_supported:
return "Value cannot be printed";
case parser_tx_nesting_not_supported:
return "Call nesting not supported";
case parser_tx_nesting_limit_reached:
return "Max nested calls reached";
case parser_tx_call_vec_too_large:
Expand Down
74 changes: 74 additions & 0 deletions app/src/substrate/substrate_coin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* (c) 2019 - 2022 Zondax GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
********************************************************************************/
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#define COIN_ADDR_TYPE 2
#define CLA 0x97

#define HDPATH_LEN_DEFAULT 5
#define HDPATH_0_DEFAULT (0x80000000 | 0x2c)
#define HDPATH_1_DEFAULT (0x80000000 | 0x1b2)
#define HDPATH_1_RECOVERY (0x80000000 | 0x1b2)

#define HDPATH_2_DEFAULT (0x80000000u | 0u)
#define HDPATH_3_DEFAULT (0u)
#define HDPATH_4_DEFAULT (0u)

#define SK_LEN_25519 64u
#define SCALAR_LEN_ED25519 32u
#define SIG_PLUS_TYPE_LEN 65u

#define PK_LEN_25519 32u
#define MAX_SIGN_SIZE 256u
#define BLAKE2B_DIGEST_SIZE 32u

typedef enum {
key_ed25519 = 0,

#if defined(SUPPORT_SR25519)
key_sr25519 = 1
#endif

} key_kind_e;

// Coin Specific
#define PK_ADDRESS_TYPE COIN_ADDR_TYPE
#define SUPPORTED_TX_VERSION_CURRENT LEDGER_MAJOR_VERSION
#define SUPPORTED_TX_VERSION_PREVIOUS (LEDGER_MAJOR_VERSION - 1)
#define SUPPORTED_SPEC_VERSION (LEDGER_MINOR_VERSION + 0)
#define SUPPORTED_MINIMUM_SPEC_VERSION 600

#define COIN_AMOUNT_DECIMAL_PLACES 12

#define COIN_GENESIS_HASH "48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a"
#define COIN_NAME "Statemine"
#define COIN_TICKER "KSM "

#define COIN_SECRET_REQUIRED_CLICKS 0

#define MENU_MAIN_APP_LINE1 "Statemine"
#define MENU_MAIN_APP_LINE2 "Ready"
#define MENU_MAIN_APP_LINE2_SECRET "KSM RECOVERY"
#define APPVERSION_LINE1 "Statemine"
#define APPVERSION_LINE2 "v" APPVERSION

#ifdef __cplusplus
}
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* (c) 2019 Zondax GmbH
* (c) 2019 - 2022 Zondax GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,26 +26,32 @@ parser_error_t _readMethod(
pd_Method_t* method)
{
switch (c->tx_obj->transactionVersion) {
case 5:
return _readMethod_V5(c, moduleIdx, callIdx, &method->V5);
case 4:
return _readMethod_V4(c, moduleIdx, callIdx, &method->V4);
default:
return parser_not_supported;
return parser_tx_version_not_supported;
}
}

uint8_t _getMethod_NumItems(uint32_t transactionVersion, uint8_t moduleIdx, uint8_t callIdx)
{
switch (transactionVersion) {
case 5:
return _getMethod_NumItems_V5(moduleIdx, callIdx);
case 4:
return _getMethod_NumItems_V4(moduleIdx, callIdx);
default:
return parser_not_supported;
return parser_tx_version_not_supported;
}
}

const char* _getMethod_ModuleName(uint32_t transactionVersion, uint8_t moduleIdx)
{
switch (transactionVersion) {
case 5:
return _getMethod_ModuleName_V5(moduleIdx);
case 4:
return _getMethod_ModuleName_V4(moduleIdx);
default:
Expand All @@ -56,6 +62,8 @@ const char* _getMethod_ModuleName(uint32_t transactionVersion, uint8_t moduleIdx
const char* _getMethod_Name(uint32_t transactionVersion, uint8_t moduleIdx, uint8_t callIdx)
{
switch (transactionVersion) {
case 5:
return _getMethod_Name_V5(moduleIdx, callIdx);
case 4:
return _getMethod_Name_V4(moduleIdx, callIdx);
default:
Expand All @@ -66,6 +74,8 @@ const char* _getMethod_Name(uint32_t transactionVersion, uint8_t moduleIdx, uint
const char* _getMethod_ItemName(uint32_t transactionVersion, uint8_t moduleIdx, uint8_t callIdx, uint8_t itemIdx)
{
switch (transactionVersion) {
case 5:
return _getMethod_ItemName_V5(moduleIdx, callIdx, itemIdx);
case 4:
return _getMethod_ItemName_V4(moduleIdx, callIdx, itemIdx);
default:
Expand All @@ -78,17 +88,22 @@ parser_error_t _getMethod_ItemValue(uint32_t transactionVersion, pd_Method_t* m,
uint8_t pageIdx, uint8_t* pageCount)
{
switch (transactionVersion) {
case 5:
return _getMethod_ItemValue_V5(&m->V5, moduleIdx, callIdx, itemIdx, outValue,
outValueLen, pageIdx, pageCount);
case 4:
return _getMethod_ItemValue_V4(&m->V4, moduleIdx, callIdx, itemIdx, outValue,
outValueLen, pageIdx, pageCount);
default:
return parser_not_supported;
return parser_tx_version_not_supported;
}
}

bool _getMethod_ItemIsExpert(uint32_t transactionVersion, uint8_t moduleIdx, uint8_t callIdx, uint8_t itemIdx)
{
switch (transactionVersion) {
case 5:
return _getMethod_ItemIsExpert_V5(moduleIdx, callIdx, itemIdx);
case 4:
return _getMethod_ItemIsExpert_V4(moduleIdx, callIdx, itemIdx);
default:
Expand All @@ -99,6 +114,8 @@ bool _getMethod_ItemIsExpert(uint32_t transactionVersion, uint8_t moduleIdx, uin
bool _getMethod_IsNestingSupported(uint32_t transactionVersion, uint8_t moduleIdx, uint8_t callIdx)
{
switch (transactionVersion) {
case 5:
return _getMethod_IsNestingSupported_V5(moduleIdx, callIdx);
case 4:
return _getMethod_IsNestingSupported_V4(moduleIdx, callIdx);
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* (c) 2019 Zondax GmbH
* (c) 2019 - 2022 Zondax GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@ extern "C" {
#include "parser_common.h"
#include "stdbool.h"
#include "substrate_dispatch_V4.h"
#include "substrate_dispatch_V5.h"
#include <stddef.h>
#include <stdint.h>

Expand All @@ -32,6 +33,9 @@ extern "C" {
{ \
switch (txVersion) { \
\
case 5: \
return PD_CALL_##CALL##_V5; \
\
case 4: \
return PD_CALL_##CALL##_V4; \
\
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 69b7bf2

Please sign in to comment.