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 and fix breaking changes #112

Open
wants to merge 11 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
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
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
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ ICON_NANOS = icons/nanos_icon.gif
ICON_NANOX = icons/nanox_icon.gif
ICON_NANOSP = icons/nanox_icon.gif
ICON_STAX = icons/stax_icon.gif
ICON_FLEX = icons/flex_icon.png

# Application allowed derivation curves.
# Possibles curves are: secp256k1, secp256r1, ed25519 and bls12381g1
Expand Down Expand Up @@ -133,6 +134,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)
73 changes: 35 additions & 38 deletions deps/ledger-zxlib/app/common/app_main.c
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
/*******************************************************************************
* (c) 2018 - 2023 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 - 2024 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.
********************************************************************************/

#include "app_main.h"

#include <string.h>
#include <os_io_seproxyhal.h>
#include <os.h>
#include <os_io_seproxyhal.h>
#include <string.h>
#include <ux.h>

#include "view.h"
#include "actions.h"
#include "tx.h"
#include "app_mode.h"
#include "coin.h"
#include "tx.h"
#include "view.h"
#include "zxcanary.h"
#include "zxmacros.h"
#include "app_mode.h"
#ifdef HAVE_SWAP
#include "swap.h"
#endif // HAVE_SWAP
#endif // HAVE_SWAP

unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B];

unsigned char io_event(__Z_UNUSED unsigned char channel) {
switch (G_io_seproxyhal_spi_buffer[0]) {

case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT: // for Nano
#ifdef HAVE_BAGL
UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer);
Expand All @@ -50,7 +50,7 @@ unsigned char io_event(__Z_UNUSED unsigned char channel) {
THROW(EXCEPTION_IO_RESET);
}

__attribute__((fallthrough));
__attribute__((fallthrough));
case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT:
#ifdef HAVE_BAGL
UX_DISPLAYED_EVENT({});
Expand All @@ -77,7 +77,7 @@ unsigned char io_event(__Z_UNUSED unsigned char channel) {
if (!io_seproxyhal_spi_is_status_sent()) {
io_seproxyhal_general_status();
}
return 1; // DO NOT reset the current APDU transport
return 1; // DO NOT reset the current APDU transport
}

unsigned short io_exchange_al(unsigned char channel, unsigned short tx_len) {
Expand All @@ -93,7 +93,7 @@ unsigned short io_exchange_al(unsigned char channel, unsigned short tx_len) {
if (channel & IO_RESET_AFTER_REPLIED) {
reset();
}
return 0; // nothing received from the master so far (it's a tx
return 0; // nothing received from the master so far (it's a tx
// transaction)
} else {
return io_seproxyhal_spi_recv(G_io_apdu_buffer, sizeof(G_io_apdu_buffer), 0);
Expand Down Expand Up @@ -132,11 +132,12 @@ 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
G_io_app.plane_mode = os_setting_get(OS_SETTING_PLANEMODE, NULL, 0);
#endif // HAVE_BLE
#endif // HAVE_BLE

USB_power(0);
USB_power(1);
Expand All @@ -148,19 +149,18 @@ void app_init() {
view_idle_show(0, NULL);
}
#else
#ifdef SUPPORT_SR25519
#ifdef SUPPORT_SR25519
zeroize_sr25519_signdata();
#endif
#endif
view_idle_show(0, NULL);
#endif // HAVE_SWAP
#endif // POSTPONE_MAIN_SCREEN_INIT
#endif // HAVE_SWAP
#endif // POSTPONE_MAIN_SCREEN_INIT

#ifdef HAVE_BLE
// Enable Bluetooth
BLE_power(0, NULL);
BLE_power(1, NULL);
#endif // HAVE_BLE

#endif // HAVE_BLE
}

void app_main() {
Expand All @@ -183,17 +183,15 @@ void app_main() {
flags = 0;
CHECK_APP_CANARY()

if (rx == 0)
THROW(APDU_CODE_EMPTY_BUFFER);
if (rx == 0) THROW(APDU_CODE_EMPTY_BUFFER);

handle_generic_apdu(&flags, &tx, rx);
CHECK_APP_CANARY()

handleApdu(&flags, &tx, rx);
CHECK_APP_CANARY()
}
CATCH(EXCEPTION_IO_RESET)
{
CATCH(EXCEPTION_IO_RESET) {
// reset IO and UX before continuing
app_init();
continue;
Expand All @@ -214,8 +212,7 @@ void app_main() {
tx += 2;
}
FINALLY;
{
}
{}
}
END_TRY;
}
Expand Down
Loading
Loading