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

[LDG-585]: update code base, ethereum-plugin-sdk and snapshots #18

Merged
merged 6 commits into from
Nov 25, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Checklist
<!-- Put an `x` in each box when you have completed the items. -->
- [ ] App update process has been followed <!-- See comment below -->
- [ ] Target branch is `develop` <!-- unless you have a very good reason -->
- [ ] Application version has been bumped <!-- required if your changes are to be deployed -->

<!-- Make sure you followed the process described in https://developers.ledger.com/docs/embedded-app/maintenance/ before opening your Pull Request.
Don't hesitate to contact us directly on Discord if you have any questions ! https://developers.ledger.com/discord -->
3 changes: 2 additions & 1 deletion .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ jobs:
uses: actions/checkout@v3
with:
repository: LedgerHQ/app-ethereum
submodules: recursive
ref: ${{ ((github.base_ref || github.ref_name) == 'main' && 'master') || (github.base_ref || github.ref_name) }}

- name: Build
Expand Down Expand Up @@ -138,4 +139,4 @@ jobs:

- name: Run Zemu tests
run: |
cd tests && yarn test
cd tests && yarn test
23 changes: 23 additions & 0 deletions .github/workflows/guidelines_enforcer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Ensure compliance with Ledger guidelines

# This workflow is mandatory in all applications
# It calls a reusable workflow guidelines_enforcer developed by Ledger's internal developer team.
# The successful completion of the reusable workflow is a mandatory step for an app to be available on the Ledger
# application store.
#
# More information on the guidelines can be found in the repository:
# LedgerHQ/ledger-app-workflows/

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

jobs:
guidelines_enforcer:
name: Call Ledger guidelines_enforcer
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_guidelines_enforcer.yml@v1
18 changes: 18 additions & 0 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Release build

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

jobs:
build:
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_bindaries"
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ debug/
dep/
obj/
tests/elfs/plugin_nano*.elf
build/

# Editors
.idea/
.vscode/

# Python
*.pyc[cod]
Expand All @@ -22,3 +24,6 @@ __pycache__/
tests/node_modules
tests/lib
tests/snapshots-tmp

# MacOS
.DS_Store
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "ethereum-plugin-sdk"]
path = ethereum-plugin-sdk
url = git@github.com:LedgerHQ/ethereum-plugin-sdk.git
url = https://github.com/LedgerHQ/ethereum-plugin-sdk.git
146 changes: 5 additions & 141 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,147 +15,11 @@
# limitations under the License.
#*******************************************************************************

ifeq ($(BOLOS_SDK),)
$(error Environment variable BOLOS_SDK is not set)
endif

include $(BOLOS_SDK)/Makefile.defines

APP_LOAD_PARAMS += --appFlags 0x800 --path "44'/60'" --path "45'" --curve secp256k1
APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)

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

APPNAME = "Paraswap"

#prepare hsm generation
ifeq ($(TARGET_NAME), TARGET_NANOS)
ICONNAME=icons/nanos_app_paraswap.gif
else
ICONNAME=icons/nanox_app_paraswap.gif
endif

################
# Default rule #
################
all: default

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

DEFINES += OS_IO_SEPROXYHAL
DEFINES += HAVE_BAGL HAVE_SPRINTF
DEFINES += LEDGER_MAJOR_VERSION=$(APPVERSION_M) LEDGER_MINOR_VERSION=$(APPVERSION_N) LEDGER_PATCH_VERSION=$(APPVERSION_P)
DEFINES += IO_HID_EP_LENGTH=64

DEFINES += UNUSED\(x\)=\(void\)x
DEFINES += APPVERSION=\"$(APPVERSION)\"

ifeq ($(TARGET_NAME),TARGET_NANOX)
DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000
DEFINES += HAVE_BLE_APDU # basic ledger apdu transport over BLE
endif

ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
else
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
DEFINES += HAVE_GLO096
DEFINES += HAVE_BAGL BAGL_WIDTH=128 BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS # long label truncation feature
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX
DEFINES += HAVE_UX_FLOW
endif

# Enabling debug PRINTF
DEBUG:= 0
ifneq ($(DEBUG),0)
DEFINES += HAVE_STACK_OVERFLOW_CHECK
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl lib_u2f
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=4 IO_HID_EP_LENGTH=64 HAVE_USB_APDU

ifeq ($(DEBUG),10)
$(warning Using semihosted PRINTF. Only run with speculos!)
CFLAGS += -include src/dbg/debug.h
DEFINES += HAVE_PRINTF PRINTF=semihosted_printf
else
ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += HAVE_PRINTF PRINTF=screen_printf
else
DEFINES += HAVE_PRINTF PRINTF=mcu_usb_printf
endif

endif
else
DEFINES += PRINTF\(...\)=
endif

