Skip to content

Commit

Permalink
Merge pull request #1 from Zondax/dev
Browse files Browse the repository at this point in the history
Add polkadot 11 support
  • Loading branch information
jleni authored Jun 22, 2020
2 parents d084568 + e68dd8d commit b3726e6
Show file tree
Hide file tree
Showing 163 changed files with 7,526 additions and 4,411 deletions.
21 changes: 9 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
command: |
source /home/zondax/.cargo/env
cd /home/zondax/project
COIN=KSM_restricted make
COIN=Ledgeracio make
test_zemu:
machine:
Expand Down Expand Up @@ -87,12 +87,9 @@ jobs:
make
- run:
name: Rename installer
command: cp /home/zondax/project/app/pkg/zxtool.sh /home/zondax/project/app/pkg/install_KSM_app.sh
- run: /home/zondax/go/bin/ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace $(/home/zondax/project/app/pkg/zxtool.sh version) /home/zondax/project/app/pkg/install_KSM_app.sh
- run:
name: Rename elf
command: cp /home/zondax/project/app/bin/app.elf /home/zondax/project/app/bin/app_KSM.elf
- run: /home/zondax/go/bin/ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace $(/home/zondax/project/app/pkg/zxtool.sh version) /home/zondax/project/app/bin/app_KSM.elf
command: cp /home/zondax/project/app/pkg/zxtool.sh /home/zondax/project/app/pkg/install_app.sh
- run: /home/zondax/go/bin/ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace $(/home/zondax/project/app/pkg/zxtool.sh version) /home/zondax/project/app/pkg/install_app.sh
- run: /home/zondax/go/bin/ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace $(/home/zondax/project/app/pkg/zxtool.sh version) /home/zondax/project/app/bin/app.elf

build_package_ledgeracio:
docker:
Expand All @@ -108,15 +105,15 @@ jobs:
command: |
source /home/zondax/.cargo/env
cd /home/zondax/project
COIN=KSM_restricted make
COIN=Ledgeracio make
- run:
name: Rename installer
command: cp /home/zondax/project/app/pkg/zxtool.sh /home/zondax/project/app/pkg/install_KSM_ledgeracio_app.sh
- run: /home/zondax/go/bin/ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace $(/home/zondax/project/app/pkg/zxtool.sh version) /home/zondax/project/app/pkg/install_KSM_ledgeracio_app.sh
command: cp /home/zondax/project/app/pkg/zxtool.sh /home/zondax/project/app/pkg/install_ledgeracio_app.sh
- run: /home/zondax/go/bin/ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace $(/home/zondax/project/app/pkg/zxtool.sh version) /home/zondax/project/app/pkg/install_ledgeracio_app.sh
- run:
name: Rename elf
command: cp /home/zondax/project/app/bin/app.elf /home/zondax/project/app/bin/app_KSM_ledgeracio.elf
- run: /home/zondax/go/bin/ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace $(/home/zondax/project/app/pkg/zxtool.sh version) /home/zondax/project/app/bin/app_KSM_ledgeracio.elf
command: cp /home/zondax/project/app/bin/app.elf /home/zondax/project/app/bin/app_ledgeracio.elf
- run: /home/zondax/go/bin/ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -replace $(/home/zondax/project/app/pkg/zxtool.sh version) /home/zondax/project/app/bin/app_ledgeracio.elf

workflows:
version: 2
Expand Down
33 changes: 3 additions & 30 deletions 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-kusama VERSION 0.0.0)
project(ledger-polkadot VERSION 0.0.0)
enable_testing()

