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

Update zxlib #5

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/codeql_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
name: Analyse
strategy:
matrix:
sdk: [ "$NANOS_SDK", "$NANOX_SDK", "$NANOSP_SDK", "$STAX_SDK" ]
sdk: [ "$NANOS_SDK", "$NANOX_SDK", "$NANOSP_SDK", "$STAX_SDK", "$FLEX_SDK"]
#'cpp' covers C and C++
language: [ 'cpp' ]
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ ifeq ($(DEBUG),1)
DEFINES += ZEMU_LOGGING
endif

ifeq ($(PRODUCTION_BUILD),1)
DEFINES += PRODUCTION_BUILD=1
endif

#########################

# Import generic rules from the SDK
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

This repository contains:

- Ledger Nano S/Nano X/Nano SPlus/STAX BOLOS app
- Ledger Nano S/Nano X/Nano SPlus/STAX/FLEX BOLOS app
- Specs / Documentation
- Ledger ragger tests

Expand Down Expand Up @@ -51,14 +51,21 @@ make
make BOLOS_SDK=$NANOX_SDK
make BOLOS_SDK=$NANOSP_SDK
make BOLOS_SDK=$STAX_SDK
make BOLOS_SDK=$FLEX_SDK
```

Stax app can be compiled in DEBUG mode for debugging purposes
Stax and flex app can be compiled in DEBUG mode for debugging purposes
```shell
make BOLOS_SDK=$STAX_SDK DEBUG=1
```
Note, that it is possible (although unlikely) for ledger to make a braking change in ledger-app-dev-tools:latest.

Note, that the build by default builds a build with captions showing that it is a demo app. To replace the captions with correct ones one should use e.g.

```shell
make BOLOS_SDK=$STAX_SDK PRODUCTION_BUILD=1
```

#### Tests

##### Speculos integration tests
Expand All @@ -71,6 +78,7 @@ pytest tests/ --tb=short -v --device nanos
pytest tests/ --tb=short -v --device nanox
pytest tests/ --tb=short -v --device nanosp
pytest tests/ --tb=short -v --device stax
pytest tests/ --tb=short -v --device flex
```