##############
# Compiler #
##############
ifneq ($(BOLOS_ENV),)
$(info BOLOS_ENV=$(BOLOS_ENV))
CLANGPATH := $(BOLOS_ENV)/clang-arm-fropi/bin/
GCCPATH := $(BOLOS_ENV)/gcc-arm-none-eabi-5_3-2016q1/bin/
else
$(info BOLOS_ENV is not set: falling back to CLANGPATH and GCCPATH)
endif
ifeq ($(CLANGPATH),)
$(info CLANGPATH is not set: clang will be used from PATH)
endif
ifeq ($(GCCPATH),)
$(info GCCPATH is not set: arm-none-eabi-* will be used from PATH)
endif

CC := $(CLANGPATH)clang

#CFLAGS += -O0
CFLAGS += -O3 -Os

AS := $(GCCPATH)arm-none-eabi-gcc

LD := $(GCCPATH)arm-none-eabi-gcc
LDFLAGS += -O3 -Os
LDLIBS += -lm -lgcc -lc

# import rules to compile glyphs(/pone)
include $(BOLOS_SDK)/Makefile.glyphs

### variables processed by the common makefile.rules of the SDK to grab source files and include dirs
APP_SOURCE_PATH += src ethereum-plugin-sdk
SDK_SOURCE_PATH += lib_ux
ifeq ($(TARGET_NAME),TARGET_NANOX)
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
endif


# remove UX warnings from SDK even though the plugin doesn't use it
DEFINES += HAVE_UX_FLOW

### initialize plugin SDK submodule if needed
ifneq ($(shell git submodule status | grep '^[-+]'),)
$(info INFO: Need to reinitialize git submodules)
$(shell git submodule update --init)
endif

load: all
python3 -m ledgerblue.loadApp $(APP_LOAD_PARAMS)

delete:
python3 -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)

# import generic rules from the sdk
include $(BOLOS_SDK)/Makefile.rules


#add dependency on custom makefile filename
dep/%.d: %.c Makefile
# Application version
APPVERSION_M = 2
APPVERSION_N = 1
APPVERSION_P = 1

listvariants:
@echo VARIANTS NONE paraswap
include ethereum-plugin-sdk/standard_plugin.mk
2 changes: 1 addition & 1 deletion ethereum-plugin-sdk
Submodule ethereum-plugin-sdk updated 44 files
+118 −0 .github/workflows/_reusable_build_with_submodule_injection.yml
+49 −0 .github/workflows/build_and_test.yml
+44 −0 .github/workflows/publish_doc_website.yml
+2 −0 .gitignore
+98 −0 CHANGELOG.md
+2 −16 README.md
+ docs/img/Ledger-logo-696.webp
+51 −0 docs/index.md
+4 −0 docs/requirements.txt
+57 −0 docs/technical_informations/diagram.md
+15 −0 docs/technical_informations/globals.md
+11 −0 docs/technical_informations/handlers/handle_finalize.md
+11 −0 docs/technical_informations/handlers/handle_init_contract.md
+11 −0 docs/technical_informations/handlers/handle_provide_parameter.md
+19 −0 docs/technical_informations/handlers/handle_provide_token.md
+11 −0 docs/technical_informations/handlers/handle_query_contract_id.md
+19 −0 docs/technical_informations/handlers/handle_query_contract_ui.md
+10 −0 docs/technical_informations/handlers/index.md
+3 −0 docs/technical_informations/index.md
+5 −0 docs/technical_informations/tx_content.md
+3 −0 docs/technical_informations/utils/common_utils.md
+3 −0 docs/technical_informations/utils/index.md
+3 −0 docs/technical_informations/utils/plugin_utils.md
+1 −0 docs/test_framework/ci.md
+1 −0 docs/test_framework/fuzzing.md
+9 −0 docs/test_framework/index.md
+1 −0 docs/test_framework/ragger.md
+ docs/walkthrough/img/uniswap.webp
+52 −0 docs/walkthrough/index.md
+0 −111 include/eth_internals.h
+0 −182 include/eth_plugin_interface.h
+75 −0 mkdocs.yml
+53 −0 src/asset_info.h
+9 −0 src/bip32_utils.h
+34 −0 src/caller_api.h
+230 −158 src/common_utils.c
+280 −0 src/common_utils.h
+23 −0 src/eth_internals.h
+461 −0 src/eth_plugin_interface.h
+122 −0 src/main.c
+45 −0 src/plugin_utils.c
+109 −0 src/plugin_utils.h
+55 −0 src/tx_content.h
+61 −0 standard_plugin.mk
Binary file removed glyphs/icon_back.gif
Binary file not shown.
Binary file removed glyphs/icon_back_x.gif
Binary file not shown.
Binary file removed glyphs/icon_certificate.gif
Binary file not shown.
Binary file removed glyphs/icon_crossmark.gif
Binary file not shown.
Binary file removed glyphs/icon_dashboard.gif
Binary file not shown.
Binary file removed glyphs/icon_dashboard_x.gif
Binary file not shown.
Binary file removed glyphs/icon_down.gif
Binary file not shown.
Binary file removed glyphs/icon_eye.gif
Binary file not shown.
Binary file removed glyphs/icon_left.gif
Binary file not shown.
Binary file removed glyphs/icon_right.gif
Binary file not shown.
Binary file removed glyphs/icon_toggle_reset.gif
Binary file not shown.
Binary file removed glyphs/icon_toggle_set.gif
Binary file not shown.
Binary file removed glyphs/icon_up.gif
Binary file not shown.
Binary file removed glyphs/icon_validate_14.gif
Binary file not shown.
Binary file removed glyphs/icon_warning.gif
Binary file not shown.
4 changes: 4 additions & 0 deletions ledger_app.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[app]
build_directory = "./"
sdk = "C"
devices = ["nanos", "nanox", "nanos+"]
101 changes: 0 additions & 101 deletions src/main.c → src/contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
* limitations under the License.
********************************************************************************/

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

