Skip to content

Commit

Permalink
Merge pull request #11 from blooo-io/feat/implement-updated-contract-…
Browse files Browse the repository at this point in the history
…methods

Feat/implement updated contract methods
  • Loading branch information
Z4karia authored Feb 23, 2023
2 parents db34419 + e99e888 commit 01836bb
Show file tree
Hide file tree
Showing 106 changed files with 4,555 additions and 5,495 deletions.
76 changes: 47 additions & 29 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Compilation & tests

on:
workflow_dispatch:
push:
branches:
- main
Expand All @@ -26,7 +27,6 @@ jobs:

- name: Build Ledger NFT plugin
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
make DEBUG=1
- name: Upload Ledger NFT binary
Expand All @@ -48,7 +48,7 @@ jobs:

- name: Build with Clang Static Analyzer
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config --global --add safe.directory /__w/LedgerHQ-app-plugin-nft/LedgerHQ-app-plugin-nft
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@v2
Expand All @@ -70,7 +70,7 @@ jobs:

- name: Build with cov-build
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config --global --add safe.directory /__w/LedgerHQ-app-plugin-nft/LedgerHQ-app-plugin-nft
make clean
cov-build --dir cov-int make default
- name: Submit the result to Coverity Scan
Expand All @@ -93,20 +93,26 @@ jobs:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Clone
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive
- name: Clone SDK
uses: actions/checkout@v3
with:
repository: LedgerHQ/ethereum-plugin-sdk
path: ethereum-plugin-sdk
ref: develop
- name: Build plugin for Nano S
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config --global --add safe.directory /__w/LedgerHQ-app-plugin-nft/LedgerHQ-app-plugin-nft
make clean
make BOLOS_SDK=$NANOS_SDK
- name: Move binary to test directory
run: |
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/ledger_nft_nanos.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: binaries
path: tests/elfs/ledger_nft_nanos.elf
Expand All @@ -118,20 +124,26 @@ jobs:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Clone
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive
- name: Clone SDK
uses: actions/checkout@v3
with:
repository: LedgerHQ/ethereum-plugin-sdk
path: ethereum-plugin-sdk
ref: develop
- name: Build plugin for Nano S+
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config --global --add safe.directory /__w/LedgerHQ-app-plugin-nft/LedgerHQ-app-plugin-nft
make clean
make BOLOS_SDK=$NANOSP_SDK
- name: Move binary to test directory
run: |
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/ledger_nft_nanosp.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: binaries
path: tests/elfs/ledger_nft_nanosp.elf
Expand All @@ -143,20 +155,26 @@ jobs:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Clone
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive
- name: Clone SDK
uses: actions/checkout@v3
with:
repository: LedgerHQ/ethereum-plugin-sdk
path: ethereum-plugin-sdk
ref: develop
- name: Build plugin for Nano X
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config --global --add safe.directory /__w/LedgerHQ-app-plugin-nft/LedgerHQ-app-plugin-nft
make clean
make BOLOS_SDK=$NANOX_SDK
- name: Move binary to test directory
run: |
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/ledger_nft_nanox.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: binaries
path: tests/elfs/ledger_nft_nanox.elf
Expand All @@ -168,22 +186,22 @@ jobs:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Checkout app-ethereum
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: LedgerHQ/app-ethereum
ref: ${{ ((github.base_ref || github.ref_name) == 'main' && 'master') || (github.base_ref || github.ref_name) }}
ref: develop
submodules: recursive
- name: Build ethereum
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config --global --add safe.directory /__w/LedgerHQ-app-plugin-nft/LedgerHQ-app-plugin-nft
make clean
make -j DEBUG=1 BYPASS_SIGNATURES=1 BOLOS_SDK=$NANOS_SDK CHAIN=ethereum ALLOW_DATA=1
- name: Move binary to test directory
run: |
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/ethereum_nanos.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: binaries
path: tests/elfs/ethereum_nanos.elf
Expand All @@ -195,22 +213,22 @@ jobs:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Checkout app-ethereum
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: LedgerHQ/app-ethereum
ref: ${{ ((github.base_ref || github.ref_name) == 'main' && 'master') || (github.base_ref || github.ref_name) }}
ref: develop
submodules: recursive
- name: Build ethereum
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config --global --add safe.directory /__w/LedgerHQ-app-plugin-nft/LedgerHQ-app-plugin-nft
make clean
make -j DEBUG=1 BYPASS_SIGNATURES=1 BOLOS_SDK=$NANOSP_SDK CHAIN=ethereum ALLOW_DATA=1
- name: Move binary to test directory
run: |
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/ethereum_nanosp.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: binaries
path: tests/elfs/ethereum_nanosp.elf
Expand All @@ -222,22 +240,22 @@ jobs:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Checkout app-ethereum
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: LedgerHQ/app-ethereum
ref: ${{ ((github.base_ref || github.ref_name) == 'main' && 'master') || (github.base_ref || github.ref_name) }}
ref: develop
submodules: recursive
- name: Build ethereum
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config --global --add safe.directory /__w/LedgerHQ-app-plugin-nft/LedgerHQ-app-plugin-nft
make clean
make -j DEBUG=1 BYPASS_SIGNATURES=1 BOLOS_SDK=$NANOX_SDK CHAIN=ethereum ALLOW_DATA=1
- name: Move binary to test directory
run: |
mkdir -p ./tests/elfs/
mv bin/app.elf ./tests/elfs/ethereum_nanox.elf
- name: Upload plugin binary
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: binaries
path: tests/elfs/ethereum_nanox.elf
Expand All @@ -258,19 +276,19 @@ jobs:
echo $HOME
echo $DISPLAY
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Download built binaries
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: binaries
path: tests/elfs/
- name: Check downloaded binaries
run: ls -lh ./tests/elfs
- run: sudo apt-get update -y && sudo apt-get install -y libusb-1.0.0 libudev-dev
- name: Install node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: "16.4.0"
node-version: "14.18.1"
- name: Install yarn
run: |
npm install -g yarn
Expand All @@ -279,4 +297,4 @@ jobs:
cd tests && yarn install
- name: Run zemu tests
run: |
cd tests && yarn test
cd tests && docker pull zondax/builder-zemu@sha256:8d7b06cedf2d018b9464f4af4b7a8357c3fbb180f3ab153f8cb8f138defb22a4 && yarn test
9 changes: 5 additions & 4 deletions .github/workflows/lint-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name: Code style check

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