Note that in case ledger-app-dev-tools:latest is updated there is a chance that slight changes in gui happen. In that case it is necessary to re-generate the snapshots, e.g.
Expand Down Expand Up @@ -99,6 +107,7 @@ make scan-build
make scan-build BOLOS_SDK=$NANOX_SDK
make scan-build BOLOS_SDK=$NANOSP_SDK
make scan-build BOLOS_SDK=$STAX_SDK
make scan-build BOLOS_SDK=$FLEX_SDK
```

## Further information
Expand Down Expand Up @@ -203,8 +212,9 @@ You can choose which device to compile and load for by setting the `BOLOS_SDK` e
- `BOLOS_SDK=$NANOX_SDK`
- `BOLOS_SDK=$NANOSP_SDK`
- `BOLOS_SDK=$STAX_SDK`
- `BOLOS_SDK=$FLEX_SDK`

For Stax device you can compile
For Stax and FLEX device you can compile
```shell
make BOLOS_SDK=$STAX_SDK DEBUG=1 # compile optionally with PRINTF
```
Expand Down
10 changes: 10 additions & 0 deletions deps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Updating zx-lib

Menu fetaure requires us to change zxlib menu layout. Thus instead of a submodule, we have ledger-zxlib included as a copy. In case you need to update zxlib, this is the list of changes performed.

- Menu contains new "Show address"/"View address" entries which display address and pubkey according to data saved on slot 0
- Menu changes. Remove "Developed by" and "Website" entries.
- Set MAX_CHARS_PER_VALUE1_LINE to 120
We experienced crashes with certain strings too long.
- Removed duplicate base58.* files to avoid warnings.

5 changes: 5 additions & 0 deletions deps/ledger-zxlib/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BasedOnStyle: Google
IndentWidth: 4
ColumnLimit: 120
DerivePointerAlignment: false
PointerAlignment: Right
21 changes: 21 additions & 0 deletions deps/ledger-zxlib/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Checks: "-*,
clang-analyzer-*,
clang-diagnostic-*,
cppcoreguidelines-init-variables,
google-readability-avoid-underscore-in-googletest-name,
google-runtime-int,
misc-*,
performance-*,
portability-*,
readability-*,
-misc-no-recursion,
-readability-function-cognitive-complexity
-readability-magic-numbers"
WarningsAsErrors: "*"
CheckOptions:
- key: readability-identifier-length.MinimumVariableNameLength
value: 2
- key: readability-identifier-length.MinimumParameterNameLength
value: 2
- key: readability-identifier-length.MinimumLoopCounterNameLength
value: 1
6 changes: 3 additions & 3 deletions deps/ledger-zxlib/.github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- run: cmake -DCMAKE_BUILD_TYPE=Debug . && make
Expand All @@ -26,7 +26,7 @@ jobs:
exists: ${{ steps.get-version.outputs.exists }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
Expand All @@ -53,7 +53,7 @@ jobs:
if: ${{ needs.check_version.outputs.exists != 'true' && github.ref == 'refs/heads/main' }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.check_version.outputs.version }}
35 changes: 27 additions & 8 deletions deps/ledger-zxlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#*******************************************************************************
#* (c) 2018 Zondax GmbH
#* (c) 2018 Zondax AG
#*
#* Licensed under the Apache License, Version 2.0 (the "License");
#* you may not use this file except in compliance with the License.
Expand All @@ -13,19 +13,38 @@
#* See the License for the specific language governing permissions and
#* limitations under the License.
#********************************************************************************
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.18)
include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/cpp-pm/hunter/archive/v0.25.5.tar.gz"
SHA1 "a20151e4c0740ee7d0f9994476856d813cdead29"
LOCAL
)

if(CMAKE_GENERATOR MATCHES "Ninja")
message(FATAL_ERROR "This project does not support the Ninja generator. "
"Please use Unix Makefiles or another supported generator. "
"This error is typical in CLion. In this case, switch to generator Unix Makefiles.")
endif()

########################################################
project(ledger-zxlib)

set(CMAKE_CXX_STANDARD 11)
cmake_policy(SET CMP0025 NEW)
cmake_policy(SET CMP0144 NEW)

enable_testing()

add_subdirectory(cmake/gtest)
hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)

###############

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
)

###############

file(GLOB_RECURSE ZXLIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/src/*.c
)
Expand All @@ -48,10 +67,10 @@ add_executable(zxlib_tests

target_include_directories(zxlib_tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${gtest_SOURCE_DIR}/include
${gmock_SOURCE_DIR}/include
)

target_link_libraries(zxlib_tests gtest_main zxlib)
target_link_libraries(zxlib_tests PRIVATE
GTest::gtest_main
zxlib)

add_test(ZXLIB_TESTS zxlib_tests)
2 changes: 1 addition & 1 deletion deps/ledger-zxlib/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2018-2020 Zondax GmbH
Copyright 2018-2024 Zondax AG

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion deps/ledger-zxlib/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ledger-zxlib

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

[![GithubActions](https://github.com/zondax/ledger-zxlib/actions/workflows/main.yml/badge.svg)](https://github.com/Zondax/ledger-zxlib/blob/main/.github/workflows/main.yaml)
[![CodeFactor](https://www.codefactor.io/repository/github/zondax/ledger-zxlib/badge)](https://www.codefactor.io/repository/github/zondax/ledger-zxlib)
2 changes: 2 additions & 0 deletions deps/ledger-zxlib/app/common/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "tx.h"
#include "coin.h"
#include "zxmacros.h"
#include "zxcanary.h"
#include "app_mode.h"
#ifdef HAVE_SWAP
#include "swap.h"
Expand Down Expand Up @@ -132,6 +133,7 @@ void handle_generic_apdu(__Z_UNUSED volatile uint32_t *flags, volatile uint32_t

void app_init() {
io_seproxyhal_init();
init_zondax_canary();

#ifdef HAVE_BLE
// grab the current plane mode setting
Expand Down
8 changes: 6 additions & 2 deletions deps/ledger-zxlib/app/ui/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ void view_initialize_init(viewfunc_initialize_t viewFuncInit) {

void view_review_show(review_type_e reviewKind) {
// Set > 0 to reply apdu message
view_review_show_impl((unsigned int)reviewKind);
view_review_show_impl((unsigned int)reviewKind, NULL, NULL);
}

void view_review_show_generic(review_type_e reviewKind, const char *title, const char *validate) {
view_review_show_impl((unsigned int)reviewKind, title, validate);
}

void view_initialize_show(uint8_t item_idx, const char *statusString) {
Expand All @@ -88,7 +92,7 @@ void h_reject(unsigned int requireReply) {
view_idle_show(0, NULL);
UX_WAIT();

if (requireReply != REVIEW_UI) {
if (requireReply != REVIEW_UI && requireReply != REVIEW_MSG) {
app_reject();
}
}
Expand Down
74 changes: 45 additions & 29 deletions deps/ledger-zxlib/app/ui/view.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
/*******************************************************************************
* (c) 2018 - 2022 Zondax AG
* (c) 2016 Ledger
*
* 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.
********************************************************************************/
* (c) 2018 - 2022 Zondax AG
* (c) 2016 Ledger
*
* 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

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

#include "coin.h"
#include "zxerror.h"

#if defined(LEDGER_SPECIFIC)
#include "bolos_target.h"
#if defined(BOLOS_SDK)
#include "os.h"
#include "cx.h"
#include "os.h"
#endif
#endif

#ifndef PRODUCTION_BUILD
#define PRODUCTION_BUILD 0
#endif

// By default our builds are not production ready
// Unless we specificaly define PRODUCTION_BUILD to 1
#if (PRODUCTION_BUILD == 0)
#undef MENU_MAIN_APP_LINE1
#undef MENU_MAIN_APP_LINE2

#define MENU_MAIN_APP_LINE1 APPVERSION_LINE1 " DEMO"
#define MENU_MAIN_APP_LINE2 "DO NOT USE"
#endif

typedef struct {
uint8_t displayIdx;
char *outKey;
Expand All @@ -46,7 +61,7 @@ typedef struct {
uint8_t pageCount;
} paging_t;

#define MAX_DEPTH 10
#define MAX_DEPTH 10
typedef struct {
uint8_t level;
uint8_t trace[MAX_DEPTH];
Expand All @@ -55,10 +70,8 @@ typedef struct {

typedef zxerr_t (*viewfunc_getNumItems_t)(uint8_t *num_items);

typedef zxerr_t (*viewfunc_getItem_t)(int8_t displayIdx,
char *outKey, uint16_t outKeyLen,
char *outVal, uint16_t outValLen,
uint8_t pageIdx, uint8_t *pageCount);
typedef zxerr_t (*viewfunc_getItem_t)(int8_t displayIdx, char *outKey, uint16_t outKeyLen, char *outVal,
uint16_t outValLen, uint8_t pageIdx, uint8_t *pageCount);

typedef zxerr_t (*viewfunc_getInnerItem_t)(uint8_t depth_level, uint8_t *trace, ui_field_t *ui_field);

Expand All @@ -69,9 +82,12 @@ typedef void (*viewfunc_accept_t)();
typedef zxerr_t (*viewfunc_initialize_t)();

typedef enum {
REVIEW_UI = 0,
REVIEW_ADDRESS,
REVIEW_TXN,
REVIEW_UI = 0,
REVIEW_ADDRESS,
// Used to review keys or params that needs user confirmation before send the response
REVIEW_GENERIC,
REVIEW_TXN,
REVIEW_MSG,
} review_type_e;

#ifdef APP_SECRET_MODE_ENABLED
Expand All @@ -95,12 +111,12 @@ void view_error_show();

void view_custom_error_show(const char *upper, const char *lower);

void view_review_init(viewfunc_getItem_t viewfuncGetItem,
viewfunc_getNumItems_t viewfuncGetNumItems,
void view_review_init(viewfunc_getItem_t viewfuncGetItem, viewfunc_getNumItems_t viewfuncGetNumItems,
viewfunc_accept_t viewfuncAccept);

void view_inspect_init(viewfunc_getInnerItem_t view_funcGetInnerItem,
viewfunc_getNumItems_t view_funcGetInnerNumItems,
viewfunc_canInspectItem_t view_funcCanInspectItem);
void view_inspect_init(viewfunc_getInnerItem_t view_funcGetInnerItem, viewfunc_getNumItems_t view_funcGetInnerNumItems,
viewfunc_canInspectItem_t view_funcCanInspectItem);

void view_review_show(review_type_e reviewKind);

void view_review_show_generic(review_type_e reviewKind, const char *title, const char *validate);
Loading
Loading