Skip to content

Commit

Permalink
Merge pull request #21 from LedgerHQ/develop
Browse files Browse the repository at this point in the history
Plugin release 2.1.1
  • Loading branch information
apaillier-ledger authored May 3, 2023
2 parents 567c267 + 72b70d9 commit 723670e
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 57 deletions.
142 changes: 104 additions & 38 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,75 +1,141 @@
name: Compilation & tests

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

jobs:
job_nano_build:
name: Build application for NanoS, X and S+
job_build_release_plugin:
name: Build release plugin
strategy:
matrix:
include:
- SDK: "$NANOS_SDK"
name: nanos
- SDK: "$NANOX_SDK"
name: nanox
- SDK: "$NANOSP_SDK"
name: nanosp
- sdk: "$NANOS_SDK"
name: "nanos"
- sdk: "$NANOX_SDK"
name: "nanox"
- sdk: "$NANOSP_SDK"
name: "nanosp"

runs-on: ubuntu-latest
container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest

steps:
- name: Clone
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive

- name: Build
run: |
make clean
make DEBUG=1 BOLOS_SDK=${{ matrix.SDK }}
make BOLOS_SDK=${{ matrix.sdk }} -j
job_build_debug_plugin:
name: Build debug plugin
strategy:
matrix:
include:
- sdk: "$NANOS_SDK"
name: "nanos"
- sdk: "$NANOX_SDK"
name: "nanox"
- sdk: "$NANOSP_SDK"
name: "nanosp"

runs-on: ubuntu-latest
container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest

steps:
- name: Clone
uses: actions/checkout@v3
with:
submodules: recursive

- name: Build
run: |
make DEBUG=1 BOLOS_SDK=${{ matrix.sdk }} -j
- name: Rename binary
run: |
mv bin/app.elf plugin_${{ matrix.name }}.elf
- name: Upload app binary
uses: actions/upload-artifact@v2
- name: Upload binary
uses: actions/upload-artifact@v3
with:
name: plugin-artifacts
path: ./plugin_*.elf
name: binaries
path: plugin_${{ matrix.name }}.elf

job_build_debug_app:
name: Build debug Ethereum app
strategy:
matrix:
include:
- sdk: "$NANOS_SDK"
name: "nanos"
- sdk: "$NANOX_SDK"
name: "nanox"
- sdk: "$NANOSP_SDK"
name: "nanosp"

jobs-e2e-tests:
needs: [job_nano_build]
runs-on: ubuntu-latest
container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest

steps:
- name: Test
- name: Checkout app-ethereum
uses: actions/checkout@v3
with:
repository: LedgerHQ/app-ethereum
ref: ${{ ((github.base_ref || github.ref_name) == 'main' && 'master') || (github.base_ref || github.ref_name) }}

- name: Build
run: |
make DEBUG=1 BYPASS_SIGNATURES=1 BOLOS_SDK=${{ matrix.sdk }} -j
- name: Rename binary
run: |
id
echo $HOME
echo $DISPLAY
mv bin/app.elf ethereum_${{ matrix.name }}.elf
- name: Upload binary
uses: actions/upload-artifact@v3
with:
name: binaries
path: ethereum_${{ matrix.name }}.elf

jobs-e2e-tests:
name: E2E Tests
needs: [job_build_debug_plugin, job_build_debug_app]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- run: sudo apt-get update -y && sudo apt-get install -y libusb-1.0.0 libudev-dev
uses: actions/checkout@v3

- name: Download built binaries
uses: actions/download-artifact@v3
with:
name: binaries
path: tests/elfs/

- name: Install node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: "14.4.0"
node-version: "16.19.0"

