From d0ea2c80e53254e629e030c00925d47e1f060f5e Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Tue, 13 Aug 2024 14:01:33 +0300 Subject: [PATCH 1/7] Remove debug sanitize from libsol The newly builders are based on Alpine Linux that doesn't support `libasan`. See https://gitlab.alpinelinux.org/alpine/aports/-/issues/10304 --- libsol/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsol/Makefile b/libsol/Makefile index 1067343e..9cf967e9 100644 --- a/libsol/Makefile +++ b/libsol/Makefile @@ -18,7 +18,7 @@ ifeq ($(COVERAGE),1) CFLAGS += --coverage endif -debug_CFLAGS = -g -fsanitize=address -fsanitize=undefined +debug_CFLAGS = -g release_CFLAGS = -O2 libsol_source_files = $(filter-out %_test.c,$(wildcard *.c)) From 3579a9c352fc7fb69f8da20f951db4b864d218a4 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Tue, 13 Aug 2024 16:28:30 +0300 Subject: [PATCH 2/7] Use the latest builder for C tests --- .github/workflows/ci-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-workflow.yml b/.github/workflows/ci-workflow.yml index 29e17faf..1556f75c 100644 --- a/.github/workflows/ci-workflow.yml +++ b/.github/workflows/ci-workflow.yml @@ -26,7 +26,7 @@ jobs: name: C tests runs-on: ubuntu-latest container: - image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-legacy:latest + image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest steps: - name: Clone uses: actions/checkout@v3 From d9f301a51c8d0ead5ecd3fece8a65ee8f237bad0 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Tue, 13 Aug 2024 16:39:50 +0300 Subject: [PATCH 3/7] Remove outdated docker-make --- docker-make | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100755 docker-make diff --git a/docker-make b/docker-make deleted file mode 100755 index 26605154..00000000 --- a/docker-make +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -docker_tag=73c9e07 -docker_image_base=ledger-app-builder -docker_image="${docker_image_base}:${docker_tag}" - -if ! docker image inspect "$docker_image" &>/dev/null; then - echo "docker image \`$docker_image\` not found. please see README.md" 1>&2 - exit 1 -fi - -here="$(readlink -f "$(dirname "$0")")" -source "$here"/util/active-target.sh - -last_target_sdk="$(read_last_target_sdk_mnemonic "$here")" -maybe_target_sdk="$(normalize_mnemonic "${1:-''}" false)" -if [[ -n "$maybe_target_sdk" ]]; then - shift -fi -target_sdk="${maybe_target_sdk:-"$last_target_sdk"}" - -if [[ -z "$target_sdk" ]]; then - echo 'cannot resolve target sdk. please pass `s`, `x` or `sp` as the first argument' 1>&2 - exit 1 -elif [[ -z "$last_target_sdk" ]]; then - write_last_target_sdk_mnemonic "$here" "$target_sdk" -elif [[ "$target_sdk" != "$last_target_sdk" ]]; then - echo "target_sdk change requested. please run \`$0 clean\` first" 1>&2 - exit 1 -fi - -bolos_sdk_var="$(sdk_mnemonic_to_bolos_variable "$target_sdk")" - -user=$(id -u) -group=$(id -g) -owner="$user:$group" - -IFS='' read -r -d '' container_script < Date: Tue, 13 Aug 2024 16:47:13 +0300 Subject: [PATCH 4/7] Update README to follow the most recent Ledger Application Builder --- README.md | 124 ++++++++++++++++-------------------------------------- 1 file changed, 37 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index 5d144947..4841a72e 100644 --- a/README.md +++ b/README.md @@ -12,118 +12,68 @@ Current Features: - Blind sign arbitrary transactions (Enabled via settings) ## Prerequisites + ### For building the app + * [Install Docker](https://docs.docker.com/get-docker/) * For Linux hosts, install the Ledger Nano [udev rules](https://github.com/LedgerHQ/udev-rules) -#### Build the [Ledger App Builder](https://developers.ledger.com/docs/nano-app/build/) Docker image -1. Clone the git repository -``` -git clone https://github.com/LedgerHQ/ledger-app-builder.git -``` -2. Change directories -``` -cd ledger-app-builder -``` -3. Checkout the target commit -``` -git checkout 73c9e07 -``` -4. Build the image -``` -docker build -t ledger-app-builder:73c9e07 . -``` - * If permissions errors are encountered, ensure that your user is in the `docker` -group and that the session has been restarted +* Pull Ledger Development Tools image -### For working with the device -#### Install Python3 PIP -Ubuntu Linux: -``` -sudo apt install pip3 +```sh +$ docker pull ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest ``` -MacOS -``` -brew install python3 -``` -#### Install ledgerblue python module -``` -pip3 install ledgerblue -``` -#### Locally clone SDK repos corresponding to those included in the Docker image -* Setup environment -```bash -cat >>"${HOME}"/.profile < +Build the app in the container. The BOLOS_SDK variable is used to specify the target SDK, allowing to compile the application for each Ledger device. See [Ledger Application Builder](https://github.com/LedgerHQ/ledger-app-builder?tab=readme-ov-file#compile-your-app-in-the-container) for more details. + +```sh +# E.g. for Nano S +$ sudo docker run --rm -ti -v "$(realpath .):/app" --user $(id -u $USER):$(id -g $USER) ghcr.io/ledgerhq/ledger-app-builder//ledger-app-dev-tools:latest +bash$ BOLOS_SDK=$NANOS_SDK make ``` ### Clean -```bash -./docker-make clean + +Within the running development container + +```sh +bash$ BOLOS_SDK=$NANOS_SDK make clean ``` ## Working with the device -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. + +See [Ledger Application Builder](https://github.com/LedgerHQ/ledger-app-builder?tab=readme-ov-file#compile-your-app-in-the-container) for more details. + ### Load + ```bash -make load-only +$ sudo docker run --rm -ti -v "$(realpath .):/app" --privileged -v "/dev/bus/usb:/dev/bus/usb" --user $(id -u $USER):$(id -g $USER) ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest +bash$ BOLOS_SDK=$NANOS_SDK make load ``` ### Delete -```bash -make delete + +Within the running development container + +```sh +bash$ BOLOS_SDK=$NANOS_SDK make delete ``` ## Test + ### Unit + Run C tests: -```bash -make -C libsol + +```sh +bash$ make -C libsol ``` + ### Integration + First enable `blind-signing` in the App settings -```bash -cargo run --manifest-path tests/Cargo.toml + +```sh +bash$ cargo run --manifest-path tests/Cargo.toml ``` From 32c42555847b15d101bd7a665312af406f4cbe5d Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 16 Aug 2024 13:18:34 +0400 Subject: [PATCH 5/7] Add python snapshots testing to README --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 4841a72e..ac8ab3a1 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,22 @@ Run C tests: bash$ make -C libsol ``` +### Ragger + +Make sure that you have already built the application for the specific device. + +Run Ragger tests: + +```sh +# Install python test suite dependencies +bash$ pip install -r "tests/python/requirements.txt" + +# Run test suite for the specific device, e.g. nanos +bash$ pytest tests/python/ --tb=short -v --device nanos -k "" +``` + +To regenerate golden snapshots, use `--golden_run` option. + ### Integration First enable `blind-signing` in the App settings From 375d0c8dc0239971de75962deb20f9b5fef10b10 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 16 Aug 2024 16:48:41 +0400 Subject: [PATCH 6/7] Change wording for token account creation flow --- libsol/spl_associated_token_account_instruction.c | 6 +++--- libsol/transaction_printers.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libsol/spl_associated_token_account_instruction.c b/libsol/spl_associated_token_account_instruction.c index 86ecdae8..0d499fae 100644 --- a/libsol/spl_associated_token_account_instruction.c +++ b/libsol/spl_associated_token_account_instruction.c @@ -41,13 +41,13 @@ int print_spl_associated_token_account_create_info(const SplAssociatedTokenAccou UNUSED(print_config); SummaryItem* item = transaction_summary_primary_item(); - summary_item_set_pubkey(item, "Create token acct", info->address); + summary_item_set_pubkey(item, "Create token account", info->address); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "From mint", info->mint); + summary_item_set_pubkey(item, "For", info->owner); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "Owned by", info->owner); + summary_item_set_pubkey(item, "Token address", info->mint); item = transaction_summary_general_item(); summary_item_set_pubkey(item, "Funded by", info->funder); diff --git a/libsol/transaction_printers.c b/libsol/transaction_printers.c index 91c5848d..d3fcd9c7 100644 --- a/libsol/transaction_printers.c +++ b/libsol/transaction_printers.c @@ -512,13 +512,13 @@ static int print_spl_token_create_account(const PrintConfig* print_config, const SplTokenInitializeAccountInfo* ia_info = &infos[1]->spl_token.initialize_account; SummaryItem* item = transaction_summary_primary_item(); - summary_item_set_pubkey(item, "Create token acct", ia_info->token_account); + summary_item_set_pubkey(item, "Create token account", ia_info->token_account); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "From mint", ia_info->mint_account); + summary_item_set_pubkey(item, "For", ia_info->owner); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "Owned by", ia_info->owner); + summary_item_set_pubkey(item, "Token address", ia_info->mint_account); if (print_config_show_authority(print_config, ca_info->from)) { item = transaction_summary_general_item(); From 7360e751d0f7e752352521c13969a2bd64b97b48 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 16 Aug 2024 18:27:08 +0400 Subject: [PATCH 7/7] Change wording for token operations flows --- libsol/spl_token_instruction.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/libsol/spl_token_instruction.c b/libsol/spl_token_instruction.c index 9de0b8fb..7dae2df8 100644 --- a/libsol/spl_token_instruction.c +++ b/libsol/spl_token_instruction.c @@ -461,7 +461,7 @@ static int print_spl_token_initialize_account_info(const char* primary_title, summary_item_set_pubkey(item, "Owner", info->owner); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "Mint", info->mint_account); + summary_item_set_pubkey(item, "Token address", info->mint_account); return 0; } @@ -503,13 +503,13 @@ int print_spl_token_transfer_info(const SplTokenTransferInfo* info, info->body.decimals); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "Mint", info->mint_account); + summary_item_set_pubkey(item, "Token address", info->mint_account); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "From", info->src_account); + summary_item_set_pubkey(item, "From (token account)", info->src_account); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "To", info->dest_account); + summary_item_set_pubkey(item, "To (token account)", info->dest_account); print_spl_token_sign(&info->sign, print_config); @@ -532,10 +532,10 @@ static int print_spl_token_approve_info(const SplTokenApproveInfo* info, info->body.decimals); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "Mint", info->mint_account); + summary_item_set_pubkey(item, "Token address", info->mint_account); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "From", info->token_account); + summary_item_set_pubkey(item, "From (token account)", info->token_account); print_spl_token_sign(&info->sign, print_config); @@ -598,10 +598,10 @@ static int print_spl_token_mint_to_info(const SplTokenMintToInfo* info, info->body.decimals); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "Mint", info->mint_account); + summary_item_set_pubkey(item, "Token address", info->mint_account); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "To", info->token_account); + summary_item_set_pubkey(item, "To (token account)", info->token_account); print_spl_token_sign(&info->sign, print_config); @@ -623,10 +623,10 @@ static int print_spl_token_burn_info(const SplTokenBurnInfo* info, info->body.decimals); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "Mint", info->mint_account); + summary_item_set_pubkey(item, "Token address", info->mint_account); item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "From", info->token_account); + summary_item_set_pubkey(item, "From (token account)", info->token_account); print_spl_token_sign(&info->sign, print_config); @@ -640,7 +640,7 @@ static int print_spl_token_close_account_info(const SplTokenCloseAccountInfo* in SummaryItem* item; item = transaction_summary_primary_item(); - summary_item_set_pubkey(item, "Close acct", info->token_account); + summary_item_set_pubkey(item, "Close token account", info->token_account); item = transaction_summary_general_item(); summary_item_set_pubkey(item, "Withdraw to", info->dest_account); @@ -655,11 +655,11 @@ static int print_spl_token_freeze_account_info(const SplTokenFreezeAccountInfo* SummaryItem* item; item = transaction_summary_primary_item(); - summary_item_set_pubkey(item, "Freeze acct", info->token_account); + summary_item_set_pubkey(item, "Freeze token account", info->token_account); if (print_config->expert_mode) { item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "Mint", info->mint_account); + summary_item_set_pubkey(item, "Token address", info->mint_account); } print_spl_token_sign(&info->sign, print_config); @@ -672,11 +672,11 @@ static int print_spl_token_thaw_account_info(const SplTokenThawAccountInfo* info SummaryItem* item; item = transaction_summary_primary_item(); - summary_item_set_pubkey(item, "Thaw acct", info->token_account); + summary_item_set_pubkey(item, "Thaw token account", info->token_account); if (print_config->expert_mode) { item = transaction_summary_general_item(); - summary_item_set_pubkey(item, "Mint", info->mint_account); + summary_item_set_pubkey(item, "Token address", info->mint_account); } print_spl_token_sign(&info->sign, print_config); @@ -691,7 +691,7 @@ static int print_spl_token_sync_native_info(const SplTokenSyncNativeInfo* info, SummaryItem* item; item = transaction_summary_primary_item(); - summary_item_set_pubkey(item, "Sync native acct", info->token_account); + summary_item_set_pubkey(item, "Sync native account", info->token_account); return 0; }