cmake_policy(SET CMP0025 NEW)
Expand Down Expand Up @@ -68,8 +68,8 @@ 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/polkadot_types.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/polkadot_dispatch.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/substrate_types.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/substrate_dispatch.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib/base58.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib/uint256.c
)
Expand Down Expand Up @@ -107,30 +107,3 @@ target_link_libraries(unittests PRIVATE

add_test(unittests ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittests)
set_tests_properties(unittests PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)

##############################################################
##############################################################
# Fuzzing
file(GLOB FUZZING_SRC
${CMAKE_CURRENT_SOURCE_DIR}/fuzzing/fuzzingMain.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tests/utils/common.cpp)

add_executable(fuzzing_stub ${FUZZING_SRC})
target_include_directories(fuzzing_stub PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/app/src
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib
${CMAKE_CURRENT_SOURCE_DIR}/tests
)

add_library(app_lib32 STATIC ${LIB_SRC})
target_include_directories(app_lib32 PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/deps/BLAKE2/ref
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/include
${CMAKE_CURRENT_SOURCE_DIR}/app/src
${CMAKE_CURRENT_SOURCE_DIR}/app/src/common
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib
)
#set_target_properties(app_lib32 PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")

target_link_libraries(fuzzing_stub app_lib32)
#set_target_properties(fuzzing_stub PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ default:
COIN=$(COIN) $(MAKE) -C app $@
endif

build2: COIN=KSM_restricted # Alternative app purpose
build2: COIN=Ledgeracio # Alternative app purpose
build2: build
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Ledger Kusama app (eXpeCT ChAoS)
# Ledger Polkadot app
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![CircleCI](https://circleci.com/gh/Zondax/ledger-kusama.svg?style=shield)](https://circleci.com/gh/Zondax/ledger-kusama)
[![CircleCI](https://circleci.com/gh/Zondax/ledger-polkadot.svg?style=shield)](https://circleci.com/gh/Zondax/ledger-polkadot)

>NOTE: The minor value in the version number indicates runtime compatibility. For instance: 0.1042.1, Indicates that the app is compatible with runtime 1042*
This project contains the Kusama app (https://kusama.network/) for Ledger Nano S and X.
This project contains the Polkadot app (https://polkadot.network/) for Ledger Nano S and X.

- Ledger Nano S/X BOLOS app
- Specs / Documentation
Expand All @@ -28,7 +28,7 @@ Tip:
*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-kusama/releases). You only need `zxtool.sh`
Download a release from here (https://github.com/Zondax/ledger-polkadot/releases). You only need `zxtool.sh`

If the file is not executable, run
```sh
Expand Down
18 changes: 7 additions & 11 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ MY_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(BOLOS_SDK)/Makefile.defines

ifndef COIN
COIN=KSM
COIN=DOT
endif

include $(CURDIR)/Makefile.version

$(info COIN = [$(COIN)])
ifeq ($(COIN),KSM)
ifeq ($(COIN),DOT)
# Main app configuration
DEFINES += APP_STANDARD
APPNAME = "Kusama"
APPNAME = "Polkadot"
APPPATH = "44'/434'"

else ifeq ($(COIN),KSM_restricted)
else ifeq ($(COIN),Ledgeracio)
DEFINES += APP_RESTRICTED
APPNAME = "Kusama_sec"
APPNAME = "Polkadot_sec"
APPPATH = "44'/434'"

else
Expand Down Expand Up @@ -96,10 +96,7 @@ DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=7 IO_HID_EP_LEN

DEFINES += LEDGER_MAJOR_VERSION=$(APPVERSION_M) LEDGER_MINOR_VERSION=$(APPVERSION_N) LEDGER_PATCH_VERSION=$(APPVERSION_P)

DEFINES += HAVE_U2F HAVE_IO_U2F
DEFINES += U2F_PROXY_MAGIC=\"KSM\"
DEFINES += USB_SEGMENT_SIZE=64
DEFINES += U2F_MAX_MESSAGE_SIZE=264 #257+5+2
DEFINES += HAVE_BOLOS_APP_STACK_CANARY

DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""
Expand All @@ -117,7 +114,6 @@ DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX
DEFINES += HAVE_UX_FLOW

#SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
SDK_SOURCE_PATH += lib_ux
else
# Assume Nano S
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
Expand Down Expand Up @@ -198,5 +194,5 @@ include $(BOLOS_SDK)/Makefile.rules
dep/%.d: %.c Makefile

listvariants:
@echo VARIANTS COIN KSM
@echo VARIANTS COIN KSM_restricted
@echo VARIANTS COIN DOT
@echo VARIANTS COIN Ledgeracio
6 changes: 3 additions & 3 deletions app/Makefile.version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APPVERSION_M=1
APPVERSION_N=2008
APPVERSION_P=2
APPVERSION_M=0
APPVERSION_N=11
APPVERSION_P=0
2 changes: 0 additions & 2 deletions app/rust/include/rslib.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#pragma once

#include <stdint.h>

int8_t rs_sha512_256(const uint8_t *input, uint32_t inputSize, uint8_t *output, uint32_t outputMaxSize);
46 changes: 0 additions & 46 deletions app/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#[macro_use]
extern crate hex_literal;

mod bolos;

extern crate core;

fn debug(_msg: &str) {}
Expand All @@ -24,47 +22,3 @@ use sha2::{Sha256, Digest, Sha512Trunc256};
fn panic(_info: &PanicInfo) -> ! {
loop {}
}


#[no_mangle]
pub extern "C" fn rs_sha512_256(input_ptr: *const u8, input_size: usize, output_ptr: *const u8, output_size: usize) -> i8 {
if output_size != 32 {
return -1;
}

let input = unsafe { core::slice::from_raw_parts(input_ptr, input_size as usize) };
let output = unsafe { mem::transmute::<*const u8, &mut [u8; 32]>(output_ptr) };

let mut hasher = Sha512Trunc256::new();
hasher.input(input);
let result = hasher.result();

output.copy_from_slice(&result);
return 0;
}

#[cfg(test)]
mod tests {

use crate::*;
use sha2::Sha512Trunc256;

#[test]
fn sha512_256_pure() {
let mut hasher = Sha512Trunc256::new();
hasher.input(b"Zondax");
let result = hasher.result();

assert_eq!(result[..], hex!("3d119a287af12a4a1f263803f18a674f200d86e07954286dfe33cad245fe1be9")[..]);
}

#[test]
fn sha512_256_c() {
let data = b"Zondax";
let result = [0u8; 32];

rs_sha512_256(data.as_ptr(), data.len(), result.as_ptr(), result.len());

assert_eq!(result[..], hex!("3d119a287af12a4a1f263803f18a674f200d86e07954286dfe33cad245fe1be9")[..]);
}
}
37 changes: 37 additions & 0 deletions app/src/coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,47 @@
********************************************************************************/
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#define CLA 0x90

#define HDPATH_LEN_DEFAULT 5
#define HDPATH_0_DEFAULT (0x80000000 | 0x2c)
#define HDPATH_1_DEFAULT (0x80000000 | 0x162) // 354

#define PK_LEN_ED25519 32u

typedef enum {
addr_ed22519 = 0,
addr_sr25519 = 1
} address_kind_e;

#define VIEW_ADDRESS_OFFSET_ED25519 (PK_LEN_ED25519)
#define VIEW_ADDRESS_ITEM_COUNT 2
#define VIEW_ADDRESS_LAST_PAGE_DEFAULT 0

// Coin Specific
#define PK_ADDRESS_TYPE COIN_ADDR_TYPE_POLKADOT
#define SUPPORTED_TX_VERSION LEDGER_MAJOR_VERSION
#define SUPPORTED_SPEC_VERSION LEDGER_MINOR_VERSION
#define SUPPORTED_MINIMUM_SPEC_VERSION 11

#define COIN_AMOUNT_DECIMAL_PLACES 12
#define CRYPTO_BLOB_SKIP_BYTES 0

#define COIN_GENESIS_HASH "91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3"
#define COIN_NAME "Polkadot"

#if defined(APP_STANDARD)
#include "coin_standard.h"
#elif defined(APP_RESTRICTED)
#include "coin_restricted.h"
#else
#error "APP VARIANT IS NOT SUPPORTED"
#endif

#ifdef __cplusplus
}
#endif
33 changes: 3 additions & 30 deletions app/src/coin_restricted.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,18 @@ extern "C" {

#include <stdint.h>
#include <stddef.h>
#include "coin_ss58.h"

#define CLA 0x99

#define HDPATH_LEN_DEFAULT 5

#define HDPATH_0_DEFAULT (0x80000000 | 0x2c)
#define HDPATH_1_DEFAULT (0x80000000 | 0x1b2) // 434
#define HDPATH_2_STASH (0x80000000u | 0u)
#define HDPATH_2_VALIDATOR (0x80000000u | 1u)
#define HDPATH_3_DEFAULT (0x80000000u)
#define HDPATH_4_DEFAULT (0x80000000u)

#define PK_LEN_ED25519 32u

typedef enum {
addr_ed22519 = 0,
addr_sr25519 = 1
} address_kind_e;

#define VIEW_ADDRESS_OFFSET_ED25519 (PK_LEN_ED25519)
#define VIEW_ADDRESS_ITEM_COUNT 2
#define VIEW_ADDRESS_LAST_PAGE_DEFAULT 0

#define MENU_MAIN_APP_LINE1 "Kusama | sec"
#define MENU_MAIN_APP_LINE1 "Polkadot | sec"
#define MENU_MAIN_APP_LINE2 "Ledgeracio"
#define APPVERSION_LINE1 "Kusama | sec"
#define APPVERSION_LINE1 "Polkadot | sec"
#define APPVERSION_LINE2 "v" APPVERSION

// Specific to Kusama
#define PK_ADDRESS_TYPE 02
#define SUPPORTED_TX_VERSION LEDGER_MAJOR_VERSION
#define SUPPORTED_SPEC_VERSION LEDGER_MINOR_VERSION
#define SUPPORTED_MINIMUM_SPEC_VERSION 2008

#define COIN_AMOUNT_DECIMAL_PLACES 12
#define CRYPTO_BLOB_SKIP_BYTES 0

#define COIN_KUSAMA_CC3_GENESIS_HASH "B0A8D493285C2DF73290DFB7E61F870F17B41801197A149CA93654499EA3DAFE"

#ifdef __cplusplus
}
#endif
30 changes: 30 additions & 0 deletions app/src/coin_ss58.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* (c) 2020 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_POLKADOT 0
#define COIN_ADDR_TYPE_KUSAMA 2
#define COIN_ADDR_TYPE_EDGEWARE 7
#define COIN_ADDR_TYPE_KULUPU 16
#define COIN_ADDR_TYPE_DOTHEREUM 20

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit b3726e6

Please sign in to comment.