Skip to content

Commit

Permalink
Merge pull request #68 from LedgerHQ/develop
Browse files Browse the repository at this point in the history
Solana 1.4.1 is released in prod, forward changes on master to reflect it
  • Loading branch information
fbeutin-ledger authored May 30, 2023
2 parents 4cd0e65 + 9475238 commit 1160a67
Show file tree
Hide file tree
Showing 469 changed files with 959 additions and 344 deletions.
81 changes: 13 additions & 68 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,75 +10,20 @@ on:

jobs:
build_application:
strategy:
matrix:
sdk:
- path: $NANOS_SDK
name: nanos
- path: $NANOX_SDK
name: nanox
- path: $NANOSP_SDK
name: nanosp

runs-on: ubuntu-latest

container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest

steps:
- name: Clone
uses: actions/checkout@v3

- name: Build application
run: |
make BOLOS_SDK=${{ matrix.sdk.path }} DEBUG=1
cp bin/app.elf bin/solana_${{ matrix.sdk.name }}.elf
- name: Upload application binaries
uses: actions/upload-artifact@v3
with:
name: solana_binaries
path: ./bin/solana_${{ matrix.sdk.name }}.elf
if-no-files-found: error

job_scan_build:
name: Clang Static Analyzer
needs: build_application
runs-on: ubuntu-latest
container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- uses: actions/checkout@v3
- name: Build with Clang Static Analyzer
run: |
make clean
scan-build --use-cc=clang -analyze-headers -enable-checker security -enable-checker unix -enable-checker valist -o scan-build --status-bugs make default
- uses: actions/upload-artifact@v3
if: failure()
with:
name: scan-build
path: scan-build

python_tests_nano:
name: NanoS Ragger tests
name: Build application using the reusable workflow
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1
with:
upload_app_binaries_artifact: compiled_app_binaries
run_for_devices: '["nanos", "nanox", "nanosp"]'