- name: Install yarn
run: |
npm install -g yarn
- name: Build/Install build js deps
- name: Install JS deps
run: |
cd tests && yarn install
- name: Download plugin artifacts
uses: actions/download-artifact@v2
with:
path: tests/elfs
- name: Copy plugin artifacts
run: |
mv tests/elfs/plugin-artifacts/*.elf tests/elfs
- name: Run zemu tests
- name: Run Zemu tests
run: |
cd tests && yarn test
15 changes: 7 additions & 8 deletions .github/workflows/lint-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: Code style check

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

jobs:
job_lint:
Expand All @@ -17,11 +16,11 @@ jobs:

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

- name: Lint
uses: DoozyX/clang-format-lint-action@v0.13
uses: DoozyX/clang-format-lint-action@v0.15
with:
source: "./"
extensions: "h,c"
clangFormatVersion: 12.0.0
clangFormatVersion: 12.0.1
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)

APPVERSION_M = 2
APPVERSION_N = 1
APPVERSION_P = 0
APPVERSION_P = 1
APPVERSION = $(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

APPNAME = "Paraswap"
Expand Down
2 changes: 1 addition & 1 deletion ethereum-plugin-sdk
32 changes: 24 additions & 8 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ static void handle_uniswap_and_forks(ethPluginProvideParameter_t *msg,
context->next_param = PATHS_OFFSET;
break;
case PATHS_OFFSET:
context->offset = U2BE(msg->parameter, PARAMETER_LENGTH - sizeof(context->offset));
if (!U2BE_from_parameter(msg->parameter, &context->offset)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = PATH;
break;
case PATH: // len(path)
Expand Down Expand Up @@ -152,7 +154,9 @@ static void handle_multiswap(ethPluginProvideParameter_t *msg, paraswap_paramete
}
break;
case PATHS_OFFSET:
context->offset = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
if (!U2BE_from_parameter(msg->parameter, &context->offset)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = PATHS_LEN;
break;
case PATHS_LEN:
Expand All @@ -163,7 +167,9 @@ static void handle_multiswap(ethPluginProvideParameter_t *msg, paraswap_paramete
PARAMETER_LENGTH; // Offset checkpoint starts after the length
break;
case OFFSET:
context->offset = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
if (!U2BE_from_parameter(msg->parameter, &context->offset)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = TOKEN_RECEIVED;
break;
case TOKEN_RECEIVED:
Expand Down Expand Up @@ -265,33 +271,43 @@ static void handle_megaswap(ethPluginProvideParameter_t *msg, paraswap_parameter
}
break;
case MEGA_PATHS_OFFSET:
context->offset = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
if (!U2BE_from_parameter(msg->parameter, &context->offset)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = MEGA_PATHS_LEN;
break;
case MEGA_PATHS_LEN:
context->next_param = FIRST_MEGAPATH_OFFSET;
break;
case FIRST_MEGAPATH_OFFSET:
context->checkpoint = msg->parameterOffset;
context->offset = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
if (!U2BE_from_parameter(msg->parameter, &context->offset)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = FIRST_MEGAPATH;
break;
case FIRST_MEGAPATH:
context->checkpoint = msg->parameterOffset;
context->next_param = PATHS_OFFSET;
break;
case PATHS_OFFSET:
context->offset = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
if (!U2BE_from_parameter(msg->parameter, &context->offset)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = PATHS_LEN;
break;
case PATHS_LEN:
context->skip = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
if (!U2BE_from_parameter(msg->parameter, &context->skip)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->skip--; // Decrease by one because we wish to acces path[-1].
context->next_param = PATH;
break;
case PATH:
context->checkpoint = msg->parameterOffset;
context->offset = U2BE(msg->parameter, PARAMETER_LENGTH - 2);
if (!U2BE_from_parameter(msg->parameter, &context->offset)) {
msg->result = ETH_PLUGIN_RESULT_ERROR;
}
context->next_param = TOKEN_RECEIVED;
break;
case TOKEN_RECEIVED:
Expand Down
24 changes: 23 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ void paraswap_plugin_call(int message, void *parameters) {
}
}

void handle_query_ui_exception(unsigned int *args) {
switch (args[0]) {
case ETH_PLUGIN_QUERY_CONTRACT_UI:
((ethQueryContractUI_t *) args[1])->result = ETH_PLUGIN_RESULT_ERROR;
break;
default:
break;
}
}

void call_app_ethereum() {
unsigned int libcall_params[3];
libcall_params[0] = (unsigned int) "Ethereum";
Expand Down Expand Up @@ -236,10 +246,22 @@ __attribute__((section(".boot"))) int main(int arg0) {
if (args[0] != ETH_PLUGIN_CHECK_PRESENCE) {
paraswap_plugin_call(args[0], (void *) args[1]);
}
os_lib_end();
}
}
CATCH_OTHER(e) {
switch (e) {
// These exceptions are only generated on handle_query_contract_ui()
case 0x6502:
case EXCEPTION_OVERFLOW:
handle_query_ui_exception((unsigned int *) arg0);
break;
default:
break;
}
PRINTF("Exception 0x%x caught\n", e);
}
FINALLY {
os_lib_end();
}
}
END_TRY;
Expand Down
Binary file removed tests/elfs/ethereum_nanos.elf
Binary file not shown.
Binary file removed tests/elfs/ethereum_nanox.elf
Binary file not shown.

0 comments on commit 723670e

Please sign in to comment.