Giter VIP home page Giter VIP logo

app-plugin-boilerplate's Introduction

Ensure compliance with Ledger guidelines Compilation & tests

app-plugin-boilerplate

This repo is meant to be a forkable example of a plugin.

Plugins are lightweight applications that go hand-in-hand with the Ethereum Application on a Nano (S, S plus, X), Stax and Flex devices.

They allow users to safely interact with smart contracts by parsing the transaction data and displaying its content in a human-readable way. This is done on a "per contract" basis, meaning a plugin is required for every DApp.

The code has been commented, and special "EDIT THIS" comments indicate where developers are expected to adapt the code to their own needs.

It is STRONGLY recommended to follow the plugin guide in order to better understand the flow and the context for plugins.

Ethereum SDK

Ethereum plugins need the Ethereum SDK. You can use the ETHEREUM_PLUGIN_SDK variable to point to the directory where you cloned this repository. By default, the Makefile expects it to be at the root directory of this plugin repository by the ethereum-plugin-sdk name.

You can see that this CI workflow verifies that the SDK used is either on the latest master or develop references. This ensures the code is compiled and tested on the latest version of the SDK.

Documentation

The documentation about the plugin shall be added in PLUGIN_SPECIFICATON.md. It shall includes at least the smart contracts and functions supported by the plugin.

Formatting

The C source code is expected to be formatted with clang-format 11.0.0 or higher.

app-plugin-boilerplate's People

Contributors

adrienlacombe avatar apaillier-ledger avatar brianchilders avatar cedelavergne-ledger avatar dependabot[bot] avatar emmanuelm41 avatar fbeutin-ledger avatar github-actions[bot] avatar jibeee avatar jmartins-ledger avatar lpascal-ledger avatar pscott avatar sgliner-ledger avatar tamtamhero avatar tdejoigny-ledger avatar xchapron-ledger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

app-plugin-boilerplate's Issues

token handling enhancement

Currently the code assumes correct token whitelisting, it would be good to show in the boilerplate how to handle the scenario in which the token is not whitelisted.

Stax tests fail when presenting 8 screen itens

The stax tests fail when we have msg->numScreens = 8 or more.
The problem is not the amount of screens shown in stax, but somehow if there are 8 itens in the screen or more, it fails with:

...
[*] patching svc instruction at 0x40015668
[*] patching svc instruction at 0x40015676
[*] exit called (255)

We did a small POC forking the repo and adding 8 screens at https://github.com/ChorusOne/stax-failing-poc

Tests are not working if you build plugins again

Tests are working fine when using the plugin_nanos.elf and plugin_nanox.elf present on the repo. However, if they are built again (using the same process CI does) and replace those new elf files, tests fail immediately. The error the console shows is

[...]
09:19:47.124:seproxyhal: printf: New APDU received:
09:19:47.219:seproxyhal: printf: E004000096048000002C8000003C8000000000000000F9011080843B9ACA00825208947A250D5630B4CF539739DF2C5DACB4C659F2488D88016345785D8A0000B8E47FF36AB50000000000000000000000000000000000000000000000018B1DD9DC51B5A9F7000000000000000000000000000000000000000000000000000000000000008000000000000000000000000015557C8B7246C38EE7
09:19:47.221:seproxyhal: printf: TxType: c0
09:19:47.223:seproxyhal: printf: Current field: 1
09:19:47.225:seproxyhal: printf: Current field: 3
09:19:47.226:seproxyhal: printf: Current field: 4
09:19:47.227:seproxyhal: printf: Current field: 5
09:19:47.229:seproxyhal: printf: Current field: 6
09:19:47.230:seproxyhal: printf: Current field: 7
09:19:47.233:seproxyhal: printf: Selector 7FF36AB5
09:19:47.233:seproxyhal: printf: External plugin will be used
09:19:47.234:seproxyhal: printf: eth_plugin_init
09:19:47.235:seproxyhal: printf: Trying plugin Boilerplate
09:19:47.236:seproxyhal: printf: -- PLUGIN INIT CONTRACT --
[*] patching svc instruction at 0x400007d4
[*] patching svc instruction at 0x40007048
[*] patching svc instruction at 0x40007056
09:19:47.240:seproxyhal: printf: method: 257
09:19:47.241:seproxyhal: printf: pluginstatus 1
09:19:47.242:seproxyhal: printf: Data field forbidden
09:19:47.242:seproxyhal: printf: Custom processor aborted
09:19:47.245:seproxyhal: printf: exception[27264]: LR=0x40000AE1
09:19:47.246:api.api: apdu: unexpected response from device
09:19:47.247:apdu: < 6a80
> b'6a80'