ragger_tests:
name: Run ragger tests using the reusable workflow
needs: build_application
runs-on: ubuntu-latest
steps:
- name: Clone
uses: actions/checkout@v3
- name: Download all binaries
uses: actions/download-artifact@v3
- name: Gather artifacts
run: |
mkdir tests/elfs
mv *_binaries/*.elf tests/elfs
- name: Install APT dependencies
run: sudo apt-get update && sudo apt-get install -y qemu-user-static
- name: Install Ragger
run: |
pip install --extra-index-url https://test.pypi.org/simple/ -r tests/python/requirements.txt
- name: Run tests
run: pytest tests/python/ -v --tb=short --device all
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_ragger_tests.yml@v1
with:
download_app_binaries_artifact: compiled_app_binaries
test_dir: tests/python
run_for_devices: '["nanos", "nanox", "nanosp"]'

job_C_test:
name: C tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
# Use Config file when the github action supports it
builtin: clear,rare
check_filenames: true
skip: ./libsol,./tests
skip: ./libsol/printer_test.c,./tests/Cargo.lock
16 changes: 16 additions & 0 deletions .github/workflows/swap-ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Swap functional tests

on:
workflow_dispatch:
push:
branches:
- master
- develop
pull_request:

jobs:
job_functional_tests:
uses: LedgerHQ/app-exchange/.github/workflows/reusable_swap_functional_tests.yml@develop
with:
branch_for_solana: ${{ github.ref }}
test_filter: '"SOL or sol or Solana or solana"'
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
build
bin
debug
dep
obj
dev-env
src/glyphs.c
src/glyphs.h
.idea
.vscode
gitignore
Expand All @@ -17,5 +16,4 @@ __pycache__
.pyc
*~

tests/elfs/
tests/python/snapshots-tmp/
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ endif

include $(BOLOS_SDK)/Makefile.defines

APP_LOAD_PARAMS = --curve ed25519
ifeq ($(TARGET_NAME), TARGET_NANOX)
APP_LOAD_PARAMS += --appFlags 0x200 # APPLICATION_FLAG_BOLOS_SETTINGS
APP_LOAD_PARAMS = --curve ed25519
ifeq ($(TARGET_NAME), TARGET_NANOS)
APP_LOAD_PARAMS += --appFlags 0x800 # APPLICATION_FLAG_LIBRARY
else
APP_LOAD_PARAMS += --appFlags 0x000
APP_LOAD_PARAMS += --appFlags 0xa00 # APPLICATION_FLAG_LIBRARY + APPLICATION_FLAG_BOLOS_SETTINGS
endif
APP_LOAD_PARAMS += --path "44'/501'"
APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)

APPNAME = "Solana"
APPVERSION_M = 1
APPVERSION_N = 3
APPVERSION_N = 4
APPVERSION_P = 1
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ git clone --branch 1.0.3 --depth 1 https://github.com/LedgerHQ/nanosplus-secure-
* Solana [system dependencies](https://github.com/solana-labs/solana/#1-install-rustc-cargo-and-rustfmt)

## Build
It is highly recommended that you read and understand the [Ledger App Builder](https://developers.ledger.com/docs/nano-app/build/)
It is highly recommended that you read and understand the [Ledger App Builder](https://developers.ledger.com/docs/embedded-app/build-app/#2-build-the-application)
build process before proceeding. A convenience wrapper script (`./docker-make`) has been provided for simplicity

`docker-make` manages the current target SDK for you, automatically setting `BOLOS_SDK` to the
Expand All @@ -104,7 +104,7 @@ from clean and clean must be run _before_ switching
```

## Working with the device
Requires that the `BOLOS_SDK` envvar [be set](https://developers.ledger.com/docs/nano-app/load/).
Requires that the `BOLOS_SDK` envvar [be set](https://developers.ledger.com/docs/embedded-app/build-app/#b-build-the-application).
This can be achieved by first [building](#build) for the desired target device.
### Load
```bash
Expand Down
1 change: 1 addition & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## 1.3.0

- Add SIGN SOLANA OFF-CHAIN MESSAGE
- Add compatibility with the Exchange Application to SWAP, FUND, or SELL SOL tokens

## About

Expand Down
2 changes: 1 addition & 1 deletion libsol/message_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <assert.h>
#include <stdio.h>

// Disable clang format for this file to keep clear buffer formating
// Disable clang format for this file to keep clear buffer formatting
/* clang-format off */