jobs:
job_lint:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ debug/
dep/
obj/
tests/elfs/
build

# Editors
.idea/
.vscode

# Codespace configuration
.devcontainer

# Python
*.pyc[cod]
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,21 @@ Need more information about the interface, the architecture, or general stuff ab

Smart contracts covered by this plugin are:

| Network | Version | Smart Contract |
| --- | --- | --- |
| Network | Version | Smart Contract |
| --- | --- | --- |
| Goerli | V0 | `0x6c304a1f99cecd3a9983001e943f3de00ed811d0`|

| Goerli | V0 | `0x9ea4571a739a1d644e17d34a86e7dee97609b256`|

On these smart contracts, the functions covered by this plugin are:

| Function | Selector | Displayed Parameters |
| --- | --- | --- |
|mint | 0xa0712d68| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |
|preSaleMint | 0x827481ea| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |
|stableMintSign | 0x11413601| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |
|stableMint | 0x804b936f| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |
|mintSign | 0xf39247a9| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |
|mint (v2) | 0xa0712d68| <table><tbody> <tr><td><code>uint256 amount</code></td></tr> </tbody></table> |

## Build

Expand Down
2 changes: 1 addition & 1 deletion ethereum-plugin-sdk
26 changes: 22 additions & 4 deletions src/contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,31 @@ static const uint8_t MINT_SELECTOR[SELECTOR_SIZE] = {0xa0, 0x71, 0x2d, 0x68};
// Selector: 0x827481ea
static const uint8_t PRE_SALE_MINT_SELECTOR[SELECTOR_SIZE] = {0x82, 0x74, 0x81, 0xea};

