Skip to content

Commit

Permalink
Adjustments/Bug fixes (#4)
Browse files Browse the repository at this point in the history
* upgrade zxlib

* adjust ValidatorPrefs type

* updating makefile

* updating icons

* updating zemu screenshots
  • Loading branch information
jleni authored Jun 25, 2020
1 parent e83560a commit 2baab0d
Show file tree
Hide file tree
Showing 25 changed files with 2,097 additions and 1,831 deletions.
52 changes: 31 additions & 21 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ endif

MY_DIR := $(dir $(lastword $(MAKEFILE_LIST)))

ifeq ($(APP_TESTING),1)
DEFINES += APP_TESTING
DEFINES += ZEMU_LOGGING
endif

all: bin/app.elf
@echo "#!/usr/bin/env bash" > $(CURDIR)/pkg/zxtool.sh
@echo "APPNAME=\"${APPNAME}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "APPVERSION=\"${APPVERSION}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "APPPATH=\""${APPPATH}"\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "LOAD_PARAMS=\"${COMMON_LOAD_PARAMS}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "DELETE_PARAMS=\"${COMMON_DELETE_PARAMS}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "APPHEX=\"" >> $(CURDIR)/pkg/zxtool.sh
@cat $(CURDIR)/bin/app.hex >> $(CURDIR)/pkg/zxtool.sh
@echo "\"" >> $(CURDIR)/pkg/zxtool.sh
@cat $(CURDIR)/../deps/ledger-zxlib/scripts/template.sh >> $(CURDIR)/pkg/zxtool.sh
@chmod +x $(CURDIR)/pkg/zxtool.sh

include $(BOLOS_SDK)/Makefile.defines

ifndef COIN
Expand Down Expand Up @@ -68,19 +86,6 @@ ifndef ICONNAME
$(error ICONNAME is not set)
endif

all: default
@echo "#!/usr/bin/env bash" > $(CURDIR)/pkg/zxtool.sh
@echo "APPNAME=\"${APPNAME}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "APPVERSION=\"${APPVERSION}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "APPPATH=\""${APPPATH}"\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "LOAD_PARAMS=\"${COMMON_LOAD_PARAMS}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "DELETE_PARAMS=\"${COMMON_DELETE_PARAMS}\"" >> $(CURDIR)/pkg/zxtool.sh
@echo "APPHEX=\"" >> $(CURDIR)/pkg/zxtool.sh
@cat $(CURDIR)/bin/app.hex >> $(CURDIR)/pkg/zxtool.sh
@echo "\"" >> $(CURDIR)/pkg/zxtool.sh
@cat $(CURDIR)/../deps/ledger-zxlib/scripts/template.sh >> $(CURDIR)/pkg/zxtool.sh
@chmod +x $(CURDIR)/pkg/zxtool.sh

############
# Platform

Expand All @@ -96,8 +101,8 @@ 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 += USB_SEGMENT_SIZE=64
DEFINES += HAVE_BOLOS_APP_STACK_CANARY
DEFINES += USB_SEGMENT_SIZE=64
DEFINES += HAVE_BOLOS_APP_STACK_CANARY

DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""

Expand All @@ -113,7 +118,6 @@ DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX

DEFINES += HAVE_UX_FLOW

#SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
else
# Assume Nano S
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
Expand Down Expand Up @@ -165,34 +169,40 @@ APP_SOURCE_PATH += $(MY_DIR)/../deps/ledger-zxlib/include
APP_SOURCE_PATH += $(MY_DIR)/../deps/ledger-zxlib/src
APP_SOURCE_PATH += $(MY_DIR)/../deps/ledger-zxlib/app/common

SDK_SOURCE_PATH += lib_stusb lib_u2f lib_stusb_impl
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl

#SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
SDK_SOURCE_PATH += lib_ux

.PHONY: rust
rust:
cd rust && CARGO_HOME="$(CURDIR)/rust/.cargo" cargo build --target thumbv6m-none-eabi --release

# Before linking, we need to be sure rust lib is there
bin/app.elf: rust

.PHONY: rust_clean
rust_clean:
cd rust && CARGO_HOME="$(CURDIR)/rust/.cargo" cargo clean

clean: rust_clean

# load, delete and listvariants are provided to comply with Ledger requirements
.PHONY: load
load:
python -m ledgerblue.loadApp $(APP_LOAD_PARAMS)

.PHONY: delete
delete:
python -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)