#include "os.h"
#include "cx.h"

#include "glyphs.h"

#include "paraswap_plugin.h"

// ---------- Paraswap V5 -------------
Expand Down Expand Up @@ -175,96 +167,3 @@ const uint8_t PARASWAP_ETH_ADDRESS[ADDRESS_LENGTH] = {0xee, 0xee, 0xee, 0xee, 0x
const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

void paraswap_plugin_call(int message, void *parameters) {
switch (message) {
case ETH_PLUGIN_INIT_CONTRACT:
handle_init_contract(parameters);
break;
case ETH_PLUGIN_PROVIDE_PARAMETER:
handle_provide_parameter(parameters);
break;
case ETH_PLUGIN_FINALIZE:
handle_finalize(parameters);
break;
case ETH_PLUGIN_PROVIDE_INFO:
handle_provide_token(parameters);
break;
case ETH_PLUGIN_QUERY_CONTRACT_ID:
handle_query_contract_id(parameters);
break;
case ETH_PLUGIN_QUERY_CONTRACT_UI:
handle_query_contract_ui(parameters);
break;
default:
PRINTF("Unhandled message %d\n", message);
break;
}
}

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";
libcall_params[1] = 0x100;
libcall_params[2] = RUN_APPLICATION;
os_lib_call((unsigned int *) &libcall_params);
}

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

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

// Try catch block. Please read the docs for more information on how to use those!
BEGIN_TRY {
TRY {
// Low-level black magic.
check_api_level(CX_COMPAT_APILEVEL);
// Check if we are called from the dashboard.
if (!arg0) {
// called from dashboard, launch Ethereum app
call_app_ethereum();
return 0;
} else {
// Not called from dashboard: called from the ethereum app!
const unsigned int *args = (unsigned int *) arg0;

// If `ETH_PLUGIN_CHECK_PRESENCE` is set, this means the caller is just trying to
// know whether this app exists or not. We can skip `paraswap_plugin_call`.
if (args[0] != ETH_PLUGIN_CHECK_PRESENCE) {
paraswap_plugin_call(args[0], (void *) args[1]);
}
}
}
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;

return 0;
}
2 changes: 1 addition & 1 deletion src/handle_finalize.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "paraswap_plugin.h"

void handle_finalize(void *parameters) {
void handle_finalize(ethPluginFinalize_t *parameters) {
ethPluginFinalize_t *msg = (ethPluginFinalize_t *) parameters;
paraswap_parameters_t *context = (paraswap_parameters_t *) msg->pluginContext;
if (context->valid) {
Expand Down
2 changes: 1 addition & 1 deletion src/handle_init_contract.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "paraswap_plugin.h"

// Called once to init.
void handle_init_contract(void *parameters) {
void handle_init_contract(ethPluginInitContract_t *parameters) {
ethPluginInitContract_t *msg = (ethPluginInitContract_t *) parameters;

if (msg->interfaceVersion != ETH_PLUGIN_INTERFACE_VERSION_LATEST) {
Expand Down
2 changes: 1 addition & 1 deletion src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static void handle_swap_uni_v2(ethPluginProvideParameter_t *msg, paraswap_parame
}
}

void handle_provide_parameter(void *parameters) {
void handle_provide_parameter(ethPluginProvideParameter_t *parameters) {
ethPluginProvideParameter_t *msg = (ethPluginProvideParameter_t *) parameters;
paraswap_parameters_t *context = (paraswap_parameters_t *) msg->pluginContext;

Expand Down
2 changes: 1 addition & 1 deletion src/handle_provide_token.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "paraswap_plugin.h"

void handle_provide_token(void *parameters) {
void handle_provide_token(ethPluginProvideInfo_t *parameters) {
ethPluginProvideInfo_t *msg = (ethPluginProvideInfo_t *) parameters;
paraswap_parameters_t *context = (paraswap_parameters_t *) msg->pluginContext;
PRINTF("PARASWAP plugin provide token: 0x%p, 0x%p\n", msg->item1, msg->item2);
Expand Down
Loading
Loading