// Function: stableMintSign
// Selector: 0x11413601
static const uint8_t STABLE_MINT_SIGN_SELECTOR[SELECTOR_SIZE] = {0x11, 0x41, 0x36, 0x01};

// Function: stableMint
// Selector: 0x804b936f
static const uint8_t STABLE_MINT_SELECTOR[SELECTOR_SIZE] = {0x80, 0x4b, 0x93, 0x6f};

// Function: mintSign
// Selector: 0xf39247a9
static const uint8_t MINT_SIGN_SELECTOR[SELECTOR_SIZE] = {0xf3, 0x92, 0x47, 0xa9};

// Function: mint (v2)
// Selector: 0xa0712d68
static const uint8_t MINT_V2_SELECTOR[SELECTOR_SIZE] = {0xa0, 0x71, 0x2d, 0x68};

// Plugin uses 0x00000 as a dummy address to reprecent ETH.
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};

// Array of all the different nft selectors.
const uint8_t *const LEDGER_NFT_SELECTORS[NUM_SELECTORS] = {
MINT_SELECTOR,
PRE_SALE_MINT_SELECTOR,
};
const uint8_t *const LEDGER_NFT_SELECTORS[NUM_SELECTORS] = {MINT_SELECTOR,
PRE_SALE_MINT_SELECTOR,
STABLE_MINT_SIGN_SELECTOR,
STABLE_MINT_SELECTOR,
MINT_SIGN_SELECTOR,
MINT_V2_SELECTOR};
4 changes: 4 additions & 0 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ void handle_init_contract(void *parameters) {
switch (context->selectorIndex) {
case MINT:
case PRE_SALE_MINT:
case STABLE_MINT_SIGN:
case STABLE_MINT:
case MINT_SIGN:
case MINT_V2:
context->next_param = AMOUNT;
break;
default:
Expand Down
4 changes: 4 additions & 0 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ void handle_provide_parameter(void *parameters) {
switch (context->selectorIndex) {
case MINT:
case PRE_SALE_MINT:
case STABLE_MINT_SIGN:
case STABLE_MINT:
case MINT_SIGN:
case MINT_V2:
handle_mint(msg, context);
break;
default:
Expand Down
12 changes: 12 additions & 0 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ void handle_query_contract_id(void *parameters) {
case PRE_SALE_MINT:
strlcpy(msg->version, "Presale Mint", msg->versionLength);
break;
case STABLE_MINT_SIGN:
strlcpy(msg->version, "Stable Mint Sign", msg->versionLength);
break;
case STABLE_MINT:
strlcpy(msg->version, "Stable Mint", msg->versionLength);
break;
case MINT_SIGN:
strlcpy(msg->version, "Mint Sign", msg->versionLength);
break;
case MINT_V2:
strlcpy(msg->version, "Mint", msg->versionLength);
break;
default:
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
7 changes: 2 additions & 5 deletions src/ledger_nft_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "eth_internals.h"
#include "eth_plugin_interface.h"

#define NUM_SELECTORS 2
#define NUM_SELECTORS 6
#define PLUGIN_NAME "Ledger NFT"
#define TOKEN_FOUND 1 << 1
#define SELECTOR_SIZE 4
Expand All @@ -15,10 +15,7 @@
extern const uint8_t NULL_ETH_ADDRESS[ADDRESS_LENGTH];

#define ADDRESS_IS_NETWORK_TOKEN(_addr) (!memcmp(_addr, NULL_ETH_ADDRESS, ADDRESS_LENGTH))
typedef enum {
MINT,
PRE_SALE_MINT,
} selector_t;
typedef enum { MINT, PRE_SALE_MINT, STABLE_MINT_SIGN, STABLE_MINT, MINT_SIGN, MINT_V2 } selector_t;

// Enumeration used to parse the smart contract data.
typedef enum {
Expand Down
Loading

0 comments on commit 01836bb

Please sign in to comment.