[...]
EthAppPleaseEnableContractData: Please enable Blind signing or Contract data in the Ethereum app Settings
[...]

Procedure:

  1. Run tests with existing elf on ./tests/elfs/* with command yarn test
  2. Re build them using CI steps
- name: Build plugin for Nano S
        run: |
          make clean
          make BOLOS_SDK=$NANOS_SDK
- name: Build plugin for Nano X
        run: |
          make clean
          make BOLOS_SDK=$NANOX_SDK
  1. Replace existing elf with the new ones (renaming the new ones to the correct value)
  2. Re run tests using yarn test

It guess the last message is quite important. It might be the cause of the issue, but I am not sure what to do to fix it.

Failed to run tests using "Ledger dev tools"

Hi!

I installed the Ledger dev tools plugin, then:

  1. Downloaded the docker image inside a fresh app-plugin-boilerplate
  2. Clicked "Build" on the extension which successfully finished
CleanShot 2024-01-03 at 16 52 48@2x 3. Clicked on "Run tests" which failed with: CleanShot 2024-01-03 at 16 53 33@2x 4. Tried to go around the problem and I docker execed into the container and ran `cp -R build/ ./tests/ethereum_build/` 5. Tests executed but failed with CleanShot 2024-01-03 at 16 55 20@2x CleanShot 2024-01-03 at 16 55 31@2x

Please suggest the steps forward, we want to release our app in the Ledger Live. Thank you!

Timeout waiting to connect

image

I want to render this value, but I don't see any instructions for this in the documentation.

try to get it in the following way, but an error is reported.

handle_provide_parameter.c

...
switch (context->next_param) {
        case MIN_AMOUNT_RECEIVED:
            copy_parameter(context->amount_pay,
                            msg->pluginSharedRO->txContent->value.value,
                            sizeof(context->amount_pay));
            copy_parameter(context->amount_received,
                           msg->parameter,
                           sizeof(context->amount_received));
            context->next_param = UNEXPECTED_PARAMETER;
            break;
        // ...
        default:
            PRINTF("Param not supported: %d\n", context->next_param);
            msg->result = ETH_PLUGIN_RESULT_ERROR;
            break;
}

handle_query_contract_ui.c

// ...
amountToString(context->amount_pay, sizeof(context->amount_pay), decimals, ticker, msg->msg, msg->msgLength);
// ...

xxx.test.js

// ...
unsignedTx.value = parseEther("0.0009");
// ...

image

Job to test plugins is broken

The current job to test plugins is broken. It must be improved.

Process to test plugins is:

  • Compile plugins for Nano S and Nano X
  • Compile Ethereum app
  • Run tests

Building plugins

Compilation of plugin code and Ethereum app are made using a shell script (see https://github.com/LedgerHQ/app-plugin-boilerplate/blob/main/tests/build_local_test_elfs.sh).

However, Ethereum app is never built (see https://github.com/LedgerHQ/app-plugin-boilerplate/runs/5154384831?check_suite_focus=true#step:4:158). Compilation script continues (lol), and only plugins are really compiled. If plugin compilation fails, execution continues.

Binaries for plugin and app for both Nano S and Nano X are in the repo.

Problem with tests

Ethereum app isn't built, so this is the binary app from the repo which is used. If plugin compilation fails, plugin binaries from the repo are used. That means tests will pass.

Ethereum app and plugins in the repo are build with "some" SDK, on a developer's machine.

So, tests are then run using fixed Ethereum binaries, and if plugin compilation fails, tests will always pass.

Solution?

This behavior should be changed. We could clone last version from master on app-ethereum, and compile plugins using this app. However, there is a problem: Ethereum SDK from master is not necessarily the same than Ethereum SDK from plugin. Ethereum SDK is autogenerated and pushed into another repo, and this is a mess.

Any idea on how to solve this problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.