.PHONY: rust

all: default rust

# Import generic rules from the SDK
include $(BOLOS_SDK)/Makefile.rules

#add dependency on custom makefile filename
dep/%.d: %.c Makefile

.PHONY: listvariants
listvariants:
@echo VARIANTS COIN DOT
@echo VARIANTS COIN Ledgeracio
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APPVERSION_M=0
APPVERSION_N=11
APPVERSION_P=1
APPVERSION_P=3
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.
Binary file modified app/nanos_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/nanox_icon.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion app/src/common/parser_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ typedef enum {
parser_init_context_empty,
parser_display_idx_out_of_range,
parser_display_page_out_of_range,
parser_unexepected_error,
parser_unexpected_error,
// Coin specific
parser_unexpected_address_type,
parser_spec_not_supported,
parser_not_supported,
parser_unexpected_buffer_end,
Expand Down
7 changes: 5 additions & 2 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ parser_error_t parser_getItem(const parser_context_t *ctx,
// CONTINUE WITH FIXED ARGUMENTS
displayIdx -= methodArgCount;
switch (displayIdx) {
case FIELD_NETWORK:
if (_detectAddressType() == PK_ADDRESS_TYPE) {
case FIELD_NETWORK: {
uint8_t addr_type;
CHECK_PARSER_ERR(_detectAddressType(&addr_type));
if (addr_type == PK_ADDRESS_TYPE) {
snprintf(outKey, outKeyLen, "Chain");
snprintf(outValue, outValueLen, COIN_NAME);
break;
Expand All @@ -150,6 +152,7 @@ parser_error_t parser_getItem(const parser_context_t *ctx,
outValue, outValueLen,
pageIdx, pageCount);
break;
}
case FIELD_ONCE:
snprintf(outKey, outKeyLen, "Nonce");
_toStringCompactIndex(&parser_tx_obj.nonce,
Expand Down
12 changes: 7 additions & 5 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ parser_error_t _readHash(parser_context_t *c, pd_Hash_t *v) {
GEN_DEF_READARRAY(32);
}

uint8_t _detectAddressType() {
parser_error_t _detectAddressType(uint8_t *addr_type) {
char hashstr[65];
uint8_t pc;

Expand All @@ -461,19 +461,21 @@ uint8_t _detectAddressType() {

// Compare with known genesis hashes
if (strcmp(hashstr, COIN_GENESIS_HASH) == 0) {
return PK_ADDRESS_TYPE;
*addr_type = PK_ADDRESS_TYPE;
return parser_ok;
}
}

return 42;
return parser_unexpected_address_type;
}

parser_error_t _toStringPubkeyAsAddress(const uint8_t *pubkey,
char *outValue, uint16_t outValueLen,
uint8_t pageIdx, uint8_t *pageCount) {
uint8_t addressType = _detectAddressType();
uint8_t addr_type;
CHECK_PARSER_ERR(_detectAddressType(&addr_type));

if (crypto_SS58EncodePubkey((uint8_t *) bufferUI, sizeof(bufferUI), addressType, pubkey) == 0) {
if (crypto_SS58EncodePubkey((uint8_t *) bufferUI, sizeof(bufferUI), addr_type, pubkey) == 0) {
return parser_no_data;
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/parser_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ parser_error_t _readEra(parser_context_t *c, pd_ExtrinsicEra_t *v);

parser_error_t _readTx(parser_context_t *c, parser_tx_t *v);

uint8_t _detectAddressType();
parser_error_t _detectAddressType(uint8_t *addr_type);

parser_error_t _toStringCompactInt(const compactInt_t *c,
uint8_t decimalPlaces,
Expand Down
17 changes: 15 additions & 2 deletions app/src/substrate_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ parser_error_t _readValidatorIndex(parser_context_t *c, pd_ValidatorIndex_t *v)

parser_error_t _readValidatorPrefs(parser_context_t *c, pd_ValidatorPrefs_t *v) {
CHECK_INPUT();
return _readCompactBalance(c, &v->balance);
return _readCompactPerBill(c, &v->commission);
}

parser_error_t _readVestingInfo(parser_context_t *c, pd_VestingInfo_t *v) {
Expand Down Expand Up @@ -1521,7 +1521,7 @@ parser_error_t _toStringValidatorPrefs(
uint16_t outValueLen,
uint8_t pageIdx,
uint8_t *pageCount) {
return _toStringCompactBalance(&v->balance, outValue, outValueLen, pageIdx, pageCount);
return _toStringCompactPerBill(&v->commission, outValue, outValueLen, pageIdx, pageCount);
}

parser_error_t _toStringVestingInfo(
Expand Down Expand Up @@ -1918,6 +1918,10 @@ parser_error_t _readCompactBalanceOf(parser_context_t *c, pd_CompactBalanceOf_t
return _readCompactBalance(c, v);
}

parser_error_t _readCompactPerBill(parser_context_t *c, pd_CompactPerBill_t *v) {
return _readCompactInt(c, v);
}

parser_error_t _readKeys(parser_context_t *c, pd_Keys_t *v) {
GEN_DEF_READARRAY(5 * 32);
}
Expand Down Expand Up @@ -2004,6 +2008,15 @@ parser_error_t _toStringCompactBalanceOf(
return _toStringCompactBalance(v, outValue, outValueLen, pageIdx, pageCount);
}

parser_error_t _toStringCompactPerBill(
const pd_CompactPerBill_t *v,
char *outValue,
uint16_t outValueLen,
uint8_t pageIdx,
uint8_t *pageCount) {
return _toStringCompactInt(v, 9, outValue, outValueLen, pageIdx, pageCount);
}

parser_error_t _toStringCompactu32(
const pd_Compactu32_t *v,
char *outValue,
Expand Down
12 changes: 11 additions & 1 deletion app/src/substrate_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ typedef compactInt_t pd_CompactMoment_t;

typedef compactInt_t pd_CompactParaId_t;

typedef compactInt_t pd_CompactPerBill_t;

typedef compactInt_t pd_CompactPropIndex_t;

typedef compactInt_t pd_CompactProposalIndex_t;
Expand Down Expand Up @@ -413,7 +415,7 @@ typedef struct {
} pd_ValidatorIndex_t;

typedef struct {
pd_CompactBalance_t balance;
pd_CompactPerBill_t commission;
} pd_ValidatorPrefs_t;

typedef struct {
Expand Down Expand Up @@ -554,6 +556,7 @@ parser_error_t _readCompactLeasePeriodOf(parser_context_t *c, pd_CompactLeasePer
parser_error_t _readCompactMemberCount(parser_context_t *c, pd_CompactMemberCount_t *v);
parser_error_t _readCompactMoment(parser_context_t *c, pd_CompactMoment_t *v);
parser_error_t _readCompactParaId(parser_context_t *c, pd_CompactParaId_t *v);
parser_error_t _readCompactPerBill(parser_context_t *c, pd_CompactPerBill_t *v);
parser_error_t _readCompactPropIndex(parser_context_t *c, pd_CompactPropIndex_t *v);
parser_error_t _readCompactProposalIndex(parser_context_t *c, pd_CompactProposalIndex_t *v);
parser_error_t _readCompactReferendumIndex(parser_context_t *c, pd_CompactReferendumIndex_t *v);
Expand Down Expand Up @@ -781,6 +784,13 @@ parser_error_t _toStringCompactParaId(
uint8_t pageIdx,
uint8_t *pageCount);

parser_error_t _toStringCompactPerBill(
const pd_CompactPerBill_t *v,
char *outValue,
uint16_t outValueLen,
uint8_t pageIdx,
uint8_t *pageCount);

parser_error_t _toStringCompactPropIndex(
const pd_CompactPropIndex_t *v,
char *outValue,
Expand Down
Binary file added app/tmp.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions deps/ledger-zxlib/app/common/view_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ static unsigned int view_error_button(unsigned int button_mask, unsigned int but
static unsigned int view_review_button(unsigned int button_mask, unsigned int button_mask_counter) {
switch (button_mask) {
case BUTTON_EVT_RELEASED | BUTTON_LEFT | BUTTON_RIGHT:
// Press both left and right buttons to quit
view_sign_show_s();
if (app_mode_expert()) {
// Press both left and right buttons to quit
view_sign_show_s();
}
break;
case BUTTON_EVT_RELEASED | BUTTON_LEFT:
// Press left to progress to the previous element
Expand Down
14 changes: 12 additions & 2 deletions deps/ledger-zxlib/app/common/view_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ UX_STEP_NOCB_INIT(ux_addr_flow_2_step, bnnn_paging,
UX_STEP_VALID(ux_addr_flow_3_step, pb, h_address_accept(0), { &C_icon_validate_14, "Ok"});

UX_FLOW(
ux_addr_flow,
ux_addr_flow_no_path,
&ux_addr_flow_1_step,
&ux_addr_flow_3_step
);

UX_FLOW(
ux_addr_flow_with_path,
&ux_addr_flow_1_step,
&ux_addr_flow_2_step,
&ux_addr_flow_3_step
Expand Down Expand Up @@ -225,7 +231,11 @@ void view_address_show_impl() {
if(G_ux.stack_count == 0) {
ux_stack_push();
}
ux_flow_init(0, ux_addr_flow, NULL);
if (app_mode_expert()) {
ux_flow_init(0, ux_addr_flow_with_path, NULL);
} else {
ux_flow_init(0, ux_addr_flow_no_path, NULL);
}
}

void view_error_show_impl() {
Expand Down
80 changes: 80 additions & 0 deletions deps/ledger-zxlib/app/common/zbuffer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*******************************************************************************
* (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.
********************************************************************************/

#include "zbuffer.h"
#include "zxmacros.h"

typedef struct {
uint8_t *ptr;
uint16_t size;
} zbuffer_t;

zbuffer_t _internal;

#define CANARY_EXPECTED 0x987def82u

zbuffer_error_e zb_get(uint8_t **buffer) {
*buffer = NULL;
if (_internal.size == 0 || _internal.ptr == NULL) {
return zb_not_allocated;
}
*buffer = _internal.ptr;
return zb_no_error;
}

zbuffer_error_e zb_init() {
_internal.size = 0;
_internal.ptr = NULL;
return zb_no_error;
}

zbuffer_error_e zb_allocate(uint16_t size) {
if (size % 4 != 0) {
return zb_misaligned_buffer;
}
_internal.size = size;
_internal.ptr = (uint8_t *) (&app_stack_canary + 4);

uint32_t *zb_canary = (uint32_t *) (_internal.ptr + _internal.size + 4);
*zb_canary = CANARY_EXPECTED;

return zb_no_error;
}

zbuffer_error_e zb_deallocate() {
if (_internal.size == 0) {
return zb_not_allocated;
}

// Flush any information
MEMZERO(_internal.ptr, _internal.size);

zb_init();
return zb_no_error;
}

zbuffer_error_e zb_check_canary() {
CHECK_APP_CANARY();
if (_internal.size != 0) {
// allocated
uint32_t *zb_canary = (uint32_t *) (_internal.ptr + _internal.size + 4);
if (*zb_canary != CANARY_EXPECTED) {
handle_stack_overflow();
}
}

return zb_no_error;
}
Loading

0 comments on commit 2baab0d

Please sign in to comment.