void test_process_message_body_ok() {
Expand Down
2 changes: 1 addition & 1 deletion src/apdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ int apdu_handle_message(const uint8_t* apdu_message,
apdu_command->state = ApduStatePayloadComplete;

return 0;
}
}
4 changes: 2 additions & 2 deletions src/getPubkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ UX_STEP_NOCB(ux_display_public_flow_5_step,
});
UX_STEP_CB(ux_display_public_flow_6_step,
pb,
sendResponse(set_result_get_pubkey(), true),
sendResponse(set_result_get_pubkey(), true, true),
{
&C_icon_validate_14,
"Approve",
});
UX_STEP_CB(ux_display_public_flow_7_step,
pb,
sendResponse(0, false),
sendResponse(0, false, true),
{
&C_icon_crossmark,
"Reject",
Expand Down
5 changes: 4 additions & 1 deletion src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ typedef enum InstructionCode {
InsSignOffchainMessage = 0x07
} InstructionCode;

extern volatile bool G_called_from_swap;
extern volatile bool G_swap_response_ready;

// display stepped screens
extern unsigned int ux_step;
extern unsigned int ux_step_count;
Expand Down Expand Up @@ -84,4 +87,4 @@ typedef struct internalStorage_t {

extern const internalStorage_t N_storage_real;
#define N_storage (*(volatile internalStorage_t*) PIC(&N_storage_real))
#endif
#endif
109 changes: 101 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@
#include "apdu.h"
#include "menu.h"

// Swap feature
#include "swap_lib_calls.h"
#include "handle_swap_sign_transaction.h"
#include "handle_get_printable_amount.h"
#include "handle_check_address.h"

ApduCommand G_command;
unsigned char G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B];
volatile bool G_called_from_swap;
volatile bool G_swap_response_ready;

static void reset_main_globals(void) {
MEMCLEAR(G_command);
Expand All @@ -41,8 +49,10 @@ void handleApdu(volatile unsigned int *flags, volatile unsigned int *tx, int rx)

const int ret = apdu_handle_message(G_io_apdu_buffer, rx, &G_command);
if (ret != 0) {
MEMCLEAR(G_command);
THROW(ret);
}

if (G_command.state == ApduStatePayloadInProgress) {
THROW(ApduReplySuccess);
}
Expand Down Expand Up @@ -96,7 +106,6 @@ void app_main(void) {
// APDU injection faults.
for (;;) {
volatile unsigned short sw = 0;

BEGIN_TRY {
TRY {
rx = tx;
Expand All @@ -105,6 +114,12 @@ void app_main(void) {
rx = io_exchange(CHANNEL_APDU | flags, rx);
flags = 0;

if (G_called_from_swap && G_swap_response_ready) {
PRINTF("Quitting app started in swap mode\n");
// Quit app, we are in limited mode and our work is done
os_sched_exit(0);
}

// no apdu received, well, reset the session, and reset the
// bootloader configuration
if (rx == 0) {
Expand Down Expand Up @@ -260,13 +275,8 @@ void nv_app_state_init() {
}
}

__attribute__((section(".boot"))) int main(void) {
// exit critical section
__asm volatile("cpsie i");

// ensure exception will work as planned
os_boot();

void coin_main(void) {
G_called_from_swap = false;
for (;;) {
UX_INIT();

Expand Down Expand Up @@ -307,5 +317,88 @@ __attribute__((section(".boot"))) int main(void) {
END_TRY;
}
app_exit();
}

static void start_app_from_lib(void) {
G_called_from_swap = true;
G_swap_response_ready = false;
UX_INIT();
io_seproxyhal_init();
nv_app_state_init();
USB_power(0);
USB_power(1);
#ifdef HAVE_BLE
// Erase globals that may inherit values from exchange
MEMCLEAR(G_io_asynch_ux_callback);
// grab the current plane mode setting
G_io_app.plane_mode = os_setting_get(OS_SETTING_PLANEMODE, NULL, 0);
BLE_power(0, NULL);
BLE_power(1, "Nano X");
#endif // HAVE_BLE
app_main();
}

static void library_main_helper(libargs_t *args) {
check_api_level(CX_COMPAT_APILEVEL);
switch (args->command) {
case CHECK_ADDRESS:
// ensure result is zero if an exception is thrown
args->check_address->result = 0;
args->check_address->result = handle_check_address(args->check_address);
break;
case SIGN_TRANSACTION:
if (copy_transaction_parameters(args->create_transaction)) {
// never returns
start_app_from_lib();
}
break;
case GET_PRINTABLE_AMOUNT:
handle_get_printable_amount(args->get_printable_amount);
break;
default:
break;
}
}

static void library_main(libargs_t *args) {
volatile bool end = false;
/* This loop ensures that library_main_helper and os_lib_end are called
* within a try context, even if an exception is thrown */
while (1) {
BEGIN_TRY {
TRY {
if (!end) {
library_main_helper(args);
}
os_lib_end();
}
FINALLY {
end = true;
}
}
END_TRY;
}
}

__attribute__((section(".boot"))) int main(int arg0) {
// exit critical section
__asm volatile("cpsie i");

// ensure exception will work as planned
os_boot();

if (arg0 == 0) {
// called from dashboard as standalone app
coin_main();
} else {
// Called as library from another app
libargs_t *args = (libargs_t *) arg0;
if (args->id == 0x100) {
library_main(args);
} else {
app_exit();
}
}

return 0;
}
Loading

0 comments on commit 1160a67

Please sign in to comment.